[libc-commits] [libc] [libc] Make BigInt bit_cast-able to compatible types (PR #75063)

Guillaume Chatelet via libc-commits libc-commits at lists.llvm.org
Tue Dec 19 01:21:36 PST 2023


================
@@ -952,6 +952,35 @@ struct make_signed<UInt<Bits>> : type_identity<Int<Bits>> {
                 "Number of bits in Int should be a multiple of 64.");
 };
 
+namespace internal {
+template <typename T> struct is_custom_uint : cpp::false_type {};
+template <size_t Bits> struct is_custom_uint<UInt<Bits>> : cpp::true_type {};
+} // namespace internal
+
+// bit_cast to UInt
+template <typename To, typename From,
+          typename = cpp::enable_if_t<internal::is_custom_uint<To>::value>,
+          typename = cpp::enable_if_t<sizeof(To) == sizeof(From)>,
+          typename = cpp::enable_if_t<cpp::is_trivially_copyable<From>::value>>
----------------
gchatelet wrote:

For consistency with the original implementation
https://github.com/llvm/llvm-project/blob/41096d19ab07650747a434345842a9e55fa972d7/libc/src/__support/CPP/bit.h#L28-L36

Now we could also pack everything in a single condition for both implementations at the _cost_ of explicitly picking up a different type for `std::enable_if` (otherwise they would both resolve to `template <typename To, typename From, void>` and compiler would complain it can't choose between the two).

https://github.com/llvm/llvm-project/pull/75063


More information about the libc-commits mailing list