Changeset 284850 in webkit
- Timestamp:
- Oct 25, 2021, 5:16:10 PM (5 years ago)
- Location:
- trunk/Source/WTF
- Files:
-
- 2 edited
-
ChangeLog (modified) (1 diff)
-
wtf/Int128.h (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r284823 r284850 1 2021-10-25 Yusuke Suzuki <ysuzuki@apple.com> 2 3 [WTF] Make Int128 operator* constexpr 4 https://bugs.webkit.org/show_bug.cgi?id=232270 5 6 Reviewed by Mark Lam. 7 8 We remove MSVC X64 (so, Windows only) switching in Int128 operator* since 9 it breaks constexpr-ness of operator*, which makes writing code difficult. 10 We can bring this kind of optimization back when C++20 std::is_constant_evaluated() 11 becomes available. 12 13 * wtf/Int128.h: 14 (WTF::operator*): 15 1 16 2021-10-25 Alex Christensen <achristensen@webkit.org> 2 17 -
trunk/Source/WTF/wtf/Int128.h
r284748 r284850 49 49 // alongside operator unsigned short() in these instances. 50 50 #define ABSL_INTERNAL_WCHAR_T __wchar_t 51 #if CPU(X86_64) 52 #include <intrin.h> 53 #pragma intrinsic(_umul128) 54 #endif // defined(_M_X64) 55 #else // defined(_MSC_VER) 51 #else 56 52 #define ABSL_INTERNAL_WCHAR_T wchar_t 57 #endif // defined(_MSC_VER)53 #endif 58 54 59 55 namespace WTF { … … 516 512 constexpr UInt128Impl operator+(UInt128Impl lhs, UInt128Impl rhs); 517 513 constexpr UInt128Impl operator-(UInt128Impl lhs, UInt128Impl rhs); 518 UInt128Impl operator*(UInt128Impl lhs, UInt128Impl rhs);514 constexpr UInt128Impl operator*(UInt128Impl lhs, UInt128Impl rhs); 519 515 WTF_EXPORT_PRIVATE UInt128Impl operator/(UInt128Impl lhs, UInt128Impl rhs); 520 516 WTF_EXPORT_PRIVATE UInt128Impl operator%(UInt128Impl lhs, UInt128Impl rhs); … … 813 809 } 814 810 815 inline UInt128Impl operator*(UInt128Impl lhs, UInt128Impl rhs) { 816 #if COMPILER(MSVC) && CPU(X86_64) 817 uint64_t carry; 818 uint64_t low = _umul128(UInt128Low64(lhs), UInt128Low64(rhs), &carry); 819 return MakeUInt128(UInt128Low64(lhs) * UInt128High64(rhs) + 820 UInt128High64(lhs) * UInt128Low64(rhs) + carry, 821 low); 822 #else 811 constexpr UInt128Impl operator*(UInt128Impl lhs, UInt128Impl rhs) { 823 812 uint64_t a32 = UInt128Low64(lhs) >> 32; 824 813 uint64_t a00 = UInt128Low64(lhs) & 0xffffffff; … … 829 818 UInt128Low64(lhs) * UInt128High64(rhs) + a32 * b32, 830 819 a00 * b00); 831 result += UInt128Impl(a32 * b00) << 32; 832 result += UInt128Impl(a00 * b32) << 32; 833 return result; 834 #endif 820 UInt128Impl v1 = UInt128Impl(a32 * b00) << 32; 821 UInt128Impl v2 = UInt128Impl(a00 * b32) << 32; 822 return result + v1 + v2; 835 823 } 836 824 … … 895 883 constexpr Int128Impl operator+(Int128Impl lhs, Int128Impl rhs); 896 884 constexpr Int128Impl operator-(Int128Impl lhs, Int128Impl rhs); 897 Int128Impl operator*(Int128Impl lhs, Int128Impl rhs);885 constexpr Int128Impl operator*(Int128Impl lhs, Int128Impl rhs); 898 886 WTF_EXPORT_PRIVATE Int128Impl operator/(Int128Impl lhs, Int128Impl rhs); 899 887 WTF_EXPORT_PRIVATE Int128Impl operator%(Int128Impl lhs, Int128Impl rhs); … … 1193 1181 } 1194 1182 1195 inlineInt128Impl operator*(Int128Impl lhs, Int128Impl rhs) {1183 constexpr Int128Impl operator*(Int128Impl lhs, Int128Impl rhs) { 1196 1184 return MakeInt128( 1197 1185 int128_internal::BitCastToSigned(UInt128High64(UInt128Impl(lhs) * rhs)),
Note:
See TracChangeset
for help on using the changeset viewer.