Skip to content

Commit 4658d6e

Browse files
committed
fixed __int48 and std::bit
1 parent dd7b013 commit 4658d6e

File tree

15 files changed

+152
-18
lines changed

15 files changed

+152
-18
lines changed

src/libcxx/include/__bit/bit_ceil.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
#include <__concepts/arithmetic.h>
1515
#include <__config>
1616
#include <limits>
17+
#ifdef _EZ80
18+
#include <__bit/bit_width.h>
19+
#endif // _EZ80
1720

1821
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1922
# pragma GCC system_header
@@ -23,6 +26,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2326

2427
#if _LIBCPP_STD_VER >= 20
2528

29+
#ifndef _EZ80
30+
2631
template <__libcpp_unsigned_integer _Tp>
2732
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Tp bit_ceil(_Tp __t) noexcept {
2833
if (__t < 2)
@@ -39,6 +44,43 @@ _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Tp bit_ceil(_Tp __t) noex
3944
}
4045
}
4146

47+
#else // _EZ80
48+
49+
template<class _Tp> _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr
50+
_Tp bit_ceil(_Tp __t) noexcept;
51+
52+
template <> _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr
53+
unsigned char bit_ceil(unsigned char __t) noexcept {
54+
return ((__t < 2) ? 1 : (static_cast<unsigned char>(2) << (bit_width<unsigned char>(__t - 1) - 1)));
55+
}
56+
57+
template <> _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr
58+
unsigned short bit_ceil(unsigned short __t) noexcept {
59+
return ((__t < 2) ? 1 : (static_cast<unsigned short>(2) << (bit_width<unsigned short>(__t - 1) - 1)));
60+
}
61+
62+
template <> _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr
63+
unsigned int bit_ceil(unsigned int __t) noexcept {
64+
return ((__t < 2) ? 1 : (static_cast<unsigned int>(2) << (bit_width<unsigned int>(__t - 1) - 1)));
65+
}
66+
67+
template <> _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr
68+
unsigned long bit_ceil(unsigned long __t) noexcept {
69+
return ((__t < 2) ? 1 : (static_cast<unsigned long>(2) << (bit_width<unsigned long>(__t - 1) - 1)));
70+
}
71+
72+
template <> _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr
73+
unsigned __int48 bit_ceil(unsigned __int48 __t) noexcept {
74+
return ((__t < 2) ? 1 : (static_cast<unsigned __int48>(2) << (bit_width<unsigned __int48>(__t - 1) - 1)));
75+
}
76+
77+
template <> _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr
78+
unsigned long long bit_ceil(unsigned long long __t) noexcept {
79+
return ((__t < 2) ? 1 : (static_cast<unsigned long long>(2) << (bit_width<unsigned long long>(__t - 1) - 1)));
80+
}
81+
82+
#endif // _EZ80
83+
4284
#endif // _LIBCPP_STD_VER >= 20
4385

4486
_LIBCPP_END_NAMESPACE_STD

src/libcxx/include/__bit/blsr.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unsigned long __libcpp_blsr(u
2525
return __x ^ (__x & -__x);
2626
}
2727

28+
#ifdef _EZ80
29+
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unsigned __int48 __libcpp_blsr(unsigned __int48 __x) _NOEXCEPT {
30+
return __x ^ (__x & -__x);
31+
}
32+
#endif // _EZ80
33+
2834
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unsigned long long __libcpp_blsr(unsigned long long __x) _NOEXCEPT {
2935
return __x ^ (__x & -__x);
3036
}

src/libcxx/include/__bit/byteswap.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,42 @@
1414
#include <__config>
1515
#include <cstdint>
1616

17+
#ifdef _EZ80
18+
#include <__type_traits/enable_if.h>
19+
#include <__type_traits/is_integral.h>
20+
#include <ez80_builtin.h>
21+
#endif // _EZ80
22+
1723
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1824
# pragma GCC system_header
1925
#endif
2026

2127
_LIBCPP_BEGIN_NAMESPACE_STD
2228

29+
#if defined(_EZ80) && _LIBCPP_STD_VER >= 20
30+
31+
template <integral _Tp>
32+
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Tp byteswap(_Tp __val) noexcept {
33+
34+
if constexpr (sizeof(_Tp) == 1) {
35+
return __val;
36+
} else if constexpr (sizeof(_Tp) == 2) {
37+
return __builtin_bswap16(__val);
38+
} else if constexpr (sizeof(_Tp) == 3) {
39+
return __ez80_bswap24(__val);
40+
} else if constexpr (sizeof(_Tp) == 4) {
41+
return __builtin_bswap32(__val);
42+
} else if constexpr (sizeof(_Tp) == 6) {
43+
return __ez80_bswap48(__val);
44+
} else if constexpr (sizeof(_Tp) == 8) {
45+
return __builtin_bswap64(__val);
46+
} else {
47+
static_assert(sizeof(_Tp) == 0, "byteswap is unimplemented for integral types of this size");
48+
}
49+
}
50+
51+
#else // _EZ80
52+
2353
#if _LIBCPP_STD_VER >= 23
2454

