From 401d5d7339a30e29bbe2b758dc7495bb2f127e4b Mon Sep 17 00:00:00 2001 From: Noah Gibbs Date: Fri, 22 Jul 2022 17:08:35 +0100 Subject: [PATCH] Port and test duparray and splatarray (https://github.com/Shopify/ruby/pull/337) * Port duparray opcode * Port and test splatarray --- bootstraptest/test_yjit_new_backend.rb | 17 +++++++++++++++ yjit/src/codegen.rs | 30 +++++++++++--------------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/bootstraptest/test_yjit_new_backend.rb b/bootstraptest/test_yjit_new_backend.rb index 266e0c618bb294..07610f1c869688 100644 --- a/bootstraptest/test_yjit_new_backend.rb +++ b/bootstraptest/test_yjit_new_backend.rb @@ -66,6 +66,23 @@ def foo() foo() } +# duparray +assert_equal '[111]', %q{ + def foo() + [ 111 ] + end + foo() +} + +# splatarray +assert_equal 'true', %q{ + def foo() + x, = *(y = true), false + x + end + foo() +} + # putobject, getlocal, newhash assert_equal '{:a=>777}', %q{ def foo(n) diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs index 9f39c77bb6f303..fa0394eed54536 100644 --- a/yjit/src/codegen.rs +++ b/yjit/src/codegen.rs @@ -1181,29 +1181,29 @@ fn gen_newarray( KeepCompiling } -/* // dup array fn gen_duparray( jit: &mut JITState, ctx: &mut Context, - cb: &mut CodeBlock, + asm: &mut Assembler, _ocb: &mut OutlinedCb, ) -> CodegenStatus { let ary = jit_get_arg(jit, 0); // Save the PC and SP because we are allocating - jit_prepare_routine_call(jit, ctx, cb, REG0); + jit_prepare_routine_call(jit, ctx, asm); // call rb_ary_resurrect(VALUE ary); - jit_mov_gc_ptr(jit, cb, C_ARG_REGS[0], ary); - call_ptr(cb, REG0, rb_ary_resurrect as *const u8); + let new_ary = asm.ccall( + rb_ary_resurrect as *const u8, + vec![ary.into()], + ); let stack_ret = ctx.stack_push(Type::Array); - mov(cb, stack_ret, RAX); + asm.mov(stack_ret, new_ary); KeepCompiling } -*/ // dup hash fn gen_duphash( @@ -1226,34 +1226,30 @@ fn gen_duphash( KeepCompiling } -/* // call to_a on the array on the stack fn gen_splatarray( jit: &mut JITState, ctx: &mut Context, - cb: &mut CodeBlock, + asm: &mut Assembler, _ocb: &mut OutlinedCb, ) -> CodegenStatus { let flag = jit_get_arg(jit, 0); // 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, cb, REG0); + jit_prepare_routine_call(jit, ctx, asm); // Get the operands from the stack let ary_opnd = ctx.stack_pop(1); // Call rb_vm_splat_array(flag, ary) - jit_mov_gc_ptr(jit, cb, C_ARG_REGS[0], flag); - mov(cb, C_ARG_REGS[1], ary_opnd); - call_ptr(cb, REG1, rb_vm_splat_array as *const u8); + let ary = asm.ccall(rb_vm_splat_array as *const u8, vec![flag.into(), ary_opnd]); let stack_ret = ctx.stack_push(Type::Array); - mov(cb, stack_ret, RAX); + asm.mov(stack_ret, ary); KeepCompiling } -*/ // new range initialized from top 2 values fn gen_newrange( @@ -5988,7 +5984,7 @@ fn get_gen_fn(opcode: VALUE) -> Option { YARVINSN_newhash => Some(gen_newhash), YARVINSN_duphash => Some(gen_duphash), YARVINSN_newarray => Some(gen_newarray), - //YARVINSN_duparray => Some(gen_duparray), + YARVINSN_duparray => Some(gen_duparray), //YARVINSN_checktype => Some(gen_checktype), YARVINSN_opt_lt => Some(gen_opt_lt), /* @@ -5998,8 +5994,8 @@ 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_splatarray => Some(gen_splatarray), */ + YARVINSN_splatarray => Some(gen_splatarray), YARVINSN_newrange => Some(gen_newrange), YARVINSN_putstring => Some(gen_putstring), /*