Bug 1641471 - [MIPS] Move {round,floor,ceil}-to-int32 to the MacroAssembler. r=tcampbell
authorZhao Jiazhong <zhaojiazhong-hf@loongson.cn>
Thu, 28 May 2020 13:48:51 +0000
changeset 532798 3d3d869180e2fb80611de9994c637ceaabb55563
parent 532797 b5f3c399b4a8420e7588cc8363659a1770112f28
child 532799 c0164e6a62d80e7e0a965fe895406ecaa15d1811
push id117378
push usertcampbell@mozilla.com
push dateThu, 28 May 2020 14:20:23 +0000
treeherderautoland@3d3d869180e2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstcampbell
bugs1641471
milestone78.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1641471 - [MIPS] Move {round,floor,ceil}-to-int32 to the MacroAssembler. r=tcampbell Differential Revision: https://phabricator.services.mozilla.com/D77218
js/src/jit/mips-shared/CodeGenerator-mips-shared.cpp
js/src/jit/mips-shared/MacroAssembler-mips-shared.cpp
--- a/js/src/jit/mips-shared/CodeGenerator-mips-shared.cpp
+++ b/js/src/jit/mips-shared/CodeGenerator-mips-shared.cpp
@@ -1115,278 +1115,16 @@ void CodeGenerator::visitMathF(LMathF* m
     case JSOp::Div:
       masm.as_divs(output, src1, src2);
       break;
     default:
       MOZ_CRASH("unexpected opcode");
   }
 }
 
