I am in the process of optimizing the most demanding function in a Unity 3d game. The most costly subroutine is the unity Mathf.Abs method which is being called on floating point values(NEVER DOUBLES). In cases, calls to this function are adding multiple milliseconds to the frame render delay. The code base is confidential so you will have to take my word that the Abs calls are central to the algorithm.
While deep profiling I discovered that mathf. Abs is just a wrapper that calls the much faster system.math.abs that is used for doubles. It seems that if I could avoid the wrapper entirely and simply call an equivalent of system.Math.Abs designed for float32, I would get significant speedup for free.
Can someone explain to me why it's so difficult to find one? The float libs I tested on NuGet are also converting the results from a double version.
I looked into the GNU implementation that used a a float_long union struct and a masking operation. Could someone steer me in the right direction of implementing this in my own namespace or finding one that will help me out?