News for hackers. Stuff that matters.
Re:Own Constant Folder in C/C++ by nickelpro on Saturday June 22, 2024 @01:34PM (#40760672)
If you're using floating point at all you have declared you don't care about determinism or absolute precision across platforms.

Fast math is simply saying "I care even less than IEEE"

This is perfectly appropriate in many settings, but _especially_ video games where such deterministic results are completely irrelevant.

Re:Own Constant Folder in C/C++ by aw1621107 on Saturday June 22, 2024 @03:05PM (#40761298)
> This is perfectly appropriate in many settings, but _especially_ video games where such deterministic results are completely irrelevant.

I'm not sure I'd agree. Off the top of my head, a potentially significant benefit to deterministic floating-point is allowing you to send updates/inputs instead of world state in multiplayer games, which could be a substantial improvement in network traffic demand. It would also allow for smaller/simpler cross-machine/platform replays, though I don't know how much that feature is desired in comparison.

Re:Own Constant Folder in C/C++ by comex on Saturday June 22, 2024 @03:18PM (#40761403)
Indeed, but this isn't hypothetical. A large fraction of multiplayer games operate by sending inputs and requiring the simulation to be deterministic.

(Some of those are single-platform or lack cross-play support, and thus only need consistency between different machines running the same build. That makes compiler optimizations less of an issue. However, some do support cross-play, and thus need consistency between different builds – using different compilers – of the same source code.)

Re:Own Constant Folder in C/C++ by nickelpro on Saturday June 22, 2024 @11:02PM (#40764408)
The existence of situations where the optimization is not appropriate, such as multiplayer input replay, does not invalidate the many situations where it is appropriate.
Re:Own Constant Folder in C/C++ by aw1621107 on Sunday June 23, 2024 @12:20AM (#40764757)
Sure, but I'm not sure anyone is trying to argue that -ffast-math is never appropriate. I was just trying to point out that your original claim that deterministic floating point is "completely irrelevant" to games was too strong.
Re:Own Constant Folder in C/C++ by immibis on Saturday June 22, 2024 @03:07PM (#40761316)
Actually, floating-point math is mostly deterministic. There is an exception for rounding errors in transcendental functions.

The perception of nondeterminism came specifically from x87, which had 80-bit native floating-point registers, which were different from every other platform's 64-bit default, and forcing values to 64-bit all the time cost performance, so compilers secretly turned data types to different ones when compiling for x87, therefore giving different results. It would be like if the compiler for ARM secretly changed every use of 'float' into 'double'.

Re:Own Constant Folder in C/C++ by nickelpro on Saturday June 22, 2024 @11:03PM (#40764418)
The existence of a theoretically pure floating-point behavior doesn't have any impact on the reality of the implementations we program for.