Title: [288374] trunk/Source/_javascript_Core
Revision
288374
Author
[email protected]
Date
2022-01-21 13:19:06 -0800 (Fri, 21 Jan 2022)

Log Message

[RISCV64] Add MacroAssemblerRISCV64 branch-testing operations
https://bugs.webkit.org/show_bug.cgi?id=235442

Patch by Zan Dobersek <[email protected]> on 2022-01-21
Reviewed by Yusuke Suzuki.

Implement MacroAssemblerRISCV64 branch-testing operations. The branching
instructions being intentionally simple in RISC-V, and with no status
register, scratch register has to be used to hold the testing result
and perform a branch based on its value. This will disallow use of these
implementations from Air, but that has to be address inside Air itself.

When performing tests for values that are smaller than 64 bits in width,
the tested value is zero-extended or, when necessary, loaded as an
unsigned value, to impose zeroed upper bits that eliminate masking
values that are too wide or get sign-extended when used as immediates.
Post-masking, these shorter-width values still have to be sign-extended
to accommodate branch instructions that are used when testing
signedness.

The test result value is then passed on, along with the desired
condition, to the new branchTestFinalize() helper method that finally
generates the appropriate branch.

* assembler/MacroAssemblerRISCV64.h:
(JSC::MacroAssemblerRISCV64::branchTest8):
(JSC::MacroAssemblerRISCV64::branchTest16):
(JSC::MacroAssemblerRISCV64::branchTest32):
(JSC::MacroAssemblerRISCV64::branchTest64):
(JSC::MacroAssemblerRISCV64::branchPtr):
(JSC::MacroAssemblerRISCV64::branchTestFinalize):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (288373 => 288374)


--- trunk/Source/_javascript_Core/ChangeLog	2022-01-21 21:18:23 UTC (rev 288373)
+++ trunk/Source/_javascript_Core/ChangeLog	2022-01-21 21:19:06 UTC (rev 288374)
@@ -1,5 +1,38 @@
 2022-01-21  Zan Dobersek  <[email protected]>
 
+        [RISCV64] Add MacroAssemblerRISCV64 branch-testing operations
+        https://bugs.webkit.org/show_bug.cgi?id=235442
+
+        Reviewed by Yusuke Suzuki.
+
+        Implement MacroAssemblerRISCV64 branch-testing operations. The branching
+        instructions being intentionally simple in RISC-V, and with no status
+        register, scratch register has to be used to hold the testing result
+        and perform a branch based on its value. This will disallow use of these
+        implementations from Air, but that has to be address inside Air itself.
+
+        When performing tests for values that are smaller than 64 bits in width,
+        the tested value is zero-extended or, when necessary, loaded as an
+        unsigned value, to impose zeroed upper bits that eliminate masking
+        values that are too wide or get sign-extended when used as immediates.
+        Post-masking, these shorter-width values still have to be sign-extended
+        to accommodate branch instructions that are used when testing
+        signedness.
+
+        The test result value is then passed on, along with the desired
+        condition, to the new branchTestFinalize() helper method that finally
+        generates the appropriate branch.
+
+        * assembler/MacroAssemblerRISCV64.h:
+        (JSC::MacroAssemblerRISCV64::branchTest8):
+        (JSC::MacroAssemblerRISCV64::branchTest16):
+        (JSC::MacroAssemblerRISCV64::branchTest32):
+        (JSC::MacroAssemblerRISCV64::branchTest64):
+        (JSC::MacroAssemblerRISCV64::branchPtr):
+        (JSC::MacroAssemblerRISCV64::branchTestFinalize):
+
+2022-01-21  Zan Dobersek  <[email protected]>
+
         [RISCV64] Add MacroAssemblerRISCV64 operations for bitfield, zero-counting, byte-swapping operations
         https://bugs.webkit.org/show_bug.cgi?id=235439
 

Modified: trunk/Source/_javascript_Core/assembler/MacroAssemblerRISCV64.h (288373 => 288374)


--- trunk/Source/_javascript_Core/assembler/MacroAssemblerRISCV64.h	2022-01-21 21:18:23 UTC (rev 288373)
+++ trunk/Source/_javascript_Core/assembler/MacroAssemblerRISCV64.h	2022-01-21 21:19:06 UTC (rev 288374)
@@ -2171,13 +2171,235 @@
     MACRO_ASSEMBLER_RISCV64_TEMPLATED_NOOP_METHOD_WITH_RETURN(branchNeg32, Jump);
     MACRO_ASSEMBLER_RISCV64_TEMPLATED_NOOP_METHOD_WITH_RETURN(branchNeg64, Jump);
 
