173 changes: 173 additions & 0 deletions libc/src/__support/CPP/type_traits.h
Original file line number Diff line number Diff line change
@@ -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
14 changes: 5 additions & 9 deletions libc/src/__support/FPUtil/BasicOperations.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand Down
5 changes: 2 additions & 3 deletions libc/src/__support/FPUtil/DivisionAndRemainderOperations.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion libc/src/__support/FPUtil/FMA.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 4 additions & 5 deletions libc/src/__support/FPUtil/FPBits.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand Down Expand Up @@ -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) {}
Expand Down
5 changes: 2 additions & 3 deletions libc/src/__support/FPUtil/Hypot.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 8 additions & 15 deletions libc/src/__support/FPUtil/ManipulationFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@
#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>

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())
Expand All @@ -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()) {
Expand All @@ -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.
Expand Down Expand Up @@ -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()) {
Expand All @@ -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)
Expand All @@ -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())
Expand Down
32 changes: 12 additions & 20 deletions libc/src/__support/FPUtil/NearestIntegerOperations.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@
#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>

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

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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()) {
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions libc/src/__support/FPUtil/NormalFloat.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "FPBits.h"

#include "src/__support/CPP/TypeTraits.h"
#include "src/__support/CPP/type_traits.h"

#include <stdint.h>

Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions libc/src/__support/FPUtil/aarch64/FMA.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion libc/src/__support/FPUtil/generic/FMA.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions libc/src/__support/FPUtil/generic/FMod.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -216,7 +216,7 @@ template <typename T> class FModDivisionInvMultHelper {
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:
Expand Down
5 changes: 2 additions & 3 deletions libc/src/__support/FPUtil/generic/sqrt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
9 changes: 4 additions & 5 deletions libc/src/__support/FPUtil/x86_64/FMA.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions libc/src/__support/FPUtil/x86_64/LongDoubleBits.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ 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.
bits = bits & ((UIntType(1) << 80) - 1);
}

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); }
Expand Down
7 changes: 3 additions & 4 deletions libc/src/__support/integer_operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions libc/src/__support/integer_to_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
//
Expand All @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions libc/src/math/generic/math_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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) {
Expand Down
18 changes: 9 additions & 9 deletions libc/src/string/memory_utils/address.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)) {}

Expand Down Expand Up @@ -79,31 +79,31 @@ template <size_t Alignment, Permission P, Temporality TS> struct Address {
}
};

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());
}

// Offsets the address by a compile time amount, this allows propagating
// 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);
}

// Offsets the address by a runtime amount but assuming that the resulting
// 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);
}
Expand All @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions libc/src/string/memory_utils/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -440,8 +440,8 @@ template <typename SizedOpT, Arg AlignOn = Arg::_1> struct Align {

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),
Expand Down
2 changes: 1 addition & 1 deletion libc/src/string/memory_utils/backend_aarch64.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
12 changes: 6 additions & 6 deletions libc/src/string/memory_utils/backend_scalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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 <>
Expand Down
42 changes: 20 additions & 22 deletions libc/src/string/memory_utils/backend_x86.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -40,76 +40,74 @@ 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));
}

// 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) {
Expand Down
10 changes: 5 additions & 5 deletions libc/src/string/memory_utils/sized_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ template <typename Backend, size_t Size> struct SizedOp {
// 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;
}
Expand All @@ -59,7 +59,7 @@ template <typename Backend, size_t Size> struct SizedOp {
// 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));
Expand All @@ -70,7 +70,7 @@ template <typename Backend, size_t Size> struct SizedOp {
// 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);
Expand All @@ -85,8 +85,8 @@ template <typename Backend, size_t Size> struct SizedOp {
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) {
Expand Down
8 changes: 4 additions & 4 deletions libc/test/src/__support/CPP/integer_sequence_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/math/NextAfterTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions libc/test/src/math/exhaustive/exhaustive_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions libc/test/src/math/exhaustive/fmod_generic_impl_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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>>;
Expand Down
8 changes: 4 additions & 4 deletions libc/test/src/string/memory_utils/address_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion libc/utils/HdrGen/PrototypeTestGen/PrototypeTestGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
20 changes: 10 additions & 10 deletions libc/utils/MPFRWrapper/MPFRUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class MPFRNumber {
// 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),
Expand All @@ -131,7 +131,7 @@ class MPFRNumber {
}

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),
Expand All @@ -141,7 +141,7 @@ class MPFRNumber {
}

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),
Expand All @@ -151,7 +151,7 @@ class MPFRNumber {
}

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),
Expand Down Expand Up @@ -396,7 +396,7 @@ class MPFRNumber {
// 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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
28 changes: 14 additions & 14 deletions libc/utils/MPFRWrapper/MPFRUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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>
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion libc/utils/UnitTest/FPMatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions libc/utils/UnitTest/FPMatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion libc/utils/UnitTest/LibcTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
11 changes: 5 additions & 6 deletions libc/utils/UnitTest/LibcTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -83,23 +83,22 @@ class Test {
// |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,
Expand Down
4 changes: 2 additions & 2 deletions libc/utils/UnitTest/StringUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
#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>

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');

Expand Down
2 changes: 1 addition & 1 deletion utils/bazel/llvm-project-overlay/libc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)
Expand Down