[libc-commits] [libc] [libc][stdfix] Implement `countlsfx` functions (PR #114318)
via libc-commits
libc-commits at lists.llvm.org
Sat Nov 2 21:52:46 PDT 2024
================
@@ -142,6 +160,25 @@ template <typename T> LIBC_INLINE constexpr T abs(T x) {
}
}
+template <typename T>
+LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_fixed_point_v<T>, int>
+countls(T x) {
+ using FXRep = FXRep<T>;
+ using BitType = typename FXRep::StorageType;
+ constexpr int CONTAIN_LEN = cpp::numeric_limits<BitType>::digits;
+ constexpr int PADDING_LEN = CONTAIN_LEN - FXRep::VALUE_LEN;
+
+ if constexpr (FXRep::SIGN_LEN != 0) {
+ if (x < 0) {
+ x = -(x + FXRep::EPS());
----------------
duncpro wrote:
This is fixed in [cc87a9a](https://github.com/llvm/llvm-project/commit/cc87a9ac973131db1047a22ebfb2b0db2d2f1926).
https://github.com/llvm/llvm-project/blob/cc87a9ac973131db1047a22ebfb2b0db2d2f1926/libc/src/__support/fixed_point/fx_bits.h#L165-L168
https://github.com/llvm/llvm-project/pull/114318
More information about the libc-commits
mailing list