22
33#include " catch2/catch.hpp"
44
5+ #include < initializer_list>
56#include < type_traits>
67
78
@@ -59,7 +60,7 @@ static_assert(
5960
6061static_assert (0b00000010000000110000010100000110 == 0x02'03'05'06 );
6162
62- TEST_CASE (" Jamie's totally working exponentiation :D " ) {
63+ TEST_CASE (" Expontiation with 8-bit lane width (overflow unsafe) " ) {
6364 using S = SWAR<8 , u32 >;
6465 constexpr auto base = S::fromLaneLiterals ({2 , 3 , 5 , 6 });
6566 constexpr auto exponent = S::fromLaneLiterals ({7 , 4 , 2 , 3 });
@@ -69,8 +70,19 @@ TEST_CASE("Jamie's totally working exponentiation :D") {
6970 CHECK (expected.value () == actual.value ());
7071}
7172
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 ());
7281}
7382
83+ };
84+
85+
7486#define HE (nbits, t, v0, v1 ) \
7587 static_assert (horizontalEquality<nbits, t>(\
7688 SWAR<nbits, t>(v0),\
@@ -358,7 +370,7 @@ TEST_CASE(
358370 " BooleanSWAR MSBtoLaneMask" ,
359371 " [swar]"
360372) {
361- // BooleanSWAR as a mask:
373+ // BooleanSWAR as a mask:
362374 auto bswar =BooleanSWAR<4 , u32 >(0x0808'0000 );
363375 auto mask = S4_32 (0x0F0F'0000 );
364376 CHECK (bswar.MSBtoLaneMask ().value () == mask.value ());
@@ -385,6 +397,6 @@ TEST_CASE(
385397 CHECK (SWAR<4 , u16 >(0x0400 ).value () == saturatingUnsignedAddition (SWAR<4 , u16 >(0x0100 ), SWAR<4 , u16 >(0x0300 )).value ());
386398 CHECK (SWAR<4 , u16 >(0x0B00 ).value () == saturatingUnsignedAddition (SWAR<4 , u16 >(0x0800 ), SWAR<4 , u16 >(0x0300 )).value ());
387399 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 ());
390402}
0 commit comments