- 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)
41 lines
1.9 KiB
Python
41 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
"""stdmac_preserve.py — raw_* 宏的输入保留性检查(链式调用前提)。"""
|
|
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()
|
|
|
|
CASES = [(0, 0, 0), (1, 1, 1), (126, 11, 1), (255, 255, 1), (170, 85, 0), (128, 1, 1), (254, 3, 1)]
|
|
|
|
print("=== raw_add: 输入 A/B/Ci 是否保留 ===")
|
|
for a, b, cin in CASES:
|
|
src = PRELUDE + set_cell("A", a) + set_cell("B", b) + set_cell("Ci", cin)
|
|
src += "raw_add A B Ci S Co tmp\noutput A\noutput B\noutput Ci\noutput S\noutput Co\n"
|
|
got = run_case(src)
|
|
ok = got[0:3] == [a, b, cin]
|
|
print(" (%3d,%3d,%d) -> A,B,Ci=%-14s S=%3d Co=%d %s" % (a, b, cin, got[0:3], got[3], got[4],
|
|
"" if ok else "<== 输入被破坏"))
|
|
|
|
print("\n=== raw_and/raw_or/raw_xor: 输入 A/B 是否保留 (用不相交位避免与 xor bug 混淆) ===")
|
|
for op in ("raw_and", "raw_or", "raw_xor"):
|
|
for a, b, _ in CASES[:5]:
|
|
src = PRELUDE + set_cell("A", a) + set_cell("B", b)
|
|
src += "%s A B S tmp\noutput A\noutput B\noutput S\n" % op
|
|
got = run_case(src)
|
|
ok = got[0:2] == [a, b]
|
|
print(" %-8s (%3d,%3d) -> A,B=%-14s S=%3d %s" % (op, a, b, got[0:2], got[2],
|
|
"" if ok else "<== 输入被破坏"))
|
|
|
|
print("\n=== raw_inc: 输入 A/Ci 是否保留 ===")
|
|
for a, b, cin in CASES:
|
|
src = PRELUDE + set_cell("A", a) + set_cell("Ci", cin)
|
|
src += "raw_inc A Ci S Co tmp\noutput A\noutput Ci\noutput S\noutput Co\n"
|
|
got = run_case(src)
|
|
ok = got[0:2] == [a, cin]
|
|
print(" (A=%3d,Ci=%d) -> A,Ci=%-14s S=%3d Co=%d %s" % (a, cin, got[0:2], got[2], got[3],
|
|
"" if ok else "<== 输入被破坏"))
|