-    MACRO_ASSEMBLER_RISCV64_TEMPLATED_NOOP_METHOD_WITH_RETURN(branchTest8, Jump);
-    MACRO_ASSEMBLER_RISCV64_TEMPLATED_NOOP_METHOD_WITH_RETURN(branchTest16, Jump);
-    MACRO_ASSEMBLER_RISCV64_TEMPLATED_NOOP_METHOD_WITH_RETURN(branchTest32, Jump);
-    MACRO_ASSEMBLER_RISCV64_TEMPLATED_NOOP_METHOD_WITH_RETURN(branchTest64, Jump);
+    Jump branchTest8(ResultCondition cond, Address address, TrustedImm32 imm = TrustedImm32(-1))
+    {
+        auto temp = temps<Data, Memory>();
+        auto resolution = resolveAddress(address, temp.memory());
+        m_assembler.lbuInsn(temp.memory(), resolution.base, Imm::I(resolution.offset));
 
-    MACRO_ASSEMBLER_RISCV64_TEMPLATED_NOOP_METHOD_WITH_RETURN(branchPtr, Jump);
+        if (!Imm::isValid<Imm::IType>(imm.m_value)) {
+            loadImmediate(imm, temp.data());
+            m_assembler.andInsn(temp.data(), temp.memory(), temp.data());
+        } else
+            m_assembler.andiInsn(temp.data(), temp.memory(), Imm::I(imm.m_value));
+        m_assembler.signExtend<8>(temp.data());
+        return branchTestFinalize(cond, temp.data());
+    }
 
