diff options
author | Chris Robinson <[email protected]> | 2014-04-19 02:11:04 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2014-04-19 02:11:04 -0700 |
commit | 59fc9aac0ee41518dba0cbd2f1518decffeaa480 (patch) | |
tree | ac9793a8e3015e595b2f679b82b7f11e4472f717 | |
parent | 8badd3740e1a2e13affb4553c69ca44b1649035b (diff) |
Use C11 alignas when available
-rw-r--r-- | Alc/align.h | 21 | ||||
-rw-r--r-- | Alc/mixer_inc.c | 4 | ||||
-rw-r--r-- | CMakeLists.txt | 10 | ||||
-rw-r--r-- | OpenAL32/Include/alAuxEffectSlot.h | 4 | ||||
-rw-r--r-- | OpenAL32/Include/alMain.h | 17 | ||||
-rw-r--r-- | OpenAL32/Include/alu.h | 10 | ||||
-rw-r--r-- | config.h.in | 6 |
7 files changed, 55 insertions, 17 deletions
diff --git a/Alc/align.h b/Alc/align.h new file mode 100644 index 00000000..babd4106 --- /dev/null +++ b/Alc/align.h @@ -0,0 +1,21 @@ +#ifndef AL_ALIGN_H +#define AL_ALIGN_H + +#ifdef HAVE_STDALIGN_H +#include <stdalign.h> +#endif + +#ifndef alignas +#ifdef HAVE_C11_ALIGNAS +#define alignas _Alignas +#elif defined(IN_IDE_PARSER) +/* KDevelop has problems with our align macro, so just use nothing for parsing. */ +#define alignas(x) +#else +/* NOTE: Our custom ALIGN macro can't take a type name like alignas can. For + * maximum compatibility, only provide constant integer values to alignas. */ +#define alignas(_x) ALIGN(_x) +#endif +#endif + +#endif /* AL_ALIGN_H */ diff --git a/Alc/mixer_inc.c b/Alc/mixer_inc.c index a2d0a16c..4748f785 100644 --- a/Alc/mixer_inc.c +++ b/Alc/mixer_inc.c @@ -2,8 +2,10 @@ #include "alMain.h" #include "alSource.h" + #include "hrtf.h" #include "mixer_defs.h" +#include "align.h" #define REAL_MERGE2(a,b) a##b @@ -36,7 +38,7 @@ void MixDirect_Hrtf(DirectParams *params, const ALfloat *restrict data, ALuint s ALfloat (*restrict Values)[2] = params->Mix.Hrtf.State.Values[srcchan]; ALuint Counter = maxu(params->Counter, OutPos) - OutPos; ALuint Offset = params->Offset + OutPos; - ALIGN(16) ALfloat Coeffs[HRIR_LENGTH][2]; + alignas(16) ALfloat Coeffs[HRIR_LENGTH][2]; ALuint Delay[2]; ALfloat left, right; ALuint pos; diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d440aab..5e84cd64 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -176,6 +176,15 @@ CHECK_C_SOURCE_COMPILES( }" HAVE_C11_STATIC_ASSERT) +# Check if we have C11 alignas +CHECK_C_SOURCE_COMPILES( +"_Alignas(4) int foo; + int main() + { + return 0; + }" +HAVE_C11_ALIGNAS) + # Add definitions, compiler switches, etc. INCLUDE_DIRECTORIES("${OpenAL_SOURCE_DIR}/include" "${OpenAL_BINARY_DIR}") IF(CMAKE_VERSION VERSION_LESS "2.8.8") @@ -319,6 +328,7 @@ ENDIF() CHECK_C_SOURCE_COMPILES("int foo(const char *str, ...) __attribute__((format(printf, 1, 2))); int main() {return 0;}" HAVE_GCC_FORMAT) +CHECK_INCLUDE_FILE(stdalign.h HAVE_STDALIGN_H) IF(NOT HAVE_C99_VLA) CHECK_INCLUDE_FILE(alloca.h HAVE_ALLOCA_H) ENDIF() diff --git a/OpenAL32/Include/alAuxEffectSlot.h b/OpenAL32/Include/alAuxEffectSlot.h index 264f8f73..75eb87ca 100644 --- a/OpenAL32/Include/alAuxEffectSlot.h +++ b/OpenAL32/Include/alAuxEffectSlot.h @@ -4,6 +4,8 @@ #include "alMain.h" #include "alEffect.h" +#include "align.h" + #ifdef __cplusplus extern "C" { #endif @@ -72,7 +74,7 @@ typedef struct ALeffectslot { volatile ALenum NeedsUpdate; ALeffectState *EffectState; - ALIGN(16) ALfloat WetBuffer[1][BUFFERSIZE]; + alignas(16) ALfloat WetBuffer[1][BUFFERSIZE]; RefCount ref; diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 3247aa96..ad305c4e 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -31,7 +31,7 @@ #endif #endif - +#include "align.h" #include "atomic.h" #include "uintmap.h" #include "vector.h" @@ -271,11 +271,6 @@ ALC_API void ALC_APIENTRY alcGetInteger64vSOFT(ALCdevice *device, ALCenum pname, /* KDevelop's parser doesn't recognize the C99-standard restrict keyword, but * recent versions (at least 4.5.1) do recognize GCC's __restrict. */ #define restrict __restrict -/* KDevelop won't see the ALIGN macro from config.h when viewing files that - * don't include it directly (e.g. headers). */ -#ifndef ALIGN -#define ALIGN(x) -#endif #endif @@ -682,11 +677,11 @@ struct ALCdevice_struct ALuint SamplesDone; /* Temp storage used for mixing. */ - ALIGN(16) ALfloat SampleData1[BUFFERSIZE]; - ALIGN(16) ALfloat SampleData2[BUFFERSIZE]; + alignas(16) ALfloat SampleData1[BUFFERSIZE]; + alignas(16) ALfloat SampleData2[BUFFERSIZE]; // Dry path buffer mix - ALIGN(16) ALfloat DryBuffer[MaxChannels][BUFFERSIZE]; + alignas(16) ALfloat DryBuffer[MaxChannels][BUFFERSIZE]; /* Running count of the mixer invocations, in 31.1 fixed point. This * actually increments *twice* when mixing, first at the start and then at @@ -708,7 +703,7 @@ struct ALCdevice_struct ALCdevice *volatile next; /* Memory space used by the default slot (Playback devices only) */ - ALIGN(16) ALCbyte _slot_mem[]; + alignas(16) ALCbyte _slot_mem[]; }; // Frequency was requested by the app or config file @@ -779,7 +774,7 @@ struct ALCcontext_struct ALCcontext *volatile next; /* Memory space used by the listener */ - ALIGN(16) ALCbyte _listener_mem[]; + alignas(16) ALCbyte _listener_mem[]; }; ALCcontext *GetContextRef(void); diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h index c1aa143d..f931b737 100644 --- a/OpenAL32/Include/alu.h +++ b/OpenAL32/Include/alu.h @@ -13,7 +13,9 @@ #include "alMain.h" #include "alBuffer.h" #include "alFilter.h" + #include "hrtf.h" +#include "align.h" #define F_PI (3.14159265358979323846f) @@ -38,15 +40,15 @@ extern "C" { #endif typedef struct HrtfState { - ALIGN(16) ALfloat History[MAX_INPUT_CHANNELS][SRC_HISTORY_LENGTH]; - ALIGN(16) ALfloat Values[MAX_INPUT_CHANNELS][HRIR_LENGTH][2]; + alignas(16) ALfloat History[MAX_INPUT_CHANNELS][SRC_HISTORY_LENGTH]; + alignas(16) ALfloat Values[MAX_INPUT_CHANNELS][HRIR_LENGTH][2]; } HrtfState; typedef struct HrtfParams { ALfloat Gain; ALfloat Dir[3]; - ALIGN(16) ALfloat Coeffs[MAX_INPUT_CHANNELS][HRIR_LENGTH][2]; - ALIGN(16) ALfloat CoeffStep[MAX_INPUT_CHANNELS][HRIR_LENGTH][2]; + alignas(16) ALfloat Coeffs[MAX_INPUT_CHANNELS][HRIR_LENGTH][2]; + alignas(16) ALfloat CoeffStep[MAX_INPUT_CHANNELS][HRIR_LENGTH][2]; ALuint Delay[MAX_INPUT_CHANNELS][2]; ALint DelayStep[MAX_INPUT_CHANNELS][2]; ALuint IrSize; diff --git a/config.h.in b/config.h.in index 5e6d0862..33eb5b62 100644 --- a/config.h.in +++ b/config.h.in @@ -95,6 +95,9 @@ /* Define if we have C11 _Static_assert support */ #cmakedefine HAVE_C11_STATIC_ASSERT +/* Define if we have C11 _Alignas support */ +#cmakedefine HAVE_C11_ALIGNAS + /* Define if we have GCC's destructor attribute */ #cmakedefine HAVE_GCC_DESTRUCTOR @@ -104,6 +107,9 @@ /* Define if we have stdint.h */ #cmakedefine HAVE_STDINT_H +/* Define if we have stdalign.h */ +#cmakedefine HAVE_STDALIGN_H + /* Define if we have windows.h */ #cmakedefine HAVE_WINDOWS_H |