Skip to content

Commit ece6246

Browse files
authored
YJIT: Implement opt_newarray_max instruction (#6893)
1 parent 5302d04 commit ece6246

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

vm_insnhelper.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5196,6 +5196,12 @@ vm_opt_newarray_max(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr)
51965196
}
51975197
}
51985198

5199+
VALUE
5200+
rb_vm_opt_newarray_max(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr)
5201+
{
5202+
return vm_opt_newarray_max(ec, num, ptr);
5203+
}
5204+
51995205
static VALUE
52005206
vm_opt_newarray_min(rb_execution_context_t *ec, rb_num_t num, const VALUE *ptr)
52015207
{

yjit/src/codegen.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3304,6 +3304,41 @@ fn gen_opt_str_uminus(
33043304
KeepCompiling
33053305
}
33063306

3307+
fn gen_opt_newarray_max(
3308+
jit: &mut JITState,
3309+
ctx: &mut Context,
3310+
asm: &mut Assembler,
3311+
_ocb: &mut OutlinedCb,
3312+
) -> CodegenStatus {
3313+
let num = jit_get_arg(jit, 0).as_u32();
3314+
3315+
// Save the PC and SP because we may allocate
3316+
jit_prepare_routine_call(jit, ctx, asm);
3317+
3318+
extern "C" {
3319+
fn rb_vm_opt_newarray_max(ec: EcPtr, num: u32, elts: *const VALUE) -> VALUE;
3320+
}
3321+
3322+
let offset_magnitude = (SIZEOF_VALUE as u32) * num;
3323+
let values_opnd = ctx.sp_opnd(-(offset_magnitude as isize));
3324+
let values_ptr = asm.lea(values_opnd);
3325+
3326+
let val_opnd = asm.ccall(
3327+
rb_vm_opt_newarray_max as *const u8,
3328+
vec![
3329+
EC,
3330+
num.into(),
3331+
values_ptr
3332+
],
3333+
);
3334+
3335+
ctx.stack_pop(num.as_usize());
3336+
let stack_ret = ctx.stack_push(Type::Unknown);
3337+
asm.mov(stack_ret, val_opnd);
3338+
3339+
KeepCompiling
3340+
}
3341+
33073342
fn gen_opt_newarray_min(
33083343
jit: &mut JITState,
33093344
ctx: &mut Context,
@@ -7006,6 +7041,7 @@ fn get_gen_fn(opcode: VALUE) -> Option<InsnGenFn> {
70067041
YARVINSN_opt_mod => Some(gen_opt_mod),
70077042
YARVINSN_opt_str_freeze => Some(gen_opt_str_freeze),
70087043
YARVINSN_opt_str_uminus => Some(gen_opt_str_uminus),
7044+
YARVINSN_opt_newarray_max => Some(gen_opt_newarray_max),
70097045
YARVINSN_opt_newarray_min => Some(gen_opt_newarray_min),
70107046
YARVINSN_splatarray => Some(gen_splatarray),
70117047
YARVINSN_concatarray => Some(gen_concatarray),

0 commit comments

Comments
 (0)