I’m working on a project where float denormals have a big impact on performance.
To clarify, float denormals are floating point numbers that are so close to 0 that its format isn’t well supported by the CPU anymore, leading to incredibly slow performance.
Any floating point calculations that tend to gradually go towards 0 are potentially impacted. In my case, that’s audio DSP stuff, but I can imagine that things like physics calculations are potentially affected too.
(For reference: https://randomascii.wordpress.com/2012/05/20/thats-not-normalthe-performance-of-odd-floats/ and also the javadoc of Float.MIN_NORMAL).
Currently, I either add a small offset or add a check to ‘nudge’ these values to 0 (the latter is surprisingly often faster than adding an offset), but that is both impractical in a lot of cases and has a performance impact in itself.
It seems it’s possible to disable float denormals on the CPU so that such numbers simply become 0 (the linked article touches upon this), so I’m thinking of creating a little dll and JNI library to do that in java.
I think it would help my project tremendously, and I guess it could be a nice exercise for me.
Now my question is: Is it actually possible, especially within the context of a JVM? I mean I’m quite out of the loop of native programming, so maybe I’m unaware of something that might make this a no-go?
Or maybe something like this already exists somewhere? (I’ve googled, but I couldn’t find anything myself).