diff --git a/src/osd/eigccx86.h b/src/osd/eigccx86.h index b3831d21524..3c8f63aa47e 100644 --- a/src/osd/eigccx86.h +++ b/src/osd/eigccx86.h @@ -456,6 +456,40 @@ _recip_approx(float value) #endif +/*------------------------------------------------- + mul_64x64 - perform a signed 64 bit x 64 bit + multiply and return the full 128 bit result +-------------------------------------------------*/ + +#ifdef __x86_64__ +#define mul_64x64 _mul_64x64 +inline int64_t ATTR_FORCE_INLINE +_mul_64x64(int64_t a, int64_t b, int64_t *hi) +{ + __int128 const r(__int128(a) * b); + *hi = int64_t(uint64_t((unsigned __int128)r >> 64)); + return int64_t(uint64_t((unsigned __int128)r)); +} +#endif + + +/*------------------------------------------------- + mulu_64x64 - perform an unsigned 64 bit x 64 + bit multiply and return the full 128 bit result +-------------------------------------------------*/ + +#ifdef __x86_64__ +#define mulu_64x64 _mulu_64x64 +inline uint64_t ATTR_FORCE_INLINE +_mulu_64x64(uint64_t a, uint64_t b, uint64_t *hi) +{ + unsigned __int128 const r((unsigned __int128)a * b); + *hi = uint64_t(r >> 64); + return uint64_t(r); +} +#endif + + /*************************************************************************** INLINE BIT MANIPULATION FUNCTIONS diff --git a/src/osd/eminline.h b/src/osd/eminline.h index 1f543a21b36..eb8ffaa9748 100644 --- a/src/osd/eminline.h +++ b/src/osd/eminline.h @@ -268,10 +268,10 @@ inline float recip_approx(float value) #ifndef mul_64x64 inline int64_t mul_64x64(int64_t a, int64_t b, int64_t *hi) { - uint64_t const a_hi = uint32_t(a >> 32); - uint64_t const b_hi = uint32_t(b >> 32); - uint64_t const a_lo = uint32_t(a); - uint64_t const b_lo = uint32_t(b); + uint64_t const a_hi = uint64_t(a) >> 32; + uint64_t const b_hi = uint64_t(b) >> 32; + uint64_t const a_lo = uint32_t(uint64_t(a)); + uint64_t const b_lo = uint32_t(uint64_t(b)); uint64_t const ab_lo = a_lo * b_lo; uint64_t const ab_m1 = a_hi * b_lo; @@ -317,6 +317,8 @@ inline uint64_t mulu_64x64(uint64_t a, uint64_t b, uint64_t *hi) } #endif + + /*************************************************************************** INLINE BIT MANIPULATION FUNCTIONS ***************************************************************************/