Skip to content

Commit

Permalink
SIMD: clean neg functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lamphamsy committed Jul 27, 2018
1 parent 74adace commit fa41c2f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 27 deletions.
9 changes: 3 additions & 6 deletions src/simd_128_u16.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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];
}
Expand Down
9 changes: 3 additions & 6 deletions src/simd_128_u32.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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];
}
Expand Down
4 changes: 2 additions & 2 deletions src/simd_256.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down
10 changes: 3 additions & 7 deletions src/simd_256_u16.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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];
}
Expand Down Expand Up @@ -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;
}
}
Expand Down
9 changes: 3 additions & 6 deletions src/simd_256_u32.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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];
}
Expand Down

0 comments on commit fa41c2f

Please sign in to comment.