@@ -454,6 +454,13 @@ yjit_gen_block(block_t *block, rb_execution_context_t *ec)
454
454
}
455
455
}
456
456
457
+ static codegen_status_t
458
+ gen_nop (jitstate_t * jit , ctx_t * ctx )
459
+ {
460
+ // Do nothing
461
+ return YJIT_KEEP_COMPILING ;
462
+ }
463
+
457
464
static codegen_status_t
458
465
gen_dup (jitstate_t * jit , ctx_t * ctx )
459
466
{
@@ -469,10 +476,22 @@ gen_dup(jitstate_t* jit, ctx_t* ctx)
469
476
return YJIT_KEEP_COMPILING ;
470
477
}
471
478
479
+ // set Nth stack entry to stack top
472
480
static codegen_status_t
473
- gen_nop (jitstate_t * jit , ctx_t * ctx )
481
+ gen_setn (jitstate_t * jit , ctx_t * ctx )
474
482
{
475
- // Do nothing
483
+ rb_num_t n = (rb_num_t )jit_get_arg (jit , 0 );
484
+
485
+ // Get the top value and its type
486
+ val_type_t top_type = ctx_get_opnd_type (ctx , OPND_STACK (0 ));
487
+ x86opnd_t top_val = ctx_stack_pop (ctx , 0 );
488
+
489
+ // Set the destination and its type
490
+ ctx_set_opnd_type (ctx , OPND_STACK (n ), top_type );
491
+ x86opnd_t dst_opnd = ctx_stack_opnd (ctx , (int32_t )n );
492
+ mov (cb , REG0 , top_val );
493
+ mov (cb , dst_opnd , REG0 );
494
+
476
495
return YJIT_KEEP_COMPILING ;
477
496
}
478
497
@@ -2219,8 +2238,9 @@ yjit_init_codegen(void)
2219
2238
leave_exit_code = yjit_gen_leave_exit (cb );
2220
2239
2221
2240
// Map YARV opcodes to the corresponding codegen functions
2222
- yjit_reg_op (BIN (dup ), gen_dup );
2223
2241
yjit_reg_op (BIN (nop ), gen_nop );
2242
+ yjit_reg_op (BIN (dup ), gen_dup );
2243
+ yjit_reg_op (BIN (setn ), gen_setn );
2224
2244
yjit_reg_op (BIN (pop ), gen_pop );
2225
2245
yjit_reg_op (BIN (putnil ), gen_putnil );
2226
2246
yjit_reg_op (BIN (putobject ), gen_putobject );
0 commit comments