Godot: Building with -ffast-math causes floating-point value differences depending on compiler (GCC vs Clang)

Created on 22 Dec 2018  路  4Comments  路  Source: godotengine/godot

Godot version:
master @ e8cdbf99e9bd9757f8d2630e66ba12654b05fbda

OS/device including version:
Linux 4.19.10, GCC 8.2.1, Clang 7.0.1

Issue description:
When building with the release_debug target, the value of a single pixel of movement is different when building with GCC compared to LLVM/Clang. I've narrowed it down to the -ffast-math flag that's used in the release_debug CCFLAGS variable. Was found when testing out input according to #24363.

Configuration | GCC | LLVM
-------- | ------------ | -------------
release_debug, -ffast-math | 1 x 1 | 0.999023 x 0.998333
release_debug, no -ffast-math | 1 x 1 | 1 x 1

Steps to reproduce:
1) Build with Clang 7.0.1 on Linux
2) Run attached example scene with script
3) See above results when moving mouse by a pixel

Minimal reproduction project:
input_test.zip

bug confirmed high priority linuxbsd buildsystem

Most helpful comment

I guess the question is, what's turning mouse coordinates into floats, and can it be changed to use pure integer mathematics? Floating point problems might pop up again in the future.

I agree that the obvious immediate answer is to disable -ffast-math, but it might be worth benchmarking to see if there's any meaningful performance differences. If it's less than 1% difference, I'd say let's just dump the compiler flag.

All 4 comments

CC @hpvb

Tested locally and confirmed those results on Mageia 7:

  • Clang 7.0.0 gives non-whole deltas,
  • GCC 8.2.1 works fine.

I'm not sure there's a whole lot we can do about this except for disabling -ffast-math. That flag is supposed to generate compiler-specific floating point inaccuracies.

Maybe build all of the releases with the exact same compiler could help though?

I guess the question is, what's turning mouse coordinates into floats, and can it be changed to use pure integer mathematics? Floating point problems might pop up again in the future.

I agree that the obvious immediate answer is to disable -ffast-math, but it might be worth benchmarking to see if there's any meaningful performance differences. If it's less than 1% difference, I'd say let's just dump the compiler flag.

Was this page helpful?
0 / 5 - 0 ratings