Closed Bug 1640587 Opened 5 years ago Closed 4 years ago

Optimize Math.pow in CacheIR and Warp

Categories

(Core :: JavaScript Engine: JIT, task, P3)

task

Tracking

()

RESOLVED FIXED
mozilla79
Tracking Status
firefox79 --- fixed

People

(Reporter: jandem, Assigned: jandem)

References

(Blocks 1 open bug)

Details

Attachments

(5 files)

No description provided.

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?

Flags: needinfo?(andrebargull)

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.

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.

Flags: needinfo?(andrebargull)

(Or instead of a bailout, there's a GuardNonNegativeInt32 CacheIR op.)

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..

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. :-)

Severity: normal → N/A
Priority: -- → P3

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

Code mostly written by André Bargull for bug 1564942.

Depends on D77777

Depends on D77778

Pushed by jdemooij@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/e1f9ababe0d2 part 1 - Use DoublePowResult for Math.pow(number, number). r=anba https://hg.mozilla.org/integration/autoland/rev/1654b08e4fbd part 2 - Use Int32PowResult for Math.pow on two int32 values when possible. r=anba https://hg.mozilla.org/integration/autoland/rev/0294692dcbe0 part 3 - Refactor MPow type policy. r=anba https://hg.mozilla.org/integration/autoland/rev/b4e9103ffa2e part 4 - Add Int32 specialization for MPow. r=anba https://hg.mozilla.org/integration/autoland/rev/b445193d595b part 5 - Transpile Int32PowResult. r=anba
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: