From fa41c2f5db35d0e3f28856a1b1df84524ce0bd54 Mon Sep 17 00:00:00 2001 From: Lam Pham-Sy Date: Fri, 27 Jul 2018 05:23:43 +0200 Subject: [PATCH] SIMD: clean neg functions --- src/simd_128_u16.h | 9 +++------ src/simd_128_u32.h | 9 +++------ src/simd_256.h | 4 ++-- src/simd_256_u16.h | 10 +++------- src/simd_256_u32.h | 9 +++------ 5 files changed, 14 insertions(+), 27 deletions(-) diff --git a/src/simd_128_u16.h b/src/simd_128_u16.h index a85dd742..b4bf7ec0 100644 --- a/src/simd_128_u16.h +++ b/src/simd_128_u16.h @@ -80,9 +80,8 @@ inline m128i sub(m128i a, m128i b, aint16 card) return _mm_sub_epi16(_a1, _b); } -/** Perform negatize of a - * neg(a) = 0 if a = 0 - * card - a otherwise +/** Negate a + * @return 0 if (a == 0), else card - a */ inline m128i neg(m128i a, aint16 card = F3) { @@ -140,7 +139,7 @@ inline m128i mul(m128i a, m128i b, aint16 card) return mul(a, b); } -/** Negatize elements of buffers +/** Apply an element-wise negation to a buffer */ inline void neg(size_t len, aint16* buf, aint16 card = F3) { @@ -151,12 +150,10 @@ inline void neg(size_t len, aint16* buf, aint16 card = F3) size_t i; for (i = 0; i < _len; i++) { - // perform negatization _buf[i] = neg(_buf[i], card); } if (_last_len > 0) { for (i = _len * ratio; i < len; i++) { - // perform negatization if (buf[i]) buf[i] = card - buf[i]; } diff --git a/src/simd_128_u32.h b/src/simd_128_u32.h index 91f681d4..98687475 100644 --- a/src/simd_128_u32.h +++ b/src/simd_128_u32.h @@ -80,9 +80,8 @@ inline m128i sub(m128i a, m128i b, aint32 card) return _mm_sub_epi32(_a1, _b); } -/** Perform negatize of a - * neg(a) = 0 if a = 0 - * card - a otherwise +/** Negate a + * @return 0 if (a == 0), else card - a */ inline m128i neg(m128i a, aint32 card = F4) { @@ -185,7 +184,7 @@ inline m128i mul(m128i a, m128i b, aint32 card) return mul_f3(a, b); } -/** Negatize elements of buffers +/** Apply an element-wise negation to a buffer */ inline void neg(size_t len, aint32* buf, aint32 card = F4) { @@ -196,12 +195,10 @@ inline void neg(size_t len, aint32* buf, aint32 card = F4) size_t i; for (i = 0; i < _len; i++) { - // perform negatization _buf[i] = neg(_buf[i], card); } if (_last_len > 0) { for (i = _len * ratio; i < len; i++) { - // perform negatization if (buf[i] > 0) buf[i] = card - buf[i]; } diff --git a/src/simd_256.h b/src/simd_256.h index 2e3cc487..ec8dc133 100644 --- a/src/simd_256.h +++ b/src/simd_256.h @@ -43,8 +43,8 @@ const m256i F3_m256i = _mm256_set1_epi32(257); // NOLINT(cert-err58-cpp) const m256i F3minus1_m256i = _mm256_set1_epi32(256); // NOLINT(cert-err58-cpp) const m256i F3_m256i_u16 = _mm256_set1_epi16(257); // NOLINT(cert-err58-cpp) -const m256i F3minus1_m256i_u16 = - _mm256_set1_epi16(256); // NOLINT(cert-err58-cpp) +// NOLINTNEXTLINE(cert-err58-cpp) +const m256i F3minus1_m256i_u16 = _mm256_set1_epi16(256); /* GCC doesn't include the split store intrinsics so define them here. */ #if defined(__GNUC__) && !defined(__clang__) diff --git a/src/simd_256_u16.h b/src/simd_256_u16.h index 11b6bbcf..6cc504a8 100644 --- a/src/simd_256_u16.h +++ b/src/simd_256_u16.h @@ -78,9 +78,8 @@ inline m256i sub(m256i a, m256i b, aint16 card) return _mm256_sub_epi16(_a1, _b); } -/** Perform negatize of a - * neg(a) = 0 if a = 0 - * card - a otherwise +/** Negate a + * @return 0 if (a == 0), else card - a */ inline m256i neg(m256i a, aint16 card = F3) { @@ -138,7 +137,7 @@ inline m256i mul(m256i a, m256i b, aint16 card) return mul(a, b); } -/** Negatize elements of buffers +/** Apply an element-wise negation to a buffer */ inline void neg(size_t len, aint16* buf, aint16 card = F3) { @@ -149,12 +148,10 @@ inline void neg(size_t len, aint16* buf, aint16 card = F3) size_t i; for (i = 0; i < _len; i++) { - // perform negatization _buf[i] = neg(_buf[i], card); } if (_last_len > 0) { for (i = _len * ratio; i < len; i++) { - // perform negatization if (buf[i]) buf[i] = card - buf[i]; } @@ -263,7 +260,6 @@ mul_two_bufs(aint16* src, aint16* dest, size_t len, aint16 card = F3) if (_last_len > 0) { for (i = _len * ratio; i < len; i++) { // perform multiplicaton - // dest[i] = uint32_t(src[i]) * uint32_t(dest[i]) % card; dest[i] = (uint32_t(src[i]) * dest[i]) % card; } } diff --git a/src/simd_256_u32.h b/src/simd_256_u32.h index e58a7da5..204c3bfd 100644 --- a/src/simd_256_u32.h +++ b/src/simd_256_u32.h @@ -80,9 +80,8 @@ inline m256i sub(m256i a, m256i b, aint32 card) return _mm256_sub_epi32(_a1, _b); } -/** Perform negatize of a - * neg(a) = 0 if a = 0 - * card - a otherwise +/** Negate a + * @return 0 if (a == 0), else card - a */ inline m256i neg(m256i a, aint32 card = F4) { @@ -185,7 +184,7 @@ inline m256i mul(m256i a, m256i b, aint32 card) return mul_f3(a, b); } -/** Negatize elements of buffers +/** Apply an element-wise negation to a buffer */ inline void neg(size_t len, aint32* buf, aint32 card = F4) { @@ -196,12 +195,10 @@ inline void neg(size_t len, aint32* buf, aint32 card = F4) size_t i; for (i = 0; i < _len; i++) { - // perform negatization _buf[i] = neg(_buf[i], card); } if (_last_len > 0) { for (i = _len * ratio; i < len; i++) { - // perform negatization if (buf[i]) buf[i] = card - buf[i]; }