Optimize Math.pow in CacheIR and Warp
Categories
(Core :: JavaScript Engine: JIT, task, P3)
Tracking
()
Tracking | Status | |
---|---|---|
firefox79 | --- | fixed |
People
(Reporter: jandem, Assigned: jandem)
References
(Blocks 1 open bug)
Details
Attachments
(5 files)
Assignee | ||
Comment 1•5 years ago
•
|
||
For Math.pow and JSOp::Pow we could do something like this:
- (double, int32) => call powi (like Ion)
- (int32 or double, double) => call ecmaPow (like Ion)
For (int32, int32), we could write a C++ function that does exactly the same thing as MacroAssembler::pow32
. Then we can call that in CacheIR.cpp and if it succeeds we go with MacroAssembler::pow32
, else we go with the (double, int32) path.
Does that make sense to you?
Assignee | ||
Comment 2•5 years ago
|
||
I'm proposing we don't optimize (int32, int32) in IonBuilder, to avoid the bailout issue discussed elsewhere. For CacheIR and Warp, as long as CacheIR.cpp, CacheIRCompiler and MIR codegen agree, we're good.
Comment 3•5 years ago
|
||
So for the (int32, int32) -> int32
case, when the exponent gets negative after Warp compilation, we still have to bail out, but CacheIR will then recompile and switch to use either (double, int32) -> powi
or (int32, double) -> ecmaPow
, depending on whether we have a large or small negative exponent? Or alternatively always switch to (int32, double) -> ecmaPow
, because a large negative exponent should be rare.
Comment 4•5 years ago
|
||
(Or instead of a bailout, there's a GuardNonNegativeInt32
CacheIR op.)
Assignee | ||
Comment 5•5 years ago
|
||
So for the (int32, int32) -> int32
optimization, we could have exponent >= 0 && NumberIsInt32(powi(base, exponent))
as condition and then there shouldn't be any bailout issues from masm.pow32
? That would be nice..
Comment 6•5 years ago
|
||
Yes. When we only attach (int32, int32) -> int32
for exponent >= 0 && NumberIsInt32(powi(base, exponent))
in CacheIR.cpp, and then also use a GuardNonNegativeInt32
op, the only case we have to bail is when there's an int32 overflow, but that means we need to recompile to double
anyway. (MacroAssembler::pow32
currently takes the failure path for both exponent < 0
and int32 overflow.)
MacroAssembler::pow32
doesn't take the failure path for exponent < 0
when base = 1
, but not using the (int32, int32) -> int32
optimisation for that case shouldn't really matter. :-)
Updated•5 years ago
|
Assignee | ||
Comment 7•4 years ago
|
||
Assignee | ||
Comment 8•4 years ago
|
||
Depends on D77775
Assignee | ||
Comment 9•4 years ago
|
||
Remove the specialization_ field and the powerType use. Use the return type instead.
For now we only use the Double specialization, although this already adds the
TypePolicy code for Int32 specialization.
Depends on D77776
Assignee | ||
Comment 10•4 years ago
|
||
Code mostly written by André Bargull for bug 1564942.
Depends on D77777
Assignee | ||
Comment 11•4 years ago
|
||
Depends on D77778
Comment 12•4 years ago
|
||
Comment 13•4 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/e1f9ababe0d2
https://hg.mozilla.org/mozilla-central/rev/1654b08e4fbd
https://hg.mozilla.org/mozilla-central/rev/0294692dcbe0
https://hg.mozilla.org/mozilla-central/rev/b4e9103ffa2e
https://hg.mozilla.org/mozilla-central/rev/b445193d595b
Description
•