This website requires JavaScript.
Explore
Help
Sign in
imjasonh
/
nescript
Watch
1
Star
0
Fork
You've already forked nescript
0
mirror of
https://github.com/imjasonh/nescript
synced
2026-07-16 12:12:04 +00:00
Code
Activity
df71c2bf50
nescript
/
tests
/
emulator
/
goldens
/
pong.audio.hash
2 lines
16 B
Text
Raw
Normal View
History
Unescape
Escape
peephole: drop dead LDA #imm before mem-INC/DEC + JMP The IR codegen lowers `i -= 1` (and friends) into a `LoadImm temp, 1; Sub d, i, temp; StoreVar i, d` triple, and the optimizer strength-reduces the Sub+StoreVar pair into `DEC i`. The constant-load-into-A that used to feed the Sub stays around as a dead `LDA #1`: LDA #1 DEC ZeroPage(rem) JMP Label("__ir_blk_while_cond_…") `remove_dead_loads` was set up to drop exactly this pattern but gave up at the trailing `JMP` because it couldn't reason about flow. Extend it to follow one unconditional `JMP <label>` to its target and resume the dead-store scan from the next instruction. The first instruction past the loop-condition label is reliably an `LDA loop_var`, which overwrites A without reading it — so the `LDA #1` is correctly identified as dead. Conditional branches still end the scan (their not-taken path is unconstrained) and only one JMP is followed (to keep the analysis local). For SHA-256 specifically this drops two `LDA #1`s per iteration of the rotate/shift bit-loops — about 1K cycles per block. The same pattern fires across most examples' loop tails. Verified: cargo test/clippy/fmt clean on rustc 1.95.0; emulator harness 34/34; reproducibility diff clean; SHA-256 of "NES" still computes to AE9145DB…4E0D. The cycle drift refreshes the four audio hashes / golden frames timing-sensitive examples already tracked. https://claude.ai/code/session_01FRmSBruVWCufm3LsUVMs8v
2026-04-16 17:14:34 +00:00
f2dbfbf3 132084
Copy permalink