Skip to content

Invalid Abs and Absf implementation, compiler optimization and external libraries #33

Description

@FirefoxMetzger
constexpr inline float _MM_CALLCONV Absf(float x)
        {
            return (x < 0) ? x * -1 : x;
        }

Does not result in the same behavior as std::abs (or any other abs implementation I've checked to date). The reason for this is hidden in the IEEE 754 - 2008 Comparisons shall ignore the sign of zero (so +0 = -0). This means that the given implementation would return Absf(-0) ==> -0 as opposed to Absf(-0) ==> 0. So I assume is is a bug in the code? Same story for the double version.

Further the compiler cannot optimize the branch yealing poor performance (compared to just removing the sign bit). Which is what every implementation I've checked so far does.

Before I submit a pull request for this, is there any limitation on using an 'external' math library? This would should significantly improve performance if said library supports extended command sets like SSE4.2 or AVX2 (if present on the target architecture, which is quite common).

Usually I am not to picky about these optimizations, but imo the math operations (which are core operations for most algebra based programms) should be as efficient as humanly possible.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions