From b26c9ce5e9b1c80a59f4faeb92be4a302232e12c Mon Sep 17 00:00:00 2001 From: Maxime Chevalier-Boisvert Date: Thu, 8 Dec 2022 17:31:33 -0500 Subject: YJIT: implement opt_newarray_min YARV instruction (#6888) --- yjit/src/codegen.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'yjit') diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs index e01266ff21..914d04bb97 100644 --- a/yjit/src/codegen.rs +++ b/yjit/src/codegen.rs @@ -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, @@ -6931,6 +6967,7 @@ fn get_gen_fn(opcode: VALUE) -> Option { 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), -- cgit v1.2.3