Bug 232129

Summary: [WTF] Replace current LLVM flang's Int128 with abseil-cpp's Int128
Product: WebKit Reporter: Yusuke Suzuki <ysuzuki>
Component: New BugsAssignee: Yusuke Suzuki <ysuzuki>
Status: RESOLVED FIXED    
Severity: Normal CC: annulen, benjamin, cdumez, cmarcelo, darin, ews-watchlist, gyuyoung.kim, philip.chimento, ryuan.choi, sergio, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
ews-feeder: commit-queue-
Patch
none
Patch
none
Patch
ews-feeder: commit-queue-
Patch
none
Patch none

Description Yusuke Suzuki 2021-10-21 20:21:24 PDT
[WTF] Replace current LLVM flang's Int128 with abseil-cpp's Int128
Comment 1 Yusuke Suzuki 2021-10-21 20:24:45 PDT
Created attachment 442107 [details]
Patch
Comment 2 Yusuke Suzuki 2021-10-21 20:42:24 PDT
Created attachment 442109 [details]
Patch
Comment 3 Yusuke Suzuki 2021-10-21 20:44:03 PDT
Created attachment 442110 [details]
Patch
Comment 4 Yusuke Suzuki 2021-10-21 20:46:24 PDT
Created attachment 442111 [details]
Patch
Comment 5 Yusuke Suzuki 2021-10-21 21:08:36 PDT
Created attachment 442116 [details]
Patch
Comment 6 Philip Chimento 2021-10-22 16:56:24 PDT
Comment on attachment 442116 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=442116&action=review

Thanks for doing this so quickly! This int128 implementation looks more comprehensive than the Flang one anyway.

I would suggest removing WTF/LeadingZeroBitCount.{h,cpp} as well, because this implementation uses the clz() from WTF/MathExtras.h (which I didn't realize existed!) for counting leading zeros, and WTF::LeadingZeroBitCount was only added because the Flang int128 pulled it in.

(I don't have reviewer privileges, so I can't mark this r+, but otherwise LGTM)

> Source/WTF/wtf/Int128.h:81
> +// Additionally, if your compiler supports `__int128`, `UInt128Impl` is

If this functionality was removed when copying from Abseil, it's probably good to remove the comment as well, to avoid confusion.

> Source/WTF/wtf/Int128.h:100
> +//     float y = absl::UInt128Max();  // Error. UInt128Impl cannot be implicitly

Probably good to remove `absl::` here and in line 103 as well

> Source/WTF/wtf/Int128.h:292
> +// Additionally, if your compiler supports `__int128`, `Int128Impl` is

Same as earlier comment.

> Source/WTF/wtf/Int128.h:830
> +#else   // ABSL_HAVE_INTRINSIC128

This is a bit confusing. Although looking in the original source I see the code is actually correct when you remove the ABSL_HAVE_INTRINSIC128 case, because the MSVC&&x86_64 case was originally an #elif. So no need to change, but maybe consider just removing the comment.

> Tools/TestWebKitAPI/Tests/WTF/Int128.cpp:-79
> -static void TestVsNative(__uint128_t x, __uint128_t y)

I would suggest keeping the VsNative tests, and actually adding similar ones for the signed int128. These are probably the best indicator if something is wrong in the implementation. That's what originally alerted me to the Flang implementation's signed int128 operator>> not extending the sign.
Comment 7 Yusuke Suzuki 2021-10-23 00:29:00 PDT
Comment on attachment 442116 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=442116&action=review

>> Source/WTF/wtf/Int128.h:81
>> +// Additionally, if your compiler supports `__int128`, `UInt128Impl` is
> 
> If this functionality was removed when copying from Abseil, it's probably good to remove the comment as well, to avoid confusion.

Done.

>> Source/WTF/wtf/Int128.h:100
>> +//     float y = absl::UInt128Max();  // Error. UInt128Impl cannot be implicitly
> 
> Probably good to remove `absl::` here and in line 103 as well

Done.

>> Source/WTF/wtf/Int128.h:292
>> +// Additionally, if your compiler supports `__int128`, `Int128Impl` is
> 
> Same as earlier comment.

Done.

>> Source/WTF/wtf/Int128.h:830
>> +#else   // ABSL_HAVE_INTRINSIC128
> 
> This is a bit confusing. Although looking in the original source I see the code is actually correct when you remove the ABSL_HAVE_INTRINSIC128 case, because the MSVC&&x86_64 case was originally an #elif. So no need to change, but maybe consider just removing the comment.

Removed.

>> Tools/TestWebKitAPI/Tests/WTF/Int128.cpp:-79
>> -static void TestVsNative(__uint128_t x, __uint128_t y)
> 
> I would suggest keeping the VsNative tests, and actually adding similar ones for the signed int128. These are probably the best indicator if something is wrong in the implementation. That's what originally alerted me to the Flang implementation's signed int128 operator>> not extending the sign.

Done.
Comment 8 Yusuke Suzuki 2021-10-23 00:29:52 PDT
Created attachment 442255 [details]
Patch
Comment 9 Yusuke Suzuki 2021-10-23 14:15:37 PDT
Comment on attachment 442255 [details]
Patch

Thank you!
Comment 10 EWS 2021-10-23 14:35:34 PDT
Committed r284748 (243457@main): <https://commits.webkit.org/243457@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 442255 [details].
Comment 11 Radar WebKit Bug Importer 2021-10-23 14:36:18 PDT
<rdar://problem/84582748>