From 9aa36719a4a82a9b910894f4681a397d889cec09 Mon Sep 17 00:00:00 2001 From: Heiher Date: Wed, 30 Sep 2015 07:03:10 +0800 Subject: [PATCH] Bug 1205232 - IonMonkey: MIPS32: Fix rounding of big negative float32 values in Ion. r=bbouvier --- js/src/jit/mips32/CodeGenerator-mips32.cpp | 32 ++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) --- js/src/jit/mips32/CodeGenerator-mips32.cpp | 32 ++++++++++++++++------ 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/js/src/jit/mips32/CodeGenerator-mips32.cpp b/js/src/jit/mips32/CodeGenerator-mips32.cpp index da3efa7eaf2..f60dc0786e9 100644 --- a/js/src/jit/mips32/CodeGenerator-mips32.cpp +++ b/js/src/jit/mips32/CodeGenerator-mips32.cpp @@ -1202,8 +1202,8 @@ CodeGeneratorMIPS::visitRound(LRound* lir) Label bail, negative, end, skipCheck; - // Load 0.5 in the temp register. - masm.loadConstantDouble(0.5, temp); + // 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); @@ -1221,8 +1221,7 @@ CodeGeneratorMIPS::visitRound(LRound* lir) masm.ma_b(&end, ShortJump); masm.bind(&skipCheck); - masm.loadConstantDouble(0.5, scratch); - masm.addDouble(input, scratch); + masm.as_addd(scratch, input, temp); masm.as_floorwd(scratch, scratch); masm.moveFromDoubleLo(scratch, output); @@ -1234,6 +1233,15 @@ CodeGeneratorMIPS::visitRound(LRound* lir) // 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 @@ -1261,8 +1269,8 @@ CodeGeneratorMIPS::visitRoundF(LRoundF* lir) Label bail, negative, end, skipCheck; - // Load 0.5 in the temp register. - masm.loadConstantFloat32(0.5, temp); + // 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); @@ -1280,8 +1288,7 @@ CodeGeneratorMIPS::visitRoundF(LRoundF* lir) masm.ma_b(&end, ShortJump); masm.bind(&skipCheck); - masm.loadConstantFloat32(0.5, scratch); - masm.as_adds(scratch, input, scratch); + masm.as_adds(scratch, input, temp); masm.as_floorws(scratch, scratch); masm.moveFromFloat32(scratch, output); @@ -1293,6 +1300,15 @@ CodeGeneratorMIPS::visitRoundF(LRoundF* lir) // 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