Skip to content

Commit 0b311dc

Browse files
committed
Improve 8bit lshift avx2 constant
1 parent bd9c72a commit 0b311dc

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

include/xsimd/arch/xsimd_avx2.hpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,9 @@ namespace xsimd
314314
{
315315
XSIMD_IF_CONSTEXPR(sizeof(T) == 1)
316316
{
317-
const __m256i byte_mask = _mm256_set1_epi16(0x00FF);
318-
__m256i u16 = _mm256_and_si256(self, byte_mask);
319-
__m256i r16 = _mm256_srli_epi16(u16, shift);
320-
return _mm256_and_si256(r16, byte_mask);
317+
constexpr uint8_t mask8 = static_cast<uint8_t>((1u << shift) - 1u);
318+
__m256i const mask = _mm256_set1_epi8(mask8);
319+
return _mm256_and_si256(_mm256_srli_epi16(self, shift), mask);
321320
}
322321
XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
323322
{
@@ -331,10 +330,6 @@ namespace xsimd
331330
{
332331
return _mm256_srli_epi64(self, shift);
333332
}
334-
else
335-
{
336-
return bitwise_rshift<shift>(self, avx {});
337-
}
338333
}
339334
}
340335

0 commit comments

Comments
 (0)