[libc-commits] [libc] [libc][stdfix] Implement `countlsfx` functions in libc. (PR #126597)

Krishna Pandey via libc-commits libc-commits at lists.llvm.org
Tue Feb 11 14:01:28 PST 2025


https://github.com/krishna2803 updated https://github.com/llvm/llvm-project/pull/126597

>From cbb321f8ee1fdbede3da46ce9bba71ecf60d49c2 Mon Sep 17 00:00:00 2001
From: krishna2803 <kpandey81930 at gmail.com>
Date: Sun, 2 Feb 2025 01:02:44 +0530
Subject: [PATCH 01/17] feat: implement template meta `countls`

---
 libc/src/__support/fixed_point/fx_bits.h | 35 +++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/libc/src/__support/fixed_point/fx_bits.h b/libc/src/__support/fixed_point/fx_bits.h
index 225ea417760a0..a955ee67745c2 100644
--- a/libc/src/__support/fixed_point/fx_bits.h
+++ b/libc/src/__support/fixed_point/fx_bits.h
@@ -12,8 +12,9 @@
 #include "include/llvm-libc-macros/stdfix-macros.h"
 #include "src/__support/CPP/bit.h"
 #include "src/__support/CPP/type_traits.h"
+#include "src/__support/CPP/limits.h" // numeric_limits
 #include "src/__support/macros/attributes.h" // LIBC_INLINE
-#include "src/__support/macros/config.h"
+#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
 #include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
 #include "src/__support/math_extras.h"
 
@@ -50,6 +51,12 @@ template <typename T> struct FXBits {
   static constexpr StorageType SIGN_MASK =
       (fx_rep::SIGN_LEN == 0 ? 0 : StorageType(1) << SIGN_OFFSET);
 
+  // mask for <integral | fraction>
+  static constexpr StorageType VALUE_MASK = INTEGRAL_MASK | FRACTION_MASK;
+
+  // mask for <sign | integral | fraction>
+  static constexpr StorageType TOTAL_MASK = SIGN_MASK | VALUE_MASK;
+
 public:
   LIBC_INLINE constexpr FXBits() = default;
 
@@ -74,6 +81,12 @@ template <typename T> struct FXBits {
     return (value & INTEGRAL_MASK) >> INTEGRAL_OFFSET;
   }
 
+  // returns complete bitstring representation the fixed point number
+  // the bitstring is of the form: padding | sign | integral | fraction
+  LIBC_INLINE constexpr StorageType get_bits() {
+    return (value & TOTAL_MASK) >> FRACTION_OFFSET;
+  }
+
   // TODO: replace bool with Sign
   LIBC_INLINE constexpr bool get_sign() {
     return static_cast<bool>((value & SIGN_MASK) >> SIGN_OFFSET);
@@ -163,6 +176,26 @@ template <typename T> LIBC_INLINE constexpr T round(T x, int n) {
   return bit_and((x + round_bit), rounding_mask);
 }
 
+// count leading zeros
+template <typename T>
+LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_fixed_point_v<T>, int>
+countls(T f) {
+  using FXRep = FXRep<T>;
+  using BitType = typename FXRep::StorageType;
+  using FXBits = FXBits<T>;
+
+  constexpr int CONTAIN_LEN = cpp::numeric_limits<BitType>::digits;
+  constexpr int PADDING_LEN = CONTAIN_LEN - (FXRep::INTEGRAL_LEN + FXRep::FRACTION_LEN);
+
+  if constexpr (FXRep::SIGN_LEN != 0) {
+    if (x < 0)
+      x = bit_not(x);
+  }
+
+  BitType value_bits = FXBits(x)::get_bits();
+  return cpp::countl_zero(value_bits) - PADDING_LEN;
+}
+
 } // namespace fixed_point
 } // namespace LIBC_NAMESPACE_DECL
 

>From cddf53e4c4951d8368c645c8250188afcf061085 Mon Sep 17 00:00:00 2001
From: krishna2803 <kpandey81930 at gmail.com>
Date: Sun, 2 Feb 2025 01:04:11 +0530
Subject: [PATCH 02/17] chore: add `limits.h` header to CmakeLists.txt

---
 libc/src/__support/fixed_point/CMakeLists.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libc/src/__support/fixed_point/CMakeLists.txt b/libc/src/__support/fixed_point/CMakeLists.txt
index 3b744081765e4..b415e2c00c488 100644
--- a/libc/src/__support/fixed_point/CMakeLists.txt
+++ b/libc/src/__support/fixed_point/CMakeLists.txt
@@ -19,6 +19,7 @@ add_header_library(
     libc.src.__support.macros.optimization
     libc.src.__support.CPP.type_traits
     libc.src.__support.CPP.bit
+    libc.src.__support.CPP.limits
     libc.src.__support.math_extras
 )
 

>From bcccd52d31589f230cbd309239daca9235792341 Mon Sep 17 00:00:00 2001
From: krishna2803 <kpandey81930 at gmail.com>
Date: Sun, 2 Feb 2025 01:15:23 +0530
Subject: [PATCH 03/17] add: `countlsfx` functions

---
 libc/src/stdfix/CMakeLists.txt | 30 ++++++++++++++++++++++++++++++
 libc/src/stdfix/countlshk.cpp  | 20 ++++++++++++++++++++
 libc/src/stdfix/countlshk.h    | 21 +++++++++++++++++++++
 libc/src/stdfix/countlshr.cpp  | 20 ++++++++++++++++++++
 libc/src/stdfix/countlshr.h    | 21 +++++++++++++++++++++
 libc/src/stdfix/countlsk.cpp   | 20 ++++++++++++++++++++
 libc/src/stdfix/countlsk.h     | 21 +++++++++++++++++++++
 libc/src/stdfix/countlslk.cpp  | 20 ++++++++++++++++++++
 libc/src/stdfix/countlslk.h    | 21 +++++++++++++++++++++
 libc/src/stdfix/countlslr.cpp  | 20 ++++++++++++++++++++
 libc/src/stdfix/countlslr.h    | 21 +++++++++++++++++++++
 libc/src/stdfix/countlsr.cpp   | 20 ++++++++++++++++++++
 libc/src/stdfix/countlsr.h     | 21 +++++++++++++++++++++
 libc/src/stdfix/countlsuhk.cpp | 20 ++++++++++++++++++++
 libc/src/stdfix/countlsuhk.h   | 21 +++++++++++++++++++++
 libc/src/stdfix/countlsuhr.cpp | 20 ++++++++++++++++++++
 libc/src/stdfix/countlsuhr.h   | 21 +++++++++++++++++++++
 libc/src/stdfix/countlsuk.cpp  | 20 ++++++++++++++++++++
 libc/src/stdfix/countlsuk.h    | 21 +++++++++++++++++++++
 libc/src/stdfix/countlsulk.cpp | 20 ++++++++++++++++++++
 libc/src/stdfix/countlsulk.h   | 21 +++++++++++++++++++++
 libc/src/stdfix/countlsulr.cpp | 20 ++++++++++++++++++++
 libc/src/stdfix/countlsulr.h   | 21 +++++++++++++++++++++
 libc/src/stdfix/countlsur.cpp  | 20 ++++++++++++++++++++
 libc/src/stdfix/countlsur.h    | 21 +++++++++++++++++++++
 25 files changed, 522 insertions(+)
 create mode 100644 libc/src/stdfix/countlshk.cpp
 create mode 100644 libc/src/stdfix/countlshk.h
 create mode 100644 libc/src/stdfix/countlshr.cpp
 create mode 100644 libc/src/stdfix/countlshr.h
 create mode 100644 libc/src/stdfix/countlsk.cpp
 create mode 100644 libc/src/stdfix/countlsk.h
 create mode 100644 libc/src/stdfix/countlslk.cpp
 create mode 100644 libc/src/stdfix/countlslk.h
 create mode 100644 libc/src/stdfix/countlslr.cpp
 create mode 100644 libc/src/stdfix/countlslr.h
 create mode 100644 libc/src/stdfix/countlsr.cpp
 create mode 100644 libc/src/stdfix/countlsr.h
 create mode 100644 libc/src/stdfix/countlsuhk.cpp
 create mode 100644 libc/src/stdfix/countlsuhk.h
 create mode 100644 libc/src/stdfix/countlsuhr.cpp
 create mode 100644 libc/src/stdfix/countlsuhr.h
 create mode 100644 libc/src/stdfix/countlsuk.cpp
 create mode 100644 libc/src/stdfix/countlsuk.h
 create mode 100644 libc/src/stdfix/countlsulk.cpp
 create mode 100644 libc/src/stdfix/countlsulk.h
 create mode 100644 libc/src/stdfix/countlsulr.cpp
 create mode 100644 libc/src/stdfix/countlsulr.h
 create mode 100644 libc/src/stdfix/countlsur.cpp
 create mode 100644 libc/src/stdfix/countlsur.h

diff --git a/libc/src/stdfix/CMakeLists.txt b/libc/src/stdfix/CMakeLists.txt
index 815f739d23efa..ac5b31320a105 100644
--- a/libc/src/stdfix/CMakeLists.txt
+++ b/libc/src/stdfix/CMakeLists.txt
@@ -104,3 +104,33 @@ add_entrypoint_object(
     libc.src.__support.fixed_point.fx_rep
     libc.src.__support.CPP.bit
 )
+
+
+foreach(suffix IN ITEMS hr r lr hk k lk uhr ur ulr uhk uk ulk)
+  add_entrypoint_object(
+    countls${suffix}
+    HDRS
+      countls${suffix}.h
+    SRCS
+      countls${suffix}.cpp
+    COMPILE_OPTIONS
+      ${libc_opt_high_flag}
+    DEPENDS
+      libc.src.__support.fixed_point.fx_bits
+  )
+  if(LIBC_COMPILER_HAS_PADDING_ON_UNSIGNED_FIXED_POINT)
+    add_entrypoint_object(
+      countls${suffix}_padding_on_unsigned_fixed_point
+      HDRS
+        countls${suffix}.h
+      SRCS
+        countls${suffix}.cpp
+      COMPILE_OPTIONS
+        ${libc_opt_high_flag}
+        -Xclang=-fpadding-on-unsigned-fixed-point
+      DEPENDS
+        libc.src.__support.fixed_point.fx_bits
+    )
+  endif()
+
+endforeach()
diff --git a/libc/src/stdfix/countlshk.cpp b/libc/src/stdfix/countlshk.cpp
new file mode 100644
index 0000000000000..65230dd688a7c
--- /dev/null
+++ b/libc/src/stdfix/countlshk.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation for countlshk function  --------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "countlshk.h"
+#include "src/__support/common.h"
+#include "src/__support/fixed_point/fx_bits.h"
+#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, countlshk, (short accum f)) {
+  return fixed_point::countls(f);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/countlshk.h b/libc/src/stdfix/countlshk.h
new file mode 100644
index 0000000000000..ecbc9075dcedf
--- /dev/null
+++ b/libc/src/stdfix/countlshk.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for countlshk function -----------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_STDFIX_COUNTLSHK_H
+#define LLVM_LIBC_SRC_STDFIX_COUNTLSHK_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
+
+namespace LIBC_NAMESPACE_DECL {
+
+int countlshk(short accum f);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_COUNTLSHK_H
diff --git a/libc/src/stdfix/countlshr.cpp b/libc/src/stdfix/countlshr.cpp
new file mode 100644
index 0000000000000..d07bab8c4a1cd
--- /dev/null
+++ b/libc/src/stdfix/countlshr.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation for countlshr function  --------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "countlshr.h"
+#include "src/__support/common.h"
+#include "src/__support/fixed_point/fx_bits.h"
+#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, countlshr, (short fract f)) {
+  return fixed_point::countls(f);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/countlshr.h b/libc/src/stdfix/countlshr.h
new file mode 100644
index 0000000000000..728b687315918
--- /dev/null
+++ b/libc/src/stdfix/countlshr.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for countlshr function -----------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_STDFIX_COUNTLSHR_H
+#define LLVM_LIBC_SRC_STDFIX_COUNTLSHR_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
+
+namespace LIBC_NAMESPACE_DECL {
+
+int countlshr(short fract f);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_COUNTLSHR_H
diff --git a/libc/src/stdfix/countlsk.cpp b/libc/src/stdfix/countlsk.cpp
new file mode 100644
index 0000000000000..87c009aba0cb5
--- /dev/null
+++ b/libc/src/stdfix/countlsk.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation for countlsk function  --------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "countlsk.h"
+#include "src/__support/common.h"
+#include "src/__support/fixed_point/fx_bits.h"
+#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, countlsk, (accum f)) {
+  return fixed_point::countls(f);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/countlsk.h b/libc/src/stdfix/countlsk.h
new file mode 100644
index 0000000000000..b7012da95a9c9
--- /dev/null
+++ b/libc/src/stdfix/countlsk.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for countlsk function -----------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_STDFIX_COUNTLSK_H
+#define LLVM_LIBC_SRC_STDFIX_COUNTLSK_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
+
+namespace LIBC_NAMESPACE_DECL {
+
+int countlsk(accum f);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_COUNTLSK_H
diff --git a/libc/src/stdfix/countlslk.cpp b/libc/src/stdfix/countlslk.cpp
new file mode 100644
index 0000000000000..16120b2f55a11
--- /dev/null
+++ b/libc/src/stdfix/countlslk.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation for countlslk function  --------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "countlslk.h"
+#include "src/__support/common.h"
+#include "src/__support/fixed_point/fx_bits.h"
+#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, countlslk, (long accum f)) {
+  return fixed_point::countls(f);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/countlslk.h b/libc/src/stdfix/countlslk.h
new file mode 100644
index 0000000000000..90a2ccc33ce64
--- /dev/null
+++ b/libc/src/stdfix/countlslk.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for countlslk function -----------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_STDFIX_COUNTLSLK_H
+#define LLVM_LIBC_SRC_STDFIX_COUNTLSLK_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
+
+namespace LIBC_NAMESPACE_DECL {
+
+int countlslk(long accum f);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_COUNTLSLK_H
diff --git a/libc/src/stdfix/countlslr.cpp b/libc/src/stdfix/countlslr.cpp
new file mode 100644
index 0000000000000..9e0369db3b4a0
--- /dev/null
+++ b/libc/src/stdfix/countlslr.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation for countlslr function  --------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "countlslr.h"
+#include "src/__support/common.h"
+#include "src/__support/fixed_point/fx_bits.h"
+#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, countlslr, (long fract f)) {
+  return fixed_point::countls(f);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/countlslr.h b/libc/src/stdfix/countlslr.h
new file mode 100644
index 0000000000000..b1565b7024e7c
--- /dev/null
+++ b/libc/src/stdfix/countlslr.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for countlslr function -----------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_STDFIX_COUNTLSLR_H
+#define LLVM_LIBC_SRC_STDFIX_COUNTLSLR_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
+
+namespace LIBC_NAMESPACE_DECL {
+
+int countlslr(long fract f);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_COUNTLSLR_H
diff --git a/libc/src/stdfix/countlsr.cpp b/libc/src/stdfix/countlsr.cpp
new file mode 100644
index 0000000000000..d18e673a3066d
--- /dev/null
+++ b/libc/src/stdfix/countlsr.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation for countlsr function  --------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "countlsr.h"
+#include "src/__support/common.h"
+#include "src/__support/fixed_point/fx_bits.h"
+#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, countlsr, (fract f)) {
+  return fixed_point::countls(f);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/countlsr.h b/libc/src/stdfix/countlsr.h
new file mode 100644
index 0000000000000..c50bd0a773e57
--- /dev/null
+++ b/libc/src/stdfix/countlsr.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for countlsr function -----------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_STDFIX_COUNTLSR_H
+#define LLVM_LIBC_SRC_STDFIX_COUNTLSR_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
+
+namespace LIBC_NAMESPACE_DECL {
+
+int countlsr(fract f);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_COUNTLSR_H
diff --git a/libc/src/stdfix/countlsuhk.cpp b/libc/src/stdfix/countlsuhk.cpp
new file mode 100644
index 0000000000000..8a24508b83bcb
--- /dev/null
+++ b/libc/src/stdfix/countlsuhk.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation for countlsuhk function  --------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "countlsuhk.h"
+#include "src/__support/common.h"
+#include "src/__support/fixed_point/fx_bits.h"
+#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, countlsuhk, (unsigned short accum f)) {
+  return fixed_point::countls(f);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/countlsuhk.h b/libc/src/stdfix/countlsuhk.h
new file mode 100644
index 0000000000000..fcb2fec3500d4
--- /dev/null
+++ b/libc/src/stdfix/countlsuhk.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for countlsuhk function -----------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_STDFIX_COUNTLSUHK_H
+#define LLVM_LIBC_SRC_STDFIX_COUNTLSUHK_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
+
+namespace LIBC_NAMESPACE_DECL {
+
+int countlsuhk(unsigned short accum f);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_COUNTLSUHK_H
diff --git a/libc/src/stdfix/countlsuhr.cpp b/libc/src/stdfix/countlsuhr.cpp
new file mode 100644
index 0000000000000..6dec26c788cd9
--- /dev/null
+++ b/libc/src/stdfix/countlsuhr.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation for countlsuhr function  --------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "countlsuhr.h"
+#include "src/__support/common.h"
+#include "src/__support/fixed_point/fx_bits.h"
+#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, countlsuhr, (unsigned short fract f)) {
+  return fixed_point::countls(f);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/countlsuhr.h b/libc/src/stdfix/countlsuhr.h
new file mode 100644
index 0000000000000..c6ce001d38b11
--- /dev/null
+++ b/libc/src/stdfix/countlsuhr.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for countlsuhr function -----------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_STDFIX_COUNTLSUHR_H
+#define LLVM_LIBC_SRC_STDFIX_COUNTLSUHR_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
+
+namespace LIBC_NAMESPACE_DECL {
+
+int countlsuhr(unsigned long fract f);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_COUNTLSUHR_H
diff --git a/libc/src/stdfix/countlsuk.cpp b/libc/src/stdfix/countlsuk.cpp
new file mode 100644
index 0000000000000..98ebf096940e4
--- /dev/null
+++ b/libc/src/stdfix/countlsuk.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation for countlsuhk function  --------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "countlsuhk.h"
+#include "src/__support/common.h"
+#include "src/__support/fixed_point/fx_bits.h"
+#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, countlsuhk, (unsigned accum f)) {
+  return fixed_point::countls(f);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/countlsuk.h b/libc/src/stdfix/countlsuk.h
new file mode 100644
index 0000000000000..b912e75fb9002
--- /dev/null
+++ b/libc/src/stdfix/countlsuk.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for countlsuk function -----------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_STDFIX_COUNTLSUK_H
+#define LLVM_LIBC_SRC_STDFIX_COUNTLSUK_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
+
+namespace LIBC_NAMESPACE_DECL {
+
+int countlsuk(unsigned accum f);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_COUNTLSUK_H
diff --git a/libc/src/stdfix/countlsulk.cpp b/libc/src/stdfix/countlsulk.cpp
new file mode 100644
index 0000000000000..043c919a653ea
--- /dev/null
+++ b/libc/src/stdfix/countlsulk.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation for countlsulk function  --------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "countlsulk.h"
+#include "src/__support/common.h"
+#include "src/__support/fixed_point/fx_bits.h"
+#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, countlsulk, (unsigned long accum f)) {
+  return fixed_point::countls(f);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/countlsulk.h b/libc/src/stdfix/countlsulk.h
new file mode 100644
index 0000000000000..55ca9d2e20ff0
--- /dev/null
+++ b/libc/src/stdfix/countlsulk.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for countlsulk function -----------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_STDFIX_COUNTLSULK_H
+#define LLVM_LIBC_SRC_STDFIX_COUNTLSULK_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
+
+namespace LIBC_NAMESPACE_DECL {
+
+int countlsulk(unsigned long accum f);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_COUNTLSULK_H
diff --git a/libc/src/stdfix/countlsulr.cpp b/libc/src/stdfix/countlsulr.cpp
new file mode 100644
index 0000000000000..a77eaeabce69f
--- /dev/null
+++ b/libc/src/stdfix/countlsulr.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation for countlsulr function  --------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "countlsulr.h"
+#include "src/__support/common.h"
+#include "src/__support/fixed_point/fx_bits.h"
+#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, countlsulr, (unsigned long fract f)) {
+  return fixed_point::countls(f);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/countlsulr.h b/libc/src/stdfix/countlsulr.h
new file mode 100644
index 0000000000000..59e7d726d01b9
--- /dev/null
+++ b/libc/src/stdfix/countlsulr.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for countlsulr function -----------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_STDFIX_COUNTLSULR_H
+#define LLVM_LIBC_SRC_STDFIX_COUNTLSULR_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
+
+namespace LIBC_NAMESPACE_DECL {
+
+int countlsulr(unsigned long fract f);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_COUNTLSULR_H
diff --git a/libc/src/stdfix/countlsur.cpp b/libc/src/stdfix/countlsur.cpp
new file mode 100644
index 0000000000000..6dcb54bdca442
--- /dev/null
+++ b/libc/src/stdfix/countlsur.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation for countlsur function  --------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "countlsur.h"
+#include "src/__support/common.h"
+#include "src/__support/fixed_point/fx_bits.h"
+#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, countlsur, (unsigned fract f)) {
+  return fixed_point::countls(f);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/countlsur.h b/libc/src/stdfix/countlsur.h
new file mode 100644
index 0000000000000..85dec93bbcd5c
--- /dev/null
+++ b/libc/src/stdfix/countlsur.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for countlsur function -----------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_STDFIX_COUNTLSUR_H
+#define LLVM_LIBC_SRC_STDFIX_COUNTLSUR_H
+
+#include "include/llvm-libc-macros/stdfix-macros.h"
+#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
+
+namespace LIBC_NAMESPACE_DECL {
+
+int countlsur(unsigned fract f);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDFIX_COUNTLSUR_H

>From 647a16c06f5d275a5683b5e7a12cb6e8af16d22f Mon Sep 17 00:00:00 2001
From: krishna2803 <kpandey81930 at gmail.com>
Date: Sun, 2 Feb 2025 01:17:14 +0530
Subject: [PATCH 04/17] chore: add `padding_on_unsigned_fixed_point`

---
 .../cmake/modules/CheckCompilerFeatures.cmake |  5 ++
 .../check_padding_on_unsigned_fixed_point.cpp |  5 ++
 libc/include/stdfix.yaml                      | 84 +++++++++++++++++++
 3 files changed, 94 insertions(+)
 create mode 100644 libc/cmake/modules/compiler_features/check_padding_on_unsigned_fixed_point.cpp

diff --git a/libc/cmake/modules/CheckCompilerFeatures.cmake b/libc/cmake/modules/CheckCompilerFeatures.cmake
index a5ea66a5935b7..ccb0e4bfc5097 100644
--- a/libc/cmake/modules/CheckCompilerFeatures.cmake
+++ b/libc/cmake/modules/CheckCompilerFeatures.cmake
@@ -15,6 +15,7 @@ set(
     "fixed_point"
     "cfloat16"
     "cfloat128"
+    "padding_on_unsigned_fixed_point"
 )
 
 # Making sure ALL_COMPILER_FEATURES is sorted.
@@ -64,6 +65,8 @@ foreach(feature IN LISTS ALL_COMPILER_FEATURES)
   set(link_options "")
   if(${feature} STREQUAL "fixed_point")
     list(APPEND compile_options "-ffixed-point")
+  elseif(${feature} STREQUAL "padding_on_unsigned_fixed_point")
+    list(APPEND compile_options "-ffixed-point -Xclang=-fpadding-on-unsigned-fixed-point")
   elseif(${feature} MATCHES "^builtin_" OR
          ${feature} STREQUAL "float16_conversion")
     set(compile_options ${LIBC_COMPILE_OPTIONS_DEFAULT})
@@ -112,6 +115,8 @@ foreach(feature IN LISTS ALL_COMPILER_FEATURES)
       set(LIBC_TYPES_HAS_FLOAT128 TRUE)
     elseif(${feature} STREQUAL "fixed_point")
       set(LIBC_COMPILER_HAS_FIXED_POINT TRUE)
+    elseif(${feature} STREQUAL "padding_on_unsigned_fixed_point")
+      set(LIBC_COMPILER_HAS_PADDING_ON_UNSIGNED_FIXED_POINT TRUE)
     elseif(${feature} STREQUAL "cfloat16")
       set(LIBC_TYPES_HAS_CFLOAT16 TRUE)
     elseif(${feature} STREQUAL "cfloat128")
diff --git a/libc/cmake/modules/compiler_features/check_padding_on_unsigned_fixed_point.cpp b/libc/cmake/modules/compiler_features/check_padding_on_unsigned_fixed_point.cpp
new file mode 100644
index 0000000000000..40b4da8c79621
--- /dev/null
+++ b/libc/cmake/modules/compiler_features/check_padding_on_unsigned_fixed_point.cpp
@@ -0,0 +1,5 @@
+#include "include/llvm-libc-macros/stdfix-macros.h"
+
+#ifndef LIBC_COMPILER_HAS_PADDING_ON_UNSIGNED_FIXED_POINT
+#error unsupported
+#endif
diff --git a/libc/include/stdfix.yaml b/libc/include/stdfix.yaml
index 9663ac0c7df4d..0abf2f3a9b3b6 100644
--- a/libc/include/stdfix.yaml
+++ b/libc/include/stdfix.yaml
@@ -306,3 +306,87 @@ functions:
     arguments:
       - type: unsigned int
     guard: LIBC_COMPILER_HAS_FIXED_POINT
+  - name: countlshr
+    standards:
+      - stdc_ext
+    return_type: int
+    arguments:
+      - type: short fract
+    guard: LIBC_COMPILER_HAS_FIXED_POINT
+  - name: countlsr
+    standards:
+      - stdc_ext
+    return_type: int
+    arguments:
+      - type: fract
+    guard: LIBC_COMPILER_HAS_FIXED_POINT
+  - name: countlslr
+    standards:
+      - stdc_ext
+    return_type: int
+    arguments:
+      - type: long fract
+    guard: LIBC_COMPILER_HAS_FIXED_POINT
+  - name: countlshk
+    standards:
+      - stdc_ext
+    return_type: int
+    arguments:
+      - type: short accum
+    guard: LIBC_COMPILER_HAS_FIXED_POINT
+  - name: countlsk
+    standards:
+      - stdc_ext
+    return_type: int
+    arguments:
+      - type: accum
+    guard: LIBC_COMPILER_HAS_FIXED_POINT
+  - name: countlslk
+    standards:
+      - stdc_ext
+    return_type: int
+    arguments:
+      - type: long accum
+    guard: LIBC_COMPILER_HAS_FIXED_POINT
+  - name: countlsuhr
+    standards:
+      - stdc_ext
+    return_type: int
+    arguments:
+      - type: unsigned short fract
+    guard: LIBC_COMPILER_HAS_FIXED_POINT
+  - name: countlsur
+    standards:
+      - stdc_ext
+    return_type: int
+    arguments:
+      - type: unsigned fract
+    guard: LIBC_COMPILER_HAS_FIXED_POINT
+  - name: countlsulr
+    standards:
+      - stdc_ext
+    return_type: int
+    arguments:
+      - type: unsigned long fract
+    guard: LIBC_COMPILER_HAS_FIXED_POINT
+  - name: countlsuhk
+    standards:
+      - stdc_ext
+    return_type: int
+    arguments:
+      - type: unsigned short accum
+    guard: LIBC_COMPILER_HAS_FIXED_POINT
+  - name: countlsuk
+    standards:
+      - stdc_ext
+    return_type: int
+    arguments:
+      - type: unsigned accum
+    guard: LIBC_COMPILER_HAS_FIXED_POINT
+  - name: countlsulk
+    standards:
+      - stdc_ext
+    return_type: int
+    arguments:
+      - type: unsigned long accum
+    guard: LIBC_COMPILER_HAS_FIXED_POINT

>From ca4d5325bc1cb45620b166a809661ad701e3bdc2 Mon Sep 17 00:00:00 2001
From: krishna2803 <kpandey81930 at gmail.com>
Date: Sun, 2 Feb 2025 01:18:16 +0530
Subject: [PATCH 05/17] chore: add entrypoints

---
 libc/config/baremetal/arm/entrypoints.txt   | 12 ++++++++++++
 libc/config/baremetal/riscv/entrypoints.txt | 12 ++++++++++++
 libc/config/linux/riscv/entrypoints.txt     | 12 ++++++++++++
 libc/config/linux/x86_64/entrypoints.txt    | 12 ++++++++++++
 4 files changed, 48 insertions(+)

diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index 694cd7b1993ca..351f727389e3a 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -469,6 +469,18 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
     libc.src.stdfix.ukbits
     libc.src.stdfix.lkbits
     libc.src.stdfix.ulkbits
+    libc.src.stdfix.countlshr
+    libc.src.stdfix.countlsr
+    libc.src.stdfix.countlslr
+    libc.src.stdfix.countlshk
+    libc.src.stdfix.countlsk
+    libc.src.stdfix.countlslk
+    libc.src.stdfix.countlsuhr
+    libc.src.stdfix.countlsur
+    libc.src.stdfix.countlsulr
+    libc.src.stdfix.countlsuhk
+    libc.src.stdfix.countlsuk
+    libc.src.stdfix.countlsulk
   )
 endif()
 
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 667ab40dca999..39c70a22a21e0 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -464,6 +464,18 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
     libc.src.stdfix.ukbits
     libc.src.stdfix.lkbits
     libc.src.stdfix.ulkbits
+    libc.src.stdfix.countlshr
+    libc.src.stdfix.countlsr
+    libc.src.stdfix.countlslr
+    libc.src.stdfix.countlshk
+    libc.src.stdfix.countlsk
+    libc.src.stdfix.countlslk
+    libc.src.stdfix.countlsuhr
+    libc.src.stdfix.countlsur
+    libc.src.stdfix.countlsulr
+    libc.src.stdfix.countlsuhk
+    libc.src.stdfix.countlsuk
+    libc.src.stdfix.countlsulk
   )
 endif()
 
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 14a05a2f3fbf2..cb68fb077a869 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -744,6 +744,18 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
     # TODO: https://github.com/llvm/llvm-project/issues/115778
     libc.src.stdfix.lkbits
     libc.src.stdfix.ulkbits
+    libc.src.stdfix.countlshr
+    libc.src.stdfix.countlsr
+    libc.src.stdfix.countlslr
+    libc.src.stdfix.countlshk
+    libc.src.stdfix.countlsk
+    libc.src.stdfix.countlslk
+    libc.src.stdfix.countlsuhr
+    libc.src.stdfix.countlsur
+    libc.src.stdfix.countlsulr
+    libc.src.stdfix.countlsuhk
+    libc.src.stdfix.countlsuk
+    libc.src.stdfix.countlsulk
   )
 endif()
 
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 366e4d34294d1..ea276f3c96386 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -869,6 +869,18 @@ if(LIBC_COMPILER_HAS_FIXED_POINT)
     libc.src.stdfix.ukbits
     libc.src.stdfix.lkbits
     libc.src.stdfix.ulkbits
+    libc.src.stdfix.countlshr
+    libc.src.stdfix.countlsr
+    libc.src.stdfix.countlslr
+    libc.src.stdfix.countlshk
+    libc.src.stdfix.countlsk
+    libc.src.stdfix.countlslk
+    libc.src.stdfix.countlsuhr
+    libc.src.stdfix.countlsur
+    libc.src.stdfix.countlsulr
+    libc.src.stdfix.countlsuhk
+    libc.src.stdfix.countlsuk
+    libc.src.stdfix.countlsulk
   )
 endif()
 

>From 5c2894f6ef1e47aa75933f40f27bb244326dcd35 Mon Sep 17 00:00:00 2001
From: krishna2803 <kpandey81930 at gmail.com>
Date: Sun, 2 Feb 2025 01:18:52 +0530
Subject: [PATCH 06/17] add: unit tests for `countlsfx` functions

---
 libc/test/src/stdfix/CMakeLists.txt      | 35 +++++++++++++
 libc/test/src/stdfix/CountlsTest.h       | 63 ++++++++++++++++++++++++
 libc/test/src/stdfix/countlshk_test.cpp  | 13 +++++
 libc/test/src/stdfix/countlshr_test.cpp  | 13 +++++
 libc/test/src/stdfix/countlsk_test.cpp   | 13 +++++
 libc/test/src/stdfix/countlslk_test.cpp  | 13 +++++
 libc/test/src/stdfix/countlslr_test.cpp  | 13 +++++
 libc/test/src/stdfix/countlsr_test.cpp   | 13 +++++
 libc/test/src/stdfix/countlsuhk_test.cpp | 13 +++++
 libc/test/src/stdfix/countlsuhr_test.cpp | 13 +++++
 libc/test/src/stdfix/countlsuk_test.cpp  | 13 +++++
 libc/test/src/stdfix/countlsulk_test.cpp | 13 +++++
 libc/test/src/stdfix/countlsulr_test.cpp | 13 +++++
 libc/test/src/stdfix/countlsur_test.cpp  | 13 +++++
 14 files changed, 254 insertions(+)
 create mode 100644 libc/test/src/stdfix/CountlsTest.h
 create mode 100644 libc/test/src/stdfix/countlshk_test.cpp
 create mode 100644 libc/test/src/stdfix/countlshr_test.cpp
 create mode 100644 libc/test/src/stdfix/countlsk_test.cpp
 create mode 100644 libc/test/src/stdfix/countlslk_test.cpp
 create mode 100644 libc/test/src/stdfix/countlslr_test.cpp
 create mode 100644 libc/test/src/stdfix/countlsr_test.cpp
 create mode 100644 libc/test/src/stdfix/countlsuhk_test.cpp
 create mode 100644 libc/test/src/stdfix/countlsuhr_test.cpp
 create mode 100644 libc/test/src/stdfix/countlsuk_test.cpp
 create mode 100644 libc/test/src/stdfix/countlsulk_test.cpp
 create mode 100644 libc/test/src/stdfix/countlsulr_test.cpp
 create mode 100644 libc/test/src/stdfix/countlsur_test.cpp

diff --git a/libc/test/src/stdfix/CMakeLists.txt b/libc/test/src/stdfix/CMakeLists.txt
index 90d20438edb4b..6d111038be5b1 100644
--- a/libc/test/src/stdfix/CMakeLists.txt
+++ b/libc/test/src/stdfix/CMakeLists.txt
@@ -73,6 +73,41 @@ foreach(suffix IN ITEMS hr r lr hk k lk uhr ur ulr uhk uk ulk)
       libc.src.__support.CPP.bit
       libc.src.__support.fixed_point.fx_bits
   )
+
+  add_libc_test(
+    countls${suffix}_test
+    SUITE
+      libc-stdfix-tests
+    HDRS
+      CountlsTest.h
+    SRCS
+      countls${suffix}_test.cpp
+    COMPILE_OPTIONS
+      -O3
+    DEPENDS
+      libc.src.stdfix.countls${suffix}
+      libc.src.__support.fixed_point.fx_rep
+      libc.src.__support.fixed_point.fx_bits
+
+    if(LIBC_COMPILER_HAS_PADDING_ON_UNSIGNED_FIXED_POINT)
+      add_libc_test(
+        countls${suffix}_padding_on_unsigned_fixed_point_test
+        SUITE
+          libc-stdfix-tests
+        HDRS
+          CountlsTest.h
+        SRCS
+          countls${suffix}_test.cpp
+        COMPILE_OPTIONS
+          -O3
+          -Xclang=-fpadding-on-unsigned-fixed-point
+        DEPENDS
+          libc.src.stdfix.countls${suffix}_padding_on_unsigned_fixed_point
+          libc.src.__support.fixed_point.fx_rep
+          libc.src.__support.fixed_point.fx_bits
+      )
+    endif()
+  )
 endforeach()
 
 add_libc_test(
diff --git a/libc/test/src/stdfix/CountlsTest.h b/libc/test/src/stdfix/CountlsTest.h
new file mode 100644
index 0000000000000..d4a4083591730
--- /dev/null
+++ b/libc/test/src/stdfix/CountlsTest.h
@@ -0,0 +1,63 @@
+//===-- Utility class to test countls -------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "test/UnitTest/Test.h"
+
+#include "src/__support/fixed_point/fx_rep.h"
+
+template <typename T> class CountlsTest : public LIBC_NAMESPACE::testing::Test {
+
+  using FXRep = LIBC_NAMESPACE::fixed_point::FXRep<T>;
+  static constexpr T zero = FXRep::ZERO();
+  static constexpr T max = FXRep::MAX();
+  static constexpr T min = FXRep::MIN();
+  static constexpr T one_half = FXRep::ONE_HALF();
+  static constexpr T one_fourth = FXRep::ONE_FOURTH();
+  static constexpr T eps = FXRep::EPS();
+
+  static constexpr auto value_len =
+      FXRep::INTEGRAL_LEN + FXRep::FRACTION_LEN;
+
+public:
+  typedef int (*CountlsFunc)(T);
+
+  void testSpecialNumbers(CountlsFunc func) {
+    constexpr bool is_signed = (FXRep::SIGN_LEN > 0);
+
+    EXPECT_EQ(FXRep::INTEGRAL_LEN, func(one_half));
+    EXPECT_EQ(FXRep::INTEGRAL_LEN + 1, func(one_fourth));
+    EXPECT_EQ(value_len, func(zero));
+    EXPECT_EQ(value_len - 1, func(eps));
+    EXPECT_EQ(0, func(max));
+    // If signed, left shifting the minimum value will overflow, so countls = 0.
+    // If unsigned, the minimum value is zero, so countls is the number of value
+    // bits according to ISO/IEC TR 18037.
+    EXPECT_EQ(is_signed ? 0 : value_len, func(min));
+
+    if (10 <= static_cast<int>(max)) {
+      EXPECT_EQ(FXRep::INTEGRAL_LEN - 4, func(10));
+    }
+
+    if (static_cast<int>(min) <= -10) {
+      EXPECT_EQ(FXRep::INTEGRAL_LEN - 4, func(-10));
+    }
+
+    if constexpr (is_signed) {
+      EXPECT_EQ(value_len, func(-eps));
+      EXPECT_EQ(FXRep::INTEGRAL_LEN + 1, func(-one_half));
+      if (FXRep::FRACTION_LEN >= 2) {
+        EXPECT_EQ(FXRep::INTEGRAL_LEN + 2, func(-one_fourth));
+      }
+    }
+  }
+};
+
+#define LIST_COUNTLS_TESTS(T, func)                                            \
+  using LlvmLibcCountlsTest = CountlsTest<T>;                                  \
+  TEST_F(LlvmLibcCountlsTest, SpecialNumbers) { testSpecialNumbers(&func); }   \
+  static_assert(true, "Require semicolon.")
\ No newline at end of file
diff --git a/libc/test/src/stdfix/countlshk_test.cpp b/libc/test/src/stdfix/countlshk_test.cpp
new file mode 100644
index 0000000000000..d5654981f91b7
--- /dev/null
+++ b/libc/test/src/stdfix/countlshk_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for countlshk ----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CountlsTest.h"
+
+#include "src/stdfix/countlshk.h"
+
+LIST_COUNTLS_TESTS(short accum, LIBC_NAMESPACE::countlshk);
\ No newline at end of file
diff --git a/libc/test/src/stdfix/countlshr_test.cpp b/libc/test/src/stdfix/countlshr_test.cpp
new file mode 100644
index 0000000000000..2021553be7e6c
--- /dev/null
+++ b/libc/test/src/stdfix/countlshr_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for countlshr ----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CountlsTest.h"
+
+#include "src/stdfix/countlshr.h"
+
+LIST_COUNTLS_TESTS(short fract, LIBC_NAMESPACE::countlshr);
\ No newline at end of file
diff --git a/libc/test/src/stdfix/countlsk_test.cpp b/libc/test/src/stdfix/countlsk_test.cpp
new file mode 100644
index 0000000000000..e7c71add68fa6
--- /dev/null
+++ b/libc/test/src/stdfix/countlsk_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for countlsk ----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CountlsTest.h"
+
+#include "src/stdfix/countlsk.h"
+
+LIST_COUNTLS_TESTS(accum, LIBC_NAMESPACE::countlsk);
\ No newline at end of file
diff --git a/libc/test/src/stdfix/countlslk_test.cpp b/libc/test/src/stdfix/countlslk_test.cpp
new file mode 100644
index 0000000000000..4c7f2970733ea
--- /dev/null
+++ b/libc/test/src/stdfix/countlslk_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for countlslk ----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CountlsTest.h"
+
+#include "src/stdfix/countlslk.h"
+
+LIST_COUNTLS_TESTS(long accum, LIBC_NAMESPACE::countlslk);
\ No newline at end of file
diff --git a/libc/test/src/stdfix/countlslr_test.cpp b/libc/test/src/stdfix/countlslr_test.cpp
new file mode 100644
index 0000000000000..93b33597b9442
--- /dev/null
+++ b/libc/test/src/stdfix/countlslr_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for countlslr ----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CountlsTest.h"
+
+#include "src/stdfix/countlslr.h"
+
+LIST_COUNTLS_TESTS(long fract, LIBC_NAMESPACE::countlslr);
\ No newline at end of file
diff --git a/libc/test/src/stdfix/countlsr_test.cpp b/libc/test/src/stdfix/countlsr_test.cpp
new file mode 100644
index 0000000000000..d465c2e1eae01
--- /dev/null
+++ b/libc/test/src/stdfix/countlsr_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for countlsr ----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CountlsTest.h"
+
+#include "src/stdfix/countlsr.h"
+
+LIST_COUNTLS_TESTS(fract, LIBC_NAMESPACE::countlsr);
\ No newline at end of file
diff --git a/libc/test/src/stdfix/countlsuhk_test.cpp b/libc/test/src/stdfix/countlsuhk_test.cpp
new file mode 100644
index 0000000000000..b72328b5b1a90
--- /dev/null
+++ b/libc/test/src/stdfix/countlsuhk_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for countlsuhk ----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CountlsTest.h"
+
+#include "src/stdfix/countlsuhk.h"
+
+LIST_COUNTLS_TESTS(unsigned short accum, LIBC_NAMESPACE::countlsuhk);
\ No newline at end of file
diff --git a/libc/test/src/stdfix/countlsuhr_test.cpp b/libc/test/src/stdfix/countlsuhr_test.cpp
new file mode 100644
index 0000000000000..b82e105017330
--- /dev/null
+++ b/libc/test/src/stdfix/countlsuhr_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for countlsuhr ----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CountlsTest.h"
+
+#include "src/stdfix/countlsuhr.h"
+
+LIST_COUNTLS_TESTS(unsigned short fract, LIBC_NAMESPACE::countlsuhr);
\ No newline at end of file
diff --git a/libc/test/src/stdfix/countlsuk_test.cpp b/libc/test/src/stdfix/countlsuk_test.cpp
new file mode 100644
index 0000000000000..5ca66822fe6fb
--- /dev/null
+++ b/libc/test/src/stdfix/countlsuk_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for countlsuk ----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CountlsTest.h"
+
+#include "src/stdfix/countlsuk.h"
+
+LIST_COUNTLS_TESTS(unsigned accum, LIBC_NAMESPACE::countlsuk);
\ No newline at end of file
diff --git a/libc/test/src/stdfix/countlsulk_test.cpp b/libc/test/src/stdfix/countlsulk_test.cpp
new file mode 100644
index 0000000000000..762d4924bac48
--- /dev/null
+++ b/libc/test/src/stdfix/countlsulk_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for countlsulk ----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CountlsTest.h"
+
+#include "src/stdfix/countlsulk.h"
+
+LIST_COUNTLS_TESTS(unsigned long accum, LIBC_NAMESPACE::countlsulk);
\ No newline at end of file
diff --git a/libc/test/src/stdfix/countlsulr_test.cpp b/libc/test/src/stdfix/countlsulr_test.cpp
new file mode 100644
index 0000000000000..62c06b233e674
--- /dev/null
+++ b/libc/test/src/stdfix/countlsulr_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for countlsulr ----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CountlsTest.h"
+
+#include "src/stdfix/countlsulr.h"
+
+LIST_COUNTLS_TESTS(unsigned long fract, LIBC_NAMESPACE::countlsulr);
\ No newline at end of file
diff --git a/libc/test/src/stdfix/countlsur_test.cpp b/libc/test/src/stdfix/countlsur_test.cpp
new file mode 100644
index 0000000000000..49236db25d40a
--- /dev/null
+++ b/libc/test/src/stdfix/countlsur_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for countlsur ----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CountlsTest.h"
+
+#include "src/stdfix/countlsur.h"
+
+LIST_COUNTLS_TESTS(unsigned fract, LIBC_NAMESPACE::countlsur);
\ No newline at end of file

>From 519ae5df684c9f850688048aa80abfaccc1ddaac Mon Sep 17 00:00:00 2001
From: krishna2803 <kpandey81930 at gmail.com>
Date: Sun, 2 Feb 2025 01:19:06 +0530
Subject: [PATCH 07/17] chore: documentation update

---
 libc/docs/headers/math/stdfix.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/docs/headers/math/stdfix.rst b/libc/docs/headers/math/stdfix.rst
index 58052f000995c..4507f2b608bf1 100644
--- a/libc/docs/headers/math/stdfix.rst
+++ b/libc/docs/headers/math/stdfix.rst
@@ -73,7 +73,7 @@ The following functions are included in the ISO/IEC TR 18037:2008 standard.
 +---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+
 | \*bits        |                |             |               |            |                |             |                |             |               |            |                |             |
 +---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+
-| countls       |                |             |               |            |                |             |                |             |               |            |                |             |
+| countls       | |check|        | |check|     | |check|       | |check|    | |check|        | |check|     | |check|        | |check|     | |check|       | |check|    | |check|        | |check|     |
 +---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+
 | divi          |                |             |               |            |                |             |                |             |               |            |                |             |
 +---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+

>From e0acc36fd25ab4f75c2551598ce13fbf5d6d8fb3 Mon Sep 17 00:00:00 2001
From: krishna2803 <kpandey81930 at gmail.com>
Date: Tue, 4 Feb 2025 20:12:12 +0530
Subject: [PATCH 08/17] chore: remove -Xclang flags and tests with padding

---
 .../cmake/modules/CheckCompilerFeatures.cmake |  2 --
 libc/src/stdfix/CMakeLists.txt                | 14 --------------
 libc/test/src/stdfix/CMakeLists.txt           | 19 -------------------
 3 files changed, 35 deletions(-)

diff --git a/libc/cmake/modules/CheckCompilerFeatures.cmake b/libc/cmake/modules/CheckCompilerFeatures.cmake
index ccb0e4bfc5097..0ba07a08ef233 100644
--- a/libc/cmake/modules/CheckCompilerFeatures.cmake
+++ b/libc/cmake/modules/CheckCompilerFeatures.cmake
@@ -65,8 +65,6 @@ foreach(feature IN LISTS ALL_COMPILER_FEATURES)
   set(link_options "")
   if(${feature} STREQUAL "fixed_point")
     list(APPEND compile_options "-ffixed-point")
-  elseif(${feature} STREQUAL "padding_on_unsigned_fixed_point")
-    list(APPEND compile_options "-ffixed-point -Xclang=-fpadding-on-unsigned-fixed-point")
   elseif(${feature} MATCHES "^builtin_" OR
          ${feature} STREQUAL "float16_conversion")
     set(compile_options ${LIBC_COMPILE_OPTIONS_DEFAULT})
diff --git a/libc/src/stdfix/CMakeLists.txt b/libc/src/stdfix/CMakeLists.txt
index ac5b31320a105..8dd3212af138e 100644
--- a/libc/src/stdfix/CMakeLists.txt
+++ b/libc/src/stdfix/CMakeLists.txt
@@ -118,19 +118,5 @@ foreach(suffix IN ITEMS hr r lr hk k lk uhr ur ulr uhk uk ulk)
     DEPENDS
       libc.src.__support.fixed_point.fx_bits
   )
-  if(LIBC_COMPILER_HAS_PADDING_ON_UNSIGNED_FIXED_POINT)
-    add_entrypoint_object(
-      countls${suffix}_padding_on_unsigned_fixed_point
-      HDRS
-        countls${suffix}.h
-      SRCS
-        countls${suffix}.cpp
-      COMPILE_OPTIONS
-        ${libc_opt_high_flag}
-        -Xclang=-fpadding-on-unsigned-fixed-point
-      DEPENDS
-        libc.src.__support.fixed_point.fx_bits
-    )
-  endif()
 
 endforeach()
diff --git a/libc/test/src/stdfix/CMakeLists.txt b/libc/test/src/stdfix/CMakeLists.txt
index 6d111038be5b1..c8c4fd96bc2b3 100644
--- a/libc/test/src/stdfix/CMakeLists.txt
+++ b/libc/test/src/stdfix/CMakeLists.txt
@@ -88,25 +88,6 @@ foreach(suffix IN ITEMS hr r lr hk k lk uhr ur ulr uhk uk ulk)
       libc.src.stdfix.countls${suffix}
       libc.src.__support.fixed_point.fx_rep
       libc.src.__support.fixed_point.fx_bits
-
-    if(LIBC_COMPILER_HAS_PADDING_ON_UNSIGNED_FIXED_POINT)
-      add_libc_test(
-        countls${suffix}_padding_on_unsigned_fixed_point_test
-        SUITE
-          libc-stdfix-tests
-        HDRS
-          CountlsTest.h
-        SRCS
-          countls${suffix}_test.cpp
-        COMPILE_OPTIONS
-          -O3
-          -Xclang=-fpadding-on-unsigned-fixed-point
-        DEPENDS
-          libc.src.stdfix.countls${suffix}_padding_on_unsigned_fixed_point
-          libc.src.__support.fixed_point.fx_rep
-          libc.src.__support.fixed_point.fx_bits
-      )
-    endif()
   )
 endforeach()
 

>From c31e5398dd01051d3495689f4870ad93a4892248 Mon Sep 17 00:00:00 2001
From: krishna2803 <kpandey81930 at gmail.com>
Date: Tue, 4 Feb 2025 20:14:09 +0530
Subject: [PATCH 09/17] nit: share loop for countlsfx and roundfx

---
 libc/src/stdfix/CMakeLists.txt | 28 ++++++++++++----------------
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/libc/src/stdfix/CMakeLists.txt b/libc/src/stdfix/CMakeLists.txt
index 8dd3212af138e..3f6f9125a086b 100644
--- a/libc/src/stdfix/CMakeLists.txt
+++ b/libc/src/stdfix/CMakeLists.txt
@@ -53,6 +53,18 @@ foreach(suffix IN ITEMS hr r lr hk k lk uhr ur ulr uhk uk ulk)
       libc.src.__support.CPP.bit
       libc.src.__support.fixed_point.fx_bits
   )
+
+  add_entrypoint_object(
+    countls${suffix}
+    HDRS
+      countls${suffix}.h
+    SRCS
+      countls${suffix}.cpp
+    COMPILE_OPTIONS
+      ${libc_opt_high_flag}
+    DEPENDS
+      libc.src.__support.fixed_point.fx_bits
+  )
 endforeach()
 
 add_entrypoint_object(
@@ -104,19 +116,3 @@ add_entrypoint_object(
     libc.src.__support.fixed_point.fx_rep
     libc.src.__support.CPP.bit
 )
-
-
-foreach(suffix IN ITEMS hr r lr hk k lk uhr ur ulr uhk uk ulk)
-  add_entrypoint_object(
-    countls${suffix}
-    HDRS
-      countls${suffix}.h
-    SRCS
-      countls${suffix}.cpp
-    COMPILE_OPTIONS
-      ${libc_opt_high_flag}
-    DEPENDS
-      libc.src.__support.fixed_point.fx_bits
-  )
-
-endforeach()

>From 9b499bcb5a1894b4991c14885cd514746c6c634a Mon Sep 17 00:00:00 2001
From: krishna2803 <kpandey81930 at gmail.com>
Date: Wed, 5 Feb 2025 12:09:25 +0530
Subject: [PATCH 10/17] fix: use `FXRep:TOTAL_LEN` to incoporate for `SIGN_LEN`

---
 libc/src/__support/fixed_point/fx_bits.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/src/__support/fixed_point/fx_bits.h b/libc/src/__support/fixed_point/fx_bits.h
index a955ee67745c2..a9e0a82e9d51a 100644
--- a/libc/src/__support/fixed_point/fx_bits.h
+++ b/libc/src/__support/fixed_point/fx_bits.h
@@ -185,7 +185,7 @@ countls(T f) {
   using FXBits = FXBits<T>;
 
   constexpr int CONTAIN_LEN = cpp::numeric_limits<BitType>::digits;
-  constexpr int PADDING_LEN = CONTAIN_LEN - (FXRep::INTEGRAL_LEN + FXRep::FRACTION_LEN);
+  constexpr int PADDING_LEN = CONTAIN_LEN - FXRep::TOTAL_LEN;
 
   if constexpr (FXRep::SIGN_LEN != 0) {
     if (x < 0)

>From 632a6d8b0997b5c455af9e205bbf84defbb66a88 Mon Sep 17 00:00:00 2001
From: krishna2803 <kpandey81930 at gmail.com>
Date: Thu, 6 Feb 2025 04:24:00 +0530
Subject: [PATCH 11/17] remove: `padding_on_unsigned_fixed_point.cpp`

---
 libc/cmake/modules/CheckCompilerFeatures.cmake               | 3 ---
 .../check_padding_on_unsigned_fixed_point.cpp                | 5 -----
 2 files changed, 8 deletions(-)
 delete mode 100644 libc/cmake/modules/compiler_features/check_padding_on_unsigned_fixed_point.cpp

diff --git a/libc/cmake/modules/CheckCompilerFeatures.cmake b/libc/cmake/modules/CheckCompilerFeatures.cmake
index 0ba07a08ef233..a5ea66a5935b7 100644
--- a/libc/cmake/modules/CheckCompilerFeatures.cmake
+++ b/libc/cmake/modules/CheckCompilerFeatures.cmake
@@ -15,7 +15,6 @@ set(
     "fixed_point"
     "cfloat16"
     "cfloat128"
-    "padding_on_unsigned_fixed_point"
 )
 
 # Making sure ALL_COMPILER_FEATURES is sorted.
@@ -113,8 +112,6 @@ foreach(feature IN LISTS ALL_COMPILER_FEATURES)
       set(LIBC_TYPES_HAS_FLOAT128 TRUE)
     elseif(${feature} STREQUAL "fixed_point")
       set(LIBC_COMPILER_HAS_FIXED_POINT TRUE)
-    elseif(${feature} STREQUAL "padding_on_unsigned_fixed_point")
-      set(LIBC_COMPILER_HAS_PADDING_ON_UNSIGNED_FIXED_POINT TRUE)
     elseif(${feature} STREQUAL "cfloat16")
       set(LIBC_TYPES_HAS_CFLOAT16 TRUE)
     elseif(${feature} STREQUAL "cfloat128")
diff --git a/libc/cmake/modules/compiler_features/check_padding_on_unsigned_fixed_point.cpp b/libc/cmake/modules/compiler_features/check_padding_on_unsigned_fixed_point.cpp
deleted file mode 100644
index 40b4da8c79621..0000000000000
--- a/libc/cmake/modules/compiler_features/check_padding_on_unsigned_fixed_point.cpp
+++ /dev/null
@@ -1,5 +0,0 @@
-#include "include/llvm-libc-macros/stdfix-macros.h"
-
-#ifndef LIBC_COMPILER_HAS_PADDING_ON_UNSIGNED_FIXED_POINT
-#error unsupported
-#endif

>From 475945d9556edbe496dbd43af2461b52a51edf00 Mon Sep 17 00:00:00 2001
From: krishna2803 <kpandey81930 at gmail.com>
Date: Thu, 6 Feb 2025 04:26:03 +0530
Subject: [PATCH 12/17] chore: change `count leading zeros` to `count leading
 sign bits`

---
 libc/src/__support/fixed_point/fx_bits.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/src/__support/fixed_point/fx_bits.h b/libc/src/__support/fixed_point/fx_bits.h
index a9e0a82e9d51a..94f826a26fea2 100644
--- a/libc/src/__support/fixed_point/fx_bits.h
+++ b/libc/src/__support/fixed_point/fx_bits.h
@@ -176,7 +176,7 @@ template <typename T> LIBC_INLINE constexpr T round(T x, int n) {
   return bit_and((x + round_bit), rounding_mask);
 }
 
-// count leading zeros
+// count leading sign bits
 template <typename T>
 LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_fixed_point_v<T>, int>
 countls(T f) {

>From b146648ae201743d470d5a600acb2f47c50c45a4 Mon Sep 17 00:00:00 2001
From: krishna2803 <kpandey81930 at gmail.com>
Date: Thu, 6 Feb 2025 04:36:24 +0530
Subject: [PATCH 13/17] fix: ensure newline at end

---
 libc/test/src/stdfix/CountlsTest.h       | 2 +-
 libc/test/src/stdfix/countlshk_test.cpp  | 2 +-
 libc/test/src/stdfix/countlshr_test.cpp  | 2 +-
 libc/test/src/stdfix/countlsk_test.cpp   | 2 +-
 libc/test/src/stdfix/countlslk_test.cpp  | 2 +-
 libc/test/src/stdfix/countlslr_test.cpp  | 2 +-
 libc/test/src/stdfix/countlsr_test.cpp   | 2 +-
 libc/test/src/stdfix/countlsuhk_test.cpp | 2 +-
 libc/test/src/stdfix/countlsuhr_test.cpp | 2 +-
 libc/test/src/stdfix/countlsuk_test.cpp  | 2 +-
 libc/test/src/stdfix/countlsulk_test.cpp | 2 +-
 libc/test/src/stdfix/countlsulr_test.cpp | 2 +-
 libc/test/src/stdfix/countlsur_test.cpp  | 2 +-
 13 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/libc/test/src/stdfix/CountlsTest.h b/libc/test/src/stdfix/CountlsTest.h
index d4a4083591730..8bfea59b1862b 100644
--- a/libc/test/src/stdfix/CountlsTest.h
+++ b/libc/test/src/stdfix/CountlsTest.h
@@ -60,4 +60,4 @@ template <typename T> class CountlsTest : public LIBC_NAMESPACE::testing::Test {
 #define LIST_COUNTLS_TESTS(T, func)                                            \
   using LlvmLibcCountlsTest = CountlsTest<T>;                                  \
   TEST_F(LlvmLibcCountlsTest, SpecialNumbers) { testSpecialNumbers(&func); }   \
-  static_assert(true, "Require semicolon.")
\ No newline at end of file
+  static_assert(true, "Require semicolon.")
diff --git a/libc/test/src/stdfix/countlshk_test.cpp b/libc/test/src/stdfix/countlshk_test.cpp
index d5654981f91b7..d874758ab635b 100644
--- a/libc/test/src/stdfix/countlshk_test.cpp
+++ b/libc/test/src/stdfix/countlshk_test.cpp
@@ -10,4 +10,4 @@
 
 #include "src/stdfix/countlshk.h"
 
-LIST_COUNTLS_TESTS(short accum, LIBC_NAMESPACE::countlshk);
\ No newline at end of file
+LIST_COUNTLS_TESTS(short accum, LIBC_NAMESPACE::countlshk);
diff --git a/libc/test/src/stdfix/countlshr_test.cpp b/libc/test/src/stdfix/countlshr_test.cpp
index 2021553be7e6c..a30022f06603c 100644
--- a/libc/test/src/stdfix/countlshr_test.cpp
+++ b/libc/test/src/stdfix/countlshr_test.cpp
@@ -10,4 +10,4 @@
 
 #include "src/stdfix/countlshr.h"
 
-LIST_COUNTLS_TESTS(short fract, LIBC_NAMESPACE::countlshr);
\ No newline at end of file
+LIST_COUNTLS_TESTS(short fract, LIBC_NAMESPACE::countlshr);
diff --git a/libc/test/src/stdfix/countlsk_test.cpp b/libc/test/src/stdfix/countlsk_test.cpp
index e7c71add68fa6..ff98483360ef3 100644
--- a/libc/test/src/stdfix/countlsk_test.cpp
+++ b/libc/test/src/stdfix/countlsk_test.cpp
@@ -10,4 +10,4 @@
 
 #include "src/stdfix/countlsk.h"
 
-LIST_COUNTLS_TESTS(accum, LIBC_NAMESPACE::countlsk);
\ No newline at end of file
+LIST_COUNTLS_TESTS(accum, LIBC_NAMESPACE::countlsk);
diff --git a/libc/test/src/stdfix/countlslk_test.cpp b/libc/test/src/stdfix/countlslk_test.cpp
index 4c7f2970733ea..2ef735976ba15 100644
--- a/libc/test/src/stdfix/countlslk_test.cpp
+++ b/libc/test/src/stdfix/countlslk_test.cpp
@@ -10,4 +10,4 @@
 
 #include "src/stdfix/countlslk.h"
 
-LIST_COUNTLS_TESTS(long accum, LIBC_NAMESPACE::countlslk);
\ No newline at end of file
+LIST_COUNTLS_TESTS(long accum, LIBC_NAMESPACE::countlslk);
diff --git a/libc/test/src/stdfix/countlslr_test.cpp b/libc/test/src/stdfix/countlslr_test.cpp
index 93b33597b9442..0d21115d51260 100644
--- a/libc/test/src/stdfix/countlslr_test.cpp
+++ b/libc/test/src/stdfix/countlslr_test.cpp
@@ -10,4 +10,4 @@
 
 #include "src/stdfix/countlslr.h"
 
-LIST_COUNTLS_TESTS(long fract, LIBC_NAMESPACE::countlslr);
\ No newline at end of file
+LIST_COUNTLS_TESTS(long fract, LIBC_NAMESPACE::countlslr);
diff --git a/libc/test/src/stdfix/countlsr_test.cpp b/libc/test/src/stdfix/countlsr_test.cpp
index d465c2e1eae01..ac4ddcb140f00 100644
--- a/libc/test/src/stdfix/countlsr_test.cpp
+++ b/libc/test/src/stdfix/countlsr_test.cpp
@@ -10,4 +10,4 @@
 
 #include "src/stdfix/countlsr.h"
 
-LIST_COUNTLS_TESTS(fract, LIBC_NAMESPACE::countlsr);
\ No newline at end of file
+LIST_COUNTLS_TESTS(fract, LIBC_NAMESPACE::countlsr);
diff --git a/libc/test/src/stdfix/countlsuhk_test.cpp b/libc/test/src/stdfix/countlsuhk_test.cpp
index b72328b5b1a90..f4958cfd02fe3 100644
--- a/libc/test/src/stdfix/countlsuhk_test.cpp
+++ b/libc/test/src/stdfix/countlsuhk_test.cpp
@@ -10,4 +10,4 @@
 
 #include "src/stdfix/countlsuhk.h"
 
-LIST_COUNTLS_TESTS(unsigned short accum, LIBC_NAMESPACE::countlsuhk);
\ No newline at end of file
+LIST_COUNTLS_TESTS(unsigned short accum, LIBC_NAMESPACE::countlsuhk);
diff --git a/libc/test/src/stdfix/countlsuhr_test.cpp b/libc/test/src/stdfix/countlsuhr_test.cpp
index b82e105017330..3d41ec5ff925b 100644
--- a/libc/test/src/stdfix/countlsuhr_test.cpp
+++ b/libc/test/src/stdfix/countlsuhr_test.cpp
@@ -10,4 +10,4 @@
 
 #include "src/stdfix/countlsuhr.h"
 
-LIST_COUNTLS_TESTS(unsigned short fract, LIBC_NAMESPACE::countlsuhr);
\ No newline at end of file
+LIST_COUNTLS_TESTS(unsigned short fract, LIBC_NAMESPACE::countlsuhr);
diff --git a/libc/test/src/stdfix/countlsuk_test.cpp b/libc/test/src/stdfix/countlsuk_test.cpp
index 5ca66822fe6fb..be5b1fa2474cc 100644
--- a/libc/test/src/stdfix/countlsuk_test.cpp
+++ b/libc/test/src/stdfix/countlsuk_test.cpp
@@ -10,4 +10,4 @@
 
 #include "src/stdfix/countlsuk.h"
 
-LIST_COUNTLS_TESTS(unsigned accum, LIBC_NAMESPACE::countlsuk);
\ No newline at end of file
+LIST_COUNTLS_TESTS(unsigned accum, LIBC_NAMESPACE::countlsuk);
diff --git a/libc/test/src/stdfix/countlsulk_test.cpp b/libc/test/src/stdfix/countlsulk_test.cpp
index 762d4924bac48..e8b647aa810ac 100644
--- a/libc/test/src/stdfix/countlsulk_test.cpp
+++ b/libc/test/src/stdfix/countlsulk_test.cpp
@@ -10,4 +10,4 @@
 
 #include "src/stdfix/countlsulk.h"
 
-LIST_COUNTLS_TESTS(unsigned long accum, LIBC_NAMESPACE::countlsulk);
\ No newline at end of file
+LIST_COUNTLS_TESTS(unsigned long accum, LIBC_NAMESPACE::countlsulk);
diff --git a/libc/test/src/stdfix/countlsulr_test.cpp b/libc/test/src/stdfix/countlsulr_test.cpp
index 62c06b233e674..7a10a351384d5 100644
--- a/libc/test/src/stdfix/countlsulr_test.cpp
+++ b/libc/test/src/stdfix/countlsulr_test.cpp
@@ -10,4 +10,4 @@
 
 #include "src/stdfix/countlsulr.h"
 
-LIST_COUNTLS_TESTS(unsigned long fract, LIBC_NAMESPACE::countlsulr);
\ No newline at end of file
+LIST_COUNTLS_TESTS(unsigned long fract, LIBC_NAMESPACE::countlsulr);
diff --git a/libc/test/src/stdfix/countlsur_test.cpp b/libc/test/src/stdfix/countlsur_test.cpp
index 49236db25d40a..e7ca6ddffcc9d 100644
--- a/libc/test/src/stdfix/countlsur_test.cpp
+++ b/libc/test/src/stdfix/countlsur_test.cpp
@@ -10,4 +10,4 @@
 
 #include "src/stdfix/countlsur.h"
 
-LIST_COUNTLS_TESTS(unsigned fract, LIBC_NAMESPACE::countlsur);
\ No newline at end of file
+LIST_COUNTLS_TESTS(unsigned fract, LIBC_NAMESPACE::countlsur);

>From 659170d3dd86f7e19081eeb8c3b6dee4f425e970 Mon Sep 17 00:00:00 2001
From: krishna2803 <kpandey81930 at gmail.com>
Date: Thu, 6 Feb 2025 04:41:36 +0530
Subject: [PATCH 14/17] style: clang-format

---
 libc/src/__support/fixed_point/fx_bits.h | 6 +++---
 libc/src/stdfix/countlshk.cpp            | 2 +-
 libc/src/stdfix/countlshk.h              | 2 +-
 libc/src/stdfix/countlshr.cpp            | 2 +-
 libc/src/stdfix/countlshr.h              | 2 +-
 libc/src/stdfix/countlsk.cpp             | 6 ++----
 libc/src/stdfix/countlsk.h               | 2 +-
 libc/src/stdfix/countlslk.cpp            | 2 +-
 libc/src/stdfix/countlslk.h              | 2 +-
 libc/src/stdfix/countlslr.cpp            | 2 +-
 libc/src/stdfix/countlslr.h              | 2 +-
 libc/src/stdfix/countlsr.cpp             | 6 ++----
 libc/src/stdfix/countlsr.h               | 2 +-
 libc/src/stdfix/countlsuhk.cpp           | 2 +-
 libc/src/stdfix/countlsuhr.cpp           | 2 +-
 libc/src/stdfix/countlsuk.cpp            | 2 +-
 libc/src/stdfix/countlsuk.h              | 2 +-
 libc/src/stdfix/countlsulk.cpp           | 2 +-
 libc/src/stdfix/countlsulr.cpp           | 2 +-
 libc/src/stdfix/countlsur.cpp            | 2 +-
 libc/src/stdfix/countlsur.h              | 2 +-
 libc/test/src/stdfix/CountlsTest.h       | 3 +--
 libc/test/src/stdfix/countlshk_test.cpp  | 2 +-
 libc/test/src/stdfix/countlshr_test.cpp  | 2 +-
 libc/test/src/stdfix/countlsk_test.cpp   | 2 +-
 libc/test/src/stdfix/countlslk_test.cpp  | 2 +-
 libc/test/src/stdfix/countlslr_test.cpp  | 2 +-
 libc/test/src/stdfix/countlsr_test.cpp   | 2 +-
 libc/test/src/stdfix/countlsuhk_test.cpp | 2 +-
 libc/test/src/stdfix/countlsuhr_test.cpp | 2 +-
 libc/test/src/stdfix/countlsuk_test.cpp  | 2 +-
 libc/test/src/stdfix/countlsulk_test.cpp | 2 +-
 libc/test/src/stdfix/countlsulr_test.cpp | 2 +-
 libc/test/src/stdfix/countlsur_test.cpp  | 2 +-
 34 files changed, 38 insertions(+), 43 deletions(-)

diff --git a/libc/src/__support/fixed_point/fx_bits.h b/libc/src/__support/fixed_point/fx_bits.h
index 94f826a26fea2..21985e6442534 100644
--- a/libc/src/__support/fixed_point/fx_bits.h
+++ b/libc/src/__support/fixed_point/fx_bits.h
@@ -11,10 +11,10 @@
 
 #include "include/llvm-libc-macros/stdfix-macros.h"
 #include "src/__support/CPP/bit.h"
-#include "src/__support/CPP/type_traits.h"
 #include "src/__support/CPP/limits.h" // numeric_limits
-#include "src/__support/macros/attributes.h" // LIBC_INLINE
-#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
+#include "src/__support/CPP/type_traits.h"
+#include "src/__support/macros/attributes.h"   // LIBC_INLINE
+#include "src/__support/macros/config.h"       // LIBC_NAMESPACE_DECL
 #include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
 #include "src/__support/math_extras.h"
 
diff --git a/libc/src/stdfix/countlshk.cpp b/libc/src/stdfix/countlshk.cpp
index 65230dd688a7c..f94728beff1cb 100644
--- a/libc/src/stdfix/countlshk.cpp
+++ b/libc/src/stdfix/countlshk.cpp
@@ -1,4 +1,4 @@
-//===-- Implementation for countlshk function  --------------------------------===//
+//===-- Implementation for countlshk function  ----------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/src/stdfix/countlshk.h b/libc/src/stdfix/countlshk.h
index ecbc9075dcedf..ab334244e166a 100644
--- a/libc/src/stdfix/countlshk.h
+++ b/libc/src/stdfix/countlshk.h
@@ -1,4 +1,4 @@
-//===-- Implementation header for countlshk function -----------*- C++ -*-===//
+//===-- Implementation header for countlshk function ------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/src/stdfix/countlshr.cpp b/libc/src/stdfix/countlshr.cpp
index d07bab8c4a1cd..d77d3e9a3c22a 100644
--- a/libc/src/stdfix/countlshr.cpp
+++ b/libc/src/stdfix/countlshr.cpp
@@ -1,4 +1,4 @@
-//===-- Implementation for countlshr function  --------------------------------===//
+//===-- Implementation for countlshr function  ----------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/src/stdfix/countlshr.h b/libc/src/stdfix/countlshr.h
index 728b687315918..579b7b680406e 100644
--- a/libc/src/stdfix/countlshr.h
+++ b/libc/src/stdfix/countlshr.h
@@ -1,4 +1,4 @@
-//===-- Implementation header for countlshr function -----------*- C++ -*-===//
+//===-- Implementation header for countlshr function ------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/src/stdfix/countlsk.cpp b/libc/src/stdfix/countlsk.cpp
index 87c009aba0cb5..b6f56adee16a6 100644
--- a/libc/src/stdfix/countlsk.cpp
+++ b/libc/src/stdfix/countlsk.cpp
@@ -1,4 +1,4 @@
-//===-- Implementation for countlsk function  --------------------------------===//
+//===-- Implementation for countlsk function  -----------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -13,8 +13,6 @@
 
 namespace LIBC_NAMESPACE_DECL {
 
-LLVM_LIBC_FUNCTION(int, countlsk, (accum f)) {
-  return fixed_point::countls(f);
-}
+LLVM_LIBC_FUNCTION(int, countlsk, (accum f)) { return fixed_point::countls(f); }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/countlsk.h b/libc/src/stdfix/countlsk.h
index b7012da95a9c9..d0c893bc078d5 100644
--- a/libc/src/stdfix/countlsk.h
+++ b/libc/src/stdfix/countlsk.h
@@ -1,4 +1,4 @@
-//===-- Implementation header for countlsk function -----------*- C++ -*-===//
+//===-- Implementation header for countlsk function -------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/src/stdfix/countlslk.cpp b/libc/src/stdfix/countlslk.cpp
index 16120b2f55a11..9bf30ff34c6ee 100644
--- a/libc/src/stdfix/countlslk.cpp
+++ b/libc/src/stdfix/countlslk.cpp
@@ -1,4 +1,4 @@
-//===-- Implementation for countlslk function  --------------------------------===//
+//===-- Implementation for countlslk function  ----------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/src/stdfix/countlslk.h b/libc/src/stdfix/countlslk.h
index 90a2ccc33ce64..60fa469797b7a 100644
--- a/libc/src/stdfix/countlslk.h
+++ b/libc/src/stdfix/countlslk.h
@@ -1,4 +1,4 @@
-//===-- Implementation header for countlslk function -----------*- C++ -*-===//
+//===-- Implementation header for countlslk function ------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/src/stdfix/countlslr.cpp b/libc/src/stdfix/countlslr.cpp
index 9e0369db3b4a0..774023c734a37 100644
--- a/libc/src/stdfix/countlslr.cpp
+++ b/libc/src/stdfix/countlslr.cpp
@@ -1,4 +1,4 @@
-//===-- Implementation for countlslr function  --------------------------------===//
+//===-- Implementation for countlslr function  ----------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/src/stdfix/countlslr.h b/libc/src/stdfix/countlslr.h
index b1565b7024e7c..c909551e77a1a 100644
--- a/libc/src/stdfix/countlslr.h
+++ b/libc/src/stdfix/countlslr.h
@@ -1,4 +1,4 @@
-//===-- Implementation header for countlslr function -----------*- C++ -*-===//
+//===-- Implementation header for countlslr function ------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/src/stdfix/countlsr.cpp b/libc/src/stdfix/countlsr.cpp
index d18e673a3066d..14563127ad5e9 100644
--- a/libc/src/stdfix/countlsr.cpp
+++ b/libc/src/stdfix/countlsr.cpp
@@ -1,4 +1,4 @@
-//===-- Implementation for countlsr function  --------------------------------===//
+//===-- Implementation for countlsr function  -----------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -13,8 +13,6 @@
 
 namespace LIBC_NAMESPACE_DECL {
 
-LLVM_LIBC_FUNCTION(int, countlsr, (fract f)) {
-  return fixed_point::countls(f);
-}
+LLVM_LIBC_FUNCTION(int, countlsr, (fract f)) { return fixed_point::countls(f); }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/countlsr.h b/libc/src/stdfix/countlsr.h
index c50bd0a773e57..75dcf4aff0ca3 100644
--- a/libc/src/stdfix/countlsr.h
+++ b/libc/src/stdfix/countlsr.h
@@ -1,4 +1,4 @@
-//===-- Implementation header for countlsr function -----------*- C++ -*-===//
+//===-- Implementation header for countlsr function -------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/src/stdfix/countlsuhk.cpp b/libc/src/stdfix/countlsuhk.cpp
index 8a24508b83bcb..2cc266f47da1f 100644
--- a/libc/src/stdfix/countlsuhk.cpp
+++ b/libc/src/stdfix/countlsuhk.cpp
@@ -1,4 +1,4 @@
-//===-- Implementation for countlsuhk function  --------------------------------===//
+//===-- Implementation for countlsuhk function  ---------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/src/stdfix/countlsuhr.cpp b/libc/src/stdfix/countlsuhr.cpp
index 6dec26c788cd9..f30b0dd731aa9 100644
--- a/libc/src/stdfix/countlsuhr.cpp
+++ b/libc/src/stdfix/countlsuhr.cpp
@@ -1,4 +1,4 @@
-//===-- Implementation for countlsuhr function  --------------------------------===//
+//===-- Implementation for countlsuhr function  ---------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/src/stdfix/countlsuk.cpp b/libc/src/stdfix/countlsuk.cpp
index 98ebf096940e4..3f32ba0815b6e 100644
--- a/libc/src/stdfix/countlsuk.cpp
+++ b/libc/src/stdfix/countlsuk.cpp
@@ -1,4 +1,4 @@
-//===-- Implementation for countlsuhk function  --------------------------------===//
+//===-- Implementation for countlsuhk function  ---------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/src/stdfix/countlsuk.h b/libc/src/stdfix/countlsuk.h
index b912e75fb9002..7ad0e701b927b 100644
--- a/libc/src/stdfix/countlsuk.h
+++ b/libc/src/stdfix/countlsuk.h
@@ -1,4 +1,4 @@
-//===-- Implementation header for countlsuk function -----------*- C++ -*-===//
+//===-- Implementation header for countlsuk function ------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/src/stdfix/countlsulk.cpp b/libc/src/stdfix/countlsulk.cpp
index 043c919a653ea..04090dd86c732 100644
--- a/libc/src/stdfix/countlsulk.cpp
+++ b/libc/src/stdfix/countlsulk.cpp
@@ -1,4 +1,4 @@
-//===-- Implementation for countlsulk function  --------------------------------===//
+//===-- Implementation for countlsulk function  ---------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/src/stdfix/countlsulr.cpp b/libc/src/stdfix/countlsulr.cpp
index a77eaeabce69f..d9d6ff404c211 100644
--- a/libc/src/stdfix/countlsulr.cpp
+++ b/libc/src/stdfix/countlsulr.cpp
@@ -1,4 +1,4 @@
-//===-- Implementation for countlsulr function  --------------------------------===//
+//===-- Implementation for countlsulr function  ---------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/src/stdfix/countlsur.cpp b/libc/src/stdfix/countlsur.cpp
index 6dcb54bdca442..777e5f387aadf 100644
--- a/libc/src/stdfix/countlsur.cpp
+++ b/libc/src/stdfix/countlsur.cpp
@@ -1,4 +1,4 @@
-//===-- Implementation for countlsur function  --------------------------------===//
+//===-- Implementation for countlsur function  ----------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/src/stdfix/countlsur.h b/libc/src/stdfix/countlsur.h
index 85dec93bbcd5c..1d34e971a52b3 100644
--- a/libc/src/stdfix/countlsur.h
+++ b/libc/src/stdfix/countlsur.h
@@ -1,4 +1,4 @@
-//===-- Implementation header for countlsur function -----------*- C++ -*-===//
+//===-- Implementation header for countlsur function ------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/test/src/stdfix/CountlsTest.h b/libc/test/src/stdfix/CountlsTest.h
index 8bfea59b1862b..fe3917754a251 100644
--- a/libc/test/src/stdfix/CountlsTest.h
+++ b/libc/test/src/stdfix/CountlsTest.h
@@ -20,8 +20,7 @@ template <typename T> class CountlsTest : public LIBC_NAMESPACE::testing::Test {
   static constexpr T one_fourth = FXRep::ONE_FOURTH();
   static constexpr T eps = FXRep::EPS();
 
-  static constexpr auto value_len =
-      FXRep::INTEGRAL_LEN + FXRep::FRACTION_LEN;
+  static constexpr auto value_len = FXRep::INTEGRAL_LEN + FXRep::FRACTION_LEN;
 
 public:
   typedef int (*CountlsFunc)(T);
diff --git a/libc/test/src/stdfix/countlshk_test.cpp b/libc/test/src/stdfix/countlshk_test.cpp
index d874758ab635b..659f869706b5f 100644
--- a/libc/test/src/stdfix/countlshk_test.cpp
+++ b/libc/test/src/stdfix/countlshk_test.cpp
@@ -1,4 +1,4 @@
-//===-- Unittests for countlshk ----------------------------------------------===//
+//===-- Unittests for countlshk -------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/test/src/stdfix/countlshr_test.cpp b/libc/test/src/stdfix/countlshr_test.cpp
index a30022f06603c..361d4acab3b11 100644
--- a/libc/test/src/stdfix/countlshr_test.cpp
+++ b/libc/test/src/stdfix/countlshr_test.cpp
@@ -1,4 +1,4 @@
-//===-- Unittests for countlshr ----------------------------------------------===//
+//===-- Unittests for countlshr -------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/test/src/stdfix/countlsk_test.cpp b/libc/test/src/stdfix/countlsk_test.cpp
index ff98483360ef3..74cb519ec78de 100644
--- a/libc/test/src/stdfix/countlsk_test.cpp
+++ b/libc/test/src/stdfix/countlsk_test.cpp
@@ -1,4 +1,4 @@
-//===-- Unittests for countlsk ----------------------------------------------===//
+//===-- Unittests for countlsk --------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/test/src/stdfix/countlslk_test.cpp b/libc/test/src/stdfix/countlslk_test.cpp
index 2ef735976ba15..006939db3c87e 100644
--- a/libc/test/src/stdfix/countlslk_test.cpp
+++ b/libc/test/src/stdfix/countlslk_test.cpp
@@ -1,4 +1,4 @@
-//===-- Unittests for countlslk ----------------------------------------------===//
+//===-- Unittests for countlslk -------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/test/src/stdfix/countlslr_test.cpp b/libc/test/src/stdfix/countlslr_test.cpp
index 0d21115d51260..896cf9259c3ea 100644
--- a/libc/test/src/stdfix/countlslr_test.cpp
+++ b/libc/test/src/stdfix/countlslr_test.cpp
@@ -1,4 +1,4 @@
-//===-- Unittests for countlslr ----------------------------------------------===//
+//===-- Unittests for countlslr -------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/test/src/stdfix/countlsr_test.cpp b/libc/test/src/stdfix/countlsr_test.cpp
index ac4ddcb140f00..d7ae91ccd6a92 100644
--- a/libc/test/src/stdfix/countlsr_test.cpp
+++ b/libc/test/src/stdfix/countlsr_test.cpp
@@ -1,4 +1,4 @@
-//===-- Unittests for countlsr ----------------------------------------------===//
+//===-- Unittests for countlsr --------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/test/src/stdfix/countlsuhk_test.cpp b/libc/test/src/stdfix/countlsuhk_test.cpp
index f4958cfd02fe3..d8e68d65160e7 100644
--- a/libc/test/src/stdfix/countlsuhk_test.cpp
+++ b/libc/test/src/stdfix/countlsuhk_test.cpp
@@ -1,4 +1,4 @@
-//===-- Unittests for countlsuhk ----------------------------------------------===//
+//===-- Unittests for countlsuhk ------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/test/src/stdfix/countlsuhr_test.cpp b/libc/test/src/stdfix/countlsuhr_test.cpp
index 3d41ec5ff925b..7dbc590d4a552 100644
--- a/libc/test/src/stdfix/countlsuhr_test.cpp
+++ b/libc/test/src/stdfix/countlsuhr_test.cpp
@@ -1,4 +1,4 @@
-//===-- Unittests for countlsuhr ----------------------------------------------===//
+//===-- Unittests for countlsuhr ------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/test/src/stdfix/countlsuk_test.cpp b/libc/test/src/stdfix/countlsuk_test.cpp
index be5b1fa2474cc..20f78d8c942b6 100644
--- a/libc/test/src/stdfix/countlsuk_test.cpp
+++ b/libc/test/src/stdfix/countlsuk_test.cpp
@@ -1,4 +1,4 @@
-//===-- Unittests for countlsuk ----------------------------------------------===//
+//===-- Unittests for countlsuk -------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/test/src/stdfix/countlsulk_test.cpp b/libc/test/src/stdfix/countlsulk_test.cpp
index e8b647aa810ac..81ae208055cd9 100644
--- a/libc/test/src/stdfix/countlsulk_test.cpp
+++ b/libc/test/src/stdfix/countlsulk_test.cpp
@@ -1,4 +1,4 @@
-//===-- Unittests for countlsulk ----------------------------------------------===//
+//===-- Unittests for countlsulk ------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/test/src/stdfix/countlsulr_test.cpp b/libc/test/src/stdfix/countlsulr_test.cpp
index 7a10a351384d5..5b9b047f7fd74 100644
--- a/libc/test/src/stdfix/countlsulr_test.cpp
+++ b/libc/test/src/stdfix/countlsulr_test.cpp
@@ -1,4 +1,4 @@
-//===-- Unittests for countlsulr ----------------------------------------------===//
+//===-- Unittests for countlsulr ------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/test/src/stdfix/countlsur_test.cpp b/libc/test/src/stdfix/countlsur_test.cpp
index e7ca6ddffcc9d..67e32d7b56217 100644
--- a/libc/test/src/stdfix/countlsur_test.cpp
+++ b/libc/test/src/stdfix/countlsur_test.cpp
@@ -1,4 +1,4 @@
-//===-- Unittests for countlsur ----------------------------------------------===//
+//===-- Unittests for countlsur -------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

>From 780fd3a05e1c0efc0b97eb734d22ec62ab6bc708 Mon Sep 17 00:00:00 2001
From: krishna2803 <kpandey81930 at gmail.com>
Date: Sat, 8 Feb 2025 00:41:41 +0530
Subject: [PATCH 15/17] fix: buildbot failures

Signed-off-by: krishna2803 <kpandey81930 at gmail.com>
---
 libc/src/__support/fixed_point/fx_bits.h | 15 +++-----
 libc/src/__support/fixed_point/fx_rep.h  | 48 ++++++++++++++++++------
 libc/src/stdfix/countlsuhr.h             |  2 +-
 libc/src/stdfix/countlsuk.cpp            |  6 +--
 libc/test/src/stdfix/CountlsTest.h       | 11 +++---
 5 files changed, 51 insertions(+), 31 deletions(-)

diff --git a/libc/src/__support/fixed_point/fx_bits.h b/libc/src/__support/fixed_point/fx_bits.h
index 21985e6442534..120a7c5f25473 100644
--- a/libc/src/__support/fixed_point/fx_bits.h
+++ b/libc/src/__support/fixed_point/fx_bits.h
@@ -177,6 +177,7 @@ template <typename T> LIBC_INLINE constexpr T round(T x, int n) {
 }
 
 // count leading sign bits
+// TODO: support fixed_point_padding
 template <typename T>
 LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_fixed_point_v<T>, int>
 countls(T f) {
@@ -184,16 +185,12 @@ countls(T f) {
   using BitType = typename FXRep::StorageType;
   using FXBits = FXBits<T>;
 
-  constexpr int CONTAIN_LEN = cpp::numeric_limits<BitType>::digits;
-  constexpr int PADDING_LEN = CONTAIN_LEN - FXRep::TOTAL_LEN;
+  if constexpr (FXRep::SIGN_LEN > 0)
+    if (f < 0)
+      f = bit_not(f);
 
-  if constexpr (FXRep::SIGN_LEN != 0) {
-    if (x < 0)
-      x = bit_not(x);
-  }
-
-  BitType value_bits = FXBits(x)::get_bits();
-  return cpp::countl_zero(value_bits) - PADDING_LEN;
+  BitType value_bits = FXBits(f).get_bits();
+  return cpp::countl_zero(value_bits) - FXRep::SIGN_LEN;
 }
 
 } // namespace fixed_point
diff --git a/libc/src/__support/fixed_point/fx_rep.h b/libc/src/__support/fixed_point/fx_rep.h
index 186938947694e..ca9fafddc4ce2 100644
--- a/libc/src/__support/fixed_point/fx_rep.h
+++ b/libc/src/__support/fixed_point/fx_rep.h
@@ -43,8 +43,10 @@ template <> struct FXRep<short fract> {
   LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
   LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = 0;
   LIBC_INLINE_VAR static constexpr int FRACTION_LEN = SFRACT_FBIT;
+  LIBC_INLINE_VAR static constexpr int VALUE_LEN =
+      INTEGRAL_LEN + FRACTION_LEN;
   LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
-      SIGN_LEN + INTEGRAL_LEN + FRACTION_LEN;
+      SIGN_LEN + VALUE_LEN;
 
   LIBC_INLINE static constexpr Type MIN() { return SFRACT_MIN; }
   LIBC_INLINE static constexpr Type MAX() { return SFRACT_MAX; }
@@ -63,8 +65,10 @@ template <> struct FXRep<unsigned short fract> {
   LIBC_INLINE_VAR static constexpr int SIGN_LEN = 0;
   LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = 0;
   LIBC_INLINE_VAR static constexpr int FRACTION_LEN = USFRACT_FBIT;
+  LIBC_INLINE_VAR static constexpr int VALUE_LEN =
+      INTEGRAL_LEN + FRACTION_LEN;
   LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
-      SIGN_LEN + INTEGRAL_LEN + FRACTION_LEN;
+      SIGN_LEN + VALUE_LEN;
 
   LIBC_INLINE static constexpr Type MIN() { return USFRACT_MIN; }
   LIBC_INLINE static constexpr Type MAX() { return USFRACT_MAX; }
@@ -83,8 +87,10 @@ template <> struct FXRep<fract> {
   LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
   LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = 0;
   LIBC_INLINE_VAR static constexpr int FRACTION_LEN = FRACT_FBIT;
+  LIBC_INLINE_VAR static constexpr int VALUE_LEN =
+      INTEGRAL_LEN + FRACTION_LEN;
   LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
-      SIGN_LEN + INTEGRAL_LEN + FRACTION_LEN;
+      SIGN_LEN + VALUE_LEN;
 
   LIBC_INLINE static constexpr Type MIN() { return FRACT_MIN; }
   LIBC_INLINE static constexpr Type MAX() { return FRACT_MAX; }
@@ -103,8 +109,10 @@ template <> struct FXRep<unsigned fract> {
   LIBC_INLINE_VAR static constexpr int SIGN_LEN = 0;
   LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = 0;
   LIBC_INLINE_VAR static constexpr int FRACTION_LEN = UFRACT_FBIT;
+  LIBC_INLINE_VAR static constexpr int VALUE_LEN =
+      INTEGRAL_LEN + FRACTION_LEN;
   LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
-      SIGN_LEN + INTEGRAL_LEN + FRACTION_LEN;
+      SIGN_LEN + VALUE_LEN;
 
   LIBC_INLINE static constexpr Type MIN() { return UFRACT_MIN; }
   LIBC_INLINE static constexpr Type MAX() { return UFRACT_MAX; }
@@ -123,8 +131,10 @@ template <> struct FXRep<long fract> {
   LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
   LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = 0;
   LIBC_INLINE_VAR static constexpr int FRACTION_LEN = LFRACT_FBIT;
+  LIBC_INLINE_VAR static constexpr int VALUE_LEN =
+      INTEGRAL_LEN + FRACTION_LEN;
   LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
-      SIGN_LEN + INTEGRAL_LEN + FRACTION_LEN;
+      SIGN_LEN + VALUE_LEN;
 
   LIBC_INLINE static constexpr Type MIN() { return LFRACT_MIN; }
   LIBC_INLINE static constexpr Type MAX() { return LFRACT_MAX; }
@@ -143,8 +153,10 @@ template <> struct FXRep<unsigned long fract> {
   LIBC_INLINE_VAR static constexpr int SIGN_LEN = 0;
   LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = 0;
   LIBC_INLINE_VAR static constexpr int FRACTION_LEN = ULFRACT_FBIT;
+  LIBC_INLINE_VAR static constexpr int VALUE_LEN =
+      INTEGRAL_LEN + FRACTION_LEN;
   LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
-      SIGN_LEN + INTEGRAL_LEN + FRACTION_LEN;
+      SIGN_LEN + VALUE_LEN;
 
   LIBC_INLINE static constexpr Type MIN() { return ULFRACT_MIN; }
   LIBC_INLINE static constexpr Type MAX() { return ULFRACT_MAX; }
@@ -163,8 +175,10 @@ template <> struct FXRep<short accum> {
   LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
   LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = SACCUM_IBIT;
   LIBC_INLINE_VAR static constexpr int FRACTION_LEN = SACCUM_FBIT;
+  LIBC_INLINE_VAR static constexpr int VALUE_LEN =
+      INTEGRAL_LEN + FRACTION_LEN;
   LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
-      SIGN_LEN + INTEGRAL_LEN + FRACTION_LEN;
+      SIGN_LEN + VALUE_LEN;
 
   LIBC_INLINE static constexpr Type MIN() { return SACCUM_MIN; }
   LIBC_INLINE static constexpr Type MAX() { return SACCUM_MAX; }
@@ -183,8 +197,10 @@ template <> struct FXRep<unsigned short accum> {
   LIBC_INLINE_VAR static constexpr int SIGN_LEN = 0;
   LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = USACCUM_IBIT;
   LIBC_INLINE_VAR static constexpr int FRACTION_LEN = USACCUM_FBIT;
+  LIBC_INLINE_VAR static constexpr int VALUE_LEN =
+      INTEGRAL_LEN + FRACTION_LEN;
   LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
-      SIGN_LEN + INTEGRAL_LEN + FRACTION_LEN;
+      SIGN_LEN + VALUE_LEN;
 
   LIBC_INLINE static constexpr Type MIN() { return USACCUM_MIN; }
   LIBC_INLINE static constexpr Type MAX() { return USACCUM_MAX; }
@@ -203,8 +219,10 @@ template <> struct FXRep<accum> {
   LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
   LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = ACCUM_IBIT;
   LIBC_INLINE_VAR static constexpr int FRACTION_LEN = ACCUM_FBIT;
+  LIBC_INLINE_VAR static constexpr int VALUE_LEN =
+      INTEGRAL_LEN + FRACTION_LEN;
   LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
-      SIGN_LEN + INTEGRAL_LEN + FRACTION_LEN;
+      SIGN_LEN + VALUE_LEN;
 
   LIBC_INLINE static constexpr Type MIN() { return ACCUM_MIN; }
   LIBC_INLINE static constexpr Type MAX() { return ACCUM_MAX; }
@@ -223,8 +241,10 @@ template <> struct FXRep<unsigned accum> {
   LIBC_INLINE_VAR static constexpr int SIGN_LEN = 0;
   LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = UACCUM_IBIT;
   LIBC_INLINE_VAR static constexpr int FRACTION_LEN = UACCUM_FBIT;
+  LIBC_INLINE_VAR static constexpr int VALUE_LEN =
+      INTEGRAL_LEN + FRACTION_LEN;
   LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
-      SIGN_LEN + INTEGRAL_LEN + FRACTION_LEN;
+      SIGN_LEN + VALUE_LEN;
 
   LIBC_INLINE static constexpr Type MIN() { return UACCUM_MIN; }
   LIBC_INLINE static constexpr Type MAX() { return UACCUM_MAX; }
@@ -243,8 +263,10 @@ template <> struct FXRep<long accum> {
   LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
   LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = LACCUM_IBIT;
   LIBC_INLINE_VAR static constexpr int FRACTION_LEN = LACCUM_FBIT;
+  LIBC_INLINE_VAR static constexpr int VALUE_LEN =
+      INTEGRAL_LEN + FRACTION_LEN;
   LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
-      SIGN_LEN + INTEGRAL_LEN + FRACTION_LEN;
+      SIGN_LEN + VALUE_LEN;
 
   LIBC_INLINE static constexpr Type MIN() { return LACCUM_MIN; }
   LIBC_INLINE static constexpr Type MAX() { return LACCUM_MAX; }
@@ -263,8 +285,10 @@ template <> struct FXRep<unsigned long accum> {
   LIBC_INLINE_VAR static constexpr int SIGN_LEN = 0;
   LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = ULACCUM_IBIT;
   LIBC_INLINE_VAR static constexpr int FRACTION_LEN = ULACCUM_FBIT;
+  LIBC_INLINE_VAR static constexpr int VALUE_LEN =
+      INTEGRAL_LEN + FRACTION_LEN;
   LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
-      SIGN_LEN + INTEGRAL_LEN + FRACTION_LEN;
+      SIGN_LEN + VALUE_LEN;
 
   LIBC_INLINE static constexpr Type MIN() { return ULACCUM_MIN; }
   LIBC_INLINE static constexpr Type MAX() { return ULACCUM_MAX; }
diff --git a/libc/src/stdfix/countlsuhr.h b/libc/src/stdfix/countlsuhr.h
index c6ce001d38b11..b60132dc7f22b 100644
--- a/libc/src/stdfix/countlsuhr.h
+++ b/libc/src/stdfix/countlsuhr.h
@@ -14,7 +14,7 @@
 
 namespace LIBC_NAMESPACE_DECL {
 
-int countlsuhr(unsigned long fract f);
+int countlsuhr(unsigned short fract f);
 
 } // namespace LIBC_NAMESPACE_DECL
 
diff --git a/libc/src/stdfix/countlsuk.cpp b/libc/src/stdfix/countlsuk.cpp
index 3f32ba0815b6e..90617cfeb5cdc 100644
--- a/libc/src/stdfix/countlsuk.cpp
+++ b/libc/src/stdfix/countlsuk.cpp
@@ -1,4 +1,4 @@
-//===-- Implementation for countlsuhk function  ---------------------------===//
+//===-- Implementation for countlsuk function  ----------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,14 +6,14 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "countlsuhk.h"
+#include "countlsuk.h"
 #include "src/__support/common.h"
 #include "src/__support/fixed_point/fx_bits.h"
 #include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
 
 namespace LIBC_NAMESPACE_DECL {
 
-LLVM_LIBC_FUNCTION(int, countlsuhk, (unsigned accum f)) {
+LLVM_LIBC_FUNCTION(int, countlsuk, (unsigned accum f)) {
   return fixed_point::countls(f);
 }
 
diff --git a/libc/test/src/stdfix/CountlsTest.h b/libc/test/src/stdfix/CountlsTest.h
index fe3917754a251..caa14a229c25a 100644
--- a/libc/test/src/stdfix/CountlsTest.h
+++ b/libc/test/src/stdfix/CountlsTest.h
@@ -20,8 +20,6 @@ template <typename T> class CountlsTest : public LIBC_NAMESPACE::testing::Test {
   static constexpr T one_fourth = FXRep::ONE_FOURTH();
   static constexpr T eps = FXRep::EPS();
 
-  static constexpr auto value_len = FXRep::INTEGRAL_LEN + FXRep::FRACTION_LEN;
-
 public:
   typedef int (*CountlsFunc)(T);
 
@@ -30,13 +28,13 @@ template <typename T> class CountlsTest : public LIBC_NAMESPACE::testing::Test {
 
     EXPECT_EQ(FXRep::INTEGRAL_LEN, func(one_half));
     EXPECT_EQ(FXRep::INTEGRAL_LEN + 1, func(one_fourth));
-    EXPECT_EQ(value_len, func(zero));
-    EXPECT_EQ(value_len - 1, func(eps));
+    EXPECT_EQ(FXRep::VALUE_LEN, func(zero));
+    EXPECT_EQ(FXRep::VALUE_LEN - 1, func(eps));
     EXPECT_EQ(0, func(max));
     // If signed, left shifting the minimum value will overflow, so countls = 0.
     // If unsigned, the minimum value is zero, so countls is the number of value
     // bits according to ISO/IEC TR 18037.
-    EXPECT_EQ(is_signed ? 0 : value_len, func(min));
+    EXPECT_EQ(is_signed ? 0 : FXRep::VALUE_LEN, func(min));
 
     if (10 <= static_cast<int>(max)) {
       EXPECT_EQ(FXRep::INTEGRAL_LEN - 4, func(10));
@@ -47,7 +45,8 @@ template <typename T> class CountlsTest : public LIBC_NAMESPACE::testing::Test {
     }
 
     if constexpr (is_signed) {
-      EXPECT_EQ(value_len, func(-eps));
+      EXPECT_EQ(FXRep::VALUE_LEN, func(-zero));
+      EXPECT_EQ(FXRep::VALUE_LEN, func(-eps));
       EXPECT_EQ(FXRep::INTEGRAL_LEN + 1, func(-one_half));
       if (FXRep::FRACTION_LEN >= 2) {
         EXPECT_EQ(FXRep::INTEGRAL_LEN + 2, func(-one_fourth));

>From c3c1c13613cfa922785329815e1cc063b01bd2de Mon Sep 17 00:00:00 2001
From: krishna2803 <kpandey81930 at gmail.com>
Date: Tue, 11 Feb 2025 02:27:51 +0530
Subject: [PATCH 16/17] style: clang-format

Signed-off-by: krishna2803 <kpandey81930 at gmail.com>
---
 libc/src/__support/fixed_point/fx_rep.h | 72 +++++++++----------------
 1 file changed, 24 insertions(+), 48 deletions(-)

diff --git a/libc/src/__support/fixed_point/fx_rep.h b/libc/src/__support/fixed_point/fx_rep.h
index ca9fafddc4ce2..7227fffa683a8 100644
--- a/libc/src/__support/fixed_point/fx_rep.h
+++ b/libc/src/__support/fixed_point/fx_rep.h
@@ -43,10 +43,8 @@ template <> struct FXRep<short fract> {
   LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
   LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = 0;
   LIBC_INLINE_VAR static constexpr int FRACTION_LEN = SFRACT_FBIT;
-  LIBC_INLINE_VAR static constexpr int VALUE_LEN =
-      INTEGRAL_LEN + FRACTION_LEN;
-  LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
-      SIGN_LEN + VALUE_LEN;
+  LIBC_INLINE_VAR static constexpr int VALUE_LEN = INTEGRAL_LEN + FRACTION_LEN;
+  LIBC_INLINE_VAR static constexpr int TOTAL_LEN = SIGN_LEN + VALUE_LEN;
 
   LIBC_INLINE static constexpr Type MIN() { return SFRACT_MIN; }
   LIBC_INLINE static constexpr Type MAX() { return SFRACT_MAX; }
@@ -65,10 +63,8 @@ template <> struct FXRep<unsigned short fract> {
   LIBC_INLINE_VAR static constexpr int SIGN_LEN = 0;
   LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = 0;
   LIBC_INLINE_VAR static constexpr int FRACTION_LEN = USFRACT_FBIT;
-  LIBC_INLINE_VAR static constexpr int VALUE_LEN =
-      INTEGRAL_LEN + FRACTION_LEN;
-  LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
-      SIGN_LEN + VALUE_LEN;
+  LIBC_INLINE_VAR static constexpr int VALUE_LEN = INTEGRAL_LEN + FRACTION_LEN;
+  LIBC_INLINE_VAR static constexpr int TOTAL_LEN = SIGN_LEN + VALUE_LEN;
 
   LIBC_INLINE static constexpr Type MIN() { return USFRACT_MIN; }
   LIBC_INLINE static constexpr Type MAX() { return USFRACT_MAX; }
@@ -87,10 +83,8 @@ template <> struct FXRep<fract> {
   LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
   LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = 0;
   LIBC_INLINE_VAR static constexpr int FRACTION_LEN = FRACT_FBIT;
-  LIBC_INLINE_VAR static constexpr int VALUE_LEN =
-      INTEGRAL_LEN + FRACTION_LEN;
-  LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
-      SIGN_LEN + VALUE_LEN;
+  LIBC_INLINE_VAR static constexpr int VALUE_LEN = INTEGRAL_LEN + FRACTION_LEN;
+  LIBC_INLINE_VAR static constexpr int TOTAL_LEN = SIGN_LEN + VALUE_LEN;
 
   LIBC_INLINE static constexpr Type MIN() { return FRACT_MIN; }
   LIBC_INLINE static constexpr Type MAX() { return FRACT_MAX; }
@@ -109,10 +103,8 @@ template <> struct FXRep<unsigned fract> {
   LIBC_INLINE_VAR static constexpr int SIGN_LEN = 0;
   LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = 0;
   LIBC_INLINE_VAR static constexpr int FRACTION_LEN = UFRACT_FBIT;
-  LIBC_INLINE_VAR static constexpr int VALUE_LEN =
-      INTEGRAL_LEN + FRACTION_LEN;
-  LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
-      SIGN_LEN + VALUE_LEN;
+  LIBC_INLINE_VAR static constexpr int VALUE_LEN = INTEGRAL_LEN + FRACTION_LEN;
+  LIBC_INLINE_VAR static constexpr int TOTAL_LEN = SIGN_LEN + VALUE_LEN;
 
   LIBC_INLINE static constexpr Type MIN() { return UFRACT_MIN; }
   LIBC_INLINE static constexpr Type MAX() { return UFRACT_MAX; }
@@ -131,10 +123,8 @@ template <> struct FXRep<long fract> {
   LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
   LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = 0;
   LIBC_INLINE_VAR static constexpr int FRACTION_LEN = LFRACT_FBIT;
-  LIBC_INLINE_VAR static constexpr int VALUE_LEN =
-      INTEGRAL_LEN + FRACTION_LEN;
-  LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
-      SIGN_LEN + VALUE_LEN;
+  LIBC_INLINE_VAR static constexpr int VALUE_LEN = INTEGRAL_LEN + FRACTION_LEN;
+  LIBC_INLINE_VAR static constexpr int TOTAL_LEN = SIGN_LEN + VALUE_LEN;
 
   LIBC_INLINE static constexpr Type MIN() { return LFRACT_MIN; }
   LIBC_INLINE static constexpr Type MAX() { return LFRACT_MAX; }
@@ -153,10 +143,8 @@ template <> struct FXRep<unsigned long fract> {
   LIBC_INLINE_VAR static constexpr int SIGN_LEN = 0;
   LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = 0;
   LIBC_INLINE_VAR static constexpr int FRACTION_LEN = ULFRACT_FBIT;
-  LIBC_INLINE_VAR static constexpr int VALUE_LEN =
-      INTEGRAL_LEN + FRACTION_LEN;
-  LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
-      SIGN_LEN + VALUE_LEN;
+  LIBC_INLINE_VAR static constexpr int VALUE_LEN = INTEGRAL_LEN + FRACTION_LEN;
+  LIBC_INLINE_VAR static constexpr int TOTAL_LEN = SIGN_LEN + VALUE_LEN;
 
   LIBC_INLINE static constexpr Type MIN() { return ULFRACT_MIN; }
   LIBC_INLINE static constexpr Type MAX() { return ULFRACT_MAX; }
@@ -175,10 +163,8 @@ template <> struct FXRep<short accum> {
   LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
   LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = SACCUM_IBIT;
   LIBC_INLINE_VAR static constexpr int FRACTION_LEN = SACCUM_FBIT;
-  LIBC_INLINE_VAR static constexpr int VALUE_LEN =
-      INTEGRAL_LEN + FRACTION_LEN;
-  LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
-      SIGN_LEN + VALUE_LEN;
+  LIBC_INLINE_VAR static constexpr int VALUE_LEN = INTEGRAL_LEN + FRACTION_LEN;
+  LIBC_INLINE_VAR static constexpr int TOTAL_LEN = SIGN_LEN + VALUE_LEN;
 
   LIBC_INLINE static constexpr Type MIN() { return SACCUM_MIN; }
   LIBC_INLINE static constexpr Type MAX() { return SACCUM_MAX; }
@@ -197,10 +183,8 @@ template <> struct FXRep<unsigned short accum> {
   LIBC_INLINE_VAR static constexpr int SIGN_LEN = 0;
   LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = USACCUM_IBIT;
   LIBC_INLINE_VAR static constexpr int FRACTION_LEN = USACCUM_FBIT;
-  LIBC_INLINE_VAR static constexpr int VALUE_LEN =
-      INTEGRAL_LEN + FRACTION_LEN;
-  LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
-      SIGN_LEN + VALUE_LEN;
+  LIBC_INLINE_VAR static constexpr int VALUE_LEN = INTEGRAL_LEN + FRACTION_LEN;
+  LIBC_INLINE_VAR static constexpr int TOTAL_LEN = SIGN_LEN + VALUE_LEN;
 
   LIBC_INLINE static constexpr Type MIN() { return USACCUM_MIN; }
   LIBC_INLINE static constexpr Type MAX() { return USACCUM_MAX; }
@@ -219,10 +203,8 @@ template <> struct FXRep<accum> {
   LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
   LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = ACCUM_IBIT;
   LIBC_INLINE_VAR static constexpr int FRACTION_LEN = ACCUM_FBIT;
-  LIBC_INLINE_VAR static constexpr int VALUE_LEN =
-      INTEGRAL_LEN + FRACTION_LEN;
-  LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
-      SIGN_LEN + VALUE_LEN;
+  LIBC_INLINE_VAR static constexpr int VALUE_LEN = INTEGRAL_LEN + FRACTION_LEN;
+  LIBC_INLINE_VAR static constexpr int TOTAL_LEN = SIGN_LEN + VALUE_LEN;
 
   LIBC_INLINE static constexpr Type MIN() { return ACCUM_MIN; }
   LIBC_INLINE static constexpr Type MAX() { return ACCUM_MAX; }
@@ -241,10 +223,8 @@ template <> struct FXRep<unsigned accum> {
   LIBC_INLINE_VAR static constexpr int SIGN_LEN = 0;
   LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = UACCUM_IBIT;
   LIBC_INLINE_VAR static constexpr int FRACTION_LEN = UACCUM_FBIT;
-  LIBC_INLINE_VAR static constexpr int VALUE_LEN =
-      INTEGRAL_LEN + FRACTION_LEN;
-  LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
-      SIGN_LEN + VALUE_LEN;
+  LIBC_INLINE_VAR static constexpr int VALUE_LEN = INTEGRAL_LEN + FRACTION_LEN;
+  LIBC_INLINE_VAR static constexpr int TOTAL_LEN = SIGN_LEN + VALUE_LEN;
 
   LIBC_INLINE static constexpr Type MIN() { return UACCUM_MIN; }
   LIBC_INLINE static constexpr Type MAX() { return UACCUM_MAX; }
@@ -263,10 +243,8 @@ template <> struct FXRep<long accum> {
   LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
   LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = LACCUM_IBIT;
   LIBC_INLINE_VAR static constexpr int FRACTION_LEN = LACCUM_FBIT;
-  LIBC_INLINE_VAR static constexpr int VALUE_LEN =
-      INTEGRAL_LEN + FRACTION_LEN;
-  LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
-      SIGN_LEN + VALUE_LEN;
+  LIBC_INLINE_VAR static constexpr int VALUE_LEN = INTEGRAL_LEN + FRACTION_LEN;
+  LIBC_INLINE_VAR static constexpr int TOTAL_LEN = SIGN_LEN + VALUE_LEN;
 
   LIBC_INLINE static constexpr Type MIN() { return LACCUM_MIN; }
   LIBC_INLINE static constexpr Type MAX() { return LACCUM_MAX; }
@@ -285,10 +263,8 @@ template <> struct FXRep<unsigned long accum> {
   LIBC_INLINE_VAR static constexpr int SIGN_LEN = 0;
   LIBC_INLINE_VAR static constexpr int INTEGRAL_LEN = ULACCUM_IBIT;
   LIBC_INLINE_VAR static constexpr int FRACTION_LEN = ULACCUM_FBIT;
-  LIBC_INLINE_VAR static constexpr int VALUE_LEN =
-      INTEGRAL_LEN + FRACTION_LEN;
-  LIBC_INLINE_VAR static constexpr int TOTAL_LEN =
-      SIGN_LEN + VALUE_LEN;
+  LIBC_INLINE_VAR static constexpr int VALUE_LEN = INTEGRAL_LEN + FRACTION_LEN;
+  LIBC_INLINE_VAR static constexpr int TOTAL_LEN = SIGN_LEN + VALUE_LEN;
 
   LIBC_INLINE static constexpr Type MIN() { return ULACCUM_MIN; }
   LIBC_INLINE static constexpr Type MAX() { return ULACCUM_MAX; }

>From 8790b2c010563947cb2c87c15e7cbf3ba46b31f1 Mon Sep 17 00:00:00 2001
From: krishna2803 <kpandey81930 at gmail.com>
Date: Wed, 12 Feb 2025 03:30:54 +0530
Subject: [PATCH 17/17] style: llvm coding standard

Signed-off-by: krishna2803 <kpandey81930 at gmail.com>
---
 libc/src/__support/fixed_point/fx_bits.h | 3 ++-
 libc/test/src/stdfix/CMakeLists.txt      | 2 +-
 libc/test/src/stdfix/CountlsTest.h       | 9 +++------
 3 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/libc/src/__support/fixed_point/fx_bits.h b/libc/src/__support/fixed_point/fx_bits.h
index 120a7c5f25473..7509419da0c43 100644
--- a/libc/src/__support/fixed_point/fx_bits.h
+++ b/libc/src/__support/fixed_point/fx_bits.h
@@ -185,9 +185,10 @@ countls(T f) {
   using BitType = typename FXRep::StorageType;
   using FXBits = FXBits<T>;
 
-  if constexpr (FXRep::SIGN_LEN > 0)
+  if constexpr (FXRep::SIGN_LEN > 0) {
     if (f < 0)
       f = bit_not(f);
+  }
 
   BitType value_bits = FXBits(f).get_bits();
   return cpp::countl_zero(value_bits) - FXRep::SIGN_LEN;
diff --git a/libc/test/src/stdfix/CMakeLists.txt b/libc/test/src/stdfix/CMakeLists.txt
index 325ec56e10b04..86a99a9d2bc5d 100644
--- a/libc/test/src/stdfix/CMakeLists.txt
+++ b/libc/test/src/stdfix/CMakeLists.txt
@@ -83,7 +83,7 @@ foreach(suffix IN ITEMS hr r lr hk k lk uhr ur ulr uhk uk ulk)
     SRCS
       countls${suffix}_test.cpp
     COMPILE_OPTIONS
-      -O3
+      ${libc_opt_high_flag}
     DEPENDS
       libc.src.stdfix.countls${suffix}
       libc.src.__support.fixed_point.fx_rep
diff --git a/libc/test/src/stdfix/CountlsTest.h b/libc/test/src/stdfix/CountlsTest.h
index caa14a229c25a..a8201acb455b5 100644
--- a/libc/test/src/stdfix/CountlsTest.h
+++ b/libc/test/src/stdfix/CountlsTest.h
@@ -36,21 +36,18 @@ template <typename T> class CountlsTest : public LIBC_NAMESPACE::testing::Test {
     // bits according to ISO/IEC TR 18037.
     EXPECT_EQ(is_signed ? 0 : FXRep::VALUE_LEN, func(min));
 
-    if (10 <= static_cast<int>(max)) {
+    if (10 <= static_cast<int>(max))
       EXPECT_EQ(FXRep::INTEGRAL_LEN - 4, func(10));
-    }
 
-    if (static_cast<int>(min) <= -10) {
+    if (static_cast<int>(min) <= -10)
       EXPECT_EQ(FXRep::INTEGRAL_LEN - 4, func(-10));
-    }
 
     if constexpr (is_signed) {
       EXPECT_EQ(FXRep::VALUE_LEN, func(-zero));
       EXPECT_EQ(FXRep::VALUE_LEN, func(-eps));
       EXPECT_EQ(FXRep::INTEGRAL_LEN + 1, func(-one_half));
-      if (FXRep::FRACTION_LEN >= 2) {
+      if (FXRep::FRACTION_LEN >= 2)
         EXPECT_EQ(FXRep::INTEGRAL_LEN + 2, func(-one_fourth));
-      }
     }
   }
 };



More information about the libc-commits mailing list