[libc][NFC] Use STL case for type_traits

Migrating all private STL code to the standard STL case but keeping it under the CPP namespace to avoid confusion. Starting with the type_traits header.

Differential Revision: https://reviews.llvm.org/D130727
This commit is contained in:
Guillaume Chatelet 2022-07-28 19:39:19 +00:00
parent d03110155b
commit f72261508a
45 changed files with 345 additions and 358 deletions

View File

@ -9,12 +9,11 @@
#ifndef LLVM_LIBC_FUZZING_MATH_COMPARE_H
#define LLVM_LIBC_FUZZING_MATH_COMPARE_H
#include "src/__support/CPP/TypeTraits.h"
#include "src/__support/CPP/type_traits.h"
#include "src/__support/FPUtil/FPBits.h"
template <typename T>
__llvm_libc::cpp::EnableIfType<__llvm_libc::cpp::IsFloatingPointType<T>::Value,
bool>
__llvm_libc::cpp::enable_if_t<__llvm_libc::cpp::is_floating_point_v<T>, bool>
ValuesEqual(T x1, T x2) {
__llvm_libc::fputil::FPBits<T> bits1(x1);
__llvm_libc::fputil::FPBits<T> bits2(x2);
@ -27,7 +26,7 @@ ValuesEqual(T x1, T x2) {
}
template <typename T>
__llvm_libc::cpp::EnableIfType<__llvm_libc::cpp::IsIntegral<T>::Value, bool>
__llvm_libc::cpp::enable_if_t<__llvm_libc::cpp::is_integral_v<T>, bool>
ValuesEqual(T x1, T x2) {
return x1 == x1;
}

View File

@ -10,7 +10,7 @@
#define LLVM_LIBC_SRC_SUPPORT_CPP_ARRAYREF_H
#include "Array.h"
#include "TypeTraits.h" //RemoveCVType
#include "type_traits.h" // RemoveCVType
#include <stddef.h> // For size_t.
@ -24,7 +24,7 @@ namespace cpp {
namespace internal {
template <typename QualifiedT> class ArrayRefBase {
public:
using value_type = RemoveCVType<QualifiedT>;
using value_type = remove_cv_t<QualifiedT>;
using pointer = value_type *;
using const_pointer = const value_type *;
using reference = value_type &;
@ -109,7 +109,7 @@ private:
template <typename T> struct ArrayRef : public internal::ArrayRefBase<const T> {
private:
static_assert(IsSameV<T, RemoveCVType<T>>,
static_assert(is_same_v<T, remove_cv_t<T>>,
"ArrayRef must have a non-const, non-volatile value_type");
using Impl = internal::ArrayRefBase<const T>;
using Impl::Impl;
@ -128,7 +128,7 @@ template <typename T>
struct MutableArrayRef : public internal::ArrayRefBase<T> {
private:
static_assert(
IsSameV<T, RemoveCVType<T>>,
is_same_v<T, remove_cv_t<T>>,
"MutableArrayRef must have a non-const, non-volatile value_type");
using Impl = internal::ArrayRefBase<T>;
using Impl::Impl;

View File

@ -71,7 +71,7 @@ add_header_library(
add_header_library(
type_traits
HDRS
TypeTraits.h
type_traits.h
DEPENDS
.uint
)

View File

@ -1,157 +0,0 @@
//===-- Self contained C++ type traits --------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPETRAITS_H
#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPETRAITS_H
#include "UInt.h"
namespace __llvm_libc {
namespace cpp {
template <bool B, typename T> struct EnableIf;
template <typename T> struct EnableIf<true, T> {
typedef T Type;
};
template <bool B, typename T>
using EnableIfType = typename EnableIf<B, T>::Type;
struct TrueValue {
static constexpr bool Value = true;
};
struct FalseValue {
static constexpr bool Value = false;
};
template <typename T> struct TypeIdentity {
typedef T Type;
};
template <typename T1, typename T2> struct IsSame : public FalseValue {};
template <typename T> struct IsSame<T, T> : public TrueValue {};
template <typename T1, typename T2>
static constexpr bool IsSameV = IsSame<T1, T2>::Value;
template <typename T> struct RemoveCV : public TypeIdentity<T> {};
template <typename T> struct RemoveCV<const T> : public TypeIdentity<T> {};
template <typename T> struct RemoveCV<volatile T> : public TypeIdentity<T> {};
template <typename T>
struct RemoveCV<const volatile T> : public TypeIdentity<T> {};
template <typename T> using RemoveCVType = typename RemoveCV<T>::Type;
template <typename Type> struct IsIntegral {
using TypeNoCV = RemoveCVType<Type>;
static constexpr bool Value =
IsSameV<char, TypeNoCV> || IsSameV<signed char, TypeNoCV> ||
IsSameV<unsigned char, TypeNoCV> || IsSameV<short, TypeNoCV> ||
IsSameV<unsigned short, TypeNoCV> || IsSameV<int, TypeNoCV> ||
IsSameV<unsigned int, TypeNoCV> || IsSameV<long, TypeNoCV> ||
IsSameV<unsigned long, TypeNoCV> || IsSameV<long long, TypeNoCV> ||
IsSameV<unsigned long long, TypeNoCV> || IsSameV<bool, TypeNoCV> ||
// 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>.
IsSameV<__llvm_libc::cpp::UInt<128>, TypeNoCV>
#ifdef __SIZEOF_INT128__
|| IsSameV<__int128_t, TypeNoCV> || IsSameV<__uint128_t, TypeNoCV>
#endif
;
};
template <typename Type> struct IsEnum {
static constexpr bool Value = __is_enum(Type);
};
template <typename T> struct IsPointerTypeNoCV : public FalseValue {};
template <typename T> struct IsPointerTypeNoCV<T *> : public TrueValue {};
template <typename T> struct IsPointerType {
static constexpr bool Value = IsPointerTypeNoCV<RemoveCVType<T>>::Value;
};
template <typename Type> struct IsFloatingPointType {
using TypeNoCV = RemoveCVType<Type>;
static constexpr bool Value = IsSame<float, TypeNoCV>::Value ||
IsSame<double, TypeNoCV>::Value ||
IsSame<long double, TypeNoCV>::Value;
};
template <typename Type> struct IsArithmetic {
static constexpr bool Value =
IsIntegral<Type>::Value || IsFloatingPointType<Type>::Value;
};
template <typename Type> struct IsSigned {
static constexpr bool Value =
IsArithmetic<Type>::Value && (Type(-1) < Type(0));
constexpr operator bool() const { return Value; }
constexpr bool operator()() const { return Value; }
};
template <typename Type> struct MakeUnsigned;
template <> struct MakeUnsigned<char> {
using Type = unsigned char;
};
template <> struct MakeUnsigned<signed char> {
using Type = unsigned char;
};
template <> struct MakeUnsigned<short> {
using Type = unsigned short;
};
template <> struct MakeUnsigned<int> {
using Type = unsigned int;
};
template <> struct MakeUnsigned<long> {
using Type = unsigned long;
};
template <> struct MakeUnsigned<long long> {
using Type = unsigned long long;
};
template <> struct MakeUnsigned<unsigned char> {
using Type = unsigned char;
};
template <> struct MakeUnsigned<unsigned short> {
using Type = unsigned short;
};
template <> struct MakeUnsigned<unsigned int> {
using Type = unsigned int;
};
template <> struct MakeUnsigned<unsigned long> {
using Type = unsigned long;
};
template <> struct MakeUnsigned<unsigned long long> {
using Type = unsigned long long;
};
#ifdef __SIZEOF_INT128__
template <> struct MakeUnsigned<__int128_t> {
using Type = __uint128_t;
};
template <> struct MakeUnsigned<__uint128_t> {
using Type = __uint128_t;
};
#endif
template <typename T> using MakeUnsignedType = typename MakeUnsigned<T>::Type;
// Compile time type selection.
template <bool _, class TrueT, class FalseT> struct Conditional {
using type = TrueT;
};
template <class TrueT, class FalseT> struct Conditional<false, TrueT, FalseT> {
using type = FalseT;
};
template <bool Cond, typename TrueT, typename FalseT>
using ConditionalType = typename Conditional<Cond, TrueT, FalseT>::type;
} // namespace cpp
} // namespace __llvm_libc
#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPETRAITS_H

View File

@ -9,12 +9,12 @@
#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_UTILITY_H
#define LLVM_LIBC_SRC_SUPPORT_CPP_UTILITY_H
#include "src/__support/CPP/TypeTraits.h"
#include "src/__support/CPP/type_traits.h"
namespace __llvm_libc::cpp {
template <typename T, T... Seq> struct IntegerSequence {
static_assert(IsIntegral<T>::Value);
static_assert(is_integral_v<T>);
template <T Next> using append = IntegerSequence<T, Seq..., Next>;
};

View File

@ -9,7 +9,7 @@
#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_ATOMIC_H
#define LLVM_LIBC_SRC_SUPPORT_CPP_ATOMIC_H
#include "TypeTraits.h"
#include "type_traits.h"
namespace __llvm_libc {
namespace cpp {
@ -25,7 +25,7 @@ enum class MemoryOrder : int {
template <typename T> struct Atomic {
// For now, we will restrict to only arithmetic types.
static_assert(IsArithmetic<T>::Value, "Only arithmetic types can be atomic.");
static_assert(is_arithmetic_v<T>, "Only arithmetic types can be atomic.");
private:
// The value stored should be appropriately aligned so that

View File

@ -11,7 +11,7 @@
#include "ArrayRef.h"
#include "StringView.h"
#include "TypeTraits.h"
#include "type_traits.h"
#include "src/__support/integer_to_string.h"
@ -56,17 +56,17 @@ public:
}
// Write the |val| as string.
template <typename T, EnableIfType<IsIntegral<T>::Value, int> = 0>
template <typename T, enable_if_t<is_integral_v<T>, int> = 0>
StringStream &operator<<(T val) {
const auto int_to_str = integer_to_string(val);
return operator<<(int_to_str.str());
}
template <typename T, EnableIfType<IsFloatingPointType<T>::Value, int> = 0>
template <typename T, enable_if_t<is_floating_point_v<T>, int> = 0>
StringStream &operator<<(T val) {
// If this specialization gets activated, then the static_assert will
// trigger a compile error about missing floating point number support.
static_assert(!IsFloatingPointType<T>::Value,
static_assert(!is_floating_point_v<T>,
"Writing floating point numbers is not yet supported");
return *this;
}

View File

@ -0,0 +1,173 @@
//===-- Self contained C++ type traits --------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPETRAITS_H
#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPETRAITS_H
#include "UInt.h"
namespace __llvm_libc {
namespace cpp {
template <bool B, typename T> struct enable_if;
template <typename T> struct enable_if<true, T> {
using type = T;
};
template <bool B, typename T = void>
using enable_if_t = typename enable_if<B, T>::type;
template <typename T, T v> struct integral_constant {
using value_type = T;
static constexpr T value = v;
};
using true_type = cpp::integral_constant<bool, true>;
using false_type = cpp::integral_constant<bool, false>;
template <typename T> struct type_identity {
using type = T;
};
template <typename T, typename U> struct is_same : cpp::false_type {};
template <typename T> struct is_same<T, T> : cpp::true_type {};
template <typename T, typename U>
inline constexpr bool is_same_v = is_same<T, U>::value;
template <typename T> struct remove_cv : public type_identity<T> {};
template <typename T> struct remove_cv<const T> : public type_identity<T> {};
template <typename T> struct remove_cv<volatile T> : public type_identity<T> {};
template <typename T>
struct remove_cv<const volatile T> : public type_identity<T> {};
template <typename T> using remove_cv_t = typename remove_cv<T>::type;
template <typename T> struct is_integral {
private:
using unqualified_type = remove_cv_t<T>;
public:
static constexpr bool value =
is_same_v<char, unqualified_type> ||
is_same_v<signed char, unqualified_type> ||
is_same_v<unsigned char, unqualified_type> ||
is_same_v<short, unqualified_type> ||
is_same_v<unsigned short, unqualified_type> ||
is_same_v<int, unqualified_type> ||
is_same_v<unsigned int, unqualified_type> ||
is_same_v<long, unqualified_type> ||
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
;
};
template <typename T>
inline constexpr bool is_integral_v = is_integral<T>::value;
template <typename T> struct is_enum {
static constexpr bool value = __is_enum(T);
};
template <typename T> struct is_pointer : cpp::false_type {};
template <typename T> struct is_pointer<T *> : cpp::true_type {};
template <typename T> struct is_pointer<T *const> : cpp::true_type {};
template <typename T> struct is_pointer<T *volatile> : cpp::true_type {};
template <typename T> struct is_pointer<T *const volatile> : cpp::true_type {};
template <typename T> inline constexpr bool is_pointer_v = is_pointer<T>::value;
template <typename T> struct is_floating_point {
private:
using unqualified_type = remove_cv_t<T>;
public:
static constexpr bool value = is_same_v<float, unqualified_type> ||
is_same_v<double, unqualified_type> ||
is_same_v<long double, unqualified_type>;
};
template <typename T>
inline constexpr bool is_floating_point_v = is_floating_point<T>::value;
template <typename T> struct is_arithmetic {
static constexpr bool value =
is_integral<T>::value || is_floating_point<T>::value;
};
template <typename T>
inline constexpr bool is_arithmetic_v = is_arithmetic<T>::value;
template <typename T> struct is_signed {
static constexpr bool value = is_arithmetic<T>::value && (T(-1) < T(0));
constexpr operator bool() const { return value; }
constexpr bool operator()() const { return value; }
};
template <typename T> inline constexpr bool is_signed_v = is_signed<T>::value;
template <typename T> struct make_unsigned;
template <> struct make_unsigned<char> {
using type = unsigned char;
};
template <> struct make_unsigned<signed char> {
using type = unsigned char;
};
template <> struct make_unsigned<short> {
using type = unsigned short;
};
template <> struct make_unsigned<int> {
using type = unsigned int;
};
template <> struct make_unsigned<long> {
using type = unsigned long;
};
template <> struct make_unsigned<long long> {
using type = unsigned long long;
};
template <> struct make_unsigned<unsigned char> {
using type = unsigned char;
};
template <> struct make_unsigned<unsigned short> {
using type = unsigned short;
};
template <> struct make_unsigned<unsigned int> {
using type = unsigned int;
};
template <> struct make_unsigned<unsigned long> {
using type = unsigned long;
};
template <> struct make_unsigned<unsigned long long> {
using type = unsigned long long;
};
#ifdef __SIZEOF_INT128__
template <> struct make_unsigned<__int128_t> {
using type = __uint128_t;
};
template <> struct make_unsigned<__uint128_t> {
using type = __uint128_t;
};
#endif
template <typename T> using make_unsigned_t = typename make_unsigned<T>::type;
// Compile time type selection.
template <bool B, typename T, typename F> struct conditional {
using type = T;
};
template <typename T, typename F> struct conditional<false, T, F> {
using type = F;
};
template <bool B, typename T, typename F>
using conditional_t = typename conditional<B, T, F>::type;
} // namespace cpp
} // namespace __llvm_libc
#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPETRAITS_H

View File

@ -11,21 +11,19 @@
#include "FPBits.h"
#include "src/__support/CPP/TypeTraits.h"
#include "src/__support/CPP/type_traits.h"
namespace __llvm_libc {
namespace fputil {
template <typename T,
cpp::EnableIfType<cpp::IsFloatingPointType<T>::Value, int> = 0>
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
static inline T abs(T x) {
FPBits<T> bits(x);
bits.set_sign(0);
return T(bits);
}
template <typename T,
cpp::EnableIfType<cpp::IsFloatingPointType<T>::Value, int> = 0>
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
static inline T fmin(T x, T y) {
FPBits<T> bitx(x), bity(y);
@ -43,8 +41,7 @@ static inline T fmin(T x, T y) {
}
}
template <typename T,
cpp::EnableIfType<cpp::IsFloatingPointType<T>::Value, int> = 0>
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
static inline T fmax(T x, T y) {
FPBits<T> bitx(x), bity(y);
@ -62,8 +59,7 @@ static inline T fmax(T x, T y) {
}
}
template <typename T,
cpp::EnableIfType<cpp::IsFloatingPointType<T>::Value, int> = 0>
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
static inline T fdim(T x, T y) {
FPBits<T> bitx(x), bity(y);

View File

@ -13,7 +13,7 @@
#include "ManipulationFunctions.h"
#include "NormalFloat.h"
#include "src/__support/CPP/TypeTraits.h"
#include "src/__support/CPP/type_traits.h"
namespace __llvm_libc {
namespace fputil {
@ -22,8 +22,7 @@ static constexpr int QUOTIENT_LSB_BITS = 3;
// The implementation is a bit-by-bit algorithm which uses integer division
// to evaluate the quotient and remainder.
template <typename T,
cpp::EnableIfType<cpp::IsFloatingPointType<T>::Value, int> = 0>
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
static inline T remquo(T x, T y, int &q) {
FPBits<T> xbits(x), ybits(y);
if (xbits.is_nan())

View File

@ -22,7 +22,7 @@
#else
// FMA instructions are not available
#include "generic/FMA.h"
#include "src/__support/CPP/TypeTraits.h"
#include "src/__support/CPP/type_traits.h"
namespace __llvm_libc {
namespace fputil {

View File

@ -12,7 +12,7 @@
#include "PlatformDefs.h"
#include "src/__support/CPP/Bit.h"
#include "src/__support/CPP/TypeTraits.h"
#include "src/__support/CPP/type_traits.h"
#include "src/__support/FPUtil/builtin_wrappers.h"
#include "src/__support/common.h"
@ -39,7 +39,7 @@ template <typename T> struct ExponentWidth {
// an x87 floating point format. This format is an IEEE 754 extension format.
// It is handled as an explicit specialization of this class.
template <typename T> struct FPBits {
static_assert(cpp::IsFloatingPointType<T>::Value,
static_assert(cpp::is_floating_point_v<T>,
"FPBits instantiated with invalid type.");
// Reinterpreting bits as an integer value and interpreting the bits of an
@ -103,13 +103,12 @@ template <typename T> struct FPBits {
// We don't want accidental type promotions/conversions, so we require exact
// type match.
template <typename XType,
cpp::EnableIfType<cpp::IsSame<T, XType>::Value, int> = 0>
template <typename XType, cpp::enable_if_t<cpp::is_same_v<T, XType>, int> = 0>
constexpr explicit FPBits(XType x)
: bits(__llvm_libc::bit_cast<UIntType>(x)) {}
template <typename XType,
cpp::EnableIfType<cpp::IsSame<XType, UIntType>::Value, int> = 0>
cpp::enable_if_t<cpp::is_same_v<XType, UIntType>, int> = 0>
constexpr explicit FPBits(XType x) : bits(x) {}
FPBits() : bits(0) {}

View File

@ -14,8 +14,8 @@
#include "FPBits.h"
#include "builtin_wrappers.h"
#include "src/__support/CPP/Bit.h"
#include "src/__support/CPP/TypeTraits.h"
#include "src/__support/CPP/UInt128.h"
#include "src/__support/CPP/type_traits.h"
namespace __llvm_libc {
namespace fputil {
@ -97,8 +97,7 @@ template <> struct DoubleLength<uint64_t> {
// - HYPOT(x, y) is +Inf if x or y is +Inf or -Inf; else
// - HYPOT(x, y) is NaN if x or y is NaN.
//
template <typename T,
cpp::EnableIfType<cpp::IsFloatingPointType<T>::Value, int> = 0>
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
static inline T hypot(T x, T y) {
using FPBits_t = FPBits<T>;
using UIntType = typename FPBits<T>::UIntType;

View File

@ -15,7 +15,7 @@
#include "PlatformDefs.h"
#include "src/__support/CPP/Bit.h"
#include "src/__support/CPP/TypeTraits.h"
#include "src/__support/CPP/type_traits.h"
#include <limits.h>
#include <math.h>
@ -23,8 +23,7 @@
namespace __llvm_libc {
namespace fputil {
template <typename T,
cpp::EnableIfType<cpp::IsFloatingPointType<T>::Value, int> = 0>
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
static inline T frexp(T x, int &exp) {
FPBits<T> bits(x);
if (bits.is_inf_or_nan())
@ -40,8 +39,7 @@ static inline T frexp(T x, int &exp) {
return normal;
}
template <typename T,
cpp::EnableIfType<cpp::IsFloatingPointType<T>::Value, int> = 0>
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
static inline T modf(T x, T &iptr) {
FPBits<T> bits(x);
if (bits.is_zero() || bits.is_nan()) {
@ -62,16 +60,14 @@ static inline T modf(T x, T &iptr) {
}
}
template <typename T,
cpp::EnableIfType<cpp::IsFloatingPointType<T>::Value, int> = 0>
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
static inline T copysign(T x, T y) {
FPBits<T> xbits(x);
xbits.set_sign(FPBits<T>(y).get_sign());
return T(xbits);
}
template <typename T,
cpp::EnableIfType<cpp::IsFloatingPointType<T>::Value, int> = 0>
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
static inline int ilogb(T x) {
// TODO: Raise appropriate floating point exceptions and set errno to the
// an appropriate error value wherever relevant.
@ -99,8 +95,7 @@ static inline int ilogb(T x) {
return normal.exponent;
}
template <typename T,
cpp::EnableIfType<cpp::IsFloatingPointType<T>::Value, int> = 0>
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
static inline T logb(T x) {
FPBits<T> bits(x);
if (bits.is_zero()) {
@ -118,8 +113,7 @@ static inline T logb(T x) {
return normal.exponent;
}
template <typename T,
cpp::EnableIfType<cpp::IsFloatingPointType<T>::Value, int> = 0>
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
static inline T ldexp(T x, int exp) {
FPBits<T> bits(x);
if (bits.is_zero() || bits.is_inf_or_nan() || exp == 0)
@ -145,8 +139,7 @@ static inline T ldexp(T x, int exp) {
return normal;
}
template <typename T,
cpp::EnableIfType<cpp::IsFloatingPointType<T>::Value, int> = 0>
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
static inline T nextafter(T from, T to) {
FPBits<T> from_bits(from);
if (from_bits.is_nan())

View File

@ -12,7 +12,7 @@
#include "FEnvImpl.h"
#include "FPBits.h"
#include "src/__support/CPP/TypeTraits.h"
#include "src/__support/CPP/type_traits.h"
#include <errno.h>
#include <math.h>
@ -20,8 +20,7 @@
namespace __llvm_libc {
namespace fputil {
template <typename T,
cpp::EnableIfType<cpp::IsFloatingPointType<T>::Value, int> = 0>
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
static inline T trunc(T x) {
FPBits<T> bits(x);
@ -52,8 +51,7 @@ static inline T trunc(T x) {
return T(bits);
}
template <typename T,
cpp::EnableIfType<cpp::IsFloatingPointType<T>::Value, int> = 0>
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
static inline T ceil(T x) {
FPBits<T> bits(x);
@ -91,8 +89,7 @@ static inline T ceil(T x) {
return trunc_value + T(1.0);
}
template <typename T,
cpp::EnableIfType<cpp::IsFloatingPointType<T>::Value, int> = 0>
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
static inline T floor(T x) {
FPBits<T> bits(x);
if (bits.get_sign()) {
@ -102,8 +99,7 @@ static inline T floor(T x) {
}
}
template <typename T,
cpp::EnableIfType<cpp::IsFloatingPointType<T>::Value, int> = 0>
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
static inline T round(T x) {
using UIntType = typename FPBits<T>::UIntType;
FPBits<T> bits(x);
@ -154,8 +150,7 @@ static inline T round(T x) {
}
}
template <typename T,
cpp::EnableIfType<cpp::IsFloatingPointType<T>::Value, int> = 0>
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
static inline T round_using_current_rounding_mode(T x) {
using UIntType = typename FPBits<T>::UIntType;
FPBits<T> bits(x);
@ -235,9 +230,8 @@ static inline T round_using_current_rounding_mode(T x) {
namespace internal {
template <typename F, typename I,
cpp::EnableIfType<cpp::IsFloatingPointType<F>::Value &&
cpp::IsIntegral<I>::Value,
int> = 0>
cpp::enable_if_t<cpp::is_floating_point_v<F> && cpp::is_integral_v<I>,
int> = 0>
static inline I rounded_float_to_signed_integer(F x) {
constexpr I INTEGER_MIN = (I(1) << (sizeof(I) * 8 - 1));
constexpr I INTEGER_MAX = -(INTEGER_MIN + 1);
@ -277,17 +271,15 @@ static inline I rounded_float_to_signed_integer(F x) {
} // namespace internal
template <typename F, typename I,
cpp::EnableIfType<cpp::IsFloatingPointType<F>::Value &&
cpp::IsIntegral<I>::Value,
int> = 0>
cpp::enable_if_t<cpp::is_floating_point_v<F> && cpp::is_integral_v<I>,
int> = 0>
static inline I round_to_signed_integer(F x) {
return internal::rounded_float_to_signed_integer<F, I>(round(x));
}
template <typename F, typename I,
cpp::EnableIfType<cpp::IsFloatingPointType<F>::Value &&
cpp::IsIntegral<I>::Value,
int> = 0>
cpp::enable_if_t<cpp::is_floating_point_v<F> && cpp::is_integral_v<I>,
int> = 0>
static inline I round_to_signed_integer_using_current_rounding_mode(F x) {
return internal::rounded_float_to_signed_integer<F, I>(
round_using_current_rounding_mode(x));

View File

@ -11,7 +11,7 @@
#include "FPBits.h"
#include "src/__support/CPP/TypeTraits.h"
#include "src/__support/CPP/type_traits.h"
#include <stdint.h>
@ -27,7 +27,7 @@ namespace fputil {
// where <mantissa> is of the form 1.<...>.
template <typename T> struct NormalFloat {
static_assert(
cpp::IsFloatingPointType<T>::Value,
cpp::is_floating_point_v<T>,
"NormalFloat template parameter has to be a floating point type.");
using UIntType = typename FPBits<T>::UIntType;

View File

@ -19,13 +19,13 @@
#error "FMA instructions are not supported"
#endif
#include "src/__support/CPP/TypeTraits.h"
#include "src/__support/CPP/type_traits.h"
namespace __llvm_libc {
namespace fputil {
template <typename T>
cpp::EnableIfType<cpp::IsSame<T, float>::Value, T> fma(T x, T y, T z) {
cpp::enable_if_t<cpp::is_same_v<T, float>, T> fma(T x, T y, T z) {
float result;
__asm__ __volatile__("fmadd %s0, %s1, %s2, %s3\n\t"
: "=w"(result)
@ -34,7 +34,7 @@ cpp::EnableIfType<cpp::IsSame<T, float>::Value, T> fma(T x, T y, T z) {
}
template <typename T>
cpp::EnableIfType<cpp::IsSame<T, double>::Value, T> fma(T x, T y, T z) {
cpp::enable_if_t<cpp::is_same_v<T, double> :, T> fma(T x, T y, T z) {
double result;
__asm__ __volatile__("fmadd %d0, %d1, %d2, %d3\n\t"
: "=w"(result)

View File

@ -10,8 +10,8 @@
#define LLVM_LIBC_SRC_SUPPORT_FPUTIL_GENERIC_FMA_H
#include "src/__support/CPP/Bit.h"
#include "src/__support/CPP/TypeTraits.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"

View File

@ -10,7 +10,7 @@
#define LLVM_LIBC_SRC_SUPPORT_FPUTIL_GENERIC_FMOD_H
#include "src/__support/CPP/Limits.h"
#include "src/__support/CPP/TypeTraits.h"
#include "src/__support/CPP/type_traits.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/builtin_wrappers.h"
@ -119,7 +119,7 @@ namespace generic {
// https://www.open-std.org/JTC1/SC22/WG14/www/docs/n1011.htm
template <typename T> struct FModExceptionalInputHandler {
static_assert(cpp::IsFloatingPointType<T>::Value,
static_assert(cpp::is_floating_point_v<T>,
"FModCStandardWrapper instantiated with invalid type.");
static bool PreCheck(T x, T y, T &out) {
@ -157,7 +157,7 @@ template <typename T> struct FModExceptionalInputHandler {
template <typename T> struct FModFastMathWrapper {
static_assert(cpp::IsFloatingPointType<T>::Value,
static_assert(cpp::is_floating_point_v<T>,
"FModFastMathWrapper instantiated with invalid type.");
static bool PreCheck(T, T, T &) { return false; }
@ -216,7 +216,7 @@ public:
template <typename T, class Wrapper = FModExceptionalInputHandler<T>,
class DivisionHelper = FModDivisionSimpleHelper<T>>
class FMod {
static_assert(cpp::IsFloatingPointType<T>::Value,
static_assert(cpp::is_floating_point_v<T>,
"FMod instantiated with invalid type.");
private:

View File

@ -11,8 +11,8 @@
#include "sqrt_80_bit_long_double.h"
#include "src/__support/CPP/Bit.h"
#include "src/__support/CPP/TypeTraits.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/PlatformDefs.h"
@ -64,8 +64,7 @@ inline void normalize<long double>(int &exponent, UInt128 &mantissa) {
// Correctly rounded IEEE 754 SQRT for all rounding modes.
// Shift-and-add algorithm.
template <typename T>
static inline cpp::EnableIfType<cpp::IsFloatingPointType<T>::Value, T>
sqrt(T x) {
static inline cpp::enable_if_t<cpp::is_floating_point_v<T>, T> sqrt(T x) {
if constexpr (internal::SpecialLongDouble<T>::VALUE) {
// Special 80-bit long double.

View File

@ -19,15 +19,14 @@
#error "FMA instructions are not supported"
#endif
#include "src/__support/CPP/TypeTraits.h"
#include "src/__support/CPP/type_traits.h"
#include <immintrin.h>
namespace __llvm_libc {
namespace fputil {
template <typename T>
static inline cpp::EnableIfType<cpp::IsSame<T, float>::Value, T> fma(T x, T y,
T z) {
static inline cpp::enable_if_t<cpp::is_same_v<T, float>, T> fma(T x, T y, T z) {
float result;
__m128 xmm = _mm_load_ss(&x); // NOLINT
__m128 ymm = _mm_load_ss(&y); // NOLINT
@ -38,8 +37,8 @@ static inline cpp::EnableIfType<cpp::IsSame<T, float>::Value, T> fma(T x, T y,
}
template <typename T>
static inline cpp::EnableIfType<cpp::IsSame<T, double>::Value, T> fma(T x, T y,
T z) {
static inline cpp::enable_if_t<cpp::is_same_v<T, double>, T> fma(T x, T y,
T z) {
double result;
__m128d xmm = _mm_load_sd(&x); // NOLINT
__m128d ymm = _mm_load_sd(&y); // NOLINT

View File

@ -100,7 +100,7 @@ template <> struct FPBits<long double> {
FPBits() : bits(0) {}
template <typename XType,
cpp::EnableIfType<cpp::IsSame<long double, XType>::Value, int> = 0>
cpp::enable_if_t<cpp::is_same_v<long double, XType>, int> = 0>
explicit FPBits(XType x) : bits(__llvm_libc::bit_cast<UIntType>(x)) {
// bits starts uninitialized, and setting it to a long double only
// overwrites the first 80 bits. This clears those upper bits.
@ -108,7 +108,7 @@ template <> struct FPBits<long double> {
}
template <typename XType,
cpp::EnableIfType<cpp::IsSame<XType, UIntType>::Value, int> = 0>
cpp::enable_if_t<cpp::is_same_v<XType, UIntType>, int> = 0>
explicit FPBits(XType x) : bits(x) {}
operator long double() { return __llvm_libc::bit_cast<long double>(bits); }

View File

@ -9,18 +9,17 @@
#ifndef LLVM_LIBC_SRC_STDLIB_ABS_UTILS_H
#define LLVM_LIBC_SRC_STDLIB_ABS_UTILS_H
#include "src/__support/CPP/TypeTraits.h"
#include "src/__support/CPP/type_traits.h"
namespace __llvm_libc {
template <typename T>
static constexpr cpp::EnableIfType<cpp::IsIntegral<T>::Value, T>
integer_abs(T n) {
static constexpr cpp::enable_if_t<cpp::is_integral_v<T>, T> integer_abs(T n) {
return (n < 0) ? -n : n;
}
template <typename T>
static constexpr cpp::EnableIfType<cpp::IsIntegral<T>::Value, void>
static constexpr cpp::enable_if_t<cpp::is_integral_v<T>, void>
integer_rem_quo(T x, T y, T &quot, T &rem) {
quot = x / y;
rem = x % y;

View File

@ -10,15 +10,15 @@
#define LLVM_LIBC_SRC_SUPPORT_INTEGER_TO_STRING_H
#include "src/__support/CPP/StringView.h"
#include "src/__support/CPP/TypeTraits.h"
#include "src/__support/CPP/type_traits.h"
namespace __llvm_libc {
template <typename T> class IntegerToString {
static_assert(cpp::IsIntegral<T>::Value,
static_assert(cpp::is_integral_v<T>,
"IntegerToString can only be used with integral types.");
using UnsignedType = cpp::MakeUnsignedType<T>;
using UnsignedType = cpp::make_unsigned_t<T>;
// We size the string buffer using an approximation algorithm:
//
@ -39,7 +39,7 @@ template <typename T> class IntegerToString {
// add an additional byte to accommodate the '-' sign in case of signed
// integers.
static constexpr size_t BUFSIZE =
(sizeof(T) * 5 + 1) / 2 + (cpp::IsSigned<T>() ? 1 : 0);
(sizeof(T) * 5 + 1) / 2 + (cpp::is_signed<T>() ? 1 : 0);
char strbuf[BUFSIZE] = {'\0'};
size_t len = 0;

View File

@ -10,7 +10,7 @@
#define LLVM_LIBC_SRC_MATH_MATH_UTILS_H
#include "src/__support/CPP/Bit.h"
#include "src/__support/CPP/TypeTraits.h"
#include "src/__support/CPP/type_traits.h"
#include "src/__support/common.h"
#include <errno.h>
#include <math.h>
@ -72,11 +72,11 @@ template <typename T> static inline T opt_barrier(T x) {
template <typename T> struct IsFloatOrDouble {
static constexpr bool
Value = // NOLINT so that this Value can match the ones for IsSame
cpp::IsSame<T, float>::Value || cpp::IsSame<T, double>::Value;
cpp::is_same_v<T, float> || cpp::is_same_v<T, double>;
};
template <typename T>
using EnableIfFloatOrDouble = cpp::EnableIfType<IsFloatOrDouble<T>::Value, int>;
using EnableIfFloatOrDouble = cpp::enable_if_t<IsFloatOrDouble<T>::Value, int>;
template <typename T, EnableIfFloatOrDouble<T> = 0>
T xflow(uint32_t sign, T y) {

View File

@ -12,7 +12,7 @@
#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_COMMON_H
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_COMMON_H
#include "src/__support/CPP/TypeTraits.h" // cpp::ConditionalType
#include "src/__support/CPP/type_traits.h" // cpp::ConditionalType
#include "src/string/memory_utils/utils.h" // is_power2
#include <stddef.h> // size_t
#include <stdint.h> // uint8_t, uint16_t, uint32_t, uint64_t
@ -48,8 +48,8 @@ template <size_t Alignment, Permission P, Temporality TS> struct Address {
static constexpr Temporality TEMPORALITY = TS;
static constexpr bool IS_READ = P == Permission::Read;
static constexpr bool IS_WRITE = P == Permission::Write;
using PointeeType = cpp::ConditionalType<!IS_WRITE, const ubyte, ubyte>;
using VoidType = cpp::ConditionalType<!IS_WRITE, const void, void>;
using PointeeType = cpp::conditional_t<!IS_WRITE, const ubyte, ubyte>;
using VoidType = cpp::conditional_t<!IS_WRITE, const void, void>;
Address(VoidType *ptr) : ptr_(reinterpret_cast<PointeeType *>(ptr)) {}
@ -79,15 +79,15 @@ private:
}
};
template <typename T> struct IsAddressType : public cpp::FalseValue {};
template <typename T> struct IsAddressType : public cpp::false_type {};
template <size_t Alignment, Permission P, Temporality TS>
struct IsAddressType<Address<Alignment, P, TS>> : public cpp::TrueValue {};
struct IsAddressType<Address<Alignment, P, TS>> : public cpp::true_type {};
// Reinterpret the address as a pointer to T.
// This is not UB since the underlying pointer always refers to a `char` in a
// buffer of raw data.
template <typename T, typename AddrT> static T *as(AddrT addr) {
static_assert(IsAddressType<AddrT>::Value);
static_assert(IsAddressType<AddrT>::value);
return reinterpret_cast<T *>(addr.ptr());
}
@ -95,7 +95,7 @@ template <typename T, typename AddrT> static T *as(AddrT addr) {
// alignment whenever possible.
template <size_t ByteOffset, typename AddrT>
static auto offsetAddr(AddrT addr) {
static_assert(IsAddressType<AddrT>::Value);
static_assert(IsAddressType<AddrT>::value);
return addr.template offset<ByteOffset>(ByteOffset);
}
@ -103,7 +103,7 @@ static auto offsetAddr(AddrT addr) {
// address will be Alignment aligned.
template <size_t Alignment, typename AddrT>
static auto offsetAddrAssumeAligned(AddrT addr, size_t byte_offset) {
static_assert(IsAddressType<AddrT>::Value);
static_assert(IsAddressType<AddrT>::value);
return Address<Alignment, AddrT::PERMISSION, AddrT::TEMPORALITY>(addr.ptr_ +
byte_offset);
}
@ -112,7 +112,7 @@ static auto offsetAddrAssumeAligned(AddrT addr, size_t byte_offset) {
// ByteOffset. This allows to propagate the address alignment whenever possible.
template <size_t ByteOffset, typename AddrT>
static auto offsetAddrMultiplesOf(AddrT addr, ptrdiff_t byte_offset) {
static_assert(IsAddressType<AddrT>::Value);
static_assert(IsAddressType<AddrT>::value);
return addr.template offset<ByteOffset>(byte_offset);
}

View File

@ -71,7 +71,7 @@ template <ptrdiff_t Bytes> struct Skip {
// Because of the runtime size, we loose the alignment information.
template <size_t Size, typename AddrT>
static auto tailAddr(AddrT addr, size_t runtime_size) {
static_assert(IsAddressType<AddrT>::Value);
static_assert(IsAddressType<AddrT>::value);
return offsetAddrAssumeAligned<1>(addr, runtime_size - Size);
}
@ -440,8 +440,8 @@ private:
template <typename Arg1AddrT, typename Arg2AddrT>
static auto align(Arg1AddrT arg1, Arg2AddrT arg2, size_t runtime_size) {
static_assert(IsAddressType<Arg1AddrT>::Value);
static_assert(IsAddressType<Arg2AddrT>::Value);
static_assert(IsAddressType<Arg1AddrT>::value);
static_assert(IsAddressType<Arg2AddrT>::value);
if constexpr (AlignOn == Arg::_1) {
auto offset = offset_to_next_aligned<ALIGN_OP_SIZE>(arg1.ptr_);
return makeAligned(offsetAddrAssumeAligned<ALIGN_OP_SIZE>(arg1, offset),

View File

@ -22,7 +22,7 @@ struct Aarch64Backend : public Scalar64BitBackend {
static constexpr bool IS_BACKEND_TYPE = true;
template <typename T, Temporality TS, Aligned AS,
cpp::EnableIfType<Scalar64BitBackend::IsScalarType<T>, bool> = true>
cpp::enable_if_t<Scalar64BitBackend::IsScalarType<T>, bool> = true>
static inline T load(const T *src) {
return Scalar64BitBackend::template load<T, TS, AS>(src);
}

View File

@ -8,7 +8,7 @@
#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_BACKEND_SCALAR_H
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_BACKEND_SCALAR_H
#include "src/__support/CPP/TypeTraits.h" // ConditionalType, EnableIfType
#include "src/__support/CPP/type_traits.h" // ConditionalType, enable_if_t
#include "src/__support/endian.h"
namespace __llvm_libc {
@ -18,8 +18,8 @@ struct Scalar64BitBackend {
template <typename T>
static constexpr bool IsScalarType =
cpp::IsSameV<T, uint8_t> || cpp::IsSameV<T, uint16_t> ||
cpp::IsSameV<T, uint32_t> || cpp::IsSameV<T, uint64_t>;
cpp::is_same_v<T, uint8_t> || cpp::is_same_v<T, uint16_t> ||
cpp::is_same_v<T, uint32_t> || cpp::is_same_v<T, uint64_t>;
template <typename T, Temporality TS, Aligned AS>
static inline T load(const T *src) {
@ -53,10 +53,10 @@ struct Scalar64BitBackend {
// Returns the type to use to consume Size bytes.
template <size_t Size>
using getNextType = cpp::ConditionalType<
using getNextType = cpp::conditional_t<
Size >= 8, uint64_t,
cpp::ConditionalType<Size >= 4, uint32_t,
cpp::ConditionalType<Size >= 2, uint16_t, uint8_t>>>;
cpp::conditional_t<Size >= 4, uint32_t,
cpp::conditional_t<Size >= 2, uint16_t, uint8_t>>>;
};
template <>

View File

@ -9,7 +9,7 @@
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_BACKEND_X86_H
#if defined(LLVM_LIBC_ARCH_X86)
#include "src/__support/CPP/TypeTraits.h" // ConditionalType, EnableIfType
#include "src/__support/CPP/type_traits.h" // ConditionalType, enable_if_t
#include "src/string/memory_utils/backend_scalar.h"
#ifdef __SSE2__
@ -40,63 +40,61 @@ struct X86Backend : public Scalar64BitBackend {
// Scalar types use base class implementations.
template <typename T, Temporality TS, Aligned AS,
cpp::EnableIfType<Scalar64BitBackend::IsScalarType<T>, bool> = true>
cpp::enable_if_t<Scalar64BitBackend::IsScalarType<T>, bool> = true>
static inline T load(const T *src) {
return Scalar64BitBackend::template load<T, TS, AS>(src);
}
// Scalar types use base class implementations.
template <typename T, Temporality TS, Aligned AS,
cpp::EnableIfType<Scalar64BitBackend::IsScalarType<T>, bool> = true>
cpp::enable_if_t<Scalar64BitBackend::IsScalarType<T>, bool> = true>
static inline void store(T *dst, T value) {
Scalar64BitBackend::template store<T, TS, AS>(dst, value);
}
// Scalar types use base class implementations.
template <typename T,
cpp::EnableIfType<Scalar64BitBackend::IsScalarType<T>, bool> = true>
cpp::enable_if_t<Scalar64BitBackend::IsScalarType<T>, bool> = true>
static inline uint64_t notEquals(T v1, T v2) {
return Scalar64BitBackend::template notEquals<T>(v1, v2);
}
// Scalar types use base class implementations.
template <typename T,
cpp::EnableIfType<Scalar64BitBackend::IsScalarType<T>, bool> = true>
cpp::enable_if_t<Scalar64BitBackend::IsScalarType<T>, bool> = true>
static inline T splat(ubyte value) {
return Scalar64BitBackend::template splat<T>(value);
}
// Scalar types use base class implementations.
template <typename T,
cpp::EnableIfType<Scalar64BitBackend::IsScalarType<T>, bool> = true>
cpp::enable_if_t<Scalar64BitBackend::IsScalarType<T>, bool> = true>
static inline int32_t threeWayCmp(T v1, T v2) {
return Scalar64BitBackend::template threeWayCmp<T>(v1, v2);
}
// X86 types are specialized below.
template <
typename T, Temporality TS, Aligned AS,
cpp::EnableIfType<!Scalar64BitBackend::IsScalarType<T>, bool> = true>
template <typename T, Temporality TS, Aligned AS,
cpp::enable_if_t<!Scalar64BitBackend::IsScalarType<T>, bool> = true>
static inline T load(const T *src);
// X86 types are specialized below.
template <
typename T, Temporality TS, Aligned AS,
cpp::EnableIfType<!Scalar64BitBackend::IsScalarType<T>, bool> = true>
template <typename T, Temporality TS, Aligned AS,
cpp::enable_if_t<!Scalar64BitBackend::IsScalarType<T>, bool> = true>
static inline void store(T *dst, T value);
// X86 types are specialized below.
template <typename T, cpp::EnableIfType<!Scalar64BitBackend::IsScalarType<T>,
bool> = true>
template <typename T,
cpp::enable_if_t<!Scalar64BitBackend::IsScalarType<T>, bool> = true>
static inline T splat(ubyte value);
// X86 types are specialized below.
template <typename T, cpp::EnableIfType<!Scalar64BitBackend::IsScalarType<T>,
bool> = true>
template <typename T,
cpp::enable_if_t<!Scalar64BitBackend::IsScalarType<T>, bool> = true>
static inline uint64_t notEquals(T v1, T v2);
template <typename T, cpp::EnableIfType<!Scalar64BitBackend::IsScalarType<T>,
bool> = true>
template <typename T,
cpp::enable_if_t<!Scalar64BitBackend::IsScalarType<T>, bool> = true>
static inline int32_t threeWayCmp(T v1, T v2) {
return char_diff(reinterpret_cast<char *>(&v1),
reinterpret_cast<char *>(&v2), notEquals(v1, v2));
@ -104,12 +102,12 @@ struct X86Backend : public Scalar64BitBackend {
// Returns the type to use to consume Size bytes.
template <size_t Size>
using getNextType = cpp::ConditionalType<
using getNextType = cpp::conditional_t<
(HAS_M512 && Size >= 64), __m512i,
cpp::ConditionalType<
cpp::conditional_t<
(HAS_M256 && Size >= 32), __m256i,
cpp::ConditionalType<(HAS_M128 && Size >= 16), __m128i,
Scalar64BitBackend::getNextType<Size>>>>;
cpp::conditional_t<(HAS_M128 && Size >= 16), __m128i,
Scalar64BitBackend::getNextType<Size>>>>;
private:
static inline int32_t char_diff(const char *a, const char *b, uint64_t mask) {

View File

@ -50,7 +50,7 @@ private:
// This is possible because the address type carries known compile-time
// alignment informations.
template <typename T, typename AddrT> static constexpr Aligned isAligned() {
static_assert(IsAddressType<AddrT>::Value);
static_assert(IsAddressType<AddrT>::value);
return AddrT::ALIGNMENT > 1 && AddrT::ALIGNMENT >= sizeof(T) ? Aligned::YES
: Aligned::NO;
}
@ -59,7 +59,7 @@ private:
// This function is responsible for extracting Temporality and Alignment from
// the Address type.
template <typename SrcAddrT> static inline auto nativeLoad(SrcAddrT src) {
static_assert(IsAddressType<SrcAddrT>::Value && SrcAddrT::IS_READ);
static_assert(IsAddressType<SrcAddrT>::value && SrcAddrT::IS_READ);
constexpr auto AS = isAligned<type, SrcAddrT>();
constexpr auto TS = SrcAddrT::TEMPORALITY;
return Backend::template load<type, TS, AS>(as<const type>(src));
@ -70,7 +70,7 @@ private:
// the Address type.
template <typename DstAddrT>
static inline void nativeStore(type value, DstAddrT dst) {
static_assert(IsAddressType<DstAddrT>::Value && DstAddrT::IS_WRITE);
static_assert(IsAddressType<DstAddrT>::value && DstAddrT::IS_WRITE);
constexpr auto AS = isAligned<type, DstAddrT>();
constexpr auto TS = DstAddrT::TEMPORALITY;
return Backend::template store<type, TS, AS>(as<type>(dst), value);
@ -85,8 +85,8 @@ private:
public:
template <typename DstAddrT, typename SrcAddrT>
static inline void copy(DstAddrT dst, SrcAddrT src) {
static_assert(IsAddressType<DstAddrT>::Value && DstAddrT::IS_WRITE);
static_assert(IsAddressType<SrcAddrT>::Value && SrcAddrT::IS_READ);
static_assert(IsAddressType<DstAddrT>::value && DstAddrT::IS_WRITE);
static_assert(IsAddressType<SrcAddrT>::value && SrcAddrT::IS_READ);
if constexpr (LLVM_LIBC_USE_BUILTIN_MEMCPY_INLINE &&
DstAddrT::TEMPORALITY == Temporality::TEMPORAL &&
SrcAddrT::TEMPORALITY == Temporality::TEMPORAL) {

View File

@ -12,13 +12,13 @@
using namespace __llvm_libc::cpp;
TEST(LlvmLibcIntegerSequencetTest, Basic) {
EXPECT_TRUE((IsSameV<IntegerSequence<int>, MakeIntegerSequence<int, 0>>));
EXPECT_TRUE((is_same_v<IntegerSequence<int>, MakeIntegerSequence<int, 0>>));
using ISeq = IntegerSequence<int, 0, 1, 2, 3>;
EXPECT_TRUE((IsSameV<ISeq, MakeIntegerSequence<int, 4>>));
EXPECT_TRUE((is_same_v<ISeq, MakeIntegerSequence<int, 4>>));
using LSeq = IntegerSequence<long, 0, 1, 2, 3>;
EXPECT_TRUE((IsSameV<LSeq, MakeIntegerSequence<long, 4>>));
EXPECT_TRUE((is_same_v<LSeq, MakeIntegerSequence<long, 4>>));
using ULLSeq = IntegerSequence<unsigned long long, 0ull, 1ull, 2ull, 3ull>;
EXPECT_TRUE((IsSameV<ULLSeq, MakeIntegerSequence<unsigned long long, 4>>));
EXPECT_TRUE((is_same_v<ULLSeq, MakeIntegerSequence<unsigned long long, 4>>));
}
template <typename T, T... Ts>

View File

@ -10,7 +10,7 @@
#define LLVM_LIBC_TEST_SRC_MATH_NEXTAFTERTEST_H
#include "src/__support/CPP/Bit.h"
#include "src/__support/CPP/TypeTraits.h"
#include "src/__support/CPP/type_traits.h"
#include "src/__support/FPUtil/BasicOperations.h"
#include "src/__support/FPUtil/FPBits.h"
#include "utils/UnitTest/FPMatcher.h"

View File

@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
#include "src/__support/CPP/TypeTraits.h"
#include "src/__support/CPP/type_traits.h"
#include "src/__support/FPUtil/FPBits.h"
#include "utils/MPFRWrapper/MPFRUtils.h"
#include "utils/UnitTest/Test.h"
@ -21,7 +21,7 @@ template <typename T, typename FloatType = float>
struct LlvmLibcExhaustiveTest : public __llvm_libc::testing::Test {
static constexpr T increment = (1 << 20);
static_assert(
__llvm_libc::cpp::IsSameV<
__llvm_libc::cpp::is_same_v<
T, typename __llvm_libc::fputil::FPBits<FloatType>::UIntType>,
"Types are not consistent");
// Break [start, stop) into `nthreads` subintervals and apply *check to each

View File

@ -5,7 +5,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "src/__support/CPP/TypeTraits.h"
#include "src/__support/CPP/type_traits.h"
#include "src/__support/FPUtil/generic/FMod.h"
#include "utils/MPFRWrapper/MPFRUtils.h"
#include "utils/UnitTest/FPMatcher.h"
@ -19,7 +19,7 @@ namespace mpfr = __llvm_libc::testing::mpfr;
template <typename T, bool InverseMultiplication>
class LlvmLibcFModTest : public __llvm_libc::testing::Test {
using DivisionHelper = __llvm_libc::cpp::ConditionalType<
using DivisionHelper = __llvm_libc::cpp::conditional_t<
InverseMultiplication,
__llvm_libc::fputil::generic::FModDivisionInvMultHelper<T>,
__llvm_libc::fputil::generic::FModDivisionSimpleHelper<T>>;

View File

@ -4,10 +4,10 @@
namespace __llvm_libc {
TEST(LlvmLibcAddress, AliasAreAddresses) {
ASSERT_TRUE(IsAddressType<SrcAddr<1>>::Value);
ASSERT_TRUE(IsAddressType<DstAddr<1>>::Value);
ASSERT_TRUE(IsAddressType<NtSrcAddr<1>>::Value);
ASSERT_TRUE(IsAddressType<NtDstAddr<1>>::Value);
ASSERT_TRUE(IsAddressType<SrcAddr<1>>::value);
ASSERT_TRUE(IsAddressType<DstAddr<1>>::value);
ASSERT_TRUE(IsAddressType<NtSrcAddr<1>>::value);
ASSERT_TRUE(IsAddressType<NtDstAddr<1>>::value);
}
TEST(LlvmLibcAddress, AliasHaveRightPermissions) {

View File

@ -73,7 +73,7 @@ bool TestGeneratorMain(llvm::raw_ostream &OS, llvm::RecordKeeper &records) {
if (llvm::StringRef(returnType).contains("_Noreturn"))
returnType = "void";
OS << " static_assert(__llvm_libc::cpp::IsSame<" << returnType << '(';
OS << " static_assert(__llvm_libc::cpp::is_same_v<" << returnType << '(';
auto args = functionSpec->getValueAsListOfDefs("Args");
for (size_t i = 0, size = args.size(); i < size; ++i) {
llvm::Record *argType = args[i]->getValueAsDef("ArgType");

View File

@ -121,7 +121,7 @@ public:
// conversions. Implicit conversions can potentially lead to loss of
// precision.
template <typename XType,
cpp::EnableIfType<cpp::IsSame<float, XType>::Value, int> = 0>
cpp::enable_if_t<cpp::is_same_v<float, XType>, int> = 0>
explicit MPFRNumber(XType x, int precision = ExtraPrecision<XType>::VALUE,
RoundingMode rounding = RoundingMode::Nearest)
: mpfr_precision(precision),
@ -131,7 +131,7 @@ public:
}
template <typename XType,
cpp::EnableIfType<cpp::IsSame<double, XType>::Value, int> = 0>
cpp::enable_if_t<cpp::is_same_v<double, XType>, int> = 0>
explicit MPFRNumber(XType x, int precision = ExtraPrecision<XType>::VALUE,
RoundingMode rounding = RoundingMode::Nearest)
: mpfr_precision(precision),
@ -141,7 +141,7 @@ public:
}
template <typename XType,
cpp::EnableIfType<cpp::IsSame<long double, XType>::Value, int> = 0>
cpp::enable_if_t<cpp::is_same_v<long double, XType>, int> = 0>
explicit MPFRNumber(XType x, int precision = ExtraPrecision<XType>::VALUE,
RoundingMode rounding = RoundingMode::Nearest)
: mpfr_precision(precision),
@ -151,7 +151,7 @@ public:
}
template <typename XType,
cpp::EnableIfType<cpp::IsIntegral<XType>::Value, int> = 0>
cpp::enable_if_t<cpp::is_integral_v<XType>, int> = 0>
explicit MPFRNumber(XType x, int precision = ExtraPrecision<float>::VALUE,
RoundingMode rounding = RoundingMode::Nearest)
: mpfr_precision(precision),
@ -396,7 +396,7 @@ public:
// of N between this number and [input].
// 4. A values of +0.0 and -0.0 are treated as equal.
template <typename T>
cpp::EnableIfType<cpp::IsFloatingPointType<T>::Value, double> ulp(T input) {
cpp::enable_if_t<cpp::is_floating_point_v<T>, double> ulp(T input) {
T thisAsT = as<T>();
if (thisAsT == input)
return T(0.0);
@ -470,7 +470,7 @@ template <> long double MPFRNumber::as<long double>() const {
namespace internal {
template <typename InputType>
cpp::EnableIfType<cpp::IsFloatingPointType<InputType>::Value, MPFRNumber>
cpp::enable_if_t<cpp::is_floating_point_v<InputType>, MPFRNumber>
unary_operation(Operation op, InputType input, unsigned int precision,
RoundingMode rounding) {
MPFRNumber mpfrInput(input, precision, rounding);
@ -519,7 +519,7 @@ unary_operation(Operation op, InputType input, unsigned int precision,
}
template <typename InputType>
cpp::EnableIfType<cpp::IsFloatingPointType<InputType>::Value, MPFRNumber>
cpp::enable_if_t<cpp::is_floating_point_v<InputType>, MPFRNumber>
unary_operation_two_outputs(Operation op, InputType input, int &output,
unsigned int precision, RoundingMode rounding) {
MPFRNumber mpfrInput(input, precision, rounding);
@ -532,7 +532,7 @@ unary_operation_two_outputs(Operation op, InputType input, int &output,
}
template <typename InputType>
cpp::EnableIfType<cpp::IsFloatingPointType<InputType>::Value, MPFRNumber>
cpp::enable_if_t<cpp::is_floating_point_v<InputType>, MPFRNumber>
binary_operation_one_output(Operation op, InputType x, InputType y,
unsigned int precision, RoundingMode rounding) {
MPFRNumber inputX(x, precision, rounding);
@ -548,7 +548,7 @@ binary_operation_one_output(Operation op, InputType x, InputType y,
}
template <typename InputType>
cpp::EnableIfType<cpp::IsFloatingPointType<InputType>::Value, MPFRNumber>
cpp::enable_if_t<cpp::is_floating_point_v<InputType>, MPFRNumber>
binary_operation_two_outputs(Operation op, InputType x, InputType y,
int &output, unsigned int precision,
RoundingMode rounding) {
@ -563,7 +563,7 @@ binary_operation_two_outputs(Operation op, InputType x, InputType y,
}
template <typename InputType>
cpp::EnableIfType<cpp::IsFloatingPointType<InputType>::Value, MPFRNumber>
cpp::enable_if_t<cpp::is_floating_point_v<InputType>, MPFRNumber>
ternary_operation_one_output(Operation op, InputType x, InputType y,
InputType z, unsigned int precision,
RoundingMode rounding) {

View File

@ -9,7 +9,7 @@
#ifndef LLVM_LIBC_UTILS_TESTUTILS_MPFRUTILS_H
#define LLVM_LIBC_UTILS_TESTUTILS_MPFRUTILS_H
#include "src/__support/CPP/TypeTraits.h"
#include "src/__support/CPP/type_traits.h"
#include "utils/UnitTest/Test.h"
#include "utils/testutils/RoundingModeUtils.h"
@ -81,7 +81,7 @@ using __llvm_libc::testutils::RoundingMode;
template <typename T> struct BinaryInput {
static_assert(
__llvm_libc::cpp::IsFloatingPointType<T>::Value,
__llvm_libc::cpp::is_floating_point_v<T>,
"Template parameter of BinaryInput must be a floating point type.");
using Type = T;
@ -90,7 +90,7 @@ template <typename T> struct BinaryInput {
template <typename T> struct TernaryInput {
static_assert(
__llvm_libc::cpp::IsFloatingPointType<T>::Value,
__llvm_libc::cpp::is_floating_point_v<T>,
"Template parameter of TernaryInput must be a floating point type.");
using Type = T;
@ -111,7 +111,7 @@ struct AreMatchingBinaryInputAndBinaryOutput {
template <typename T>
struct AreMatchingBinaryInputAndBinaryOutput<BinaryInput<T>, BinaryOutput<T>> {
static constexpr bool VALUE = cpp::IsFloatingPointType<T>::Value;
static constexpr bool VALUE = cpp::is_floating_point_v<T>;
};
template <typename T>
@ -260,30 +260,30 @@ template <Operation op, typename InputType, typename OutputType>
constexpr bool is_valid_operation() {
return (Operation::BeginUnaryOperationsSingleOutput < op &&
op < Operation::EndUnaryOperationsSingleOutput &&
cpp::IsSame<InputType, OutputType>::Value &&
cpp::IsFloatingPointType<InputType>::Value) ||
cpp::is_same_v<InputType, OutputType> &&
cpp::is_floating_point_v<InputType>) ||
(Operation::BeginUnaryOperationsTwoOutputs < op &&
op < Operation::EndUnaryOperationsTwoOutputs &&
cpp::IsFloatingPointType<InputType>::Value &&
cpp::IsSame<OutputType, BinaryOutput<InputType>>::Value) ||
cpp::is_floating_point_v<InputType> &&
cpp::is_same_v<OutputType, BinaryOutput<InputType>>) ||
(Operation::BeginBinaryOperationsSingleOutput < op &&
op < Operation::EndBinaryOperationsSingleOutput &&
cpp::IsFloatingPointType<OutputType>::Value &&
cpp::IsSame<InputType, BinaryInput<OutputType>>::Value) ||
cpp::is_floating_point_v<OutputType> &&
cpp::is_same_v<InputType, BinaryInput<OutputType>>) ||
(Operation::BeginBinaryOperationsTwoOutputs < op &&
op < Operation::EndBinaryOperationsTwoOutputs &&
internal::AreMatchingBinaryInputAndBinaryOutput<InputType,
OutputType>::VALUE) ||
(Operation::BeginTernaryOperationsSingleOuput < op &&
op < Operation::EndTernaryOperationsSingleOutput &&
cpp::IsFloatingPointType<OutputType>::Value &&
cpp::IsSame<InputType, TernaryInput<OutputType>>::Value);
cpp::is_floating_point_v<OutputType> &&
cpp::is_same_v<InputType, TernaryInput<OutputType>>);
}
template <Operation op, typename InputType, typename OutputType>
__attribute__((no_sanitize("address")))
cpp::EnableIfType<is_valid_operation<op, InputType, OutputType>(),
internal::MPFRMatcher<op, InputType, OutputType>>
cpp::enable_if_t<is_valid_operation<op, InputType, OutputType>(),
internal::MPFRMatcher<op, InputType, OutputType>>
get_mpfr_matcher(InputType input, OutputType output_unused,
double ulp_tolerance, RoundingMode rounding) {
return internal::MPFRMatcher<op, InputType, OutputType>(input, ulp_tolerance,

View File

@ -20,7 +20,7 @@ namespace fputil {
namespace testing {
template <typename ValType, typename StreamType>
cpp::EnableIfType<cpp::IsFloatingPointType<ValType>::Value, void>
cpp::enable_if_t<cpp::is_floating_point_v<ValType>, void>
describeValue(const char *label, ValType value, StreamType &stream) {
stream << label;

View File

@ -21,12 +21,12 @@ namespace fputil {
namespace testing {
template <typename ValType, typename StreamType>
cpp::EnableIfType<cpp::IsFloatingPointType<ValType>::Value, void>
cpp::enable_if_t<cpp::is_floating_point_v<ValType>, void>
describeValue(const char *label, ValType value, StreamType &stream);
template <typename T, __llvm_libc::testing::TestCondition Condition>
class FPMatcher : public __llvm_libc::testing::Matcher<T> {
static_assert(__llvm_libc::cpp::IsFloatingPointType<T>::Value,
static_assert(__llvm_libc::cpp::is_floating_point_v<T>,
"FPMatcher can only be used with floating point values.");
static_assert(Condition == __llvm_libc::testing::Cond_EQ ||
Condition == __llvm_libc::testing::Cond_NE,

View File

@ -36,7 +36,7 @@ namespace internal {
// When the value is of integral type, just display it as normal.
template <typename ValType>
cpp::EnableIfType<cpp::IsIntegral<ValType>::Value, std::string>
cpp::enable_if_t<cpp::is_integral_v<ValType>, std::string>
describeValue(ValType Value) {
return std::to_string(Value);
}

View File

@ -14,7 +14,7 @@
#include "PlatformDefs.h"
#include "src/__support/CPP/TypeTraits.h"
#include "src/__support/CPP/type_traits.h"
#include "utils/testutils/ExecuteFunction.h"
#include "utils/testutils/StreamWrapper.h"
@ -83,23 +83,22 @@ protected:
// |Cond| on mismatched |LHS| and |RHS| types can potentially succeed because
// of type promotion.
template <typename ValType,
cpp::EnableIfType<cpp::IsIntegral<ValType>::Value, int> = 0>
cpp::enable_if_t<cpp::is_integral_v<ValType>, int> = 0>
bool test(TestCondition Cond, ValType LHS, ValType RHS, const char *LHSStr,
const char *RHSStr, const char *File, unsigned long Line) {
return internal::test(Ctx, Cond, LHS, RHS, LHSStr, RHSStr, File, Line);
}
template <typename ValType,
cpp::EnableIfType<cpp::IsEnum<ValType>::Value, int> = 0>
cpp::enable_if_t<cpp::is_enum<ValType>::value, int> = 0>
bool test(TestCondition Cond, ValType LHS, ValType RHS, const char *LHSStr,
const char *RHSStr, const char *File, unsigned long Line) {
return internal::test(Ctx, Cond, (long long)LHS, (long long)RHS, LHSStr,
RHSStr, File, Line);
}
template <
typename ValType,
cpp::EnableIfType<cpp::IsPointerType<ValType>::Value, ValType> = nullptr>
template <typename ValType,
cpp::enable_if_t<cpp::is_pointer_v<ValType>, ValType> = nullptr>
bool test(TestCondition Cond, ValType LHS, ValType RHS, const char *LHSStr,
const char *RHSStr, const char *File, unsigned long Line) {
return internal::test(Ctx, Cond, (unsigned long long)LHS,

View File

@ -9,7 +9,7 @@
#ifndef LLVM_LIBC_UTILS_UNITTEST_SIMPLE_STRING_CONV_H
#define LLVM_LIBC_UTILS_UNITTEST_SIMPLE_STRING_CONV_H
#include "src/__support/CPP/TypeTraits.h"
#include "src/__support/CPP/type_traits.h"
#include <string>
@ -17,7 +17,7 @@ namespace __llvm_libc {
// Return the first N hex digits of an integer as a string in upper case.
template <typename T>
cpp::EnableIfType<cpp::IsIntegral<T>::Value, std::string>
cpp::enable_if_t<cpp::is_integral_v<T>, std::string>
int_to_hex(T X, size_t Length = sizeof(T) * 2) {
std::string s(Length, '0');

View File

@ -100,7 +100,7 @@ cc_library(
cc_library(
name = "__support_cpp_type_traits",
hdrs = [
"src/__support/CPP/TypeTraits.h",
"src/__support/CPP/type_traits.h",
],
deps = [":libc_root","__support_cpp_uint"],
)