|
@ -12,26 +12,22 @@ |
|
|
cache_insert(next_case); \ |
|
|
cache_insert(next_case); \ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
cache_t cache[16]; |
|
|
|
|
|
|
|
|
|
|
|
/// why is it slower to use pointer?
|
|
|
|
|
|
//cache_t *cache_top;
|
|
|
|
|
|
|
|
|
|
|
|
int cache_size; |
|
|
int cache_size; |
|
|
|
|
|
cache_t cache[16]; |
|
|
|
|
|
|
|
|
inline bool cache_insert(cache_t &new_item) { |
|
|
inline bool cache_insert(cache_t &new_item) { |
|
|
|
|
|
|
|
|
// auto *p = cache;
|
|
|
// TODO: try closed hashing
|
|
|
// for (; p < cache_top; ++p) {
|
|
|
// auto volatile hash = new_item.code;
|
|
|
// if (p->code == new_item.code) {
|
|
|
// printf("%016lX -> ", hash); // 64-bits
|
|
|
// return false; // already exist -> insert failed
|
|
|
// hash ^= hash >> 32;
|
|
|
// }
|
|
|
// printf("%08lX -> ", hash & 0xFFFFFFFF); // 32-bits
|
|
|
// }
|
|
|
// hash ^= hash >> 16;
|
|
|
//
|
|
|
// printf("%04lX -> ", hash & 0xFFFF); // 16-bits
|
|
|
// *p = new_item;
|
|
|
// hash ^= hash >> 8;
|
|
|
// ++cache_top;
|
|
|
// printf("%02lX -> ", hash & 0xFF); // 8-bits
|
|
|
// return true;
|
|
|
// hash ^= hash >> 4;
|
|
|
|
|
|
// printf("%01lX\n", hash & 0xF); // 4-bits
|
|
|
|
|
|
|
|
|
auto *p = cache; |
|
|
auto *p = cache; |
|
|
for (; p < cache + cache_size; ++p) { |
|
|
for (; p < cache + cache_size; ++p) { |
|
@ -39,7 +35,6 @@ inline bool cache_insert(cache_t &new_item) { |
|
|
return false; // already exist -> insert failed
|
|
|
return false; // already exist -> insert failed
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
*p = new_item; |
|
|
*p = new_item; |
|
|
++cache_size; |
|
|
++cache_size; |
|
|
return true; |
|
|
return true; |
|
@ -47,25 +42,17 @@ inline bool cache_insert(cache_t &new_item) { |
|
|
|
|
|
|
|
|
void move_1x1(uint64_t code, int addr) { |
|
|
void move_1x1(uint64_t code, int addr) { |
|
|
cache_size = 1; |
|
|
cache_size = 1; |
|
|
// cache_top = cache + 1;
|
|
|
|
|
|
cache[0].code = code; // load into queue
|
|
|
cache[0].code = code; // load into queue
|
|
|
cache[0].addr = addr; |
|
|
cache[0].addr = addr; |
|
|
cache[0].filter = 0; // filter unset
|
|
|
cache[0].filter = 0; // filter unset
|
|
|
|
|
|
|
|
|
int count = 0; |
|
|
int current = 0; |
|
|
// cache_t *current = cache;
|
|
|
|
|
|
|
|
|
|
|
|
while (count != cache_size) { // start bfs search
|
|
|
|
|
|
// while (current != cache_top) { // start bfs search
|
|
|
|
|
|
|
|
|
|
|
|
code = cache[count].code; |
|
|
while (current != cache_size) { // start bfs search
|
|
|
addr = cache[count].addr; |
|
|
code = cache[current].code; |
|
|
// code = current->code;
|
|
|
addr = cache[current].addr; |
|
|
// addr = current->addr;
|
|
|
|
|
|
int next_addr; // address after block moved
|
|
|
int next_addr; // address after block moved
|
|
|
int filter = cache[count++].filter; // case filter
|
|
|
int filter = cache[current++].filter; // case filter
|
|
|
// int filter = current->filter; // case filter
|
|
|
|
|
|
// ++current;
|
|
|
|
|
|
|
|
|
|
|
|
if (filter != UP && addr >= 4 * 3 && !(code >> (next_addr = addr + UP) & F_1x1)) { |
|
|
if (filter != UP && addr >= 4 * 3 && !(code >> (next_addr = addr + UP) & F_1x1)) { |
|
|
release_1x1(-UP); // block can move up
|
|
|
release_1x1(-UP); // block can move up
|
|
@ -93,7 +80,6 @@ void next_step(uint64_t raw_code, uint64_t mask) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::cout << cache_size << std::endl; |
|
|
std::cout << cache_size << std::endl; |
|
|
// std::cout << (cache_top - cache) << std::endl;
|
|
|
|
|
|
std::cout << RawCode(cache[0].code).dump_case() << std::endl; |
|
|
std::cout << RawCode(cache[0].code).dump_case() << std::endl; |
|
|
std::cout << RawCode(cache[1].code).dump_case() << std::endl; |
|
|
std::cout << RawCode(cache[1].code).dump_case() << std::endl; |
|
|
std::cout << RawCode(cache[2].code).dump_case() << std::endl; |
|
|
std::cout << RawCode(cache[2].code).dump_case() << std::endl; |
|
|