From 7837c5f4dfe6606d14db8586b9da640836238f71 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Wed, 11 Jan 2023 02:43:40 +0800 Subject: [PATCH] feat: next_step statistics for all cases --- src/core/core.cc | 12 +++++++++++- src/core/core.h | 3 ++- src/main.cc | 29 ++++++++++++++++++++--------- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/core/core.cc b/src/core/core.cc index 7d13ff2..4c8b5d4 100644 --- a/src/core/core.cc +++ b/src/core/core.cc @@ -128,7 +128,10 @@ void Core::move_2x2(uint64_t code, int addr) { // try to move target 2x2 block #include -void Core::next_step(uint64_t raw_code) { +uint32_t Core::next_step(uint64_t raw_code) { + + uint32_t sum = 0; + auto code = raw_code; for (int addr = 0; code; addr += 3, code >>= 3) { // traverse every 3-bits switch (code & 0b111) { // match low 3-bits @@ -161,6 +164,13 @@ void Core::next_step(uint64_t raw_code) { // std::cout << std::endl; } + + sum += cache_size - 1; + } } + +// std::cout << "sum = " << sum << std::endl; + return sum; + } diff --git a/src/core/core.h b/src/core/core.h index a94b959..afb8545 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -19,7 +19,8 @@ class Core { public: - void next_step(uint64_t raw_code); +// void next_step(uint64_t raw_code); + uint32_t next_step(uint64_t raw_code); private: struct cache_t { diff --git a/src/main.cc b/src/main.cc index e8db63a..d7d5851 100644 --- a/src/main.cc +++ b/src/main.cc @@ -9,6 +9,7 @@ //#include "core_demo.h" #include +#include //void get_status() { // switch (BasicRanges::status()) { @@ -143,9 +144,7 @@ int main() { // std::cout << CommonCode(RawCode(0x0E58FC85FFEBC4DB)).to_string() << std::endl; -// next_step(CommonCode("4FEA134").to_raw_code().unwrap(), 0); // mask unset - -// auto raw_code = RawCode(CommonCode("4fea134")).unwrap(); + auto c = Core(); std::vector all_cases_raw; for (int head = 0; head < 16; ++head) { @@ -157,19 +156,31 @@ int main() { } } - std::cout << "start benchmark" << std::endl; - auto start_time = clock(); +// std::cout << "start benchmark" << std::endl; +// auto start_time = clock(); - auto c = Core(); +// auto raw_code = RawCode(CommonCode("4fea134")).unwrap(); // for (int i = 0; i < 100000000; ++i) { // c.next_step(raw_code); // } + + std::vector steps; for (auto const &raw_code : all_cases_raw) { - c.next_step(raw_code); + steps.emplace_back(c.next_step(raw_code)); + } +// std::sort(steps.begin(), steps.end()); +// std::cout << steps[0] << std::endl; +// std::cout << steps[steps.size() - 1] << std::endl; + for (int i = 0; i < all_cases_raw.size(); ++i) { +// if (steps[i] == 0) { + if (steps[i] == 68) { // max next steps + 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 << (clock() - start_time) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl; - std::cout << "complete benchmark" << std::endl; +// std::cout << (clock() - start_time) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl; +// std::cout << "complete benchmark" << std::endl; return 0; }