Commit b688f9bc authored by Tomasz Wlostowski's avatar Tomasz Wlostowski Committed by Maciej Suminski
Browse files

math_util: speed up rescaling on 64-bit platforms by using native 128-bit types

parent 655721d9
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include <cstdlib>
#include <climits>
#include <math/math_util.h>
#include <stdint.h>

template<>
int rescale( int aNumerator, int aValue, int aDenominator )
@@ -38,6 +39,9 @@ int rescale( int aNumerator, int aValue, int aDenominator )
template<>
int64_t rescale( int64_t aNumerator, int64_t aValue, int64_t aDenominator )
{
#ifdef __x86_64__
    return ( (__int128_t) aNumerator * (__int128_t) aValue ) / aDenominator;
#else
    int64_t r = 0;
    int64_t sign = ( ( aNumerator < 0 ) ? -1 : 1 ) * ( aDenominator < 0 ? -1 : 1 ) *
                                                     ( aValue < 0 ? -1 : 1 );
@@ -84,4 +88,5 @@ int64_t rescale( int64_t aNumerator, int64_t aValue, int64_t aDenominator )

        return t1 * sign;
    }
#endif
}