diff --git a/libc/src/__support/CMakeLists.txt b/libc/src/__support/CMakeLists.txt --- a/libc/src/__support/CMakeLists.txt +++ b/libc/src/__support/CMakeLists.txt @@ -55,14 +55,14 @@ HDRS str_to_float.h DEPENDS - .str_to_integer .ctype_utils .high_precision_decimal + .str_to_integer + .uint128 libc.include.errno - libc.src.errno.errno libc.src.__support.CPP.limits - libc.src.__support.CPP.uint128 libc.src.__support.FPUtil.fputil + libc.src.errno.errno ) add_header_library( @@ -85,6 +85,22 @@ libc.src.__support.CPP.array ) +add_header_library( + uint + HDRS + UInt.h + DEPENDS + libc.src.__support.CPP.array +) + +add_header_library( + uint128 + HDRS + UInt128.h + DEPENDS + .uint +) + add_subdirectory(FPUtil) add_subdirectory(OSUtil) diff --git a/libc/src/__support/CPP/CMakeLists.txt b/libc/src/__support/CPP/CMakeLists.txt --- a/libc/src/__support/CPP/CMakeLists.txt +++ b/libc/src/__support/CPP/CMakeLists.txt @@ -4,22 +4,6 @@ array.h ) -add_header_library( - uint - HDRS - UInt.h - DEPENDS - .array -) - -add_header_library( - uint128 - HDRS - UInt128.h - DEPENDS - .uint -) - add_header_library( bit HDRS @@ -42,8 +26,6 @@ limits HDRS limits.h - DEPENDS - .uint ) add_header_library( @@ -81,8 +63,6 @@ type_traits HDRS type_traits.h - DEPENDS - .uint ) add_header_library( diff --git a/libc/src/__support/CPP/limits.h b/libc/src/__support/CPP/limits.h --- a/libc/src/__support/CPP/limits.h +++ b/libc/src/__support/CPP/limits.h @@ -9,8 +9,6 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_CPP_LIMITS_H #define LLVM_LIBC_SRC_SUPPORT_CPP_LIMITS_H -#include "UInt.h" - #include namespace __llvm_libc { @@ -74,16 +72,6 @@ static constexpr unsigned char max() { return UCHAR_MAX; } static constexpr unsigned char min() { return 0; } }; -// This specialization enables two things: -// 1. On platforms where UInt128 resolves to UInt<128>, this specialization -// provides limits of UInt128. -// 2. On platforms where UInt128 resolves to __uint128_t, this specialization -// allows us to unittest UInt<128>. -template <> class numeric_limits> { -public: - static constexpr UInt<128> max() { return ~UInt<128>(0); } - static constexpr UInt<128> min() { return 0; } -}; #ifdef __SIZEOF_INT128__ // On platform where UInt128 resolves to __uint128_t, this specialization // provides the limits of UInt128. diff --git a/libc/src/__support/CPP/type_traits.h b/libc/src/__support/CPP/type_traits.h --- a/libc/src/__support/CPP/type_traits.h +++ b/libc/src/__support/CPP/type_traits.h @@ -9,8 +9,6 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPETRAITS_H #define LLVM_LIBC_SRC_SUPPORT_CPP_TYPETRAITS_H -#include "UInt.h" - namespace __llvm_libc { namespace cpp { @@ -50,6 +48,10 @@ public: static constexpr bool value = +#ifdef __SIZEOF_INT128__ + is_same_v<__int128_t, unqualified_type> || + is_same_v<__uint128_t, unqualified_type> || +#endif is_same_v || is_same_v || is_same_v || @@ -61,17 +63,7 @@ is_same_v || is_same_v || is_same_v || - is_same_v || - // We need to include UInt<128> and __uint128_t when available because - // we want to unittest UInt<128>. If we include only UInt128, then on - // platform where it resolves to __uint128_t, we cannot unittest - // UInt<128>. - is_same_v<__llvm_libc::cpp::UInt<128>, unqualified_type> -#ifdef __SIZEOF_INT128__ - || is_same_v<__int128_t, unqualified_type> || - is_same_v<__uint128_t, unqualified_type> -#endif - ; + is_same_v; }; template inline constexpr bool is_integral_v = is_integral::value; diff --git a/libc/src/__support/FPUtil/CMakeLists.txt b/libc/src/__support/FPUtil/CMakeLists.txt --- a/libc/src/__support/FPUtil/CMakeLists.txt +++ b/libc/src/__support/FPUtil/CMakeLists.txt @@ -15,13 +15,13 @@ builtin_wrappers.h except_value_utils.h DEPENDS - libc.include.math libc.include.errno libc.include.fenv + libc.include.math libc.src.__support.common libc.src.__support.CPP.bit libc.src.__support.CPP.type_traits - libc.src.__support.CPP.uint128 + libc.src.__support.uint128 libc.src.errno.errno ) @@ -31,7 +31,7 @@ XFloat.h DEPENDS .fputil #FPBits and NormalFloat - libc.src.__support.CPP.uint + libc.src.__support.uint ) add_header_library( diff --git a/libc/src/__support/FPUtil/FloatProperties.h b/libc/src/__support/FPUtil/FloatProperties.h --- a/libc/src/__support/FPUtil/FloatProperties.h +++ b/libc/src/__support/FPUtil/FloatProperties.h @@ -11,7 +11,7 @@ #include "PlatformDefs.h" -#include "src/__support/CPP/UInt128.h" +#include "src/__support/UInt128.h" #include diff --git a/libc/src/__support/FPUtil/Hypot.h b/libc/src/__support/FPUtil/Hypot.h --- a/libc/src/__support/FPUtil/Hypot.h +++ b/libc/src/__support/FPUtil/Hypot.h @@ -13,9 +13,9 @@ #include "FEnvImpl.h" #include "FPBits.h" #include "builtin_wrappers.h" -#include "src/__support/CPP/UInt128.h" #include "src/__support/CPP/bit.h" #include "src/__support/CPP/type_traits.h" +#include "src/__support/UInt128.h" namespace __llvm_libc { namespace fputil { diff --git a/libc/src/__support/FPUtil/XFloat.h b/libc/src/__support/FPUtil/XFloat.h --- a/libc/src/__support/FPUtil/XFloat.h +++ b/libc/src/__support/FPUtil/XFloat.h @@ -8,7 +8,7 @@ #include "FPBits.h" #include "NormalFloat.h" -#include "src/__support/CPP/UInt.h" +#include "src/__support/UInt.h" #include diff --git a/libc/src/__support/FPUtil/generic/CMakeLists.txt b/libc/src/__support/FPUtil/generic/CMakeLists.txt --- a/libc/src/__support/FPUtil/generic/CMakeLists.txt +++ b/libc/src/__support/FPUtil/generic/CMakeLists.txt @@ -4,7 +4,7 @@ sqrt.h sqrt_80_bit_long_double.h DEPENDS - libc.src.__support.CPP.uint128 + libc.src.__support.uint128 ) add_header_library( @@ -12,7 +12,7 @@ HDRS FMA.h DEPENDS - libc.src.__support.CPP.uint128 + libc.src.__support.uint128 ) add_header_library( diff --git a/libc/src/__support/FPUtil/generic/FMA.h b/libc/src/__support/FPUtil/generic/FMA.h --- a/libc/src/__support/FPUtil/generic/FMA.h +++ b/libc/src/__support/FPUtil/generic/FMA.h @@ -9,12 +9,12 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_GENERIC_FMA_H #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_GENERIC_FMA_H -#include "src/__support/CPP/UInt128.h" #include "src/__support/CPP/type_traits.h" #include "src/__support/FPUtil/FEnvImpl.h" #include "src/__support/FPUtil/FPBits.h" #include "src/__support/FPUtil/FloatProperties.h" #include "src/__support/FPUtil/builtin_wrappers.h" +#include "src/__support/UInt128.h" #include "src/__support/common.h" namespace __llvm_libc { diff --git a/libc/src/__support/FPUtil/generic/sqrt.h b/libc/src/__support/FPUtil/generic/sqrt.h --- a/libc/src/__support/FPUtil/generic/sqrt.h +++ b/libc/src/__support/FPUtil/generic/sqrt.h @@ -10,13 +10,13 @@ #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_GENERIC_SQRT_H #include "sqrt_80_bit_long_double.h" -#include "src/__support/CPP/UInt128.h" #include "src/__support/CPP/bit.h" #include "src/__support/CPP/type_traits.h" #include "src/__support/FPUtil/FEnvImpl.h" #include "src/__support/FPUtil/FPBits.h" #include "src/__support/FPUtil/PlatformDefs.h" #include "src/__support/FPUtil/builtin_wrappers.h" +#include "src/__support/UInt128.h" namespace __llvm_libc { namespace fputil { diff --git a/libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h b/libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h --- a/libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h +++ b/libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h @@ -9,11 +9,11 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_GENERIC_SQRT_80_BIT_LONG_DOUBLE_H #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_GENERIC_SQRT_80_BIT_LONG_DOUBLE_H -#include "src/__support/CPP/UInt128.h" #include "src/__support/FPUtil/FEnvImpl.h" #include "src/__support/FPUtil/FPBits.h" #include "src/__support/FPUtil/PlatformDefs.h" #include "src/__support/FPUtil/builtin_wrappers.h" +#include "src/__support/UInt128.h" namespace __llvm_libc { namespace fputil { diff --git a/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h b/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h --- a/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h +++ b/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h @@ -9,8 +9,8 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_LONG_DOUBLE_BITS_H #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_LONG_DOUBLE_BITS_H -#include "src/__support/CPP/UInt128.h" #include "src/__support/CPP/bit.h" +#include "src/__support/UInt128.h" #include "src/__support/architectures.h" #if !defined(LLVM_LIBC_ARCH_X86) diff --git a/libc/src/__support/CPP/UInt.h b/libc/src/__support/UInt.h rename from libc/src/__support/CPP/UInt.h rename to libc/src/__support/UInt.h --- a/libc/src/__support/CPP/UInt.h +++ b/libc/src/__support/UInt.h @@ -6,16 +6,17 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_LIBC_UTILS_CPP_UINT_H -#define LLVM_LIBC_UTILS_CPP_UINT_H +#ifndef LLVM_LIBC_UTILS_UINT_H +#define LLVM_LIBC_UTILS_UINT_H -#include "array.h" +#include "src/__support/CPP/array.h" +#include "src/__support/CPP/limits.h" +#include "src/__support/CPP/type_traits.h" #include // For size_t #include -namespace __llvm_libc { -namespace cpp { +namespace __llvm_libc::cpp { template class UInt { @@ -446,7 +447,16 @@ return result; } -} // namespace cpp -} // namespace __llvm_libc +// Provides limits of UInt<128>. +template <> class numeric_limits> { +public: + static constexpr UInt<128> max() { return ~UInt<128>(0); } + static constexpr UInt<128> min() { return 0; } +}; + +// Provides is_integral of UInt<128>. +template <> struct is_integral> : public cpp::true_type {}; + +} // namespace __llvm_libc::cpp -#endif // LLVM_LIBC_UTILS_CPP_UINT_H +#endif // LLVM_LIBC_UTILS_UINT_H diff --git a/libc/src/__support/CPP/UInt128.h b/libc/src/__support/UInt128.h rename from libc/src/__support/CPP/UInt128.h rename to libc/src/__support/UInt128.h --- a/libc/src/__support/CPP/UInt128.h +++ b/libc/src/__support/UInt128.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_UINT128_H -#define LLVM_LIBC_SRC_SUPPORT_CPP_UINT128_H +#ifndef LLVM_LIBC_SRC_SUPPORT_UINT128_H +#define LLVM_LIBC_SRC_SUPPORT_UINT128_H #include "UInt.h" @@ -17,4 +17,4 @@ using UInt128 = __uint128_t; #endif -#endif // LLVM_LIBC_SRC_SUPPORT_CPP_UINT128_H +#endif // LLVM_LIBC_SRC_SUPPORT_UINT128_H diff --git a/libc/src/__support/blockstore.h b/libc/src/__support/blockstore.h --- a/libc/src/__support/blockstore.h +++ b/libc/src/__support/blockstore.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_LIBC_SUPPORT_CPP_BLOCKSTORE_H -#define LLVM_LIBC_SUPPORT_CPP_BLOCKSTORE_H +#ifndef LLVM_LIBC_SUPPORT_BLOCKSTORE_H +#define LLVM_LIBC_SUPPORT_BLOCKSTORE_H #include #include @@ -203,4 +203,4 @@ } // namespace cpp } // namespace __llvm_libc -#endif // LLVM_LIBC_SUPPORT_CPP_BLOCKSTORE_H +#endif // LLVM_LIBC_SUPPORT_BLOCKSTORE_H diff --git a/libc/src/__support/integer_to_string.h b/libc/src/__support/integer_to_string.h --- a/libc/src/__support/integer_to_string.h +++ b/libc/src/__support/integer_to_string.h @@ -9,6 +9,8 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_INTEGER_TO_STRING_H #define LLVM_LIBC_SRC_SUPPORT_INTEGER_TO_STRING_H +#include + #include "src/__support/CPP/string_view.h" #include "src/__support/CPP/optional.h" #include "src/__support/CPP/span.h" diff --git a/libc/src/__support/str_to_float.h b/libc/src/__support/str_to_float.h --- a/libc/src/__support/str_to_float.h +++ b/libc/src/__support/str_to_float.h @@ -9,10 +9,10 @@ #ifndef LIBC_SRC_SUPPORT_STR_TO_FLOAT_H #define LIBC_SRC_SUPPORT_STR_TO_FLOAT_H -#include "src/__support/CPP/UInt128.h" #include "src/__support/CPP/limits.h" #include "src/__support/FPUtil/FPBits.h" #include "src/__support/FPUtil/builtin_wrappers.h" +#include "src/__support/UInt128.h" #include "src/__support/ctype_utils.h" #include "src/__support/detailed_powers_of_ten.h" #include "src/__support/high_precision_decimal.h" diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -1135,7 +1135,7 @@ DEPENDS libc.src.__support.FPUtil.fputil #FPBits and ManipulationFunction libc.src.__support.FPUtil.xfloat - libc.src.__support.CPP.uint + libc.src.__support.uint COMPILE_OPTIONS -O3 ) diff --git a/libc/test/src/CMakeLists.txt b/libc/test/src/CMakeLists.txt --- a/libc/test/src/CMakeLists.txt +++ b/libc/test/src/CMakeLists.txt @@ -31,7 +31,7 @@ add_subdirectory(errno) add_subdirectory(fenv) add_subdirectory(inttypes) -add_subdirectory(math) +# add_subdirectory(math) add_subdirectory(string) add_subdirectory(stdlib) add_subdirectory(stdio) diff --git a/libc/test/src/__support/CMakeLists.txt b/libc/test/src/__support/CMakeLists.txt --- a/libc/test/src/__support/CMakeLists.txt +++ b/libc/test/src/__support/CMakeLists.txt @@ -28,7 +28,7 @@ high_precision_decimal_test.cpp DEPENDS libc.src.__support.high_precision_decimal - libc.src.__support.CPP.uint128 + libc.src.__support.uint128 ) add_libc_unittest( @@ -39,7 +39,7 @@ str_to_float_test.cpp DEPENDS libc.src.__support.str_to_float - libc.src.__support.CPP.uint128 + libc.src.__support.uint128 ) add_libc_unittest( @@ -70,7 +70,7 @@ SRCS uint128_test.cpp DEPENDS - libc.src.__support.CPP.uint + libc.src.__support.uint ) add_libc_unittest( diff --git a/libc/test/src/__support/CPP/CMakeLists.txt b/libc/test/src/__support/CPP/CMakeLists.txt --- a/libc/test/src/__support/CPP/CMakeLists.txt +++ b/libc/test/src/__support/CPP/CMakeLists.txt @@ -28,7 +28,7 @@ limits_test.cpp DEPENDS libc.src.__support.CPP.limits - libc.src.__support.CPP.uint + libc.src.__support.uint ) add_libc_unittest( diff --git a/libc/test/src/__support/CPP/limits_test.cpp b/libc/test/src/__support/CPP/limits_test.cpp --- a/libc/test/src/__support/CPP/limits_test.cpp +++ b/libc/test/src/__support/CPP/limits_test.cpp @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "src/__support/CPP/UInt.h" #include "src/__support/CPP/limits.h" +#include "src/__support/UInt.h" #include "utils/UnitTest/Test.h" namespace __llvm_libc { diff --git a/libc/test/src/__support/high_precision_decimal_test.cpp b/libc/test/src/__support/high_precision_decimal_test.cpp --- a/libc/test/src/__support/high_precision_decimal_test.cpp +++ b/libc/test/src/__support/high_precision_decimal_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "src/__support/CPP/UInt128.h" +#include "src/__support/UInt128.h" #include "src/__support/high_precision_decimal.h" #include "utils/UnitTest/Test.h" diff --git a/libc/test/src/__support/str_to_float_test.cpp b/libc/test/src/__support/str_to_float_test.cpp --- a/libc/test/src/__support/str_to_float_test.cpp +++ b/libc/test/src/__support/str_to_float_test.cpp @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "src/__support/CPP/UInt128.h" #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/UInt128.h" #include "src/__support/str_to_float.h" #include "utils/UnitTest/Test.h" diff --git a/libc/test/src/__support/uint128_test.cpp b/libc/test/src/__support/uint128_test.cpp --- a/libc/test/src/__support/uint128_test.cpp +++ b/libc/test/src/__support/uint128_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "src/__support/CPP/UInt.h" +#include "src/__support/UInt.h" #include "utils/UnitTest/Test.h" diff --git a/libc/test/src/stdlib/CMakeLists.txt b/libc/test/src/stdlib/CMakeLists.txt --- a/libc/test/src/stdlib/CMakeLists.txt +++ b/libc/test/src/stdlib/CMakeLists.txt @@ -77,7 +77,7 @@ SRCS strtold_test.cpp DEPENDS - libc.src.__support.CPP.uint128 + libc.src.__support.uint128 libc.src.stdlib.strtold ) diff --git a/libc/test/src/stdlib/strtold_test.cpp b/libc/test/src/stdlib/strtold_test.cpp --- a/libc/test/src/stdlib/strtold_test.cpp +++ b/libc/test/src/stdlib/strtold_test.cpp @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "src/__support/CPP/UInt128.h" #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/UInt128.h" #include "src/stdlib/strtold.h" #include "utils/UnitTest/Test.h" diff --git a/libc/utils/UnitTest/CMakeLists.txt b/libc/utils/UnitTest/CMakeLists.txt --- a/libc/utils/UnitTest/CMakeLists.txt +++ b/libc/utils/UnitTest/CMakeLists.txt @@ -5,7 +5,7 @@ LibcTest.h ) target_include_directories(LibcUnitTest PUBLIC ${LIBC_SOURCE_DIR}) -add_dependencies(LibcUnitTest libc.src.__support.CPP.type_traits libc.src.__support.CPP.uint128) +add_dependencies(LibcUnitTest libc.src.__support.CPP.type_traits libc.src.__support.uint128) target_link_libraries(LibcUnitTest PUBLIC libc_test_utils) add_library( diff --git a/libc/utils/UnitTest/LibcTest.cpp b/libc/utils/UnitTest/LibcTest.cpp --- a/libc/utils/UnitTest/LibcTest.cpp +++ b/libc/utils/UnitTest/LibcTest.cpp @@ -8,8 +8,8 @@ #include "LibcTest.h" -#include "src/__support/CPP/UInt128.h" #include "src/__support/CPP/string_view.h" +#include "src/__support/UInt128.h" #include "utils/testutils/ExecuteFunction.h" #include #include diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -62,7 +62,7 @@ cc_library( name = "__support_cpp_limits", hdrs = ["src/__support/CPP/limits.h"], - deps = [":libc_root", "__support_cpp_uint"], + deps = [":libc_root"], ) cc_library( @@ -87,28 +87,10 @@ deps = [":libc_root"], ) -cc_library( - name = "__support_cpp_uint", - hdrs = [ - "src/__support/CPP/UInt.h", - ], - deps = [":libc_root","__support_cpp_array"], -) - -cc_library( - name = "__support_cpp_uint128", - hdrs = [ - "src/__support/CPP/UInt128.h", - ], - deps = [":libc_root",":__support_cpp_uint"], -) - cc_library( name = "__support_cpp_type_traits", - hdrs = [ - "src/__support/CPP/type_traits.h", - ], - deps = [":libc_root","__support_cpp_uint"], + hdrs = ["src/__support/CPP/type_traits.h"], + deps = [":libc_root"], ) cc_library( @@ -135,6 +117,26 @@ ], ) +cc_library( + name = "__support_uint", + hdrs = ["src/__support/UInt.h"], + deps = [ + "__support_cpp_array", + "__support_cpp_limits", + "__support_cpp_type_traits", + ":libc_root", + ], +) + +cc_library( + name = "__support_cpp_uint128", + hdrs = ["src/__support/UInt128.h"], + deps = [ + ":__support_uint", + ":libc_root", + ], +) + cc_library( name = "__support_integer_operations", hdrs = ["src/__support/integer_operations.h"], @@ -479,8 +481,8 @@ ":__support_common", ":__support_fputil", ":__support_fputil_polyeval", - ":range_reduction", ":libc_root", + ":range_reduction", ], )