[libc] Add support for cpp::make_signed

This commit is contained in:
Guillaume Chatelet 2023-08-03 13:44:13 +00:00
parent eb2558c566
commit cdbc3ab7d6
2 changed files with 37 additions and 0 deletions

View File

@ -163,6 +163,25 @@ template <> struct make_unsigned<__uint128_t> : type_identity<__uint128_t> {};
#endif
template <typename T> using make_unsigned_t = typename make_unsigned<T>::type;
template <typename T> struct make_signed;
template <> struct make_signed<char> : type_identity<char> {};
template <> struct make_signed<signed char> : type_identity<char> {};
template <> struct make_signed<short> : type_identity<short> {};
template <> struct make_signed<int> : type_identity<int> {};
template <> struct make_signed<long> : type_identity<long> {};
template <> struct make_signed<long long> : type_identity<long long> {};
template <> struct make_signed<unsigned char> : type_identity<char> {};
template <> struct make_signed<unsigned short> : type_identity<short> {};
template <> struct make_signed<unsigned int> : type_identity<int> {};
template <> struct make_signed<unsigned long> : type_identity<long> {};
template <>
struct make_signed<unsigned long long> : type_identity<long long> {};
#ifdef __SIZEOF_INT128__
template <> struct make_signed<__int128_t> : type_identity<__int128_t> {};
template <> struct make_signed<__uint128_t> : type_identity<__int128_t> {};
#endif
template <typename T> using make_signed_t = typename make_signed<T>::type;
// Compile time type selection.
template <bool B, typename T, typename F>
struct conditional : type_identity<T> {};

View File

@ -909,6 +909,24 @@ struct make_unsigned<Int<Bits>> : type_identity<UInt<Bits>> {
"Number of bits in Int should be a multiple of 64.");
};
template <size_t Bits>
struct make_unsigned<UInt<Bits>> : type_identity<UInt<Bits>> {
static_assert(Bits > 0 && Bits % 64 == 0,
"Number of bits in Int should be a multiple of 64.");
};
template <size_t Bits>
struct make_signed<Int<Bits>> : type_identity<Int<Bits>> {
static_assert(Bits > 0 && Bits % 64 == 0,
"Number of bits in Int should be a multiple of 64.");
};
template <size_t Bits>
struct make_signed<UInt<Bits>> : type_identity<Int<Bits>> {
static_assert(Bits > 0 && Bits % 64 == 0,
"Number of bits in Int should be a multiple of 64.");
};
} // namespace __llvm_libc::cpp
#endif // LLVM_LIBC_SRC_SUPPORT_UINT_H