Skip to content

Commit

Permalink
All test reinstated & pass on x86_64
Browse files Browse the repository at this point in the history
  • Loading branch information
hivert committed Oct 28, 2023
1 parent 62a38dd commit 95b1b63
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 108 deletions.
11 changes: 4 additions & 7 deletions include/perm16_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,21 @@ inline uint32_t PTransf16::fix_points_bitset(bool complement) const {
}

inline uint8_t PTransf16::smallest_fix_point() const {
uint32_t res = fix_points_bitset(false);
return res == 0 ? 0xFF : __builtin_ffsl(res) - 1;
return __builtin_ffs(fix_points_bitset(false)) - 1;
}
/** Returns the smallest non fix point of \c *this */
inline uint8_t PTransf16::smallest_moved_point() const {
uint32_t res = fix_points_bitset(true);
return res == 0 ? 0xFF : __builtin_ffsl(res) - 1;
return __builtin_ffs(fix_points_bitset(true)) - 1;
}
/** Returns the largest fix point of \c *this */
inline uint8_t PTransf16::largest_fix_point() const {
uint32_t res = fix_points_bitset(false);

return res == 0 ? 0xFF : 15 - __builtin_ctzl(res);
return res == 0 ? 0xFF : 31 - __builtin_clz(res);
}
/** Returns the largest non fix point of \c *this */
inline uint8_t PTransf16::largest_moved_point() const {
uint32_t res = fix_points_bitset(true);
return res == 0 ? 0xFF : 15 - __builtin_ctzl(res);
return res == 0 ? 0xFF : 31 - __builtin_clz(res);
}
/** Returns the number of fix points of \c *this */
inline uint8_t PTransf16::nb_fix_points() const {
Expand Down
48 changes: 19 additions & 29 deletions tests/test_epu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@
#include "test_main.hpp"
#include <catch2/catch_test_macros.hpp>

// TODO uncomment
// #define TEST_AGREES(ref, fun) \
// BOOST_FIXTURE_TEST_CASE(Epu8::agrees_##fun, Fix) { \
// for (auto x : v) \
// REQUIRE(fun(x) == ref(x)); \
// }

namespace HPCombi {

struct Fix {
Expand Down Expand Up @@ -409,12 +402,10 @@ TEST_CASE_METHOD(Fix, "Epu8::horiz_sum_ref", "[Epu8][024]") {
REQUIRE(horiz_sum_ref(Pc) == 203);
}

// TODO uncomment, compiler complains that Epu8 is an unknown type!?
// TEST_AGREES(Fix, Epu8, horiz_sum_ref, horiz_sum_gen, v, "[Epu8][025]")
// TEST_AGREES(Fix, Epu8, horiz_sum_ref, horiz_sum4, v, "[Epu8][026]")
//
// TEST_AGREES(Fix, Epu8, horiz_sum_ref, horiz_sum3, v, "[Epu8][027]")
// TEST_AGREES(Fix, Epu8, horiz_sum_ref, horiz_sum, v, "[Epu8][028]")
TEST_AGREES_FUN(Fix, Epu8, horiz_sum_ref, horiz_sum_gen, v, "[Epu8][025]")
TEST_AGREES_FUN(Fix, Epu8, horiz_sum_ref, horiz_sum4, v, "[Epu8][026]")
TEST_AGREES_FUN(Fix, Epu8, horiz_sum_ref, horiz_sum3, v, "[Epu8][027]")
TEST_AGREES_FUN(Fix, Epu8, horiz_sum_ref, horiz_sum, v, "[Epu8][028]")

TEST_CASE_METHOD(Fix, "Epu8::partial_sums_ref", "[Epu8][029]") {
REQUIRE_THAT(partial_sums_ref(zero), Equals(zero));
Expand Down Expand Up @@ -484,11 +475,10 @@ TEST_CASE_METHOD(Fix, "Epu8::horiz_max_ref", "[Epu8][033]") {
REQUIRE(horiz_max_ref(Pc) == 43);
}

// TODO uncomment, compiler complains that Epu8 is an unknown type!?
// TEST_AGREES(Fix, Epu8, horiz_max_ref, horiz_max_gen, v, "[Epu8][034]")
// TEST_AGREES(Fix, Epu8, horiz_max_ref, horiz_max4, v, "[Epu8][035]")
// TEST_AGREES(Fix, Epu8, horiz_max_ref, horiz_max3, v, "[Epu8][036]")
// TEST_AGREES(Fix, Epu8, horiz_max_ref, horiz_max, v, "[Epu8][037]")
TEST_AGREES_FUN(Fix, Epu8, horiz_max_ref, horiz_max_gen, v, "[Epu8][034]")
TEST_AGREES_FUN(Fix, Epu8, horiz_max_ref, horiz_max4, v, "[Epu8][035]")
TEST_AGREES_FUN(Fix, Epu8, horiz_max_ref, horiz_max3, v, "[Epu8][036]")
TEST_AGREES_FUN(Fix, Epu8, horiz_max_ref, horiz_max, v, "[Epu8][037]")

TEST_CASE_METHOD(Fix, "Epu8::partial_max_ref", "[Epu8][038]") {
REQUIRE_THAT(partial_max_ref(zero), Equals(zero));
Expand Down Expand Up @@ -543,11 +533,11 @@ TEST_CASE_METHOD(Fix, "Epu8::horiz_min_ref", "[Epu8][042]") {
REQUIRE(horiz_min_ref(epu8rev) == 0);
REQUIRE(horiz_min_ref(Pc) == 5);
}
// TODO uncomment
// TEST_AGREES(horiz_min_ref, horiz_min_gen)
// TEST_AGREES(horiz_min_ref, horiz_min4)
// TEST_AGREES(horiz_min_ref, horiz_min3)
// TEST_AGREES(horiz_min_ref, horiz_min)

TEST_AGREES_FUN(Fix, Epu8, horiz_min_ref, horiz_min_gen, v, "[Epu8][034]")
TEST_AGREES_FUN(Fix, Epu8, horiz_min_ref, horiz_min4, v, "[Epu8][035]")
TEST_AGREES_FUN(Fix, Epu8, horiz_min_ref, horiz_min3, v, "[Epu8][036]")
TEST_AGREES_FUN(Fix, Epu8, horiz_min_ref, horiz_min, v, "[Epu8][037]")

TEST_CASE_METHOD(Fix, "Epu8::partial_min_ref", "[Epu8][043]") {
REQUIRE_THAT(partial_min_ref(zero), Equals(zero));
Expand Down Expand Up @@ -604,12 +594,12 @@ TEST_CASE_METHOD(Fix, "Epu8::eval16_ref", "[Epu8][047]") {
REQUIRE_THAT(eval16_ref(epu8rev), Equals(Epu8({}, 1)));
REQUIRE_THAT(eval16_ref(Pc), Equals(Epu8({0, 0, 0, 0, 0, 2, 0, 10}, 0)));
}
// TODO uncomment
// TEST_Epu8::AGREES(eval16_ref, eval16_cycle, "[Epu8][000]")
// TEST_Epu8::AGREES(eval16_ref, eval16_popcount, "[Epu8][000]")
// TEST_Epu8::AGREES(eval16_ref, eval16_arr, "[Epu8][000]")
// TEST_Epu8::AGREES(eval16_ref, eval16_gen, "[Epu8][000]")
// TEST_Epu8::AGREES(eval16_ref, eval16, "[Epu8][000]")

TEST_AGREES_FUN_EPU8(Fix, Epu8, eval16_ref, eval16_cycle, v, "[Epu8][034]")
TEST_AGREES_FUN_EPU8(Fix, Epu8, eval16_ref, eval16_popcount, v, "[Epu8][034]")
TEST_AGREES_FUN_EPU8(Fix, Epu8, eval16_ref, eval16_arr, v, "[Epu8][034]")
TEST_AGREES_FUN_EPU8(Fix, Epu8, eval16_ref, eval16_gen, v, "[Epu8][034]")
TEST_AGREES_FUN_EPU8(Fix, Epu8, eval16_ref, eval16, v, "[Epu8][034]")

TEST_CASE("Epu8::popcount4", "[Epu8][048]") {
REQUIRE_THAT(popcount4,
Expand Down
24 changes: 19 additions & 5 deletions tests/test_main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,40 @@
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_templated.hpp>

#define TEST_AGREES_FUN(fixture, type, ref, fun, vct, tags) \
TEST_CASE_METHOD(fixture, #type "::" #ref " == " #type "::" #fun, tags) { \
for (auto p : vct) { \
REQUIRE(fun(p) == ref(p)); \
} \
}

#define TEST_AGREES_FUN_EPU8(fixture, type, ref, fun, vct, tags) \
TEST_CASE_METHOD(fixture, #type "::" #ref " == " #type "::" #fun, tags) { \
for (auto p : vct) { \
REQUIRE_THAT(fun(p), Equals(ref(p))); \
} \
}

#define TEST_AGREES(fixture, type, ref, fun, vct, tags) \
TEST_CASE_METHOD(fixture, #type "::" #ref " == " #type "::" #fun, tags) { \
for (type p : vct) { \
for (auto p : vct) { \
REQUIRE(p.fun() == p.ref()); \
} \
}

#define TEST_AGREES2(fixture, type, ref, fun, vct, tags) \
TEST_CASE_METHOD(fixture, #type "::" #ref " == " #type "::" #fun, tags) { \
for (type p1 : vct) { \
for (type p2 : vct) { \
for (auto p1 : vct) { \
for (auto p2 : vct) { \
REQUIRE(p1.fun(p2) == p1.ref(p2)); \
} \
} \
}

#define TEST_AGREES_EPU8(fixture, type, ref, fun, vct, tags) \
TEST_CASE_METHOD(fixture, #type "::" #ref " == " #type "::" #fun, tags) { \
for (type p : vct) { \
REQUIRE_THAT(p.fun(), Equals(p.ref())); \
for (auto p : vct) { \
REQUIRE_THAT(p.fun(), Equals(p.ref())); \
} \
}

Expand Down
132 changes: 65 additions & 67 deletions tests/test_perm16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,31 +142,25 @@ TEST_CASE("PTransf16::image_mask_ref_ref", "[PTransf16][002]") {
Equals(Epu8({0, FF, 0, FF, FF, 0, FF, FF, FF, FF, FF, FF, FF, FF, FF, 0}, 0)));
}

// TODO uncomment
// TEST_CASE("PTransf16::left_one", "[PTransf16][003]") {
// REQUIRE(PTransf16({}).left_one() == PTransf16::one());
// REQUIRE(PTransf16({4, 4, 4, 4}).left_one() ==
// PTransf16({FF, FF, FF, FF}));
// REQUIRE(PTransf16(Epu8(1)).left_one() == PTransf16(Epu8({FF, 1},
// FF))); REQUIRE(PTransf16(Epu8(2)).left_one() ==
// PTransf16(Epu8({FF, FF, 2}, FF)));
// REQUIRE(PTransf16(Epu8({2, 2, 2, 0xf}, 2)).left_one() ==
// PTransf16({FF, FF, 2, FF, FF, FF, FF, FF, FF, FF, FF, FF, FF,
// FF,
// FF, 15}));
// REQUIRE(PTransf16(Epu8({FF, 2, 2, 0xf}, FF)).left_one() ==
// PTransf16({FF, FF, 2, FF, FF, FF, FF, FF, FF, FF, FF, FF, FF,
// FF,
// FF, 15}));
// REQUIRE(
// PTransf16(Epu8({0, 2, 2, 0xf, 2, 2, 2, 2, 5, 2}, 2)).left_one() ==
// PTransf16(
// {0, FF, 2, FF, FF, 5, FF, FF, FF, FF, FF, FF, FF, FF, FF, 15 }));
// REQUIRE(
// PTransf16(Epu8({0, 2, FF, 0xf, 2, FF, 2, FF, 5}, FF)).left_one() ==
// PTransf16(
// {0, FF, 2, FF, FF, 5, FF, FF, FF, FF, FF, FF, FF, FF, FF, 15 }));
// }

TEST_CASE("PTransf16::left_one", "[PTransf16][003]") {
REQUIRE(PTransf16({}).left_one() == PTransf16::one());
REQUIRE(PTransf16({4, 4, 4, 4}).left_one() == PTransf16({FF, FF, FF, FF}));
REQUIRE(PTransf16(Epu8(1)).left_one() == PTransf16(Epu8({FF, 1}, FF)));
REQUIRE(PTransf16(Epu8(2)).left_one() == PTransf16(Epu8({FF, FF, 2}, FF)));
REQUIRE(PTransf16(Epu8({2, 2, 2, 0xf}, 2)).left_one() ==
PTransf16({FF, FF, 2, FF, FF, FF, FF, FF, FF, FF, FF, FF, FF, FF,
FF, 15}));
REQUIRE(PTransf16(Epu8({FF, 2, 2, 0xf}, FF)).left_one() ==
PTransf16({FF, FF, 2, FF, FF, FF, FF, FF, FF, FF, FF, FF, FF, FF,
FF, 15}));
REQUIRE(PTransf16(Epu8({0, 2, 2, 0xf, 2, 2, 2, 2, 5, 2}, 2)).left_one() ==
PTransf16(
{0, FF, 2, FF, FF, 5, FF, FF, FF, FF, FF, FF, FF, FF, FF, 15}));
REQUIRE(PTransf16(Epu8({0, 2, FF, 0xf, 2, FF, 2, FF, 5}, FF)).left_one() ==
PTransf16(
{0, FF, 2, FF, FF, 5, FF, FF, FF, FF, FF, FF, FF, FF, FF, 15}));
}

TEST_CASE("PTransf16::domain_mask", "[PTransf16][004]") {
REQUIRE_THAT(PTransf16({}).domain_mask(), Equals(Epu8(FF)));
Expand Down Expand Up @@ -229,22 +223,22 @@ TEST_CASE("PTransf16::rank_ref", "[PTransf16][006]") {
}

// TODO uncomment
// TEST_CASE("PTransf16::rank", "[PTransf16][007]") {
// REQUIRE(PTransf16({}).rank() == 16);
// REQUIRE(PTransf16({4, 4, 4, 4}).rank() == 12);
// REQUIRE(
// PTransf16({1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}).rank() ==
// 1);
// REQUIRE(
// PTransf16({2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}).rank() ==
// 1);
// REQUIRE(
// PTransf16({2, 2, 2, 0xf, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}).rank()
// == 2);
// REQUIRE(
// PTransf16({0, 2, 2, 0xf, 2, 2, 2, 2, 5, 2, 2, 2, 2, 2, 2, 2}).rank()
// == 4);
// }
TEST_CASE("PTransf16::rank", "[PTransf16][007]") {
REQUIRE(PTransf16({}).rank() == 16);
REQUIRE(PTransf16({4, 4, 4, 4}).rank() == 12);
REQUIRE(
PTransf16({1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}).rank() ==
1);
REQUIRE(
PTransf16({2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}).rank() ==
1);
REQUIRE(
PTransf16({2, 2, 2, 0xf, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}).rank()
== 2);
REQUIRE(
PTransf16({0, 2, 2, 0xf, 2, 2, 2, 2, 5, 2, 2, 2, 2, 2, 2, 2}).rank()
== 4);
}

TEST_CASE("PTransf16::fix_points_mask", "[PTransf16][008]") {
REQUIRE_THAT(PTransf16({}).fix_points_mask(), Equals(Epu8(FF)));
Expand Down Expand Up @@ -369,17 +363,15 @@ TEST_CASE("PPerm16::hash", "[PPerm16][018]") {
REQUIRE(std::hash<PPerm16>()(PPerm16::one()) != 0);
REQUIRE(std::hash<PPerm16>()(PPerm16({4, 5, 0}, {9, 0, 1})) != 0);
}
// TODO uncomment
// TEST_CASE_METHOD(Perm16Fixture, "PPerm16::left_one", "[PPerm16][019]") {
// REQUIRE(PPerm16({}).left_one() == PPerm16::one());
// REQUIRE(PPerm16({FF, FF, FF, 4}).left_one() ==
// PPerm16({FF, FF, FF, FF}));
// REQUIRE(PPerm16({FF, 4, FF, FF}).left_one() ==
// PPerm16({FF, FF, FF, FF}));
// for (auto pp : PPlist) {
// REQUIRE(pp.left_one() * pp == pp);
// }
// }

TEST_CASE_METHOD(Perm16Fixture, "PPerm16::left_one", "[PPerm16][019]") {
REQUIRE(PPerm16({}).left_one() == PPerm16::one());
REQUIRE(PPerm16({FF, FF, FF, 4}).left_one() == PPerm16({FF, FF, FF, FF}));
REQUIRE(PPerm16({FF, 4, FF, FF}).left_one() == PPerm16({FF, FF, FF, FF}));
for (auto pp : PPlist) {
REQUIRE(pp.left_one() * pp == pp);
}
}

TEST_CASE_METHOD(Perm16Fixture, "PPerm16::right_one", "[PPerm16][020]") {
REQUIRE(PPerm16({}).right_one() == PPerm16::one());
Expand Down Expand Up @@ -429,21 +421,27 @@ TEST_CASE_METHOD(Perm16Fixture, "Perm16::smallest_fix_point", "[Perm16][023]") {

TEST_CASE_METHOD(Perm16Fixture, "Perm16::smallest_moved_point",
"[Perm16][024]") {
REQUIRE(Perm16::one().smallest_moved_point() == FF);
REQUIRE(PPa.smallest_moved_point() == 0);
REQUIRE(PPb.smallest_moved_point() == 0);
REQUIRE(RandPerm.smallest_moved_point() == 0);
REQUIRE(Perm16({0, 1, 3, 2}).smallest_moved_point() == 2);
}

// TODO broken test
// TEST_CASE_METHOD(Perm16Fixture, "Perm16::largest_fix_point", "[Perm16][025]")
// {
// REQUIRE(Perm16::one().largest_fix_point() == 15);
// REQUIRE(PPa.largest_fix_point() == 15);
// REQUIRE(PPb.largest_fix_point() == 14);
// REQUIRE(RandPerm.largest_fix_point() == 1);
// }
CHECK(Perm16::one().smallest_moved_point() == int(FF));
CHECK(PPa.smallest_moved_point() == 0);
CHECK(PPb.smallest_moved_point() == 0);
CHECK(RandPerm.smallest_moved_point() == 0);
CHECK(Perm16({0, 1, 3, 2}).smallest_moved_point() == 2);
}

TEST_CASE_METHOD(Perm16Fixture, "Perm16::largest_fix_point", "[Perm16][025]") {
CHECK(Perm16::one().largest_fix_point() == 15);
CHECK(int(PPa.largest_fix_point()) == 15);
CHECK(PPb.largest_fix_point() == 14);
CHECK(RandPerm.largest_fix_point() == 1);
CHECK(PTransf16(Epu8({0, 2, 2, 0xf, 2, 2, 2, 2, 5, 2}, 2))
.largest_fix_point() == 2);
CHECK(PTransf16(Epu8({0, 2, 2, 0xf, 2, 2, 2, 2, 8, 2}, 10))
.largest_fix_point() == 10);
CHECK(PTransf16(Epu8({0, 2, 2, 0xf, 2, 2, 2, 2, 8, 2}, 14))
.largest_fix_point() == 14);
CHECK(PTransf16(Epu8({0, 2, 2, 0xf, 2, 2, 2, 2, 8, 2}, 15))
.largest_fix_point() == 15);
}

TEST_CASE_METHOD(Perm16Fixture, "Perm16::nb_fix_points", "[Perm16][026]") {
REQUIRE(Perm16::one().nb_fix_points() == 16);
Expand Down

0 comments on commit 95b1b63

Please sign in to comment.