Skip to content

Commit 0e78b8b

Browse files
Extra batch_bool invariant testing
1 parent 50d205d commit 0e78b8b

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

test/test_batch_bool.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,4 +922,49 @@ TEST_CASE_TEMPLATE("[xsimd batch bool]", B, BATCH_TYPES)
922922

923923
SUBCASE("mask utils (compile-time)") { Test.test_mask_compile_time(); }
924924
}
925+
926+
TEST_CASE_TEMPLATE("batch_bool mask hygiene", B, BATCH_TYPES)
927+
{
928+
using batch_type = B;
929+
using arch_type = typename B::arch_type;
930+
using value_type = typename B::value_type;
931+
932+
SUBCASE("any(a != a) is false")
933+
{
934+
batch_type a(value_type(1));
935+
CHECK_FALSE(xsimd::any(a != a));
936+
}
937+
938+
SUBCASE("all(~(a != a)) is true")
939+
{
940+
batch_type a(value_type(1));
941+
CHECK_UNARY(xsimd::all(~(a != a)));
942+
}
943+
944+
SUBCASE("any(~(a == a)) is false")
945+
{
946+
batch_type a(value_type(1));
947+
CHECK_FALSE(xsimd::any(~(a == a)));
948+
}
949+
950+
SUBCASE("eq(mask, _mask) is all-true")
951+
{
952+
auto m0 = (batch_type(value_type(1)) != batch_type(value_type(1)));
953+
CHECK_UNARY(xsimd::all(m0 == m0));
954+
}
955+
956+
SUBCASE("batch_bool stored to bool[] is canonical 0/1")
957+
{
958+
batch_type a(value_type(1)), b(value_type(2));
959+
auto m = (a == b); // all false
960+
alignas(arch_type::alignment()) bool buf[B::size + 1] = { true, true }; // sentinel
961+
m.store_aligned(buf);
962+
for (std::size_t i = 0; i < B::size; ++i)
963+
{
964+
// bit-level check: must be exactly 0, not just falsy
965+
CHECK_EQ(*reinterpret_cast<uint8_t const*>(&buf[i]), uint8_t(0));
966+
}
967+
}
968+
}
969+
925970
#endif

0 commit comments

Comments
 (0)