Hacker News new | ask | show | jobs
by TazeTSchnitzel 1387 days ago
Global state is the root of so many evils! FPU rounding mode, FPU flush-to-zero mode, C locale, errno, and probably some other things should all be eliminated. The functionality should still exist but not as global flags.
2 comments

At least many of those are thread-local. But not C locale, it is truly horrible.
OTOH MXCSR being threadlocal means that automatically linking crtfastmath.o makes even less sense as it only affects the inital thread that loaded the object so you still need to set FTY/DAZ manually if you really want them.

And implicit locales should just die. It's sad that even newer functionality like std::format relies on them. Sadder that if it didn't then you'd probably have compiler developers pulling shit like GCC/libstdc++ does for std::from_chars [0] which defeats the entire point of that function but hey, at least they can mark that as implemented. Not like there are suitably licensed implementations of the functionality [1] available that they could use instead if they don't want to implement float parsing themselves.

[0] https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/s...

[1] https://github.com/fastfloat/fast_float

I thought that std::format avoided most of the implicit locale dependency. I know it has some for date formatting though.
I wonder if it would make sense for the processor to scope these settings to stack frames, and clear them when the appropriate ret happens.

Somewhere on this page there's a discussion of dirty upper half states in Intel vector instructions, and something similar might help there.