summaryrefslogtreecommitdiff
path: root/yjit/src/asm/arm64/inst/call.rs
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2022-07-05 16:04:19 -0400
committerTakashi Kokubun <takashikkbn@gmail.com>2022-08-29 08:46:58 -0700
commit7a9b581e0896d4aa7a037da90c837b830213c8e8 (patch)
tree8d613c9cca2af21aa17840270b23acb233b9f3ff /yjit/src/asm/arm64/inst/call.rs
parentb272c57f27628ab114206c777d5b274713d31079 (diff)
Arm64 progress (https://github.com/Shopify/ruby/pull/304)
* Get initial wiring up * Split IncrCounter instruction * Breakpoints in Arm64 * Support for ORR * MOV instruction encodings * Implement JmpOpnd and CRet * Add ORN * Add MVN * PUSH, POP, CCALL for Arm64 * Some formatting and implement Op::Not for Arm64 * Consistent constants when working with the Arm64 SP * Allow OR-ing values into the memory buffer * Test lowering Arm64 ADD * Emit unconditional jumps consistently in Arm64 * Begin emitting conditional jumps for A64 * Back out some labelref changes * Remove label API that no longer exists * Use a trait for the label encoders * Encode nop * Add in nops so jumps are the same width no matter what on Arm64 * Op::Jbe for CodePtr * Pass src_addr and dst_addr instead of calculated offset to label refs * Even more jump work for Arm64 * Fix up jumps to use consistent assertions * Handle splitting Add, Sub, and Not insns for Arm64 * More Arm64 splits and various fixes * PR feedback for Arm64 support * Split up jumps and conditional jump logic
Diffstat (limited to 'yjit/src/asm/arm64/inst/call.rs')
-rw-r--r--yjit/src/asm/arm64/inst/call.rs51
1 files changed, 44 insertions, 7 deletions
diff --git a/yjit/src/asm/arm64/inst/call.rs b/yjit/src/asm/arm64/inst/call.rs
index 6f23acf9f5..8d65359f77 100644
--- a/yjit/src/asm/arm64/inst/call.rs
+++ b/yjit/src/asm/arm64/inst/call.rs
@@ -1,22 +1,41 @@
-/// The struct that represents an A64 branch with link instruction that can be
-/// encoded.
+/// The operation to perform for this instruction.
+enum Op {
+ /// Branch directly, with a hint that this is not a subroutine call or
+ /// return.
+ Branch = 0,
+
+ /// Branch directly, with a hint that this is a subroutine call or return.
+ BranchWithLink = 1
+}
+
+/// The struct that represents an A64 branch with our without link instruction
+/// that can be encoded.
///
/// +-------------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
/// | 31 30 29 28 | 27 26 25 24 | 23 22 21 20 | 19 18 17 16 | 15 14 13 12 | 11 10 09 08 | 07 06 05 04 | 03 02 01 00 |
-/// | 1 0 0 1 0 1 |
-/// | imm26.................................................................................... |
+/// | 0 0 1 0 1 |
+/// | op imm26.................................................................................... |
/// +-------------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
///
pub struct Call {
/// The PC-relative offset to jump to (which will be multiplied by 4).
- imm26: i32
+ imm26: i32,
+
+ /// The operation to perform for this instruction.
+ op: Op
}
impl Call {
+ /// B
+ /// https://developer.arm.com/documentation/ddi0596/2021-12/Base-Instructions/B--Branch-
+ pub fn b(imm26: i32) -> Self {
+ Self { imm26, op: Op::Branch }
+ }
+
/// BL
/// https://developer.arm.com/documentation/ddi0596/2021-12/Base-Instructions/BL--Branch-with-Link-?lang=en
pub fn bl(imm26: i32) -> Self {
- Self { imm26 }
+ Self { imm26, op: Op::BranchWithLink }
}
}
@@ -29,7 +48,7 @@ impl From<Call> for u32 {
let imm26 = (inst.imm26 as u32) & ((1 << 26) - 1);
0
- | (1 << 31)
+ | ((inst.op as u32) << 31)
| (FAMILY << 26)
| imm26
}
@@ -64,4 +83,22 @@ mod tests {
let result: u32 = Call::bl(-256).into();
assert_eq!(0x97ffff00, result);
}
+
+ #[test]
+ fn test_b() {
+ let result: u32 = Call::b(0).into();
+ assert_eq!(0x14000000, result);
+ }
+
+ #[test]
+ fn test_b_positive() {
+ let result: u32 = Call::b(256).into();
+ assert_eq!(0x14000100, result);
+ }
+
+ #[test]
+ fn test_b_negative() {
+ let result: u32 = Call::b(-256).into();
+ assert_eq!(0x17ffff00, result);
+ }
}