YJIT: add specialized codegen for fixnum XOR (#9763)

This commit is contained in:
Maxime Chevalier-Boisvert 2024-01-30 14:57:13 -05:00 committed by GitHub
parent 731367d0ab
commit fe5590e464
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 36 additions and 0 deletions

View File

@ -1,3 +1,6 @@
# To run the tests in this file only, with YJIT enabled:
# make btest BTESTS=bootstraptest/test_yjit.rb RUN_OPTS="--yjit-call-threshold=1"
# regression test for popping before side exit
assert_equal "ok", %q{
def foo(a, *) = a
@ -4451,6 +4454,11 @@ assert_equal '[0, 1, -4]', %q{
[0 >> 1, 2 >> 1, -7 >> 1]
}
# Integer XOR
assert_equal '[0, 0, 4]', %q{
[0 ^ 0, 1 ^ 1, 7 ^ 3]
}
assert_equal '[nil, "yield"]', %q{
def defined_yield = defined?(yield)
[defined_yield, defined_yield {}]

View File

@ -4877,6 +4877,33 @@ fn jit_rb_int_rshift(
true
}
fn jit_rb_int_xor(
jit: &mut JITState,
asm: &mut Assembler,
ocb: &mut OutlinedCb,
_ci: *const rb_callinfo,
_cme: *const rb_callable_method_entry_t,
_block: Option<BlockHandler>,
_argc: i32,
_known_recv_class: *const VALUE,
) -> bool {
if asm.ctx.two_fixnums_on_stack(jit) != Some(true) {
return false;
}
guard_two_fixnums(jit, asm, ocb);
let rhs = asm.stack_pop(1);
let lhs = asm.stack_pop(1);
// XOR and then re-tag the resulting fixnum
let out_val = asm.xor(lhs, rhs);
let out_val = asm.or(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,
asm: &mut Assembler,
@ -9090,6 +9117,7 @@ pub fn yjit_reg_method_codegen_fns() {
yjit_reg_method(rb_cInteger, "/", jit_rb_int_div);
yjit_reg_method(rb_cInteger, "<<", jit_rb_int_lshift);
yjit_reg_method(rb_cInteger, ">>", jit_rb_int_rshift);
yjit_reg_method(rb_cInteger, "^", jit_rb_int_xor);
yjit_reg_method(rb_cInteger, "[]", jit_rb_int_aref);
yjit_reg_method(rb_cString, "empty?", jit_rb_str_empty_p);