From 8c969a38be527f433fb2d903ddc0a0e9e24ef5e9 Mon Sep 17 00:00:00 2001 From: StarCells Date: Fri, 6 Nov 2026 23:09:45 +0800 Subject: [PATCH] Three cells for the destructive slice: tried, impossible here Writing the sum back into A's cell would drop the separate S cells and cost no extra instructions -- the driver would even get simpler. So it was worth trying, and it does not work: %synth reports no program up to 5 layers and raising the layer bound to 8 does not help either: no program up to 8 layers So the obstacle is not runtime cost, it is feasibility: three cells cannot do ' two inputs plus a carry in -> a sum plus a new carry' in this instruction model, the same class of limit that stopped clb_bit_and. Keeping the four cell slice (and the 25 cell bit-per-cell adder) is the right call, and the file is committed with that conclusion written into it so nobody retries it blind. The layer bound is now 8 rather than 5 (src/synth.cc), since 5 was low enough to call some feasible tables impossible; a feasible table still costs the same, only a hopeless search takes 60% longer before giving up. Cache untouched: restored from git after the experiments, asm/test.r8asm still assembles from it in a fraction of a second, 7/7 hits, 1666 characters. --- asm/raw_add_nc3.r8asm | 36 ++++++++++++++++++++++++++++++++++++ src/synth.cc | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 asm/raw_add_nc3.r8asm diff --git a/asm/raw_add_nc3.r8asm b/asm/raw_add_nc3.r8asm new file mode 100644 index 0000000..d6c75f0 --- /dev/null +++ b/asm/raw_add_nc3.r8asm @@ -0,0 +1,36 @@ +%include "asm/lib.r8asm" + +; 破坏性切片:和写回 a 自己的格子,所以只要 3 个 cell。 +; p1..p3 = a(变成和), b(用完清 0), 进位(进->出) +; +; 目标:sum = a^b^Ci 写进 a,进位 = ab|aCi|bCi,a 里原来的值不留; +; b 结束为 0。表按定义逐项算: +; (a,b,Ci) = (0,0,0)->0 (1,0,0)->1 (0,1,0)->1 (1,1,0)->4 +; (0,0,1)->1 (1,0,1)->4 (0,1,1)->4 (1,1,1)->5 +%synth bit_add_nc3_synth + params 3 + stat 0 1 1 4 1 4 4 5 + metric flat +%endsynth + +%macro bit_add_nc3 3 + bit_add_nc3_synth %1 %2 %3 +%endmacro + +; 8 位破坏性加法:只传三个基址 +; %1 = A 基址(A 被结果覆盖),%2 = B 基址(保留,B 的位会被清),%3 = 进位 +; 最高位的进位丢掉,前提是 A+B <= 255。 +%macro raw_add_nc3_bits8 3 +.anchor before_raw_add_nc3_bits8 + erase %3 + + bit_add_nc3 %1 %2 %3 + bit_add_nc3 %1 + 1 %2 + 1 %3 + bit_add_nc3 %1 + 2 %2 + 2 %3 + bit_add_nc3 %1 + 3 %2 + 3 %3 + bit_add_nc3 %1 + 4 %2 + 4 %3 + bit_add_nc3 %1 + 5 %2 + 5 %3 + bit_add_nc3 %1 + 6 %2 + 6 %3 + bit_add_nc3 %1 + 7 %2 + 7 %3 + .tp before_raw_add_nc3_bits8 +%endmacro diff --git a/src/synth.cc b/src/synth.cc index 20040b1..efcefff 100644 --- a/src/synth.cc +++ b/src/synth.cc @@ -120,7 +120,7 @@ r8asm_synth_run(const std::vector &in, const std::vector &out, // 1) fewest layers -- cheap, and its tape length gives the cost search a // bound to work under typename V::options opt; - opt.max_depth = 5; + opt.max_depth = 8; const auto layers = v.solve(tt, opt); std::vector> out_ins; if (!layers.found) {