Skip to content

Commit efacead

Browse files
committed
Alignment instruction ZSTD_ALIGNED() in common/compiler.h
1 parent d80de37 commit efacead

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

lib/common/compiler.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@
281281
#endif
282282

283283
/*-**************************************************************
284-
* Alignment check
284+
* Alignment
285285
*****************************************************************/
286286

287287
/* @return 1 if @u is a 2^n value, 0 otherwise
@@ -315,6 +315,19 @@ MEM_STATIC int ZSTD_isPower2(size_t u) {
315315
# endif
316316
#endif /* ZSTD_ALIGNOF */
317317

318+
#ifndef ZSTD_ALIGNED
319+
/* C90-compatible alignment macro (GCC/Clang). Adjust for other compilers if needed. */
320+
# if defined(__GNUC__)
321+
# define ZSTD_ALIGNED(a) __attribute__((aligned(a)))
322+
# elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) /* C11 */
323+
# define ZSTD_ALIGNED(a) alignas(a)
324+
# else
325+
/* this compiler will require its own alignment instruction */
326+
# define ZSTD_ALIGNED(...)
327+
# endif
328+
#endif /* ZSTD_ALIGNED */
329+
330+
318331
/*-**************************************************************
319332
* Sanitizer
320333
*****************************************************************/

lib/compress/zstd_compress.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7386,22 +7386,12 @@ size_t ZSTD_convertBlockSequences(ZSTD_CCtx* cctx,
73867386

73877387
#if defined(ZSTD_ARCH_X86_AVX2)
73887388

7389-
/* C90-compatible alignment macro (GCC/Clang). Adjust for other compilers if needed. */
7390-
#if defined(__GNUC__)
7391-
# define ALIGNED32 __attribute__((aligned(32)))
7392-
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) /* C11 */
7393-
# define ALIGNED32 alignas(32)
7394-
#else
7395-
/* this compiler will require its own alignment instruction */
7396-
# define ALIGNED32
7397-
#endif
7398-
73997389
BlockSummary ZSTD_get1BlockSummary(const ZSTD_Sequence* seqs, size_t nbSeqs)
74007390
{
74017391
size_t i;
74027392
__m256i const zeroVec = _mm256_setzero_si256();
74037393
__m256i sumVec = zeroVec; /* accumulates match+lit in 32-bit lanes */
7404-
ALIGNED32 U32 tmp[8]; /* temporary buffer for reduction */
7394+
ZSTD_ALIGNED(32) U32 tmp[8]; /* temporary buffer for reduction */
74057395
size_t mSum = 0, lSum = 0;
74067396
ZSTD_STATIC_ASSERT(sizeof(ZSTD_Sequence) == 16);
74077397

0 commit comments

Comments
 (0)