From: Mans Rullgard <mans@mansr.com>
To: sox-devel@lists.sourceforge.net
Subject: [PATCH 4/6] Add macros for increasing data alignment
Date: Wed, 16 Sep 2015 15:16:28 +0100 [thread overview]
Message-ID: <1442412990-20764-4-git-send-email-mans@mansr.com> (raw)
In-Reply-To: <1442412990-20764-1-git-send-email-mans@mansr.com>
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
next prev parent reply other threads:[~2015-09-16 14:16 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-16 14:16 [PATCH 1/6] Add SOX_ENCODING_DSD Mans Rullgard
2015-09-16 14:16 ` [PATCH 2/6] Add DSF file support Mans Rullgard
2015-09-16 14:16 ` [PATCH 3/6] Add support for reading DSDIFF files Mans Rullgard
2015-09-16 14:16 ` Mans Rullgard [this message]
2015-12-20 12:41 ` [PATCH 4/6] Add macros for increasing data alignment Eric Wong
2015-12-20 13:54 ` Måns Rullgård
2015-12-21 10:55 ` Eric Wong
2015-12-21 11:37 ` Måns Rullgård
2015-12-21 18:33 ` Eric Wong
2015-12-21 18:37 ` Måns Rullgård
2015-09-16 14:16 ` [PATCH 5/6] Add a sigma-delta modulator for DSD encoding Mans Rullgard
2015-10-03 22:31 ` Eric Wong
2015-10-03 22:39 ` Måns Rullgård
2015-09-16 14:16 ` [PATCH 6/6] Add DSD over PCM (dop) effect Mans Rullgard
2015-12-19 12:09 ` Eric Wong
2015-12-19 12:14 ` Måns Rullgård
2015-12-20 5:04 ` Eric Wong
2015-12-20 13:44 ` Måns Rullgård
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://lists.sourceforge.net/lists/listinfo/sox-devel
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1442412990-20764-4-git-send-email-mans@mansr.com \
--to=sox-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/sox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).