Browse Source

feat: benchmark for moving 1x1 block

legacy
Dnomd343 2 years ago
parent
commit
3cd6a5e9bc
  1. 82
      src/core_demo.cc
  2. 14
      src/core_demo.h
  3. 4
      src/main.cc

82
src/core_demo.cc

@ -1,9 +1,87 @@
#include <iostream> #include <iostream>
#include "raw_code.h" #include "raw_code.h"
#include "core_demo.h"
cache_t cache[16];
// TODO: use cache_t *move_cache_top?
int cache_size;
inline bool cache_insert(uint64_t code) {
// std::cout << "cache insert" << std::endl;
auto *p = cache;
for (; p < cache + cache_size; ++p) {
if (*p == code) {
return false; // already exist -> insert failed
}
}
*p = code;
// p->code = code;
// p->filter = filter;
++cache_size;
return true;
}
/// input -> raw_code / block address
void move_1x1(uint64_t code, int addr) {
// std::cout << "enter move_1x1 at " << addr << std::endl;
int target_addr;
uint64_t ret_code;
/// try to move up
if (addr >= 4 * 3 && !(code >> (target_addr = addr + UP) & F_1x1)) {
ret_code = code & ~(F_1x1 << addr) | C_1x1 << target_addr;
if (cache_insert(ret_code)) {
move_1x1(ret_code, target_addr);
}
}
/// try to move down
if (addr <= 15 * 3 && !(code >> (target_addr = addr + DOWN) & F_1x1)) {
ret_code = code & ~(F_1x1 << addr) | C_1x1 << target_addr;
if (cache_insert(ret_code)) {
move_1x1(ret_code, target_addr);
}
}
/// try to move left
if ((addr & 0b11) != 0 && !(code >> (target_addr = addr + LEFT) & F_1x1)) {
ret_code = code & ~(F_1x1 << addr) | C_1x1 << target_addr;
if (cache_insert(ret_code)) {
move_1x1(ret_code, target_addr);
}
}
/// try to move right
if ((addr & 0x3) != 1 && !(code >> (target_addr = addr + RIGHT) & F_1x1)) {
ret_code = code & ~(F_1x1 << addr) | C_1x1 << target_addr;
if (cache_insert(ret_code)) {
move_1x1(ret_code, target_addr);
}
}
}
void next_step(uint64_t raw_code, uint64_t mask) { void next_step(uint64_t raw_code, uint64_t mask) {
std::cout << RawCode(raw_code).dump_case(); // std::cout << RawCode(raw_code).dump_case();
printf("mask -> %016lX\n", mask); // printf("mask -> %016lX\n", mask);
// case 1 -> 8.8s
for (int i = 0; i < 1000000000; ++i) {
cache_size = 1;
cache[0] = raw_code;
move_1x1(raw_code, 17 * 3);
}
// std::cout << cache_size << std::endl;
//
// std::cout << RawCode(cache[0]).dump_case() << std::endl;
// std::cout << RawCode(cache[1]).dump_case() << std::endl;
// std::cout << RawCode(cache[2]).dump_case() << std::endl;
} }

14
src/core_demo.h

@ -2,4 +2,18 @@
#include <cstdint> #include <cstdint>
#define UP (-12) // -4 * 3-bits
#define LEFT (-3) // +1 * 3-bits
#define DOWN (+12) // +4 * 3-bits
#define DOWN_2 (+24) // +8 * 3-bits
#define RIGHT (+3) // +1 * 3-bits
#define RIGHT_2 (+6) // +2 * 3-bits
//struct cache_t {
// uint64_t code; // raw code
// uint64_t mask; // only 000 or 111
//};
typedef uint64_t cache_t;
void next_step(uint64_t raw_code, uint64_t mask); void next_step(uint64_t raw_code, uint64_t mask);

4
src/main.cc

@ -139,10 +139,10 @@ int main() {
// auto r = RawCode(0x0E58FC85FFEBC4DD); // invalid raw code -> only for test // auto r = RawCode(0x0E58FC85FFEBC4DD); // invalid raw code -> only for test
// std::cout << r.dump_case() << std::endl; // std::cout << r.dump_case() << std::endl;
// std::cout << CommonCode(RawCode(0x0E58FC85FFEBC4DB)).to_string() << std::endl;
next_step(0x0E58FC85FFEBC4DB, 0); // mask unset
std::cout << CommonCode(RawCode(0x0E58FC85FFEBC4DB)).to_string() << std::endl; next_step(CommonCode("4FEA134").to_raw_code().unwrap(), 0); // mask unset
return 0; return 0;
} }

Loading…
Cancel
Save