@@ -478,6 +478,34 @@ gen_dup(jitstate_t* jit, ctx_t* ctx)
478
478
return YJIT_KEEP_COMPILING ;
479
479
}
480
480
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
+
481
509
// set Nth stack entry to stack top
482
510
static codegen_status_t
483
511
gen_setn (jitstate_t * jit , ctx_t * ctx )
@@ -505,6 +533,15 @@ gen_pop(jitstate_t* jit, ctx_t* ctx)
505
533
return YJIT_KEEP_COMPILING ;
506
534
}
507
535
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
+
508
545
static codegen_status_t
509
546
gen_putnil (jitstate_t * jit , ctx_t * ctx )
510
547
{
@@ -2260,8 +2297,10 @@ yjit_init_codegen(void)
2260
2297
// Map YARV opcodes to the corresponding codegen functions
2261
2298
yjit_reg_op (BIN (nop ), gen_nop );
2262
2299
yjit_reg_op (BIN (dup ), gen_dup );
2300
+ yjit_reg_op (BIN (dupn ), gen_dupn );
2263
2301
yjit_reg_op (BIN (setn ), gen_setn );
2264
2302
yjit_reg_op (BIN (pop ), gen_pop );
2303
+ yjit_reg_op (BIN (adjuststack ), gen_adjuststack );
2265
2304
yjit_reg_op (BIN (putnil ), gen_putnil );
2266
2305
yjit_reg_op (BIN (putobject ), gen_putobject );
2267
2306
yjit_reg_op (BIN (putobject_INT2FIX_0_ ), gen_putobject_int2fix );
0 commit comments