diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2024-02-29 07:39:32 +0600 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2024-02-29 04:01:48 +0100 |
commit | c2dca161c0ed455a962d23f8e2fcb64143c5e674 (patch) | |
tree | 4431886bbfd13b69656c2ba7ffde73e8205a28fe /sal | |
parent | e2473fe3a547e5a11d3b91ab8ded833bf5b74356 (diff) |
Use <bit> instead of platform-specific intrinsics
Change-Id: I79636ff9c3b2fe601b0b3c94a111b36af0011775
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164131
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sal')
-rw-r--r-- | sal/rtl/math.cxx | 29 |
1 files changed, 6 insertions, 23 deletions
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 <rtl/math.hxx> #include <algorithm> +#include <bit> #include <cassert> #include <cfenv> #include <cmath> @@ -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<const sal_math_Double*>(&fAbsValue); - int nExponent = pValParts->inf_parts.exponent - 1023; + auto& rValParts = reinterpret_cast<const sal_math_Double*>(&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; |