2
2
3
3
#include " catch2/catch.hpp"
4
4
5
+ #include < initializer_list>
5
6
#include < type_traits>
6
7
7
8
@@ -59,7 +60,7 @@ static_assert(
59
60
60
61
static_assert (0b00000010000000110000010100000110 == 0x02'03'05'06 );
61
62
62
- TEST_CASE (" Jamie's totally working exponentiation :D " ) {
63
+ TEST_CASE (" Expontiation with 8-bit lane width (overflow unsafe) " ) {
63
64
using S = SWAR<8 , u32 >;
64
65
constexpr auto base = S::fromLaneLiterals ({2 , 3 , 5 , 6 });
65
66
constexpr auto exponent = S::fromLaneLiterals ({7 , 4 , 2 , 3 });
@@ -69,8 +70,19 @@ TEST_CASE("Jamie's totally working exponentiation :D") {
69
70
CHECK (expected.value () == actual.value ());
70
71
}
71
72
73
+ TEST_CASE (" Expontiation with 16-bit lane width (overflow unsafe)" ) {
74
+ using S = SWAR<16 , u64 >; // Change to 16-bit lane width
75
+ constexpr auto base = S::fromLaneLiterals ({10 , 2 , 7 , 3 });
76
+ constexpr auto exponent = S::fromLaneLiterals ({3 , 5 , 1 , 4 });
77
+ constexpr auto expected = S::fromLaneLiterals ({1000 , 32 , 7 , 81 });
78
+ constexpr auto actual = exponentiation_OverflowUnsafe (base, exponent);
79
+ static_assert (expected.value () == actual.value ());
80
+ CHECK (expected.value () == actual.value ());
72
81
}
73
82
83
+ };
84
+
85
+
74
86
#define HE (nbits, t, v0, v1 ) \
75
87
static_assert (horizontalEquality<nbits, t>(\
76
88
SWAR<nbits, t>(v0),\
@@ -358,7 +370,7 @@ TEST_CASE(
358
370
" BooleanSWAR MSBtoLaneMask" ,
359
371
" [swar]"
360
372
) {
361
- // BooleanSWAR as a mask:
373
+ // BooleanSWAR as a mask:
362
374
auto bswar =BooleanSWAR<4 , u32 >(0x0808'0000 );
363
375
auto mask = S4_32 (0x0F0F'0000 );
364
376
CHECK (bswar.MSBtoLaneMask ().value () == mask.value ());
@@ -385,6 +397,6 @@ TEST_CASE(
385
397
CHECK (SWAR<4 , u16 >(0x0400 ).value () == saturatingUnsignedAddition (SWAR<4 , u16 >(0x0100 ), SWAR<4 , u16 >(0x0300 )).value ());
386
398
CHECK (SWAR<4 , u16 >(0x0B00 ).value () == saturatingUnsignedAddition (SWAR<4 , u16 >(0x0800 ), SWAR<4 , u16 >(0x0300 )).value ());
387
399
CHECK (SWAR<4 , u16 >(0x0F00 ).value () == saturatingUnsignedAddition (SWAR<4 , u16 >(0x0800 ), SWAR<4 , u16 >(0x0700 )).value ());
388
- CHECK (SWAR<4 , u16 >(0x0F00 ).value () == saturatingUnsignedAddition (SWAR<4 , u16 >(0x0800 ), SWAR<4 , u16 >(0x0800 )).value ());
389
- CHECK (S4_32 (0x0F0C'F000 ).value () == saturatingUnsignedAddition (S4_32 (0x0804'F000 ), S4_32 (0x0808'F000 )).value ());
400
+ CHECK (SWAR<4 , u16 >(0x0F00 ).value () == saturatingUnsignedAddition (SWAR<4 , u16 >(0x0800 ), SWAR<4 , u16 >(0x0800 )).value ());
401
+ CHECK (S4_32 (0x0F0C'F000 ).value () == saturatingUnsignedAddition (S4_32 (0x0804'F000 ), S4_32 (0x0808'F000 )).value ());
390
402
}
0 commit comments