Browse Source

perf: single space mover

master
Dnomd343 3 weeks ago
parent
commit
f2e16d0133
  1. 169
      src/core/mover/internal/s2_mover.cc
  2. 5
      src/core/mover/s2_mover.h

169
src/core/mover/internal/s2_mover.cc

@ -284,83 +284,98 @@ void S2Mover::two_space_b(uint64_t code, int offset) const {
} while (false);
}
void S2Mover::one_space(uint64_t code, int offset) const {
// ---------------- case up ----------------
do {
if (offset >= 4) {
/// 1x1
if (APPLY_MASK(code, offset - 4, 0b111) == 0b011) {
release_(SET_1x1(UNSET_1x1(code, offset - 4), offset));
break;
template <int N>
void S2Mover::one_space(uint64_t code) const {
if constexpr(N >= 4) { // case up
if (APPLY_MASK(code, N - 4, 0b111) == BLOCK_1x1) {
release_(SET_1x1(UNSET_1x1(code, N - 4), N));
} else if constexpr(N >= 8) {
if (APPLY_MASK(code, N - 8, 0b111) == BLOCK_2x1) {
release_(SET_2x1(UNSET_2x1(code, N - 8), N - 4));
}
}
}
if constexpr(N < 16) { // case down
const uint8_t block = APPLY_MASK(code, N + 4, 0b111);
if (block == BLOCK_1x1) {
release_(SET_1x1(UNSET_1x1(code, N + 4), N));
} else if constexpr(N < 12) {
if (block == BLOCK_2x1) {
release_(SET_2x1(UNSET_2x1(code, N + 4), N));
}
}
}
if constexpr(N % 4 != 0) { // case left
if (APPLY_MASK(code, N - 1, 0b111) == BLOCK_1x1) {
release_(SET_1x1(UNSET_1x1(code, N - 1), N));
} else if constexpr(N % 4 >= 2) {
if (APPLY_MASK(code, N - 2, 0b111) == BLOCK_1x2) {
release_(SET_1x2(UNSET_1x2(code, N - 2), N - 1));
}
}
}
if constexpr(N % 4 != 3) { // case right
const uint8_t block = APPLY_MASK(code, N + 1, 0b111);
if (block == BLOCK_1x1) {
release_(SET_1x1(UNSET_1x1(code, N + 1), N));
} else if constexpr(N % 4 <= 1) {
if (block == BLOCK_1x2) {
release_(SET_1x2(UNSET_1x2(code, N + 1), N));
}
}
}
}
void S2Mover::one_space_(uint64_t code, int offset) const {
switch (offset) {
// case 0: return one_space<0>(code);
// case 1: return one_space<1>(code);
// case 2: return one_space<2>(code);
// case 3: return one_space<3>(code);
// case 4: return one_space<4>(code);
// case 5: return one_space<5>(code);
// case 6: return one_space<6>(code);
// case 7: return one_space<7>(code);
// case 8: return one_space<8>(code);
// case 9: return one_space<9>(code);
// case 10: return one_space<10>(code);
// case 11: return one_space<11>(code);
// case 12: return one_space<12>(code);
// case 13: return one_space<13>(code);
// case 14: return one_space<14>(code);
// case 15: return one_space<15>(code);
// case 16: return one_space<16>(code);
// case 17: return one_space<17>(code);
// case 18: return one_space<18>(code);
// case 19: return one_space<19>(code);
case 0: one_space<0>(code); break;
case 1: one_space<1>(code); break;
case 2: one_space<2>(code); break;
case 3: one_space<3>(code); break;
case 4: one_space<4>(code); break;
case 5: one_space<5>(code); break;
case 6: one_space<6>(code); break;
case 7: one_space<7>(code); break;
case 8: one_space<8>(code); break;
case 9: one_space<9>(code); break;
case 10: one_space<10>(code); break;
case 11: one_space<11>(code); break;
case 12: one_space<12>(code); break;
case 13: one_space<13>(code); break;
case 14: one_space<14>(code); break;
case 15: one_space<15>(code); break;
case 16: one_space<16>(code); break;
case 17: one_space<17>(code); break;
case 18: one_space<18>(code); break;
case 19: one_space<19>(code); break;
default: std::unreachable();
}
}
if (offset >= 8) {
/// 2x1
if (APPLY_MASK(code, offset - 8, 0b111'000'000'000'111) == 0b111'000'000'000'010) {
release_(SET_2x1(UNSET_2x1(code, offset - 8), offset - 4));
break;
}
}
} while (false);
// ---------------- case down ----------------
do {
if (offset < 16) {
/// 1x1
if (APPLY_MASK(code, offset + 4, 0b111) == 0b011) {
release_(SET_1x1(UNSET_1x1(code, offset + 4), offset));
break;
}
}
if (offset < 12) {
/// 2x1
if (APPLY_MASK(code, offset + 4, 0b111'000'000'000'111) == 0b111'000'000'000'010) {
release_(SET_2x1(UNSET_2x1(code, offset + 4), offset));
break;
}
}
} while (false);
// ---------------- case left ----------------
do {
if ((offset % 4) != 0) {
/// 1x1
if (APPLY_MASK(code, offset - 1, 0b111) == 0b011) {
release_(SET_1x1(UNSET_1x1(code, offset - 1), offset));
break;
}
}
if ((offset % 4) >= 2) {
/// 1x2
if (APPLY_MASK(code, offset - 2, 0b111'111) == 0b111'001) {
release_(SET_1x2(UNSET_1x2(code, offset - 2), offset - 1));
break;
}
}
} while (false);
// ---------------- case right ----------------
do {
if ((offset % 4) != 3) {
/// 1x1
if (APPLY_MASK(code, offset + 1, 0b111) == 0b011) {
release_(SET_1x1(UNSET_1x1(code, offset + 1), offset));
break;
}
}
if ((offset % 4) <= 1) {
/// 1x2
if (APPLY_MASK(code, offset + 1, 0b111'111) == 0b111'001) {
release_(SET_1x2(UNSET_1x2(code, offset + 1), offset));
break;
}
}
} while (false);
}
void S2Mover::next_cases(uint64_t code) {
// std::cout << RawCode::unsafe_create(code) << std::endl;
@ -402,7 +417,7 @@ void S2Mover::next_cases(uint64_t code) {
} else if (space_1 + 4 == space_2) {
two_space_b(code, space_1);
} else {
one_space(code, space_1);
one_space(code, space_2);
one_space_(code, space_1);
one_space_(code, space_2);
}
}

5
src/core/mover/s2_mover.h

@ -18,7 +18,10 @@ private:
void two_space_a(uint64_t code, int offset) const;
void two_space_b(uint64_t code, int offset) const;
void one_space(uint64_t code, int offset) const;
void one_space_(uint64_t code, int offset) const;
template <int N>
void one_space(uint64_t code) const;
};
} // namespace klotski::mover

Loading…
Cancel
Save