Measure the finer chain tail: 84/120 becomes 18/120, and the derivation was right by cancellation
blit.s gains v7 -- v6's 24-pixel movem chain plus a second chain whose unit is
one `move.l (a0)+,(a2)+`. Measured over 13 span lengths by span.sh, every config
pixel-exact:
cycles = 66.0 per span + 9.143 per COARSE pixel + 9.978 per FINE pixel
fitting all 13 to within 0.2%. v5 and v6 re-measure to FINDINGS 30 exactly, so
the harness has not drifted underneath the new variant.
Rescored against the same scsi window and the same additive model, v7 takes
84/120 frames over budget to 18/120 -- exactly what FINDINGS 39.4 derived, and
that agreement is two cancelling errors: the derivation's 2-register movem tail
is 29% too dear per pixel, and its "nothing per span" for the second chain entry
is 22.3 clocks too cheap. The plain post-incrementing move.l is the right tail
instruction, and it makes the padding quantum 2 pixels, which a run of 4x4
blocks pads to exactly zero.
The DMAC stays dropped on a measurement now rather than an argument: v7 takes
back 37 of the 43 frames the array chain would, with no reserved channel and no
timing neither emulator here can verify. Break-even against all-V1 moves from
L=4 blocks to L=2.
The fine displacement is carried mid-stream rather than in the span record, so
the decoder holds nothing across the copy and keeps all 12 payload registers --
which is the whole reason the coarse unit is 24 pixels.
span.sh is now -seconds_to_run 200 (30 s wall, 36 configs) and takes its
expected snapshot count from the generated metadata instead of a literal 23.
Claude-Session: https://claude.ai/code/session_01194oWYW8DQXK1SZ2DnChW6
This commit is contained in:
@@ -41,8 +41,11 @@ CPU + DMA, additive. Session 10's first pass used max(CPU, bus) and got 53/120
|
||||
where the additive model gives 84/120; FINDINGS 35's flat debit was right.
|
||||
|
||||
So the only material difference left is v6's 24-pixel padding quantum -- and
|
||||
that is a property of v6's unrolled chain, not of the CPU. The `v6 fine tail`
|
||||
column prices fixing it in software instead.
|
||||
that is a property of v6's unrolled chain, not of the CPU. The `v7 fine tail`
|
||||
column prices fixing it in software instead, and as of session 11 that column
|
||||
is MEASURED on the 68000 (blit.s v7, tools/bench/span.sh, FINDINGS 40) rather
|
||||
than derived: 66.0 clocks per span + 9.143 per coarse pixel + 9.978 per fine
|
||||
pixel, with a 2-pixel quantum that a run of 4x4 blocks pads to exactly.
|
||||
"""
|
||||
import sys, os, argparse
|
||||
sys.path.insert(0, "tools/encoder")
|
||||
@@ -100,8 +103,8 @@ def span_cost(design, L):
|
||||
if design == "v6":
|
||||
px = B.pad24(4 * L)
|
||||
return 4 * px, 4 * (B.V6_SPAN_CYC + px * B.V6_PX_CYC)
|
||||
if design == "v6fine":
|
||||
px, c = B.v6_fine(4 * L)
|
||||
if design == "v7":
|
||||
px, c = B.v7_span(4 * L)
|
||||
return 4 * px, 4 * c
|
||||
px = 4 * L
|
||||
return 4 * px, 4 * (B.DMA_CHAIN_CLK + px * a.dma_px_clk)
|
||||
@@ -127,7 +130,9 @@ def score(design):
|
||||
cur_b = sum(BLK_B[int(b)] for b in m[by][i:j])
|
||||
px, sc = span_cost(design, L)
|
||||
sc += L * C_SKIP_MIXED # the dispatch still happens
|
||||
span_b = 4 * SPAN_HDR + px * SPAN_BYTES_PX
|
||||
# v7 carries a second u16 (the fine displacement) per span.
|
||||
hdr = B.V7_SPAN_HDR if design == "v7" else SPAN_HDR
|
||||
span_b = 4 * hdr + px * SPAN_BYTES_PX
|
||||
if sc < cur_c:
|
||||
cand.append((cur_c - sc, span_b - cur_b, by, i, j, sc, L))
|
||||
cand.sort(key=lambda s: -(s[0] / max(s[1], 1)))
|
||||
@@ -154,7 +159,7 @@ def score(design):
|
||||
|
||||
|
||||
DESIGNS = [("today", "none"), ("v6 span", "v6"),
|
||||
("v6 fine tail", "v6fine"), ("DMAC chain", "dmac")]
|
||||
("v7 fine tail", "v7"), ("DMAC chain", "dmac")]
|
||||
res = {n: score(k) for n, k in DESIGNS}
|
||||
|
||||
print(f"{a.container}: {d.nframes} frames, {d.nb} blocks, {a.fps:g} fps")
|
||||
@@ -188,11 +193,11 @@ print(f"\n ADDITIVE: frame = CPU + span painting + disk DMA. The 68000 has no"
|
||||
|
||||
# What is left of the case, isolated.
|
||||
v6m = int((res["v6 span"][0] > FRAME_CYC).sum())
|
||||
finem = int((res["v6 fine tail"][0] > FRAME_CYC).sum())
|
||||
finem = int((res["v7 fine tail"][0] > FRAME_CYC).sum())
|
||||
dmam = int((res["DMAC chain"][0] > FRAME_CYC).sum())
|
||||
print(f"\nWHAT THE DMAC ACTUALLY BUYS, decomposed")
|
||||
print(f" v6 as built {v6m}/{d.nframes} frames over")
|
||||
print(f" v6 with a finer chain tail (software) {finem}/{d.nframes}")
|
||||
print(f" v7, a finer chain tail (MEASURED) {finem}/{d.nframes}")
|
||||
print(f" DMAC chain {dmam}/{d.nframes}")
|
||||
print(f" -> of the gap between v6 and the DMAC, "
|
||||
f"{100*(v6m-finem)/max(v6m-dmam,1):.0f}% is the 24-pixel padding")
|
||||
@@ -206,9 +211,9 @@ print(f" in software. The rest is 1.7% a pixel and 7.7 clocks a span.")
|
||||
|
||||
print(f"\nbreak-even against all-V1 ({C_V1:.1f} cycles/block), clocks per block")
|
||||
print(f" {'L':<16}" + "".join(f"{L:>8}" for L in (1, 2, 3, 4, 8, 16, 64)))
|
||||
for nm, dz in (("v6 as built", "v6"), ("v6 fine tail", "v6fine"), ("DMAC chain", "dmac")):
|
||||
for nm, dz in (("v6 as built", "v6"), ("v7 fine tail", "v7"), ("DMAC chain", "dmac")):
|
||||
print(f" {nm:<16}" + "".join(f"{span_cost(dz, L)[1]/L:>8.0f}"
|
||||
for L in (1, 2, 3, 4, 8, 16, 64)))
|
||||
for nm, dz in (("v6 as built", "v6"), ("v6 fine tail", "v6fine"), ("DMAC chain", "dmac")):
|
||||
for nm, dz in (("v6 as built", "v6"), ("v7 fine tail", "v7"), ("DMAC chain", "dmac")):
|
||||
brk = next((L for L in range(1, 65) if span_cost(dz, L)[1] < L * C_V1), None)
|
||||
print(f" {nm:<16} beats all-V1 from L={brk} blocks up")
|
||||
|
||||
+48
-14
@@ -110,20 +110,54 @@ def block_bus(mode_map, spanned=None):
|
||||
return pref, data
|
||||
|
||||
|
||||
# --- v6 with a finer tail (PROPOSAL, unmeasured -- Claude's, session 10) ----
|
||||
# --- v7: v6 with a finer tail (MEASURED, session 11, FINDINGS 40) ----------
|
||||
# v6 pads every span up to 24 pixels because its unrolled chain is built from
|
||||
# 12-register movem units. Adding a second, finer chain of 2-register units
|
||||
# (4 pixels) for the tail caps the padding at 3 pixels instead of 23, for the
|
||||
# price of some more unrolled code and nothing per span.
|
||||
# A 4-pixel unit: movem.l (a0)+,2 = 2w instr + 4 reads; movem.l 2,(a2) = 2w +
|
||||
# 4 writes; lea = 2w. 14 bus cycles for 4 pixels = 56 clocks, against a full
|
||||
# unit's 24 x 9.152 = 220 for 24. Dearer per pixel, paid at most once a span.
|
||||
V6_TAIL_PX, V6_TAIL_CLK = 4, 56
|
||||
# 12-register movem units, and FINDINGS 39.3 attributed 86% of the DMAC array
|
||||
# chain's advantage over v6 to exactly that padding. v7 keeps the coarse chain
|
||||
# and appends a second chain whose unit is one `move.l (a0)+,(a2)+` -- 2 pixels,
|
||||
# so the quantum is 2 and a run of 4x4 blocks pads to NOTHING.
|
||||
#
|
||||
# Session 10 proposed a 2-REGISTER MOVEM tail (4 pixels, derived at 56 clocks)
|
||||
# and that would have been the wrong instruction: movem.l (a0)+,d0-d1 plus
|
||||
# movem.l d0-d1,(a2) plus the lea is 14 bus cycles for 4 pixels, where two plain
|
||||
# move.l are 10. The plainest instruction on the machine wins the tail.
|
||||
#
|
||||
# The second entry point needs a second dispatch, and the fine displacement is
|
||||
# carried MID-STREAM (after the coarse pixels, before the fine ones) rather than
|
||||
# in the span record, so the decoder holds nothing extra across the copy and
|
||||
# keeps all 12 payload registers. Costed as 2 more bytes per span.
|
||||
#
|
||||
# MEASURED by tools/bench/span.sh (blit.s v7, 13 span lengths, every config
|
||||
# pixel-exact): cycles = 66.0/span + 9.143/coarse pixel + 9.978/fine pixel,
|
||||
# fitting all 13 to within 0.2%.
|
||||
V7_SPAN_CYC = 66.0 # MEASURED, FINDINGS 40
|
||||
V7_CPX_CYC = 9.143 # MEASURED, FINDINGS 40 (24-pixel coarse unit)
|
||||
V7_FPX_CYC = 9.978 # MEASURED, FINDINGS 40 (2-pixel fine unit)
|
||||
V7_FINE_PX = 2
|
||||
# Bus: per span v6's 9 plus a second {move.w (a0)+,d0 ; jmp} = 2 + 2.
|
||||
# Per fine unit: move.l (a0)+,(a2)+ = 1 instruction word + 2 reads + 2 writes.
|
||||
V7_SPAN_BUS = 13
|
||||
V7_FINE_BUS = 5
|
||||
V7_SPAN_HDR = 8 # {u32 address, u16 coarse disp} + u16 fine disp
|
||||
|
||||
|
||||
def v6_fine(npix):
|
||||
"""(pixels carried, CPU clocks) for a span with the finer tail."""
|
||||
k, r = divmod(npix, V6_UNIT_PX)
|
||||
t = -(-r // V6_TAIL_PX)
|
||||
return (k * V6_UNIT_PX + t * V6_TAIL_PX,
|
||||
V6_SPAN_CYC + k * V6_UNIT_PX * V6_PX_CYC + t * V6_TAIL_CLK)
|
||||
def pad2(npix):
|
||||
return -(-npix // V7_FINE_PX) * V7_FINE_PX
|
||||
|
||||
|
||||
def v7_span(npix):
|
||||
"""(pixels carried, CPU clocks) for a v7 span of npix pixels."""
|
||||
k, r = divmod(pad2(npix), V6_UNIT_PX)
|
||||
return (k * V6_UNIT_PX + r,
|
||||
V7_SPAN_CYC + k * V6_UNIT_PX * V7_CPX_CYC + r * V7_FPX_CYC)
|
||||
|
||||
|
||||
def v7_span_bus(npix):
|
||||
"""Bus CYCLES a v7 span occupies -- instruction words plus data accesses."""
|
||||
k, r = divmod(pad2(npix), V6_UNIT_PX)
|
||||
return V7_SPAN_BUS + k * V6_UNIT_BUS + (r // V7_FINE_PX) * V7_FINE_BUS
|
||||
|
||||
|
||||
def v6_span_bus(npix):
|
||||
k = pad24(npix) // V6_UNIT_PX
|
||||
return V6_SPAN_BUS + k * V6_UNIT_BUS
|
||||
|
||||
@@ -69,6 +69,27 @@
|
||||
; And with row and remainder handling gone, 12 registers are free again
|
||||
; (d0-d6/a1/a3-a6), which is why the unit is 24 pixels and not V5's 16.
|
||||
;
|
||||
; V7 v6 with a SECOND, finer chain for the tail (FINDINGS 39.4). v6 pays for
|
||||
; its 24-pixel quantum in padding: an average span wastes ~11 pixels, and
|
||||
; FINDINGS 39.3 attributes 86% of the DMAC array-chain's advantage over v6
|
||||
; to exactly that. V7 keeps the 24-pixel coarse chain and appends a chain
|
||||
; of 2-pixel units, so a span is 24*c + 2*f pixels and the padding is at
|
||||
; most one pixel -- ZERO for the real case, where a span is a run of 4x4
|
||||
; blocks and its length is a multiple of 4.
|
||||
;
|
||||
; The fine unit is `move.l (a0)+,(a2)+` (20 cycles, 2 pixels), NOT a
|
||||
; 2-register movem: movem.l (a0)+,d0-d1 plus movem.l d0-d1,(a2) plus the
|
||||
; lea is 52+8 cycles for 4 pixels, so the obvious "smaller movem" tail is
|
||||
; 50% dearer per pixel than the plainest instruction on the machine.
|
||||
;
|
||||
; The second entry point costs a second dispatch, and the trick that pays
|
||||
; for it is that the fine displacement is NOT in the span record: it sits
|
||||
; in the STREAM, after the coarse pixels and before the fine ones. The
|
||||
; coarse chain falls out into `move.w (a0)+,d0 / jmp`, by which point d0
|
||||
; is dead payload and a0 is pointing exactly at it. So v7 holds nothing
|
||||
; extra across the copy and keeps all 12 payload registers -- a record is
|
||||
; still {u32 address, u16 displacement}, with one more u16 mid-span.
|
||||
;
|
||||
; 12 registers per movem burst (d0-d7/a2-a5 = 48 bytes) is the maximum
|
||||
; available: a0=src, a1=dst, a6=end sentinel. The row counter lives in the
|
||||
; a1-vs-a6 compare rather than a d-register for exactly this reason.
|
||||
@@ -88,6 +109,10 @@ DSTE = $C38000 ; GVRAM + 224*1024 (one past last)
|
||||
ROWS = 192 ; picture rows a V5 stream describes
|
||||
V6UNIT = 12 ; bytes of code per V6 chain unit
|
||||
V6MAX = 11 ; chain units = 11*24 = 264 pixels >= one row
|
||||
V7CU = 12 ; bytes of code per V7 COARSE unit (24 px)
|
||||
V7CN = 11 ; coarse units: 11*24 = 264 px >= one row
|
||||
V7FU = 2 ; bytes of code per V7 FINE unit (2 px)
|
||||
V7FN = 11 ; fine units: 11*2 = 22 px > one coarse unit
|
||||
|
||||
org $10000
|
||||
start:
|
||||
@@ -103,6 +128,8 @@ start:
|
||||
beq v5
|
||||
cmp.l #6,d0
|
||||
beq v6
|
||||
cmp.l #7,d0
|
||||
beq v7
|
||||
bra v3
|
||||
|
||||
; ---------------------------------------------------------------- V1
|
||||
@@ -282,5 +309,68 @@ v6ch:
|
||||
bne v6
|
||||
bra done
|
||||
|
||||
; ---------------------------------------------------------------- V7
|
||||
; a0 stream, a2 destination, d7 spans remaining; everything else is payload.
|
||||
; Stream per span: u32 dest, u16 coarse disp, c*48 B pixels,
|
||||
; u16 fine disp, f*4 B pixels.
|
||||
v7: move.l SPTR.l,a0
|
||||
move.w (a0)+,d7 ; total spans in the frame
|
||||
subq.w #1,d7
|
||||
v7span: move.l (a0)+,a2 ; absolute GVRAM destination
|
||||
move.w (a0)+,d0 ; (V7CN - coarse) * V7CU
|
||||
jmp v7ch(pc,d0.w)
|
||||
v7ch:
|
||||
movem.l (a0)+,d0-d6/a1/a3-a6
|
||||
movem.l d0-d6/a1/a3-a6,(a2)
|
||||
lea 48(a2),a2
|
||||
movem.l (a0)+,d0-d6/a1/a3-a6
|
||||
movem.l d0-d6/a1/a3-a6,(a2)
|
||||
lea 48(a2),a2
|
||||
movem.l (a0)+,d0-d6/a1/a3-a6
|
||||
movem.l d0-d6/a1/a3-a6,(a2)
|
||||
lea 48(a2),a2
|
||||
movem.l (a0)+,d0-d6/a1/a3-a6
|
||||
movem.l d0-d6/a1/a3-a6,(a2)
|
||||
lea 48(a2),a2
|
||||
movem.l (a0)+,d0-d6/a1/a3-a6
|
||||
movem.l d0-d6/a1/a3-a6,(a2)
|
||||
lea 48(a2),a2
|
||||
movem.l (a0)+,d0-d6/a1/a3-a6
|
||||
movem.l d0-d6/a1/a3-a6,(a2)
|
||||
lea 48(a2),a2
|
||||
movem.l (a0)+,d0-d6/a1/a3-a6
|
||||
movem.l d0-d6/a1/a3-a6,(a2)
|
||||
lea 48(a2),a2
|
||||
movem.l (a0)+,d0-d6/a1/a3-a6
|
||||
movem.l d0-d6/a1/a3-a6,(a2)
|
||||
lea 48(a2),a2
|
||||
movem.l (a0)+,d0-d6/a1/a3-a6
|
||||
movem.l d0-d6/a1/a3-a6,(a2)
|
||||
lea 48(a2),a2
|
||||
movem.l (a0)+,d0-d6/a1/a3-a6
|
||||
movem.l d0-d6/a1/a3-a6,(a2)
|
||||
lea 48(a2),a2
|
||||
movem.l (a0)+,d0-d6/a1/a3-a6
|
||||
movem.l d0-d6/a1/a3-a6,(a2)
|
||||
lea 48(a2),a2
|
||||
v7cx: move.w (a0)+,d0 ; (V7FN - fine) * V7FU, from mid-stream
|
||||
jmp v7fh(pc,d0.w)
|
||||
v7fh:
|
||||
move.l (a0)+,(a2)+
|
||||
move.l (a0)+,(a2)+
|
||||
move.l (a0)+,(a2)+
|
||||
move.l (a0)+,(a2)+
|
||||
move.l (a0)+,(a2)+
|
||||
move.l (a0)+,(a2)+
|
||||
move.l (a0)+,(a2)+
|
||||
move.l (a0)+,(a2)+
|
||||
move.l (a0)+,(a2)+
|
||||
move.l (a0)+,(a2)+
|
||||
move.l (a0)+,(a2)+
|
||||
dbra d7,v7span
|
||||
subq.l #1,ITER.l
|
||||
bne v7
|
||||
bra done
|
||||
|
||||
done: move.l #$FF,FLAG.l ; timer stops here
|
||||
halt: bra.s halt
|
||||
|
||||
@@ -31,6 +31,20 @@ v6 -- the same spans with that arithmetic moved here, where it is free:
|
||||
line stride is 1024 bytes and only the first 512 are displayed. The jump
|
||||
displacement selects an entry point into the decoder's unrolled copy chain.
|
||||
|
||||
v7 -- v6 plus a second, FINER chain for the tail (FINDINGS 39.4). Padding to
|
||||
v6's 24-pixel quantum wastes ~11 pixels on an average span, and FINDINGS
|
||||
39.3 attributes 86% of the DMAC array-chain's advantage over v6 to it. A
|
||||
v7 span is 24*c + 2*f pixels, so the quantum is 2 and a run of 4x4 blocks
|
||||
(always a multiple of 4 pixels) pads to NOTHING:
|
||||
u16 nspans
|
||||
nspans * { u32 absolute GVRAM address, u16 coarse displacement,
|
||||
c * 48 bytes of pixels,
|
||||
u16 fine displacement, f * 4 bytes of pixels }
|
||||
The fine displacement is in the STREAM rather than the record because that
|
||||
is what lets the decoder keep all 12 payload registers: the coarse chain
|
||||
falls out into a `move.w (a0)+,d0 / jmp` with d0 dead and a0 pointing at
|
||||
it. Costed here as an 8-byte record, since it is 2 more bytes a span.
|
||||
|
||||
Pixels are word-expanded with the palette index in the low byte; the high byte
|
||||
is whatever we put there because gvram_w masks it off (x68k_crtc.cpp:501).
|
||||
"""
|
||||
@@ -58,8 +72,18 @@ CONFIGS = [(4, 0), (8, 0), (12, 0), (16, 0), (16, 1), (20, 0), (24, 0),
|
||||
# v6 geometry, and it must match blit.s: 12 registers per movem = 48 bytes =
|
||||
# 24 pixels per chain unit, 11 units in the chain.
|
||||
UNITPX, UNITSZ, UNITS = 24, 12, 11
|
||||
# v7 geometry, and it must match blit.s: coarse unit as v6, fine unit is one
|
||||
# `move.l (a0)+,(a2)+` = 2 bytes of code = 2 pixels, 11 of them (22 px > 24).
|
||||
FINEPX, FINESZ, FINES = 2, 2, 11
|
||||
GVRAM, YOFF, STRIDE = 0xC00000, 32, 1024
|
||||
|
||||
# v7 span lengths, in pixels. Multiples of 4 (a real span is a run of 4x4
|
||||
# blocks), chosen so the fine remainder P mod 24 takes every value a real span
|
||||
# can: 0, 4, 8, 12, 16, 20. 4/8/12/16/20 are pure-fine, 24/48/72/120/240 are
|
||||
# pure-coarse, the rest mix -- which is what makes the three-term fit
|
||||
# cycles = A*spans + Bc*coarse_px + Bf*fine_px identifiable.
|
||||
V7CONFIGS = [4, 8, 12, 16, 20, 24, 28, 44, 48, 72, 100, 120, 256]
|
||||
|
||||
blob, metas = bytearray(), []
|
||||
for P, x0 in CONFIGS:
|
||||
off = len(blob)
|
||||
@@ -78,7 +102,8 @@ for P, x0 in CONFIGS:
|
||||
blob += idx[y, x:x+n].astype(">u2").tobytes()
|
||||
nspans += 1; npix += n
|
||||
metas.append(dict(name=f"{P}{'u' if x0 else ''}", p=P, x0=x0, off=off,
|
||||
len=len(blob)-off, nspans=nspans, npix=npix, var=5))
|
||||
len=len(blob)-off, nspans=nspans, npix=npix,
|
||||
cpx=npix, fpx=0, var=5))
|
||||
|
||||
# v6: one config per chain depth, so the fit sees spans from 24 to 264 pixels.
|
||||
for units in range(1, UNITS+1):
|
||||
@@ -100,7 +125,33 @@ for units in range(1, UNITS+1):
|
||||
blob += px.astype(">u2").tobytes()
|
||||
nspans += 1; npix += P
|
||||
metas.append(dict(name=f"{P}", p=P, x0=0, off=off, len=len(blob)-off,
|
||||
nspans=nspans, npix=npix, var=6))
|
||||
nspans=nspans, npix=npix, cpx=npix, fpx=0, var=6))
|
||||
|
||||
# v7: same tiling, but the span is cut at a 2-pixel quantum instead of 24.
|
||||
for P in V7CONFIGS:
|
||||
units, fine = divmod(P, UNITPX)
|
||||
assert fine % FINEPX == 0 and fine // FINEPX <= FINES, P
|
||||
assert units <= UNITS, P
|
||||
off = len(blob)
|
||||
nspans = npix = 0
|
||||
rows = []
|
||||
for y in range(H):
|
||||
x = 0
|
||||
while x < W:
|
||||
rows.append((y, x)); x += P
|
||||
blob += struct.pack(">H", len(rows))
|
||||
for y, x in rows:
|
||||
assert x + P <= STRIDE // 2, (P, x) # the overrun must stay on the line
|
||||
blob += struct.pack(">IH", GVRAM + (YOFF+y)*STRIDE + x*2,
|
||||
(UNITS-units)*UNITSZ)
|
||||
px = np.concatenate([idx[y, x:x+P], np.zeros(max(0, x+P-W), np.uint8)])
|
||||
blob += px[:units*UNITPX].astype(">u2").tobytes()
|
||||
blob += struct.pack(">H", (FINES - fine//FINEPX)*FINESZ)
|
||||
blob += px[units*UNITPX:].astype(">u2").tobytes()
|
||||
nspans += 1; npix += P
|
||||
metas.append(dict(name=f"{P}", p=P, x0=0, off=off, len=len(blob)-off,
|
||||
nspans=nspans, npix=npix,
|
||||
cpx=nspans*units*UNITPX, fpx=nspans*fine, var=7))
|
||||
|
||||
open(OUT, "wb").write(blob)
|
||||
with open(META, "w") as f:
|
||||
@@ -108,7 +159,8 @@ with open(META, "w") as f:
|
||||
f.write(f" W={W}, H={H}, total={len(blob)},\n configs = {{\n")
|
||||
for m in metas:
|
||||
f.write(" {{var={var}, name=\"{name}\", p={p}, x0={x0}, off={off},"
|
||||
" len={len}, nspans={nspans}, npix={npix}}},\n".format(**m))
|
||||
" len={len}, nspans={nspans}, npix={npix}, cpx={cpx},"
|
||||
" fpx={fpx}}},\n".format(**m))
|
||||
f.write(" },\n}\n")
|
||||
|
||||
print(f"{SRC} {W}x{H} -> {OUT} {len(blob)} B, {len(metas)} configs")
|
||||
|
||||
+57
-11
@@ -108,7 +108,8 @@ local function launch(cfg)
|
||||
push(STREAM, blob, cfg.off+1, cfg.len)
|
||||
clear_picture()
|
||||
-- ~4 emulated seconds per config: 1/55.46 s granularity costs under 0.5%.
|
||||
local est = cfg.nspans*(cfg.var == 6 and 50 or 60) + cfg.npix*10
|
||||
local est = cfg.nspans*(cfg.var == 5 and 60 or (cfg.var == 6 and 50 or 70))
|
||||
+ cfg.npix*10
|
||||
cfg.iter = math.max(4, math.floor(4*CPUHZ/est))
|
||||
SP:write_u32(FLAG, 0)
|
||||
SP:write_u32(VAR, cfg.var)
|
||||
@@ -143,6 +144,34 @@ local function fit(rs)
|
||||
return (sy*pp - py*sp)/det, (ss*py - sp*sy)/det
|
||||
end
|
||||
|
||||
-- v7 has two per-pixel costs -- the 24-pixel coarse chain and the 2-pixel fine
|
||||
-- chain -- so its fit is cycles = A*spans + Bc*coarse_px + Bf*fine_px, solved
|
||||
-- by plain Gaussian elimination on the 3x3 normal equations. prep_spans.py
|
||||
-- picks span lengths so every fine remainder a real span can have (0,4,..,20)
|
||||
-- appears, which is what makes the three terms separable.
|
||||
local function fit3(rs)
|
||||
local M3 = {{0,0,0,0},{0,0,0,0},{0,0,0,0}}
|
||||
for _,r in ipairs(rs) do
|
||||
local x = {r.cfg.nspans, r.cfg.cpx, r.cfg.fpx}
|
||||
for i=1,3 do
|
||||
for j=1,3 do M3[i][j] = M3[i][j] + x[i]*x[j] end
|
||||
M3[i][4] = M3[i][4] + x[i]*r.cyc
|
||||
end
|
||||
end
|
||||
for c=1,3 do
|
||||
local piv = c
|
||||
for r=c+1,3 do if math.abs(M3[r][c]) > math.abs(M3[piv][c]) then piv=r end end
|
||||
M3[c], M3[piv] = M3[piv], M3[c]
|
||||
for r=1,3 do
|
||||
if r ~= c then
|
||||
local f = M3[r][c]/M3[c][c]
|
||||
for k=c,4 do M3[r][k] = M3[r][k] - f*M3[c][k] end
|
||||
end
|
||||
end
|
||||
end
|
||||
return M3[1][4]/M3[1][1], M3[2][4]/M3[2][2], M3[3][4]/M3[3][3]
|
||||
end
|
||||
|
||||
local step, st, t0 = 0, "boot", nil
|
||||
|
||||
SUB = emu.add_machine_frame_notifier(function()
|
||||
@@ -159,7 +188,7 @@ SUB = emu.add_machine_frame_notifier(function()
|
||||
report(SPEC.configs[step], t - (t0 or t))
|
||||
st = "snap"; return
|
||||
end
|
||||
if t > 300 then P("TIMEOUT flag="..string.format("%08X",fl)); M:exit() end
|
||||
if t > 900 then P("TIMEOUT flag="..string.format("%08X",fl)); M:exit() end
|
||||
return
|
||||
end
|
||||
if st == "snap" then
|
||||
@@ -174,7 +203,7 @@ SUB = emu.add_machine_frame_notifier(function()
|
||||
end
|
||||
if st == "finish" then
|
||||
P("---- measured (instruction cycles only; real GVRAM adds wait states) ----")
|
||||
for _,v in ipairs{5,6} do
|
||||
for _,v in ipairs{5,6,7} do
|
||||
local sub = {}
|
||||
for _,r in ipairs(results) do if r.cfg.var == v then sub[#sub+1] = r end end
|
||||
-- v5's fit is over its BURSTING configs only (span length a multiple of
|
||||
@@ -183,13 +212,22 @@ SUB = emu.add_machine_frame_notifier(function()
|
||||
-- instead, which is where the remainder shows up as error.
|
||||
local fitset = {}
|
||||
for _,r in ipairs(sub) do
|
||||
if v == 6 or r.cfg.p % 16 == 0 then fitset[#fitset+1] = r end
|
||||
if v ~= 5 or r.cfg.p % 16 == 0 then fitset[#fitset+1] = r end
|
||||
end
|
||||
local A, Bp, Bf
|
||||
if v == 7 then
|
||||
A, Bp, Bf = fit3(fitset)
|
||||
P(string.format("-- v7: cycles = %.1f per span + %.3f per COARSE pixel"
|
||||
.." + %.3f per FINE pixel (fitted on %d of %d configs)",
|
||||
A, Bp, Bf, #fitset, #sub))
|
||||
else
|
||||
A, Bp = fit(fitset)
|
||||
Bf = Bp
|
||||
P(string.format("-- v%d: cycles = %.1f per span + %.3f per pixel"
|
||||
.." (fitted on %d of %d configs)", v, A, Bp, #fitset, #sub))
|
||||
end
|
||||
local A, Bp = fit(fitset)
|
||||
P(string.format("-- v%d: cycles = %.1f per span + %.3f per pixel"
|
||||
.." (fitted on %d of %d configs)", v, A, Bp, #fitset, #sub))
|
||||
for _,r in ipairs(sub) do
|
||||
local model = A*r.cfg.nspans + Bp*r.cfg.npix
|
||||
local model = A*r.cfg.nspans + Bp*r.cfg.cpx + Bf*r.cfg.fpx
|
||||
P(string.format(" span %4s px %8.0f cyc %5.2f cyc/px %6.1f cyc/span"
|
||||
.." vs fit %+6.1f%%", r.cfg.name, r.cyc,
|
||||
r.cyc/r.cfg.npix, r.cyc/r.cfg.nspans, 100*(model/r.cyc-1)))
|
||||
@@ -199,9 +237,17 @@ SUB = emu.add_machine_frame_notifier(function()
|
||||
-- v6 pads each to a whole 24-pixel chain unit.
|
||||
local line = " -> cycles per 4x4 block in a run of L blocks: "
|
||||
for _,L in ipairs{1,2,4,8,16,64} do
|
||||
local px = 4*L
|
||||
if v == 6 then px = math.ceil(px/24)*24 end
|
||||
line = line..string.format("L=%d %.0f ", L, 4*(A + px*Bp)/L)
|
||||
local px, cyc = 4*L, nil
|
||||
if v == 6 then
|
||||
px = math.ceil(px/24)*24
|
||||
cyc = A + px*Bp
|
||||
elseif v == 7 then
|
||||
local c = math.floor(px/24)*24
|
||||
cyc = A + c*Bp + (px-c)*Bf -- a multiple of 4 pads to nothing
|
||||
else
|
||||
cyc = A + px*Bp
|
||||
end
|
||||
line = line..string.format("L=%d %.0f ", L, 4*cyc/L)
|
||||
end
|
||||
P(line.."(V1 is 299.9)")
|
||||
if v == 5 then
|
||||
|
||||
+9
-5
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
# Measure the cost of a row-linear literal span on the 68000 (FINDINGS 30).
|
||||
# ~25 s. Run from the repo root. Needs tmp/frame256.bin (check.sh makes it).
|
||||
# ~45 s. Run from the repo root. Needs tmp/frame256.bin (check.sh makes it).
|
||||
#
|
||||
# NOT part of check.sh, for the same reason blit.s is not: the output is a wall
|
||||
# timing, so gating on it would make the green light host-sensitive. What IS
|
||||
@@ -14,18 +14,22 @@ python3 tools/bench/prep_spans.py
|
||||
tools/vasm/vasmm68k_mot -Fbin -o tmp/blit.bin tools/bench/blit.s > /dev/null
|
||||
mkdir -p tmp/snap_span
|
||||
rm -f tmp/snap_span/x68000/*.png
|
||||
( cd tmp && SDL_VIDEODRIVER=dummy timeout -k 5 1800 mame x68000 -bios ipl10 \
|
||||
( cd tmp && SDL_VIDEODRIVER=dummy stdbuf -oL timeout -k 5 1800 mame x68000 -bios ipl10 \
|
||||
-ramsize 2M -video soft -window -sound none -nothrottle -plugins \
|
||||
-autoboot_script ../tools/bench/span.lua \
|
||||
-snapshot_directory ./snap_span -snapview native -seconds_to_run 150 \
|
||||
-snapshot_directory ./snap_span -snapview native -seconds_to_run 200 \
|
||||
> span.log 2>&1 )
|
||||
grep -a "^\[SPAN\]" tmp/span.log
|
||||
|
||||
# One snapshot per config, and the expected count comes from the generated
|
||||
# metadata rather than a literal: adding a config must not silently weaken the
|
||||
# assertion that every one of them drew the picture.
|
||||
want=$(grep -c '{var=' tmp/spans_meta.lua)
|
||||
n=0
|
||||
for f in tmp/snap_span/x68000/*.png; do
|
||||
python3 tools/bench/verify_frame256.py "$f" > /dev/null || {
|
||||
echo "FAIL: $f is not pixel-exact"; python3 tools/bench/verify_frame256.py "$f"; exit 1; }
|
||||
n=$((n+1))
|
||||
done
|
||||
[ "$n" -eq 23 ] || { echo "FAIL: $n snapshots, expected 23"; exit 1; }
|
||||
echo "OK $n/23 span configs drew a pixel-exact frame"
|
||||
[ "$n" -eq "$want" ] || { echo "FAIL: $n snapshots, expected $want"; exit 1; }
|
||||
echo "OK $n/$want span configs drew a pixel-exact frame"
|
||||
|
||||
Reference in New Issue
Block a user