Skip to content

Commit 4261a23

Browse files
committed
revert accidental change
1 parent c83ac4a commit 4261a23

File tree

2 files changed

+118
-104
lines changed

2 files changed

+118
-104
lines changed

inc/zoo/swar/SWAR.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,4 @@ static_assert(
510510
0x0706050403020100ull
511511
);
512512

513-
514-
515513
}}
516-
517-
518-
static_assert(zoo::swar::SWAR<8, zoo::swar::u32>::baseFromLaneLiterals({0, 0, 0, 0}) == 0);

test/swar/BasicOperations.cpp

Lines changed: 118 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <type_traits>
66

7+
78
using namespace zoo;
89
using namespace zoo::swar;
910

@@ -20,8 +21,7 @@ constexpr auto Doubled =
2021

2122
static_assert(0x090B0D0F == Doubled.even.value());
2223
static_assert(0x080A0C0E == Doubled.odd.value());
23-
static_assert(PrecisionFixtureTest ==
24-
halvePrecision(Doubled.even, Doubled.odd).value());
24+
static_assert(PrecisionFixtureTest == halvePrecision(Doubled.even, Doubled.odd).value());
2525

2626
constexpr SWAR<8, u32> Micand{0x5030201};
2727
constexpr SWAR<8, u32> Mplier{0xA050301};
@@ -33,11 +33,15 @@ constexpr SWAR<8, u32> Mplier{0xA050301};
3333
// 1*1 = 1
3434
constexpr auto Expected = 0x320F0601;
3535

36-
static_assert(Expected ==
37-
multiplication_OverflowUnsafe(Micand, Mplier).value());
36+
static_assert(
37+
Expected == multiplication_OverflowUnsafe(Micand, Mplier).value()
38+
);
3839
static_assert(
3940
0x320F0601 != // intentionally use a too-small bit count
40-
multiplication_OverflowUnsafe_SpecificBitCount<3>(Micand, Mplier).value());
41+
multiplication_OverflowUnsafe_SpecificBitCount<3>(Micand, Mplier).value()
42+
);
43+
44+
static_assert(0b00000010000000110000010100000110 == 0x02'03'05'06);
4145

4246
TEST_CASE("Jamie's totally working exponentiation :D") {
4347
using S = SWAR<8, u32>;
@@ -49,12 +53,13 @@ TEST_CASE("Jamie's totally working exponentiation :D") {
4953
CHECK(expected.value() == actual.value());
5054
}
5155

52-
} // namespace Multiplication
56+
}
5357

