[libc-commits] [libc] [libc][stdfix] Implement fixed point fxbits functions in llvm libc (PR #114694)
via libc-commits
libc-commits at lists.llvm.org
Sat Nov 2 21:35:45 PDT 2024
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 ffe04e0351203524b212f850b48edf54dc5dbeb5 f7bb64156b54aaeb8c06a644deef6fd5410c071a --extensions cpp,h -- libc/src/stdfix/hkbits.cpp libc/src/stdfix/hkbits.h libc/src/stdfix/hrbits.cpp libc/src/stdfix/hrbits.h libc/src/stdfix/kbits.cpp libc/src/stdfix/kbits.h libc/src/stdfix/lkbits.cpp libc/src/stdfix/lkbits.h libc/src/stdfix/lrbits.cpp libc/src/stdfix/lrbits.h libc/src/stdfix/rbits.cpp libc/src/stdfix/rbits.h libc/src/stdfix/uhkbits.cpp libc/src/stdfix/uhkbits.h libc/src/stdfix/uhrbits.cpp libc/src/stdfix/uhrbits.h libc/src/stdfix/ukbits.cpp libc/src/stdfix/ukbits.h libc/src/stdfix/ulkbits.cpp libc/src/stdfix/ulkbits.h libc/src/stdfix/ulrbits.cpp libc/src/stdfix/ulrbits.h libc/src/stdfix/urbits.cpp libc/src/stdfix/urbits.h libc/test/src/stdfix/FxbitsTest.h libc/test/src/stdfix/hkbits_test.cpp libc/test/src/stdfix/hrbits_test.cpp libc/test/src/stdfix/kbits_test.cpp libc/test/src/stdfix/lkbits_test.cpp libc/test/src/stdfix/lrbits_test.cpp libc/test/src/stdfix/rbits_test.cpp libc/test/src/stdfix/uhkbits_test.cpp libc/test/src/stdfix/uhrbits_test.cpp libc/test/src/stdfix/ukbits_test.cpp libc/test/src/stdfix/ulkbits_test.cpp libc/test/src/stdfix/ulrbits_test.cpp libc/test/src/stdfix/urbits_test.cpp libc/include/llvm-libc-macros/stdfix-macros.h libc/src/__support/fixed_point/fx_bits.h
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/libc/src/__support/fixed_point/fx_bits.h b/libc/src/__support/fixed_point/fx_bits.h
index 6bc4cdbfcd..a28b2cc873 100644
--- a/libc/src/__support/fixed_point/fx_bits.h
+++ b/libc/src/__support/fixed_point/fx_bits.h
@@ -169,8 +169,7 @@ template <typename T, typename XType> LIBC_INLINE constexpr T fxbits(XType x) {
// Shift number by FX_IBITS so the bits are in the right spot.
// If the number is negative we need to make it positive, shift it and then
// renegate it to get the correct value.
- if (cpp::is_signed_v<XType> &&
- (x >> (FXRep::TOTAL_LEN - FXRep::SIGN_LEN))) {
+ if (cpp::is_signed_v<XType> && (x >> (FXRep::TOTAL_LEN - FXRep::SIGN_LEN))) {
x = -x;
x >>= FXRep::INTEGRAL_LEN;
x = -x;
diff --git a/libc/src/stdfix/hkbits.cpp b/libc/src/stdfix/hkbits.cpp
index f09e92d62e..17a741d00c 100644
--- a/libc/src/stdfix/hkbits.cpp
+++ b/libc/src/stdfix/hkbits.cpp
@@ -6,7 +6,6 @@
//
//===----------------------------------------------------------------------===//
-
#include "hkbits.h"
#include "src/__support/common.h"
diff --git a/libc/src/stdfix/hkbits.h b/libc/src/stdfix/hkbits.h
index 9cfff9c1ef..39902a109e 100644
--- a/libc/src/stdfix/hkbits.h
+++ b/libc/src/stdfix/hkbits.h
@@ -8,13 +8,13 @@
#ifndef LLVM_LIBC_SRC_STDFIX_HKBITS_H
#define LLVM_LIBC_SRC_STDFIX_HKBITS_H
-
+
#include "include/llvm-libc-macros/stdfix-macros.h"
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
-short accum hkbits(int_hk_t x);
+short accum hkbits(int_hk_t x);
}
-#endif
+#endif
diff --git a/libc/src/stdfix/hrbits.cpp b/libc/src/stdfix/hrbits.cpp
index ece82c9e54..6073b407ac 100644
--- a/libc/src/stdfix/hrbits.cpp
+++ b/libc/src/stdfix/hrbits.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "hrbits.h"
+#include "hrbits.h"
#include "src/__support/common.h"
#include "src/__support/fixed_point/fx_bits.h"
@@ -15,7 +15,7 @@
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(short fract, hrbits, (int_hr_t x)) {
- return fixed_point::fxbits<short fract, int_hr_t>(x);
+ return fixed_point::fxbits<short fract, int_hr_t>(x);
}
-}
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/hrbits.h b/libc/src/stdfix/hrbits.h
index 3499e471ce..055f29c8b9 100644
--- a/libc/src/stdfix/hrbits.h
+++ b/libc/src/stdfix/hrbits.h
@@ -13,7 +13,7 @@
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
-short fract hrbits(int_hr_t x);
+short fract hrbits(int_hr_t x);
}
-#endif
+#endif
diff --git a/libc/src/stdfix/kbits.cpp b/libc/src/stdfix/kbits.cpp
index e49220671e..de82642024 100644
--- a/libc/src/stdfix/kbits.cpp
+++ b/libc/src/stdfix/kbits.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "kbits.h"
+#include "kbits.h"
#include "src/__support/common.h"
#include "src/__support/fixed_point/fx_bits.h"
@@ -15,7 +15,7 @@
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(accum, kbits, (int_k_t x)) {
- return fixed_point::fxbits<accum, int_k_t>(x);
+ return fixed_point::fxbits<accum, int_k_t>(x);
}
-}
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/kbits.h b/libc/src/stdfix/kbits.h
index a2d2624a67..499a45f02d 100644
--- a/libc/src/stdfix/kbits.h
+++ b/libc/src/stdfix/kbits.h
@@ -1,4 +1,5 @@
-//===-- Implementation header for kbits --------------------------*- C++ -*-===//
+//===-- Implementation header for kbits --------------------------*- C++
+//-*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-
#ifndef LLVM_LIBC_SRC_STDFIX_KBITS_H
#define LLVM_LIBC_SRC_STDFIX_KBITS_H
@@ -14,8 +14,8 @@
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
-accum kbits(int_k_t x);
+accum kbits(int_k_t x);
}
-#endif
+#endif
diff --git a/libc/src/stdfix/lkbits.cpp b/libc/src/stdfix/lkbits.cpp
index 98e00bfd5e..016bec1138 100644
--- a/libc/src/stdfix/lkbits.cpp
+++ b/libc/src/stdfix/lkbits.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "lkbits.h"
+#include "lkbits.h"
#include "src/__support/common.h"
#include "src/__support/fixed_point/fx_bits.h"
@@ -15,7 +15,7 @@
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(long accum, lkbits, (int_lk_t x)) {
- return fixed_point::fxbits<long accum, int_lk_t>(x);
+ return fixed_point::fxbits<long accum, int_lk_t>(x);
}
-}
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/lkbits.h b/libc/src/stdfix/lkbits.h
index 01c4d50f7d..5b9f4834a2 100644
--- a/libc/src/stdfix/lkbits.h
+++ b/libc/src/stdfix/lkbits.h
@@ -13,7 +13,7 @@
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
-long accum lkbits(int_lk_t x);
+long accum lkbits(int_lk_t x);
}
-#endif
+#endif
diff --git a/libc/src/stdfix/lrbits.cpp b/libc/src/stdfix/lrbits.cpp
index 8f5cf532e9..a7ddc91ac1 100644
--- a/libc/src/stdfix/lrbits.cpp
+++ b/libc/src/stdfix/lrbits.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "lrbits.h"
+#include "lrbits.h"
#include "src/__support/common.h"
#include "src/__support/fixed_point/fx_bits.h"
@@ -15,7 +15,7 @@
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(long fract, lrbits, (int_lr_t x)) {
- return fixed_point::fxbits<long fract, int_lr_t>(x);
+ return fixed_point::fxbits<long fract, int_lr_t>(x);
}
-}
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdfix/lrbits.h b/libc/src/stdfix/lrbits.h
index dec00b2799..aaba9f189a 100644
--- a/libc/src/stdfix/lrbits.h
+++ b/libc/src/stdfix/lrbits.h
@@ -13,7 +13,7 @@
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
-long fract lrbits(int_lr_t x);
+long fract lrbits(int_lr_t x);
}
-#endif
+#endif
diff --git a/libc/src/stdfix/rbits.h b/libc/src/stdfix/rbits.h
index b6b80a2369..530265355a 100644
--- a/libc/src/stdfix/rbits.h
+++ b/libc/src/stdfix/rbits.h
@@ -8,13 +8,13 @@
#ifndef LLVM_LIBC_SRC_STDFIX_RBITS_H
#define LLVM_LIBC_SRC_STDFIX_RBITS_H
-
+
#include "include/llvm-libc-macros/stdfix-macros.h"
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
-fract rbits(int_r_t x);
+fract rbits(int_r_t x);
}
-#endif
+#endif
diff --git a/libc/src/stdfix/uhkbits.h b/libc/src/stdfix/uhkbits.h
index c2be44bd96..1b6172c2cb 100644
--- a/libc/src/stdfix/uhkbits.h
+++ b/libc/src/stdfix/uhkbits.h
@@ -8,13 +8,13 @@
#ifndef LLVM_LIBC_SRC_STDFIX_UHKBITS_H
#define LLVM_LIBC_SRC_STDFIX_UHKBITS_H
-
+
#include "include/llvm-libc-macros/stdfix-macros.h"
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
-unsigned short accum uhkbits(uint_uhk_t x);
+unsigned short accum uhkbits(uint_uhk_t x);
}
-#endif
+#endif
diff --git a/libc/src/stdfix/uhrbits.h b/libc/src/stdfix/uhrbits.h
index fa86bcbfe3..7824526e71 100644
--- a/libc/src/stdfix/uhrbits.h
+++ b/libc/src/stdfix/uhrbits.h
@@ -8,13 +8,13 @@
#ifndef LLVM_LIBC_SRC_STDFIX_UHRBITS_H
#define LLVM_LIBC_SRC_STDFIX_UHRBITS_H
-
+
#include "include/llvm-libc-macros/stdfix-macros.h"
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
-unsigned short fract uhrbits(uint_uhr_t x);
+unsigned short fract uhrbits(uint_uhr_t x);
}
-#endif
+#endif
diff --git a/libc/src/stdfix/ukbits.h b/libc/src/stdfix/ukbits.h
index 2eaedd7d92..f82bfae9da 100644
--- a/libc/src/stdfix/ukbits.h
+++ b/libc/src/stdfix/ukbits.h
@@ -8,13 +8,13 @@
#ifndef LLVM_LIBC_SRC_STDFIX_UKBITS_H
#define LLVM_LIBC_SRC_STDFIX_UKBITS_H
-
+
#include "include/llvm-libc-macros/stdfix-macros.h"
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
-unsigned accum ukbits(uint_uk_t x);
+unsigned accum ukbits(uint_uk_t x);
}
-#endif
+#endif
diff --git a/libc/src/stdfix/ulkbits.h b/libc/src/stdfix/ulkbits.h
index a922a18c72..fabb499d14 100644
--- a/libc/src/stdfix/ulkbits.h
+++ b/libc/src/stdfix/ulkbits.h
@@ -8,13 +8,13 @@
#ifndef LLVM_LIBC_SRC_STDFIX_ULKBITS_H
#define LLVM_LIBC_SRC_STDFIX_ULKBITS_H
-
+
#include "include/llvm-libc-macros/stdfix-macros.h"
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
-unsigned long accum ulkbits(uint_ulk_t x);
+unsigned long accum ulkbits(uint_ulk_t x);
}
-#endif
+#endif
diff --git a/libc/src/stdfix/ulrbits.h b/libc/src/stdfix/ulrbits.h
index fc5ebe9845..c0357a15a0 100644
--- a/libc/src/stdfix/ulrbits.h
+++ b/libc/src/stdfix/ulrbits.h
@@ -8,13 +8,13 @@
#ifndef LLVM_LIBC_SRC_STDFIX_ULRBITS_H
#define LLVM_LIBC_SRC_STDFIX_ULRBITS_H
-
+
#include "include/llvm-libc-macros/stdfix-macros.h"
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
-unsigned long fract ulrbits(uint_ulr_t x);
+unsigned long fract ulrbits(uint_ulr_t x);
}
-#endif
+#endif
diff --git a/libc/src/stdfix/urbits.h b/libc/src/stdfix/urbits.h
index 2fbbfb6879..47725e0bc5 100644
--- a/libc/src/stdfix/urbits.h
+++ b/libc/src/stdfix/urbits.h
@@ -8,13 +8,13 @@
#ifndef LLVM_LIBC_SRC_STDFIX_URBITS_H
#define LLVM_LIBC_SRC_STDFIX_URBITS_H
-
+
#include "include/llvm-libc-macros/stdfix-macros.h"
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
-unsigned fract urbits(uint_ur_t x);
+unsigned fract urbits(uint_ur_t x);
}
-#endif
+#endif
diff --git a/libc/test/src/stdfix/FxbitsTest.h b/libc/test/src/stdfix/FxbitsTest.h
index 0ee58e1293..be09639cb5 100644
--- a/libc/test/src/stdfix/FxbitsTest.h
+++ b/libc/test/src/stdfix/FxbitsTest.h
@@ -6,35 +6,36 @@
//
//===----------------------------------------------------------------------===//
-#include "test/UnitTest/Test.h"
#include "src/__support/fixed_point/fx_rep.h"
+#include "test/UnitTest/Test.h"
-template <typename T, typename XType> class FxbitsTest : public LIBC_NAMESPACE::testing::Test {
- using FXRep = LIBC_NAMESPACE::fixed_point::FXRep<T>;
- static constexpr T zero = FXRep::ZERO();
- static constexpr T min = FXRep::MIN();
- static constexpr T max = FXRep::MAX();
- static constexpr T half = static_cast<T>(0.5);
- static constexpr T neg_half = static_cast<T>(-0.5);
- static constexpr T one =
- (FXRep::INTEGRAL_LEN > 0) ? static_cast<T>(1) : FXRep::MAX();
- static constexpr T neg_one = static_cast<T>(-1);
- static constexpr T eps = FXRep::EPS();
+template <typename T, typename XType>
+class FxbitsTest : public LIBC_NAMESPACE::testing::Test {
+ using FXRep = LIBC_NAMESPACE::fixed_point::FXRep<T>;
+ static constexpr T zero = FXRep::ZERO();
+ static constexpr T min = FXRep::MIN();
+ static constexpr T max = FXRep::MAX();
+ static constexpr T half = static_cast<T>(0.5);
+ static constexpr T neg_half = static_cast<T>(-0.5);
+ static constexpr T one =
+ (FXRep::INTEGRAL_LEN > 0) ? static_cast<T>(1) : FXRep::MAX();
+ static constexpr T neg_one = static_cast<T>(-1);
+ static constexpr T eps = FXRep::EPS();
public:
- typedef T (*FxbitsFunc)(XType);
+ typedef T (*FxbitsFunc)(XType);
- void testSpecialNumbers(FxbitsFunc func) {
- EXPECT_EQ(zero, func(0));
- EXPECT_EQ(half, func((XType) (0b1 << (FXRep::FRACTION_LEN - 1)))); // 0.1000...b
- EXPECT_EQ(min, func((XType) 0x1));
- EXPECT_EQ(one, func(1));
- EXPECT_EQ(neg_one, func(-1));
- }
+ void testSpecialNumbers(FxbitsFunc func) {
+ EXPECT_EQ(zero, func(0));
+ EXPECT_EQ(half,
+ func((XType)(0b1 << (FXRep::FRACTION_LEN - 1)))); // 0.1000...b
+ EXPECT_EQ(min, func((XType)0x1));
+ EXPECT_EQ(one, func(1));
+ EXPECT_EQ(neg_one, func(-1));
+ }
};
-
-#define LIST_FXBITS_TEST(T, XType, func) \
- using LlvmLibcFxbitsTest = FxbitsTest<T, XType>; \
- TEST_F(LlvmLibcFxbitsTest, SpecialNumbers) { testSpecialNumbers(&func); } \
- static_assert(true, "Require semicolon.")
+#define LIST_FXBITS_TEST(T, XType, func) \
+ using LlvmLibcFxbitsTest = FxbitsTest<T, XType>; \
+ TEST_F(LlvmLibcFxbitsTest, SpecialNumbers) { testSpecialNumbers(&func); } \
+ static_assert(true, "Require semicolon.")
diff --git a/libc/test/src/stdfix/lkbits_test.cpp b/libc/test/src/stdfix/lkbits_test.cpp
index d0956e0deb..81dfd6fbc6 100644
--- a/libc/test/src/stdfix/lkbits_test.cpp
+++ b/libc/test/src/stdfix/lkbits_test.cpp
@@ -2,4 +2,3 @@
#include "src/stdfix/lkbits.h"
LIST_FXBITS_TEST(long accum, int_lk_t, LIBC_NAMESPACE::lkbits);
-
diff --git a/libc/test/src/stdfix/ukbits_test.cpp b/libc/test/src/stdfix/ukbits_test.cpp
index cd54ff7847..71bcaa165c 100644
--- a/libc/test/src/stdfix/ukbits_test.cpp
+++ b/libc/test/src/stdfix/ukbits_test.cpp
@@ -2,4 +2,3 @@
#include "src/stdfix/ukbits.h"
LIST_FXBITS_TEST(unsigned accum, uint_uk_t, LIBC_NAMESAPCE::ukbits);
-
diff --git a/libc/test/src/stdfix/ulkbits_test.cpp b/libc/test/src/stdfix/ulkbits_test.cpp
index 90f2dce277..1e57e07cc7 100644
--- a/libc/test/src/stdfix/ulkbits_test.cpp
+++ b/libc/test/src/stdfix/ulkbits_test.cpp
@@ -2,4 +2,3 @@
#include "src/stdfix/ulkbits.h"
LIST_FXBITS_TEST(unsigned long accum, uint_ulk_t, LIBC_NAMESPACE::ulkbits);
-
``````````
</details>
https://github.com/llvm/llvm-project/pull/114694
More information about the libc-commits
mailing list