From: Yann Collet Date: Tue, 14 Jan 2025 23:54:10 +0000 (-0800) Subject: Alignment instruction ZSTD_ALIGNED() in common/compiler.h X-Git-Tag: v1.5.7^2~36^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8bff69af869fca1cc44172c2ae5d5f995322509b;p=thirdparty%2Fzstd.git Alignment instruction ZSTD_ALIGNED() in common/compiler.h --- diff --git a/lib/common/compiler.h b/lib/common/compiler.h index f636b7f25..2a8002288 100644 --- a/lib/common/compiler.h +++ b/lib/common/compiler.h @@ -281,7 +281,7 @@ #endif /*-************************************************************** -* Alignment check +* Alignment *****************************************************************/ /* @return 1 if @u is a 2^n value, 0 otherwise @@ -315,6 +315,19 @@ MEM_STATIC int ZSTD_isPower2(size_t u) { # endif #endif /* ZSTD_ALIGNOF */ +#ifndef ZSTD_ALIGNED +/* C90-compatible alignment macro (GCC/Clang). Adjust for other compilers if needed. */ +# if defined(__GNUC__) +# define ZSTD_ALIGNED(a) __attribute__((aligned(a))) +# elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) /* C11 */ +# define ZSTD_ALIGNED(a) alignas(a) +# else + /* this compiler will require its own alignment instruction */ +# define ZSTD_ALIGNED(...) +# endif +#endif /* ZSTD_ALIGNED */ + + /*-************************************************************** * Sanitizer *****************************************************************/ diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 8e5f369bb..eba2d07dc 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -7386,22 +7386,12 @@ size_t ZSTD_convertBlockSequences(ZSTD_CCtx* cctx, #if defined(ZSTD_ARCH_X86_AVX2) -/* C90-compatible alignment macro (GCC/Clang). Adjust for other compilers if needed. */ -#if defined(__GNUC__) -# define ALIGNED32 __attribute__((aligned(32))) -#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) /* C11 */ -# define ALIGNED32 alignas(32) -#else - /* this compiler will require its own alignment instruction */ -# define ALIGNED32 -#endif - BlockSummary ZSTD_get1BlockSummary(const ZSTD_Sequence* seqs, size_t nbSeqs) { size_t i; __m256i const zeroVec = _mm256_setzero_si256(); __m256i sumVec = zeroVec; /* accumulates match+lit in 32-bit lanes */ - ALIGNED32 U32 tmp[8]; /* temporary buffer for reduction */ + ZSTD_ALIGNED(32) U32 tmp[8]; /* temporary buffer for reduction */ size_t mSum = 0, lSum = 0; ZSTD_STATIC_ASSERT(sizeof(ZSTD_Sequence) == 16);