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