math_util: speed up rescaling on 64-bit platforms by using native 128-bit types
This commit is contained in:
parent
655721d9ae
commit
b688f9bc20
|
@ -27,20 +27,24 @@
|
|||
#include <cstdlib>
|
||||
#include <climits>
|
||||
#include <math/math_util.h>
|
||||
#include <stdint.h>
|
||||
|
||||
template <>
|
||||
template<>
|
||||
int rescale( int aNumerator, int aValue, int aDenominator )
|
||||
{
|
||||
return (int) ( (int64_t) aNumerator * (int64_t) aValue / (int64_t) aDenominator );
|
||||
}
|
||||
|
||||
|
||||
template <>
|
||||
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 );
|
||||
( aValue < 0 ? -1 : 1 );
|
||||
|
||||
int64_t a = std::abs( aNumerator );
|
||||
int64_t b = std::abs( aValue );
|
||||
|
@ -84,4 +88,5 @@ int64_t rescale( int64_t aNumerator, int64_t aValue, int64_t aDenominator )
|
|||
|
||||
return t1 * sign;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue