News for hackers. Stuff that matters.
Re:Own Constant Folder in C/C++ by parasti on Saturday June 22, 2024 @08:26AM (#40758606)
A lesson I learned very early on: don't use -ffast-math unless you know what it does. It has a very appealing name that suggests nice things. You probably won't ever need it.
Re:Own Constant Folder in C/C++ by adgjlsfhk1 on Saturday June 22, 2024 @09:44AM (#40759107)
I prefer -funsafemath. Who doesn't want their math to be fun and safe?
Re:Own Constant Folder in C/C++ by glitchc on Saturday June 22, 2024 @10:00AM (#40759219)
I don't know how many people got your joke, but that flag actually says unsafe math. The -f prefix signifies a floating point flag.
Re:Own Constant Folder in C/C++ by rockwotj on Saturday June 22, 2024 @10:18AM (#40759319)
I am pretty sure the -f is for feature. Because there are flags like -fno-exceptions and -fcoroutines
Re:Own Constant Folder in C/C++ by jkrejcha on Saturday June 22, 2024 @11:33AM (#40759773)
It's a feature flag, they're not all necessarily floating point related. As an example though, I still intentionally humorously misread -funroll-loops as funroll loops even though it's f(eature) unroll loops
Re:Own Constant Folder in C/C++ by hackcasual on Sunday June 23, 2024 @12:01AM (#40764684)
The f in that case stands for fruit
Re:Own Constant Folder in C/C++ by SassyBird on Saturday June 22, 2024 @09:37AM (#40759053)
And even if you do know what it does, it’s very impractical given that it’s a global option. Turning it on for selected portions of code would be a completely different game.
Re:Own Constant Folder in C/C++ by swatcoder on Saturday June 22, 2024 @11:51AM (#40759909)
You're mistaken.

You can/would just use it in the translation units where you want it; usually for numerical code where you want certain optimizations or behaviors and know that the tradeoffs are irrelevant.

It's mostly harmless for everday application math anyway, and so enabling it for your whole application isn't a catastrophe, but it's not what people who know what they're doing would usually do. It's usually used for a specific file or perhaps a specific support library.

Re:Own Constant Folder in C/C++ by leni536 on Saturday June 22, 2024 @05:44PM (#40762476)
-ffast-math affects other translation units too, because it introduces a global initialization that affects some CPU flags. You can't really contain it to a single TU.
Re:Own Constant Folder in C/C++ by senkora on Saturday June 22, 2024 @08:58PM (#40763698)
It seems like this depends on whether you specify -ffast-math when linking or only when compiling: https://stackoverflow.com/a/68938551

My understanding is that if you don't specify -ffast-math when linking then you shouldn't get crtfastmath.o linked in.

Re:Own Constant Folder in C/C++ by adgjlsfhk1 on Saturday June 22, 2024 @10:37PM (#40764280)
so this is complicated by the fact that GCC has a bug until last year where it would set the subnormal truncation flag when it wasn't supposed to.
Re:Own Constant Folder in C/C++ by adgjlsfhk1 on Saturday June 22, 2024 @09:45AM (#40759111)
Julia has this (via a @fastmath macro) and it's so nice!