News for hackers. Stuff that matters.
Re:Own Constant Folder in C/C++ by gpderetta on Saturday June 22, 2024 @10:52AM (#40759512)
You can set fast math (or a subset of it) on a translation unit basis.
Re:Own Constant Folder in C/C++ by tialaramex on Saturday June 22, 2024 @12:59PM (#40760424)
Because the language works by textual inclusion and so a "translation unit" isn't really just your code this is much more likely to result in nasty surprises, up to and including ODR violations.
Re:Own Constant Folder in C/C++ by gpderetta on Saturday June 22, 2024 @01:47PM (#40760752)
Yes, if you try hard enough I'm sure you can find ways to screw up.

From a practical point of view it is fine.

Re:Own Constant Folder in C/C++ by cozzyd on Saturday June 22, 2024 @02:58PM (#40761255)
Or even on a per function basis, at least with gcc (no clue about clang...)
Re:Own Constant Folder in C/C++ by gpderetta on Saturday June 22, 2024 @03:01PM (#40761270)
In principle yes, you can use Attribute optimize, but I wouldn't rely on it. Too many bugs open against it.
Re:Own Constant Folder in C/C++ by cozzyd on Saturday June 22, 2024 @03:07PM (#40761312)
It's worked for me in the past but maybe I got lucky.
Re:Own Constant Folder in C/C++ by pdw on Saturday June 22, 2024 @05:41PM (#40762447)
That's not really true. If you link a shared library that was compiled with -ffast-math, that will affect the entire program. https://moyix.blogspot.com/2022/09/someones-been-messing-wit...
Re:Own Constant Folder in C/C++ by gpderetta on Saturday June 22, 2024 @09:13PM (#40763771)
To enable this "feature" I believe you have to specify fast math while linking the .so, it is not enough to do it when compiling.

It had also been fixed recent GCC versions.