Files
r8asm-rev-tests/tools/verify_xor_2469c3a.py
starcells d452e5cda1 验收 2469c3a 新 bit_raw_xor:121/121 全对、A/B 保持、脏入口 0 例,且比修一行版短 350 字节
- tools/verify_xor_2469c3a.py:全表 + ans/tmp 脏入口扫描 + tape 长度对比
- 尾部 .tp before_xor 指向未定义 anchor(静默 0)实测净零:现役 2150 / 改真名 2220 / 整行删 2150
- 全库矩阵 @2469c3a:raw_add 242 / raw_and 121 / raw_or 121 / raw_xor 121 / raw_inc 22,总失败 0
2026-09-13 05:06:11 +00:00

59 lines
2.4 KiB
Python

#!/usr/bin/env python3
"""verify_xor_2469c3a.py — 验收用户推上来的新 bit_raw_xor(2469c3a)。
1) 全表 121 对:A/B 保持、S = A^B
2) 入口脏(ans/tmp 残留)下计算是否受影响
3) tape 长度 vs 我此前验证过的候选体(OR 体删末块 %3 set_1)
"""
import itertools
import os
import subprocess
import sys
import tempfile
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, REV, build_tools, run_case, set_cell, PROBE # noqa: E402
build_tools()
CAND = open(os.path.join(HERE, "tests", "xor_fix_probe.r8asm.frag")).read()
VALS = [0, 1, 2, 3, 5, 126, 127, 128, 170, 254, 255]
def case(call, a, b, ans_in=0, tmp_in=0, frag=""):
src = PRELUDE + frag + set_cell("A", a) + set_cell("B", b)
if ans_in or tmp_in:
src += ".tp S\n.xor %d\n.tp tmp\n.xor %d\n" % (ans_in, tmp_in)
src += "%s\noutput A\noutput B\noutput S\n" % call
return run_case(src)
bad = [c for c in itertools.product(VALS, VALS) if case("raw_xor A B S tmp", c[0], c[1]) != [c[0], c[1], c[0] ^ c[1]]]
print("现役 raw_xor(2469c3a) 全表:失败 %d/121 %s" % (len(bad), bad[:3]))
print("\n入口脏(ans/tmp 残留)下是否影响计算(A/B 保持 + S 正确):")
for ans_in in (0, 1, 85, 255):
for tmp_in in (0, 1, 85, 255):
bad2 = []
for a, b in itertools.product(VALS, VALS):
got = case("raw_xor A B S tmp", a, b, ans_in, tmp_in)
if got != [a, b, a ^ b]:
bad2.append((a, b, got))
if bad2:
print(" ans脏=%-3d tmp脏=%-3d 受影响 %2d/121 例:%s" % (ans_in, tmp_in, len(bad2), bad2[:2]))
print(" (未列出的组合 = 0 例)")
print("\ntape 长度对比(同一段程序只换 xor 宏):")
for label, call, frag in (("现役 raw_xor(2469c3a)", "raw_xor A B S tmp", ""),
("候选(OR 体删一行)", "raw_xor_cand A B S tmp", CAND)):
src = PRELUDE + frag + "raw_add A B Ci S Co tmp\n" + call + "\n"
with tempfile.NamedTemporaryFile("w", suffix=".r8asm", delete=False, dir=REV) as f:
f.write(src)
p = f.name
out = subprocess.run([PROBE, p], cwd=REV, capture_output=True, text=True)
os.unlink(p)
if out.returncode != 0:
print(" %-22s 汇编失败: %s" % (label, out.stderr.strip()[-120:]))
else:
print(" %-22s tape %d 字节" % (label, len(out.stdout)))