Bug 910796 - SpiderMonkey: Micro-optimize clampIntToUint8. r=mjrosenb
authorDan Gohman <sunfish@google.com>
Wed, 11 Sep 2013 08:35:38 -0700
changeset 159480 3d9f3a2e90f4085844108ff59711cc0420cd35d5
parent 159479 14ade51fe8bae470a023aca6b97961e7fc81de3f
child 159481 db83498e31f030c93579d019b628e0b8ce803d62
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmjrosenb
bugs910796
milestone26.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 910796 - SpiderMonkey: Micro-optimize clampIntToUint8. r=mjrosenb
js/src/jit/BaselineIC.cpp
js/src/jit/CodeGenerator.cpp
js/src/jit/IonMacroAssembler.cpp
js/src/jit/Lowering.cpp
js/src/jit/arm/MacroAssembler-arm.h
js/src/jit/shared/MacroAssembler-x86-shared.h
--- a/js/src/jit/BaselineIC.cpp
+++ b/js/src/jit/BaselineIC.cpp
@@ -5178,17 +5178,17 @@ ICSetElem_TypedArray::Compiler::generate
         } else {
             masm.storeToTypedFloatArray(type_, FloatReg0, dest);
         }
         EmitReturnFromIC(masm);
     } else if (type_ == ScalarTypeRepresentation::TYPE_UINT8_CLAMPED) {
         Label notInt32;
         masm.branchTestInt32(Assembler::NotEqual, value, &notInt32);
         masm.unboxInt32(value, secondScratch);
-        masm.clampIntToUint8(secondScratch, secondScratch);
+        masm.clampIntToUint8(secondScratch);
 
         Label clamped;
         masm.bind(&clamped);
         masm.storeToTypedIntArray(type_, secondScratch, dest);
         EmitReturnFromIC(masm);
 
         // If the value is a double, clamp to uint8 and jump back.
         // Else, jump to failure.
--- a/js/src/jit/CodeGenerator.cpp
+++ b/js/src/jit/CodeGenerator.cpp
@@ -6751,19 +6751,19 @@ CodeGenerator::visitStoreTypedArrayEleme
         masm.bind(&skip);
 
     return true;
 }
 
 bool
 CodeGenerator::visitClampIToUint8(LClampIToUint8 *lir)
 {
-    Register input = ToRegister(lir->input());
     Register output = ToRegister(lir->output());
-    masm.clampIntToUint8(input, output);
+    JS_ASSERT(output == ToRegister(lir->input()));
+    masm.clampIntToUint8(output);
     return true;
 }
 
 bool
 CodeGenerator::visitClampDToUint8(LClampDToUint8 *lir)
 {
     FloatRegister input = ToFloatRegister(lir->input());
     Register output = ToRegister(lir->output());
--- a/js/src/jit/IonMacroAssembler.cpp
+++ b/js/src/jit/IonMacroAssembler.cpp
@@ -1624,17 +1624,17 @@ MacroAssembler::convertValueToInt(ValueO
         jump(&done);
     }
 
     // Integers can be unboxed.
     if (isInt32.used()) {
         bind(&isInt32);
         unboxInt32(value, output);
         if (behavior == IntConversion_ClampToUint8)
-            clampIntToUint8(output, output);
+            clampIntToUint8(output);
     }
 
     bind(&done);
 }
 
 bool
 MacroAssembler::convertValueToInt(JSContext *cx, const Value &v, Register output, Label *fail,
                                   IntConversionBehavior behavior)
--- a/js/src/jit/Lowering.cpp
+++ b/js/src/jit/Lowering.cpp
@@ -2381,17 +2381,17 @@ LIRGenerator::visitClampToUint8(MClampTo
 {
     MDefinition *in = ins->input();
 
     switch (in->type()) {
       case MIRType_Boolean:
         return redefine(ins, in);
 
       case MIRType_Int32:
-        return define(new LClampIToUint8(useRegisterAtStart(in)), ins);
+        return defineReuseInput(new LClampIToUint8(useRegisterAtStart(in)), ins, 0);
 
       case MIRType_Double:
         return define(new LClampDToUint8(useRegisterAtStart(in), tempCopy(in, 0)), ins);
 
       case MIRType_Value:
       {
         LClampVToUint8 *lir = new LClampVToUint8(tempFloat());
         if (!useBox(lir, LClampVToUint8::Input, in))
--- a/js/src/jit/arm/MacroAssembler-arm.h
+++ b/js/src/jit/arm/MacroAssembler-arm.h
@@ -1259,23 +1259,22 @@ class MacroAssemblerARMCompat : public M
     }
     void storeFloat(FloatRegister src, BaseIndex addr) {
         // Harder cases not handled yet.
         JS_ASSERT(addr.offset == 0);
         uint32_t scale = Imm32::ShiftOf(addr.scale).value;
         ma_vstr(VFPRegister(src).singleOverlay(), addr.base, addr.index, scale);
     }
 
-    void clampIntToUint8(Register src, Register dest) {
-        // look at (src >> 8) if it is 0, then src shouldn't be clamped
+    void clampIntToUint8(Register reg) {
+        // look at (reg >> 8) if it is 0, then reg shouldn't be clamped
         // if it is <0, then we want to clamp to 0, otherwise, we wish to clamp to 255
-        as_mov(ScratchRegister, asr(src, 8), SetCond);
-        ma_mov(src, dest);
-        ma_mov(Imm32(0xff), dest, NoSetCond, NotEqual);
-        ma_mov(Imm32(0), dest, NoSetCond, Signed);
+        as_mov(ScratchRegister, asr(reg, 8), SetCond);
+        ma_mov(Imm32(0xff), reg, NoSetCond, NotEqual);
+        ma_mov(Imm32(0), reg, NoSetCond, Signed);
     }
 
     void cmp32(const Register &lhs, const Imm32 &rhs);
     void cmp32(const Register &lhs, const Register &rhs);
     void cmp32(const Operand &lhs, const Imm32 &rhs);
     void cmp32(const Operand &lhs, const Register &rhs);
 
     void cmpPtr(const Register &lhs, const ImmWord &rhs);
--- a/js/src/jit/shared/MacroAssembler-x86-shared.h
+++ b/js/src/jit/shared/MacroAssembler-x86-shared.h
@@ -418,36 +418,25 @@ class MacroAssemblerX86Shared : public A
                 andl(Imm32(1), dest);
                 j(Assembler::NonZero, fail);
             }
 
             bind(&notZero);
         }
     }
 
-    void clampIntToUint8(Register src, Register dest) {
-        Label inRange, done;
-        branchTest32(Assembler::Zero, src, Imm32(0xffffff00), &inRange);
+    void clampIntToUint8(Register reg) {
+        Label inRange;
+        branchTest32(Assembler::Zero, reg, Imm32(0xffffff00), &inRange);
         {
-            Label negative;
-            branchTest32(Assembler::Signed, src, src, &negative);
-            {
-                movl(Imm32(255), dest);
-                jump(&done);
-            }
-            bind(&negative);
-            {
-                xorl(dest, dest);
-                jump(&done);
-            }
+            sarl(Imm32(31), reg);
+            notl(reg);
+            andl(Imm32(255), reg);
         }
         bind(&inRange);
-        if (src != dest)
-            movl(src, dest);
-        bind(&done);
     }
 
     bool maybeInlineDouble(double d, const FloatRegister &dest) {
         uint64_t u = mozilla::BitwiseCast<uint64_t>(d);
 
         // Loading zero with xor is specially optimized in hardware.
         if (u == 0) {
             xorpd(dest, dest);