Skip to content

[libc] Provide LIBC_TYPES_HAS_INT128 #84149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 8, 2024

Conversation

gchatelet
Copy link
Contributor

Umbrella bug #83182

@llvmbot
Copy link
Member

llvmbot commented Mar 6, 2024

@llvm/pr-subscribers-libc

Author: Guillaume Chatelet (gchatelet)

Changes

Umbrella bug #83182


Patch is 21.85 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/84149.diff

23 Files Affected:

  • (modified) libc/src/__support/CMakeLists.txt (+3)
  • (modified) libc/src/__support/CPP/CMakeLists.txt (+1)
  • (modified) libc/src/__support/CPP/limits.h (+3-2)
  • (modified) libc/src/__support/CPP/type_traits/is_integral.h (+2-1)
  • (modified) libc/src/__support/CPP/type_traits/make_signed.h (+2-1)
  • (modified) libc/src/__support/CPP/type_traits/make_unsigned.h (+2-1)
  • (modified) libc/src/__support/UInt.h (+10-9)
  • (modified) libc/src/__support/UInt128.h (+3-2)
  • (modified) libc/src/__support/integer_utils.h (+3-2)
  • (modified) libc/src/__support/macros/properties/types.h (+7)
  • (modified) libc/test/UnitTest/CMakeLists.txt (+1)
  • (modified) libc/test/UnitTest/LibcTest.cpp (+3-2)
  • (modified) libc/test/UnitTest/TestLogger.cpp (+4-3)
  • (modified) libc/test/src/__support/CMakeLists.txt (+4-2)
  • (modified) libc/test/src/__support/CPP/CMakeLists.txt (+2)
  • (modified) libc/test/src/__support/CPP/bit_test.cpp (+2-1)
  • (modified) libc/test/src/__support/CPP/limits_test.cpp (+3-2)
  • (modified) libc/test/src/__support/integer_literals_test.cpp (+3-2)
  • (modified) libc/test/src/__support/uint_test.cpp (+5-4)
  • (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+4)
  • (modified) utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel (+2)
  • (modified) utils/bazel/llvm-project-overlay/libc/test/src/__support/BUILD.bazel (+2)
  • (modified) utils/bazel/llvm-project-overlay/libc/test/src/__support/CPP/BUILD.bazel (+2)
