[NFC][libc] Move Uint implementation to parent directory

Differential Revision: https://reviews.llvm.org/D132638
This commit is contained in:
Guillaume Chatelet 2022-08-25 09:09:10 +00:00
parent 5def954a5b
commit 9d239b37f7
31 changed files with 101 additions and 111 deletions

View File

@ -55,14 +55,14 @@ add_header_library(
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 @@ add_header_library(
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)

View File

@ -4,22 +4,6 @@ add_header_library(
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 @@ add_header_library(
limits
HDRS
limits.h
DEPENDS
.uint
)
add_header_library(
@ -81,8 +63,6 @@ add_header_library(
type_traits
HDRS
type_traits.h
DEPENDS
.uint
)
add_header_library(

View File

@ -9,8 +9,6 @@
#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_LIMITS_H
#define LLVM_LIBC_SRC_SUPPORT_CPP_LIMITS_H
#include "UInt.h"
#include <limits.h>
namespace __llvm_libc {
@ -74,16 +72,6 @@ public:
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<UInt<128>> {
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.

View File

@ -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 @@ private:
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<char, unqualified_type> ||
is_same_v<signed char, unqualified_type> ||
is_same_v<unsigned char, unqualified_type> ||
@ -61,17 +63,7 @@ public:
is_same_v<unsigned long, unqualified_type> ||
is_same_v<long long, unqualified_type> ||
is_same_v<unsigned long long, unqualified_type> ||
is_same_v<bool, unqualified_type> ||
// 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<bool, unqualified_type>;
};
template <typename T>
inline constexpr bool is_integral_v = is_integral<T>::value;

View File

@ -15,13 +15,13 @@ add_header_library(
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 @@ add_header_library(
XFloat.h
DEPENDS
.fputil #FPBits and NormalFloat
libc.src.__support.CPP.uint
libc.src.__support.uint
)
add_header_library(

View File

@ -11,7 +11,7 @@
#include "PlatformDefs.h"
#include "src/__support/CPP/UInt128.h"
#include "src/__support/UInt128.h"
#include <stdint.h>

View File

@ -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 {

View File

@ -8,7 +8,7 @@
#include "FPBits.h"
#include "NormalFloat.h"
#include "src/__support/CPP/UInt.h"
#include "src/__support/UInt.h"
#include <stdint.h>

View File

@ -4,7 +4,7 @@ add_header_library(
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 @@ add_header_library(
HDRS
FMA.h
DEPENDS
libc.src.__support.CPP.uint128
libc.src.__support.uint128
)
add_header_library(

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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)

View File

@ -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 <stddef.h> // For size_t
#include <stdint.h>
namespace __llvm_libc {
namespace cpp {
namespace __llvm_libc::cpp {
template <size_t Bits> class UInt {
@ -446,7 +447,16 @@ constexpr UInt<128> UInt<128>::operator*(const UInt<128> &other) const {
return result;
}
} // namespace cpp
} // namespace __llvm_libc
// Provides limits of UInt<128>.
template <> class numeric_limits<UInt<128>> {
public:
static constexpr UInt<128> max() { return ~UInt<128>(0); }
static constexpr UInt<128> min() { return 0; }
};
#endif // LLVM_LIBC_UTILS_CPP_UINT_H
// Provides is_integral of UInt<128>.
template <> struct is_integral<UInt<128>> : public cpp::true_type {};
} // namespace __llvm_libc::cpp
#endif // LLVM_LIBC_UTILS_UINT_H

View File

@ -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 = __llvm_libc::cpp::UInt<128>;
using UInt128 = __uint128_t;
#endif
#endif // LLVM_LIBC_SRC_SUPPORT_CPP_UINT128_H
#endif // LLVM_LIBC_SRC_SUPPORT_UINT128_H

View File

@ -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 <stddef.h>
#include <stdint.h>
@ -203,4 +203,4 @@ using ReverseOrderBlockStore = BlockStore<T, BLOCK_SIZE, true>;
} // namespace cpp
} // namespace __llvm_libc
#endif // LLVM_LIBC_SUPPORT_CPP_BLOCKSTORE_H
#endif // LLVM_LIBC_SUPPORT_BLOCKSTORE_H

View File

@ -9,6 +9,8 @@
#ifndef LLVM_LIBC_SRC_SUPPORT_INTEGER_TO_STRING_H
#define LLVM_LIBC_SRC_SUPPORT_INTEGER_TO_STRING_H
#include <stdint.h>
#include "src/__support/CPP/string_view.h"
#include "src/__support/CPP/optional.h"
#include "src/__support/CPP/span.h"

View File

@ -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"

View File

@ -1135,7 +1135,7 @@ add_object_library(
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
)

View File

@ -31,7 +31,7 @@ add_subdirectory(ctype)
add_subdirectory(errno)
add_subdirectory(fenv)
add_subdirectory(inttypes)
add_subdirectory(math)
# add_subdirectory(math)
add_subdirectory(string)
add_subdirectory(stdlib)
add_subdirectory(stdio)

View File

@ -28,7 +28,7 @@ add_libc_unittest(
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 @@ add_libc_unittest(
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 @@ add_libc_unittest(
SRCS
uint128_test.cpp
DEPENDS
libc.src.__support.CPP.uint
libc.src.__support.uint
)
add_libc_unittest(

View File

@ -28,7 +28,7 @@ add_libc_unittest(
limits_test.cpp
DEPENDS
libc.src.__support.CPP.limits
libc.src.__support.CPP.uint
libc.src.__support.uint
)
add_libc_unittest(

View File

@ -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 {

View File

@ -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"

View File

@ -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"

View File

@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
#include "src/__support/CPP/UInt.h"
#include "src/__support/UInt.h"
#include "utils/UnitTest/Test.h"

View File

@ -77,7 +77,7 @@ add_libc_unittest(
SRCS
strtold_test.cpp
DEPENDS
libc.src.__support.CPP.uint128
libc.src.__support.uint128
libc.src.stdlib.strtold
)

View File

@ -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"

View File

@ -5,7 +5,7 @@ add_library(
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(

View File

@ -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 <cassert>
#include <iostream>

View File

@ -62,7 +62,7 @@ cc_library(
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 @@ cc_library(
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(
],
)
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 @@ cc_library(
":__support_common",
":__support_fputil",
":__support_fputil_polyeval",
":range_reduction",
":libc_root",
":range_reduction",
],
)