Skip to content

Commit 3425fd0

Browse files
committed
Fix shift inside if constexpr
1 parent 0b311dc commit 3425fd0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

include/xsimd/arch/xsimd_avx2.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ namespace xsimd
181181
static_assert(shift < bits, "Shift must be less than the number of bits in T");
182182
XSIMD_IF_CONSTEXPR(sizeof(T) == 1)
183183
{
184-
constexpr uint8_t mask8 = static_cast<uint8_t>(~0u << shift);
184+
// TODO(C++17): without `if constexpr` we must ensure the compile-time shift does not overflow
185+
constexpr uint8_t mask8 = static_cast<uint8_t>(sizeof(T) == 1 ? (~0u << shift) : 0);
185186
__m256i const mask = _mm256_set1_epi8(mask8);
186187
return _mm256_and_si256(_mm256_slli_epi16(self, shift), mask);
187188
}
@@ -314,7 +315,8 @@ namespace xsimd
314315
{
315316
XSIMD_IF_CONSTEXPR(sizeof(T) == 1)
316317
{
317-
constexpr uint8_t mask8 = static_cast<uint8_t>((1u << shift) - 1u);
318+
// TODO(C++17): without `if constexpr` we must ensure the compile-time shift does not overflow
319+
constexpr uint8_t mask8 = static_cast<uint8_t>(sizeof(T) == 1 ? ((1u << shift) - 1u) : 0);
318320
__m256i const mask = _mm256_set1_epi8(mask8);
319321
return _mm256_and_si256(_mm256_srli_epi16(self, shift), mask);
320322
}

0 commit comments

Comments
 (0)