-void CodeGenerator::visitFloor(LFloor* lir) {
-  FloatRegister input = ToFloatRegister(lir->input());
-  FloatRegister scratch = ScratchDoubleReg;
-  Register output = ToRegister(lir->output());
-
-  Label skipCheck, done;
-
-  // If Nan, 0 or -0 check for bailout
-  masm.loadConstantDouble(0.0, scratch);
-  masm.ma_bc1d(input, scratch, &skipCheck, Assembler::DoubleNotEqual,
-               ShortJump);
-
-  // If high part is not zero, it is NaN or -0, so we bail.
-  masm.moveFromDoubleHi(input, SecondScratchReg);
-  bailoutCmp32(Assembler::NotEqual, SecondScratchReg, Imm32(0),
-               lir->snapshot());
-
-  // Input was zero, so return zero.
-  masm.move32(Imm32(0), output);
-  masm.ma_b(&done, ShortJump);
-
-  masm.bind(&skipCheck);
-  masm.as_floorwd(scratch, input);
-  masm.moveFromDoubleLo(scratch, output);
-
-  bailoutCmp32(Assembler::Equal, output, Imm32(INT_MIN), lir->snapshot());
-  bailoutCmp32(Assembler::Equal, output, Imm32(INT_MAX), lir->snapshot());
-
-  masm.bind(&done);
-}
-
-void CodeGenerator::visitFloorF(LFloorF* lir) {
-  FloatRegister input = ToFloatRegister(lir->input());
-  FloatRegister scratch = ScratchFloat32Reg;
-  Register output = ToRegister(lir->output());
-
-  Label skipCheck, done;
-
-  // If Nan, 0 or -0 check for bailout
-  masm.loadConstantFloat32(0.0f, scratch);
-  masm.ma_bc1s(input, scratch, &skipCheck, Assembler::DoubleNotEqual,
-               ShortJump);
-
-  // If binary value is not zero, it is NaN or -0, so we bail.
-  masm.moveFromDoubleLo(input, SecondScratchReg);
-  bailoutCmp32(Assembler::NotEqual, SecondScratchReg, Imm32(0),
-               lir->snapshot());
-
-  // Input was zero, so return zero.
-  masm.move32(Imm32(0), output);
-  masm.ma_b(&done, ShortJump);
-
-  masm.bind(&skipCheck);
-  masm.as_floorws(scratch, input);
-  masm.moveFromDoubleLo(scratch, output);
-
-  bailoutCmp32(Assembler::Equal, output, Imm32(INT_MIN), lir->snapshot());
-  bailoutCmp32(Assembler::Equal, output, Imm32(INT_MAX), lir->snapshot());
-
-  masm.bind(&done);
-}
-
-void CodeGenerator::visitCeil(LCeil* lir) {
-  FloatRegister input = ToFloatRegister(lir->input());
-  FloatRegister scratch = ScratchDoubleReg;
-  Register output = ToRegister(lir->output());
-
-  Label performCeil, done;
-
-  // If x < -1 or x > 0 then perform ceil.
-  masm.loadConstantDouble(0, scratch);
-  masm.branchDouble(Assembler::DoubleGreaterThan, input, scratch, &performCeil);
-  masm.loadConstantDouble(-1, scratch);
-  masm.branchDouble(Assembler::DoubleLessThanOrEqual, input, scratch,
-                    &performCeil);
-
-  // If high part is not zero, the input was not 0, so we bail.
-  masm.moveFromDoubleHi(input, SecondScratchReg);
-  bailoutCmp32(Assembler::NotEqual, SecondScratchReg, Imm32(0),
-               lir->snapshot());
-
-  // Input was zero, so return zero.
-  masm.move32(Imm32(0), output);
-  masm.ma_b(&done, ShortJump);
-
-  masm.bind(&performCeil);
-  masm.as_ceilwd(scratch, input);
-  masm.moveFromDoubleLo(scratch, output);
-
-  bailoutCmp32(Assembler::Equal, output, Imm32(INT_MIN), lir->snapshot());
-  bailoutCmp32(Assembler::Equal, output, Imm32(INT_MAX), lir->snapshot());
-
-  masm.bind(&done);
-}
-
-void CodeGenerator::visitCeilF(LCeilF* lir) {
-  FloatRegister input = ToFloatRegister(lir->input());
-  FloatRegister scratch = ScratchFloat32Reg;
-  Register output = ToRegister(lir->output());
-
-  Label performCeil, done;
-
-  // If x < -1 or x > 0 then perform ceil.
-  masm.loadConstantFloat32(0.0f, scratch);
-  masm.branchFloat(Assembler::DoubleGreaterThan, input, scratch, &performCeil);
-  masm.loadConstantFloat32(-1.0f, scratch);
-  masm.branchFloat(Assembler::DoubleLessThanOrEqual, input, scratch,
-                   &performCeil);
-
-  // If binary value is not zero, the input was not 0, so we bail.
-  masm.moveFromFloat32(input, SecondScratchReg);
-  bailoutCmp32(Assembler::NotEqual, SecondScratchReg, Imm32(0),
-               lir->snapshot());
-
-  // Input was zero, so return zero.
-  masm.move32(Imm32(0), output);
-  masm.ma_b(&done, ShortJump);
-
-  masm.bind(&performCeil);
-  masm.as_ceilws(scratch, input);
-  masm.moveFromFloat32(scratch, output);
-
-  bailoutCmp32(Assembler::Equal, output, Imm32(INT_MIN), lir->snapshot());
-  bailoutCmp32(Assembler::Equal, output, Imm32(INT_MAX), lir->snapshot());
-
-  masm.bind(&done);
-}
-
-void CodeGenerator::visitRound(LRound* lir) {
-  FloatRegister input = ToFloatRegister(lir->input());
-  FloatRegister temp = ToFloatRegister(lir->temp());
-  FloatRegister scratch = ScratchDoubleReg;
-  Register output = ToRegister(lir->output());
-
-  Label bail, negative, end, skipCheck;
-
-  // Load biggest number less than 0.5 in the temp register.
-  masm.loadConstantDouble(GetBiggestNumberLessThan(0.5), temp);
-
-  // Branch to a slow path for negative inputs. Doesn't catch NaN or -0.
-  masm.loadConstantDouble(0.0, scratch);
-  masm.ma_bc1d(input, scratch, &negative, Assembler::DoubleLessThan, ShortJump);
-
-  // If Nan, 0 or -0 check for bailout
-  masm.ma_bc1d(input, scratch, &skipCheck, Assembler::DoubleNotEqual,
-               ShortJump);
-
-  // If high part is not zero, it is NaN or -0, so we bail.
-  masm.moveFromDoubleHi(input, SecondScratchReg);
-  bailoutCmp32(Assembler::NotEqual, SecondScratchReg, Imm32(0),
-               lir->snapshot());
-
-  // Input was zero, so return zero.
-  masm.move32(Imm32(0), output);
-  masm.ma_b(&end, ShortJump);
-
-  masm.bind(&skipCheck);
-  masm.as_addd(scratch, input, temp);
-  masm.as_floorwd(scratch, scratch);
-
-  masm.moveFromDoubleLo(scratch, output);
-
-  bailoutCmp32(Assembler::Equal, output, Imm32(INT_MIN), lir->snapshot());
-  bailoutCmp32(Assembler::Equal, output, Imm32(INT_MAX), lir->snapshot());
-
-  masm.jump(&end);
-
-  // Input is negative, but isn't -0.
-  masm.bind(&negative);
-
-  // Inputs in ]-0.5; 0] need to be added 0.5, other negative inputs need to
-  // be added the biggest double less than 0.5.
-  Label loadJoin;
-  masm.loadConstantDouble(-0.5, scratch);
-  masm.branchDouble(Assembler::DoubleLessThan, input, scratch, &loadJoin);
-  masm.loadConstantDouble(0.5, temp);
-  masm.bind(&loadJoin);
-
-  masm.addDouble(input, temp);
-
-  // If input + 0.5 >= 0, input is a negative number >= -0.5 and the
-  // result is -0.
-  masm.branchDouble(Assembler::DoubleGreaterThanOrEqual, temp, scratch, &bail);
-  bailoutFrom(&bail, lir->snapshot());
-
-  // Truncate and round toward zero.
-  // This is off-by-one for everything but integer-valued inputs.
-  masm.as_floorwd(scratch, temp);
-  masm.moveFromDoubleLo(scratch, output);
-
-  bailoutCmp32(Assembler::Equal, output, Imm32(INT_MIN), lir->snapshot());
-
-  masm.bind(&end);
-}
-
-void CodeGenerator::visitRoundF(LRoundF* lir) {
-  FloatRegister input = ToFloatRegister(lir->input());
-  FloatRegister temp = ToFloatRegister(lir->temp());
-  FloatRegister scratch = ScratchFloat32Reg;
-  Register output = ToRegister(lir->output());
-
-  Label bail, negative, end, skipCheck;
-
-  // Load biggest number less than 0.5 in the temp register.
-  masm.loadConstantFloat32(GetBiggestNumberLessThan(0.5f), temp);
-
-  // Branch to a slow path for negative inputs. Doesn't catch NaN or -0.
-  masm.loadConstantFloat32(0.0f, scratch);
-  masm.ma_bc1s(input, scratch, &negative, Assembler::DoubleLessThan, ShortJump);
-
-  // If Nan, 0 or -0 check for bailout
-  masm.ma_bc1s(input, scratch, &skipCheck, Assembler::DoubleNotEqual,
-               ShortJump);
-
-  // If binary value is not zero, it is NaN or -0, so we bail.
-  masm.moveFromFloat32(input, SecondScratchReg);
-  bailoutCmp32(Assembler::NotEqual, SecondScratchReg, Imm32(0),
-               lir->snapshot());
-
-  // Input was zero, so return zero.
-  masm.move32(Imm32(0), output);
-  masm.ma_b(&end, ShortJump);
-
-  masm.bind(&skipCheck);
-  masm.as_adds(scratch, input, temp);
-  masm.as_floorws(scratch, scratch);
-
-  masm.moveFromFloat32(scratch, output);
-
-  bailoutCmp32(Assembler::Equal, output, Imm32(INT_MIN), lir->snapshot());
-  bailoutCmp32(Assembler::Equal, output, Imm32(INT_MAX), lir->snapshot());
-
-  masm.jump(&end);
-
-  // Input is negative, but isn't -0.
-  masm.bind(&negative);
-
-  // Inputs in ]-0.5; 0] need to be added 0.5, other negative inputs need to
-  // be added the biggest double less than 0.5.
-  Label loadJoin;
-  masm.loadConstantFloat32(-0.5f, scratch);
-  masm.branchFloat(Assembler::DoubleLessThan, input, scratch, &loadJoin);
-  masm.loadConstantFloat32(0.5f, temp);
-  masm.bind(&loadJoin);
-
-  masm.as_adds(temp, input, temp);
-
-  // If input + 0.5 >= 0, input is a negative number >= -0.5 and the
-  // result is -0.
-  masm.branchFloat(Assembler::DoubleGreaterThanOrEqual, temp, scratch, &bail);
-  bailoutFrom(&bail, lir->snapshot());
-
-  // Truncate and round toward zero.
-  // This is off-by-one for everything but integer-valued inputs.
-  masm.as_floorws(scratch, temp);
-  masm.moveFromFloat32(scratch, output);
-
-  bailoutCmp32(Assembler::Equal, output, Imm32(INT_MIN), lir->snapshot());
-
-  masm.bind(&end);
-}
-
 void CodeGenerator::visitTrunc(LTrunc* lir) {
   FloatRegister input = ToFloatRegister(lir->input());
   Register output = ToRegister(lir->output());
 
   Label notZero;
   masm.as_truncwd(ScratchFloat32Reg, input);
   masm.as_cfc1(ScratchRegister, Assembler::FCSR);
   masm.moveFromFloat32(ScratchFloat32Reg, output);
--- a/js/src/jit/mips-shared/MacroAssembler-mips-shared.cpp
+++ b/js/src/jit/mips-shared/MacroAssembler-mips-shared.cpp
@@ -2851,37 +2851,247 @@ void MacroAssembler::patchNearAddressMov
 
 // ========================================================================
 // Spectre Mitigations.
 
 void MacroAssembler::speculationBarrier() { MOZ_CRASH(); }
 
 void MacroAssembler::floorFloat32ToInt32(FloatRegister src, Register dest,
                                          Label* fail) {
-  MOZ_CRASH("Port CodeGenerator::visitFloorF code");
+  ScratchFloat32Scope scratch(*this);
+
+  Label skipCheck, done;
+
+  // If Nan, 0 or -0 check for bailout
+  loadConstantFloat32(0.0f, scratch);
+  ma_bc1s(src, scratch, &skipCheck, Assembler::DoubleNotEqual, ShortJump);
+
+  // If binary value is not zero, it is NaN or -0, so we bail.
+  moveFromDoubleLo(src, SecondScratchReg);
+  branch32(Assembler::NotEqual, SecondScratchReg, Imm32(0), fail);
+
+  // Input was zero, so return zero.
+  move32(Imm32(0), dest);
+  ma_b(&done, ShortJump);
+
+  bind(&skipCheck);
+  as_floorws(scratch, src);
+  moveFromDoubleLo(scratch, dest);
+
+  branch32(Assembler::Equal, dest, Imm32(INT_MIN), fail);
+  branch32(Assembler::Equal, dest, Imm32(INT_MAX), fail);
+
+  bind(&done);
 }
 
 void MacroAssembler::floorDoubleToInt32(FloatRegister src, Register dest,
                                         Label* fail) {
-  MOZ_CRASH("Port CodeGenerator::visitFloor code");
+  ScratchDoubleScope scratch(*this);
+
+  Label skipCheck, done;
+
+  // If Nan, 0 or -0 check for bailout
+  loadConstantDouble(0.0, scratch);
+  ma_bc1d(src, scratch, &skipCheck, Assembler::DoubleNotEqual, ShortJump);
+
+  // If high part is not zero, it is NaN or -0, so we bail.
+  moveFromDoubleHi(src, SecondScratchReg);
+  branch32(Assembler::NotEqual, SecondScratchReg, Imm32(0), fail);
+
+  // Input was zero, so return zero.
+  move32(Imm32(0), dest);
+  ma_b(&done, ShortJump);
+
+  bind(&skipCheck);
+  as_floorwd(scratch, src);
+  moveFromDoubleLo(scratch, dest);
+
+  branch32(Assembler::Equal, dest, Imm32(INT_MIN), fail);
+  branch32(Assembler::Equal, dest, Imm32(INT_MAX), fail);
+
+  bind(&done);
 }
 
 void MacroAssembler::ceilFloat32ToInt32(FloatRegister src, Register dest,
                                         Label* fail) {
-  MOZ_CRASH("Port CodeGenerator::visitCeilF code");
+  ScratchFloat32Scope scratch(*this);
+
+  Label performCeil, done;
+
+  // If x < -1 or x > 0 then perform ceil.
+  loadConstantFloat32(0.0f, scratch);
+  branchFloat(Assembler::DoubleGreaterThan, src, scratch, &performCeil);
+  loadConstantFloat32(-1.0f, scratch);
+  branchFloat(Assembler::DoubleLessThanOrEqual, src, scratch, &performCeil);
+
+  // If binary value is not zero, the input was not 0, so we bail.
+  moveFromFloat32(src, SecondScratchReg);
+  branch32(Assembler::NotEqual, SecondScratchReg, Imm32(0), fail);
+
+  // Input was zero, so return zero.
+  move32(Imm32(0), dest);
+  ma_b(&done, ShortJump);
+
+  bind(&performCeil);
+  as_ceilws(scratch, src);
+  moveFromFloat32(scratch, dest);
+
+  branch32(Assembler::Equal, dest, Imm32(INT_MIN), fail);
+  branch32(Assembler::Equal, dest, Imm32(INT_MAX), fail);
+
+  bind(&done);
 }
 
 void MacroAssembler::ceilDoubleToInt32(FloatRegister src, Register dest,
                                        Label* fail) {
-  MOZ_CRASH("Port CodeGenerator::visitCeil code");
+  ScratchDoubleScope scratch(*this);
+
+  Label performCeil, done;
+
+  // If x < -1 or x > 0 then perform ceil.
+  loadConstantDouble(0, scratch);
+  branchDouble(Assembler::DoubleGreaterThan, src, scratch, &performCeil);
+  loadConstantDouble(-1, scratch);
+  branchDouble(Assembler::DoubleLessThanOrEqual, src, scratch, &performCeil);
+
+  // If high part is not zero, the input was not 0, so we bail.
+  moveFromDoubleHi(src, SecondScratchReg);
+  branch32(Assembler::NotEqual, SecondScratchReg, Imm32(0), fail);
+
+  // Input was zero, so return zero.
+  move32(Imm32(0), dest);
+  ma_b(&done, ShortJump);
+
+  bind(&performCeil);
+  as_ceilwd(scratch, src);
+  moveFromDoubleLo(scratch, dest);
+
+  branch32(Assembler::Equal, dest, Imm32(INT_MIN), fail);
+  branch32(Assembler::Equal, dest, Imm32(INT_MAX), fail);
+
+  bind(&done);
 }
 
 void MacroAssembler::roundFloat32ToInt32(FloatRegister src, Register dest,
                                          FloatRegister temp, Label* fail) {
-  MOZ_CRASH("Port CodeGenerator::visitRoundF code");
+  ScratchFloat32Scope scratch(*this);
+
+  Label negative, end, skipCheck;
+
+  // Load biggest number less than 0.5 in the temp register.
+  loadConstantFloat32(GetBiggestNumberLessThan(0.5f), temp);
+
+  // Branch to a slow path for negative inputs. Doesn't catch NaN or -0.
+  loadConstantFloat32(0.0f, scratch);
+  ma_bc1s(src, scratch, &negative, Assembler::DoubleLessThan, ShortJump);
+
+  // If Nan, 0 or -0 check for bailout
+  ma_bc1s(src, scratch, &skipCheck, Assembler::DoubleNotEqual, ShortJump);
+
+  // If binary value is not zero, it is NaN or -0, so we bail.
+  moveFromFloat32(src, SecondScratchReg);
+  branch32(Assembler::NotEqual, SecondScratchReg, Imm32(0), fail);
+
+  // Input was zero, so return zero.
+  move32(Imm32(0), dest);
+  ma_b(&end, ShortJump);
+
+  bind(&skipCheck);
+  as_adds(scratch, src, temp);
+  as_floorws(scratch, scratch);
+
+  moveFromFloat32(scratch, dest);
+
+  branchTest32(Assembler::Equal, dest, Imm32(INT_MIN), fail);
+  branchTest32(Assembler::Equal, dest, Imm32(INT_MAX), fail);
+
+  jump(&end);
+
+  // Input is negative, but isn't -0.
+  bind(&negative);
+
+  // Inputs in ]-0.5; 0] need to be added 0.5, other negative inputs need to
+  // be added the biggest double less than 0.5.
+  Label loadJoin;
+  loadConstantFloat32(-0.5f, scratch);
+  branchFloat(Assembler::DoubleLessThan, src, scratch, &loadJoin);
+  loadConstantFloat32(0.5f, temp);
+  bind(&loadJoin);
+
+  as_adds(temp, src, temp);
+
+  // If input + 0.5 >= 0, input is a negative number >= -0.5 and the
+  // result is -0.
+  branchFloat(Assembler::DoubleGreaterThanOrEqual, temp, scratch, fail);
+
+  // Truncate and round toward zero.
+  // This is off-by-one for everything but integer-valued inputs.
+  as_floorws(scratch, temp);
+  moveFromFloat32(scratch, dest);
+
+  branch32(Assembler::Equal, dest, Imm32(INT_MIN), fail);
+
+  bind(&end);
 }
 
 void MacroAssembler::roundDoubleToInt32(FloatRegister src, Register dest,
                                         FloatRegister temp, Label* fail) {
-  MOZ_CRASH("Port CodeGenerator::visitRound code");
+  ScratchDoubleScope scratch(*this);
+
+  Label negative, end, skipCheck;
+
+  // Load biggest number less than 0.5 in the temp register.
+  loadConstantDouble(GetBiggestNumberLessThan(0.5), temp);
+
+  // Branch to a slow path for negative inputs. Doesn't catch NaN or -0.
+  loadConstantDouble(0.0, scratch);
+  ma_bc1d(src, scratch, &negative, Assembler::DoubleLessThan, ShortJump);
+
+  // If Nan, 0 or -0 check for bailout
+  ma_bc1d(src, scratch, &skipCheck, Assembler::DoubleNotEqual, ShortJump);
+
+  // If high part is not zero, it is NaN or -0, so we bail.
+  moveFromDoubleHi(src, SecondScratchReg);
+  branch32(Assembler::NotEqual, SecondScratchReg, Imm32(0), fail);
+
+  // Input was zero, so return zero.
+  move32(Imm32(0), dest);
+  ma_b(&end, ShortJump);
+
+  bind(&skipCheck);
+  as_addd(scratch, src, temp);
+  as_floorwd(scratch, scratch);
+
+  moveFromDoubleLo(scratch, dest);
+
+  branch32(Assembler::Equal, dest, Imm32(INT_MIN), fail);
+  branch32(Assembler::Equal, dest, Imm32(INT_MAX), fail);
+
+  jump(&end);
+
+  // Input is negative, but isn't -0.
+  bind(&negative);
+
+  // Inputs in ]-0.5; 0] need to be added 0.5, other negative inputs need to
+  // be added the biggest double less than 0.5.
+  Label loadJoin;
+  loadConstantDouble(-0.5, scratch);
+  branchDouble(Assembler::DoubleLessThan, src, scratch, &loadJoin);
+  loadConstantDouble(0.5, temp);
+  bind(&loadJoin);
+
+  addDouble(src, temp);
+
+  // If input + 0.5 >= 0, input is a negative number >= -0.5 and the
+  // result is -0.
+  branchDouble(Assembler::DoubleGreaterThanOrEqual, temp, scratch, fail);
+
+  // Truncate and round toward zero.
+  // This is off-by-one for everything but integer-valued inputs.
+  as_floorwd(scratch, temp);
+  moveFromDoubleLo(scratch, dest);
+
+  branch32(Assembler::Equal, dest, Imm32(INT_MIN), fail);
+
+  bind(&end);
 }
 
 //}}} check_macroassembler_style