From 84e54dfe95d738bb412994eb427719994f4533fe Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Tue, 10 Jan 2023 16:00:10 +0800 Subject: [PATCH] update: lambda or inline function will loss speed --- src/core_demo.cc | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/src/core_demo.cc b/src/core_demo.cc index 589c252..3ea34fd 100644 --- a/src/core_demo.cc +++ b/src/core_demo.cc @@ -22,6 +22,16 @@ inline bool cache_insert(cache_t &new_item) { return true; } +//inline void demo(uint64_t code, int addr, int next_addr, int f) { +// cache_t next_case = { +// .code = code & ~(F_1x1 << addr) | (C_1x1 << next_addr), +// .mask = (uint64_t)0b111 << next_addr, +// .filter = f, +// .addr = next_addr +// }; +// cache_insert(next_case); +//} + void move_1x1_demo(uint64_t code, int addr) { cache_size = 1; @@ -31,22 +41,29 @@ void move_1x1_demo(uint64_t code, int addr) { int count = 0; + int next_addr; + +// auto demo = [&](int f) { +// cache_t next_case = { +// .code = code & ~(F_1x1 << addr) | (C_1x1 << next_addr), +// .mask = (uint64_t)0b111 << next_addr, +// .filter = f, +// .addr = next_addr +// }; +// cache_insert(next_case); +// }; + while (count != cache_size) { code = cache[count].code; addr = cache[count].addr; - int filter = cache[count].filter; ++count; - uint64_t ret_code; - - int next_addr; /// try to move up if (filter != UP && addr >= 4 * 3 && !(code >> (next_addr = addr + UP) & F_1x1)) { -// ret_code = code & ~(F_1x1 << addr) | (C_1x1 << next_addr); cache_t next_case = { .code = code & ~(F_1x1 << addr) | (C_1x1 << next_addr), .mask = (uint64_t)0b111 << next_addr, @@ -54,12 +71,12 @@ void move_1x1_demo(uint64_t code, int addr) { .addr = next_addr }; cache_insert(next_case); - +// demo(DOWN); +// demo(code, addr, next_addr, DOWN); } /// try to move down if (filter != DOWN && addr <= 15 * 3 && !(code >> (next_addr = addr + DOWN) & F_1x1)) { -// ret_code = code & ~(F_1x1 << addr) | (C_1x1 << next_addr); cache_t next_case = { .code = code & ~(F_1x1 << addr) | (C_1x1 << next_addr), .mask = (uint64_t)0b111 << next_addr, @@ -67,12 +84,12 @@ void move_1x1_demo(uint64_t code, int addr) { .addr = next_addr }; cache_insert(next_case); - +// demo(UP); +// demo(code, addr, next_addr, UP); } /// try to move left - if (filter != LEFT && (addr & 0b11) != 0 && !(code >> (next_addr = addr + LEFT) & F_1x1)) { - ret_code = code & ~(F_1x1 << addr) | (C_1x1 << next_addr); + if (filter != LEFT && (addr & 3) != 0 && !(code >> (next_addr = addr + LEFT) & F_1x1)) { cache_t next_case = { .code = code & ~(F_1x1 << addr) | (C_1x1 << next_addr), .mask = (uint64_t)0b111 << next_addr, @@ -80,12 +97,12 @@ void move_1x1_demo(uint64_t code, int addr) { .addr = next_addr }; cache_insert(next_case); - +// demo(RIGHT); +// demo(code, addr, next_addr, RIGHT); } /// try to move right - if (filter != RIGHT && (addr & 0x3) != 1 && !(code >> (next_addr = addr + RIGHT) & F_1x1)) { -// ret_code = code & ~(F_1x1 << addr) | (C_1x1 << next_addr); + if (filter != RIGHT && (addr & 3) != 1 && !(code >> (next_addr = addr + RIGHT) & F_1x1)) { cache_t next_case = { .code = code & ~(F_1x1 << addr) | (C_1x1 << next_addr), .mask = (uint64_t)0b111 << next_addr, @@ -93,9 +110,9 @@ void move_1x1_demo(uint64_t code, int addr) { .addr = next_addr }; cache_insert(next_case); - +// demo(LEFT); +// demo(code, addr, next_addr, LEFT); } - }