Skip to content

Reduce floating-point exception handling overhead - #243

Merged
dingusdev merged 2 commits into
dingusdev:masterfrom
mihaip:upstream-fpu-exceptions
Oct 17, 2026
Merged

dingusdev merged 2 commits into
dingusdev:masterfrom
mihaip:upstream-fpu-exceptions

Conversation

@mihaip

@mihaip mihaip commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

I noticed while running the BeOS GL Teapot demo that we were spending a lot of time dealing with FPU exception flags ( std::fetestexcept and std::feclearexcept). Make this more efficient by querying for all flags at once, and only clearing them if any are set (this is all conditional on FE_ALL_EXCEPT being available - it's not for Emscripten). We can also use some ARM64 instructions to further speed things up on Apple Silicon.

To make this easier to measure in isolation, add an FPU-centric benchmark based on the recorded operations from the teapot demo.

Combine the host exception checks and only clear exceptions when needed.
On Apple ARM64, use ACLE intrinsics to read and update FPSR directly,
preserving unrelated status bits. Skip these checks when FE_ALL_EXCEPT
is zero.

On an M2 Max, the FPU replay benchmark drops from 32.6 ns/instruction to
21.3 ns with combined checks and 17.9 ns with the ARM64 helpers, giving
roughly 1.5x and 1.8x throughput respectively.
Complement bench1's integer workload with a replay through the real FPU
opcode dispatcher. The 512 instruction and register snapshots are based
on observed FPU operations while running GLTeapot on BeOS PR1.

Report median host time per instruction and provide a checksum mode for
checking that different implementations produce the same results,
without guest boot, display updates, or timer overhead.
@mihaip
mihaip force-pushed the upstream-fpu-exceptions branch from 08633b4 to 961b980 Compare October 16, 2026 21:47
mihaip added a commit to mihaip/infinite-mac that referenced this pull request Oct 16, 2026
Picks up dingusdev/dingusppc#243 which reduces the overhead of FPU
exception handling (though it's mostly a no-op for Emscripten, which
does not support them, see emscripten-core/emscripten#11087).

For #219
@dingusdev
dingusdev merged commit 904c1b1 into dingusdev:master Oct 17, 2026
7 checks passed
@mihaip
mihaip deleted the upstream-fpu-exceptions branch October 17, 2026 18:15
mihaip added a commit to mihaip/infinite-mac that referenced this pull request Oct 17, 2026
No-op code wise, just picking up the merge of dingusdev/dingusppc#243
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants