[libc-commits] [libc] [wip][libc] Implemented fixed point divifx functions in llvm-libc (PR #138238)

via libc-commits libc-commits at lists.llvm.org
Fri May 2 01:02:33 PDT 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions cpp,h -- libc/src/__support/fixed_point/divifx.h libc/src/stdfix/divir.cpp libc/src/stdfix/divir.h libc/test/src/stdfix/DiviFxTest.h libc/test/src/stdfix/divir_test.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/libc/src/__support/fixed_point/divifx.h b/libc/src/__support/fixed_point/divifx.h
index af715612c..643232522 100644
--- a/libc/src/__support/fixed_point/divifx.h
+++ b/libc/src/__support/fixed_point/divifx.h
@@ -43,17 +43,15 @@ namespace internal {
 // --- Helper type traits for selecting intermediate calculation types ---
 
 template <typename IntType, int FractionalBits>
-using SelectDivIntermediateSigned =
-    cpp::conditional_t<
-        (sizeof(IntType) * 8 - 1 + FractionalBits <= 64), int64_t,
+using SelectDivIntermediateSigned = cpp::conditional_t<
+    (sizeof(IntType) * 8 - 1 + FractionalBits <= 64), int64_t,
 #ifdef LIBC_INTERNAL_HAS_INT128
-        cpp::conditional_t<(sizeof(IntType) * 8 - 1 + FractionalBits <= 128),
-                           int128_t,
-                           void>
+    cpp::conditional_t<(sizeof(IntType) * 8 - 1 + FractionalBits <= 128),
+                       int128_t, void>
 #else
-        void
+    void
 #endif
-        >;
+    >;
 
 template <typename IntType, int FractionalBits>
 using SelectDivIntermediateUnsigned = cpp::conditional_t<
@@ -68,13 +66,12 @@ using SelectDivIntermediateUnsigned = cpp::conditional_t<
 
 // --- Core implementation template ---
 
-
 template <typename IntType, typename FxType>
 LIBC_INLINE IntType divifx_impl(IntType i, FxType fx) {
   // Get metadata about the fixed-point type using FXRep helper
   using FX = FXRep<FxType>;
   using StorageType = typename FX::StorageType;
-  constexpr int F = FX::FRACTION_LEN;        // Number of fractional bits
+  constexpr int F = FX::FRACTION_LEN;       // Number of fractional bits
   constexpr bool FxIsSigned = FX::SIGN_LEN; // Is the fx type signed?
 
   // Extract the raw integer bits from the fixed-point divisor
@@ -82,7 +79,6 @@ LIBC_INLINE IntType divifx_impl(IntType i, FxType fx) {
 
   volatile StorageType check_raw_fx = raw_fx;
   if (LIBC_UNLIKELY(check_raw_fx == 0)) {
-
   }
 
   // Select appropriately sized intermediate types for the calculation
diff --git a/libc/src/stdfix/divir.h b/libc/src/stdfix/divir.h
index ef803160f..5466f5451 100644
--- a/libc/src/stdfix/divir.h
+++ b/libc/src/stdfix/divir.h
@@ -10,7 +10,7 @@
 #define LLVM_LIBC_SRC_STDFIX_DIVIR_H
 
 #include "include/llvm-libc-macros/stdfix-macros.h" // Provides 'fract' type
-#include "src/__support/macros/config.h"           // LIBC_NAMESPACE_DECL
+#include "src/__support/macros/config.h"            // LIBC_NAMESPACE_DECL
 
 namespace LIBC_NAMESPACE_DECL {
 
diff --git a/libc/test/src/stdfix/DiviFxTest.h b/libc/test/src/stdfix/DiviFxTest.h
index 1ee2a5e7b..2de13d2c2 100644
--- a/libc/test/src/stdfix/DiviFxTest.h
+++ b/libc/test/src/stdfix/DiviFxTest.h
@@ -8,8 +8,8 @@
 
 #include "test/UnitTest/Test.h"
 
-#include "src/__support/fixed_point/fx_rep.h"
 #include "src/__support/fixed_point/divifx.h"
+#include "src/__support/fixed_point/fx_rep.h"
 
 template <typename T, typename XType>
 class DiviFxTest : public LIBC_NAMESPACE::testing::Test {
@@ -33,8 +33,8 @@ public:
 };
 
 #define LIST_DIVIFX_TESTS(Name, T, XType, func)                                \
-  using LlvmLibcDivifx##Name##Test = DiviFxTest<T, XType>;                       \
-  TEST_F(LlvmLibcDivifx##Name##Test, SpecialNumbers) {                           \
+  using LlvmLibcDivifx##Name##Test = DiviFxTest<T, XType>;                     \
+  TEST_F(LlvmLibcDivifx##Name##Test, SpecialNumbers) {                         \
     testSpecialNumbers(&func);                                                 \
   }                                                                            \
   static_assert(true, "Require semicolon.")

``````````

</details>


https://github.com/llvm/llvm-project/pull/138238


More information about the libc-commits mailing list