54-
#define HE(nbits, t, v0, v1) \
55-
static_assert(horizontalEquality<nbits, t>( \
56-
SWAR<nbits, t>(v0), \
57-
SWAR<nbits, t>(meta::BitmaskMaker<t, v1, nbits>::value)));
58+
#define HE(nbits, t, v0, v1) \
59+
static_assert(horizontalEquality<nbits, t>(\
60+
SWAR<nbits, t>(v0),\
61+
SWAR<nbits, t>(meta::BitmaskMaker<t, v1, nbits>::value)\
62+
));
5863
HE(8, u64, 0x0808'0808'0808'0808, 0x8);
5964
HE(4, u64, 0x1111'1111'1111'1111, 0x1);
6065
HE(3, u64, 0xFFFF'FFFF'FFFF'FFFF, 0x7);
@@ -65,42 +70,47 @@ HE(2, u8, 0xAA, 0x2);
6570
#undef HE
6671

6772
TEST_CASE("Old version", "[deprecated][swar]") {
68-
SWAR<8, u32> Micand{0x5030201};
69-
SWAR<8, u32> Mplier{0xA050301};
70-
auto Expected = 0x320F0601;
71-
auto result = multiplication_OverflowUnsafe_SpecificBitCount_deprecated<4>(
72-
Micand, Mplier);
73-
CHECK(Expected == result.value());
73+
SWAR<8, u32> Micand{0x5030201};
74+
SWAR<8, u32> Mplier{0xA050301};
75+
auto Expected = 0x320F0601;
76+
auto result =
77+
multiplication_OverflowUnsafe_SpecificBitCount_deprecated<4>(
78+
Micand, Mplier
79+
);
80+
CHECK(Expected == result.value());
7481
}
7582

7683
TEST_CASE("Parity", "[swar]") {
77-
// For each nibble, E indicates (E)ven and O (O)dd parities
78-
// EEOEEOOO
79-
auto Examples = 0xFF13A7E4;
80-
SWAR<4, u32> casesBy4{Examples};
81-
SWAR<8, u32> casesBy8{Examples};
82-
auto by4 = parity(casesBy4);
83-
auto by8 = parity(casesBy8);
84-
CHECK(by4.value() == 0x00800888);
85-
CHECK(by8.value() == 0x00808000);
84+
// For each nibble, E indicates (E)ven and O (O)dd parities
85+
// EEOEEOOO
86+
auto Examples = 0xFF13A7E4;
87+
SWAR<4, u32> casesBy4{Examples};
88+
SWAR<8, u32> casesBy8{Examples};
89+
auto by4 = parity(casesBy4);
90+
auto by8 = parity(casesBy8);
91+
CHECK(by4.value() == 0x00800888);
92+
CHECK(by8.value() == 0x00808000);
8693
}
8794

88-
TEST_CASE("Isolate", "[swar]") {
89-
for (auto i = 0; i < 63; ++i) {
90-
CHECK(i == isolate<8>(i));
91-
CHECK(i == isolate<8>(0xFF00 + i));
92-
CHECK(i == isolate<8>(0xFFFF00 + i));
93-
}
94-
for (auto i = 0; i < 31; ++i) {
95-
CHECK(i == isolate<7>(i));
96-
CHECK(i == isolate<7>(0xFF00 + i));
97-
CHECK(i == isolate<7>(0xFFFF00 + i));
98-
}
99-
for (auto i = 0; i < 31; ++i) {
100-
CHECK(i == isolate<11>(i));
101-
CHECK(i == isolate<11>(0xF800 + i));
102-
CHECK(i == isolate<11>(0xFFF800 + i));
103-
}
95+
TEST_CASE(
96+
"Isolate",
97+
"[swar]"
98+
) {
99+
for (auto i = 0; i < 63; ++i) {
100+
CHECK(i == isolate<8>(i));
101+
CHECK(i == isolate<8>(0xFF00+i));
102+
CHECK(i == isolate<8>(0xFFFF00+i));
103+
}
104+
for (auto i = 0; i < 31; ++i) {
105+
CHECK(i == isolate<7>(i));
106+
CHECK(i == isolate<7>(0xFF00+i));
107+
CHECK(i == isolate<7>(0xFFFF00+i));
108+
}
109+
for (auto i = 0; i < 31; ++i) {
110+
CHECK(i == isolate<11>(i));
111+
CHECK(i == isolate<11>(0xF800+i));
112+
CHECK(i == isolate<11>(0xFFF800+i));
113+
}
104114
}
105115

106116
static_assert(1 == popcount<5>(0x100ull));
@@ -113,13 +123,13 @@ static_assert(0x210 == popcount<1>(0x320));
113123
static_assert(0x4321 == popcount<2>(0xF754));
114124
static_assert(0x50004 == popcount<4>(0x3E001122));
115125

116-
static_assert(1 == msbIndex<u64>(1ull << 1));
117-
static_assert(3 == msbIndex<u64>(1ull << 3));
118-
static_assert(5 == msbIndex<u64>(1ull << 5));
119-
static_assert(8 == msbIndex<u64>(1ull << 8));
120-
static_assert(17 == msbIndex<u64>(1ull << 17));
121-
static_assert(30 == msbIndex<u64>(1ull << 30));
122-
static_assert(31 == msbIndex<u64>(1ull << 31));
126+
static_assert(1 == msbIndex<u64>(1ull<<1));
127+
static_assert(3 == msbIndex<u64>(1ull<<3));
128+
static_assert(5 == msbIndex<u64>(1ull<<5));
129+
static_assert(8 == msbIndex<u64>(1ull<<8));
130+
static_assert(17 == msbIndex<u64>(1ull<<17));
131+
static_assert(30 == msbIndex<u64>(1ull<<30));
132+
static_assert(31 == msbIndex<u64>(1ull<<31));
123133

124134
namespace {
125135
using namespace zoo::meta;
@@ -130,7 +140,7 @@ static_assert(0x0808'0808'0808'0808ull == BitmaskMaker<u64, 0x08ull, 8>::value);
130140
static_assert(0x0101'0101'0101'0101ull == BitmaskMaker<u64, 0x01ull, 8>::value);
131141
static_assert(0x0E0E'0E0E'0E0E'0E0Eull == BitmaskMaker<u64, 0x0Eull, 8>::value);
132142
static_assert(0x0303'0303'0303'0303ull == BitmaskMaker<u64, 0x03ull, 8>::value);
133-
} // namespace
143+
}
134144

135145
static_assert(0x00 == clearLSB<u8>(0x80));
136146
static_assert(0x80 == clearLSB<u8>(0xC0));
@@ -218,44 +228,53 @@ static_assert(0x0808'0808 == u32(broadcast<8>(SWAR<8, u32>(0x0000'0008))));
218228
static_assert(0x0B0B'0B0B == u32(broadcast<8>(SWAR<8, u32>(0x0000'000B))));
219229
static_assert(0x0E0E'0E0E == u32(broadcast<8>(SWAR<8, u32>(0x0000'000E))));
220230
static_assert(0x6B6B'6B6B == u32(broadcast<8>(SWAR<8, u32>(0x0000'006B))));
221-
static_assert(0x0808'0808'0808'0808ull ==
222-
u64(broadcast<8>(SWAR<8, u64>(0x0000'0000'0000'0008ull))));
231+
static_assert(0x0808'0808'0808'0808ull == u64(broadcast<8>(SWAR<8, u64>(0x0000'0000'0000'0008ull))));
223232

224-
static_assert(1 == lsbIndex(1 << 1));
225-
static_assert(3 == lsbIndex(1 << 3));
226-
static_assert(5 == lsbIndex(1 << 5));
227-
static_assert(8 == lsbIndex(1 << 8));
228-
static_assert(17 == lsbIndex(1 << 17));
229-
static_assert(30 == lsbIndex(1 << 30));
233+
static_assert(1 == lsbIndex(1<<1));
234+
static_assert(3 == lsbIndex(1<<3));
235+
static_assert(5 == lsbIndex(1<<5));
236+
static_assert(8 == lsbIndex(1<<8));
237+
static_assert(17 == lsbIndex(1<<17));
238+
static_assert(30 == lsbIndex(1<<30));
230239

231240
/*
232241
These tests were not catching errors known to have been present
233-
static_assert(0x80880008 == greaterEqual<3>(SWAR<4,
234-
uint32_t>(0x3245'1027)).value()); static_assert(0x88888888 ==
235-
greaterEqual<0>(SWAR<4, uint32_t>(0x0123'4567)).value());
236-
static_assert(0x88888888 == greaterEqual<0>(SWAR<4,
237-
uint32_t>(0x7654'3210)).value()); static_assert(0x00000008 ==
238-
greaterEqual<7>(SWAR<4, uint32_t>(0x0123'4567)).value());
239-
static_assert(0x80000000 == greaterEqual<7>(SWAR<4,
240-
uint32_t>(0x7654'3210)).value());
242+
static_assert(0x80880008 == greaterEqual<3>(SWAR<4, uint32_t>(0x3245'1027)).value());
243+
static_assert(0x88888888 == greaterEqual<0>(SWAR<4, uint32_t>(0x0123'4567)).value());
244+
static_assert(0x88888888 == greaterEqual<0>(SWAR<4, uint32_t>(0x7654'3210)).value());
245+
static_assert(0x00000008 == greaterEqual<7>(SWAR<4, uint32_t>(0x0123'4567)).value());
246+
static_assert(0x80000000 == greaterEqual<7>(SWAR<4, uint32_t>(0x7654'3210)).value());
241247
*/
242248

243249
// Unusual formatting for easy visual verification.
244-
#define GE_MSB_TEST(left, right, result) \
245-
static_assert(result == greaterEqual_MSB_off<4, u32>(SWAR<4, u32>(left), \
246-
SWAR<4, u32>(right)) \
247-
.value());
248-
249-
GE_MSB_TEST(0x1000'0010, 0x0111'1101, 0x8000'0080)
250-
GE_MSB_TEST(0x4333'3343, 0x4444'4444, 0x8000'0080)
251-
GE_MSB_TEST(0x0550'0110, 0x0110'0550, 0x8888'8008)
252-
GE_MSB_TEST(0x4771'1414, 0x4641'1774, 0x8888'8008)
253-
254-
GE_MSB_TEST(0x0123'4567, 0x0000'0000, 0x8888'8888)
255-
GE_MSB_TEST(0x0123'4567, 0x7777'7777, 0x0000'0008)
256-
257-
GE_MSB_TEST(0x0000'0000, 0x0123'4567, 0x8000'0000)
258-
GE_MSB_TEST(0x7777'7777, 0x0123'4567, 0x8888'8888)
250+
#define GE_MSB_TEST(left, right, result) static_assert(result== greaterEqual_MSB_off<4, u32>(SWAR<4, u32>(left), SWAR<4, u32>(right)).value());
251+
252+
GE_MSB_TEST(0x1000'0010,
253+
0x0111'1101,
254+
0x8000'0080)
255+
GE_MSB_TEST(0x4333'3343,
256+
0x4444'4444,
257+
0x8000'0080)
258+
GE_MSB_TEST(0x0550'0110,
259+
0x0110'0550,
260+
0x8888'8008)
261+
GE_MSB_TEST(0x4771'1414,
262+
0x4641'1774,
263+
0x8888'8008)
264+
265+
GE_MSB_TEST(0x0123'4567,
266+
0x0000'0000,
267+
0x8888'8888)
268+
GE_MSB_TEST(0x0123'4567,
269+
0x7777'7777,
270+
0x0000'0008)
271+
272+
GE_MSB_TEST(0x0000'0000,
273+
0x0123'4567,
274+
0x8000'0000)
275+
GE_MSB_TEST(0x7777'7777,
276+
0x0123'4567,
277+
0x8888'8888)
259278

260279
// 3 bits on msb side, 5 bits on lsb side.
261280
using Lanes = SWARWithSubLanes<5, 3, u32>;
@@ -266,25 +285,25 @@ static constexpr inline u32 allF = broadcast<8>(S8u32(0x0000'00FFul)).value();
266285
static_assert(allF == Lanes(allF).value());
267286
static_assert(0xFFFF'FFFF == Lanes(allF).value());
268287

269-
static_assert(0xFFFF'FFE0 == Lanes(allF).least(0, 0).value());
270-
static_assert(0xFFFF'FFE1 == Lanes(allF).least(1, 0).value());
271-
static_assert(0xFFFF'E0FF == Lanes(allF).least(0, 1).value());
272-
static_assert(0xFFFF'E1FF == Lanes(allF).least(1, 1).value());
273-
274-
static_assert(0xFFE0'FFFF == Lanes(allF).least(0, 2).value());
275-
static_assert(0xFFE1'FFFF == Lanes(allF).least(1, 2).value());
276-
static_assert(0xE0FF'FFFF == Lanes(allF).least(0, 3).value());
277-
static_assert(0xE1FF'FFFF == Lanes(allF).least(1, 3).value());
278-
279-
static_assert(0xFFFF'FF1F == Lanes(allF).most(0, 0).value());
280-
static_assert(0xFFFF'FF3F == Lanes(allF).most(1, 0).value());
281-
static_assert(0xFFFF'1FFF == Lanes(allF).most(0, 1).value());
282-
static_assert(0xFFFF'3FFF == Lanes(allF).most(1, 1).value());
283-
284-
static_assert(0xFF1F'FFFF == Lanes(allF).most(0, 2).value());
285-
static_assert(0xFF3F'FFFF == Lanes(allF).most(1, 2).value());
286-
static_assert(0x1FFF'FFFF == Lanes(allF).most(0, 3).value());
287-
static_assert(0x3FFF'FFFF == Lanes(allF).most(1, 3).value());
288+
static_assert(0xFFFF'FFE0 == Lanes(allF).least(0,0).value());
289+
static_assert(0xFFFF'FFE1 == Lanes(allF).least(1,0).value());
290+
static_assert(0xFFFF'E0FF == Lanes(allF).least(0,1).value());
291+
static_assert(0xFFFF'E1FF == Lanes(allF).least(1,1).value());
292+
293+
static_assert(0xFFE0'FFFF == Lanes(allF).least(0,2).value());
294+
static_assert(0xFFE1'FFFF == Lanes(allF).least(1,2).value());
295+
static_assert(0xE0FF'FFFF == Lanes(allF).least(0,3).value());
296+
static_assert(0xE1FF'FFFF == Lanes(allF).least(1,3).value());
297+
298+
static_assert(0xFFFF'FF1F == Lanes(allF).most(0,0).value());
299+
static_assert(0xFFFF'FF3F == Lanes(allF).most(1,0).value());
300+
static_assert(0xFFFF'1FFF == Lanes(allF).most(0,1).value());
301+
static_assert(0xFFFF'3FFF == Lanes(allF).most(1,1).value());
302+
303+
static_assert(0xFF1F'FFFF == Lanes(allF).most(0,2).value());
304+
static_assert(0xFF3F'FFFF == Lanes(allF).most(1,2).value());
305+
static_assert(0x1FFF'FFFF == Lanes(allF).most(0,3).value());
306+
static_assert(0x3FFF'FFFF == Lanes(allF).most(1,3).value());
288307

289308
static_assert(0x0000'001f == Lanes(all0).least(31, 0).most(0, 0).value());
290309
static_assert(0x0000'1f00 == Lanes(all0).least(31, 1).most(0, 1).value());

0 commit comments

Comments
 (0)