- 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)
35 lines
1.4 KiB
Python
35 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
"""stdmac_inc_detail.py — 聚焦 raw_inc / bit_raw_inc 的失败面。"""
|
|
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()
|
|
|
|
print("=== bit_raw_inc 单比特真值表(A+Cin -> S,Cout 期望) ===")
|
|
for a in (0, 1):
|
|
for cin in (0, 1):
|
|
src = PRELUDE + set_cell("A", a) + set_cell("Ci", cin)
|
|
src += "bit_raw_inc A Ci S Co tmp\noutput S\noutput Co\n"
|
|
print(" A=%d Ci=%d want=%s got=%s" % (a, cin, [a ^ cin, a & cin], run_case(src)))
|
|
|
|
print("\n=== raw_inc 全表 (a,cin) -> (S,Co) ===")
|
|
bad = []
|
|
for a in (0, 1, 2, 3, 5, 126, 127, 128, 170, 254, 255):
|
|
for cin in (0, 1):
|
|
src = PRELUDE + set_cell("A", a) + set_cell("Ci", cin)
|
|
src += "raw_inc A Ci S Co tmp\noutput S\noutput Co\n"
|
|
got = run_case(src)
|
|
want = [(a + cin) & 0xFF, (a + cin) >> 8]
|
|
flag = "" if got == want else " <== 错"
|
|
print(" A=%-4d Ci=%d want=%-10s got=%s%s" % (a, cin, want, got, flag))
|
|
if got != want:
|
|
bad.append((a, cin, want, got))
|
|
|
|
print("\n差异规律: got[0]^want[0] 与 A/Ci 关系")
|
|
for a, cin, want, got in bad:
|
|
print(" A=%-4d Ci=%d got_S=%-4d want_S=%-4d S^A=%d S^Ci=%d" % (a, cin, got[0], want[0], got[0] ^ a, got[0] ^ cin))
|