Skip to content

Commit

Permalink
Port and test duparray and splatarray (#337)
Browse files Browse the repository at this point in the history
* Port duparray opcode

* Port and test splatarray
  • Loading branch information
noahgibbs authored and k0kubun committed Aug 26, 2022
1 parent ff5fa44 commit 6147438
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
17 changes: 17 additions & 0 deletions bootstraptest/test_yjit_new_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@ def foo()
foo()
}

# duparray
assert_equal '[111]', %q{
def foo()
[ 111 ]
end
foo()
}

# splatarray
assert_equal 'true', %q{
def foo()
x, = *(y = true), false
x
end
foo()
}

# putobject, getlocal, newhash
assert_equal '{:a=>777}', %q{
def foo(n)
Expand Down
30 changes: 13 additions & 17 deletions yjit/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1181,29 +1181,29 @@ fn gen_newarray(
KeepCompiling
}

/*
// dup array
fn gen_duparray(
jit: &mut JITState,
ctx: &mut Context,
cb: &mut CodeBlock,
asm: &mut Assembler,
_ocb: &mut OutlinedCb,
) -> CodegenStatus {
let ary = jit_get_arg(jit, 0);

// Save the PC and SP because we are allocating
jit_prepare_routine_call(jit, ctx, cb, REG0);
jit_prepare_routine_call(jit, ctx, asm);

// call rb_ary_resurrect(VALUE ary);
jit_mov_gc_ptr(jit, cb, C_ARG_REGS[0], ary);
call_ptr(cb, REG0, rb_ary_resurrect as *const u8);
let new_ary = asm.ccall(
rb_ary_resurrect as *const u8,
vec![ary.into()],
);

let stack_ret = ctx.stack_push(Type::Array);
mov(cb, stack_ret, RAX);
asm.mov(stack_ret, new_ary);

KeepCompiling
}
*/

// dup hash
fn gen_duphash(
Expand All @@ -1226,34 +1226,30 @@ fn gen_duphash(
KeepCompiling
}

/*
// call to_a on the array on the stack
fn gen_splatarray(
jit: &mut JITState,
ctx: &mut Context,
cb: &mut CodeBlock,
asm: &mut Assembler,
_ocb: &mut OutlinedCb,
) -> CodegenStatus {
let flag = jit_get_arg(jit, 0);

// Save the PC and SP because the callee may allocate
// Note that this modifies REG_SP, which is why we do it first
jit_prepare_routine_call(jit, ctx, cb, REG0);
jit_prepare_routine_call(jit, ctx, asm);

// Get the operands from the stack
let ary_opnd = ctx.stack_pop(1);

// Call rb_vm_splat_array(flag, ary)
jit_mov_gc_ptr(jit, cb, C_ARG_REGS[0], flag);
mov(cb, C_ARG_REGS[1], ary_opnd);
call_ptr(cb, REG1, rb_vm_splat_array as *const u8);
let ary = asm.ccall(rb_vm_splat_array as *const u8, vec![flag.into(), ary_opnd]);

let stack_ret = ctx.stack_push(Type::Array);
mov(cb, stack_ret, RAX);
asm.mov(stack_ret, ary);

KeepCompiling
}
*/

// new range initialized from top 2 values
fn gen_newrange(
Expand Down Expand Up @@ -5988,7 +5984,7 @@ fn get_gen_fn(opcode: VALUE) -> Option<InsnGenFn> {
YARVINSN_newhash => Some(gen_newhash),
YARVINSN_duphash => Some(gen_duphash),
YARVINSN_newarray => Some(gen_newarray),
//YARVINSN_duparray => Some(gen_duparray),
YARVINSN_duparray => Some(gen_duparray),
//YARVINSN_checktype => Some(gen_checktype),
YARVINSN_opt_lt => Some(gen_opt_lt),
/*
Expand All @@ -5998,8 +5994,8 @@ fn get_gen_fn(opcode: VALUE) -> Option<InsnGenFn> {
YARVINSN_opt_mod => Some(gen_opt_mod),
YARVINSN_opt_str_freeze => Some(gen_opt_str_freeze),
YARVINSN_opt_str_uminus => Some(gen_opt_str_uminus),
YARVINSN_splatarray => Some(gen_splatarray),
*/
YARVINSN_splatarray => Some(gen_splatarray),
YARVINSN_newrange => Some(gen_newrange),
YARVINSN_putstring => Some(gen_putstring),
/*
Expand Down

0 comments on commit 6147438

Please sign in to comment.