Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YJIT: implement opt_newarray_min YARV instruction #6888

Merged
merged 1 commit into from Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions vm_insnhelper.c
Expand Up @@ -5216,6 +5216,12 @@ vm_opt_newarray_min(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr)
}
}

VALUE
rb_vm_opt_newarray_min(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr)
{
return vm_opt_newarray_min(ec, num, ptr);
}

#undef id_cmp

#define IMEMO_CONST_CACHE_SHAREABLE IMEMO_FL_USER0
Expand Down
37 changes: 37 additions & 0 deletions yjit/src/codegen.rs
Expand Up @@ -3304,6 +3304,42 @@ fn gen_opt_str_uminus(
KeepCompiling
}

fn gen_opt_newarray_min(
jit: &mut JITState,
ctx: &mut Context,
asm: &mut Assembler,
_ocb: &mut OutlinedCb,
) -> CodegenStatus {

let num = jit_get_arg(jit, 0).as_u32();

// Save the PC and SP because we may allocate
jit_prepare_routine_call(jit, ctx, asm);

extern "C" {
fn rb_vm_opt_newarray_min(ec: EcPtr, num: u32, elts: *const VALUE) -> VALUE;
}

let offset_magnitude = (SIZEOF_VALUE as u32) * num;
let values_opnd = ctx.sp_opnd(-(offset_magnitude as isize));
let values_ptr = asm.lea(values_opnd);

let val_opnd = asm.ccall(
rb_vm_opt_newarray_min as *const u8,
vec![
EC,
num.into(),
values_ptr
],
);

ctx.stack_pop(num.as_usize());
let stack_ret = ctx.stack_push(Type::Unknown);
asm.mov(stack_ret, val_opnd);

KeepCompiling
}

fn gen_opt_not(
jit: &mut JITState,
ctx: &mut Context,
Expand Down Expand Up @@ -6931,6 +6967,7 @@ 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_opt_newarray_min => Some(gen_opt_newarray_min),
YARVINSN_splatarray => Some(gen_splatarray),
YARVINSN_concatarray => Some(gen_concatarray),
YARVINSN_newrange => Some(gen_newrange),
Expand Down