diff --git a/.r8forge_cache/1a6abdeead659b5f.txt b/.r8forge_cache/1a6abdeead659b5f.txt new file mode 100644 index 0000000..a2115a6 --- /dev/null +++ b/.r8forge_cache/1a6abdeead659b5f.txt @@ -0,0 +1,6 @@ +# params 4 mode 0 metric 1 +2 9 0 +0 6 0 +1 9 0 +3 4 1 +0 12 0 diff --git a/asm/raw_add_nc4.r8asm b/asm/raw_add_nc4.r8asm new file mode 100644 index 0000000..60eedef --- /dev/null +++ b/asm/raw_add_nc4.r8asm @@ -0,0 +1,19 @@ +%include "asm/lib.r8asm" + +; 4 个 cell 的忽略进位加法切片:连 tmp 都不要了,进位就借用 tmp 的位置。 +; +; p1..p4 = A, B, 进位(进->出), S +; +; 目标:S = A^B^Ci,进位 = AB|AC|BC,A、B 结束为 0。 +; 每个输入组合后的值只落在「进位」和 S 这两位,所以表里只出现 0/4/8/12。 +%synth bit_add_nc4_synth + params 4 + stat 0 8 8 4 8 4 4 12 0 8 8 4 8 4 4 12 + metric flat +%endsynth + +%macro bit_add_nc4 4 + .tp %4 + set_0 + bit_add_nc4_synth %1 %2 %3 %4 +%endmacro diff --git a/src/derive.cc b/src/derive.cc index 77b21a3..b77de05 100644 --- a/src/derive.cc +++ b/src/derive.cc @@ -94,6 +94,36 @@ int main(int argc, char **argv) { std::cout << "\n"; return 0; } + // params == -2: same as -1 but dumps every non zero cell afterwards + if (params == -2) { + r8asm a; + if (!a.import_file(file, 8)) { + std::cerr << "could not assemble " << file << "\n"; + return 1; + } + machine m; + for (int i = 3; i < argc; i++) { + const char *eq = std::strchr(argv[i], '='); + if (eq == nullptr) { + continue; + } + const int at = std::atoi(std::string(argv[i], size_t(eq - argv[i])).c_str()); + m.cells[size_t(at)] = uint8_t(std::atoi(eq + 1) & 0xff); + } + m.run(a.export_rot8()); + std::cout << "out"; + for (uint8_t v : m.out) { + std::cout << " " << int(v); + } + std::cout << "\ncells"; + for (size_t i = 0; i < m.cells.size(); i++) { + if (m.cells[i] != 0) { + std::cout << " " << i << "=" << std::hex << int(m.cells[i]) << std::dec; + } + } + std::cout << "\n"; + return 0; + } // params == -1: the rest of argv is addr=value; set those cells, run, dump OUT if (params == -1) { r8asm a;