Replace the M6 pre-opt --scale with --bitptr: every source GEP (and an inttoptr of a bit addend over a ptrtoint base) becomes an opaque @__tms_bitptr(i32 bitoff, ptr base) call (nounwind readnone), so the optimizer cannot canonicalize an already-bit offset back into a byte GEP for the post-opt --scale to multiply by 8 again. tms-clang -O2 is now clang -> --bitptr -> opt default<O2> -> --scale (optimizer byte GEPs only) -> --lower-bitptr -> opt instcombine. -O0 is clang -> --bitptr -> --lower-bitptr. --lower-bitptr restores inttoptr(add(ptrtoint base, bitoff)); the final instcombine restores the M0 int_diff 8/32 folding and the shim's emit_uint64 needs instcombine<no-verify-fixpoint> for a known zext/nneg non-idempotent shape. Constant-expression GEPs keep the inttoptr/add form. Remove the shim memmove constant-step workaround (natural d += n) and add the M7 -O2 pointer gate (C driver at -O2, GSPA/GSPLNK, MAME, exact markers/bytes and one-scale IR/asm evidence). Update the M0 shape checks for the final instcombine's bit-index `getelementptr i8, %p, 24` late form (still 24 bits; the old 192 is rejected).
97 lines
2.5 KiB
Lua
97 lines
2.5 KiB
Lua
-- pointer-check.lua -- read the M7.1 `-O2` pointer gate markers and the exact
|
|
-- copy bytes, and compare them with the expected values.
|
|
--
|
|
-- M4_LOADER_LUA is the dwt loader script. Marker n is at 018A8000 + n*0x20
|
|
-- bits (0..8 from the driver, 9 the post-return sentinel); the copy bytes are
|
|
-- at 018A9000 + n*8 bits.
|
|
--
|
|
-- The marker read runs one frame before loader.lua's inspection/exit frame.
|
|
|
|
dofile(os.getenv("M4_LOADER_LUA"))
|
|
|
|
local ENDF = tonumber(os.getenv("LOADER_END") or "2700")
|
|
local BASE = 0x018A8000
|
|
local OUT = 0x018A9000
|
|
local N = 9
|
|
local SENT = 0x5A5A5A5A
|
|
local frames = 0
|
|
local checked = false
|
|
|
|
local expect = {
|
|
1, -- a[0..7] == "aabcdefg" after the overlapping backward copy
|
|
1, -- a[8] == 'h', a[9] and a[65] untouched
|
|
81, -- b[3] == 'Q' after `p += 3; *p = 'Q'`
|
|
0, -- b[0] untouched
|
|
0, -- b[24] untouched (the old double-scaled byte)
|
|
0, -- b[127] untouched
|
|
5, -- (q - b) in bytes
|
|
40, -- (u32)q - (u32)b in bits
|
|
1, -- the forward byte checks
|
|
}
|
|
local want_bytes = "aabcdefgh"
|
|
|
|
local function escape(s)
|
|
return (s:gsub("\n", "\\n"))
|
|
end
|
|
|
|
emu.register_frame_done(function()
|
|
frames = frames + 1
|
|
if frames == ENDF - 1 and not checked then
|
|
checked = true
|
|
local prog = manager.machine.devices[':maincpu'].spaces['program']
|
|
local got = {}
|
|
local bad = 0
|
|
for i = 0, N - 1 do
|
|
got[i] = prog:read_u32(BASE + i * 0x20)
|
|
if got[i] ~= expect[i + 1] then
|
|
bad = bad + 1
|
|
end
|
|
end
|
|
local sent = prog:read_u32(BASE + 9 * 0x20)
|
|
if sent ~= SENT then
|
|
bad = bad + 1
|
|
end
|
|
|
|
local bytes = {}
|
|
for i = 0, #want_bytes - 1 do
|
|
bytes[#bytes + 1] =
|
|
string.char(prog:read_u8(OUT + i * 8))
|
|
end
|
|
local got_bytes = table.concat(bytes)
|
|
|
|
io.write("M7 pointer:")
|
|
for i = 0, N - 1 do
|
|
io.write(string.format(" %08X", got[i]))
|
|
end
|
|
io.write(string.format(" %08X\n", sent))
|
|
print(string.format("M7 pointer bytes(%d): '%s' want '%s'",
|
|
#got_bytes, escape(got_bytes), escape(want_bytes)))
|
|
|
|
if got_bytes ~= want_bytes then
|
|
bad = bad + 1
|
|
end
|
|
|
|
if bad == 0 then
|
|
print("M4: pointer gate markers and bytes match")
|
|
print("M4 MAME: PASS")
|
|
print("M7 POINTER MAME: PASS")
|
|
else
|
|
for i = 0, N - 1 do
|
|
if got[i] ~= expect[i + 1] then
|
|
print(string.format(
|
|
"M7 pointer: marker %d got %08X want %08X",
|
|
i, got[i], expect[i + 1]))
|
|
end
|
|
end
|
|
if sent ~= SENT then
|
|
print(string.format(
|
|
"M7 pointer: sentinel got %08X want %08X",
|
|
sent, SENT))
|
|
end
|
|
print("M4: pointer gate marker/byte mismatch")
|
|
print("M4 MAME: FAIL")
|
|
print("M7 POINTER MAME: FAIL")
|
|
end
|
|
end
|
|
end, "m7-pointer-check")
|