From ce5196e19fc3f0eba5dd6ea24bf9c5ac6e5a22ea Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Sat, 11 Mar 2023 11:49:31 +0800 Subject: [PATCH 01/35] more operator of int128 --- stl/inc/__msvc_int128.hpp | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/stl/inc/__msvc_int128.hpp b/stl/inc/__msvc_int128.hpp index d0bb3167b3e..13789be8efb 100644 --- a/stl/inc/__msvc_int128.hpp +++ b/stl/inc/__msvc_int128.hpp @@ -793,6 +793,12 @@ struct _Unsigned128 : _Base128 { return *this; } + _TEMPLATE_CLASS_INTEGRAL(_Ty) + _NODISCARD_FRIEND constexpr _Ty operator>>(_Ty _Left, const _Unsigned128& _Right) noexcept { + _Left >>= _Right._Word[0]; + return _Left; + } + constexpr _Unsigned128& operator++() noexcept { if (++_Word[0] == 0) { ++_Word[1]; @@ -934,6 +940,13 @@ struct _Unsigned128 : _Base128 { _NODISCARD_FRIEND constexpr _Unsigned128 operator%(const _Base128& _Num, const _Base128& _Den) noexcept { return _Unsigned128{_Base128::_Modulo(_Num, _Den)}; } + _TEMPLATE_CLASS_INTEGRAL(_Ty) + _NODISCARD_FRIEND constexpr _Ty operator%(_Ty _Left, const _Unsigned128& _Right) noexcept { + if (_Right._Word[1] == 0) { + _Left %= _Right._Word[0]; + } + return _Left; + } _TEMPLATE_CLASS_INTEGRAL(_Ty) constexpr _Unsigned128& operator%=(const _Ty _Den) noexcept { @@ -981,6 +994,15 @@ struct _Unsigned128 : _Base128 { _Word[1] |= _That._Word[1]; return *this; } + + _NODISCARD constexpr explicit operator bool() const noexcept { + return _Word[0] != 0 || _Word[1] != 0; + } + + //for static_cast + _NODISCARD constexpr explicit operator double() const noexcept { + return static_cast(_Word[1]) * 18446744073709551616.0 + static_cast(_Word[0]); + } }; template <> @@ -1318,6 +1340,10 @@ struct _Signed128 : _Base128 { _NODISCARD_FRIEND constexpr _Signed128 operator%(_Signed128 _Left, const _Ty _Right) noexcept { return _Left % _Signed128{_Right}; } + _TEMPLATE_CLASS_INTEGRAL(_Ty) + _NODISCARD_FRIEND constexpr _Ty operator%(_Ty _Left, const _Signed128& _Right) noexcept { + return static_cast<_Ty>(_Signed128{_Left} % _Right); + } _TEMPLATE_CLASS_INTEGRAL(_Ty) constexpr _Signed128& operator%=(const _Ty _That) noexcept { @@ -1367,6 +1393,20 @@ struct _Signed128 : _Base128 { _Word[1] |= _That._Word[1]; return *this; } + + _TEMPLATE_CLASS_INTEGRAL(_Ty) + _NODISCARD_FRIEND constexpr _Ty operator>>(_Ty _Left, const _Signed128& _Right) noexcept { + return static_cast<_Ty>(_Signed128{_Left} >> _Right); + } + + _NODISCARD constexpr explicit operator bool() const noexcept { + return _Word[0] != 0 || _Word[1] != 0; + } + + //for static_cast + _NODISCARD constexpr explicit operator double() const noexcept { + return static_cast(_Word[1]) * 18446744073709551616.0 + static_cast(_Word[0]); + } }; template <> From 2e8b843c71e03f99efdb013e11964b0c1f68315d Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Sat, 11 Mar 2023 14:18:44 +0800 Subject: [PATCH 02/35] remove operator bool and template operator float_T --- stl/inc/__msvc_int128.hpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/stl/inc/__msvc_int128.hpp b/stl/inc/__msvc_int128.hpp index 13789be8efb..569a1daf2f8 100644 --- a/stl/inc/__msvc_int128.hpp +++ b/stl/inc/__msvc_int128.hpp @@ -995,13 +995,12 @@ struct _Unsigned128 : _Base128 { return *this; } - _NODISCARD constexpr explicit operator bool() const noexcept { - return _Word[0] != 0 || _Word[1] != 0; + _NODISCARD constexpr explicit operator long double() const noexcept { + return static_cast(_Word[1]) * 18446744073709551616.0 + static_cast(_Word[0]); } - - //for static_cast - _NODISCARD constexpr explicit operator double() const noexcept { - return static_cast(_Word[1]) * 18446744073709551616.0 + static_cast(_Word[0]); + template , int> = 0> + _NODISCARD constexpr explicit operator _Ty() const noexcept { + return static_cast<_Ty>(static_cast(*this)); } }; @@ -1399,13 +1398,12 @@ struct _Signed128 : _Base128 { return static_cast<_Ty>(_Signed128{_Left} >> _Right); } - _NODISCARD constexpr explicit operator bool() const noexcept { - return _Word[0] != 0 || _Word[1] != 0; + _NODISCARD constexpr explicit operator long double() const noexcept { + return static_cast(_Word[1]) * 18446744073709551616.0 + static_cast(_Word[0]); } - - //for static_cast - _NODISCARD constexpr explicit operator double() const noexcept { - return static_cast(_Word[1]) * 18446744073709551616.0 + static_cast(_Word[0]); + template , int> = 0> + _NODISCARD constexpr explicit operator _Ty() const noexcept { + return static_cast<_Ty>(static_cast(*this)); } }; From faec74d51a08d54f76deb232d703afdce76ab582 Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Sat, 11 Mar 2023 14:28:56 +0800 Subject: [PATCH 03/35] remove operators --- stl/inc/__msvc_int128.hpp | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/stl/inc/__msvc_int128.hpp b/stl/inc/__msvc_int128.hpp index 569a1daf2f8..f7de009802a 100644 --- a/stl/inc/__msvc_int128.hpp +++ b/stl/inc/__msvc_int128.hpp @@ -793,12 +793,6 @@ struct _Unsigned128 : _Base128 { return *this; } - _TEMPLATE_CLASS_INTEGRAL(_Ty) - _NODISCARD_FRIEND constexpr _Ty operator>>(_Ty _Left, const _Unsigned128& _Right) noexcept { - _Left >>= _Right._Word[0]; - return _Left; - } - constexpr _Unsigned128& operator++() noexcept { if (++_Word[0] == 0) { ++_Word[1]; @@ -940,13 +934,6 @@ struct _Unsigned128 : _Base128 { _NODISCARD_FRIEND constexpr _Unsigned128 operator%(const _Base128& _Num, const _Base128& _Den) noexcept { return _Unsigned128{_Base128::_Modulo(_Num, _Den)}; } - _TEMPLATE_CLASS_INTEGRAL(_Ty) - _NODISCARD_FRIEND constexpr _Ty operator%(_Ty _Left, const _Unsigned128& _Right) noexcept { - if (_Right._Word[1] == 0) { - _Left %= _Right._Word[0]; - } - return _Left; - } _TEMPLATE_CLASS_INTEGRAL(_Ty) constexpr _Unsigned128& operator%=(const _Ty _Den) noexcept { @@ -1339,10 +1326,6 @@ struct _Signed128 : _Base128 { _NODISCARD_FRIEND constexpr _Signed128 operator%(_Signed128 _Left, const _Ty _Right) noexcept { return _Left % _Signed128{_Right}; } - _TEMPLATE_CLASS_INTEGRAL(_Ty) - _NODISCARD_FRIEND constexpr _Ty operator%(_Ty _Left, const _Signed128& _Right) noexcept { - return static_cast<_Ty>(_Signed128{_Left} % _Right); - } _TEMPLATE_CLASS_INTEGRAL(_Ty) constexpr _Signed128& operator%=(const _Ty _That) noexcept { @@ -1393,11 +1376,6 @@ struct _Signed128 : _Base128 { return *this; } - _TEMPLATE_CLASS_INTEGRAL(_Ty) - _NODISCARD_FRIEND constexpr _Ty operator>>(_Ty _Left, const _Signed128& _Right) noexcept { - return static_cast<_Ty>(_Signed128{_Left} >> _Right); - } - _NODISCARD constexpr explicit operator long double() const noexcept { return static_cast(_Word[1]) * 18446744073709551616.0 + static_cast(_Word[0]); } From 636907b6f17a20b015e53add248f36907b3cbeb4 Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Sat, 11 Mar 2023 14:33:58 +0800 Subject: [PATCH 04/35] fix negative --- stl/inc/__msvc_int128.hpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/stl/inc/__msvc_int128.hpp b/stl/inc/__msvc_int128.hpp index f7de009802a..6e104188a4e 100644 --- a/stl/inc/__msvc_int128.hpp +++ b/stl/inc/__msvc_int128.hpp @@ -1377,7 +1377,14 @@ struct _Signed128 : _Base128 { } _NODISCARD constexpr explicit operator long double() const noexcept { - return static_cast(_Word[1]) * 18446744073709551616.0 + static_cast(_Word[0]); + bool _Negative = false; + _Signed128 _Copy{*this}; + _Copy._Strip_negative(_Negative); + long double _Result = static_cast(_Copy._Word[0]) + static_cast(_Copy._Word[1]) * 18446744073709551616.0; + if (_Negative) { + _Result = -_Result; + } + return _Result; } template , int> = 0> _NODISCARD constexpr explicit operator _Ty() const noexcept { From 165b493051eb86fcfc08cfc838de2af724cfe36e Mon Sep 17 00:00:00 2001 From: steve green Date: Sat, 11 Mar 2023 14:59:24 +0800 Subject: [PATCH 05/35] Update stl/inc/__msvc_int128.hpp Co-authored-by: A. Jiang --- stl/inc/__msvc_int128.hpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/stl/inc/__msvc_int128.hpp b/stl/inc/__msvc_int128.hpp index 6e104188a4e..6255f9c8618 100644 --- a/stl/inc/__msvc_int128.hpp +++ b/stl/inc/__msvc_int128.hpp @@ -982,12 +982,9 @@ struct _Unsigned128 : _Base128 { return *this; } - _NODISCARD constexpr explicit operator long double() const noexcept { - return static_cast(_Word[1]) * 18446744073709551616.0 + static_cast(_Word[0]); - } template , int> = 0> _NODISCARD constexpr explicit operator _Ty() const noexcept { - return static_cast<_Ty>(static_cast(*this)); + return static_cast<_Ty>(_Word[1]) * static_cast<_Ty>(18446744073709551616.0) + static_cast<_Ty>(_Word[0]); } }; From 22a03832097ae65866f74055f841be5162dccdde Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Sat, 11 Mar 2023 15:05:59 +0800 Subject: [PATCH 06/35] Update __msvc_int128.hpp --- stl/inc/__msvc_int128.hpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/stl/inc/__msvc_int128.hpp b/stl/inc/__msvc_int128.hpp index 6255f9c8618..cd13f84d9db 100644 --- a/stl/inc/__msvc_int128.hpp +++ b/stl/inc/__msvc_int128.hpp @@ -1373,19 +1373,12 @@ struct _Signed128 : _Base128 { return *this; } - _NODISCARD constexpr explicit operator long double() const noexcept { - bool _Negative = false; - _Signed128 _Copy{*this}; - _Copy._Strip_negative(_Negative); - long double _Result = static_cast(_Copy._Word[0]) + static_cast(_Copy._Word[1]) * 18446744073709551616.0; - if (_Negative) { - _Result = -_Result; - } - return _Result; - } template , int> = 0> _NODISCARD constexpr explicit operator _Ty() const noexcept { - return static_cast<_Ty>(static_cast(*this)); + bool _Negative = int64_t(_Word[1]) < 0; + _Unsigned128 _Abs = static_cast<_Unsigned128>(*this); + auto _Result = static_cast<_Ty>(_Abs); + return _Negative ? -_Result : _Result; } }; From 7f9e7b32cf51366239a78e5e3015f999a6cce398 Mon Sep 17 00:00:00 2001 From: steve green Date: Sat, 11 Mar 2023 15:15:01 +0800 Subject: [PATCH 07/35] fromat Co-authored-by: Igor Zhukov --- stl/inc/__msvc_int128.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stl/inc/__msvc_int128.hpp b/stl/inc/__msvc_int128.hpp index cd13f84d9db..fd413073a7e 100644 --- a/stl/inc/__msvc_int128.hpp +++ b/stl/inc/__msvc_int128.hpp @@ -1375,9 +1375,9 @@ struct _Signed128 : _Base128 { template , int> = 0> _NODISCARD constexpr explicit operator _Ty() const noexcept { - bool _Negative = int64_t(_Word[1]) < 0; + bool _Negative = int64_t(_Word[1]) < 0; _Unsigned128 _Abs = static_cast<_Unsigned128>(*this); - auto _Result = static_cast<_Ty>(_Abs); + auto _Result = static_cast<_Ty>(_Abs); return _Negative ? -_Result : _Result; } }; From 0cbc6103b7f37972cce59c4cfeecdf8b07a474bd Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Sat, 11 Mar 2023 15:36:54 +0800 Subject: [PATCH 08/35] fixof cast --- stl/inc/__msvc_int128.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/__msvc_int128.hpp b/stl/inc/__msvc_int128.hpp index fd413073a7e..2876d560658 100644 --- a/stl/inc/__msvc_int128.hpp +++ b/stl/inc/__msvc_int128.hpp @@ -1376,7 +1376,7 @@ struct _Signed128 : _Base128 { template , int> = 0> _NODISCARD constexpr explicit operator _Ty() const noexcept { bool _Negative = int64_t(_Word[1]) < 0; - _Unsigned128 _Abs = static_cast<_Unsigned128>(*this); + _Unsigned128 _Abs {_Word[0],abs(int64_t(_Word[1]))}; auto _Result = static_cast<_Ty>(_Abs); return _Negative ? -_Result : _Result; } From d374ebfc9d571f3d850283f9cd25330837f087c7 Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Sat, 11 Mar 2023 15:46:08 +0800 Subject: [PATCH 09/35] is_integral & is_arithmetic of int128 --- stl/inc/xtr1common | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/stl/inc/xtr1common b/stl/inc/xtr1common index f646d9625da..35ddaf0dd13 100644 --- a/stl/inc/xtr1common +++ b/stl/inc/xtr1common @@ -175,13 +175,18 @@ _EXPORT_STD _NODISCARD constexpr bool is_constant_evaluated() noexcept { } #endif // _HAS_CXX20 +struct _Signed128; +struct _Unsigned128; + _EXPORT_STD template _INLINE_VAR constexpr bool is_integral_v = _Is_any_of_v, bool, char, signed char, unsigned char, wchar_t, #ifdef __cpp_char8_t char8_t, #endif // __cpp_char8_t - char16_t, char32_t, short, unsigned short, int, unsigned int, long, unsigned long, long long, unsigned long long>; + char16_t, char32_t, short, unsigned short, int, unsigned int, long, unsigned long, long long, unsigned long long, + _Signed128, _Unsigned128 +>; _EXPORT_STD template struct is_integral : bool_constant> {}; From 8128a52b4f984da4fdf81b9e002874fdb581c9fe Mon Sep 17 00:00:00 2001 From: steve green Date: Sat, 11 Mar 2023 16:03:54 +0800 Subject: [PATCH 10/35] format Co-authored-by: Igor Zhukov --- stl/inc/__msvc_int128.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stl/inc/__msvc_int128.hpp b/stl/inc/__msvc_int128.hpp index 2876d560658..b9be6675db4 100644 --- a/stl/inc/__msvc_int128.hpp +++ b/stl/inc/__msvc_int128.hpp @@ -1375,9 +1375,9 @@ struct _Signed128 : _Base128 { template , int> = 0> _NODISCARD constexpr explicit operator _Ty() const noexcept { - bool _Negative = int64_t(_Word[1]) < 0; - _Unsigned128 _Abs {_Word[0],abs(int64_t(_Word[1]))}; - auto _Result = static_cast<_Ty>(_Abs); + bool _Negative = int64_t(_Word[1]) < 0; + _Unsigned128 _Abs{_Word[0], abs(int64_t(_Word[1]))}; + auto _Result = static_cast<_Ty>(_Abs); return _Negative ? -_Result : _Result; } }; From 85d42297b4bf3a1ea33554361e29da350ff29e37 Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Sat, 11 Mar 2023 16:11:23 +0800 Subject: [PATCH 11/35] float to int128 --- stl/inc/__msvc_int128.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/stl/inc/__msvc_int128.hpp b/stl/inc/__msvc_int128.hpp index b9be6675db4..401d22b91e1 100644 --- a/stl/inc/__msvc_int128.hpp +++ b/stl/inc/__msvc_int128.hpp @@ -986,6 +986,12 @@ struct _Unsigned128 : _Base128 { _NODISCARD constexpr explicit operator _Ty() const noexcept { return static_cast<_Ty>(_Word[1]) * static_cast<_Ty>(18446744073709551616.0) + static_cast<_Ty>(_Word[0]); } + + template , int> = 0> + constexpr explicit _Unsigned128(const _Ty _Val) noexcept { + _Word[0] = static_cast(_Val); + _Word[1] = static_cast(_Val / static_cast<_Ty>(18446744073709551616.0)); + } }; template <> @@ -1380,6 +1386,11 @@ struct _Signed128 : _Base128 { auto _Result = static_cast<_Ty>(_Abs); return _Negative ? -_Result : _Result; } + template , int> = 0> + constexpr explicit _Signed128(const _Ty _Val) noexcept { + _Word[0] = static_cast(_Val); + _Word[1] = static_cast(_Val / static_cast<_Ty>(18446744073709551616.0)); + } }; template <> From 71fd942e3c5a6748f990c6b8fcfad23d76083c46 Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Sat, 11 Mar 2023 16:12:29 +0800 Subject: [PATCH 12/35] format --- stl/inc/xtr1common | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/stl/inc/xtr1common b/stl/inc/xtr1common index 35ddaf0dd13..d0b14e8aff2 100644 --- a/stl/inc/xtr1common +++ b/stl/inc/xtr1common @@ -179,14 +179,13 @@ struct _Signed128; struct _Unsigned128; _EXPORT_STD template -_INLINE_VAR constexpr bool is_integral_v = _Is_any_of_v, bool, char, signed char, unsigned char, - wchar_t, +_INLINE_VAR constexpr bool is_integral_v = + _Is_any_of_v, bool, char, signed char, unsigned char, wchar_t, #ifdef __cpp_char8_t - char8_t, + char8_t, #endif // __cpp_char8_t - char16_t, char32_t, short, unsigned short, int, unsigned int, long, unsigned long, long long, unsigned long long, - _Signed128, _Unsigned128 ->; + char16_t, char32_t, short, unsigned short, int, unsigned int, long, unsigned long, long long, + unsigned long long, _Signed128, _Unsigned128>; _EXPORT_STD template struct is_integral : bool_constant> {}; From 6de8a8eefde1df927a2095cbf8deb052f81b6ac0 Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Sat, 11 Mar 2023 16:18:01 +0800 Subject: [PATCH 13/35] fix of float2signed128 --- stl/inc/__msvc_int128.hpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/stl/inc/__msvc_int128.hpp b/stl/inc/__msvc_int128.hpp index 401d22b91e1..456e66acecc 100644 --- a/stl/inc/__msvc_int128.hpp +++ b/stl/inc/__msvc_int128.hpp @@ -1382,14 +1382,19 @@ struct _Signed128 : _Base128 { template , int> = 0> _NODISCARD constexpr explicit operator _Ty() const noexcept { bool _Negative = int64_t(_Word[1]) < 0; - _Unsigned128 _Abs{_Word[0], abs(int64_t(_Word[1]))}; + const _Unsigned128 _Abs{_Word[0], abs(int64_t(_Word[1]))}; auto _Result = static_cast<_Ty>(_Abs); return _Negative ? -_Result : _Result; } template , int> = 0> constexpr explicit _Signed128(const _Ty _Val) noexcept { - _Word[0] = static_cast(_Val); - _Word[1] = static_cast(_Val / static_cast<_Ty>(18446744073709551616.0)); + const bool _Negative = _Val < 0; + const _Ty _Absval = _Negative ? -_Val : _Val; + _Word[0] = static_cast(_Absval); + _Word[1] = static_cast(_Absval / static_cast<_Ty>(18446744073709551616.0)); + if (_Negative) { + _Word[1] |= 1ull << 63; + } } }; From 96a6c6886cdcad1e3fe20c7259e0325d50e47c5c Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Sat, 11 Mar 2023 16:21:33 +0800 Subject: [PATCH 14/35] looks like int128 can't cast to size_t, idk why --- stl/inc/__msvc_int128.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/stl/inc/__msvc_int128.hpp b/stl/inc/__msvc_int128.hpp index 456e66acecc..88fbba9437e 100644 --- a/stl/inc/__msvc_int128.hpp +++ b/stl/inc/__msvc_int128.hpp @@ -992,6 +992,10 @@ struct _Unsigned128 : _Base128 { _Word[0] = static_cast(_Val); _Word[1] = static_cast(_Val / static_cast<_Ty>(18446744073709551616.0)); } + + _NODISCARD constexpr explicit operator size_t() const noexcept { + return static_cast(_Word[0]); + } }; template <> @@ -1396,6 +1400,10 @@ struct _Signed128 : _Base128 { _Word[1] |= 1ull << 63; } } + + _NODISCARD constexpr operator size_t() const noexcept { + return static_cast(_Word[0]); + } }; template <> From 6aa5c10d6f56f54b9b0922bc0eb68cc83d7f28ed Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Sat, 11 Mar 2023 16:52:20 +0800 Subject: [PATCH 15/35] remove is_integral & is_arithmetic of int128 --- stl/inc/xtr1common | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/stl/inc/xtr1common b/stl/inc/xtr1common index d0b14e8aff2..f646d9625da 100644 --- a/stl/inc/xtr1common +++ b/stl/inc/xtr1common @@ -175,17 +175,13 @@ _EXPORT_STD _NODISCARD constexpr bool is_constant_evaluated() noexcept { } #endif // _HAS_CXX20 -struct _Signed128; -struct _Unsigned128; - _EXPORT_STD template -_INLINE_VAR constexpr bool is_integral_v = - _Is_any_of_v, bool, char, signed char, unsigned char, wchar_t, +_INLINE_VAR constexpr bool is_integral_v = _Is_any_of_v, bool, char, signed char, unsigned char, + wchar_t, #ifdef __cpp_char8_t - char8_t, + char8_t, #endif // __cpp_char8_t - char16_t, char32_t, short, unsigned short, int, unsigned int, long, unsigned long, long long, - unsigned long long, _Signed128, _Unsigned128>; + char16_t, char32_t, short, unsigned short, int, unsigned int, long, unsigned long, long long, unsigned long long>; _EXPORT_STD template struct is_integral : bool_constant> {}; From 1cf420d6906b1e3a2e7d5827d898cfe9c3074f91 Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Sat, 11 Mar 2023 18:40:41 +0800 Subject: [PATCH 16/35] =?UTF-8?q?explicit=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit holy fkin shi --- stl/inc/__msvc_int128.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/__msvc_int128.hpp b/stl/inc/__msvc_int128.hpp index 88fbba9437e..a3343e59559 100644 --- a/stl/inc/__msvc_int128.hpp +++ b/stl/inc/__msvc_int128.hpp @@ -1401,7 +1401,7 @@ struct _Signed128 : _Base128 { } } - _NODISCARD constexpr operator size_t() const noexcept { + _NODISCARD constexpr explicit operator size_t() const noexcept { return static_cast(_Word[0]); } }; From 59e0bb83bb1a42863699d1afc83ec185b25fdb76 Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Sat, 11 Mar 2023 18:40:46 +0800 Subject: [PATCH 17/35] Revert "remove is_integral & is_arithmetic of int128" This reverts commit 6aa5c10d6f56f54b9b0922bc0eb68cc83d7f28ed. --- stl/inc/xtr1common | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/stl/inc/xtr1common b/stl/inc/xtr1common index f646d9625da..d0b14e8aff2 100644 --- a/stl/inc/xtr1common +++ b/stl/inc/xtr1common @@ -175,13 +175,17 @@ _EXPORT_STD _NODISCARD constexpr bool is_constant_evaluated() noexcept { } #endif // _HAS_CXX20 +struct _Signed128; +struct _Unsigned128; + _EXPORT_STD template -_INLINE_VAR constexpr bool is_integral_v = _Is_any_of_v, bool, char, signed char, unsigned char, - wchar_t, +_INLINE_VAR constexpr bool is_integral_v = + _Is_any_of_v, bool, char, signed char, unsigned char, wchar_t, #ifdef __cpp_char8_t - char8_t, + char8_t, #endif // __cpp_char8_t - char16_t, char32_t, short, unsigned short, int, unsigned int, long, unsigned long, long long, unsigned long long>; + char16_t, char32_t, short, unsigned short, int, unsigned int, long, unsigned long, long long, + unsigned long long, _Signed128, _Unsigned128>; _EXPORT_STD template struct is_integral : bool_constant> {}; From a711aa9fde1b4e64b44c6eb6c54dd204f4c9fa49 Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Sat, 11 Mar 2023 18:56:39 +0800 Subject: [PATCH 18/35] fix abs using --- stl/inc/__msvc_int128.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/__msvc_int128.hpp b/stl/inc/__msvc_int128.hpp index a3343e59559..37e53646946 100644 --- a/stl/inc/__msvc_int128.hpp +++ b/stl/inc/__msvc_int128.hpp @@ -1386,7 +1386,7 @@ struct _Signed128 : _Base128 { template , int> = 0> _NODISCARD constexpr explicit operator _Ty() const noexcept { bool _Negative = int64_t(_Word[1]) < 0; - const _Unsigned128 _Abs{_Word[0], abs(int64_t(_Word[1]))}; + const _Unsigned128 _Abs{_Word[0], (_Negative ? uint64_t(-int64_t(_Word[1])) : uint64_t(_Word[1]))}; auto _Result = static_cast<_Ty>(_Abs); return _Negative ? -_Result : _Result; } From acf5ff67287eda06a5ed78d013ec3254ec3aa48b Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Sat, 11 Mar 2023 21:10:22 +0800 Subject: [PATCH 19/35] Revert "Revert "remove is_integral & is_arithmetic of int128"" This reverts commit 59e0bb83bb1a42863699d1afc83ec185b25fdb76. --- stl/inc/xtr1common | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/stl/inc/xtr1common b/stl/inc/xtr1common index d0b14e8aff2..f646d9625da 100644 --- a/stl/inc/xtr1common +++ b/stl/inc/xtr1common @@ -175,17 +175,13 @@ _EXPORT_STD _NODISCARD constexpr bool is_constant_evaluated() noexcept { } #endif // _HAS_CXX20 -struct _Signed128; -struct _Unsigned128; - _EXPORT_STD template -_INLINE_VAR constexpr bool is_integral_v = - _Is_any_of_v, bool, char, signed char, unsigned char, wchar_t, +_INLINE_VAR constexpr bool is_integral_v = _Is_any_of_v, bool, char, signed char, unsigned char, + wchar_t, #ifdef __cpp_char8_t - char8_t, + char8_t, #endif // __cpp_char8_t - char16_t, char32_t, short, unsigned short, int, unsigned int, long, unsigned long, long long, - unsigned long long, _Signed128, _Unsigned128>; + char16_t, char32_t, short, unsigned short, int, unsigned int, long, unsigned long, long long, unsigned long long>; _EXPORT_STD template struct is_integral : bool_constant> {}; From 3f96d6d0540cd3934d56b5621d30f7231b6305c3 Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Sat, 11 Mar 2023 21:18:32 +0800 Subject: [PATCH 20/35] fix float to int128 Co-Authored-By: A. Jiang <23228989+frederick-vs-ja@users.noreply.github.com> --- stl/inc/__msvc_int128.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stl/inc/__msvc_int128.hpp b/stl/inc/__msvc_int128.hpp index 37e53646946..358f7d551c9 100644 --- a/stl/inc/__msvc_int128.hpp +++ b/stl/inc/__msvc_int128.hpp @@ -1392,12 +1392,12 @@ struct _Signed128 : _Base128 { } template , int> = 0> constexpr explicit _Signed128(const _Ty _Val) noexcept { - const bool _Negative = _Val < 0; + const bool _Negative = _Val < _Ty{}; const _Ty _Absval = _Negative ? -_Val : _Val; _Word[0] = static_cast(_Absval); _Word[1] = static_cast(_Absval / static_cast<_Ty>(18446744073709551616.0)); if (_Negative) { - _Word[1] |= 1ull << 63; + *this = -*this; } } From ec352e2f1ee68ccb779998746731f1d7b37ca8f0 Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Sat, 11 Mar 2023 21:20:59 +0800 Subject: [PATCH 21/35] fix of int128tofloat Co-Authored-By: A. Jiang <23228989+frederick-vs-ja@users.noreply.github.com> --- stl/inc/__msvc_int128.hpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/stl/inc/__msvc_int128.hpp b/stl/inc/__msvc_int128.hpp index 358f7d551c9..61fcf7d67b8 100644 --- a/stl/inc/__msvc_int128.hpp +++ b/stl/inc/__msvc_int128.hpp @@ -1385,10 +1385,9 @@ struct _Signed128 : _Base128 { template , int> = 0> _NODISCARD constexpr explicit operator _Ty() const noexcept { - bool _Negative = int64_t(_Word[1]) < 0; - const _Unsigned128 _Abs{_Word[0], (_Negative ? uint64_t(-int64_t(_Word[1])) : uint64_t(_Word[1]))}; - auto _Result = static_cast<_Ty>(_Abs); - return _Negative ? -_Result : _Result; + const auto _Unsigned_self = static_cast<_Unsigned128>(*this); + return static_cast(_Word[1]) < 0 ? -static_cast<_Ty>(-_Unsigned_self) + : static_cast<_Ty>(_Unsigned_self); } template , int> = 0> constexpr explicit _Signed128(const _Ty _Val) noexcept { From 7416bfaee5d5d51b73d65d21a26c7191c541e71b Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Sat, 11 Mar 2023 21:24:15 +0800 Subject: [PATCH 22/35] workaround of clong Co-Authored-By: A. Jiang <23228989+frederick-vs-ja@users.noreply.github.com> --- stl/inc/__msvc_int128.hpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/stl/inc/__msvc_int128.hpp b/stl/inc/__msvc_int128.hpp index 61fcf7d67b8..730e48ed98a 100644 --- a/stl/inc/__msvc_int128.hpp +++ b/stl/inc/__msvc_int128.hpp @@ -987,11 +987,23 @@ struct _Unsigned128 : _Base128 { return static_cast<_Ty>(_Word[1]) * static_cast<_Ty>(18446744073709551616.0) + static_cast<_Ty>(_Word[0]); } + /** + // original code, see https://github.com/microsoft/STL/pull/3559#discussion_r1133080097 for why not to use it template , int> = 0> constexpr explicit _Unsigned128(const _Ty _Val) noexcept { _Word[0] = static_cast(_Val); _Word[1] = static_cast(_Val / static_cast<_Ty>(18446744073709551616.0)); } + **/ + constexpr explicit _Unsigned128(const float _Val) noexcept { + _Word[0] = static_cast(_Val); + _Word[1] = static_cast(_Val / 18446744073709551616.0f); + } + constexpr explicit _Unsigned128(const double _Val) noexcept { + _Word[0] = static_cast(_Val); + _Word[1] = static_cast(_Val / 18446744073709551616.0); + } + constexpr explicit _Unsigned128(const long double _Val) noexcept : _Unsigned128(static_cast(_Val)) {} _NODISCARD constexpr explicit operator size_t() const noexcept { return static_cast(_Word[0]); From 54d1e2a2d8e3873c15624022f5f532c3ad19ab8c Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Sun, 12 Mar 2023 00:20:25 +0800 Subject: [PATCH 23/35] Just a note --- stl/inc/__msvc_int128.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stl/inc/__msvc_int128.hpp b/stl/inc/__msvc_int128.hpp index 730e48ed98a..aa17a36905f 100644 --- a/stl/inc/__msvc_int128.hpp +++ b/stl/inc/__msvc_int128.hpp @@ -1005,6 +1005,8 @@ struct _Unsigned128 : _Base128 { } constexpr explicit _Unsigned128(const long double _Val) noexcept : _Unsigned128(static_cast(_Val)) {} + // explicit conversion to size_t, we need this because there may have some ice in msvc + // see https://github.com/microsoft/STL/pull/3559#discussion_r1133067391 for more details _NODISCARD constexpr explicit operator size_t() const noexcept { return static_cast(_Word[0]); } @@ -1412,6 +1414,8 @@ struct _Signed128 : _Base128 { } } + // explicit conversion to size_t, we need this because there may have some ice in msvc + // see https://github.com/microsoft/STL/pull/3559#discussion_r1133067391 for more details _NODISCARD constexpr explicit operator size_t() const noexcept { return static_cast(_Word[0]); } From f86914ce0bba6bdeb72198f221b74a37ea14edb8 Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Sun, 12 Mar 2023 00:53:17 +0800 Subject: [PATCH 24/35] workaround of _Signed128 --- stl/inc/__msvc_int128.hpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/stl/inc/__msvc_int128.hpp b/stl/inc/__msvc_int128.hpp index aa17a36905f..83e408ecd81 100644 --- a/stl/inc/__msvc_int128.hpp +++ b/stl/inc/__msvc_int128.hpp @@ -1403,6 +1403,8 @@ struct _Signed128 : _Base128 { return static_cast(_Word[1]) < 0 ? -static_cast<_Ty>(-_Unsigned_self) : static_cast<_Ty>(_Unsigned_self); } + /** + // original code, see https://github.com/microsoft/STL/pull/3559#discussion_r1133080097 for why not to use it template , int> = 0> constexpr explicit _Signed128(const _Ty _Val) noexcept { const bool _Negative = _Val < _Ty{}; @@ -1413,6 +1415,34 @@ struct _Signed128 : _Base128 { *this = -*this; } } + **/ + constexpr explicit _Signed128(const float _Val) noexcept { + const bool _Negative = _Val < 0.0f; + const float _Absval = _Negative ? -_Val : _Val; + _Word[0] = static_cast(_Absval); + _Word[1] = static_cast(_Absval / 18446744073709551616.0f); + if (_Negative) { + *this = -*this; + } + } + constexpr explicit _Signed128(const double _Val) noexcept { + const bool _Negative = _Val < 0.0; + const double _Absval = _Negative ? -_Val : _Val; + _Word[0] = static_cast(_Absval); + _Word[1] = static_cast(_Absval / 18446744073709551616.0); + if (_Negative) { + *this = -*this; + } + } + constexpr explicit _Signed128(const long double _Val) noexcept { + const bool _Negative = _Val < 0.0L; + const long double _Absval = _Negative ? -_Val : _Val; + _Word[0] = static_cast(_Absval); + _Word[1] = static_cast(_Absval / 18446744073709551616.0L); + if (_Negative) { + *this = -*this; + } + } // explicit conversion to size_t, we need this because there may have some ice in msvc // see https://github.com/microsoft/STL/pull/3559#discussion_r1133067391 for more details From 6d99bacf670aee95fc51f052da575da9172c2c53 Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Sun, 12 Mar 2023 00:56:58 +0800 Subject: [PATCH 25/35] little update --- stl/inc/__msvc_int128.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/stl/inc/__msvc_int128.hpp b/stl/inc/__msvc_int128.hpp index 83e408ecd81..b977337d4ca 100644 --- a/stl/inc/__msvc_int128.hpp +++ b/stl/inc/__msvc_int128.hpp @@ -1003,7 +1003,10 @@ struct _Unsigned128 : _Base128 { _Word[0] = static_cast(_Val); _Word[1] = static_cast(_Val / 18446744073709551616.0); } - constexpr explicit _Unsigned128(const long double _Val) noexcept : _Unsigned128(static_cast(_Val)) {} + constexpr explicit _Unsigned128(const long double _Val) noexcept { + _Word[0] = static_cast(_Val); + _Word[1] = static_cast(_Val / 18446744073709551616.0L); + } // explicit conversion to size_t, we need this because there may have some ice in msvc // see https://github.com/microsoft/STL/pull/3559#discussion_r1133067391 for more details From 035ec61facf7a50685fd6a1a9cdc8452c3dca0f4 Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Sun, 12 Mar 2023 00:58:15 +0800 Subject: [PATCH 26/35] **clang-format** --- stl/inc/__msvc_int128.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/__msvc_int128.hpp b/stl/inc/__msvc_int128.hpp index b977337d4ca..e7f5db4e26e 100644 --- a/stl/inc/__msvc_int128.hpp +++ b/stl/inc/__msvc_int128.hpp @@ -1438,7 +1438,7 @@ struct _Signed128 : _Base128 { } } constexpr explicit _Signed128(const long double _Val) noexcept { - const bool _Negative = _Val < 0.0L; + const bool _Negative = _Val < 0.0L; const long double _Absval = _Negative ? -_Val : _Val; _Word[0] = static_cast(_Absval); _Word[1] = static_cast(_Absval / 18446744073709551616.0L); From 1c63f8ff742c5b6572c8d48e1bc1f6c7abb125e8 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Sun, 12 Mar 2023 12:13:54 +0800 Subject: [PATCH 27/35] Cleanup workaround --- stl/inc/__msvc_int128.hpp | 170 ++++++++++++++++++-------------------- 1 file changed, 80 insertions(+), 90 deletions(-) diff --git a/stl/inc/__msvc_int128.hpp b/stl/inc/__msvc_int128.hpp index e7f5db4e26e..d2aebbd70c4 100644 --- a/stl/inc/__msvc_int128.hpp +++ b/stl/inc/__msvc_int128.hpp @@ -27,8 +27,10 @@ #ifdef __cpp_lib_concepts #include #define _TEMPLATE_CLASS_INTEGRAL(type) template +#define _TEMPLATE_CLASS_FP(type) template #else // ^^^ defined(__cpp_lib_concepts) / !defined(__cpp_lib_concepts) vvv #define _TEMPLATE_CLASS_INTEGRAL(type) template , int> = 0> +#define _TEMPLATE_CLASS_FP(type) template , int> = 0> #endif // ^^^ !defined(__cpp_lib_concepts) ^^^ #pragma pack(push, _CRT_PACKING) @@ -309,11 +311,6 @@ struct constexpr explicit _Base128(const uint64_t _Low, const uint64_t _High) noexcept : _Word{_Low, _High} {} - _TEMPLATE_CLASS_INTEGRAL(_Ty) - _NODISCARD constexpr explicit operator _Ty() const noexcept { - return static_cast<_Ty>(_Word[0]); - } - _NODISCARD constexpr explicit operator bool() const noexcept { return (_Word[0] | _Word[1]) != 0; } @@ -721,6 +718,36 @@ struct _Unsigned128 : _Base128 { using _Base128::_Base128; constexpr explicit _Unsigned128(const _Base128& _That) noexcept : _Base128{_That} {} +#ifdef __clang__ // TRANSITION, Clang 16 or 17 + constexpr explicit _Unsigned128(const float _Val) noexcept { + _Word[0] = static_cast(_Val); + _Word[1] = static_cast(_Val / 18446744073709551616.0f); + } + + constexpr explicit _Unsigned128(const double _Val) noexcept { + _Word[0] = static_cast(_Val); + _Word[1] = static_cast(_Val / 18446744073709551616.0); + } + + constexpr explicit _Unsigned128(const long double _Val) noexcept : _Unsigned128(static_cast(_Val)) {} +#else // ^^^ workaround / no workaround vvv + _TEMPLATE_CLASS_FP(_Ty) + constexpr explicit _Unsigned128(const _Ty _Val) noexcept { + _Word[0] = static_cast(_Val); + _Word[1] = static_cast(_Val / static_cast<_Ty>(18446744073709551616.0f)); + } +#endif // ^^^ no workaround ^^^ + + _TEMPLATE_CLASS_INTEGRAL(_Ty) + _NODISCARD constexpr explicit operator _Ty() const noexcept { + return static_cast<_Ty>(_Word[0]); + } + + _TEMPLATE_CLASS_FP(_Ty) + _NODISCARD constexpr explicit operator _Ty() const noexcept { + return static_cast<_Ty>(_Word[1]) * static_cast<_Ty>(18446744073709551616.0) + static_cast<_Ty>(_Word[0]); + } + constexpr _Unsigned128& operator=(const _Base128& _That) noexcept { _Base128::operator=(_That); return *this; @@ -981,38 +1008,6 @@ struct _Unsigned128 : _Base128 { _Word[1] |= _That._Word[1]; return *this; } - - template , int> = 0> - _NODISCARD constexpr explicit operator _Ty() const noexcept { - return static_cast<_Ty>(_Word[1]) * static_cast<_Ty>(18446744073709551616.0) + static_cast<_Ty>(_Word[0]); - } - - /** - // original code, see https://github.com/microsoft/STL/pull/3559#discussion_r1133080097 for why not to use it - template , int> = 0> - constexpr explicit _Unsigned128(const _Ty _Val) noexcept { - _Word[0] = static_cast(_Val); - _Word[1] = static_cast(_Val / static_cast<_Ty>(18446744073709551616.0)); - } - **/ - constexpr explicit _Unsigned128(const float _Val) noexcept { - _Word[0] = static_cast(_Val); - _Word[1] = static_cast(_Val / 18446744073709551616.0f); - } - constexpr explicit _Unsigned128(const double _Val) noexcept { - _Word[0] = static_cast(_Val); - _Word[1] = static_cast(_Val / 18446744073709551616.0); - } - constexpr explicit _Unsigned128(const long double _Val) noexcept { - _Word[0] = static_cast(_Val); - _Word[1] = static_cast(_Val / 18446744073709551616.0L); - } - - // explicit conversion to size_t, we need this because there may have some ice in msvc - // see https://github.com/microsoft/STL/pull/3559#discussion_r1133067391 for more details - _NODISCARD constexpr explicit operator size_t() const noexcept { - return static_cast(_Word[0]); - } }; template <> @@ -1070,6 +1065,53 @@ struct _Signed128 : _Base128 { using _Base128::_Base128; constexpr explicit _Signed128(const _Base128& _That) noexcept : _Base128{_That} {} +#ifdef __clang__ // TRANSITION, Clang 16 or 17 + constexpr explicit _Signed128(const float _Val) noexcept { + const bool _Negative = _Val < 0.0f; + const float _Absval = _Negative ? -_Val : _Val; + _Word[0] = static_cast(_Absval); + _Word[1] = static_cast(_Absval / 18446744073709551616.0f); + if (_Negative) { + *this = -*this; + } + } + + constexpr explicit _Signed128(const double _Val) noexcept { + const bool _Negative = _Val < 0.0; + const double _Absval = _Negative ? -_Val : _Val; + _Word[0] = static_cast(_Absval); + _Word[1] = static_cast(_Absval / 18446744073709551616.0); + if (_Negative) { + *this = -*this; + } + } + + constexpr explicit _Signed128(const long double _Val) noexcept : _Signed128(static_cast(_Val)) {} +#else // ^^^ workaround / no workaround vvv + _TEMPLATE_CLASS_FP(_Ty) + constexpr explicit _Signed128(const _Ty _Val) noexcept { + const bool _Negative = _Val < 0.0f; + const _Ty _Absval = _Negative ? -_Val : _Val; + _Word[0] = static_cast(_Absval); + _Word[1] = static_cast(_Absval / static_cast<_Ty>(18446744073709551616.0)); + if (_Negative) { + *this = -*this; + } + } +#endif // ^^^ no workaround ^^^ + + _TEMPLATE_CLASS_INTEGRAL(_Ty) + _NODISCARD constexpr explicit operator _Ty() const noexcept { + return static_cast<_Ty>(_Word[0]); + } + + _TEMPLATE_CLASS_FP(_Ty) + _NODISCARD constexpr explicit operator _Ty() const noexcept { + const auto _Unsigned_self = static_cast<_Unsigned128>(*this); + return static_cast(_Word[1]) < 0 ? -static_cast<_Ty>(-_Unsigned_self) + : static_cast<_Ty>(_Unsigned_self); + } + constexpr _Signed128& operator=(const _Base128& _That) noexcept { _Base128::operator=(_That); return *this; @@ -1399,59 +1441,6 @@ struct _Signed128 : _Base128 { _Word[1] |= _That._Word[1]; return *this; } - - template , int> = 0> - _NODISCARD constexpr explicit operator _Ty() const noexcept { - const auto _Unsigned_self = static_cast<_Unsigned128>(*this); - return static_cast(_Word[1]) < 0 ? -static_cast<_Ty>(-_Unsigned_self) - : static_cast<_Ty>(_Unsigned_self); - } - /** - // original code, see https://github.com/microsoft/STL/pull/3559#discussion_r1133080097 for why not to use it - template , int> = 0> - constexpr explicit _Signed128(const _Ty _Val) noexcept { - const bool _Negative = _Val < _Ty{}; - const _Ty _Absval = _Negative ? -_Val : _Val; - _Word[0] = static_cast(_Absval); - _Word[1] = static_cast(_Absval / static_cast<_Ty>(18446744073709551616.0)); - if (_Negative) { - *this = -*this; - } - } - **/ - constexpr explicit _Signed128(const float _Val) noexcept { - const bool _Negative = _Val < 0.0f; - const float _Absval = _Negative ? -_Val : _Val; - _Word[0] = static_cast(_Absval); - _Word[1] = static_cast(_Absval / 18446744073709551616.0f); - if (_Negative) { - *this = -*this; - } - } - constexpr explicit _Signed128(const double _Val) noexcept { - const bool _Negative = _Val < 0.0; - const double _Absval = _Negative ? -_Val : _Val; - _Word[0] = static_cast(_Absval); - _Word[1] = static_cast(_Absval / 18446744073709551616.0); - if (_Negative) { - *this = -*this; - } - } - constexpr explicit _Signed128(const long double _Val) noexcept { - const bool _Negative = _Val < 0.0L; - const long double _Absval = _Negative ? -_Val : _Val; - _Word[0] = static_cast(_Absval); - _Word[1] = static_cast(_Absval / 18446744073709551616.0L); - if (_Negative) { - *this = -*this; - } - } - - // explicit conversion to size_t, we need this because there may have some ice in msvc - // see https://github.com/microsoft/STL/pull/3559#discussion_r1133067391 for more details - _NODISCARD constexpr explicit operator size_t() const noexcept { - return static_cast(_Word[0]); - } }; template <> @@ -1512,6 +1501,7 @@ struct common_type<_Unsigned128, _Signed128> { _STD_END +#undef _TEMPLATE_CLASS_FP #undef _TEMPLATE_CLASS_INTEGRAL #undef _ZERO_OR_NO_INIT From bf9c0b32327e9bce19ea7f14aad1df10f6abe51d Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Sun, 12 Mar 2023 12:23:10 +0800 Subject: [PATCH 28/35] Simple test coverage for FP conversions --- .../tests/P1522R1_difference_type/test.cpp | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/std/tests/P1522R1_difference_type/test.cpp b/tests/std/tests/P1522R1_difference_type/test.cpp index fa26a332c6a..b3e2140980b 100644 --- a/tests/std/tests/P1522R1_difference_type/test.cpp +++ b/tests/std/tests/P1522R1_difference_type/test.cpp @@ -1345,6 +1345,45 @@ constexpr bool test_cross() { return true; } +// Extension: explicit conversion from and to floating-point types + +template +constexpr bool test_one_floating_point() { + constexpr Flt zero = Flt{}; + constexpr Flt one = Flt{1.0}; + constexpr Flt neg_one = Flt{-1.0}; + + assert(_Unsigned128{zero} == _Unsigned128{}); + assert(_Unsigned128{zero} == 0); + assert(static_cast(_Unsigned128{zero}) == Flt{}); + + assert(_Unsigned128{one} == _Unsigned128{1}); + assert(_Unsigned128{one} == 1); + assert(static_cast(_Unsigned128{one}) == Flt{1.0}); + + assert(_Signed128{zero} == _Signed128{}); + assert(_Signed128{zero} == 0); + assert(static_cast(_Signed128{zero}) == Flt{}); + + assert(_Signed128{one} == _Signed128{1}); + assert(_Signed128{one} == 1); + assert(static_cast(_Signed128{one}) == Flt{1.0}); + + assert(_Signed128{neg_one} == _Signed128{-1}); + assert(_Signed128{neg_one} == -1); + assert(static_cast(_Signed128{neg_one}) == Flt{-1.0}); + + return true; +} + +constexpr bool test_floating_point() { + assert(test_one_floating_point()); + assert(test_one_floating_point()); + assert(test_one_floating_point()); + + return true; +} + int main() { test_unsigned(); STATIC_ASSERT(test_unsigned()); @@ -1352,4 +1391,6 @@ int main() { STATIC_ASSERT(test_signed()); test_cross(); STATIC_ASSERT(test_cross()); + test_floating_point(); + static_assert(test_floating_point()); } From 564b107165a550bb5e47445d61750b063c042598 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Sun, 12 Mar 2023 12:30:33 +0800 Subject: [PATCH 29/35] C++14 and `static_assert` What a sad story. --- tests/std/tests/P1522R1_difference_type/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/std/tests/P1522R1_difference_type/test.cpp b/tests/std/tests/P1522R1_difference_type/test.cpp index b3e2140980b..544161cd940 100644 --- a/tests/std/tests/P1522R1_difference_type/test.cpp +++ b/tests/std/tests/P1522R1_difference_type/test.cpp @@ -1392,5 +1392,5 @@ int main() { test_cross(); STATIC_ASSERT(test_cross()); test_floating_point(); - static_assert(test_floating_point()); + STATIC_ASSERT(test_floating_point()); } From 8f1ec0bdf3cb78cebfcb2dd0b3df3c38bd10539b Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Sun, 12 Mar 2023 12:47:20 +0800 Subject: [PATCH 30/35] format --- stl/inc/__msvc_int128.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/__msvc_int128.hpp b/stl/inc/__msvc_int128.hpp index d2aebbd70c4..8bf0beb5015 100644 --- a/stl/inc/__msvc_int128.hpp +++ b/stl/inc/__msvc_int128.hpp @@ -1068,7 +1068,7 @@ struct _Signed128 : _Base128 { #ifdef __clang__ // TRANSITION, Clang 16 or 17 constexpr explicit _Signed128(const float _Val) noexcept { const bool _Negative = _Val < 0.0f; - const float _Absval = _Negative ? -_Val : _Val; + const float _Absval = _Negative ? -_Val : _Val; _Word[0] = static_cast(_Absval); _Word[1] = static_cast(_Absval / 18446744073709551616.0f); if (_Negative) { From 6eee4c513a3f41f74542b3826e2b855c42f47710 Mon Sep 17 00:00:00 2001 From: steve green Date: Sun, 12 Mar 2023 12:54:36 +0800 Subject: [PATCH 31/35] Update tests/std/tests/P1522R1_difference_type/test.cpp thx for help Co-authored-by: Igor Zhukov --- tests/std/tests/P1522R1_difference_type/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/std/tests/P1522R1_difference_type/test.cpp b/tests/std/tests/P1522R1_difference_type/test.cpp index 544161cd940..3fe72ae5fa0 100644 --- a/tests/std/tests/P1522R1_difference_type/test.cpp +++ b/tests/std/tests/P1522R1_difference_type/test.cpp @@ -1347,7 +1347,7 @@ constexpr bool test_cross() { // Extension: explicit conversion from and to floating-point types -template +template constexpr bool test_one_floating_point() { constexpr Flt zero = Flt{}; constexpr Flt one = Flt{1.0}; From 19b5ce102f7ae24eb8f96fdb0e492d0c30c038d8 Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Sun, 12 Mar 2023 13:01:43 +0800 Subject: [PATCH 32/35] I like longer names so --- stl/inc/__msvc_int128.hpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/stl/inc/__msvc_int128.hpp b/stl/inc/__msvc_int128.hpp index 8bf0beb5015..4a37a3c4be6 100644 --- a/stl/inc/__msvc_int128.hpp +++ b/stl/inc/__msvc_int128.hpp @@ -26,11 +26,11 @@ #ifdef __cpp_lib_concepts #include -#define _TEMPLATE_CLASS_INTEGRAL(type) template -#define _TEMPLATE_CLASS_FP(type) template +#define _TEMPLATE_CLASS_INTEGRAL(type) template +#define _TEMPLATE_CLASS_FLOATING_POINT(type) template #else // ^^^ defined(__cpp_lib_concepts) / !defined(__cpp_lib_concepts) vvv -#define _TEMPLATE_CLASS_INTEGRAL(type) template , int> = 0> -#define _TEMPLATE_CLASS_FP(type) template , int> = 0> +#define _TEMPLATE_CLASS_INTEGRAL(type) template , int> = 0> +#define _TEMPLATE_CLASS_FLOATING_POINT(type) template , int> = 0> #endif // ^^^ !defined(__cpp_lib_concepts) ^^^ #pragma pack(push, _CRT_PACKING) @@ -731,7 +731,7 @@ struct _Unsigned128 : _Base128 { constexpr explicit _Unsigned128(const long double _Val) noexcept : _Unsigned128(static_cast(_Val)) {} #else // ^^^ workaround / no workaround vvv - _TEMPLATE_CLASS_FP(_Ty) + _TEMPLATE_CLASS_FLOATING_POINT(_Ty) constexpr explicit _Unsigned128(const _Ty _Val) noexcept { _Word[0] = static_cast(_Val); _Word[1] = static_cast(_Val / static_cast<_Ty>(18446744073709551616.0f)); @@ -743,7 +743,7 @@ struct _Unsigned128 : _Base128 { return static_cast<_Ty>(_Word[0]); } - _TEMPLATE_CLASS_FP(_Ty) + _TEMPLATE_CLASS_FLOATING_POINT(_Ty) _NODISCARD constexpr explicit operator _Ty() const noexcept { return static_cast<_Ty>(_Word[1]) * static_cast<_Ty>(18446744073709551616.0) + static_cast<_Ty>(_Word[0]); } @@ -1088,7 +1088,7 @@ struct _Signed128 : _Base128 { constexpr explicit _Signed128(const long double _Val) noexcept : _Signed128(static_cast(_Val)) {} #else // ^^^ workaround / no workaround vvv - _TEMPLATE_CLASS_FP(_Ty) + _TEMPLATE_CLASS_FLOATING_POINT(_Ty) constexpr explicit _Signed128(const _Ty _Val) noexcept { const bool _Negative = _Val < 0.0f; const _Ty _Absval = _Negative ? -_Val : _Val; @@ -1105,7 +1105,7 @@ struct _Signed128 : _Base128 { return static_cast<_Ty>(_Word[0]); } - _TEMPLATE_CLASS_FP(_Ty) + _TEMPLATE_CLASS_FLOATING_POINT(_Ty) _NODISCARD constexpr explicit operator _Ty() const noexcept { const auto _Unsigned_self = static_cast<_Unsigned128>(*this); return static_cast(_Word[1]) < 0 ? -static_cast<_Ty>(-_Unsigned_self) @@ -1501,7 +1501,7 @@ struct common_type<_Unsigned128, _Signed128> { _STD_END -#undef _TEMPLATE_CLASS_FP +#undef _TEMPLATE_CLASS_FLOATING_POINT #undef _TEMPLATE_CLASS_INTEGRAL #undef _ZERO_OR_NO_INIT From d29abb35de55386710ee04d9bdad175997b2e2e8 Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Tue, 14 Mar 2023 18:01:53 +0800 Subject: [PATCH 33/35] Treating long double as long double --- stl/inc/__msvc_int128.hpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/stl/inc/__msvc_int128.hpp b/stl/inc/__msvc_int128.hpp index 4a37a3c4be6..f95ca0e6497 100644 --- a/stl/inc/__msvc_int128.hpp +++ b/stl/inc/__msvc_int128.hpp @@ -729,7 +729,10 @@ struct _Unsigned128 : _Base128 { _Word[1] = static_cast(_Val / 18446744073709551616.0); } - constexpr explicit _Unsigned128(const long double _Val) noexcept : _Unsigned128(static_cast(_Val)) {} + constexpr explicit _Unsigned128(const long double _Val) noexcept { + _Word[0] = static_cast(_Val); + _Word[1] = static_cast(_Val / 18446744073709551616.0L); + } #else // ^^^ workaround / no workaround vvv _TEMPLATE_CLASS_FLOATING_POINT(_Ty) constexpr explicit _Unsigned128(const _Ty _Val) noexcept { @@ -1086,7 +1089,15 @@ struct _Signed128 : _Base128 { } } - constexpr explicit _Signed128(const long double _Val) noexcept : _Signed128(static_cast(_Val)) {} + constexpr explicit _Signed128(const long double _Val) noexcept { + const bool _Negative = _Val < 0.0L; + const long double _Absval = _Negative ? -_Val : _Val; + _Word[0] = static_cast(_Absval); + _Word[1] = static_cast(_Absval / 18446744073709551616.0L); + if (_Negative) { + *this = -*this; + } + } #else // ^^^ workaround / no workaround vvv _TEMPLATE_CLASS_FLOATING_POINT(_Ty) constexpr explicit _Signed128(const _Ty _Val) noexcept { From d1b8d0031f0e23006c3640ae8559badcfca6a4ac Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Tue, 14 Mar 2023 18:18:36 +0800 Subject: [PATCH 34/35] remove f --- stl/inc/__msvc_int128.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/__msvc_int128.hpp b/stl/inc/__msvc_int128.hpp index f95ca0e6497..3359c14a350 100644 --- a/stl/inc/__msvc_int128.hpp +++ b/stl/inc/__msvc_int128.hpp @@ -737,7 +737,7 @@ struct _Unsigned128 : _Base128 { _TEMPLATE_CLASS_FLOATING_POINT(_Ty) constexpr explicit _Unsigned128(const _Ty _Val) noexcept { _Word[0] = static_cast(_Val); - _Word[1] = static_cast(_Val / static_cast<_Ty>(18446744073709551616.0f)); + _Word[1] = static_cast(_Val / static_cast<_Ty>(18446744073709551616.0)); } #endif // ^^^ no workaround ^^^ From e876bbd001b3c87765a83549678df63e788e2cfa Mon Sep 17 00:00:00 2001 From: steve02081504 Date: Tue, 14 Mar 2023 18:51:22 +0800 Subject: [PATCH 35/35] Revert "Treating long double as long double" This reverts commit d29abb35de55386710ee04d9bdad175997b2e2e8. --- stl/inc/__msvc_int128.hpp | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/stl/inc/__msvc_int128.hpp b/stl/inc/__msvc_int128.hpp index 3359c14a350..52a6f27ccc5 100644 --- a/stl/inc/__msvc_int128.hpp +++ b/stl/inc/__msvc_int128.hpp @@ -729,10 +729,7 @@ struct _Unsigned128 : _Base128 { _Word[1] = static_cast(_Val / 18446744073709551616.0); } - constexpr explicit _Unsigned128(const long double _Val) noexcept { - _Word[0] = static_cast(_Val); - _Word[1] = static_cast(_Val / 18446744073709551616.0L); - } + constexpr explicit _Unsigned128(const long double _Val) noexcept : _Unsigned128(static_cast(_Val)) {} #else // ^^^ workaround / no workaround vvv _TEMPLATE_CLASS_FLOATING_POINT(_Ty) constexpr explicit _Unsigned128(const _Ty _Val) noexcept { @@ -1089,15 +1086,7 @@ struct _Signed128 : _Base128 { } } - constexpr explicit _Signed128(const long double _Val) noexcept { - const bool _Negative = _Val < 0.0L; - const long double _Absval = _Negative ? -_Val : _Val; - _Word[0] = static_cast(_Absval); - _Word[1] = static_cast(_Absval / 18446744073709551616.0L); - if (_Negative) { - *this = -*this; - } - } + constexpr explicit _Signed128(const long double _Val) noexcept : _Signed128(static_cast(_Val)) {} #else // ^^^ workaround / no workaround vvv _TEMPLATE_CLASS_FLOATING_POINT(_Ty) constexpr explicit _Signed128(const _Ty _Val) noexcept {