⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 284850 in webkit


Ignore:
Timestamp:
Oct 25, 2021, 5:16:10 PM (5 years ago)
Author:
ysuzuki@apple.com
Message:

[WTF] Make Int128 operator* constexpr
https://bugs.webkit.org/show_bug.cgi?id=232270

Reviewed by Mark Lam.

We remove MSVC X64 (so, Windows only) switching in Int128 operator* since
it breaks constexpr-ness of operator*, which makes writing code difficult.
We can bring this kind of optimization back when C++20 std::is_constant_evaluated()
becomes available.

  • wtf/Int128.h:

(WTF::operator*):

Location:
trunk/Source/WTF
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r284823 r284850  
     12021-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
    1162021-10-25  Alex Christensen  <achristensen@webkit.org>
    217
  • trunk/Source/WTF/wtf/Int128.h

    r284748 r284850  
    4949// alongside operator unsigned short() in these instances.
    5050#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
    5652#define ABSL_INTERNAL_WCHAR_T wchar_t
    57 #endif  // defined(_MSC_VER)
     53#endif
    5854
    5955namespace WTF {
     
    516512constexpr UInt128Impl operator+(UInt128Impl lhs, UInt128Impl rhs);
    517513constexpr UInt128Impl operator-(UInt128Impl lhs, UInt128Impl rhs);
    518 UInt128Impl operator*(UInt128Impl lhs, UInt128Impl rhs);
     514constexpr UInt128Impl operator*(UInt128Impl lhs, UInt128Impl rhs);
    519515WTF_EXPORT_PRIVATE UInt128Impl operator/(UInt128Impl lhs, UInt128Impl rhs);
    520516WTF_EXPORT_PRIVATE UInt128Impl operator%(UInt128Impl lhs, UInt128Impl rhs);
     
    813809}
    814810
    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
     811constexpr UInt128Impl operator*(UInt128Impl lhs, UInt128Impl rhs) {
    823812  uint64_t a32 = UInt128Low64(lhs) >> 32;
    824813  uint64_t a00 = UInt128Low64(lhs) & 0xffffffff;
     
    829818                      UInt128Low64(lhs) * UInt128High64(rhs) + a32 * b32,
    830819                  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;
    835823}
    836824
     
    895883constexpr Int128Impl operator+(Int128Impl lhs, Int128Impl rhs);
    896884constexpr Int128Impl operator-(Int128Impl lhs, Int128Impl rhs);
    897 Int128Impl operator*(Int128Impl lhs, Int128Impl rhs);
     885constexpr Int128Impl operator*(Int128Impl lhs, Int128Impl rhs);
    898886WTF_EXPORT_PRIVATE Int128Impl operator/(Int128Impl lhs, Int128Impl rhs);
    899887WTF_EXPORT_PRIVATE Int128Impl operator%(Int128Impl lhs, Int128Impl rhs);
     
    11931181}
    11941182
    1195 inline Int128Impl operator*(Int128Impl lhs, Int128Impl rhs) {
     1183constexpr Int128Impl operator*(Int128Impl lhs, Int128Impl rhs) {
    11961184  return MakeInt128(
    11971185      int128_internal::BitCastToSigned(UInt128High64(UInt128Impl(lhs) * rhs)),
Note: See TracChangeset for help on using the changeset viewer.