Title: [276449] trunk
Revision
276449
Author
[email protected]
Date
2021-04-22 11:41:56 -0700 (Thu, 22 Apr 2021)

Log Message

[JSC] Baseline should have fast path for switch_imm
https://bugs.webkit.org/show_bug.cgi?id=224521

Reviewed by Tadeu Zagallo.

JSTests:

* stress/switch-imm-baseline.js: Added.
(shouldBe):
(test):

Source/_javascript_Core:

This patch implements op_switch_imm fast path in Baseline.
We have this fast path in LLInt, DFG, and FTL. So only Baseline lacks this.

* dfg/DFGSpeculativeJIT.cpp:
(JSC::DFG::SpeculativeJIT::emitSwitchIntJump):
* jit/JITOpcodes.cpp:
(JSC::JIT::emit_op_switch_imm):
* jit/JITOpcodes32_64.cpp:
(JSC::JIT::emit_op_switch_imm):

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChangeLog (276448 => 276449)


--- trunk/JSTests/ChangeLog	2021-04-22 18:09:53 UTC (rev 276448)
+++ trunk/JSTests/ChangeLog	2021-04-22 18:41:56 UTC (rev 276449)
@@ -1,3 +1,14 @@
+2021-04-22  Yusuke Suzuki  <[email protected]>
+
+        [JSC] Baseline should have fast path for switch_imm
+        https://bugs.webkit.org/show_bug.cgi?id=224521
+
+        Reviewed by Tadeu Zagallo.
+
+        * stress/switch-imm-baseline.js: Added.
+        (shouldBe):
+        (test):
+
 2021-04-21  Yusuke Suzuki  <[email protected]>
 
         [JSC] DFG / FTL should inline switch_string

Added: trunk/JSTests/stress/switch-imm-baseline.js (0 => 276449)


--- trunk/JSTests/stress/switch-imm-baseline.js	                        (rev 0)
+++ trunk/JSTests/stress/switch-imm-baseline.js	2021-04-22 18:41:56 UTC (rev 276449)
@@ -0,0 +1,36 @@
+//@ runDefault("--useDFGJIT=0")
+
+function shouldBe(actual, expected) {
+    if (actual !== expected)
+        throw new Error('bad value: ' + actual);
+}
+
+function test(value) {
+    switch (value) {
+    case 0:
+        return 1;
+    case 1:
+        return 2;
+    case 2:
+        return 3;
+    case 3:
+        return 4;
+    case 5:
+        return 6;
+    }
+    return 7;
+}
+noInline(test);
+
+for (var i = 0; i < 1e3; ++i) {
+    shouldBe(test(0), 1);
+    shouldBe(test(1), 2);
+    shouldBe(test(2), 3);
+    shouldBe(test(3), 4);
+    shouldBe(test(4), 7);
+    shouldBe(test(5), 6);
+    shouldBe(test("Hey"), 7);
+    shouldBe(test(null), 7);
+    shouldBe(test(undefined), 7);
+    shouldBe(test({}), 7);
+}

Modified: trunk/Source/_javascript_Core/ChangeLog (276448 => 276449)


--- trunk/Source/_javascript_Core/ChangeLog	2021-04-22 18:09:53 UTC (rev 276448)
+++ trunk/Source/_javascript_Core/ChangeLog	2021-04-22 18:41:56 UTC (rev 276449)
@@ -1,3 +1,20 @@
+2021-04-22  Yusuke Suzuki  <[email protected]>
+
+        [JSC] Baseline should have fast path for switch_imm
+        https://bugs.webkit.org/show_bug.cgi?id=224521
+
+        Reviewed by Tadeu Zagallo.
+
+        This patch implements op_switch_imm fast path in Baseline.
+        We have this fast path in LLInt, DFG, and FTL. So only Baseline lacks this.
+
+        * dfg/DFGSpeculativeJIT.cpp:
+        (JSC::DFG::SpeculativeJIT::emitSwitchIntJump):
+        * jit/JITOpcodes.cpp:
+        (JSC::JIT::emit_op_switch_imm):
+        * jit/JITOpcodes32_64.cpp:
+        (JSC::JIT::emit_op_switch_imm):
+
 2021-04-21  Yusuke Suzuki  <[email protected]>
 
         [JSC] DFG / FTL should inline switch_string

Modified: trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp (276448 => 276449)


--- trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp	2021-04-22 18:09:53 UTC (rev 276448)
+++ trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp	2021-04-22 18:41:56 UTC (rev 276449)
@@ -11511,10 +11511,14 @@
     addBranch(
         m_jit.branch32(JITCompiler::AboveOrEqual, value, Imm32(linkedTable.m_ctiOffsets.size())),
         data->fallThrough.block);
-    m_jit.move(TrustedImmPtr(linkedTable.m_ctiOffsets.begin()), scratch);
+    m_jit.move(TrustedImmPtr(linkedTable.m_ctiOffsets.data()), scratch);
+
+#if USE(JSVALUE64)
+    m_jit.farJump(JITCompiler::BaseIndex(scratch, value, JITCompiler::ScalePtr), JSSwitchPtrTag);
+#else
     m_jit.loadPtr(JITCompiler::BaseIndex(scratch, value, JITCompiler::ScalePtr), scratch);
-    
     m_jit.farJump(scratch, JSSwitchPtrTag);
+#endif
     data->didUseJumpTable = true;
 }
 

Modified: trunk/Source/_javascript_Core/jit/JITOpcodes.cpp (276448 => 276449)


--- trunk/Source/_javascript_Core/jit/JITOpcodes.cpp	2021-04-22 18:09:53 UTC (rev 276448)
+++ trunk/Source/_javascript_Core/jit/JITOpcodes.cpp	2021-04-22 18:41:56 UTC (rev 276449)
@@ -894,8 +894,6 @@
 
 void JIT::emit_op_switch_imm(const Instruction* currentInstruction)
 {
-    // FIXME: We should have a fast path.
-    // https://bugs.webkit.org/show_bug.cgi?id=224521
     auto bytecode = currentInstruction->as<OpSwitchImm>();
     size_t tableIndex = bytecode.m_tableIndex;
     unsigned defaultOffset = jumpTarget(currentInstruction, bytecode.m_defaultOffset);
@@ -908,7 +906,15 @@
     linkedTable.ensureCTITable(unlinkedTable);
 
     emitGetVirtualRegister(scrutinee, regT0);
-    callOperation(operationSwitchImmWithUnknownKeyType, TrustedImmPtr(&vm()), regT0, tableIndex, unlinkedTable.m_min);
+    auto notInt32 = branchIfNotInt32(regT0);
+    sub32(Imm32(unlinkedTable.m_min), regT0);
+
+    addJump(branch32(AboveOrEqual, regT0, Imm32(linkedTable.m_ctiOffsets.size())), defaultOffset);
+    move(TrustedImmPtr(linkedTable.m_ctiOffsets.data()), regT1);
+    farJump(BaseIndex(regT1, regT0, ScalePtr), JSSwitchPtrTag);
+
+    notInt32.link(this);
+    callOperationNoExceptionCheck(operationSwitchImmWithUnknownKeyType, TrustedImmPtr(&vm()), regT0, tableIndex, unlinkedTable.m_min);
     farJump(returnValueGPR, JSSwitchPtrTag);
 }
 

Modified: trunk/Source/_javascript_Core/jit/JITOpcodes32_64.cpp (276448 => 276449)


--- trunk/Source/_javascript_Core/jit/JITOpcodes32_64.cpp	2021-04-22 18:09:53 UTC (rev 276448)
+++ trunk/Source/_javascript_Core/jit/JITOpcodes32_64.cpp	2021-04-22 18:41:56 UTC (rev 276449)
@@ -1000,7 +1000,16 @@
     linkedTable.ensureCTITable(unlinkedTable);
 
     emitLoad(scrutinee, regT1, regT0);
-    callOperation(operationSwitchImmWithUnknownKeyType, TrustedImmPtr(&vm()), JSValueRegs(regT1, regT0), tableIndex, unlinkedTable.m_min);
+    auto notInt32 = branchIfNotInt32(regT1);
+    sub32(Imm32(unlinkedTable.m_min), regT0);
+
+    addJump(branch32(AboveOrEqual, regT0, Imm32(linkedTable.m_ctiOffsets.size())), defaultOffset);
+    move(TrustedImmPtr(linkedTable.m_ctiOffsets.data()), regT1);
+    loadPtr(BaseIndex(regT1, regT0, ScalePtr), regT1);
+    farJump(regT1, NoPtrTag);
+
+    notInt32.link(this);
+    callOperationNoExceptionCheck(operationSwitchImmWithUnknownKeyType, TrustedImmPtr(&vm()), JSValueRegs(regT1, regT0), tableIndex, unlinkedTable.m_min);
     farJump(returnValueGPR, NoPtrTag);
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to