Inline immediate number version of op_mul.
[WebKit-https.git] / JavaScriptCore / masm / X86Assembler.h
index df0a297..0255dcb 100644 (file)
@@ -147,8 +147,7 @@ private:
 #define SIB(type, reg, rm) MODRM(type, reg, rm)
 #define CAN_SIGN_EXTEND_8_32(value) (value == ((int)(signed char)value))
 
-class X86Assembler {
-public:
+namespace X86 {
     typedef enum {
         eax,
         ecx,
@@ -159,10 +158,15 @@ public:
         esi,
         edi,
 
-        NO_BASE  = ebp,
-        HAS_SIB  = esp,
-        NO_SCALE = esp,
+        noBase = ebp,
+        hasSib = esp,
+        noScale = esp,
     } RegisterID;
+}
+
+class X86Assembler {
+public:
+    typedef X86::RegisterID RegisterID;
 
     typedef enum {
         OP_ADD_EvGv                     = 0x01,
@@ -178,6 +182,7 @@ public:
         OP_PUSH_EAX                     = 0x50,
         OP_POP_EAX                      = 0x58,
         PRE_OPERAND_SIZE                = 0x66,
+        OP_IMUL_GvEvIz                  = 0x69,
         OP_GROUP1_EvIz                  = 0x81,
         OP_GROUP1_EvIb                  = 0x83,
         OP_TEST_EvGv                    = 0x85,
@@ -207,7 +212,7 @@ public:
         OP2_JL_rel32    = 0x8C,
         OP2_JGE_rel32   = 0x8D,
         OP2_JLE_rel32   = 0x8E,
-        OP2_MUL_GvEv    = 0xAF,
+        OP2_IMUL_GvEv   = 0xAF,
         OP2_MOVZX_GvEw  = 0xB7,
 
         GROUP1_OP_ADD = 0,
@@ -468,11 +473,18 @@ public:
         emitModRm_opr(GROUP2_OP_SHL, dst);
     }
 
-    void mull_rr(RegisterID src, RegisterID dst)
+    void imull_rr(RegisterID src, RegisterID dst)
     {
         m_buffer->putByte(OP_2BYTE_ESCAPE);
-        m_buffer->putByte(OP2_MUL_GvEv);
+        m_buffer->putByte(OP2_IMUL_GvEv);
+        emitModRm_rr(dst, src);
+    }
+    
+    void imull_i32r(RegisterID src, int32_t value, RegisterID dst)
+    {
+        m_buffer->putByte(OP_IMUL_GvEvIz);
         emitModRm_rr(dst, src);
+        m_buffer->putInt(value);
     }
 
     void idivl_r(RegisterID dst)
@@ -774,6 +786,23 @@ public:
         return m_buffer->copy();
     }
 
+#if COMPILER(MSVC)
+    void emitConvertToFastCall()
+    {
+        movl_mr(4, X86::esp, X86::eax);
+        movl_mr(8, X86::esp, X86::edx);
+        movl_mr(12, X86::esp, X86::ecx);
+    }
+
+    void emitRestoreArgumentReference()
+    {
+        movl_rm(X86::esp, 0, X86::esp);
+    }
+#else
+    void emitConvertToFastCall() {};
+    void emitRestoreArgumentReference() {};
+#endif
+
 private:
     void emitModRm_rr(RegisterID reg, RegisterID rm)
     {
@@ -788,29 +817,29 @@ private:
 
     void emitModRm_rm(RegisterID reg, void* addr)
     {
-        m_buffer->putByte(MODRM(0, reg, NO_BASE));
+        m_buffer->putByte(MODRM(0, reg, X86::noBase));
         m_buffer->putInt((int)addr);
     }
 
     void emitModRm_rm(RegisterID reg, RegisterID base)
     {
-        if (base == esp) {
-            m_buffer->putByte(MODRM(0, reg, HAS_SIB));
-            m_buffer->putByte(SIB(0, NO_SCALE, esp));
+        if (base == X86::esp) {
+            m_buffer->putByte(MODRM(0, reg, X86::hasSib));
+            m_buffer->putByte(SIB(0, X86::noScale, X86::esp));
         } else
             m_buffer->putByte(MODRM(0, reg, base));
     }
 
     void emitModRm_rm_Unchecked(RegisterID reg, RegisterID base, int offset)
     {
-        if (base == esp) {
+        if (base == X86::esp) {
             if (CAN_SIGN_EXTEND_8_32(offset)) {
-                m_buffer->putByteUnchecked(MODRM(1, reg, HAS_SIB));
-                m_buffer->putByteUnchecked(SIB(0, NO_SCALE, esp));
+                m_buffer->putByteUnchecked(MODRM(1, reg, X86::hasSib));
+                m_buffer->putByteUnchecked(SIB(0, X86::noScale, X86::esp));
                 m_buffer->putByteUnchecked(offset);
             } else {
-                m_buffer->putByteUnchecked(MODRM(2, reg, HAS_SIB));
-                m_buffer->putByteUnchecked(SIB(0, NO_SCALE, esp));
+                m_buffer->putByteUnchecked(MODRM(2, reg, X86::hasSib));
+                m_buffer->putByteUnchecked(SIB(0, X86::noScale, X86::esp));
                 m_buffer->putIntUnchecked(offset);
             }
         } else {
@@ -836,7 +865,7 @@ private:
         while (scale >>= 1)
             shift++;
     
-        m_buffer->putByte(MODRM(0, reg, HAS_SIB));
+        m_buffer->putByte(MODRM(0, reg, X86::hasSib));
         m_buffer->putByte(SIB(shift, index, base));
     }
 
@@ -847,11 +876,11 @@ private:
             shift++;
     
         if (CAN_SIGN_EXTEND_8_32(offset)) {
-            m_buffer->putByte(MODRM(1, reg, HAS_SIB));
+            m_buffer->putByte(MODRM(1, reg, X86::hasSib));
             m_buffer->putByte(SIB(shift, index, base));
             m_buffer->putByte(offset);
         } else {
-            m_buffer->putByte(MODRM(2, reg, HAS_SIB));
+            m_buffer->putByte(MODRM(2, reg, X86::hasSib));
             m_buffer->putByte(SIB(shift, index, base));
             m_buffer->putInt(offset);
         }