From e77bd70bdd860c52c561568cffb251d88bba064c Mon Sep 17 00:00:00 2001 From: Alfred Klomp Date: Thu, 5 Jan 2023 21:59:30 +0100 Subject: [PATCH] #118: enc: asm: add memory and flags as clobbers Add the memory and flags ("cc") as clobbers to all assembly encoder implementations. This informs the compiler that the assembly will access an unspecified amount of memory and will modify the flags. The compiler will not use any dangling references to memory or keep a cached copy of the flags register. In tests, the compilers seem to output the exact same code as before, so this should have no functional impact beyond ensuring correctness. Resolves #118. --- lib/arch/avx/enc_loop_asm.c | 3 +++ lib/arch/avx2/enc_loop_asm.c | 3 +++ lib/arch/neon32/enc_loop.c | 3 ++- lib/arch/neon64/enc_loop_asm.c | 3 ++- lib/arch/ssse3/enc_loop_asm.c | 3 +++ 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/arch/avx/enc_loop_asm.c b/lib/arch/avx/enc_loop_asm.c index ada81e2a..979269af 100644 --- a/lib/arch/avx/enc_loop_asm.c +++ b/lib/arch/avx/enc_loop_asm.c @@ -255,6 +255,9 @@ enc_loop_avx (const uint8_t **s, size_t *slen, uint8_t **o, size_t *olen) [msk3] "x" (_mm_set1_epi32(0x01000010)), [n51] "x" (_mm_set1_epi8(51)), [n25] "x" (_mm_set1_epi8(25)) + + // Clobbers. + : "cc", "memory" ); } diff --git a/lib/arch/avx2/enc_loop_asm.c b/lib/arch/avx2/enc_loop_asm.c index 87aba284..eb775a1d 100644 --- a/lib/arch/avx2/enc_loop_asm.c +++ b/lib/arch/avx2/enc_loop_asm.c @@ -282,6 +282,9 @@ enc_loop_avx2 (const uint8_t **s, size_t *slen, uint8_t **o, size_t *olen) [msk3] "x" (_mm256_set1_epi32(0x01000010)), [n51] "x" (_mm256_set1_epi8(51)), [n25] "x" (_mm256_set1_epi8(25)) + + // Clobbers. + : "cc", "memory" ); } diff --git a/lib/arch/neon32/enc_loop.c b/lib/arch/neon32/enc_loop.c index e9e8e285..d694b337 100644 --- a/lib/arch/neon32/enc_loop.c +++ b/lib/arch/neon32/enc_loop.c @@ -100,7 +100,8 @@ enc_loop_neon32_inner_asm (const uint8_t **s, uint8_t **o) [n63] "w" (n63) // Clobbers. - : "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31" + : "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31", + "cc", "memory" ); } #endif diff --git a/lib/arch/neon64/enc_loop_asm.c b/lib/arch/neon64/enc_loop_asm.c index cf2fd27e..182e9cdf 100644 --- a/lib/arch/neon64/enc_loop_asm.c +++ b/lib/arch/neon64/enc_loop_asm.c @@ -160,7 +160,8 @@ enc_loop_neon64 (const uint8_t **s, size_t *slen, uint8_t **o, size_t *olen) // Clobbers. : "v2", "v3", "v4", "v5", "v8", "v9", "v10", "v11", - "v12", "v13", "v14", "v15" + "v12", "v13", "v14", "v15", + "cc", "memory" ); } diff --git a/lib/arch/ssse3/enc_loop_asm.c b/lib/arch/ssse3/enc_loop_asm.c index 893fe0e7..0cdb340a 100644 --- a/lib/arch/ssse3/enc_loop_asm.c +++ b/lib/arch/ssse3/enc_loop_asm.c @@ -259,6 +259,9 @@ enc_loop_ssse3 (const uint8_t **s, size_t *slen, uint8_t **o, size_t *olen) [msk3] "x" (_mm_set1_epi32(0x01000010)), [n51] "x" (_mm_set1_epi8(51)), [n25] "x" (_mm_set1_epi8(25)) + + // Clobbers. + : "cc", "memory" ); }