[libc-commits] [libc] [libc] Fix for adding macro I (PR #111872)
Shourya Goel via libc-commits
libc-commits at lists.llvm.org
Thu Oct 10 10:39:14 PDT 2024
https://github.com/Sh0g0-1758 updated https://github.com/llvm/llvm-project/pull/111872
>From 357833beaf32bb55178b80b95ab5d7be7ca6f104 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Thu, 10 Oct 2024 22:28:54 +0530
Subject: [PATCH 1/2] fix
---
libc/src/__support/CPP/string_view.h | 4 ++--
libc/src/__support/CPP/utility/in_place.h | 6 +++---
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/libc/src/__support/CPP/string_view.h b/libc/src/__support/CPP/string_view.h
index 88f5270c3170a3..745c62c35f0a0a 100644
--- a/libc/src/__support/CPP/string_view.h
+++ b/libc/src/__support/CPP/string_view.h
@@ -31,8 +31,8 @@ class string_view {
LIBC_INLINE static int compareMemory(const char *Lhs, const char *Rhs,
size_t Length) {
- for (size_t I = 0; I < Length; ++I)
- if (int Diff = (int)Lhs[I] - (int)Rhs[I])
+ for (size_t i = 0; i < Length; ++i)
+ if (int Diff = (int)Lhs[i] - (int)Rhs[i])
return Diff;
return 0;
}
diff --git a/libc/src/__support/CPP/utility/in_place.h b/libc/src/__support/CPP/utility/in_place.h
index b5411f247d5519..3967eb1c535e45 100644
--- a/libc/src/__support/CPP/utility/in_place.h
+++ b/libc/src/__support/CPP/utility/in_place.h
@@ -27,11 +27,11 @@ template <class T> struct in_place_type_t {
};
template <class T> LIBC_INLINE_VAR constexpr in_place_type_t<T> in_place_type{};
-template <size_t I> struct in_place_index_t {
+template <size_t IDX> struct in_place_index_t {
LIBC_INLINE explicit in_place_index_t() = default;
};
-template <size_t I>
-LIBC_INLINE_VAR constexpr in_place_index_t<I> in_place_index{};
+template <size_t IDX>
+LIBC_INLINE_VAR constexpr in_place_index_t<IDX> in_place_index{};
} // namespace cpp
} // namespace LIBC_NAMESPACE_DECL
>From 06a0b71257bcbfb073161d9ab831a601212c65e6 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Thu, 10 Oct 2024 23:09:00 +0530
Subject: [PATCH 2/2] fix more files
---
.../FPUtil/NearestIntegerOperations.h | 34 ++++----
libc/test/src/math/RoundToIntegerTest.h | 84 +++++++++----------
2 files changed, 59 insertions(+), 59 deletions(-)
diff --git a/libc/src/__support/FPUtil/NearestIntegerOperations.h b/libc/src/__support/FPUtil/NearestIntegerOperations.h
index e4e497b898e83a..f496d54a14e2bb 100644
--- a/libc/src/__support/FPUtil/NearestIntegerOperations.h
+++ b/libc/src/__support/FPUtil/NearestIntegerOperations.h
@@ -346,12 +346,12 @@ fromfpx(T x, int rnd, unsigned int width) {
namespace internal {
-template <typename F, typename I,
- cpp::enable_if_t<cpp::is_floating_point_v<F> && cpp::is_integral_v<I>,
+template <typename F, typename InType,
+ cpp::enable_if_t<cpp::is_floating_point_v<F> && cpp::is_integral_v<InType>,
int> = 0>
-LIBC_INLINE I rounded_float_to_signed_integer(F x) {
- constexpr I INTEGER_MIN = (I(1) << (sizeof(I) * 8 - 1));
- constexpr I INTEGER_MAX = -(INTEGER_MIN + 1);
+LIBC_INLINE InType rounded_float_to_signed_integer(F x) {
+ constexpr InType INTEGER_MIN = (InType(1) << (sizeof(InType) * 8 - 1));
+ constexpr InType INTEGER_MAX = -(INTEGER_MIN + 1);
FPBits<F> bits(x);
auto set_domain_error_and_raise_invalid = []() {
set_errno_if_required(EDOM);
@@ -364,7 +364,7 @@ LIBC_INLINE I rounded_float_to_signed_integer(F x) {
}
int exponent = bits.get_exponent();
- constexpr int EXPONENT_LIMIT = sizeof(I) * 8 - 1;
+ constexpr int EXPONENT_LIMIT = sizeof(InType) * 8 - 1;
if (exponent > EXPONENT_LIMIT) {
set_domain_error_and_raise_invalid();
return bits.is_neg() ? INTEGER_MIN : INTEGER_MAX;
@@ -374,29 +374,29 @@ LIBC_INLINE I rounded_float_to_signed_integer(F x) {
return bits.is_neg() ? INTEGER_MIN : INTEGER_MAX;
}
// If the control reaches here, then it means that the rounded
- // value is the most negative number for the signed integer type I.
+ // value is the most negative number for the signed integer type InType.
}
- // For all other cases, if `x` can fit in the integer type `I`,
+ // For all other cases, if `x` can fit in the integer type `InType`,
// we just return `x`. static_cast will convert the floating
// point value to the exact integer value.
- return static_cast<I>(x);
+ return static_cast<InType>(x);
}
} // namespace internal
-template <typename F, typename I,
- cpp::enable_if_t<cpp::is_floating_point_v<F> && cpp::is_integral_v<I>,
+template <typename F, typename InType,
+ cpp::enable_if_t<cpp::is_floating_point_v<F> && cpp::is_integral_v<InType>,
int> = 0>
-LIBC_INLINE I round_to_signed_integer(F x) {
- return internal::rounded_float_to_signed_integer<F, I>(round(x));
+LIBC_INLINE InType round_to_signed_integer(F x) {
+ return internal::rounded_float_to_signed_integer<F, InType>(round(x));
}
-template <typename F, typename I,
- cpp::enable_if_t<cpp::is_floating_point_v<F> && cpp::is_integral_v<I>,
+template <typename F, typename InType,
+ cpp::enable_if_t<cpp::is_floating_point_v<F> && cpp::is_integral_v<InType>,
int> = 0>
-LIBC_INLINE I round_to_signed_integer_using_current_rounding_mode(F x) {
- return internal::rounded_float_to_signed_integer<F, I>(
+LIBC_INLINE InType round_to_signed_integer_using_current_rounding_mode(F x) {
+ return internal::rounded_float_to_signed_integer<F, InType>(
round_using_current_rounding_mode(x));
}
diff --git a/libc/test/src/math/RoundToIntegerTest.h b/libc/test/src/math/RoundToIntegerTest.h
index 995aba7b233ec8..aa08c6451fe8f8 100644
--- a/libc/test/src/math/RoundToIntegerTest.h
+++ b/libc/test/src/math/RoundToIntegerTest.h
@@ -26,11 +26,11 @@ using LIBC_NAMESPACE::Sign;
static constexpr int ROUNDING_MODES[4] = {FE_UPWARD, FE_DOWNWARD, FE_TOWARDZERO,
FE_TONEAREST};
-template <typename F, typename I, bool TestModes = false>
+template <typename F, typename OutType, bool TestModes = false>
class RoundToIntegerTestTemplate
: public LIBC_NAMESPACE::testing::FEnvSafeTest {
public:
- typedef I (*RoundToIntegerFunc)(F);
+ typedef OutType (*RoundToIntegerFunc)(F);
private:
using FPBits = LIBC_NAMESPACE::fputil::FPBits<F>;
@@ -49,10 +49,10 @@ class RoundToIntegerTestTemplate
static constexpr StorageType MIN_SUBNORMAL =
FPBits::min_subnormal().uintval();
- static constexpr I INTEGER_MIN = I(1) << (sizeof(I) * 8 - 1);
- static constexpr I INTEGER_MAX = -(INTEGER_MIN + 1);
+ static constexpr OutType INTEGER_MIN = OutType(1) << (sizeof(OutType) * 8 - 1);
+ static constexpr OutType INTEGER_MAX = -(INTEGER_MIN + 1);
- void test_one_input(RoundToIntegerFunc func, F input, I expected,
+ void test_one_input(RoundToIntegerFunc func, F input, OutType expected,
bool expectError) {
LIBC_NAMESPACE::libc_errno = 0;
LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT);
@@ -120,24 +120,24 @@ class RoundToIntegerTestTemplate
}
void do_round_numbers_test(RoundToIntegerFunc func) {
- test_one_input(func, zero, I(0), false);
- test_one_input(func, neg_zero, I(0), false);
- test_one_input(func, F(1.0), I(1), false);
- test_one_input(func, F(-1.0), I(-1), false);
- test_one_input(func, F(10.0), I(10), false);
- test_one_input(func, F(-10.0), I(-10), false);
- test_one_input(func, F(1234.0), I(1234), false);
- test_one_input(func, F(-1234.0), I(-1234), false);
+ test_one_input(func, zero, OutType(0), false);
+ test_one_input(func, neg_zero, OutType(0), false);
+ test_one_input(func, F(1.0), OutType(1), false);
+ test_one_input(func, F(-1.0), OutType(-1), false);
+ test_one_input(func, F(10.0), OutType(10), false);
+ test_one_input(func, F(-10.0), OutType(-10), false);
+ test_one_input(func, F(1234.0), OutType(1234), false);
+ test_one_input(func, F(-1234.0), OutType(-1234), false);
// The rest of this function compares with an equivalent MPFR function
// which rounds floating point numbers to long values. There is no MPFR
// function to round to long long or wider integer values. So, we will
- // the remaining tests only if the width of I less than equal to that of
+ // the remaining tests only if the width of OutType less than equal to that of
// long.
- if (sizeof(I) > sizeof(long))
+ if (sizeof(OutType) > sizeof(long))
return;
- constexpr int EXPONENT_LIMIT = sizeof(I) * 8 - 1;
+ constexpr int EXPONENT_LIMIT = sizeof(OutType) * 8 - 1;
constexpr int BIASED_EXPONENT_LIMIT = EXPONENT_LIMIT + FPBits::EXP_BIAS;
if (BIASED_EXPONENT_LIMIT > FPBits::MAX_BIASED_EXPONENT)
return;
@@ -179,7 +179,7 @@ class RoundToIntegerTestTemplate
else
erangeflag = mpfr::round_to_long(x, mpfr_long_result);
ASSERT_FALSE(erangeflag);
- I mpfr_result = mpfr_long_result;
+ OutType mpfr_result = mpfr_long_result;
test_one_input(func, x, mpfr_result, false);
}
}
@@ -201,12 +201,12 @@ class RoundToIntegerTestTemplate
// This function compares with an equivalent MPFR function which rounds
// floating point numbers to long values. There is no MPFR function to
// round to long long or wider integer values. So, we will peform the
- // comparisons in this function only if the width of I less than equal to
+ // comparisons in this function only if the width of OutType less than equal to
// that of long.
- if (sizeof(I) > sizeof(long))
+ if (sizeof(OutType) > sizeof(long))
return;
- constexpr int EXPONENT_LIMIT = sizeof(I) * 8 - 1;
+ constexpr int EXPONENT_LIMIT = sizeof(OutType) * 8 - 1;
constexpr int BIASED_EXPONENT_LIMIT = EXPONENT_LIMIT + FPBits::EXP_BIAS;
if (BIASED_EXPONENT_LIMIT > FPBits::MAX_BIASED_EXPONENT)
return;
@@ -240,30 +240,30 @@ class RoundToIntegerTestTemplate
constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
static_cast<StorageType>((MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT),
StorageType(1));
- for (StorageType i = MIN_SUBNORMAL; i <= MAX_SUBNORMAL; i += STEP) {
- F x = FPBits(i).get_val();
+ for (StorageType OutType = MIN_SUBNORMAL; OutType <= MAX_SUBNORMAL; OutType += STEP) {
+ F x = FPBits(OutType).get_val();
if (x == F(0.0))
continue;
// All subnormal numbers should round to zero.
if (TestModes) {
if (x > 0) {
LIBC_NAMESPACE::fputil::set_round(FE_UPWARD);
- test_one_input(func, x, I(1), false);
+ test_one_input(func, x, OutType(1), false);
LIBC_NAMESPACE::fputil::set_round(FE_DOWNWARD);
- test_one_input(func, x, I(0), false);
+ test_one_input(func, x, OutType(0), false);
LIBC_NAMESPACE::fputil::set_round(FE_TOWARDZERO);
- test_one_input(func, x, I(0), false);
+ test_one_input(func, x, OutType(0), false);
LIBC_NAMESPACE::fputil::set_round(FE_TONEAREST);
- test_one_input(func, x, I(0), false);
+ test_one_input(func, x, OutType(0), false);
} else {
LIBC_NAMESPACE::fputil::set_round(FE_UPWARD);
- test_one_input(func, x, I(0), false);
+ test_one_input(func, x, OutType(0), false);
LIBC_NAMESPACE::fputil::set_round(FE_DOWNWARD);
- test_one_input(func, x, I(-1), false);
+ test_one_input(func, x, OutType(-1), false);
LIBC_NAMESPACE::fputil::set_round(FE_TOWARDZERO);
- test_one_input(func, x, I(0), false);
+ test_one_input(func, x, OutType(0), false);
LIBC_NAMESPACE::fputil::set_round(FE_TONEAREST);
- test_one_input(func, x, I(0), false);
+ test_one_input(func, x, OutType(0), false);
}
} else {
test_one_input(func, x, 0L, false);
@@ -275,17 +275,17 @@ class RoundToIntegerTestTemplate
// This function compares with an equivalent MPFR function which rounds
// floating point numbers to long values. There is no MPFR function to
// round to long long or wider integer values. So, we will peform the
- // comparisons in this function only if the width of I less than equal to
+ // comparisons in this function only if the width of OutType less than equal to
// that of long.
- if (sizeof(I) > sizeof(long))
+ if (sizeof(OutType) > sizeof(long))
return;
constexpr int COUNT = 1'000'001;
constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
static_cast<StorageType>((MAX_NORMAL - MIN_NORMAL) / COUNT),
StorageType(1));
- for (StorageType i = MIN_NORMAL; i <= MAX_NORMAL; i += STEP) {
- FPBits xbits(i);
+ for (StorageType OutType = MIN_NORMAL; OutType <= MAX_NORMAL; OutType += STEP) {
+ FPBits xbits(OutType);
F x = xbits.get_val();
// In normal range on x86 platforms, the long double implicit 1 bit can be
// zero making the numbers NaN. We will skip them.
@@ -297,7 +297,7 @@ class RoundToIntegerTestTemplate
long mpfr_long_result;
bool erangeflag = mpfr::round_to_long(x, to_mpfr_rounding_mode(m),
mpfr_long_result);
- I mpfr_result = mpfr_long_result;
+ OutType mpfr_result = mpfr_long_result;
LIBC_NAMESPACE::fputil::set_round(m);
if (erangeflag)
test_one_input(func, x, x > 0 ? INTEGER_MAX : INTEGER_MIN, true);
@@ -307,7 +307,7 @@ class RoundToIntegerTestTemplate
} else {
long mpfr_long_result;
bool erangeflag = mpfr::round_to_long(x, mpfr_long_result);
- I mpfr_result = mpfr_long_result;
+ OutType mpfr_result = mpfr_long_result;
if (erangeflag)
test_one_input(func, x, x > 0 ? INTEGER_MAX : INTEGER_MIN, true);
else
@@ -317,9 +317,9 @@ class RoundToIntegerTestTemplate
}
};
-#define LIST_ROUND_TO_INTEGER_TESTS_HELPER(F, I, func, TestModes) \
+#define LIST_ROUND_TO_INTEGER_TESTS_HELPER(F, OutType, func, TestModes) \
using LlvmLibcRoundToIntegerTest = \
- RoundToIntegerTestTemplate<F, I, TestModes>; \
+ RoundToIntegerTestTemplate<F, OutType, TestModes>; \
TEST_F(LlvmLibcRoundToIntegerTest, InfinityAndNaN) { \
testInfinityAndNaN(&func); \
} \
@@ -335,10 +335,10 @@ class RoundToIntegerTestTemplate
} \
TEST_F(LlvmLibcRoundToIntegerTest, NormalRange) { testNormalRange(&func); }
-#define LIST_ROUND_TO_INTEGER_TESTS(F, I, func) \
- LIST_ROUND_TO_INTEGER_TESTS_HELPER(F, I, func, false)
+#define LIST_ROUND_TO_INTEGER_TESTS(F, OutType, func) \
+ LIST_ROUND_TO_INTEGER_TESTS_HELPER(F, OutType, func, false)
-#define LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(F, I, func) \
- LIST_ROUND_TO_INTEGER_TESTS_HELPER(F, I, func, true)
+#define LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(F, OutType, func) \
+ LIST_ROUND_TO_INTEGER_TESTS_HELPER(F, OutType, func, true)
#endif // LLVM_LIBC_TEST_SRC_MATH_ROUNDTOINTEGERTEST_H
More information about the libc-commits
mailing list