Skip to content

Commit 7c26b50

Browse files
committed
Address review
1 parent afe91c8 commit 7c26b50

5 files changed

Lines changed: 13 additions & 17 deletions

File tree

include/xsimd/arch/xsimd_avx512f.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,10 +2256,8 @@ namespace xsimd
22562256
{
22572257
static_assert(sizeof...(Values) == batch_bool<T, A>::size, "consistent init");
22582258
using register_type = typename batch_bool<T, A>::register_type;
2259-
register_type r = 0;
22602259
unsigned shift = 0;
2261-
((r |= register_type(values ? 1 : 0) << (shift++)), ...);
2262-
return r;
2260+
return (register_type(0) | ... | (register_type(values ? 1 : 0) << (shift++)));
22632261
}
22642262

22652263
// shuffle

include/xsimd/arch/xsimd_avx512vl_128.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,8 @@ namespace xsimd
174174
{
175175
static_assert(sizeof...(Values) == batch_bool<T, A>::size, "consistent init");
176176
using register_type = typename batch_bool<T, A>::register_type;
177-
register_type r = 0;
178177
unsigned shift = 0;
179-
((r |= register_type(values ? 1 : 0) << (shift++)), ...);
180-
return r;
178+
return (register_type(0) | ... | (register_type(values ? 1 : 0) << (shift++)));
181179
}
182180

183181
// store

include/xsimd/arch/xsimd_avx512vl_256.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,8 @@ namespace xsimd
174174
{
175175
static_assert(sizeof...(Values) == batch_bool<T, A>::size, "consistent init");
176176
using register_type = typename batch_bool<T, A>::register_type;
177-
register_type r = 0;
178177
unsigned shift = 0;
179-
((r |= register_type(values ? 1 : 0) << (shift++)), ...);
180-
return r;
178+
return (register_type(0) | ... | (register_type(values ? 1 : 0) << (shift++)));
181179
}
182180

183181
// store

include/xsimd/utils/bits.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@ namespace xsimd
1919
{
2020
namespace utils
2121
{
22-
template <typename I, typename... Args>
23-
constexpr I make_bit_mask(I bit, Args... bits)
22+
template <typename... Args>
23+
constexpr auto make_bit_mask(Args... bits)
2424
{
25-
static_assert(std::is_unsigned_v<I>, "Bit operations must be done on unsigned integers");
26-
[[maybe_unused]] constexpr I bit_count = static_cast<I>(8 * sizeof(I));
27-
assert(((bit < bit_count) && ... && (static_cast<I>(bits) < bit_count)));
28-
return static_cast<I>(((I { 1 } << bit) | ... | (I { 1 } << static_cast<I>(bits))));
25+
using out_type = std::common_type_t<unsigned short, std::make_unsigned_t<Args>...>;
26+
[[maybe_unused]] constexpr auto bit_count = static_cast<out_type>(8 * sizeof(out_type));
27+
assert((((static_cast<out_type>(bits) < bit_count) && ...)));
28+
return static_cast<out_type>((0u | ... | (1u << bits)));
2929
}
3030

31-
template <int... Bits, typename I>
31+
template <auto... Bits, typename I>
3232
constexpr bool all_bits_set(I value)
3333
{
3434
static_assert(std::is_unsigned_v<I>, "Bit operations must be done on unsigned integers");
3535
constexpr I mask = make_bit_mask<I>(static_cast<I>(Bits)...);
3636
return (value & mask) == mask;
3737
}
3838

39-
template <int Bit, typename I>
39+
template <auto Bit, typename I>
4040
constexpr I set_bit(I value)
4141
{
4242
static_assert(std::is_unsigned_v<I>, "Bit operations must be done on unsigned integers");

test/test_utils_bits.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
TEST_CASE("[utils::make_bit_mask] single bit")
1919
{
20+
CHECK_EQ(xsimd::utils::make_bit_mask(), 0x0);
21+
CHECK_EQ(xsimd::utils::make_bit_mask(1), 0b0010);
2022
CHECK_EQ(xsimd::utils::make_bit_mask<std::uint8_t>(0), 0x01);
2123
CHECK_EQ(xsimd::utils::make_bit_mask<std::uint8_t>(7), 0x80);
2224
CHECK_EQ(xsimd::utils::make_bit_mask<std::uint32_t>(0), 0x01u);

0 commit comments

Comments
 (0)