Skip to content

Prevent some invalid associativity in to_float implementation for avx…#1265

Merged
serge-sans-paille merged 1 commit intomasterfrom
fix/fast-math-to-float-avx2
Feb 27, 2026
Merged

Prevent some invalid associativity in to_float implementation for avx…#1265
serge-sans-paille merged 1 commit intomasterfrom
fix/fast-math-to-float-avx2

Conversation

@serge-sans-paille
Copy link
Contributor

…2 under -ffast-math

Fix #1264

With -ffast-math (-fassociative-math), the compiler may reassociate
(xH-C)+xL into xH+(xL-C). Since xL<<C this causes catastrophic
cancellation, zeroing the result.

Add an asm register barrier between the sub and add to prevent
reassociation. The barrier forces the intermediate into a register
without emitting any instructions.

Fixes #1264
@serge-sans-paille serge-sans-paille force-pushed the fix/fast-math-to-float-avx2 branch from c78168c to b118082 Compare February 27, 2026 14:39
@serge-sans-paille
Copy link
Contributor Author

@DiamonDinoia I've cherry-picked your patch, removed the redundant guard and pushed it here

@DiamonDinoia
Copy link
Contributor

Sure, it looks good!

@serge-sans-paille serge-sans-paille merged commit c3a8d37 into master Feb 27, 2026
140 checks passed
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.

Incorrect result for log() on AVX2 with -ffast-math

2 participants