Bug 1111234 - SpiderMonkey: Use 8-bit immediate fields when possible for push and imull r=luke
authorDan Gohman <sunfish@mozilla.com>
Mon, 15 Dec 2014 20:53:59 -0800
changeset 219860 f073ba9ff1fbb935419c631113b617749ed9d18c
parent 219859 19edf4b9d338c8004a1a9d8905894b47c28d53a3
child 219861 ccb0d6eaf1d0950f5a6418b51a00dff262ce4cee
push id12723
push usercbook@mozilla.com
push dateTue, 16 Dec 2014 12:53:09 +0000
treeherderb2g-inbound@468d98a46fdb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1111234
milestone37.0a1
Bug 1111234 - SpiderMonkey: Use 8-bit immediate fields when possible for push and imull r=luke
js/src/jit/shared/Assembler-x86-shared.h
js/src/jit/shared/BaseAssembler-x86-shared.h
js/src/jit/x86/Assembler-x86.h
--- a/js/src/jit/shared/Assembler-x86-shared.h
+++ b/js/src/jit/shared/Assembler-x86-shared.h
@@ -1269,23 +1269,23 @@ class AssemblerX86Shared : public Assemb
     }
     void bsr(const Register &src, const Register &dest) {
         masm.bsr_rr(src.code(), dest.code());
     }
     void imull(Register multiplier) {
         masm.imull_r(multiplier.code());
     }
     void imull(Imm32 imm, Register dest) {
-        masm.imull_i32r(dest.code(), imm.value, dest.code());
+        masm.imull_ir(imm.value, dest.code(), dest.code());
     }
     void imull(Register src, Register dest) {
         masm.imull_rr(src.code(), dest.code());
     }
     void imull(Imm32 imm, Register src, Register dest) {
-        masm.imull_i32r(src.code(), imm.value, dest.code());
+        masm.imull_ir(imm.value, src.code(), dest.code());
     }
     void imull(const Operand &src, Register dest) {
         switch (src.kind()) {
           case Operand::REG:
             masm.imull_rr(src.reg(), dest.code());
             break;
           case Operand::MEM_REG_DISP:
             masm.imull_mr(src.disp(), src.base(), dest.code());
@@ -1436,17 +1436,17 @@ class AssemblerX86Shared : public Assemb
             masm.lock_xaddl_rm(srcdest.code(), mem.disp(), mem.base(), mem.index(), mem.scale());
             break;
           default:
             MOZ_CRASH("unexpected operand kind");
         }
     }
 
     void push(const Imm32 imm) {
-        masm.push_i32(imm.value);
+        masm.push_i(imm.value);
     }
 
     void push(const Operand &src) {
         switch (src.kind()) {
           case Operand::REG:
             masm.push_r(src.reg());
             break;
           case Operand::MEM_REG_DISP:
--- a/js/src/jit/shared/BaseAssembler-x86-shared.h
+++ b/js/src/jit/shared/BaseAssembler-x86-shared.h
@@ -259,16 +259,18 @@ private:
 #endif
 #ifdef JS_CODEGEN_X64
         OP_MOVSXD_GvEv                  = 0x63,
 #endif
         PRE_OPERAND_SIZE                = 0x66,
         PRE_SSE_66                      = 0x66,
         OP_PUSH_Iz                      = 0x68,
         OP_IMUL_GvEvIz                  = 0x69,
+        OP_PUSH_Ib                      = 0x6a,
+        OP_IMUL_GvEvIb                  = 0x6b,
         OP_GROUP1_EbIb                  = 0x80,
         OP_GROUP1_EvIz                  = 0x81,
         OP_GROUP1_EvIb                  = 0x83,
         OP_TEST_EbGb                    = 0x84,
         OP_TEST_EvGv                    = 0x85,
         OP_XCHG_GvEv                    = 0x87,
         OP_MOV_EbGv                     = 0x88,
         OP_MOV_EvGv                     = 0x89,
@@ -558,16 +560,28 @@ public:
     }
 
     void pop_r(RegisterID reg)
     {
         spew("pop        %s", nameIReg(reg));
         m_formatter.oneByteOp(OP_POP_EAX, reg);
     }
 
+    void push_i(int imm)
+    {
+        spew("push       %s$0x%x", PRETTY_PRINT_OFFSET(imm));
+        if (CAN_SIGN_EXTEND_8_32(imm)) {
+            m_formatter.oneByteOp(OP_PUSH_Ib);
+            m_formatter.immediate8(imm);
+        } else {
+            m_formatter.oneByteOp(OP_PUSH_Iz);
+            m_formatter.immediate32(imm);
+        }
+    }
+
     void push_i32(int imm)
     {
         spew("push       %s$0x%x", PRETTY_PRINT_OFFSET(imm));
         m_formatter.oneByteOp(OP_PUSH_Iz);
         m_formatter.immediate32(imm);
     }
 
     void push_m(int offset, RegisterID base)
@@ -1434,21 +1448,26 @@ public:
 
     void imull_mr(int offset, RegisterID base, RegisterID dst)
     {
         spew("imull      %s0x%x(%s), %s",
              PRETTY_PRINT_OFFSET(offset), nameIReg(base), nameIReg(4,dst));
         m_formatter.twoByteOp(OP2_IMUL_GvEv, offset, base, dst);
     }
 
-    void imull_i32r(RegisterID src, int32_t value, RegisterID dst)
+    void imull_ir(int32_t value, RegisterID src, RegisterID dst)
     {
         spew("imull      $%d, %s, %s", value, nameIReg(4, src), nameIReg(4, dst));
-        m_formatter.oneByteOp(OP_IMUL_GvEvIz, src, dst);
-        m_formatter.immediate32(value);
+        if (CAN_SIGN_EXTEND_8_32(value)) {
+            m_formatter.oneByteOp(OP_IMUL_GvEvIb, src, dst);
+            m_formatter.immediate8(value);
+        } else {
+            m_formatter.oneByteOp(OP_IMUL_GvEvIz, src, dst);
+            m_formatter.immediate32(value);
+        }
     }
 
     void idivl_r(RegisterID divisor)
     {
         spew("idivl      %s", nameIReg(4, divisor));
         m_formatter.oneByteOp(OP_GROUP3_Ev, divisor, GROUP3_OP_IDIV);
     }
 
--- a/js/src/jit/x86/Assembler-x86.h
+++ b/js/src/jit/x86/Assembler-x86.h
@@ -199,17 +199,17 @@ class Assembler : public AssemblerX86Sha
 
     // Copy the assembly code to the given buffer, and perform any pending
     // relocations relying on the target address.
     void executableCopy(uint8_t *buffer);
 
     // Actual assembly emitting functions.
 
     void push(ImmGCPtr ptr) {
-        push(Imm32(uintptr_t(ptr.value)));
+        masm.push_i32(int32_t(ptr.value));
         writeDataRelocation(ptr);
     }
     void push(ImmMaybeNurseryPtr ptr) {
         push(noteMaybeNurseryPtr(ptr));
     }
     void push(const ImmWord imm) {
         push(Imm32(imm.value));
     }
@@ -217,17 +217,17 @@ class Assembler : public AssemblerX86Sha
         push(ImmWord(uintptr_t(imm.value)));
     }
     void push(FloatRegister src) {
         subl(Imm32(sizeof(double)), StackPointer);
         movsd(src, Address(StackPointer, 0));
     }
 
     CodeOffsetLabel pushWithPatch(ImmWord word) {
-        push(Imm32(word.value));
+        masm.push_i32(int32_t(word.value));
         return CodeOffsetLabel(masm.currentOffset());
     }
 
     void pop(FloatRegister src) {
         movsd(Address(StackPointer, 0), src);
         addl(Imm32(sizeof(double)), StackPointer);
     }