Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/llvm/llvm-project.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorDominic Chen <ddchen@apple.com>2022-04-22 01:08:04 +0300
committerDominic Chen <ddchen@apple.com>2022-04-28 22:00:28 +0300
commitce6bfd102af5d3431ff19f322fce27e033a34c49 (patch)
treea7c44e1841a1c627c8f9c7ec5209f51e7f44cfad /libc
parent8042699a3088280292066a2fb1869f372369301f (diff)
[libc] Support 32-bit ARM platform tests
Set LONG_DOUBLE_IS_DOUBLE, add ifdefs for 128-bit integer types Differential Revision: https://reviews.llvm.org/D124204
Diffstat (limited to 'libc')
-rw-r--r--libc/src/__support/CPP/Limits.h3
-rw-r--r--libc/src/__support/CPP/TypeTraits.h7
-rw-r--r--libc/src/__support/FPUtil/PlatformDefs.h4
-rw-r--r--libc/test/src/__support/CPP/limits_test.cpp2
-rw-r--r--libc/test/src/__support/high_precision_decimal_test.cpp12
-rw-r--r--libc/test/src/__support/str_to_float_test.cpp2
-rw-r--r--libc/test/src/stdlib/strtold_test.cpp2
-rw-r--r--libc/utils/UnitTest/LibcTest.cpp6
8 files changed, 33 insertions, 5 deletions
diff --git a/libc/src/__support/CPP/Limits.h b/libc/src/__support/CPP/Limits.h
index 7e5de101c5b8..ba6c96fdef40 100644
--- a/libc/src/__support/CPP/Limits.h
+++ b/libc/src/__support/CPP/Limits.h
@@ -52,6 +52,7 @@ public:
static constexpr unsigned long long max() { return ULLONG_MAX; }
static constexpr unsigned long long min() { return 0; }
};
+#ifdef __SIZEOF_INT128__
template <> class NumericLimits<__uint128_t> {
public:
static constexpr __uint128_t max() { return ~__uint128_t(0); }
@@ -62,7 +63,7 @@ public:
static constexpr __int128_t max() { return ~__uint128_t(0) >> 1; }
static constexpr __int128_t min() { return __int128_t(1) << 127; }
};
-
+#endif
} // namespace cpp
} // namespace __llvm_libc
diff --git a/libc/src/__support/CPP/TypeTraits.h b/libc/src/__support/CPP/TypeTraits.h
index 0c542f1a79fd..b07e25ffd924 100644
--- a/libc/src/__support/CPP/TypeTraits.h
+++ b/libc/src/__support/CPP/TypeTraits.h
@@ -49,8 +49,11 @@ template <typename Type> struct IsIntegral {
IsSameV<unsigned short, TypeNoCV> || IsSameV<int, TypeNoCV> ||
IsSameV<unsigned int, TypeNoCV> || IsSameV<long, TypeNoCV> ||
IsSameV<unsigned long, TypeNoCV> || IsSameV<long long, TypeNoCV> ||
- IsSameV<unsigned long long, TypeNoCV> || IsSameV<bool, TypeNoCV> ||
- IsSameV<__uint128_t, TypeNoCV> || IsSameV<__int128_t, TypeNoCV>;
+ IsSameV<unsigned long long, TypeNoCV> || IsSameV<bool, TypeNoCV>
+#ifdef __SIZEOF_INT128__
+ || IsSameV<__uint128_t, TypeNoCV> || IsSameV<__int128_t, TypeNoCV>
+#endif
+ ;
};
template <typename T> struct IsPointerTypeNoCV : public FalseValue {};
diff --git a/libc/src/__support/FPUtil/PlatformDefs.h b/libc/src/__support/FPUtil/PlatformDefs.h
index a32c4af1b0ad..6f22bc38bdff 100644
--- a/libc/src/__support/FPUtil/PlatformDefs.h
+++ b/libc/src/__support/FPUtil/PlatformDefs.h
@@ -15,8 +15,10 @@
#define X87_FPU
#endif
+// https://developer.arm.com/documentation/dui0491/i/C-and-C---Implementation-Details/Basic-data-types
// https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms
-#if defined(_WIN32) || (defined(__APPLE__) && defined(__aarch64__))
+#if defined(_WIN32) || defined(__arm__) || \
+ (defined(__APPLE__) && defined(__aarch64__))
#define LONG_DOUBLE_IS_DOUBLE
#endif
diff --git a/libc/test/src/__support/CPP/limits_test.cpp b/libc/test/src/__support/CPP/limits_test.cpp
index fa0ae38cae6d..0272b5a6521a 100644
--- a/libc/test/src/__support/CPP/limits_test.cpp
+++ b/libc/test/src/__support/CPP/limits_test.cpp
@@ -29,6 +29,7 @@ TEST(LlvmLibcLimitsTest, LimitsFollowSpec) {
ULLONG_MAX);
}
+#ifdef __SIZEOF_INT128__
// This checks that the current environment supports 128 bit integers.
TEST(LlvmLibcLimitsTest, Int128Works) {
__int128_t max128 = ~__uint128_t(0) >> 1;
@@ -47,3 +48,4 @@ TEST(LlvmLibcLimitsTest, Int128Works) {
__uint128_t(__llvm_libc::cpp::NumericLimits<unsigned long long>::max()));
ASSERT_EQ(__llvm_libc::cpp::NumericLimits<__uint128_t>::max(), umax128);
}
+#endif
diff --git a/libc/test/src/__support/high_precision_decimal_test.cpp b/libc/test/src/__support/high_precision_decimal_test.cpp
index 1761dae0fcf9..46cc572c7624 100644
--- a/libc/test/src/__support/high_precision_decimal_test.cpp
+++ b/libc/test/src/__support/high_precision_decimal_test.cpp
@@ -344,26 +344,34 @@ TEST(LlvmLibcHighPrecisionDecimalTest, RoundingTest) {
EXPECT_EQ(hpd.round_to_integer_type<uint32_t>(), uint32_t(1));
EXPECT_EQ(hpd.round_to_integer_type<uint64_t>(), uint64_t(1));
+#ifdef __SIZEOF_INT128__
EXPECT_EQ(hpd.round_to_integer_type<__uint128_t>(), __uint128_t(1));
+#endif
hpd.shift(1); // shift left 1 to get 2.469 (rounds to 2)
EXPECT_EQ(hpd.round_to_integer_type<uint32_t>(), uint32_t(2));
EXPECT_EQ(hpd.round_to_integer_type<uint64_t>(), uint64_t(2));
+#ifdef __SIZEOF_INT128__
EXPECT_EQ(hpd.round_to_integer_type<__uint128_t>(), __uint128_t(2));
+#endif
hpd.shift(1); // shift left 1 to get 4.938 (rounds to 5)
EXPECT_EQ(hpd.round_to_integer_type<uint32_t>(), uint32_t(5));
EXPECT_EQ(hpd.round_to_integer_type<uint64_t>(), uint64_t(5));
+#ifdef __SIZEOF_INT128__
EXPECT_EQ(hpd.round_to_integer_type<__uint128_t>(), __uint128_t(5));
+#endif
// 2.5 is right between two integers, so we round to even (2)
hpd = __llvm_libc::internal::HighPrecisionDecimal("2.5");
EXPECT_EQ(hpd.round_to_integer_type<uint32_t>(), uint32_t(2));
EXPECT_EQ(hpd.round_to_integer_type<uint64_t>(), uint64_t(2));
+#ifdef __SIZEOF_INT128__
EXPECT_EQ(hpd.round_to_integer_type<__uint128_t>(), __uint128_t(2));
+#endif
// unless it's marked as having truncated, which means it's actually slightly
// higher, forcing a round up (3)
@@ -371,7 +379,9 @@ TEST(LlvmLibcHighPrecisionDecimalTest, RoundingTest) {
EXPECT_EQ(hpd.round_to_integer_type<uint32_t>(), uint32_t(3));
EXPECT_EQ(hpd.round_to_integer_type<uint64_t>(), uint64_t(3));
+#ifdef __SIZEOF_INT128__
EXPECT_EQ(hpd.round_to_integer_type<__uint128_t>(), __uint128_t(3));
+#endif
// Check that the larger int types are being handled properly (overflow is not
// handled, so int types that are too small are ignored for this test.)
@@ -380,6 +390,7 @@ TEST(LlvmLibcHighPrecisionDecimalTest, RoundingTest) {
hpd = __llvm_libc::internal::HighPrecisionDecimal("1099511627776");
EXPECT_EQ(hpd.round_to_integer_type<uint64_t>(), uint64_t(1099511627776));
+#ifdef __SIZEOF_INT128__
EXPECT_EQ(hpd.round_to_integer_type<__uint128_t>(),
__uint128_t(1099511627776));
@@ -390,4 +401,5 @@ TEST(LlvmLibcHighPrecisionDecimalTest, RoundingTest) {
__uint128_t result = __uint128_t(1) << 100;
EXPECT_EQ(hpd.round_to_integer_type<__uint128_t>(), result);
+#endif
}
diff --git a/libc/test/src/__support/str_to_float_test.cpp b/libc/test/src/__support/str_to_float_test.cpp
index dc70ebc1571d..211e3dc04eeb 100644
--- a/libc/test/src/__support/str_to_float_test.cpp
+++ b/libc/test/src/__support/str_to_float_test.cpp
@@ -313,7 +313,7 @@ TEST_F(LlvmLibcStrToFloatTest, EiselLemireFloat80Fallback) {
ASSERT_FALSE(__llvm_libc::internal::eisel_lemire<long double>(
1, -1000, &quadOutputMantissa, &outputExp2));
}
-#else
+#elif defined(__SIZEOF_INT128__)
TEST_F(LlvmLibcStrToFloatTest, EiselLemireFloat128Simple) {
eisel_lemire_test<long double>(123, 0, (__uint128_t(0x1ec0000000000) << 64),
16389);
diff --git a/libc/test/src/stdlib/strtold_test.cpp b/libc/test/src/stdlib/strtold_test.cpp
index d077bb1df196..7583e5916bcc 100644
--- a/libc/test/src/stdlib/strtold_test.cpp
+++ b/libc/test/src/stdlib/strtold_test.cpp
@@ -15,6 +15,7 @@
#include <limits.h>
#include <stddef.h>
+#ifdef __SIZEOF_INT128__
class LlvmLibcStrToLDTest : public __llvm_libc::testing::Test {
public:
void run_test(const char *inputString, const ptrdiff_t expectedStrLen,
@@ -221,3 +222,4 @@ TEST_F(LlvmLibcStrToLDTest, NaNTests) {
(__uint128_t(0x7fffc00000) << 40),
(__uint128_t(0x7fff800000000000) << 64));
}
+#endif
diff --git a/libc/utils/UnitTest/LibcTest.cpp b/libc/utils/UnitTest/LibcTest.cpp
index ed3ca4173c61..21b54a1b14b5 100644
--- a/libc/utils/UnitTest/LibcTest.cpp
+++ b/libc/utils/UnitTest/LibcTest.cpp
@@ -42,6 +42,7 @@ describeValue(ValType Value) {
std::string describeValue(std::string Value) { return std::string(Value); }
+#ifdef __SIZEOF_INT128__
// When the value is __uint128_t, also show its hexadecimal digits.
// Using template to force exact match, prevent ambiguous promotion.
std::string describeValue128(__uint128_t Value) {
@@ -61,6 +62,7 @@ template <> std::string describeValue<__int128_t>(__int128_t Value) {
template <> std::string describeValue<__uint128_t>(__uint128_t Value) {
return describeValue128(Value);
}
+#endif
template <typename ValType>
void explainDifference(ValType LHS, ValType RHS, const char *LHSStr,
@@ -218,10 +220,12 @@ template bool test<long long>(RunContext *Ctx, TestCondition Cond,
const char *RHSStr, const char *File,
unsigned long Line);
+#ifdef __SIZEOF_INT128__
template bool test<__int128_t>(RunContext *Ctx, TestCondition Cond,
__int128_t LHS, __int128_t RHS,
const char *LHSStr, const char *RHSStr,
const char *File, unsigned long Line);
+#endif
template bool test<unsigned char>(RunContext *Ctx, TestCondition Cond,
unsigned char LHS, unsigned char RHS,
@@ -253,10 +257,12 @@ template bool test<unsigned long long>(RunContext *Ctx, TestCondition Cond,
const char *LHSStr, const char *RHSStr,
const char *File, unsigned long Line);
+#ifdef __SIZEOF_INT128__
template bool test<__uint128_t>(RunContext *Ctx, TestCondition Cond,
__uint128_t LHS, __uint128_t RHS,
const char *LHSStr, const char *RHSStr,
const char *File, unsigned long Line);
+#endif
} // namespace internal