Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 29f17dd

Browse files
committed
YJIT: Port next_page to x86_64
1 parent 2d7b060 commit 29f17dd

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

yjit/src/backend/arm64/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -703,8 +703,7 @@ impl Assembler
703703
// For each instruction
704704
let start_write_pos = cb.get_write_pos();
705705
let mut i: usize = 0;
706-
while i < self.insns.len() {
707-
let insn = &self.insns[i];
706+
while let Some(insn) = self.insns.get(i) {
708707
let had_dropped_bytes = cb.has_dropped_bytes();
709708
let src_ptr = cb.get_write_ptr();
710709
match insn {
@@ -1003,7 +1002,7 @@ impl Assembler
10031002
}
10041003
};
10051004

1006-
// On failure, jump to the next page and retry the last insn
1005+
// On failure, jump to the next page and retry the current insn
10071006
if !had_dropped_bytes && cb.has_dropped_bytes() && cb.next_page(None) {
10081007
let dst_ptr = cb.get_write_ptr();
10091008
cb.set_write_ptr(src_ptr);

yjit/src/backend/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ fn test_jcc_ptr()
253253
{
254254
let (mut asm, mut cb) = setup_asm();
255255

256-
let side_exit = Target::CodePtr((5 as *mut u8).into());
256+
let side_exit = Target::CodePtr(((cb.get_write_ptr().raw_ptr() as usize + 5) as *mut u8).into());
257257
let not_mask = asm.not(Opnd::mem(32, EC, RUBY_OFFSET_EC_INTERRUPT_MASK));
258258
asm.test(
259259
Opnd::mem(32, EC, RUBY_OFFSET_EC_INTERRUPT_FLAG),
@@ -270,7 +270,7 @@ fn test_jmp_ptr()
270270
{
271271
let (mut asm, mut cb) = setup_asm();
272272

273-
let stub = Target::CodePtr((5 as *mut u8).into());
273+
let stub = Target::CodePtr(((cb.get_write_ptr().raw_ptr() as usize + 5) as *mut u8).into());
274274
asm.jmp(stub);
275275

276276
asm.compile_with_num_regs(&mut cb, 0);
@@ -281,7 +281,7 @@ fn test_jo()
281281
{
282282
let (mut asm, mut cb) = setup_asm();
283283

284-
let side_exit = Target::CodePtr((5 as *mut u8).into());
284+
let side_exit = Target::CodePtr(((cb.get_write_ptr().raw_ptr() as usize + 5) as *mut u8).into());
285285

286286
let arg1 = Opnd::mem(64, SP, 0);
287287
let arg0 = Opnd::mem(64, SP, 8);

yjit/src/backend/x86_64/mod.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,10 @@ impl Assembler
372372

373373
// For each instruction
374374
let start_write_pos = cb.get_write_pos();
375-
for insn in &self.insns {
375+
let mut i: usize = 0;
376+
while let Some(insn) = self.insns.get(i) {
377+
let had_dropped_bytes = cb.has_dropped_bytes();
378+
let src_ptr = cb.get_write_ptr();
376379
match insn {
377380
Insn::Comment(text) => {
378381
if cfg!(feature = "asm_comments") {
@@ -662,6 +665,18 @@ impl Assembler
662665
// instructions can never make it to the emit stage.
663666
_ => panic!("unsupported instruction passed to x86 backend: {:?}", insn)
664667
};
668+
669+
// On failure, jump to the next page and retry the current insn
670+
if !had_dropped_bytes && cb.has_dropped_bytes() && cb.next_page(None) {
671+
let dst_ptr = cb.get_write_ptr();
672+
cb.set_write_ptr(src_ptr);
673+
cb.without_page_end_reserve(|cb| {
674+
jmp_ptr(cb, dst_ptr);
675+
});
676+
cb.set_write_ptr(dst_ptr);
677+
} else {
678+
i += 1;
679+
}
665680
}
666681

667682
gc_offsets

0 commit comments

Comments
 (0)