summaryrefslogtreecommitdiff
path: root/yjit/src/codegen.rs
diff options
context:
space:
mode:
authorMaple Ong <maple.develops@gmail.com>2022-08-15 12:54:26 -0400
committerTakashi Kokubun <takashikkbn@gmail.com>2022-08-29 08:47:11 -0700
commit5a76a15a0f93100c7ff6361a34b06af936cc36c6 (patch)
tree8e11582f3ce368481939f415cfc5ab7ba372f0e4 /yjit/src/codegen.rs
parent2f9df466546263028ece7757cb6f813800d2d6b5 (diff)
YJIT: Implement concatarray in yjit (https://github.com/Shopify/ruby/pull/405)
* Create code generation func * Make rb_vm_concat_array available to use in Rust * Map opcode to code gen func * Implement code gen for concatarray * Add test for concatarray * Use new asm backend * Add comment to C func wrapper
Diffstat (limited to 'yjit/src/codegen.rs')
-rw-r--r--yjit/src/codegen.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs
index 3428466297..a6473842f8 100644
--- a/yjit/src/codegen.rs
+++ b/yjit/src/codegen.rs
@@ -1256,6 +1256,30 @@ fn gen_splatarray(
KeepCompiling
}
+// concat two arrays
+fn gen_concatarray(
+ jit: &mut JITState,
+ ctx: &mut Context,
+ asm: &mut Assembler,
+ _ocb: &mut OutlinedCb,
+) -> CodegenStatus {
+ // Save the PC and SP because the callee may allocate
+ // Note that this modifies REG_SP, which is why we do it first
+ jit_prepare_routine_call(jit, ctx, asm);
+
+ // Get the operands from the stack
+ let ary2st_opnd = ctx.stack_pop(1);
+ let ary1_opnd = ctx.stack_pop(1);
+
+ // Call rb_vm_concat_array(ary1, ary2st)
+ let ary = asm.ccall(rb_vm_concat_array as *const u8, vec![ary1_opnd, ary2st_opnd]);
+
+ let stack_ret = ctx.stack_push(Type::Array);
+ asm.mov(stack_ret, ary);
+
+ KeepCompiling
+}
+
// new range initialized from top 2 values
fn gen_newrange(
jit: &mut JITState,
@@ -5862,6 +5886,7 @@ fn get_gen_fn(opcode: VALUE) -> Option<InsnGenFn> {
YARVINSN_opt_str_freeze => Some(gen_opt_str_freeze),
YARVINSN_opt_str_uminus => Some(gen_opt_str_uminus),
YARVINSN_splatarray => Some(gen_splatarray),
+ YARVINSN_concatarray => Some(gen_concatarray),
YARVINSN_newrange => Some(gen_newrange),
YARVINSN_putstring => Some(gen_putstring),
YARVINSN_expandarray => Some(gen_expandarray),