Skip to content

Commit fb8d637

Browse files
author
git apple-llvm automerger
committed
Merge commit '23c397c7c940' from llvm.org/main into next
2 parents 039260c + 23c397c commit fb8d637

File tree

22 files changed

+72
-36
lines changed

22 files changed

+72
-36
lines changed

libc/src/__support/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ add_header_library(
205205
libc.src.__support.CPP.bit
206206
libc.src.__support.CPP.type_traits
207207
libc.src.__support.macros.optimization
208+
libc.src.__support.macros.properties.types
208209
)
209210

210211
add_header_library(
@@ -213,6 +214,7 @@ add_header_library(
213214
UInt128.h
214215
DEPENDS
215216
.uint
217+
libc.src.__support.macros.properties.types
216218
)
217219

218220
add_header_library(

libc/src/__support/CPP/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ add_header_library(
4949
DEPENDS
5050
.type_traits
5151
libc.include.llvm-libc-macros.limits_macros
52+
libc.src.__support.macros.properties.types
5253
)
5354

5455
add_header_library(

libc/src/__support/CPP/limits.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
#include "include/llvm-libc-macros/limits-macros.h" // CHAR_BIT
1313
#include "src/__support/CPP/type_traits/is_integral.h"
1414
#include "src/__support/CPP/type_traits/is_signed.h"
15-
#include "src/__support/macros/attributes.h" // LIBC_INLINE
15+
#include "src/__support/macros/attributes.h" // LIBC_INLINE
16+
#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
1617

1718
namespace LIBC_NAMESPACE {
1819
namespace cpp {
@@ -76,7 +77,7 @@ template <>
7677
struct numeric_limits<unsigned char>
7778
: public internal::integer_impl<unsigned char, 0, UCHAR_MAX> {};
7879

79-
#ifdef __SIZEOF_INT128__
80+
#ifdef LIBC_TYPES_HAS_INT128
8081
// On platform where UInt128 resolves to __uint128_t, this specialization
8182
// provides the limits of UInt128.
8283
template <>

libc/src/__support/CPP/type_traits/is_integral.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "src/__support/CPP/type_traits/is_same.h"
1212
#include "src/__support/CPP/type_traits/remove_cv.h"
1313
#include "src/__support/macros/attributes.h"
14+
#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
1415

1516
namespace LIBC_NAMESPACE::cpp {
1617

@@ -25,7 +26,7 @@ template <typename T> struct is_integral {
2526
public:
2627
LIBC_INLINE_VAR static constexpr bool value = __is_unqualified_any_of<
2728
T,
28-
#ifdef __SIZEOF_INT128__
29+
#ifdef LIBC_TYPES_HAS_INT128
2930
__int128_t, __uint128_t,
3031
#endif
3132
char, signed char, unsigned char, short, unsigned short, int,

libc/src/__support/CPP/type_traits/make_signed.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_MAKE_SIGNED_H
1010

1111
#include "src/__support/CPP/type_traits/type_identity.h"
12+
#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
1213

1314
namespace LIBC_NAMESPACE::cpp {
1415

@@ -26,7 +27,7 @@ template <> struct make_signed<unsigned int> : type_identity<int> {};
2627
template <> struct make_signed<unsigned long> : type_identity<long> {};
2728
template <>
2829
struct make_signed<unsigned long long> : type_identity<long long> {};
29-
#ifdef __SIZEOF_INT128__
30+
#ifdef LIBC_TYPES_HAS_INT128
3031
template <> struct make_signed<__int128_t> : type_identity<__int128_t> {};
3132
template <> struct make_signed<__uint128_t> : type_identity<__int128_t> {};
3233
#endif

libc/src/__support/CPP/type_traits/make_unsigned.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_MAKE_UNSIGNED_H
1010

1111
#include "src/__support/CPP/type_traits/type_identity.h"
12+
#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
1213

1314
namespace LIBC_NAMESPACE::cpp {
1415

@@ -31,7 +32,7 @@ template <>
3132
struct make_unsigned<unsigned long> : type_identity<unsigned long> {};
3233
template <>
3334
struct make_unsigned<unsigned long long> : type_identity<unsigned long long> {};
34-
#ifdef __SIZEOF_INT128__
35+
#ifdef LIBC_TYPES_HAS_INT128
3536
template <> struct make_unsigned<__int128_t> : type_identity<__uint128_t> {};
3637
template <> struct make_unsigned<__uint128_t> : type_identity<__uint128_t> {};
3738
#endif

libc/src/__support/UInt.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
#include "src/__support/CPP/limits.h"
1515
#include "src/__support/CPP/optional.h"
1616
#include "src/__support/CPP/type_traits.h"
17-
#include "src/__support/macros/attributes.h" // LIBC_INLINE
18-
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
19-
#include "src/__support/math_extras.h" // SumCarry, DiffBorrow
17+
#include "src/__support/macros/attributes.h" // LIBC_INLINE
18+
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
19+
#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
20+
#include "src/__support/math_extras.h" // SumCarry, DiffBorrow
2021
#include "src/__support/number_pair.h"
2122

2223
#include <stddef.h> // For size_t
@@ -30,9 +31,9 @@ template <typename T> struct half_width;
3031
template <> struct half_width<uint64_t> : cpp::type_identity<uint32_t> {};
3132
template <> struct half_width<uint32_t> : cpp::type_identity<uint16_t> {};
3233
template <> struct half_width<uint16_t> : cpp::type_identity<uint8_t> {};
33-
#ifdef __SIZEOF_INT128__
34+
#ifdef LIBC_TYPES_HAS_INT128
3435
template <> struct half_width<__uint128_t> : cpp::type_identity<uint64_t> {};
35-
#endif // __SIZEOF_INT128__
36+
#endif // LIBC_TYPES_HAS_INT128
3637

3738
template <typename T> using half_width_t = typename half_width<T>::type;
3839

@@ -69,7 +70,7 @@ LIBC_INLINE constexpr NumberPair<uint32_t> full_mul<uint32_t>(uint32_t a,
6970
return result;
7071
}
7172

72-
#ifdef __SIZEOF_INT128__
73+
#ifdef LIBC_TYPES_HAS_INT128
7374
template <>
7475
LIBC_INLINE constexpr NumberPair<uint64_t> full_mul<uint64_t>(uint64_t a,
7576
uint64_t b) {
@@ -79,7 +80,7 @@ LIBC_INLINE constexpr NumberPair<uint64_t> full_mul<uint64_t>(uint64_t a,
7980
result.hi = uint64_t(prod >> 64);
8081
return result;
8182
}
82-
#endif // __SIZEOF_INT128__
83+
#endif // LIBC_TYPES_HAS_INT128
8384

8485
} // namespace internal
8586

@@ -682,7 +683,7 @@ struct BigInt {
682683
val[1] = uint32_t(tmp >> 32);
683684
return;
684685
}
685-
#ifdef __SIZEOF_INT128__
686+
#ifdef LIBC_TYPES_HAS_INT128
686687
if constexpr ((Bits == 128) && (WORD_SIZE == 64)) {
687688
// Use builtin 128 bits if available;
688689
if (s >= 128) {
@@ -696,7 +697,7 @@ struct BigInt {
696697
val[1] = uint64_t(tmp >> 64);
697698
return;
698699
}
699-
#endif // __SIZEOF_INT128__
700+
#endif // LIBC_TYPES_HAS_INT128
700701
if (LIBC_UNLIKELY(s == 0))
701702
return;
702703

@@ -753,7 +754,7 @@ struct BigInt {
753754
val[1] = uint32_t(tmp >> 32);
754755
return;
755756
}
756-
#ifdef __SIZEOF_INT128__
757+
#ifdef LIBC_TYPES_HAS_INT128
757758
if constexpr ((Bits == 128) && (WORD_SIZE == 64)) {
758759
// Use builtin 128 bits if available;
759760
if (s >= 128) {
@@ -771,7 +772,7 @@ struct BigInt {
771772
val[1] = uint64_t(tmp >> 64);
772773
return;
773774
}
774-
#endif // __SIZEOF_INT128__
775+
#endif // LIBC_TYPES_HAS_INT128
775776

776777
if (LIBC_UNLIKELY(s == 0))
777778
return;

libc/src/__support/UInt128.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
#define LLVM_LIBC_SRC___SUPPORT_UINT128_H
1111

1212
#include "UInt.h"
13+
#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
1314

14-
#if defined(__SIZEOF_INT128__)
15+
#ifdef LIBC_TYPES_HAS_INT128
1516
using UInt128 = __uint128_t;
1617
using Int128 = __int128_t;
1718
#else
1819
using UInt128 = LIBC_NAMESPACE::UInt<128>;
1920
using Int128 = LIBC_NAMESPACE::Int<128>;
20-
#endif
21+
#endif // LIBC_TYPES_HAS_INT128
2122

2223
#endif // LLVM_LIBC_SRC___SUPPORT_UINT128_H

libc/src/__support/macros/properties/types.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include "src/__support/macros/properties/cpu_features.h"
1818
#include "src/__support/macros/properties/os.h"
1919

20+
#include <stdint.h> // __SIZEOF_INT128__
21+
2022
// 'long double' properties.
2123
#if (LDBL_MANT_DIG == 53)
2224
#define LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64
@@ -26,6 +28,11 @@
2628
#define LIBC_TYPES_LONG_DOUBLE_IS_FLOAT128
2729
#endif
2830

31+
// int128 / uint128 support
32+
#if defined(__SIZEOF_INT128__)
33+
#define LIBC_TYPES_HAS_INT128
34+
#endif // defined(__SIZEOF_INT128__)
35+
2936
// -- float16 support ---------------------------------------------------------
3037
// TODO: move this logic to "llvm-libc-types/float16.h"
3138
#if defined(LIBC_TARGET_ARCH_IS_X86_64) && defined(LIBC_TARGET_CPU_HAS_SSE2)

libc/test/UnitTest/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ add_unittest_framework_library(
7373
libc.src.__support.CPP.string_view
7474
libc.src.__support.CPP.type_traits
7575
libc.src.__support.fixed_point.fx_rep
76+
libc.src.__support.macros.properties.types
7677
libc.src.__support.OSUtil.osutil
7778
libc.src.__support.uint
7879
libc.src.__support.uint128

libc/test/UnitTest/LibcTest.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "src/__support/CPP/string_view.h"
1414
#include "src/__support/UInt128.h"
1515
#include "src/__support/fixed_point/fx_rep.h"
16+
#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
1617
#include "test/UnitTest/TestLogger.h"
1718

1819
#if __STDC_HOSTED__
@@ -215,11 +216,11 @@ TEST_SPECIALIZATION(bool);
215216

216217
// We cannot just use a single UInt128 specialization as that resolves to only
217218
// one type, UInt<128> or __uint128_t. We want both overloads as we want to
218-
#ifdef __SIZEOF_INT128__
219+
#ifdef LIBC_TYPES_HAS_INT128
219220
// When builtin __uint128_t type is available, include its specialization
220221
// also.
221222
TEST_SPECIALIZATION(__uint128_t);
222-
#endif
223+
#endif // LIBC_TYPES_HAS_INT128
223224

224225
TEST_SPECIALIZATION(LIBC_NAMESPACE::Int<128>);
225226

libc/test/UnitTest/TestLogger.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "src/__support/OSUtil/io.h" // write_to_stderr
55
#include "src/__support/UInt.h" // is_big_int
66
#include "src/__support/UInt128.h"
7+
#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
78

89
#include <stdint.h>
910

@@ -72,9 +73,9 @@ template TestLogger &TestLogger::operator<< <unsigned long>(unsigned long);
7273
template TestLogger &
7374
TestLogger::operator<< <unsigned long long>(unsigned long long);
7475

75-
#ifdef __SIZEOF_INT128__
76+
#ifdef LIBC_TYPES_HAS_INT128
7677
template TestLogger &TestLogger::operator<< <__uint128_t>(__uint128_t);
77-
#endif
78+
#endif // LIBC_TYPES_HAS_INT128
7879
template TestLogger &TestLogger::operator<< <UInt<128>>(UInt<128>);
7980
template TestLogger &TestLogger::operator<< <UInt<192>>(UInt<192>);
8081
template TestLogger &TestLogger::operator<< <UInt<256>>(UInt<256>);

libc/test/src/__support/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ if(NOT LIBC_TARGET_ARCHITECTURE_IS_NVPTX)
106106
SRCS
107107
uint_test.cpp
108108
DEPENDS
109-
libc.src.__support.uint
110109
libc.src.__support.CPP.optional
110+
libc.src.__support.macros.properties.types
111+
libc.src.__support.uint
111112
)
112113
endif()
113114

@@ -118,8 +119,9 @@ add_libc_test(
118119
SRCS
119120
integer_literals_test.cpp
120121
DEPENDS
121-
libc.src.__support.integer_literals
122122
libc.src.__support.CPP.optional
123+
libc.src.__support.integer_literals
124+
libc.src.__support.macros.properties.types
123125
)
124126

125127
add_libc_test(

libc/test/src/__support/CPP/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ add_libc_test(
88
bit_test.cpp
99
DEPENDS
1010
libc.src.__support.CPP.bit
11+
libc.src.__support.macros.properties.types
1112
libc.src.__support.uint
1213
)
1314

@@ -49,6 +50,7 @@ add_libc_test(
4950
limits_test.cpp
5051
DEPENDS
5152
libc.src.__support.CPP.limits
53+
libc.src.__support.macros.properties.types
5254
libc.src.__support.uint
5355
)
5456

libc/test/src/__support/CPP/bit_test.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,24 @@
88

99
#include "src/__support/CPP/bit.h"
1010
#include "src/__support/UInt.h"
11+
#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
1112
#include "test/UnitTest/Test.h"
1213

1314
#include <stdint.h>
1415

1516
namespace LIBC_NAMESPACE::cpp {
1617

1718
using UnsignedTypesNoBigInt = testing::TypeList<
18-
#if defined(__SIZEOF_INT128__)
19+
#if defined(LIBC_TYPES_HAS_INT128)
1920
__uint128_t,
20-
#endif
21+
#endif // LIBC_TYPES_HAS_INT128
2122
unsigned char, unsigned short, unsigned int, unsigned long,
2223
unsigned long long>;
2324

2425
using UnsignedTypes = testing::TypeList<
25-
#if defined(__SIZEOF_INT128__)
26+
#if defined(LIBC_TYPES_HAS_INT128)
2627
__uint128_t,
27-
#endif
28+
#endif // LIBC_TYPES_HAS_INT128
2829
unsigned char, unsigned short, unsigned int, unsigned long,
2930
unsigned long long, UInt<128>>;
3031

libc/test/src/__support/CPP/limits_test.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "src/__support/CPP/limits.h"
1010
#include "src/__support/UInt.h"
11+
#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
1112
#include "test/UnitTest/Test.h"
1213

1314
namespace LIBC_NAMESPACE {
@@ -36,9 +37,9 @@ TEST(LlvmLibcLimitsTest, UInt128Limits) {
3637
auto umax64 = LIBC_NAMESPACE::UInt<128>(cpp::numeric_limits<uint64_t>::max());
3738
EXPECT_GT(umax128, umax64);
3839
ASSERT_EQ(~LIBC_NAMESPACE::UInt<128>(0), umax128);
39-
#ifdef __SIZEOF_INT128__
40+
#ifdef LIBC_TYPES_HAS_INT128
4041
ASSERT_EQ(~__uint128_t(0), cpp::numeric_limits<__uint128_t>::max());
41-
#endif
42+
#endif // LIBC_TYPES_HAS_INT128
4243
}
4344

4445
} // namespace LIBC_NAMESPACE

libc/test/src/__support/integer_literals_test.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
//===----------------------------------------------------------------------===//
99

1010
#include "src/__support/integer_literals.h"
11+
#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
1112
#include "test/UnitTest/Test.h"
1213

1314
using LIBC_NAMESPACE::operator""_u8;
@@ -66,7 +67,7 @@ TEST(LlvmLibcIntegerLiteralTest, u64) {
6667
}
6768

6869
TEST(LlvmLibcIntegerLiteralTest, u128) {
69-
#if defined(__SIZEOF_INT128__)
70+
#ifdef LIBC_TYPES_HAS_INT128
7071
const __uint128_t ZERO = 0;
7172
const __uint128_t U8_MAX = UINT8_MAX;
7273
const __uint128_t U16_MAX = UINT16_MAX;
@@ -80,7 +81,7 @@ TEST(LlvmLibcIntegerLiteralTest, u128) {
8081
const UInt128 U32_MAX = UINT32_MAX;
8182
const UInt128 U64_MAX = UINT64_MAX;
8283
const UInt128 U128_MAX = (U64_MAX << 64) | U64_MAX;
83-
#endif
84+
#endif // LIBC_TYPES_HAS_INT128
8485
EXPECT_EQ(ZERO, 0_u128);
8586
EXPECT_EQ(U8_MAX, 255_u128);
8687
EXPECT_EQ(U8_MAX, 0xFF_u128);

0 commit comments

Comments
 (0)