2555
template <integral _Tp>
@@ -49,6 +79,8 @@ _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Tp byteswap(_Tp __val) no
4979

5080
#endif // _LIBCPP_STD_VER >= 23
5181

82+
#endif // _EZ80
83+
5284
_LIBCPP_END_NAMESPACE_STD
5385

5486
#endif // _LIBCPP___BIT_BYTESWAP_H

src/libcxx/include/__bit/rotate.h

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,30 @@
2020

2121
_LIBCPP_BEGIN_NAMESPACE_STD
2222

23-
template<class _Tp>
24-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
25-
_Tp __rotr(_Tp __t, unsigned int __cnt) _NOEXCEPT
26-
{
27-
static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__rotr requires an unsigned integer type");
28-
const unsigned int __dig = numeric_limits<_Tp>::digits;
29-
if ((__cnt % __dig) == 0)
30-
return __t;
31-
return (__t >> (__cnt % __dig)) | (__t << (__dig - (__cnt % __dig)));
23+
template <class _Tp>
24+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp __rotr(_Tp __t, int __cnt) _NOEXCEPT {
25+
static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__rotr requires an unsigned integer type");
26+
const unsigned int __dig = numeric_limits<_Tp>::digits;
27+
if ((__cnt % __dig) == 0)
28+
return __t;
29+
30+
if (__cnt < 0) {
31+
__cnt *= -1;
32+
return (__t << (__cnt % __dig)) | (__t >> (__dig - (__cnt % __dig))); // rotr with negative __cnt is similar to rotl
33+
}
34+
35+
return (__t >> (__cnt % __dig)) | (__t << (__dig - (__cnt % __dig)));
3236
}
3337

3438
#if _LIBCPP_STD_VER >= 20
3539

3640
template <__libcpp_unsigned_integer _Tp>
37-
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp rotl(_Tp __t, unsigned int __cnt) noexcept {
38-
const unsigned int __dig = numeric_limits<_Tp>::digits;
39-
if ((__cnt % __dig) == 0)
40-
return __t;
41-
return (__t << (__cnt % __dig)) | (__t >> (__dig - (__cnt % __dig)));
41+
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp rotl(_Tp __t, int __cnt) noexcept {
42+
return std::__rotr(__t, -__cnt);
4243
}
4344

4445
template <__libcpp_unsigned_integer _Tp>
45-
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp rotr(_Tp __t, unsigned int __cnt) noexcept {
46+
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp rotr(_Tp __t, int __cnt) noexcept {
4647
return std::__rotr(__t, __cnt);
4748
}
4849

src/libcxx/include/__random/is_valid.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ template<> struct __libcpp_random_is_valid_inttype<unsigned int> : true_type {};
4141
template<> struct __libcpp_random_is_valid_inttype<unsigned long> : true_type {};
4242
template<> struct __libcpp_random_is_valid_inttype<unsigned long long> : true_type {};
4343

44+
#ifdef _EZ80
45+
template<> struct __libcpp_random_is_valid_inttype<signed __int48> : true_type {}; // extension
46+
template<> struct __libcpp_random_is_valid_inttype<unsigned __int48> : true_type {}; // extension
47+
#endif // _EZ80
48+
4449
#ifndef _LIBCPP_HAS_NO_INT128
4550
template<> struct __libcpp_random_is_valid_inttype<__int128_t> : true_type {}; // extension
4651
template<> struct __libcpp_random_is_valid_inttype<__uint128_t> : true_type {}; // extension

src/libcxx/include/__type_traits/is_integral.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ template <> struct __libcpp_is_integral<int> { enum { va
3939
template <> struct __libcpp_is_integral<unsigned int> { enum { value = 1 }; };
4040
template <> struct __libcpp_is_integral<long> { enum { value = 1 }; };
4141
template <> struct __libcpp_is_integral<unsigned long> { enum { value = 1 }; };
42+
#ifdef _EZ80
43+
template <> struct __libcpp_is_integral<signed __int48> { enum { value = 1 }; };
44+
template <> struct __libcpp_is_integral<unsigned __int48> { enum { value = 1 }; };
45+
#endif // _EZ80
4246
template <> struct __libcpp_is_integral<long long> { enum { value = 1 }; };
4347
template <> struct __libcpp_is_integral<unsigned long long> { enum { value = 1 }; };
4448
#ifndef _LIBCPP_HAS_NO_INT128

src/libcxx/include/__type_traits/is_signed_integer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ template <class _Tp> struct __libcpp_is_signed_integer : publi
2323
template <> struct __libcpp_is_signed_integer<signed char> : public true_type {};
2424
template <> struct __libcpp_is_signed_integer<signed short> : public true_type {};
2525
template <> struct __libcpp_is_signed_integer<signed int> : public true_type {};
26+
#ifdef _EZ80
27+
template <> struct __libcpp_is_signed_integer<signed __int48> : public true_type {};
28+
#endif // _EZ80
2629
template <> struct __libcpp_is_signed_integer<signed long> : public true_type {};
2730
template <> struct __libcpp_is_signed_integer<signed long long> : public true_type {};
2831
#ifndef _LIBCPP_HAS_NO_INT128

src/libcxx/include/__type_traits/is_unsigned_integer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ template <> struct __libcpp_is_unsigned_integer<unsigned char> : p
2424
template <> struct __libcpp_is_unsigned_integer<unsigned short> : public true_type {};
2525
template <> struct __libcpp_is_unsigned_integer<unsigned int> : public true_type {};
2626
template <> struct __libcpp_is_unsigned_integer<unsigned long> : public true_type {};
27+
#ifdef _EZ80
28+
template <> struct __libcpp_is_unsigned_integer<unsigned __int48> : public true_type {};
29+
#endif // _EZ80
2730
template <> struct __libcpp_is_unsigned_integer<unsigned long long> : public true_type {};
2831
#ifndef _LIBCPP_HAS_NO_INT128
2932
template <> struct __libcpp_is_unsigned_integer<__uint128_t> : public true_type {};

src/libcxx/include/__type_traits/make_signed.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,17 @@ typedef __type_list<signed char,
3434
__type_list<signed short,
3535
__type_list<signed int,
3636
__type_list<signed long,
37+
# ifdef _EZ80
38+
__type_list<signed __int48,
39+
# endif // _EZ80
3740
__type_list<signed long long,
3841
# ifndef _LIBCPP_HAS_NO_INT128
3942
__type_list<__int128_t,
4043
# endif
4144
__nat
45+
# ifdef _EZ80
46+
>
47+
# endif // _EZ80
4248
# ifndef _LIBCPP_HAS_NO_INT128
4349
>
4450
# endif
@@ -61,6 +67,10 @@ template <> struct __make_signed< signed int, true> {typedef int ty
6167
template <> struct __make_signed<unsigned int, true> {typedef int type;};
6268
template <> struct __make_signed< signed long, true> {typedef long type;};
6369
template <> struct __make_signed<unsigned long, true> {typedef long type;};
70+
#ifdef _EZ80
71+
template <> struct __make_signed< signed __int48, true> {typedef signed __int48 type;};
72+
template <> struct __make_signed<unsigned __int48, true> {typedef signed __int48 type;};
73+
#endif // _EZ80
6474
template <> struct __make_signed< signed long long, true> {typedef long long type;};
6575
template <> struct __make_signed<unsigned long long, true> {typedef long long type;};
6676
# ifndef _LIBCPP_HAS_NO_INT128

src/libcxx/include/__type_traits/make_unsigned.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,17 @@ typedef __type_list<unsigned char,
3636
__type_list<unsigned short,
3737
__type_list<unsigned int,
3838
__type_list<unsigned long,
39+
# ifdef _EZ80
40+
__type_list<unsigned __int48,
41+
# endif // _EZ80
3942
__type_list<unsigned long long,
4043
# ifndef _LIBCPP_HAS_NO_INT128
4144
__type_list<__uint128_t,
4245
# endif
4346
__nat
47+
# ifdef _EZ80
48+
>
49+
# endif // _EZ80
4450
# ifndef _LIBCPP_HAS_NO_INT128
4551
>
4652
# endif
@@ -63,6 +69,10 @@ template <> struct __make_unsigned< signed int, true> {typedef unsigned i
6369
template <> struct __make_unsigned<unsigned int, true> {typedef unsigned int type;};
6470
template <> struct __make_unsigned< signed long, true> {typedef unsigned long type;};
6571
template <> struct __make_unsigned<unsigned long, true> {typedef unsigned long type;};
72+
#ifdef _EZ80
73+
template <> struct __make_unsigned< signed __int48, true> {typedef unsigned __int48 type;};
74+
template <> struct __make_unsigned<unsigned __int48, true> {typedef unsigned __int48 type;};
75+
#endif // _EZ80
6676
template <> struct __make_unsigned< signed long long, true> {typedef unsigned long long type;};
6777
template <> struct __make_unsigned<unsigned long long, true> {typedef unsigned long long type;};
6878
# ifndef _LIBCPP_HAS_NO_INT128

0 commit comments

Comments
 (0)