- tools/stdmac_matrix.py: raw_add/and/or/xor/inc 全量对拍(真链路:probe_dump 汇编 -> ROT-8 VM -> 读 out) - tools/stdmac_xor_fix_probe.py + tests/xor_fix_probe.r8asm.frag: 候选体 = OR 体删末块 %3 set_1,121/121 通过 - tools/stdmac_inc_fix_probe.py + tests/inc_fix_probe.r8asm.frag: 最小修法 = 对调 bit_raw_inc 第 3/4 实参,22/22 + 链式通过 - tools/stdmac_preserve.py: 五个 raw_ 宏均保留输入(A/B/Ci) - tests/probe_dump.cc: 任意 .r8asm -> tape 的驱动(须在 r8asm_rev 根目录跑,include 是相对 cwd)
44 lines
1.9 KiB
Python
44 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
"""stdmac_inc_fix_probe.py — 验证 raw_inc 的接线假设(测试侧重写 glue,不动核心仓)。
|
|
|
|
若修正版通过全表 + 链式用例,则结论钉死:bit_raw_inc 体内 %3=Cout / %4=Sum(与注释相反),
|
|
当前 raw_inc 把 S/Co 实参按注释顺序传,导致输出接反且进位链喂 Sum。
|
|
"""
|
|
import itertools
|
|
import os
|
|
import sys
|
|
|
|
HERE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
sys.path.insert(0, os.path.join(HERE, "tools"))
|
|
from stdmac_matrix import PRELUDE, build_tools, run_case, set_cell # noqa: E402
|
|
|
|
build_tools()
|
|
FRAG = open(os.path.join(HERE, "tests", "inc_fix_probe.r8asm.frag")).read()
|
|
|
|
VALS = [0, 1, 2, 3, 5, 126, 127, 128, 170, 254, 255]
|
|
|
|
for variant, call in (("原样 raw_inc", "raw_inc A Ci S Co tmp"),
|
|
("修正 raw_inc_fix", "raw_inc_fix A Ci S Co tmp")):
|
|
bad = []
|
|
for a, cin in itertools.product(VALS, [0, 1]):
|
|
src = PRELUDE + FRAG + set_cell("A", a) + set_cell("Ci", cin)
|
|
src += "%s\noutput A\noutput Ci\noutput S\noutput Co\n" % call
|
|
got = run_case(src)
|
|
want = [a, cin, (a + cin) & 0xFF, (a + cin) >> 8]
|
|
if got != want:
|
|
bad.append((a, cin, want, got))
|
|
print("%-18s 失败 %2d / %d 例" % (variant, len(bad), len(VALS) * 2))
|
|
for a, cin, want, got in bad[:4]:
|
|
print(" A=%-4d Ci=%d want=%s got=%s" % (a, cin, want, got))
|
|
|
|
print("\n=== 链式:修正版连续自增(输出用独立 cell D,避免 A/S 混叠) ===")
|
|
for a in (126, 254):
|
|
want = [a + 1, 0, (a + 2) & 0xFF, (a + 2) >> 8]
|
|
src = PRELUDE + FRAG + set_cell("A", a) + set_cell("Ci", 1)
|
|
src += ".var D 10\n.tp D\n.xor 0\n"
|
|
src += "raw_inc_fix A Ci S Co tmp\noutput S\noutput Co\n"
|
|
src += "raw_inc_fix S Ci D Co tmp\noutput D\noutput Co\n"
|
|
got = run_case(src)
|
|
print(" A=%d Ci=1 两次自增: S,Co,D,Co 期望 %s got=%s %s"
|
|
% (a, want, got, "" if got == want else "<== 错"))
|