This adds the LSX_ALIGN() macro to request a specified alignment of
static data and struct definitions using GCC and MSVC attributes.
Also check for the aligned_alloc() function and alias to Microsoft's
_aligned_malloc() if necessary.
---
 configure.ac |  2 +-
 src/util.h   | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 23138a9..08f80e7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -207,7 +207,7 @@ AC_HEADER_STDC
 AC_CHECK_HEADERS(fcntl.h unistd.h byteswap.h sys/stat.h sys/time.h sys/timeb.h 
sys/types.h sys/utsname.h termios.h glob.h fenv.h)
 
 dnl Checks for library functions.
-AC_CHECK_FUNCS(strcasecmp strdup popen vsnprintf gettimeofday mkstemp fmemopen)
+AC_CHECK_FUNCS(strcasecmp strdup popen vsnprintf gettimeofday mkstemp fmemopen 
aligned_alloc)
 
 dnl Check if math library is needed.
 AC_SEARCH_LIBS([pow], [m])
diff --git a/src/util.h b/src/util.h
index 87970bb..b5cc9b8 100644
--- a/src/util.h
+++ b/src/util.h
@@ -184,6 +184,26 @@
 #define field_offset(type, field) ((size_t)&(((type *)0)->field))
 #define unless(x) if (!(x))
 
+/*----------------------------- Data alignment 
-------------------------------*/
+
+#ifdef __GNUC__
+#define LSX_ALIGN(n) __attribute__((aligned(n)))
+#elif defined _MSC_VER
+#define LSX_ALIGN(n) __declspec(align(n))
+#else
+#define LSX_ALIGN(n)
+#endif
+
+#ifdef HAVE_ALIGNED_ALLOC
+  #define aligned_free(p) free(p)
+#elif defined _MSC_VER
+  #define aligned_alloc(a, s) _aligned_malloc(s, a)
+  #define aligned_free(p) _aligned_free(p)
+#else
+  #define aligned_alloc(a, s) malloc(s)
+  #define aligned_free(p) free(p)
+#endif
+
 /*------------------------------- Maths stuff 
--------------------------------*/
 
 #include <math.h>
-- 
2.5.2


------------------------------------------------------------------------------
Monitor Your Dynamic Infrastructure at Any Scale With Datadog!
Get real-time metrics from all of your servers, apps and tools
in one place.
SourceForge users - Click here to start your Free Trial of Datadog now!
http://pubads.g.doubleclick.net/gampad/clk?id=241902991&iu=/4140
_______________________________________________
SoX-devel mailing list
SoX-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sox-devel

Reply via email to