YJIT: implement codegen for rb_int_lshift (#8201)
* YJIT: implement codegen for rb_int_lshift * Update yjit/src/asm/x86_64/mod.rs Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com> --------- Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
This commit is contained in:
parent
475241ee91
commit
a8cd18f08d
Notes:
git
2023-08-11 15:01:37 +00:00
Merged-By: maximecb <maximecb@ruby-lang.org>
1
yjit.rb
1
yjit.rb
@ -264,6 +264,7 @@ module RubyVM::YJIT
|
||||
print_counters(stats, out: out, prefix: 'opt_aref_', prompt: 'opt_aref exit reasons: ')
|
||||
print_counters(stats, out: out, prefix: 'opt_aref_with_', prompt: 'opt_aref_with exit reasons: ')
|
||||
print_counters(stats, out: out, prefix: 'expandarray_', prompt: 'expandarray exit reasons: ')
|
||||
print_counters(stats, out: out, prefix: 'lshift_', prompt: 'left shift (ltlt) exit reasons: ')
|
||||
print_counters(stats, out: out, prefix: 'opt_getconstant_path_', prompt: 'opt_getconstant_path exit reasons: ')
|
||||
print_counters(stats, out: out, prefix: 'invalidate_', prompt: 'invalidation reasons: ')
|
||||
|
||||
|
@ -1277,7 +1277,7 @@ fn write_shift(cb: &mut CodeBlock, op_mem_one_pref: u8, op_mem_cl_pref: u8, op_m
|
||||
}
|
||||
|
||||
_ => {
|
||||
unreachable!();
|
||||
unreachable!("unsupported operands: {:?}, {:?}", opnd0, opnd1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -544,6 +544,7 @@ impl Insn {
|
||||
Insn::Jb(target) |
|
||||
Insn::Je(target) |
|
||||
Insn::Jl(target) |
|
||||
Insn::Jg(target) |
|
||||
Insn::Jmp(target) |
|
||||
Insn::Jne(target) |
|
||||
Insn::Jnz(target) |
|
||||
@ -692,6 +693,7 @@ impl Insn {
|
||||
Insn::Jb(target) |
|
||||
Insn::Je(target) |
|
||||
Insn::Jl(target) |
|
||||
Insn::Jg(target) |
|
||||
Insn::Jmp(target) |
|
||||
Insn::Jne(target) |
|
||||
Insn::Jnz(target) |
|
||||
@ -1843,6 +1845,10 @@ impl Assembler {
|
||||
self.push_insn(Insn::Jl(target));
|
||||
}
|
||||
|
||||
pub fn jg(&mut self, target: Target) {
|
||||
self.push_insn(Insn::Jg(target));
|
||||
}
|
||||
|
||||
pub fn jmp(&mut self, target: Target) {
|
||||
self.push_insn(Insn::Jmp(target));
|
||||
}
|
||||
|
@ -4471,7 +4471,6 @@ fn jit_rb_int_div(
|
||||
true
|
||||
}
|
||||
|
||||
/*
|
||||
fn jit_rb_int_lshift(
|
||||
jit: &mut JITState,
|
||||
asm: &mut Assembler,
|
||||
@ -4487,28 +4486,42 @@ fn jit_rb_int_lshift(
|
||||
}
|
||||
guard_two_fixnums(jit, asm, ocb);
|
||||
|
||||
let comptime_shift = jit.peek_at_stack(&asm.ctx, 0);
|
||||
|
||||
if !comptime_shift.fixnum_p() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Untag the fixnum shift amount
|
||||
let shift_amt = comptime_shift.as_isize() >> 1;
|
||||
|
||||
if shift_amt > 63 || shift_amt < 0 {
|
||||
return false;
|
||||
}
|
||||
|
||||
let rhs = asm.stack_pop(1);
|
||||
let lhs = asm.stack_pop(1);
|
||||
|
||||
// Ruby supports using a negative shift value
|
||||
asm.comment("Guard shift negative");
|
||||
let shift_val = asm.sub(rhs, 1.into());
|
||||
asm.cmp(shift_val, 0.into());
|
||||
asm.jl(Target::side_exit(Counter::lshift_range));
|
||||
// Guard on the shift value we speculated on
|
||||
asm.cmp(rhs, comptime_shift.into());
|
||||
asm.jne(Target::side_exit(Counter::lshift_amt_changed));
|
||||
|
||||
asm.cmp(shift_val, 63.into());
|
||||
asm.jg(Target::side_exit(Counter::lshift_range));
|
||||
let in_val = asm.sub(lhs, 1.into());
|
||||
let shift_opnd = Opnd::UImm(shift_amt as u64);
|
||||
let out_val = asm.lshift(in_val, shift_opnd);
|
||||
let unshifted = asm.rshift(out_val, shift_opnd);
|
||||
|
||||
// FIXME: we don't yet support shift with non-immediate values in the backend
|
||||
// Do the shifting
|
||||
let out_val = asm.lshift(lhs, shift_val);
|
||||
asm.jo(Target::side_exit(Counter::lshift_overflow));
|
||||
// Guard that we did not overflow
|
||||
asm.cmp(unshifted, in_val);
|
||||
asm.jne(Target::side_exit(Counter::lshift_overflow));
|
||||
|
||||
// Re-tag the output value
|
||||
let out_val = asm.add(out_val, 1.into());
|
||||
|
||||
let ret_opnd = asm.stack_push(Type::Fixnum);
|
||||
asm.mov(ret_opnd, out_val);
|
||||
true
|
||||
}
|
||||
*/
|
||||
|
||||
fn jit_rb_int_aref(
|
||||
jit: &mut JITState,
|
||||
@ -8593,7 +8606,7 @@ impl CodegenGlobals {
|
||||
|
||||
self.yjit_reg_method(rb_cInteger, "*", jit_rb_int_mul);
|
||||
self.yjit_reg_method(rb_cInteger, "/", jit_rb_int_div);
|
||||
//self.yjit_reg_method(rb_cInteger, "<<", jit_rb_int_lshift);
|
||||
self.yjit_reg_method(rb_cInteger, "<<", jit_rb_int_lshift);
|
||||
self.yjit_reg_method(rb_cInteger, "[]", jit_rb_int_aref);
|
||||
|
||||
// rb_str_to_s() methods in string.c
|
||||
|
@ -348,7 +348,7 @@ make_counters! {
|
||||
opt_mod_zero,
|
||||
opt_div_zero,
|
||||
|
||||
lshift_range,
|
||||
lshift_amt_changed,
|
||||
lshift_overflow,
|
||||
|
||||
opt_aref_argc_not_one,
|
||||
|
Loading…
x
Reference in New Issue
Block a user