Skip to content

Commit 8f19815

Browse files
committed
Restores correctness
1 parent 07e4538 commit 8f19815

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

inc/zoo/swar/SWAR.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ struct SWAR {
9292
MostSignificantBit = LeastSignificantBit << (NBits - 1),
9393
LeastSignificantLaneMask =
9494
sizeof(T) * 8 == NBits ? // needed to avoid shifting all bits
95-
~T(0) :
96-
~(~T(0) << T{NBits}),
95+
type(~T(0)) :
96+
~(type(~type(0)) << type{NBits}),
9797
// Use LowerBits in favor of ~MostSignificantBit to not pollute
9898
// "don't care" bits when non-power-of-two bit lane sizes are supported
9999
LowerBits = MostSignificantBit - LeastSignificantBit,
@@ -158,12 +158,12 @@ struct SWAR {
158158

159159
// Returns lane at position with other lanes cleared.
160160
constexpr T isolateLane(int position) const noexcept {
161-
return m_v & (LeastSignificantLaneMask << (NBits * position));
161+
return m_v & (LeastSignificantLaneMask << T(NBits * position));
162162
}
163163

164164
// Returns lane value at position, in lane 0, rest of SWAR cleared.
165165
constexpr T at(int position) const noexcept {
166-
return LeastSignificantLaneMask & (m_v >> (NBits * position));
166+
return LeastSignificantLaneMask & (m_v >> T(NBits * position));
167167
}
168168

169169
constexpr SWAR clear(int position) const noexcept {

test/swar/BasicOperations.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ static_assert(SWAR<8, u32>::MaxUnsignedLaneValue == 255);
3939
static_assert(SWAR<4, u32>::MaxUnsignedLaneValue == 15);
4040
static_assert(SWAR<2, u32>::MaxUnsignedLaneValue == 3);
4141

42+
auto v = SWAR<3, u16>::LeastSignificantLaneMask;
43+
4244

4345
#define ZOO_PP_UNPARENTHESIZE(...) __VA_ARGS__
4446
#define X(TYPE, av, expected) \
@@ -282,6 +284,7 @@ TEST_CASE("Parity", "[swar]") {
282284
CHECK(by16.value() == 0x8000'8000);
283285
}
284286

287+
#if ZOO_USE_LEASTNBITSMASK
285288
TEST_CASE(
286289
"Isolate",
287290
"[swar]"
@@ -322,6 +325,7 @@ TEST_CASE(
322325
//CHECK(0xFFFF'FFFF'FFFF'FFFFull == isolate<64, u64>(allones)); // Broken until PR/93 goes in.
323326
}
324327
}
328+
#endif
325329

326330
TEST_CASE("Compress/Expand", "[swar]") {
327331
unsigned
@@ -387,6 +391,7 @@ static_assert(0x20 == isolateLSB<u8>(0xE0));
387391
static_assert(0x40 == isolateLSB<u8>(0xC0));
388392
static_assert(0x80 == isolateLSB<u8>(0x80));
389393

394+
#if ZOO_USE_LEASTNBITSMASK
390395
static_assert(0x80u == mostNBitsMask<1, u8>());
391396
static_assert(0xC0u == mostNBitsMask<2, u8>());
392397
static_assert(0xE0u == mostNBitsMask<3, u8>());
@@ -477,6 +482,7 @@ static_assert(0x18 == isolateLSBits<2, u8>(0xF8));
477482
static_assert(0x03 == isolateLSBits<2, u8>(0xFB));
478483
static_assert(0x0C == isolateLSBits<2, u8>(0xFC));
479484
static_assert(0x03 == isolateLSBits<2, u8>(0xFF));
485+
#endif
480486

481487
static_assert(0x0606'0606 == u32(broadcast<8>(SWAR<8, u32>(0x0000'0006))));
482488
static_assert(0x0808'0808 == u32(broadcast<8>(SWAR<8, u32>(0x0000'0008))));

0 commit comments

Comments
 (0)