Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions include/hpcombi/epu8_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,27 @@

namespace HPCombi {

static constexpr const std::array<epu8, 17> MASK =
{
Epu8(0),
{0xFF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0xFF, 0xFF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0xFF, 0xFF, 0xFF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0xFF, 0xFF, 0xFF, 0xFF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0, 0, 0, 0, 0, 0, 0, 0},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0, 0, 0, 0, 0, 0, 0},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0, 0, 0, 0, 0, 0},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0, 0, 0, 0, 0},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0, 0, 0, 0},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0, 0, 0},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0, 0},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0},
Epu8(0xFF)
};

///////////////////////////////////////////////////////////////////////////////
// Implementation part for inline functions
///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -483,12 +504,11 @@ inline epu8 popcount16(epu8 v) noexcept {
permuted(Epu8.popcount(), v >> 4));
}



inline bool is_partial_transformation(epu8 v, const size_t k) noexcept {
uint64_t diff = last_diff(v, Epu8.id(), 16);
// (forall x in v, x + 1 <= 16) and
// (v = Perm16::one() or last diff index < 16)
return (simde_mm_movemask_epi8(v + Epu8(1) <= Epu8(0x10)) == 0xffff) &&
(diff == 16 || diff < k);
HPCOMBI_ASSERT(k <= 16);
return simde_mm_movemask_epi8((v & MASK[k]) + Epu8(1) <= Epu8(0x10)) == 0xffff;
}

inline bool is_transformation(epu8 v, const size_t k) noexcept {
Expand Down
10 changes: 5 additions & 5 deletions tests/test_epu8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,17 +648,17 @@ TEST_CASE_METHOD(Fix, "is_partial_transformation", "[Epu8][063]") {
CHECK(is_partial_transformation(Epu8({}, 0xff)));
CHECK(is_partial_transformation(Epu8({2, 0xff, 3}, 0)));

CHECK(!is_partial_transformation(zero, 15));
CHECK(is_partial_transformation(zero, 15));
CHECK(is_partial_transformation(Pa));
CHECK(is_partial_transformation(Pa, 6));
CHECK(is_partial_transformation(Pa, 5));
CHECK(!is_partial_transformation(Pa, 4));
CHECK(!is_partial_transformation(Pa, 1));
CHECK(!is_partial_transformation(Pa, 0));
CHECK(is_partial_transformation(Pa, 4));
CHECK(is_partial_transformation(Pa, 1));
CHECK(is_partial_transformation(Pa, 0));

CHECK(is_partial_transformation(RP));
CHECK(is_partial_transformation(RP, 16));
CHECK(!is_partial_transformation(RP, 15));
CHECK(is_partial_transformation(RP, 15));
CHECK(is_partial_transformation(Epu8({1, 2, 1, 0xFF, 0, 5, 0xFF, 2}, 0)));
CHECK(!is_partial_transformation(Epu8({1, 2, 1, 0xFF, 0, 16, 0xFF, 2}, 0)));
}
Expand Down
28 changes: 28 additions & 0 deletions tests/test_perm16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,4 +535,32 @@ TEST_CASE_METHOD(Perm16Fixture, "Perm16::left_weak_leq", "[Perm16][044]") {
}
}
}

TEST_CASE("PTransf16::validate", "[PTransf16][045]") {
PTransf16 x({0, 1, 255});
REQUIRE(x.validate(16));
REQUIRE(x.validate(2));
REQUIRE(x.validate(3));

x = PTransf16({0, 1});
REQUIRE(x.validate(16));
REQUIRE(x.validate(2));
REQUIRE(x.validate(3));

x = PTransf16({1, 0});
REQUIRE(x.validate(16));
REQUIRE(x.validate(2));
REQUIRE(x.validate(3));

x = PTransf16({0xFF, 0});
REQUIRE(x.validate(16));
REQUIRE(x.validate(1));
REQUIRE(x.validate(2));
REQUIRE(x.validate(3));

x = PTransf16({0, 1, 2, 17});
REQUIRE(x.validate(3));
REQUIRE(!x.validate(4));
REQUIRE(!x.validate());
}
} // namespace HPCombi