mul32 should convert powers of 2 to an lshift
authorkeith_miller@apple.com <keith_miller@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Jan 2019 22:42:11 +0000 (22:42 +0000)
committerkeith_miller@apple.com <keith_miller@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Jan 2019 22:42:11 +0000 (22:42 +0000)
https://bugs.webkit.org/show_bug.cgi?id=193957

Reviewed by Yusuke Suzuki.

* assembler/MacroAssembler.h:
(JSC::MacroAssembler::mul32):
* assembler/testmasm.cpp:
(JSC::int32Operands):
(JSC::testMul32WithImmediates):
(JSC::run):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@240731 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/assembler/MacroAssembler.h
Source/JavaScriptCore/assembler/testmasm.cpp

index 036239a..86594e5 100644 (file)
@@ -1,3 +1,17 @@
+2019-01-30  Keith Miller  <keith_miller@apple.com>
+
+        mul32 should convert powers of 2 to an lshift
+        https://bugs.webkit.org/show_bug.cgi?id=193957
+
+        Reviewed by Yusuke Suzuki.
+
+        * assembler/MacroAssembler.h:
+        (JSC::MacroAssembler::mul32):
+        * assembler/testmasm.cpp:
+        (JSC::int32Operands):
+        (JSC::testMul32WithImmediates):
+        (JSC::run):
+
 2019-01-30  Yusuke Suzuki  <ysuzuki@apple.com>
 
         [JSC] Make disassembler data structures constant read-only data
index 22c50ad..c18ed83 100644 (file)
@@ -1904,6 +1904,15 @@ public:
         urshift32(src, trustedImm32ForShift(amount), dest);
     }
 
+    void mul32(TrustedImm32 imm, RegisterID src, RegisterID dest)
+    {
+        if (hasOneBitSet(imm.m_value)) {
+            lshift32(src, TrustedImm32(getLSBSet(imm.m_value)), dest);
+            return;
+        }
+        MacroAssemblerBase::mul32(imm, src, dest);
+    }
+
     // If the result jump is taken that means the assert passed.
     void jitAssert(const WTF::ScopedLambda<Jump(void)>&);
 
index 8239a94..2df019f 100644 (file)
@@ -264,6 +264,21 @@ static Vector<float> floatOperands()
     };
 }
 
+static Vector<int32_t> int32Operands()
+{
+    return Vector<int32_t> {
+        0,
+        1,
+        -1,
+        2,
+        -2,
+        42,
+        -42,
+        64,
+        std::numeric_limits<int32_t>::max(),
+        std::numeric_limits<int32_t>::min(),
+    };
+}
 
 void testCompareDouble(MacroAssembler::DoubleCondition condition)
 {
@@ -306,6 +321,23 @@ void testCompareDouble(MacroAssembler::DoubleCondition condition)
     }
 }
 
+void testMul32WithImmediates()
+{
+    for (auto immediate : int32Operands()) {
+        auto mul = compile([=] (CCallHelpers& jit) {
+            jit.emitFunctionPrologue();
+
+            jit.mul32(CCallHelpers::TrustedImm32(immediate), GPRInfo::argumentGPR0, GPRInfo::returnValueGPR);
+
+            jit.emitFunctionEpilogue();
+            jit.ret();
+        });
+
+        for (auto value : int32Operands())
+            CHECK_EQ(invoke<int>(mul, value), immediate * value);
+    }
+}
+
 #if CPU(X86) || CPU(X86_64) || CPU(ARM64)
 void testCompareFloat(MacroAssembler::DoubleCondition condition)
 {
@@ -956,6 +988,7 @@ void run(const char* filter)
     RUN(testCompareDouble(MacroAssembler::DoubleGreaterThanOrEqualOrUnordered));
     RUN(testCompareDouble(MacroAssembler::DoubleLessThanOrUnordered));
     RUN(testCompareDouble(MacroAssembler::DoubleLessThanOrEqualOrUnordered));
+    RUN(testMul32WithImmediates());
 
 #if CPU(X86) || CPU(X86_64) || CPU(ARM64)
     RUN(testCompareFloat(MacroAssembler::DoubleEqual));