Last Comment Bug 685707 - IonMonkey: Implement JSOP_DIV
: IonMonkey: Implement JSOP_DIV
Status: RESOLVED FIXED
:
Product: Core
Classification: Components
Component: JavaScript Engine (show other bugs)
: unspecified
: All All
: -- normal (vote)
: ---
Assigned To: David Anderson [:dvander]
:
Mentors:
Depends on:
Blocks: 684381
  Show dependency treegraph
 
Reported: 2011-09-08 15:46 PDT by David Anderson [:dvander]
Modified: 2011-10-19 11:01 PDT (History)
1 user (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
fix (20.06 KB, patch)
2011-09-08 15:46 PDT, David Anderson [:dvander]
no flags Details | Diff | Splinter Review
v2 (21.60 KB, patch)
2011-09-08 17:58 PDT, David Anderson [:dvander]
sstangl: review+
Details | Diff | Splinter Review

Description David Anderson [:dvander] 2011-09-08 15:46:15 PDT
Need this to run a Mandelbrot benchmark.
Comment 1 David Anderson [:dvander] 2011-09-08 15:46:55 PDT
Created attachment 559311 [details] [diff] [review]
fix
Comment 2 David Anderson [:dvander] 2011-09-08 17:58:24 PDT
Created attachment 559353 [details] [diff] [review]
v2

The original patch broke constant folding.
Comment 3 Sean Stangl [:sstangl] 2011-09-09 01:04:51 PDT
Comment on attachment 559353 [details] [diff] [review]
v2

Review of attachment 559353 [details] [diff] [review]:
-----------------------------------------------------------------

::: js/src/ion/MIR.cpp
@@ +565,5 @@
> +    if (specialization_ == MIRType_None)
> +        return this;
> +
> +    MDefinition *lhs = getOperand(0);
> +    MDefinition *rhs = getOperand(1);

From Bug 685695,
MDefinition *lhs = lhs();
MDefinition *rhs = rhs();

@@ +571,5 @@
> +        return folded;
> +
> +    // 0 / x -> 0
> +    // x / 1 -> x
> +    if (IsConstant(lhs, 0) || IsConstant(rhs, 1))

Also "-0 / x -> -0" and "NaN / x -> NaN", but perhaps these doesn't pass the threshold for usefulness.

It might be more reasonable to handle the NaN case (for all arith) in EvaluateConstantOperands() -- if one of the operands is constant and NaN, the other does not need to be constant for the result to be known.

::: js/src/ion/shared/CodeGenerator-x86-shared.cpp
@@ +453,5 @@
> +{
> +    Register remainder = ToRegister(ins->remainder());
> +    Register lhs = ToRegister(ins->lhs());
> +    Register rhs = ToRegister(ins->rhs());
> +

If we alias %eax to %rax and %edx to %rdx for x64, as in JSC's Assembler, then we can assert that the Registers are as required.

@@ +472,5 @@
> +    // Prevent negative 0.
> +    Label nonzero;
> +    masm.testl(lhs, lhs);
> +    masm.j(Assembler::NonZero, &nonzero);
> +    masm.cmpl(rhs, Imm32(0));

I don't know whether a test on the sign bit should be preferred over cmp in this case, but I suspect cmp is fine.

@@ +483,5 @@
> +    masm.idiv(rhs);
> +
> +    // If the remainder is > 0, bailout since this must be a double.
> +    masm.testl(remainder, remainder);
> +    if (!bailoutIf(Assembler::NonZero, ins->snapshot()))

Having two integer operands and a double result seems like a very common case, but this is fine for now.

::: js/src/ion/shared/LIR-x86-shared.h
@@ +44,5 @@
> +
> +namespace js {
> +namespace ion {
> +
> +class LDivI : public LBinaryMath<1>

LBinaryMath<Temps(1)>, ideally.

::: js/src/ion/x64/Lowering-x64.cpp
@@ +215,5 @@
>  
> +bool
> +LIRGeneratorX64::lowerDivI(MDiv *div)
> +{
> +    LDivI *lir = new LDivI(useFixed(div->lhs(), rax), useRegister(div->lhs()), tempFixed(rdx));

Technically %eax and %edx in the JSC assembler are aliases for %rax and %rdx, respectively, so we could eliminate the duplication via some Lowering-x86-shared.{cpp,h}. The duplication is fine here, though.

::: js/src/jit-test/tests/sunspider/check-math-spectral-norm.js
@@ +4,5 @@
>  // contributed by Ian Osgood
>  
>  function A(i,j) {
> +  //var t = (i+j)*(i+j+1);
> +  //var k = 2+i+1;

Probably not intended for checkin.
Comment 4 David Anderson [:dvander] 2011-09-10 19:24:45 PDT
http://hg.mozilla.org/projects/ionmonkey/rev/e6f9d57d8836

I added the register aliases, but am going to hold off on Lowering-x86-shared until we get more duplication.

> LBinaryMath<Temps(1)>, ideally.

Where Temps is what?

Note You need to log in before you can comment on or make changes to this bug.