diff --git a/libc/src/__support/CMakeLists.txt b/libc/src/__support/CMakeLists.txt
index 1a4b3e9a2145c0..dde3a908d5d3b2 100644
--- a/libc/src/__support/CMakeLists.txt
+++ b/libc/src/__support/CMakeLists.txt
@@ -203,6 +203,7 @@ add_header_library(
     libc.src.__support.common
     libc.src.__support.CPP.bit
     libc.src.__support.CPP.type_traits
+    libc.src.__support.macros.properties.types
 )
 
 add_header_library(
@@ -217,6 +218,7 @@ add_header_library(
     libc.src.__support.CPP.bit
     libc.src.__support.CPP.type_traits
     libc.src.__support.macros.optimization
+    libc.src.__support.macros.properties.types
 )
 
 add_header_library(
@@ -225,6 +227,7 @@ add_header_library(
     UInt128.h
   DEPENDS
     .uint
+    libc.src.__support.macros.properties.types
 )
 
 add_header_library(
diff --git a/libc/src/__support/CPP/CMakeLists.txt b/libc/src/__support/CPP/CMakeLists.txt
index 6c35bc7090819e..6216505eae23a3 100644
--- a/libc/src/__support/CPP/CMakeLists.txt
+++ b/libc/src/__support/CPP/CMakeLists.txt
@@ -49,6 +49,7 @@ add_header_library(
   DEPENDS
     .type_traits
     libc.include.llvm-libc-macros.limits_macros
+    libc.src.__support.macros.properties.types
 )
 
 add_header_library(
diff --git a/libc/src/__support/CPP/limits.h b/libc/src/__support/CPP/limits.h
index 1ffde5f9556f87..5b9b3e755c72ba 100644
--- a/libc/src/__support/CPP/limits.h
+++ b/libc/src/__support/CPP/limits.h
@@ -12,7 +12,8 @@
 #include "include/llvm-libc-macros/limits-macros.h" // CHAR_BIT
 #include "src/__support/CPP/type_traits/is_integral.h"
 #include "src/__support/CPP/type_traits/is_signed.h"
-#include "src/__support/macros/attributes.h" // LIBC_INLINE
+#include "src/__support/macros/attributes.h"       // LIBC_INLINE
+#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
 
 namespace LIBC_NAMESPACE {
 namespace cpp {
@@ -76,7 +77,7 @@ template <>
 struct numeric_limits<unsigned char>
     : public internal::integer_impl<unsigned char, 0, UCHAR_MAX> {};
 
-#ifdef __SIZEOF_INT128__
+#ifdef LIBC_TYPES_HAS_INT128
 // On platform where UInt128 resolves to __uint128_t, this specialization
 // provides the limits of UInt128.
 template <>
diff --git a/libc/src/__support/CPP/type_traits/is_integral.h b/libc/src/__support/CPP/type_traits/is_integral.h
index 2808be594b20ed..68e16ff8418336 100644
--- a/libc/src/__support/CPP/type_traits/is_integral.h
+++ b/libc/src/__support/CPP/type_traits/is_integral.h
@@ -11,6 +11,7 @@
 #include "src/__support/CPP/type_traits/is_same.h"
 #include "src/__support/CPP/type_traits/remove_cv.h"
 #include "src/__support/macros/attributes.h"
+#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
 
 namespace LIBC_NAMESPACE::cpp {
 
@@ -25,7 +26,7 @@ template <typename T> struct is_integral {
 public:
   LIBC_INLINE_VAR static constexpr bool value = __is_unqualified_any_of<
       T,
-#ifdef __SIZEOF_INT128__
+#ifdef LIBC_TYPES_HAS_INT128
       __int128_t, __uint128_t,
 #endif
       char, signed char, unsigned char, short, unsigned short, int,
diff --git a/libc/src/__support/CPP/type_traits/make_signed.h b/libc/src/__support/CPP/type_traits/make_signed.h
index 21302850bfd4ab..4652d8b6bfa56a 100644
--- a/libc/src/__support/CPP/type_traits/make_signed.h
+++ b/libc/src/__support/CPP/type_traits/make_signed.h
@@ -9,6 +9,7 @@
 #define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_MAKE_SIGNED_H
 
 #include "src/__support/CPP/type_traits/type_identity.h"
+#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
 
 namespace LIBC_NAMESPACE::cpp {
 
@@ -26,7 +27,7 @@ template <> struct make_signed<unsigned int> : type_identity<int> {};
 template <> struct make_signed<unsigned long> : type_identity<long> {};
 template <>
 struct make_signed<unsigned long long> : type_identity<long long> {};
-#ifdef __SIZEOF_INT128__
+#ifdef LIBC_TYPES_HAS_INT128
 template <> struct make_signed<__int128_t> : type_identity<__int128_t> {};
 template <> struct make_signed<__uint128_t> : type_identity<__int128_t> {};
 #endif
diff --git a/libc/src/__support/CPP/type_traits/make_unsigned.h b/libc/src/__support/CPP/type_traits/make_unsigned.h
index 20948014a66574..1e814ae002a777 100644
--- a/libc/src/__support/CPP/type_traits/make_unsigned.h
+++ b/libc/src/__support/CPP/type_traits/make_unsigned.h
@@ -9,6 +9,7 @@
 #define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_MAKE_UNSIGNED_H
 
 #include "src/__support/CPP/type_traits/type_identity.h"
+#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
 
 namespace LIBC_NAMESPACE::cpp {
 
@@ -31,7 +32,7 @@ template <>
 struct make_unsigned<unsigned long> : type_identity<unsigned long> {};
 template <>
 struct make_unsigned<unsigned long long> : type_identity<unsigned long long> {};
-#ifdef __SIZEOF_INT128__
+#ifdef LIBC_TYPES_HAS_INT128
 template <> struct make_unsigned<__int128_t> : type_identity<__uint128_t> {};
 template <> struct make_unsigned<__uint128_t> : type_identity<__uint128_t> {};
 #endif
diff --git a/libc/src/__support/UInt.h b/libc/src/__support/UInt.h
index 5973e6fab1d7d5..f5ccdaa697ccce 100644
--- a/libc/src/__support/UInt.h
+++ b/libc/src/__support/UInt.h
@@ -15,9 +15,10 @@
 #include "src/__support/CPP/optional.h"
 #include "src/__support/CPP/type_traits.h"
 #include "src/__support/integer_utils.h"
-#include "src/__support/macros/attributes.h"   // LIBC_INLINE
-#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
-#include "src/__support/math_extras.h"         // SumCarry, DiffBorrow
+#include "src/__support/macros/attributes.h"       // LIBC_INLINE
+#include "src/__support/macros/optimization.h"     // LIBC_UNLIKELY
+#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
+#include "src/__support/math_extras.h"             // SumCarry, DiffBorrow
 #include "src/__support/number_pair.h"
 
 #include <stddef.h> // For size_t
@@ -31,9 +32,9 @@ template <typename T> struct half_width;
 template <> struct half_width<uint64_t> : type_identity<uint32_t> {};
 template <> struct half_width<uint32_t> : type_identity<uint16_t> {};
 template <> struct half_width<uint16_t> : type_identity<uint8_t> {};
-#ifdef __SIZEOF_INT128__
+#ifdef LIBC_TYPES_HAS_INT128
 template <> struct half_width<__uint128_t> : type_identity<uint64_t> {};
-#endif // __SIZEOF_INT128__
+#endif // LIBC_TYPES_HAS_INT128
 
 template <typename T> using half_width_t = typename half_width<T>::type;
 } // namespace internal
@@ -615,7 +616,7 @@ struct BigInt {
       val[1] = uint32_t(tmp >> 32);
       return;
     }
-#ifdef __SIZEOF_INT128__
+#ifdef LIBC_TYPES_HAS_INT128
     if constexpr ((Bits == 128) && (WORD_SIZE == 64)) {
       // Use builtin 128 bits if available;
       if (s >= 128) {
@@ -629,7 +630,7 @@ struct BigInt {
       val[1] = uint64_t(tmp >> 64);
       return;
     }
-#endif // __SIZEOF_INT128__
+#endif // LIBC_TYPES_HAS_INT128
     if (LIBC_UNLIKELY(s == 0))
       return;
 
@@ -686,7 +687,7 @@ struct BigInt {
       val[1] = uint32_t(tmp >> 32);
       return;
     }
-#ifdef __SIZEOF_INT128__
+#ifdef LIBC_TYPES_HAS_INT128
     if constexpr ((Bits == 128) && (WORD_SIZE == 64)) {
       // Use builtin 128 bits if available;
       if (s >= 128) {
@@ -704,7 +705,7 @@ struct BigInt {
       val[1] = uint64_t(tmp >> 64);
       return;
     }
-#endif // __SIZEOF_INT128__
+#endif // LIBC_TYPES_HAS_INT128
 
     if (LIBC_UNLIKELY(s == 0))
       return;
diff --git a/libc/src/__support/UInt128.h b/libc/src/__support/UInt128.h
index 0558e5095f9f51..704144985e723d 100644
--- a/libc/src/__support/UInt128.h
+++ b/libc/src/__support/UInt128.h
@@ -10,13 +10,14 @@
 #define LLVM_LIBC_SRC___SUPPORT_UINT128_H
 
 #include "UInt.h"
+#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
 
-#if defined(__SIZEOF_INT128__)
+#ifdef LIBC_TYPES_HAS_INT128
 using UInt128 = __uint128_t;
 using Int128 = __int128_t;
 #else
 using UInt128 = LIBC_NAMESPACE::cpp::UInt<128>;
 using Int128 = LIBC_NAMESPACE::cpp::Int<128>;
-#endif
+#endif //  LIBC_TYPES_HAS_INT128
 
 #endif // LLVM_LIBC_SRC___SUPPORT_UINT128_H
diff --git a/libc/src/__support/integer_utils.h b/libc/src/__support/integer_utils.h
index 15e04bda808231..4794a577ff17f7 100644
--- a/libc/src/__support/integer_utils.h
+++ b/libc/src/__support/integer_utils.h
@@ -11,6 +11,7 @@
 
 #include "src/__support/CPP/type_traits.h"
 #include "src/__support/common.h"
+#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
 
 #include "math_extras.h"
 #include "number_pair.h"
@@ -52,7 +53,7 @@ LIBC_INLINE constexpr NumberPair<uint32_t> full_mul<uint32_t>(uint32_t a,
   return result;
 }
 
-#ifdef __SIZEOF_INT128__
+#ifdef LIBC_TYPES_HAS_INT128
 template <>
 LIBC_INLINE constexpr NumberPair<uint64_t> full_mul<uint64_t>(uint64_t a,
                                                               uint64_t b) {
@@ -62,7 +63,7 @@ LIBC_INLINE constexpr NumberPair<uint64_t> full_mul<uint64_t>(uint64_t a,
   result.hi = uint64_t(prod >> 64);
   return result;
 }
-#endif // __SIZEOF_INT128__
+#endif // LIBC_TYPES_HAS_INT128
 
 } // namespace LIBC_NAMESPACE
 
diff --git a/libc/src/__support/macros/properties/types.h b/libc/src/__support/macros/properties/types.h
index 8760f78875c417..42345e4743cefa 100644
--- a/libc/src/__support/macros/properties/types.h
+++ b/libc/src/__support/macros/properties/types.h
@@ -17,6 +17,8 @@
 #include "src/__support/macros/properties/cpu_features.h"
 #include "src/__support/macros/properties/os.h"
 
+#include <stdint.h> // __SIZEOF_INT128__
+
 // 'long double' properties.
 #if (LDBL_MANT_DIG == 53)
 #define LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64
@@ -26,6 +28,11 @@
 #define LIBC_TYPES_LONG_DOUBLE_IS_FLOAT128
 #endif
 
+// int128 / uint128 support
+#if defined(__SIZEOF_INT128__)
+#define LIBC_TYPES_HAS_INT128
+#endif // defined(__SIZEOF_INT128__)
+
 // -- float16 support ---------------------------------------------------------
 // TODO: move this logic to "llvm-libc-types/float16.h"
 #if defined(LIBC_TARGET_ARCH_IS_X86_64) && defined(LIBC_TARGET_CPU_HAS_SSE2)
diff --git a/libc/test/UnitTest/CMakeLists.txt b/libc/test/UnitTest/CMakeLists.txt
index 4668f0061975f8..01e484a1a65cd6 100644
--- a/libc/test/UnitTest/CMakeLists.txt
+++ b/libc/test/UnitTest/CMakeLists.txt
@@ -73,6 +73,7 @@ add_unittest_framework_library(
     libc.src.__support.CPP.string_view
     libc.src.__support.CPP.type_traits
     libc.src.__support.fixed_point.fx_rep
+    libc.src.__support.macros.properties.types
     libc.src.__support.OSUtil.osutil
     libc.src.__support.uint128
 )
diff --git a/libc/test/UnitTest/LibcTest.cpp b/libc/test/UnitTest/LibcTest.cpp
index 7b0e4fca83683b..8456d09221f9da 100644
--- a/libc/test/UnitTest/LibcTest.cpp
+++ b/libc/test/UnitTest/LibcTest.cpp
@@ -13,6 +13,7 @@
 #include "src/__support/CPP/string_view.h"
 #include "src/__support/UInt128.h"
 #include "src/__support/fixed_point/fx_rep.h"
+#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
 #include "test/UnitTest/TestLogger.h"
 
 #if __STDC_HOSTED__
@@ -215,11 +216,11 @@ TEST_SPECIALIZATION(bool);
 
 // We cannot just use a single UInt128 specialization as that resolves to only
 // one type, UInt<128> or __uint128_t. We want both overloads as we want to
-#ifdef __SIZEOF_INT128__
+#ifdef LIBC_TYPES_HAS_INT128
 // When builtin __uint128_t type is available, include its specialization
 // also.
 TEST_SPECIALIZATION(__uint128_t);
-#endif
+#endif // LIBC_TYPES_HAS_INT128
 
 TEST_SPECIALIZATION(LIBC_NAMESPACE::cpp::Int<128>);
 
diff --git a/libc/test/UnitTest/TestLogger.cpp b/libc/test/UnitTest/TestLogger.cpp
index 6bb0e17dc3888e..8da1c5a2201ede 100644
--- a/libc/test/UnitTest/TestLogger.cpp
+++ b/libc/test/UnitTest/TestLogger.cpp
@@ -3,6 +3,7 @@
 #include "src/__support/CPP/string_view.h"
 #include "src/__support/OSUtil/io.h" // write_to_stderr
 #include "src/__support/UInt128.h"
+#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
 
 #include <stdint.h>
 
@@ -68,11 +69,11 @@ template TestLogger &TestLogger::operator<< <unsigned short>(unsigned short);
 template TestLogger &TestLogger::operator<< <unsigned int>(unsigned int);
 template TestLogger &TestLogger::operator<< <unsigned long>(unsigned long);
 template TestLogger &
-TestLogger::operator<< <unsigned long long>(unsigned long long);
+    TestLogger::operator<< <unsigned long long>(unsigned long long);
 
-#ifdef __SIZEOF_INT128__
+#ifdef LIBC_TYPES_HAS_INT128
 template TestLogger &TestLogger::operator<< <__uint128_t>(__uint128_t);
-#endif
+#endif // LIBC_TYPES_HAS_INT128
 template TestLogger &TestLogger::operator<< <cpp::UInt<128>>(cpp::UInt<128>);
 template TestLogger &TestLogger::operator<< <cpp::UInt<192>>(cpp::UInt<192>);
 template TestLogger &TestLogger::operator<< <cpp::UInt<256>>(cpp::UInt<256>);
diff --git a/libc/test/src/__support/CMakeLists.txt b/libc/test/src/__support/CMakeLists.txt
index 7200ac276fe502..f27ca9fd9ad6cd 100644
--- a/libc/test/src/__support/CMakeLists.txt
+++ b/libc/test/src/__support/CMakeLists.txt
@@ -91,8 +91,9 @@ if(NOT LIBC_TARGET_ARCHITECTURE_IS_NVPTX)
     SRCS
       uint_test.cpp
     DEPENDS
-      libc.src.__support.uint
       libc.src.__support.CPP.optional
+      libc.src.__support.macros.properties.types
+      libc.src.__support.uint
   )
 endif()
 
@@ -103,8 +104,9 @@ add_libc_test(
   SRCS
     integer_literals_test.cpp
   DEPENDS
-    libc.src.__support.integer_literals
     libc.src.__support.CPP.optional
+    libc.src.__support.integer_literals
+    libc.src.__support.macros.properties.types
 )
 
 add_libc_test(
diff --git a/libc/test/src/__support/CPP/CMakeLists.txt b/libc/test/src/__support/CPP/CMakeLists.txt
index d7f332f5b0fbd9..f94429e03b3cbc 100644
--- a/libc/test/src/__support/CPP/CMakeLists.txt
+++ b/libc/test/src/__support/CPP/CMakeLists.txt
@@ -8,6 +8,7 @@ add_libc_test(
     bit_test.cpp
   DEPENDS
     libc.src.__support.CPP.bit
+    libc.src.__support.macros.properties.types
     libc.src.__support.uint
 )
 
@@ -49,6 +50,7 @@ add_libc_test(
     limits_test.cpp
   DEPENDS
     libc.src.__support.CPP.limits
+    libc.src.__support.macros.properties.types
     libc.src.__support.uint
 )
 
diff --git a/libc/test/src/__support/CPP/bit_test.cpp b/libc/test/src/__support/CPP/bit_test.cpp
index 115a5d505c4b7a..873bcc9c9fbc79 100644
--- a/libc/test/src/__support/CPP/bit_test.cpp
+++ b/libc/test/src/__support/CPP/bit_test.cpp
@@ -8,6 +8,7 @@
 
 #include "src/__support/CPP/bit.h"
 #include "src/__support/UInt.h"
+#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
 #include "test/UnitTest/Test.h"
 
 #include <stdint.h>
@@ -17,7 +18,7 @@ namespace LIBC_NAMESPACE::cpp {
 using UnsignedTypes =
     testing::TypeList<unsigned char, unsigned short, unsigned int,
                       unsigned long, unsigned long long,
-#if defined(__SIZEOF_INT128__)
+#ifdef LIBC_TYPES_HAS_INT128
                       __uint128_t,
 #endif
                       cpp::UInt<128>>;
diff --git a/libc/test/src/__support/CPP/limits_test.cpp b/libc/test/src/__support/CPP/limits_test.cpp
index 12641b7b51b6ce..7b1d43ae5e0cc0 100644
--- a/libc/test/src/__support/CPP/limits_test.cpp
+++ b/libc/test/src/__support/CPP/limits_test.cpp
@@ -8,6 +8,7 @@
 
 #include "src/__support/CPP/limits.h"
 #include "src/__support/UInt.h"
+#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
 #include "test/UnitTest/Test.h"
 
 namespace LIBC_NAMESPACE {
@@ -37,9 +38,9 @@ TEST(LlvmLibcLimitsTest, UInt128Limits) {
       LIBC_NAMESPACE::cpp::UInt<128>(cpp::numeric_limits<uint64_t>::max());
   EXPECT_GT(umax128, umax64);
   ASSERT_EQ(~LIBC_NAMESPACE::cpp::UInt<128>(0), umax128);
-#ifdef __SIZEOF_INT128__
+#ifdef LIBC_TYPES_HAS_INT128
   ASSERT_EQ(~__uint128_t(0), cpp::numeric_limits<__uint128_t>::max());
-#endif
+#endif // LIBC_TYPES_HAS_INT128
 }
 
 } // namespace LIBC_NAMESPACE
diff --git a/libc/test/src/__support/integer_literals_test.cpp b/libc/test/src/__support/integer_literals_test.cpp
index 10c3625a0e5a49..90bbf23d5e4b61 100644
--- a/libc/test/src/__support/integer_literals_test.cpp
+++ b/libc/test/src/__support/integer_literals_test.cpp
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/__support/integer_literals.h"
+#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
 #include "test/UnitTest/Test.h"
 
 using LIBC_NAMESPACE::operator""_u8;
@@ -66,7 +67,7 @@ TEST(LlvmLibcIntegerLiteralTest, u64) {
 }
 
 TEST(LlvmLibcIntegerLiteralTest, u128) {
-#if defined(__SIZEOF_INT128__)
+#ifdef LIBC_TYPES_HAS_INT128
   const __uint128_t ZERO = 0;
   const __uint128_t U8_MAX = UINT8_MAX;
   const __uint128_t U16_MAX = UINT16_MAX;
@@ -80,7 +81,7 @@ TEST(LlvmLibcIntegerLiteralTest, u128) {
   const UInt128 U32_MAX = UINT32_MAX;
   const UInt128 U64_MAX = UINT64_MAX;
   const UInt128 U128_MAX = (U64_MAX << 64) | U64_MAX;
-#endif
+#endif // LIBC_TYPES_HAS_INT128
   EXPECT_EQ(ZERO, 0_u128);
   EXPECT_EQ(U8_MAX, 255_u128);
   EXPECT_EQ(U8_MAX, 0xFF_u128);
diff --git a/libc/test/src/__support/uint_test.cpp b/libc/test/src/__support/uint_test.cpp
index 963c553b10d01d..34566d0456c595 100644
--- a/libc/test/src/__support/uint_test.cpp
+++ b/libc/test/src/__support/uint_test.cpp
@@ -8,6 +8,7 @@
 
 #include "src/__support/CPP/optional.h"
 #include "src/__support/UInt.h"
+#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
 
 #include "test/UnitTest/Test.h"
 #include <math.h> // HUGE_VALF, HUGE_VALF
@@ -41,7 +42,7 @@ TEST(LlvmLibcUIntClassTest, BitCastToFromDouble) {
   }
 }
 
-#ifdef __SIZEOF_INT128__
+#ifdef LIBC_TYPES_HAS_INT128
 TEST(LlvmLibcUIntClassTest, BitCastToFromNativeUint128) {
   static_assert(cpp::is_trivially_copyable<LL_UInt128>::value);
   static_assert(sizeof(LL_UInt128) == sizeof(__uint128_t));
@@ -52,7 +53,7 @@ TEST(LlvmLibcUIntClassTest, BitCastToFromNativeUint128) {
     EXPECT_TRUE(value == forth);
   }
 }
-#endif
+#endif // LIBC_TYPES_HAS_INT128
 
 #ifdef LIBC_TYPES_HAS_FLOAT128
 TEST(LlvmLibcUIntClassTest, BitCastToFromNativeFloat128) {
@@ -652,7 +653,7 @@ TEST(LlvmLibcUIntClassTest, BasicArithmeticInt128Tests) {
   ASSERT_EQ(c * b, b);
 }
 
-#ifdef __SIZEOF_INT128__
+#ifdef LIBC_TYPES_HAS_INT128
 
 TEST(LlvmLibcUIntClassTest, ConstructorFromUInt128Tests) {
   __uint128_t a = (__uint128_t(123) << 64) + 1;
@@ -707,7 +708,7 @@ TEST(LlvmLibcUIntClassTest, WordTypeUInt128Tests) {
   EXPECT_TRUE(f == r);
 }
 
-#endif // __SIZEOF_INT128__
+#endif // LIBC_TYPES_HAS_INT128
 
 TEST(LlvmLibcUIntClassTest, OtherWordTypeTests) {
   using LL_UInt96 = cpp::BigInt<96, false, uint32_t>;
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 49a454379e1c7a..f3735997806768 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -211,6 +211,7 @@ libc_support_library(
     deps = [
         "__support_cpp_type_traits",
         "__support_macros_attributes",
+        ":__support_macros_properties_types",
         ":llvm_libc_macros_limits_macros",
     ],
 )
@@ -444,6 +445,7 @@ libc_support_library(
     deps = [
         ":__support_common",
         ":__support_cpp_type_traits",
+        ":__support_macros_properties_types",
         ":__support_math_extras",
         ":__support_number_pair",
     ],
@@ -461,6 +463,7 @@ libc_support_library(
         ":__support_integer_utils",
         ":__support_macros_attributes",
         ":__support_macros_optimization",
+        ":__support_macros_properties_types",
         ":__support_math_extras",
         ":__support_number_pair",
     ],
@@ -470,6 +473,7 @@ libc_support_library(
     name = "__support_uint128",
     hdrs = ["src/__support/UInt128.h"],
     deps = [
+        ":__support_macros_properties_types",
         ":__support_uint",
     ],
 )
diff --git a/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel
index a5c18fbb68b398..cb7b6f0f423113 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel
@@ -17,6 +17,7 @@ libc_support_library(
     deps = [
         "//libc:__support_cpp_string",
         "//libc:__support_cpp_string_view",
+        "//libc:__support_macros_properties_types",
         "//libc:__support_osutil_io",
         "//libc:__support_uint128",
     ],
...
[truncated]

@gchatelet gchatelet changed the title [libc] Provide LIBC_TYPES_HAS_INT128 [libc] Provide LIBC_TYPES_HAS_INT128 Mar 6, 2024
@gchatelet
Copy link
Contributor Author

@lntue should we also provide aliases (using int128_t = __int128_t) as we do for _Float16 et al.?
It looks to me like it would be more consistent.

@lntue
Copy link
Contributor

lntue commented Mar 6, 2024

@lntue should we also provide aliases (using int128_t = __int128_t) as we do for _Float16 et al.?
It looks to me like it would be more consistent.

For us, shall the alias be uint128 instead, similar to float16, just in case uint128_t is standardized in the future?

@gchatelet
Copy link
Contributor Author

@lntue should we also provide aliases (using int128_t = __int128_t) as we do for _Float16 et al.?
It looks to me like it would be more consistent.

For us, shall the alias be uint128 instead, similar to float16, just in case uint128_t is standardized in the future?

I was suggesting something like the following in types.h

// int128 / uint128 support
#if defined(__SIZEOF_INT128__)
#define LIBC_TYPES_HAS_INT128
using uint128_t = __uint128_t;
using int128_t = __int128_t;
#endif // defined(__SIZEOF_INT128__)

So we could provide both signed and unsigned. The aim is to use them as the other types (i.e., uint64_t) whenever they are available.

And yes it would be only for internal usage.

@@ -17,6 +17,8 @@
#include "src/__support/macros/properties/cpu_features.h"
#include "src/__support/macros/properties/os.h"

#include <stdint.h> // __SIZEOF_INT128__
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you include include/llvm-libc-macros/stdint-macros.h instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in this PR for the same reasons as #83441 (comment)

@lntue
Copy link
Contributor

lntue commented Mar 6, 2024

@lntue should we also provide aliases (using int128_t = __int128_t) as we do for _Float16 et al.?
It looks to me like it would be more consistent.

For us, shall the alias be uint128 instead, similar to float16, just in case uint128_t is standardized in the future?

I was suggesting something like the following in types.h

// int128 / uint128 support
#if defined(__SIZEOF_INT128__)
#define LIBC_TYPES_HAS_INT128
using uint128_t = __uint128_t;
using int128_t = __int128_t;
#endif // defined(__SIZEOF_INT128__)

So we could provide both signed and unsigned. The aim is to use them as the other types (i.e., uint64_t) whenever they are available.

And yes it would be only for internal usage.

My original intent was to distinguish between our internal one (u)int128 with the possible (if standardized) spelling (u)int128_t. But now we are providing a complete stdint.h header, so I think it is ok to use uint128_t and int128_t for this. On the other hand, it might be at odds with float16 and float128 spellings.

@gchatelet
Copy link
Contributor Author

@lntue should we also provide aliases (using int128_t = __int128_t) as we do for _Float16 et al.?
It looks to me like it would be more consistent.

For us, shall the alias be uint128 instead, similar to float16, just in case uint128_t is standardized in the future?

I was suggesting something like the following in types.h

// int128 / uint128 support
#if defined(__SIZEOF_INT128__)
#define LIBC_TYPES_HAS_INT128
using uint128_t = __uint128_t;
using int128_t = __int128_t;
#endif // defined(__SIZEOF_INT128__)

So we could provide both signed and unsigned. The aim is to use them as the other types (i.e., uint64_t) whenever they are available.
And yes it would be only for internal usage.

My original intent was to distinguish between our internal one (u)int128 with the possible (if standardized) spelling (u)int128_t. But now we are providing a complete stdint.h header, so I think it is ok to use uint128_t and int128_t for this. On the other hand, it might be at odds with float16 and float128 spellings.

Ha! Then I misunderstood your point. Right now the type would be available through types.h, if it gets standardized we'd have to add it to our stdint.h and guard it properly. Why would you want to distinguish between the two? They ought to have the same semantics anyways (same size, same alignment requirements).

@lntue
Copy link
Contributor

lntue commented Mar 6, 2024

@lntue should we also provide aliases (using int128_t = __int128_t) as we do for _Float16 et al.?
It looks to me like it would be more consistent.

For us, shall the alias be uint128 instead, similar to float16, just in case uint128_t is standardized in the future?

I was suggesting something like the following in types.h

// int128 / uint128 support
#if defined(__SIZEOF_INT128__)
#define LIBC_TYPES_HAS_INT128
using uint128_t = __uint128_t;
using int128_t = __int128_t;
#endif // defined(__SIZEOF_INT128__)

So we could provide both signed and unsigned. The aim is to use them as the other types (i.e., uint64_t) whenever they are available.
And yes it would be only for internal usage.

My original intent was to distinguish between our internal one (u)int128 with the possible (if standardized) spelling (u)int128_t. But now we are providing a complete stdint.h header, so I think it is ok to use uint128_t and int128_t for this. On the other hand, it might be at odds with float16 and float128 spellings.

Ha! Then I misunderstood your point. Right now the type would be available through types.h, if it gets standardized we'd have to add it to our stdint.h and guard it properly. Why would you want to distinguish between the two? They ought to have the same semantics anyways (same size, same alignment requirements).

That's fine for me. And ideally it's only used for some type setup things, and all the internal computational usage should use the UInt128 type instead, so that it works on all platforms.

@gchatelet gchatelet force-pushed the add_LIBC_TYPES_HAS_INT128 branch from b3c2a30 to 5ac268a Compare March 8, 2024 10:06
@gchatelet
Copy link
Contributor Author

Can I haz approvalz?

@gchatelet gchatelet merged commit 23c397c into llvm:main Mar 8, 2024
@gchatelet gchatelet deleted the add_LIBC_TYPES_HAS_INT128 branch March 8, 2024 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants