[PATCH] [libc++] Teach is_integral, is_[un]signed and make_[un]signed about __[u]int128_t

David Majnemer david.majnemer at gmail.com
Sun Mar 2 11:22:47 PST 2014


Per the cxx_status documentation:

"__int128 is not treated as an extended integer type, because changing
intmax_t would be an ABI-incompatible change."

With this in mind, I don't think it makes sense for these intrinsics to
accept __int128.

On Sunday, March 2, 2014, Stephan Tolksdorf <st at quanttec.com> wrote:

> Hi mclow.lists,
>
>
> I've added _LIBCPP_INT128 and _LIBCPP_UINT128 macros to __config to make
> it easy to support 128-bit integers that are not spelled __int128_t and
> __uint128_t.
>
> I was't sure whether the __SIZEOF_INT128__ check should be moved into the
> compiler-dependent sections of __config or not. AFAIK, 128-bit integer
> types are currently only supported by GCC-compatible compilers.
>
> http://llvm-reviews.chandlerc.com/D2917
>
> Files:
>   include/__config
>   include/type_traits
>   test/utilities/meta/meta.trans/meta.trans.sign/make_signed.pass.cpp
>   test/utilities/meta/meta.trans/meta.trans.sign/make_unsigned.pass.cpp
>   test/utilities/meta/meta.unary/meta.unary.cat/integral.pass.cpp
>   test/utilities/meta/meta.unary/meta.unary.comp/integral.pass.cpp
>   test/utilities/meta/meta.unary/meta.unary.prop/is_signed.pass.cpp
>   test/utilities/meta/meta.unary/meta.unary.prop/is_unsigned.pass.cpp
>
> Index: include/__config
> ===================================================================
> --- include/__config
> +++ include/__config
> @@ -485,6 +485,11 @@
>  typedef unsigned int   char32_t;
>  #endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
>
> +#ifdef __SIZEOF_INT128__
> +#define _LIBCPP_INT128   __int128_t
> +#define _LIBCPP_UINT128 __uint128_t
> +#endif
> +
>  #ifdef _LIBCPP_HAS_NO_STATIC_ASSERT
>
>  template <bool> struct __static_assert_test;
> Index: include/type_traits
> ===================================================================
> --- include/type_traits
> +++ include/type_traits
> @@ -324,6 +324,10 @@
>  template <>          struct __libcpp_is_integral<unsigned long>      :
> public true_type {};
>  template <>          struct __libcpp_is_integral<long long>          :
> public true_type {};
>  template <>          struct __libcpp_is_integral<unsigned long long> :
> public true_type {};
> +#ifdef _LIBCPP_INT128
> +template <>          struct __libcpp_is_integral<_LIBCPP_INT128>     :
> public true_type {};
> +template <>          struct __libcpp_is_integral<_LIBCPP_UINT128>    :
> public true_type {};
> +#endif
>
>  template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_integral
>      : public __libcpp_is_integral<typename remove_cv<_Tp>::type> {};
> @@ -1239,16 +1243,24 @@
>      __type_list<signed int,
>      __type_list<signed long,
>      __type_list<signed long long,
> +#ifdef _LIBCPP_INT128
> +    __type_list<_LIBCPP_INT128, __nat>
> +#else
>      __nat
> +#endif
>      > > > > > __signed_types;
>
>  typedef
>      __type_list<unsigned char,
>      __type_list<unsigned short,
>      __type_list<unsigned int,
>      __type_list<unsigned long,
>      __type_list<unsigned long long,
> +#ifdef _LIBCPP_UINT128
> +    __type_list<_LIBCPP_UINT128, __nat>
> +#else
>      __nat
> +#endif
>      > > > > > __unsigned_types;
>
>  template <class _TypeList, size_t _Size, bool = _Size <= sizeof(typename
> _TypeList::_Head)> struct __find_first;
> @@ -1332,6 +1344,10 @@
>  template <> struct __make_signed<unsigned long,      true> {typedef long
>      type;};
>  template <> struct __make_signed<  signed long long, true> {typedef long
> long type;};
>  template <> struct __make_signed<unsigned long long, true> {typedef long
> long type;};
> +#ifdef _LIBCPP_INT128
> +template <> struct __make_signed<_LIBCPP_INT128,     true> {typedef
> _LIBCPP_INT128 type;};
> +template <> struct __make_signed<_LIBCPP_UINT128,    true> {typedef
> _LIBCPP_INT128 type;};
> +#endif
>
>  template <class _Tp>
>  struct _LIBCPP_TYPE_VIS_ONLY make_signed
> @@ -1361,6 +1377,10 @@
>  template <> struct __make_unsigned<unsigned long,      true> {typedef
> unsigned long      type;};
>  template <> struct __make_unsigned<  signed long long, true> {typedef
> unsigned long long type;};
>  template <> struct __make_unsigned<unsigned long long, true> {typedef
> unsigned long long type;};
> +#ifdef _LIBCPP_INT128
> +template <> struct __make_unsigned<_LIBCPP_INT128,     true> {typedef
> _LIBCPP_UINT128    type;};
> +template <> struct __make_unsigned<_LIBCPP_UINT128,    true> {typedef
> _LIBCPP_UINT128    type;};
> +#endif
>
>  template <class _Tp>
>  struct _LIBCPP_TYPE_VIS_ONLY make_unsigned
> Index: test/utilities/meta/meta.trans/meta.trans.sign/make_signed.pass.cpp
> ===================================================================
> --- test/utilities/meta/meta.trans/meta.trans.sign/make_signed.pass.cpp
> +++ test/utilities/meta/meta.trans/meta.trans.sign/make_signed.pass.cpp
> @@ -21,6 +21,13 @@
>      big = 0xFFFFFFFFFFFFFFFFULL
>  };
>
> +#ifdef _LIBCPP_INT128
> +enum HugeEnum : _LIBCPP_UINT128
> +{
> +    hugezero
> +};
> +#endif
> +
>  template <class T, class U>
>  void test_make_signed()
>  {
> @@ -47,4 +54,9 @@
>      test_make_signed< const wchar_t, std::conditional<sizeof(wchar_t) ==
> 4, const int, const short>::type >();
>      test_make_signed< const Enum, const int >();
>      test_make_signed< BigEnum, std::conditional<sizeof(long) == 4, long
> long, long>::type >();
> +#ifdef _LIBCPP_INT128
> +    test_make_signed< _LIBCPP_INT128, _LIBCPP_INT128 >();
> +    test_make_signed< _LIBCPP_UINT128, _LIBCPP_INT128 >();
> +    test_make_signed< HugeEnum, _LIBCPP_INT128 >();
> +#endif
>  }
> Index:
> test/utilities/meta/meta.trans/meta.trans.sign/make_unsigned.pass.cpp
> ===================================================================
> --- test/utilities/meta/meta.trans/meta.trans.sign/make_unsigned.pass.cpp
> +++ test/utilities/meta/meta.trans/meta.trans.sign/make_unsigned.pass.cpp
> @@ -21,6 +21,13 @@
>      big = 0xFFFFFFFFFFFFFFFFULL
>  };
>
> +#ifdef _LIBCPP_INT128
> +enum HugeEnum : _LIBCPP_INT128
> +{
> +    hugezero
> +};
> +#endif
> +
>  template <class T, class U>
>  void test_make_unsigned()
>  {
> @@ -48,4 +55,9 @@
>      test_make_unsigned<const Enum, const unsigned int> ();
>      test_make_unsigned<BigEnum,
>                     std::conditional<sizeof(long) == 4, unsigned long
> long, unsigned long>::type> ();
> +#ifdef _LIBCPP_INT128
> +    test_make_unsigned<_LIBCPP_INT128, _LIBCPP_UINT128>();
> +    test_make_unsigned<_LIBCPP_UINT128, _LIBCPP_UINT128>();
> +    test_make_unsigned<HugeEnum, _LIBCPP_UINT128>();
> +#endif
>  }
> Index: test/utilities/meta/meta.unary/meta.unary.cat/integral.pass.cpp
> ===================================================================
> --- test/utilities/meta/meta.unary/meta.unary.cat/integral.pass.cpp
> +++ test/utilities/meta/meta.unary/meta.unary.cat/integral.pass.cpp
> @@ -58,4 +58,8 @@
>      test_integral<unsigned long>();
>      test_integral<long long>();
>      test_integral<unsigned long long>();
> +#ifdef _LIBCPP_INT128
> +    test_integral<_LIBCPP_INT128>();
> +    test_integral<_LIBCPP_UINT128>();
> +#endif
>  }
> Index: test/utilities/meta/meta.unary/meta.unary.comp/integral.pass.cpp
> ===================================================================
> --- test/utilities/meta/meta.unary/meta.unary.comp/integral.pass.cpp
> +++ test/utilities/meta/meta.unary/meta.unary.comp/integral.pass.cpp
> @@ -49,4 +49,8 @@
>      test_integral<unsigned long>();
>      test_integral<long long>();
>      test_integral<unsigned long long>();
> +#ifdef _LIBCPP_INT128
> +    test_integral<_LIBCPP_INT128>();
> +    test_integral<_LIBCPP_UINT128>();
> +#endif
>  }
> Index: test/utilities/meta/meta.unary/meta.unary.prop/is_signed.pass.cpp
> ===================================================================
> --- test/utilities/meta/meta.unary/meta.unary.prop/is_signed.pass.cpp
> +++ test/utilities/meta/meta.unary/meta.unary.prop/is_signed.pass.cpp
> @@ -51,4 +51,9 @@
>
>      test_is_signed<int>();
>      test_is_signed<double>();
> +
> +#ifdef _LIBCPP_INT128
> +    test_is_signed<_LIBCPP_INT128>();
> +    test_is_not_signed<_LIBCPP_UINT128>();
> +#endif
>  }
> Index: test/utilities/meta/meta.unary/meta.unary.prop/is_unsigned.pass.cpp
> ===================================================================
> --- test/utilities/meta/meta.unary/meta.unary.prop/is_unsigned.pass.cpp
> +++ test/utilities/meta/meta.unary/meta.unary.prop/is_unsigned.pass.cpp
> @@ -51,4 +51,9 @@
>
>      test_is_unsigned<bool>();
>      test_is_unsigned<unsigned>();
> +
> +#ifdef _LIBCPP_INT128
> +    test_is_unsigned<_LIBCPP_UINT128>();
> +    test_is_not_unsigned<_LIBCPP_INT128>();
> +#endif
>  }
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140302/4edf1470/attachment.html>


More information about the cfe-commits mailing list