summaryrefslogtreecommitdiff
path: root/yjit
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2022-12-12 07:19:24 -0800
committerGitHub <noreply@github.com>2022-12-12 10:19:24 -0500
commitece624605785f6640118a0cfd97618e71abfbee8 (patch)
tree63d698e04382b9553dd0c135a0160aacda858693 /yjit
parent5302d04e5a7fe226a4e9f6aba8b681e0d5088b27 (diff)
YJIT: Implement opt_newarray_max instruction (#6893)
Notes
Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
Diffstat (limited to 'yjit')
-rw-r--r--yjit/src/codegen.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs
index e18594413c..16fe837f4d 100644
--- a/yjit/src/codegen.rs
+++ b/yjit/src/codegen.rs
@@ -3304,6 +3304,41 @@ fn gen_opt_str_uminus(
KeepCompiling
}
+fn gen_opt_newarray_max(
+ 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_max(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_max 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_newarray_min(
jit: &mut JITState,
ctx: &mut Context,
@@ -7006,6 +7041,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_splatarray => Some(gen_splatarray),
YARVINSN_concatarray => Some(gen_concatarray),