Bug 234408 - [JSC] OpPow should have a "small int exponent" fast path at lower tiers
Summary: [JSC] OpPow should have a "small int exponent" fast path at lower tiers
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Ross Kirsling
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-12-16 15:27 PST by Ross Kirsling
Modified: 2021-12-19 00:35 PST (History)
8 users (show)

See Also:


Attachments
Patch (6.45 KB, patch)
2021-12-16 15:31 PST, Ross Kirsling
no flags Details | Formatted Diff | Diff
Patch (12.43 KB, patch)
2021-12-16 18:16 PST, Ross Kirsling
no flags Details | Formatted Diff | Diff
Patch (12.43 KB, patch)
2021-12-16 20:50 PST, Ross Kirsling
no flags Details | Formatted Diff | Diff
Patch (12.49 KB, patch)
2021-12-16 21:35 PST, Ross Kirsling
no flags Details | Formatted Diff | Diff
Patch for landing (12.36 KB, patch)
2021-12-18 23:17 PST, Ross Kirsling
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ross Kirsling 2021-12-16 15:27:02 PST
[JSC] OpPow should have a "small int exponent" fast path at lower tiers
Comment 1 Ross Kirsling 2021-12-16 15:31:53 PST
Created attachment 447395 [details]
Patch
Comment 2 Yusuke Suzuki 2021-12-16 15:34:00 PST
Comment on attachment 447395 [details]
Patch

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

> Source/JavaScriptCore/llint/LowLevelInterpreter32_64.asm:1120
> +    bigt t1, 1000, .slow

Let's define 1000 as a constant in C++. And use `constexpr XXX` here. And in power implementation, we should use that constant too.
Comment 3 Ross Kirsling 2021-12-16 18:16:17 PST
Created attachment 447406 [details]
Patch
Comment 4 Ross Kirsling 2021-12-16 20:50:07 PST
Created attachment 447418 [details]
Patch
Comment 5 Ross Kirsling 2021-12-16 21:35:26 PST
Created attachment 447425 [details]
Patch
Comment 6 Ross Kirsling 2021-12-16 22:07:18 PST
Comment on attachment 447425 [details]
Patch

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

A couple of notes.

> Source/JavaScriptCore/jit/JITArithmetic.cpp:496
> +    addSlowCase(branch32(GreaterThan, rightRegs.payloadGPR(), TrustedImm32(maxExponentForIntegerMathPow)));

I do wonder if maxExponentForIntegerMathPow should be 1024 instead of 1000. It hardly matters but it seems weird to use a base-10 threshold for bitshifting.

> Source/JavaScriptCore/jit/JITArithmetic.cpp:-964
> -/* ------------------------------ END: OP_ADD, OP_SUB, OP_MUL, OP_POW ------------------------------ */

(Removing this since it's an END with no BEGIN and this file has not had an OP_POW.)
Comment 7 Ross Kirsling 2021-12-16 22:07:20 PST Comment hidden (obsolete)
Comment 8 Yusuke Suzuki 2021-12-18 22:14:26 PST
Comment on attachment 447425 [details]
Patch

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

r=me

> Source/JavaScriptCore/llint/LowLevelInterpreter64.asm:1341
> +    addq numberTag, t0

What is the purpose of this addition? t0 is already 1, so just ci2ds is fine (it is not boxed double etc.).

> JSTests/microbenchmarks/pow-double-int.js:7
> +for (let i = -50; i <= 50; i += 0.1)
> +    for (let j = 0; j <= 1000; j++) 
> +        exponentiate(i, j);

Can you add a test case getting Infinity, -Infinity, and NaN for double input?
Comment 9 Ross Kirsling 2021-12-18 23:16:29 PST
(In reply to Yusuke Suzuki from comment #8)
> > Source/JavaScriptCore/llint/LowLevelInterpreter64.asm:1341
> > +    addq numberTag, t0
> 
> What is the purpose of this addition? t0 is already 1, so just ci2ds is fine
> (it is not boxed double etc.).

Thanks for pointing this out -- I assumed that I needed it in order to do a double calculation with an immediate, but apparently I was wrong.

> > JSTests/microbenchmarks/pow-double-int.js:7
> > +for (let i = -50; i <= 50; i += 0.1)
> > +    for (let j = 0; j <= 1000; j++) 
> > +        exponentiate(i, j);
> 
> Can you add a test case getting Infinity, -Infinity, and NaN for double
> input?

I think this is covered by the following:
stress/pow-nan-behaviors.js
stress/pow-with-constants.js

But let me know if we need more.
Comment 10 Ross Kirsling 2021-12-18 23:17:00 PST
Created attachment 447541 [details]
Patch for landing
Comment 11 EWS 2021-12-19 00:34:19 PST
Committed r287236 (245396@main): <https://commits.webkit.org/245396@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 447541 [details].
Comment 12 Radar WebKit Bug Importer 2021-12-19 00:35:19 PST
<rdar://problem/86680069>