From c2dca161c0ed455a962d23f8e2fcb64143c5e674 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Thu, 29 Feb 2024 07:39:32 +0600 Subject: Use instead of platform-specific intrinsics Change-Id: I79636ff9c3b2fe601b0b3c94a111b36af0011775 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164131 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- sal/rtl/math.cxx | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) (limited to 'sal') diff --git a/sal/rtl/math.cxx b/sal/rtl/math.cxx index fe45b90a8297..5b6c780b5001 100644 --- a/sal/rtl/math.cxx +++ b/sal/rtl/math.cxx @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -118,18 +119,6 @@ bool isRepresentableInteger(double fAbsValue) return nInt == fAbsValue; } -// Returns 1-based index of least significant bit in a number, or zero if number is zero -int findFirstSetBit(unsigned n) -{ -#if defined _WIN32 - unsigned long pos; - unsigned char bNonZero = _BitScanForward(&pos, n); - return (bNonZero == 0) ? 0 : pos + 1; -#else - return __builtin_ffs(n); -#endif -} - /** Returns number of binary bits for fractional part of the number Expects a proper non-negative double value, not +-INF, not NAN */ @@ -138,19 +127,13 @@ int getBitsInFracPart(double fAbsValue) assert(std::isfinite(fAbsValue) && fAbsValue >= 0.0); if (fAbsValue == 0.0) return 0; - auto pValParts = reinterpret_cast(&fAbsValue); - int nExponent = pValParts->inf_parts.exponent - 1023; + auto& rValParts = reinterpret_cast(&fAbsValue)->parts; + int nExponent = rValParts.exponent - 1023; if (nExponent >= 52) return 0; // All bits in fraction are in integer part of the number - int nLeastSignificant = findFirstSetBit(pValParts->inf_parts.fraction_lo); - if (nLeastSignificant == 0) - { - nLeastSignificant = findFirstSetBit(pValParts->inf_parts.fraction_hi); - if (nLeastSignificant == 0) - nLeastSignificant = 53; // the implied leading 1 is the least significant - else - nLeastSignificant += 32; - } + int nLeastSignificant = rValParts.fraction + ? std::countr_zero(rValParts.fraction) + 1 + : 53; // the implied leading 1 is the least significant int nFracSignificant = 53 - nLeastSignificant; int nBitsInFracPart = nFracSignificant - nExponent; -- cgit