-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Literals Utils #80
Changes from 5 commits
295d602
dbf8115
2327807
7c10d29
0b8b214
e3a802d
7ed6e88
03edd02
0648bb1
0d0a833
33183cd
1cba60e
8aa4ea5
2a383cb
1dc2d89
aabab90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
#include <ios> | ||
#include <iomanip> | ||
#include <iostream> | ||
#include <sys/wait.h> | ||
thecppzoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#include <type_traits> | ||
|
||
|
||
|
@@ -33,6 +34,38 @@ using S32_32 = SWAR<32, uint32_t>; | |
|
||
using S64_64 = SWAR<64, uint64_t>; | ||
|
||
static_assert(SWAR<16, u64>::MaxUnsignedLaneValue == 65535); | ||
static_assert(SWAR<16, u32>::MaxUnsignedLaneValue == 65535); | ||
static_assert(SWAR<8, u32>::MaxUnsignedLaneValue == 255); | ||
static_assert(SWAR<4, u32>::MaxUnsignedLaneValue == 15); | ||
static_assert(SWAR<2, u32>::MaxUnsignedLaneValue == 3); | ||
Comment on lines
+32
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Decimal is not the natural base for these tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand why we might want to have just one format, decimal makes the repo a little more approachable and understandable. |
||
|
||
static_assert(SWAR{Literals<32, u64>, {2, 1}}.value() == 0x00000002'00000001); | ||
static_assert(SWAR{Literals<32, u64>, {1, 2}}.value() == 0x00000001'00000002); | ||
|
||
static_assert(SWAR{Literals<16, u64>, {4, 3, 2, 1}}.value() == 0x0004'0003'0002'0001); | ||
static_assert(SWAR{Literals<16, u64>, {1, 2, 3, 4}}.value() == 0x0001'0002'0003'0004); | ||
|
||
static_assert(SWAR{Literals<16, u32>, {2, 1}}.value() == 0x0002'0001); | ||
static_assert(SWAR{Literals<16, u32>, {1, 2}}.value() == 0x0001'0002); | ||
|
||
static_assert(SWAR{Literals<8, u32>, {4, 3, 2, 1}}.value() == 0x04'03'02'01); | ||
static_assert(SWAR{Literals<8, u32>, {1, 2, 3, 4}}.value() == 0x01'02'03'04); | ||
|
||
static_assert(SWAR{Literals<8, u16>, {2, 1}}.value() == 0x0201); | ||
static_assert(SWAR{Literals<8, u16>, {1, 2}}.value() == 0x0102); | ||
|
||
static_assert(SWAR{Literals<4, u8>, {2, 1}}.value() == 0x21); | ||
static_assert(SWAR{Literals<4, u8>, {1, 2}}.value() == 0x12); | ||
|
||
#define F false | ||
#define T true | ||
static_assert(BooleanSWAR{Literals<4, u16>, {F, F, F, F}}.value() == 0); | ||
static_assert(BooleanSWAR{Literals<4, u16>, {T, F, F, F}}.value() == 0b1000'0000'0000'0000); | ||
static_assert(BooleanSWAR{Literals<4, u16>, {F, T, F, F}}.value() == 0b0000'1000'0000'0000); | ||
static_assert(BooleanSWAR{Literals<4, u16>, {false, false, true, false}}.value() == 0b0000'0000'1000'0000); | ||
static_assert(BooleanSWAR{Literals<4, u16>, {false, false, false, true}}.value() == 0b0000'0000'0000'1000); | ||
thecppzoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
thecppzoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
namespace Multiplication { | ||
|
||
static_assert(~int64_t(0) == negate(S4_64{S4_64::LeastSignificantBit}).value()); | ||
|
@@ -357,23 +390,23 @@ TEST_CASE( | |
const auto left = S2_16{0}.blitElement(1, i); | ||
const auto right = S2_16{S2_16::AllOnes}.blitElement(1, i-1); | ||
const auto test = S2_16{0}.blitElement(1, 2); | ||
CHECK(test.value() == greaterEqual<2, u16>(left, right).value()); | ||
CHECK(test.value() == greaterEqual<2, u16>(left, right).value()); | ||
} | ||
} | ||
SECTION("single") { | ||
for (uint32_t i = 1; i < 15; i++) { | ||
const auto large = S4_32{0}.blitElement(1, i+1); | ||
const auto small = S4_32{S4_32::AllOnes}.blitElement(1, i-1); | ||
const auto test = S4_32{0}.blitElement(1, 8); | ||
CHECK(test.value() == greaterEqual<4, u32>(large, small).value()); | ||
CHECK(test.value() == greaterEqual<4, u32>(large, small).value()); | ||
} | ||
} | ||
SECTION("allLanes") { | ||
for (uint32_t i = 1; i < 15; i++) { | ||
const auto small = S4_32(S4_32::LeastSignificantBit * (i-1)); | ||
const auto large = S4_32(S4_32::LeastSignificantBit * (i+1)); | ||
const auto test = S4_32(S4_32::LeastSignificantBit * 8); | ||
CHECK(test.value() == greaterEqual<4, u32>(large, small).value()); | ||
CHECK(test.value() == greaterEqual<4, u32>(large, small).value()); | ||
} | ||
} | ||
} | ||
|
@@ -425,7 +458,7 @@ TEST_CASE( | |
"BooleanSWAR MSBtoLaneMask", | ||
"[swar]" | ||
) { | ||
// BooleanSWAR as a mask: | ||
// BooleanSWAR as a mask: | ||
auto bswar =BooleanSWAR<4, u32>(0x0808'0000); | ||
auto mask = S4_32(0x0F0F'0000); | ||
CHECK(bswar.MSBtoLaneMask().value() == mask.value()); | ||
|
@@ -452,6 +485,6 @@ TEST_CASE( | |
CHECK(SWAR<4, u16>(0x0400).value() == saturatingUnsignedAddition(SWAR<4, u16>(0x0100), SWAR<4, u16>(0x0300)).value()); | ||
CHECK(SWAR<4, u16>(0x0B00).value() == saturatingUnsignedAddition(SWAR<4, u16>(0x0800), SWAR<4, u16>(0x0300)).value()); | ||
CHECK(SWAR<4, u16>(0x0F00).value() == saturatingUnsignedAddition(SWAR<4, u16>(0x0800), SWAR<4, u16>(0x0700)).value()); | ||
CHECK(SWAR<4, u16>(0x0F00).value() == saturatingUnsignedAddition(SWAR<4, u16>(0x0800), SWAR<4, u16>(0x0800)).value()); | ||
CHECK(S4_32(0x0F0C'F000).value() == saturatingUnsignedAddition(S4_32(0x0804'F000), S4_32(0x0808'F000)).value()); | ||
CHECK(SWAR<4, u16>(0x0F00).value() == saturatingUnsignedAddition(SWAR<4, u16>(0x0800), SWAR<4, u16>(0x0800)).value()); | ||
CHECK(S4_32(0x0F0C'F000).value() == saturatingUnsignedAddition(S4_32(0x0804'F000), S4_32(0x0808'F000)).value()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not in use, remove