diff options
author | Aaron Patterson <tenderlove@ruby-lang.org> | 2023-04-18 13:16:14 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2023-04-18 17:16:22 -0700 |
commit | b816ea87725d85b0b9cf9628603245041a2d5123 (patch) | |
tree | 87b150264fc31d00f3cb28dd2d64b5dc875e27e8 /yjit | |
parent | 66938fc703af9df14d0bb5958e55728fc8fd481c (diff) |
Implement opt_newarray_send in YJIT
This commit implements opt_newarray_send along with min / max / hash for
stack allocated arrays
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/6090
Diffstat (limited to 'yjit')
-rw-r--r-- | yjit/src/codegen.rs | 56 |
1 files changed, 54 insertions, 2 deletions
diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs index 3f12d3c273..640940777c 100644 --- a/yjit/src/codegen.rs +++ b/yjit/src/codegen.rs @@ -3359,6 +3359,59 @@ fn gen_opt_newarray_max( Some(KeepCompiling) } +fn gen_opt_newarray_send( + jit: &mut JITState, + asm: &mut Assembler, + _ocb: &mut OutlinedCb, +) -> Option<CodegenStatus> { + let method = jit.get_arg(1).as_u32(); + + if method == idMin { + gen_opt_newarray_min(jit, asm, _ocb) + } else if method == idMax { + gen_opt_newarray_max(jit, asm, _ocb) + } else if method == idHash { + gen_opt_newarray_hash(jit, asm, _ocb) + } else { + None + } +} + +fn gen_opt_newarray_hash( + jit: &mut JITState, + asm: &mut Assembler, + _ocb: &mut OutlinedCb, +) -> Option<CodegenStatus> { + + let num = jit.get_arg(0).as_u32(); + + // Save the PC and SP because we may allocate + jit_prepare_routine_call(jit, asm); + + extern "C" { + fn rb_vm_opt_newarray_hash(ec: EcPtr, num: u32, elts: *const VALUE) -> VALUE; + } + + let offset_magnitude = (SIZEOF_VALUE as u32) * num; + let values_opnd = asm.ctx.sp_opnd(-(offset_magnitude as isize)); + let values_ptr = asm.lea(values_opnd); + + let val_opnd = asm.ccall( + rb_vm_opt_newarray_hash as *const u8, + vec![ + EC, + num.into(), + values_ptr + ], + ); + + asm.stack_pop(num.as_usize()); + let stack_ret = asm.stack_push(Type::Unknown); + asm.mov(stack_ret, val_opnd); + + Some(KeepCompiling) +} + fn gen_opt_newarray_min( jit: &mut JITState, asm: &mut Assembler, @@ -7824,8 +7877,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_max => Some(gen_opt_newarray_max), - YARVINSN_opt_newarray_min => Some(gen_opt_newarray_min), + YARVINSN_opt_newarray_send => Some(gen_opt_newarray_send), YARVINSN_splatarray => Some(gen_splatarray), YARVINSN_concatarray => Some(gen_concatarray), YARVINSN_newrange => Some(gen_newrange), |