+    Jump branchTest8(ResultCondition cond, AbsoluteAddress address, TrustedImm32 imm = TrustedImm32(-1))
+    {
+        auto temp = temps<Data, Memory>();
+        loadImmediate(TrustedImmPtr(address.m_ptr), temp.memory());
+        m_assembler.lbuInsn(temp.memory(), temp.memory(), Imm::I<0>());
+
+        if (!Imm::isValid<Imm::IType>(imm.m_value)) {
+            loadImmediate(imm, temp.data());
+            m_assembler.andInsn(temp.data(), temp.memory(), temp.data());
+        } else
+            m_assembler.andiInsn(temp.data(), temp.memory(), Imm::I(imm.m_value));
+        m_assembler.signExtend<8>(temp.data());
+        return branchTestFinalize(cond, temp.data());
+    }
+
+    Jump branchTest8(ResultCondition cond, BaseIndex address, TrustedImm32 imm = TrustedImm32(-1))
+    {
+        auto temp = temps<Data, Memory>();
+        auto resolution = resolveAddress(address, temp.memory());
+        m_assembler.lbuInsn(temp.memory(), resolution.base, Imm::I(resolution.offset));
+
+        if (!Imm::isValid<Imm::IType>(imm.m_value)) {
+            loadImmediate(imm, temp.data());
+            m_assembler.andInsn(temp.data(), temp.memory(), temp.data());
+        } else
+            m_assembler.andiInsn(temp.data(), temp.memory(), Imm::I(imm.m_value));
+        m_assembler.signExtend<8>(temp.data());
+        return branchTestFinalize(cond, temp.data());
+    }
+
+    Jump branchTest8(ResultCondition cond, ExtendedAddress address, TrustedImm32 imm = TrustedImm32(-1))
+    {
+        auto temp = temps<Data, Memory>();
+        auto resolution = resolveAddress(address, temp.memory());
+        m_assembler.lbuInsn(temp.memory(), resolution.base, Imm::I(resolution.offset));
+
+        if (!Imm::isValid<Imm::IType>(imm.m_value)) {
+            loadImmediate(imm, temp.data());
+            m_assembler.andInsn(temp.data(), temp.memory(), temp.data());
+        } else
+            m_assembler.andiInsn(temp.data(), temp.memory(), Imm::I(imm.m_value));
+        m_assembler.signExtend<8>(temp.data());
+        return branchTestFinalize(cond, temp.data());
+    }
+
+    Jump branchTest16(ResultCondition cond, Address address, TrustedImm32 imm = TrustedImm32(-1))
+    {
+        auto temp = temps<Data, Memory>();
+        auto resolution = resolveAddress(address, temp.memory());
+        m_assembler.lhuInsn(temp.memory(), resolution.base, Imm::I(resolution.offset));
+
+        if (!Imm::isValid<Imm::IType>(imm.m_value)) {
+            loadImmediate(imm, temp.data());
+            m_assembler.andInsn(temp.data(), temp.memory(), temp.data());
+        } else
+            m_assembler.andiInsn(temp.data(), temp.memory(), Imm::I(imm.m_value));
+        m_assembler.signExtend<16>(temp.data());
+        return branchTestFinalize(cond, temp.data());
+    }
+
+    Jump branchTest16(ResultCondition cond, BaseIndex address, TrustedImm32 imm = TrustedImm32(-1))
+    {
+        auto temp = temps<Data, Memory>();
+        auto resolution = resolveAddress(address, temp.memory());
+        m_assembler.lhuInsn(temp.memory(), resolution.base, Imm::I(resolution.offset));
+
+        if (!Imm::isValid<Imm::IType>(imm.m_value)) {
+            loadImmediate(imm, temp.data());
+            m_assembler.andInsn(temp.data(), temp.memory(), temp.data());
+        } else
+            m_assembler.andiInsn(temp.data(), temp.memory(), Imm::I(imm.m_value));
+        m_assembler.signExtend<16>(temp.data());
+        return branchTestFinalize(cond, temp.data());
+    }
+
+    Jump branchTest32(ResultCondition cond, RegisterID lhs, RegisterID rhs)
+    {
+        auto temp = temps<Data>();
+        m_assembler.zeroExtend<32>(temp.data(), lhs);
+        m_assembler.andInsn(temp.data(), temp.data(), rhs);
+        m_assembler.signExtend<32>(temp.data());
+        return branchTestFinalize(cond, temp.data());
+    }
+
+    Jump branchTest32(ResultCondition cond, RegisterID lhs, TrustedImm32 imm = TrustedImm32(-1))
+    {
+        auto temp = temps<Data, Memory>();
+        m_assembler.zeroExtend<32>(temp.memory(), lhs);
+
+        if (!Imm::isValid<Imm::IType>(imm.m_value)) {
+            loadImmediate(imm, temp.data());
+            m_assembler.andInsn(temp.data(), temp.memory(), temp.data());
+        } else
+            m_assembler.andiInsn(temp.data(), temp.memory(), Imm::I(imm.m_value));
+        m_assembler.signExtend<32>(temp.data());
+        return branchTestFinalize(cond, temp.data());
+    }
+
+    Jump branchTest32(ResultCondition cond, Address address, TrustedImm32 imm = TrustedImm32(-1))
+    {
+        auto temp = temps<Data, Memory>();
+        auto resolution = resolveAddress(address, temp.memory());
+        m_assembler.lwuInsn(temp.memory(), resolution.base, Imm::I(resolution.offset));
+
+        if (!Imm::isValid<Imm::IType>(imm.m_value)) {
+            loadImmediate(imm, temp.data());
+            m_assembler.andInsn(temp.data(), temp.memory(), temp.data());
+        } else
+            m_assembler.andiInsn(temp.data(), temp.memory(), Imm::I(imm.m_value));
+        m_assembler.signExtend<32>(temp.data());
+        return branchTestFinalize(cond, temp.data());
+    }
+
+    Jump branchTest32(ResultCondition cond, AbsoluteAddress address, TrustedImm32 imm = TrustedImm32(-1))
+    {
+        auto temp = temps<Data, Memory>();
+        loadImmediate(TrustedImmPtr(address.m_ptr), temp.memory());
+        m_assembler.lwuInsn(temp.memory(), temp.memory(), Imm::I<0>());
+
+        if (!Imm::isValid<Imm::IType>(imm.m_value)) {
+            loadImmediate(imm, temp.data());
+            m_assembler.andInsn(temp.data(), temp.memory(), temp.data());
+        } else
+            m_assembler.andiInsn(temp.data(), temp.memory(), Imm::I(imm.m_value));
+        m_assembler.signExtend<32>(temp.data());
+        return branchTestFinalize(cond, temp.data());
+    }
+
+
+    Jump branchTest64(ResultCondition cond, RegisterID lhs, RegisterID rhs)
+    {
+        auto temp = temps<Data>();
+        m_assembler.andInsn(temp.data(), lhs, rhs);
+        return branchTestFinalize(cond, temp.data());
+    }
+
+    Jump branchTest64(ResultCondition cond, RegisterID lhs, TrustedImm32 imm = TrustedImm32(-1))
+    {
+        auto temp = temps<Data>();
+        if (!Imm::isValid<Imm::IType>(imm.m_value)) {
+            loadImmediate(imm, temp.data());
+            m_assembler.andInsn(temp.data(), lhs, temp.data());
+        } else
+            m_assembler.andiInsn(temp.data(), lhs, Imm::I(imm.m_value));
+        return branchTestFinalize(cond, temp.data());
+    }
+
+    Jump branchTest64(ResultCondition cond, RegisterID lhs, TrustedImm64 imm)
+    {
+        auto temp = temps<Data>();
+        if (!Imm::isValid<Imm::IType>(imm.m_value)) {
+            loadImmediate(imm, temp.data());
+            m_assembler.andInsn(temp.data(), lhs, temp.data());
+        } else
+            m_assembler.andiInsn(temp.data(), lhs, Imm::I(imm.m_value));
+        return branchTestFinalize(cond, temp.data());
+    }
+
+    Jump branchTest64(ResultCondition cond, Address address, RegisterID rhs)
+    {
+        auto temp = temps<Data, Memory>();
+        auto resolution = resolveAddress(address, temp.memory());
+        m_assembler.ldInsn(temp.data(), resolution.base, Imm::I(resolution.offset));
+        m_assembler.andInsn(temp.data(), temp.data(), rhs);
+        return branchTestFinalize(cond, temp.data());
+    }
+
+    Jump branchTest64(ResultCondition cond, Address address, TrustedImm32 imm = TrustedImm32(-1))
+    {
+        auto temp = temps<Data, Memory>();
+        auto resolution = resolveAddress(address, temp.memory());
+        m_assembler.ldInsn(temp.memory(), resolution.base, Imm::I(resolution.offset));
+
+        if (!Imm::isValid<Imm::IType>(imm.m_value)) {
+            loadImmediate(imm, temp.data());
+            m_assembler.andInsn(temp.data(), temp.memory(), temp.data());
+        } else
+            m_assembler.andiInsn(temp.data(), temp.memory(), Imm::I(imm.m_value));
+        return branchTestFinalize(cond, temp.data());
+    }
+
+    Jump branchTest64(ResultCondition cond, AbsoluteAddress address, TrustedImm32 imm = TrustedImm32(-1))
+    {
+        auto temp = temps<Data, Memory>();
+        loadImmediate(TrustedImmPtr(address.m_ptr), temp.memory());
+        m_assembler.ldInsn(temp.memory(), temp.memory(), Imm::I<0>());
+
+        if (!Imm::isValid<Imm::IType>(imm.m_value)) {
+            loadImmediate(imm, temp.data());
+            m_assembler.andInsn(temp.data(), temp.memory(), temp.data());
+        } else
+            m_assembler.andiInsn(temp.data(), temp.memory(), Imm::I(imm.m_value));
+        return branchTestFinalize(cond, temp.data());
+    }
+
+    Jump branchTest64(ResultCondition cond, BaseIndex address, TrustedImm32 imm = TrustedImm32(-1))
+    {
+        auto temp = temps<Data, Memory>();
+        auto resolution = resolveAddress(address, temp.memory());
+        m_assembler.ldInsn(temp.memory(), resolution.base, Imm::I(resolution.offset));
+
+        if (!Imm::isValid<Imm::IType>(imm.m_value)) {
+            loadImmediate(imm, temp.data());
+            m_assembler.andInsn(temp.data(), temp.memory(), temp.data());
+        } else
+            m_assembler.andiInsn(temp.data(), temp.memory(), Imm::I(imm.m_value));
+        return branchTestFinalize(cond, temp.data());
+    }
+
+    Jump branchPtr(RelationalCondition cond, BaseIndex address, RegisterID rhs)
+    {
+        return branch64(cond, address, rhs);
+    }
+
     DataLabel32 moveWithPatch(TrustedImm32 imm, RegisterID dest)
     {
         RISCV64Assembler::ImmediateLoader imml(RISCV64Assembler::ImmediateLoader::Placeholder, imm.m_value);
@@ -2964,6 +3186,25 @@
         return Jump(label);
     }
 
+    Jump branchTestFinalize(ResultCondition cond, RegisterID src)
+    {
+        switch (cond) {
+        case Overflow:
+            break;
+        case Signed:
+            return makeBranch(LessThan, src, RISCV64Registers::zero);
+        case PositiveOrZero:
+            return makeBranch(GreaterThanOrEqual, src, RISCV64Registers::zero);
+        case Zero:
+            return makeBranch(Equal, src, RISCV64Registers::zero);
+        case NonZero:
+            return makeBranch(NotEqual, src, RISCV64Registers::zero);
+        }
+
+        RELEASE_ASSERT_NOT_REACHED();
+        return { };
+    }
+
     void compareFinalize(RelationalCondition cond, RegisterID lhs, RegisterID rhs, RegisterID dest)
     {
         switch (cond) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to