Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDEV-34969: test fail main.spatial_utility_function_simplify #3553

Open
wants to merge 1 commit into
base: preview-11.7-preview
Choose a base branch
from

Conversation

DaveGosselin-MariaDB
Copy link
Member

@DaveGosselin-MariaDB DaveGosselin-MariaDB commented Sep 26, 2024

On aarch64 and when computing the perpendicular distance, we need to avoid the fmsub (Fused Multiply-Subtract) because it can return slightly different precision results when evaluating expressions like

  x = a - (b * c)

such as we did (before this patch) in perpendicular-distance. Instead, we now store the result of the multiplication (b * c) and then subtract it from a which avoids (in all build types) fmsub.

This error occurs because the C standard allows implementations to use higher precision throughout calculations before storing to the destination type. This can allow for differences in the final result if using higher precision meaningfully changes intermediate values which is what happened in our case. By breaking the operation into two, we prevent the use case where fmsub applies, even for optimized builds under our current build flags configuration. The compiler then decomposes the operation into separate fsub and fmul instructions which corrects the result.

See also
dotnet/runtime#64591
https://stackoverflow.com/questions/51124436/strange-issue-with-floating-point-accuracy-on-arm64

On aarch64 and when computing the perpendicular distance, we need to
avoid the fmsub (Fused Multiply-Subtract) because it can return
slightly different precision results when evaluating expressions
like
  x = a - (b * c)
such as we did (before this patch) in perpendicular-distance.  Instead,
we now store the result of the multiplication (b * c) and then subtract
it from a which avoids (in all build types) fmsub.

This error occurs because the C   standard allows implementations to
use higher precision throughout calculations before storing to the destination
type.  This can allow for differences in the final result if using higher
precision meaningfully changes intermediate values which is what happened in
our case.  By breaking the operation into two, we prevent the use case where
fmsub applies, even for optimized builds under our current build flags
configuration.

See also
  dotnet/runtime#64591
  https://stackoverflow.com/questions/51124436/strange-issue-with-floating-point-accuracy-on-arm64
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@grooverdan
Copy link
Member

Ah, like #482. Good POC fix. I don't think it will take compilers long to started fusing a split bit of code. Is _attribute__((target("fp-contract=off")) on a inline function for this secion?

@DaveGosselin-MariaDB
Copy link
Member Author

Ah, like #482. Good POC fix. I don't think it will take compilers long to started fusing a split bit of code. Is _attribute__((target("fp-contract=off")) on a inline function for this secion?

Thank you 😄 I wasn't aware of fp-contract=off, I will update the patch accordingly.

@DaveGosselin-MariaDB
Copy link
Member Author

DaveGosselin-MariaDB commented Sep 27, 2024

@grooverdan
When I supply __attribute__((target("fp-contract=off")), the compiler complains:

' fp-contract=off' is not a recognized feature for this target (ignoring feature)

Googling a bit doesn't seem to turn up much useful. Maybe I'm holding it wrong. I looked at #482 and didn't see a use of it in that commit. Additionally, cmake/floating_point.cmake is gone from our codebase, was there a problem with it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants