diff options
| author | gbc dev <gbc@localhost> | 2026-09-22 20:48:09 +0200 |
|---|---|---|
| committer | gbc dev <gbc@localhost> | 2026-09-22 20:48:09 +0200 |
| commit | a2aa8fbb20cab296d44bcdd23c63c0f76ec52869 (patch) | |
| tree | 700f7a394f8bceb27199590343b158e872e1404d /Makefile | |
| parent | web: selecting a Game Boy puts the caret in its console (diff) | |
| download | sl0pboy-a2aa8fbb20cab296d44bcdd23c63c0f76ec52869.tar.gz sl0pboy-a2aa8fbb20cab296d44bcdd23c63c0f76ec52869.tar.xz sl0pboy-a2aa8fbb20cab296d44bcdd23c63c0f76ec52869.zip | |
wasm: cap the stack at 256KB - 16.25MB -> 0.5MB per Game Boy
zig defaults the wasm stack to 16MB, and that lands in the module's *initial*
memory, so every instance allocated 16.25MB before executing an instruction.
With several Game Boys on one page that was the dominant cost: 123MB for six.
The machine is a static and nothing here recurses deeply, so 256KB is plenty.
Per instance: 20.5MB -> 4.8MB of linear memory (six: 123MB -> 29MB). Note the
spelling - zig cc rejects -Wl,--stack-size and -zstack-size, and wants
-Wl,-z,stack-size=N.
With memory no longer the constraint, the page cap goes 6 -> 8 on measurement
rather than guesswork. Emulation-only, one thread: 12.5x realtime at 1, 3.1x
at 4, 1.5x at 8, and exactly 1.0x at 12 - i.e. ~12 is where a thread runs out
of road with nothing left for rendering. 8 holds a verified 60fps each in a
real browser with all eight leased.
Golden frames are still pixel-exact on cgb-acid2, dmg-acid2, cpu_instrs@600
and pky@400 with its .sav, and two Game Boys still lease and ping 4/4.
Diffstat (limited to 'Makefile')
| -rw-r--r-- | Makefile | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -16,9 +16,14 @@ BIN := $(BUILD)/sl0pboy WASM_SRCS := $(addprefix $(SRCDIR)/,cpu.c ppu.c timer.c gb.c cart.c wasm.c) WASM_OUT := web/sl0pboy.wasm WASM_CC := zig cc +# --stack-size: zig defaults the wasm stack to 16MB, which lands in the +# module's *initial* memory - so every Game Boy on the page cost 16.25MB +# before running an instruction. The machine is a static and the C code has no +# deep recursion, so 256KB is plenty: 260 pages -> 8 pages per instance. WASM_FLAGS := -target wasm32-wasi -mexec-model=reactor -O2 -std=c11 \ -Wall -Wextra -Wno-unused-parameter \ - -Wl,--no-entry -Wl,--export-dynamic -Wl,--strip-all + -Wl,--no-entry -Wl,--export-dynamic -Wl,--strip-all \ + -Wl,-z,stack-size=262144 .PHONY: all clean run wasm |
