Bug 212385 - Add some new emitters to the X86_64 and ARM64 MacroAssemblers.
Summary: Add some new emitters to the X86_64 and ARM64 MacroAssemblers.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Mark Lam
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-05-26 13:59 PDT by Mark Lam
Modified: 2020-05-26 16:38 PDT (History)
7 users (show)

See Also:


Attachments
proposed patch. (14.34 KB, patch)
2020-05-26 14:38 PDT, Mark Lam
rmorisset: review+
Details | Formatted Diff | Diff
patch for landing. (15.67 KB, patch)
2020-05-26 16:17 PDT, Mark Lam
no flags Details | Formatted Diff | Diff
patch for landing. (15.83 KB, patch)
2020-05-26 16:23 PDT, Mark Lam
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Lam 2020-05-26 13:59:16 PDT
Specifically, these:
    clearBit64
    clearBits64WithMask
    countTrailingZeros64WithoutNullCheck

clearBit64 provides a faster way to clear a bit without having to a shift to make a mask first.
clearBits64WithMask does the equivalent of and64 with the 1's complement of the provided mask.
countTrailingZeros64WithoutNullCheck does the same thing as countTrailingZeros64, except that it assumes that the word in the register it is processing will never be null, and therefore skips the null check.  This is useful in code that already does a null check ahead of time.  So, there's no need to do a redundant null check.
Comment 1 Mark Lam 2020-05-26 14:33:32 PDT
(In reply to Mark Lam from comment #0)
> clearBit64 provides a faster way to clear a bit without having to a shift to
> make a mask first.

Correction: clearBit64 will emit the shift to make the mask.
Comment 2 Mark Lam 2020-05-26 14:38:54 PDT
Created attachment 400277 [details]
proposed patch.
Comment 3 Radar WebKit Bug Importer 2020-05-26 14:40:20 PDT
<rdar://problem/63642626>
Comment 4 Saam Barati 2020-05-26 14:47:33 PDT
Comment on attachment 400277 [details]
proposed patch.

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

> Source/JavaScriptCore/ChangeLog:16
> +        clearBits64WithMask does the equivalent of and64 with the 1's complement of the
> +        provided mask.

feels weird to call this a "mask" when we're really using ~mask
Comment 5 Mark Lam 2020-05-26 15:02:35 PDT
Comment on attachment 400277 [details]
proposed patch.

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

>> Source/JavaScriptCore/ChangeLog:16
>> +        provided mask.
> 
> feels weird to call this a "mask" when we're really using ~mask

It is a mask: one that defines the bits to clear instead of the bits to keep (as is the case with and64).  I'm open to an alternate term if you can think of anything better.
Comment 6 Robin Morisset 2020-05-26 15:06:29 PDT
Comment on attachment 400277 [details]
proposed patch.

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

r=me

> Source/JavaScriptCore/ChangeLog:22
> +        redundant null check.

Do we have any way of easily inserting an assert in the generated code when in debug? It could be useful for these kind of things.

> Source/JavaScriptCore/assembler/testmasm.cpp:474
> +    auto test = compile([=] (CCallHelpers& jit) {

what are you capturing by copy and why?
Comment 7 Mark Lam 2020-05-26 15:15:03 PDT
Comment on attachment 400277 [details]
proposed patch.

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

>> Source/JavaScriptCore/ChangeLog:22
>> +        redundant null check.
> 
> Do we have any way of easily inserting an assert in the generated code when in debug? It could be useful for these kind of things.

Hmmm,  I'll see if it's easy to do.  If not, I'll do it in another patch.

>> Source/JavaScriptCore/assembler/testmasm.cpp:474
>> +    auto test = compile([=] (CCallHelpers& jit) {
> 
> what are you capturing by copy and why?

Copy paste error.  I'll remove the '='.

> Source/JavaScriptCore/assembler/testmasm.cpp:501
> +    auto test = compile([=] (CCallHelpers& jit) {

Ditto.

> Source/JavaScriptCore/assembler/testmasm.cpp:555
> +    auto test = compile([=] (CCallHelpers& jit) {

Ditto.
Comment 8 Mark Lam 2020-05-26 16:16:18 PDT
(In reply to Mark Lam from comment #7)
> >> Source/JavaScriptCore/ChangeLog:22
> >> +        redundant null check.
> > 
> > Do we have any way of easily inserting an assert in the generated code when in debug? It could be useful for these kind of things.
> 
> Hmmm,  I'll see if it's easy to do.  If not, I'll do it in another patch.

I've added an assertion check.
Comment 9 Mark Lam 2020-05-26 16:17:03 PDT
Created attachment 400284 [details]
patch for landing.

Thanks for the review.  Here's the updated patch for landing.
Comment 10 Robin Morisset 2020-05-26 16:18:32 PDT
(In reply to Mark Lam from comment #8)
> (In reply to Mark Lam from comment #7)
> > >> Source/JavaScriptCore/ChangeLog:22
> > >> +        redundant null check.
> > > 
> > > Do we have any way of easily inserting an assert in the generated code when in debug? It could be useful for these kind of things.
> > 
> > Hmmm,  I'll see if it's easy to do.  If not, I'll do it in another patch.
> 
> I've added an assertion check.

Great, thanks!
Comment 11 Mark Lam 2020-05-26 16:23:50 PDT
Created attachment 400285 [details]
patch for landing.

Also added the assertion to MacroAssemblerARM64 as well.  ARM64 doesn't really need the check because it's implementation will always have correctly even if the word is 0.  However, it's good to have the assertion consistently to help catch logic errors in the client that break this invariant.
Comment 12 Mark Lam 2020-05-26 16:38:13 PDT
Landed in r262168: <http://trac.webkit.org/r262168>.