Browse Source

feat: release function pointer

master
Dnomd343 2 years ago
parent
commit
1b4f543aaa
  1. 25
      src/core/core.cc
  2. 2
      src/core/core.h
  3. 51
      src/main.cc

25
src/core/core.cc

@ -126,12 +126,7 @@ void Core::move_2x2(uint64_t code, int addr) { // try to move target 2x2 block
} }
} }
#include <iostream> void Core::next_step(uint64_t raw_code, void (*release)(uint64_t, uint64_t)) { // search next step cases
uint32_t Core::next_step(uint64_t raw_code) {
uint32_t sum = 0;
auto code = raw_code; auto code = raw_code;
for (int addr = 0; code; addr += 3, code >>= 3) { // traverse every 3-bits for (int addr = 0; code; addr += 3, code >>= 3) { // traverse every 3-bits
switch (code & 0b111) { // match low 3-bits switch (code & 0b111) { // match low 3-bits
@ -153,24 +148,10 @@ uint32_t Core::next_step(uint64_t raw_code) {
if (cache_size != 1) { // found one or more next cases if (cache_size != 1) { // found one or more next cases
for (int i = 1; i < cache_size; ++i) { for (int i = 1; i < cache_size; ++i) {
// TODO: release next cases (code and mask) // TODO: try to send multi-items data
release(cache[i].code, cache[i].mask); // release next cases
// std::cout << RawCode(cache[i].code).dump_case();
// std::cout << "~~~~~~~" << std::endl;
// auto mask = cache[i].mask;
// for (int n = 0; n < 20; ++n, mask >>= 3) {
// std::cout << "+."[!(mask & 0b111)] << " \n"[!(~n & 0b11)];
// }
// std::cout << std::endl;
} }
sum += cache_size - 1;
} }
} }
// std::cout << "sum = " << sum << std::endl;
return sum;
} }

2
src/core/core.h

@ -20,7 +20,7 @@
class Core { class Core {
public: public:
// void next_step(uint64_t raw_code); // void next_step(uint64_t raw_code);
uint32_t next_step(uint64_t raw_code); void next_step(uint64_t raw_code, void (*release)(uint64_t code, uint64_t mask));
private: private:
struct cache_t { struct cache_t {

51
src/main.cc

@ -37,6 +37,15 @@
// } // }
//} //}
void release(uint64_t code, uint64_t mask) {
std::cout << RawCode(code).dump_case();
std::cout << "~~~~~~~" << std::endl;
for (int n = 0; n < 20; ++n, mask >>= 3) {
std::cout << "+."[!(mask & 0b111)] << " \n"[!(~n & 0b11)];
}
std::cout << std::endl;
}
int main() { int main() {
// printf("%p\n", BasicRanges::build); // printf("%p\n", BasicRanges::build);
@ -146,15 +155,19 @@ int main() {
auto c = Core(); auto c = Core();
std::vector<uint64_t> all_cases_raw; // auto raw_code = RawCode(CommonCode("4fea134")).unwrap();
for (int head = 0; head < 16; ++head) { auto raw_code = RawCode(CommonCode("1A9bf0c")).unwrap();
uint64_t prefix = (uint64_t)head << 32; c.next_step(raw_code, release);
for (auto const &range : (*AllCases::fetch())[head]) {
all_cases_raw.emplace_back( // std::vector<uint64_t> all_cases_raw;
RawCode(CommonCode::unsafe_create(prefix | range)).unwrap() // for (int head = 0; head < 16; ++head) {
); // uint64_t prefix = (uint64_t)head << 32;
} // for (auto const &range : (*AllCases::fetch())[head]) {
} // all_cases_raw.emplace_back(
// RawCode(CommonCode::unsafe_create(prefix | range)).unwrap()
// );
// }
// }
// std::cout << "start benchmark" << std::endl; // std::cout << "start benchmark" << std::endl;
// auto start_time = clock(); // auto start_time = clock();
@ -164,20 +177,20 @@ int main() {
// c.next_step(raw_code); // c.next_step(raw_code);
// } // }
std::vector<uint32_t> steps; // std::vector<uint32_t> steps;
for (auto const &raw_code : all_cases_raw) { // for (auto const &raw_code : all_cases_raw) {
steps.emplace_back(c.next_step(raw_code)); // steps.emplace_back(c.next_step(raw_code));
} // }
// std::sort(steps.begin(), steps.end()); // std::sort(steps.begin(), steps.end());
// std::cout << steps[0] << std::endl; // std::cout << steps[0] << std::endl;
// std::cout << steps[steps.size() - 1] << std::endl; // std::cout << steps[steps.size() - 1] << std::endl;
for (int i = 0; i < all_cases_raw.size(); ++i) { // for (int i = 0; i < all_cases_raw.size(); ++i) {
// if (steps[i] == 0) { // if (steps[i] == 0) {
if (steps[i] == 68) { // max next steps // if (steps[i] == 68) { // max next steps
std::cout << RawCode(all_cases_raw[i]).dump_case(); // std::cout << RawCode(all_cases_raw[i]).dump_case();
std::cout << CommonCode(RawCode(all_cases_raw[i])).to_string() << std::endl << std::endl; // std::cout << CommonCode(RawCode(all_cases_raw[i])).to_string() << std::endl << std::endl;
} // }
} // }
// std::cout << (clock() - start_time) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl; // std::cout << (clock() - start_time) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl;
// std::cout << "complete benchmark" << std::endl; // std::cout << "complete benchmark" << std::endl;

Loading…
Cancel
Save