From 75eb902055a60341221599314599a64e17a340aa Mon Sep 17 00:00:00 2001 From: Guillaume Chatelet Date: Thu, 29 Feb 2024 16:06:11 +0000 Subject: [PATCH 1/3] [libc] Provide `LIBC_TYPES_HAS_INT64` --- libc/src/__support/UInt.h | 11 ++++++----- .../src/__support/macros/properties/CMakeLists.txt | 1 + libc/src/__support/macros/properties/types.h | 10 ++++++++-- libc/src/string/memory_utils/op_generic.h | 9 +++------ libc/test/src/string/memory_utils/op_tests.cpp | 14 +++++++------- 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/libc/src/__support/UInt.h b/libc/src/__support/UInt.h index ae1fe7aaa1828..d024c17772c38 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_INT64 +#include "src/__support/math_extras.h" // SumCarry, DiffBorrow #include "src/__support/number_pair.h" #include // For size_t @@ -872,11 +873,11 @@ namespace internal { // availability. template struct WordTypeSelector : cpp::type_identity< -#if defined(UINT64_MAX) +#ifdef LIBC_TYPES_HAS_INT64 uint64_t #else uint32_t -#endif +#endif // LIBC_TYPES_HAS_INT64 > { }; // Except if we request 32 bits explicitly. diff --git a/libc/src/__support/macros/properties/CMakeLists.txt b/libc/src/__support/macros/properties/CMakeLists.txt index bbc45650f3fca..62436a8ebf2da 100644 --- a/libc/src/__support/macros/properties/CMakeLists.txt +++ b/libc/src/__support/macros/properties/CMakeLists.txt @@ -34,5 +34,6 @@ add_header_library( .cpu_features .os libc.include.llvm-libc-macros.float_macros + libc.include.llvm-libc-macros.stdint_macros libc.include.llvm-libc-types.float128 ) diff --git a/libc/src/__support/macros/properties/types.h b/libc/src/__support/macros/properties/types.h index e812a9dfcfd8a..9aa004510d206 100644 --- a/libc/src/__support/macros/properties/types.h +++ b/libc/src/__support/macros/properties/types.h @@ -10,8 +10,9 @@ #ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_TYPES_H #define LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_TYPES_H -#include "llvm-libc-macros/float-macros.h" // LDBL_MANT_DIG -#include "llvm-libc-types/float128.h" // float128 +#include "llvm-libc-macros/float-macros.h" // LDBL_MANT_DIG +#include "llvm-libc-macros/stdint-macros.h" // UINT64_MAX +#include "llvm-libc-types/float128.h" // float128 #include "src/__support/macros/properties/architectures.h" #include "src/__support/macros/properties/compiler.h" #include "src/__support/macros/properties/cpu_features.h" @@ -26,6 +27,11 @@ #define LIBC_LONG_DOUBLE_IS_FLOAT128 #endif +// int64 / uint64 support +#if defined(UINT64_MAX) +#define LIBC_TYPES_HAS_INT64 +#endif // UINT64_MAX + // float16 support. #if defined(LIBC_TARGET_ARCH_IS_X86_64) && defined(LIBC_TARGET_CPU_HAS_SSE2) #if (defined(LIBC_COMPILER_CLANG_VER) && (LIBC_COMPILER_CLANG_VER >= 1500)) || \ diff --git a/libc/src/string/memory_utils/op_generic.h b/libc/src/string/memory_utils/op_generic.h index c7dbd5dd1d6cc..9f356adb9449d 100644 --- a/libc/src/string/memory_utils/op_generic.h +++ b/libc/src/string/memory_utils/op_generic.h @@ -28,6 +28,7 @@ #include "src/__support/common.h" #include "src/__support/endian.h" #include "src/__support/macros/optimization.h" +#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT64 #include "src/string/memory_utils/op_builtin.h" #include "src/string/memory_utils/utils.h" @@ -37,10 +38,6 @@ static_assert((UINTPTR_MAX == 4294967295U) || (UINTPTR_MAX == 18446744073709551615UL), "We currently only support 32- or 64-bit platforms"); -#if defined(UINT64_MAX) -#define LLVM_LIBC_HAS_UINT64 -#endif - namespace LIBC_NAMESPACE { // Compiler types using the vector attributes. using generic_v128 = uint8_t __attribute__((__vector_size__(16))); @@ -60,9 +57,9 @@ template struct is_scalar : cpp::false_type {}; template <> struct is_scalar : cpp::true_type {}; template <> struct is_scalar : cpp::true_type {}; template <> struct is_scalar : cpp::true_type {}; -#ifdef LLVM_LIBC_HAS_UINT64 +#ifdef LIBC_TYPES_HAS_INT64 template <> struct is_scalar : cpp::true_type {}; -#endif // LLVM_LIBC_HAS_UINT64 +#endif // LIBC_TYPES_HAS_INT64 template constexpr bool is_scalar_v = is_scalar::value; template struct is_vector : cpp::false_type {}; diff --git a/libc/test/src/string/memory_utils/op_tests.cpp b/libc/test/src/string/memory_utils/op_tests.cpp index 15ac9607bf3e3..95a04755eb4db 100644 --- a/libc/test/src/string/memory_utils/op_tests.cpp +++ b/libc/test/src/string/memory_utils/op_tests.cpp @@ -7,9 +7,9 @@ //===----------------------------------------------------------------------===// #include "memory_check_utils.h" +#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT64 #include "src/string/memory_utils/op_aarch64.h" #include "src/string/memory_utils/op_builtin.h" -#include "src/string/memory_utils/op_generic.h" // LLVM_LIBC_HAS_UINT64 #include "src/string/memory_utils/op_riscv.h" #include "src/string/memory_utils/op_x86.h" #include "test/UnitTest/Test.h" @@ -124,9 +124,9 @@ using MemsetImplementations = testing::TypeList< builtin::Memset<32>, // builtin::Memset<64>, #endif -#ifdef LLVM_LIBC_HAS_UINT64 +#ifdef LIBC_TYPES_HAS_INT64 generic::Memset, generic::Memset>, -#endif +#endif // LIBC_TYPES_HAS_INT64 #ifdef __AVX512F__ generic::Memset, generic::Memset>, #endif @@ -210,9 +210,9 @@ using BcmpImplementations = testing::TypeList< #ifndef LIBC_TARGET_ARCH_IS_ARM // Removing non uint8_t types for ARM generic::Bcmp, generic::Bcmp, // -#ifdef LLVM_LIBC_HAS_UINT64 +#ifdef LIBC_TYPES_HAS_INT64 generic::Bcmp, -#endif // LLVM_LIBC_HAS_UINT64 +#endif // LIBC_TYPES_HAS_INT64 generic::BcmpSequence, generic::BcmpSequence, // generic::BcmpSequence, // @@ -292,9 +292,9 @@ using MemcmpImplementations = testing::TypeList< #ifndef LIBC_TARGET_ARCH_IS_ARM // Removing non uint8_t types for ARM generic::Memcmp, generic::Memcmp, // -#ifdef LLVM_LIBC_HAS_UINT64 +#ifdef LIBC_TYPES_HAS_INT64 generic::Memcmp, -#endif // LLVM_LIBC_HAS_UINT64 +#endif // LIBC_TYPES_HAS_INT64 generic::MemcmpSequence, generic::MemcmpSequence, // #endif // LIBC_TARGET_ARCH_IS_ARM From cd668a6995d297d971c2b5f10dd4c28211d4d87f Mon Sep 17 00:00:00 2001 From: Guillaume Chatelet Date: Wed, 6 Mar 2024 10:36:18 +0000 Subject: [PATCH 2/3] Use instead of stdint-macros.h --- libc/src/__support/macros/properties/types.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libc/src/__support/macros/properties/types.h b/libc/src/__support/macros/properties/types.h index ba6ca1493c437..94b0829b6bdc2 100644 --- a/libc/src/__support/macros/properties/types.h +++ b/libc/src/__support/macros/properties/types.h @@ -10,14 +10,15 @@ #ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_TYPES_H #define LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_TYPES_H -#include "include/llvm-libc-macros/float-macros.h" // LDBL_MANT_DIG -#include "include/llvm-libc-macros/stdint-macros.h" // UINT64_MAX -#include "include/llvm-libc-types/float128.h" // float128 +#include "include/llvm-libc-macros/float-macros.h" // LDBL_MANT_DIG +#include "include/llvm-libc-types/float128.h" // float128 #include "src/__support/macros/properties/architectures.h" #include "src/__support/macros/properties/compiler.h" #include "src/__support/macros/properties/cpu_features.h" #include "src/__support/macros/properties/os.h" +#include // UINT64_MAX + // 'long double' properties. #if (LDBL_MANT_DIG == 53) #define LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64 From 84eccc3bc45c3d09d5e45af025db4944ea5c5e12 Mon Sep 17 00:00:00 2001 From: Guillaume Chatelet Date: Wed, 6 Mar 2024 10:39:01 +0000 Subject: [PATCH 3/3] remove the need for stdint_macros --- libc/src/__support/macros/properties/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/libc/src/__support/macros/properties/CMakeLists.txt b/libc/src/__support/macros/properties/CMakeLists.txt index 62436a8ebf2da..bbc45650f3fca 100644 --- a/libc/src/__support/macros/properties/CMakeLists.txt +++ b/libc/src/__support/macros/properties/CMakeLists.txt @@ -34,6 +34,5 @@ add_header_library( .cpu_features .os libc.include.llvm-libc-macros.float_macros - libc.include.llvm-libc-macros.stdint_macros libc.include.llvm-libc-types.float128 )