A cycle is an access to memory, not an instruction
cycleCount used to tick once per instruction, so RSTA cost what SETD cost and a CALL moving ten bytes of Stack cost what a branch cost. No machine anybody could build works that way, and the emulator's job is to be the thing the hardware is designed against. Every touch of memory now goes through one of four accessors that charge for it: fetching an opcode, fetching the bytes after it, reading or writing Data Memory, and reaching a device port. One access, one cycle, nothing overlapped. The accessors exist so the cost is counted where the access happens rather than in a table of per instruction costs kept somewhere else - a table like that is a second copy of what the code does, and the two drift. The run loop spends a budget of cycles instead of running a count of instructions, so the emulated rate means something: an instruction costs what it touches, and a batch ends when the cycles are gone. What the numbers say now: RSTA 1 and SETD 4, being one byte and four. LDA 3, DPUA 2. CALL and RET together 24, RCAL and RRET together 8, because the first pair moves twenty bytes of Stack and the second moves four. The average SplitBit instruction costs 3.72 of these, measured over the native assembler assembling a program. And the measurement that prompted all of this: converting the filesystem's hottest leaf routine to RCAL is 3.1 per cent cheaper on a directory heavy workload. The old model said 0.0, which is what a model that cannot see memory traffic must say about a change that is nothing else. Three tests moved. settle() strips the cycle count from recorded output, so nothing should have churned - but it was anchored to the start of a line and replCalculator's last output has no newline on it, which leaves the halt message mid line where the pattern never reached. Not anchored any more. The two Life programs are bounded by a cycle count because they never end, and that number was rescaled from 3,000,000 to 11,200,000 - the same amount of work at 3.72 cycles to the instruction. Nothing about either program changed. No limit reproduces the old output exactly, because the cut now lands elsewhere in a frame, so they are recorded again rather than tuned to match. Whether hardware overlaps a fetch with the end of the previous instruction is left open on purpose. This is the conservative model; pipelining is a decision to make while drawing the hardware, not one to inherit from an emulator. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E2JrLzFvuFX9fgi1LDRjrW
This commit is contained in:
co-authored by
Claude Opus 5
parent
54f5cfe8a4
commit
f1e5cc46f6
+8
-4
@@ -460,15 +460,19 @@ inputTestOld | testPrograms/inputTest.asm | run | inputTest
|
||||
replCalculator | Examples/replCalculator.asm | run | replCalculator.in | -
|
||||
|
||||
# ---- Programs that run forever by design, bounded by a cycle count ----
|
||||
# 3,000,000 cycles is about fourteen generations of the glider, which puts
|
||||
# evolveBoard and its pointer juggling through its paces many times over.
|
||||
16x16Life | Examples/gameOfLife/16x16Life.asm | run | - | 3000000
|
||||
# 11,200,000 cycles is about fourteen generations of the glider, which puts evolveBoard and
|
||||
# its pointer juggling through its paces many times over.
|
||||
#
|
||||
# It was 3,000,000, and the number changed rather than the amount of work: a cycle used to
|
||||
# be an instruction and is now a memory access, and the average SplitBit instruction makes
|
||||
# 3.72 of those. Nothing about these two programs changed at all.
|
||||
16x16Life | Examples/gameOfLife/16x16Life.asm | run | - | 11200000
|
||||
# The four pointer rewrite, on the same budget so the two can be compared directly.
|
||||
# Note that this cannot show a speed difference: frameDelay is 255 by 255 and swamps
|
||||
# the simulation, so both versions render the same fourteen generations and produce
|
||||
# identical bytes. What it checks is that the rewrite still evolves the board the same
|
||||
# way, which is what a regression test is for.
|
||||
16x16LifeModern | Examples/gameOfLife/16x16LifeModern.asm | run | - | 3000000
|
||||
16x16LifeModern | Examples/gameOfLife/16x16LifeModern.asm | run | - | 11200000
|
||||
|
||||
# ---- Libraries: no entry point, so only check that they assemble ----
|
||||
# The CosmOS libraries assemble on their own, unlike print.asm below, which cannot: it
|
||||
|
||||
Reference in New Issue
Block a user