@@ -478,6 +478,34 @@ gen_dup(jitstate_t* jit, ctx_t* ctx)
478478 return YJIT_KEEP_COMPILING ;
479479}
480480
481+ // duplicate stack top n elements
482+ static codegen_status_t
483+ gen_dupn (jitstate_t * jit , ctx_t * ctx )
484+ {
485+ rb_num_t n = (rb_num_t )jit_get_arg (jit , 0 );
486+
487+ // In practice, seems to be only used for n==2
488+ if (n != 2 ) {
489+ return YJIT_CANT_COMPILE ;
490+ }
491+
492+ val_type_t type1 = ctx_get_opnd_type (ctx , OPND_STACK (1 ));
493+ x86opnd_t opnd1 = ctx_stack_opnd (ctx , 1 );
494+
495+ val_type_t type0 = ctx_get_opnd_type (ctx , OPND_STACK (0 ));
496+ x86opnd_t opnd0 = ctx_stack_opnd (ctx , 0 );
497+
498+ x86opnd_t dst1 = ctx_stack_push (ctx , type1 );
499+ mov (cb , REG0 , opnd1 );
500+ mov (cb , dst1 , REG0 );
501+
502+ x86opnd_t dst0 = ctx_stack_push (ctx , type0 );
503+ mov (cb , REG0 , opnd0 );
504+ mov (cb , dst0 , REG0 );
505+
506+ return YJIT_KEEP_COMPILING ;
507+ }
508+
481509// set Nth stack entry to stack top
482510static codegen_status_t
483511gen_setn (jitstate_t * jit , ctx_t * ctx )
@@ -505,6 +533,15 @@ gen_pop(jitstate_t* jit, ctx_t* ctx)
505533 return YJIT_KEEP_COMPILING ;
506534}
507535
536+ // Pop n values off the stack
537+ static codegen_status_t
538+ gen_adjuststack (jitstate_t * jit , ctx_t * ctx )
539+ {
540+ rb_num_t n = (rb_num_t )jit_get_arg (jit , 0 );
541+ ctx_stack_pop (ctx , n );
542+ return YJIT_KEEP_COMPILING ;
543+ }
544+
508545static codegen_status_t
509546gen_putnil (jitstate_t * jit , ctx_t * ctx )
510547{
@@ -2260,8 +2297,10 @@ yjit_init_codegen(void)
22602297 // Map YARV opcodes to the corresponding codegen functions
22612298 yjit_reg_op (BIN (nop ), gen_nop );
22622299 yjit_reg_op (BIN (dup ), gen_dup );
2300+ yjit_reg_op (BIN (dupn ), gen_dupn );
22632301 yjit_reg_op (BIN (setn ), gen_setn );
22642302 yjit_reg_op (BIN (pop ), gen_pop );
2303+ yjit_reg_op (BIN (adjuststack ), gen_adjuststack );
22652304 yjit_reg_op (BIN (putnil ), gen_putnil );
22662305 yjit_reg_op (BIN (putobject ), gen_putobject );
22672306 yjit_reg_op (BIN (putobject_INT2FIX_0_ ), gen_putobject_int2fix );
0 commit comments