Browse Source

perf: basic trait of core module

master
Dnomd343 2 years ago
parent
commit
2f14e32517
  1. 31
      src/core/core.cc
  2. 28
      src/core/core.h
  3. 4
      src/main.cc

31
src/core/core.cc

@ -129,36 +129,33 @@ 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) {
auto temp_code = raw_code;
// uint64_t raw_code = _code;
for (int addr = 0; temp_code; addr += 3, temp_code >>= 3) {
switch (temp_code & 0b111) {
auto code = raw_code;
for (int addr = 0; code; addr += 3, code >>= 3) { // traverse every 3-bits
switch (code & 0b111) { // match low 3-bits
case B_1x1:
move_1x1(raw_code, addr);
move_1x1(raw_code, addr); // try to move 1x1 block
break;
case B_1x2:
move_1x2(raw_code, addr);
move_1x2(raw_code, addr); // try to move 1x2 block
break;
case B_2x1:
move_2x1(raw_code, addr);
move_2x1(raw_code, addr); // try to move 2x1 block
break;
case B_2x2:
move_2x2(raw_code, addr);
move_2x2(raw_code, addr); // try to move 2x2 block
break;
default:
continue; // B_space or B_fill
}
if (cache_size != 1) {
if (cache_size != 1) { // found one or more next cases
for (int i = 1; i < cache_size; ++i) {
// std::cout << RawCode(cache[i].code).dump_case();
// printf("(%016lX)\n\n", cache[i].mask);
// TODO: release next cases (code and mask)
std::cout << RawCode(cache[i].code).dump_case();
printf("(%016lX)\n\n", cache[i].mask);
}
// std::cout << "found: " << cache_size - 1 << std::endl;
}
}
}

28
src/core/core.h

@ -19,36 +19,22 @@
class Core {
public:
void next_step(uint64_t raw_code);
private:
struct cache_t {
uint64_t code; // raw code
uint64_t code; // case raw code
uint64_t mask; // only 000 or 111
int filter;
int addr;
int filter; // UP | DOWN | LEFT | RIGHT
int addr; // (0 ~ 19) * 3
};
int cache_size;
cache_t cache[16];
inline void cache_insert(Core::cache_t &next_case);
void move_1x1(uint64_t code, int addr);
void move_1x2(uint64_t code, int addr);
void move_2x1(uint64_t code, int addr);
void move_2x2(uint64_t code, int addr);
// void move_1x1(int addr);
// void move_1x2(int addr);
// void move_2x1(int addr);
// void move_2x2(int addr);
void next_step(uint64_t raw_code);
// void next_step();
// uint64_t _code;
// Core(uint64_t raw_code) : _code(raw_code) {}
inline void cache_insert(Core::cache_t &next_case);
};

4
src/main.cc

@ -148,9 +148,9 @@ int main() {
auto c = Core();
// auto c = Core(raw_code);
for (int i = 0; i < 100000000; ++i) {
// for (int i = 0; i < 100000000; ++i) {
c.next_step(raw_code);
}
// }
return 0;
}

Loading…
Cancel
Save