Skip to content

Compile z_bgcheck.c on arm64 macOS with -ffp-contract=off#6584

Merged
serprex merged 1 commit into
HarbourMasters:developfrom
agamache:nofpcontract-bgcheck
Jun 6, 2026
Merged

Compile z_bgcheck.c on arm64 macOS with -ffp-contract=off#6584
serprex merged 1 commit into
HarbourMasters:developfrom
agamache:nofpcontract-bgcheck

Conversation

@agamache

@agamache agamache commented May 1, 2026

Copy link
Copy Markdown
Contributor

When compiling for arm64 and x86_64, compiler optimizations for contracting floating point operations to fused-multiply-add instructions behave differently, producing code that is not IEEE 754 compliant on arm64 macOS. In some specific scenarios, these inconsistencies result in different behavior from the base game, such as not being able to enter Bottom of the Well as adult using a weirdshot.

This pull request adds the compiler flag "-ffp-contract=off" only on arm64 macOS to disable these optimizations in z_bgcheck.c, restoring IEEE 754 compliant behavior for those specific interactions.

Build Artifacts

@serprex serprex left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh we should apply this to all files in soh/src

@serprex

serprex commented May 5, 2026

Copy link
Copy Markdown
Member

thinking more, we can apply this flag globally
(fast-math things may be useful for audio stuff or interpolation, but doesn't seem critical)

@agamache

agamache commented May 5, 2026

Copy link
Copy Markdown
Contributor Author

I know audio stuttering has been an issue on the macOS version in the past, but I can try running a version with the flag applied globally to get a quick idea of any effects on performance when I get home from work this evening

@serprex

serprex commented May 5, 2026

Copy link
Copy Markdown
Member

mac stuttering was caused by calling sleep with too large a duration

@agamache agamache force-pushed the nofpcontract-bgcheck branch from 1142edf to 8369c56 Compare May 5, 2026 23:36
@agamache

agamache commented May 5, 2026

Copy link
Copy Markdown
Contributor Author

I just tested a build with the flag applied globally in the top-level CMakeLists.txt and didn't observe any performance regressions

@serprex serprex requested a review from Malkierian May 5, 2026 23:52
@serprex

serprex commented May 31, 2026

Copy link
Copy Markdown
Member

I'm curious if this is needed for Windows ARM too, #6635
Should just ban fused multiply add on all platforms

@serprex serprex merged commit db60f64 into HarbourMasters:develop Jun 6, 2026
7 checks passed
@banteg

banteg commented Jun 8, 2026

Copy link
Copy Markdown

I know audio stuttering has been an issue on the macOS version in the past, but I can try running a version with the flag applied globally to get a quick idea of any effects on performance when I get home from work this evening

i fully fixed macos audio here btw, try it out Kenix3/libultraship#1098 + #6594

@banteg

banteg commented Jun 8, 2026

Copy link
Copy Markdown

i tested this pr also fixes the water temple softlock from #6620

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.

3 participants