@@ -476,6 +476,34 @@ gen_dup(jitstate_t* jit, ctx_t* ctx)
476
476
return YJIT_KEEP_COMPILING ;
477
477
}
478
478
479
+ // duplicate stack top n elements
480
+ static codegen_status_t
481
+ gen_dupn (jitstate_t * jit , ctx_t * ctx )
482
+ {
483
+ rb_num_t n = (rb_num_t )jit_get_arg (jit , 0 );
484
+
485
+ // In practice, seems to be only used for n==2
486
+ if (n != 2 ) {
487
+ return YJIT_CANT_COMPILE ;
488
+ }
489
+
490
+ val_type_t type1 = ctx_get_opnd_type (ctx , OPND_STACK (1 ));
491
+ x86opnd_t opnd1 = ctx_stack_opnd (ctx , 1 );
492
+
493
+ val_type_t type0 = ctx_get_opnd_type (ctx , OPND_STACK (0 ));
494
+ x86opnd_t opnd0 = ctx_stack_opnd (ctx , 0 );
495
+
496
+ x86opnd_t dst1 = ctx_stack_push (ctx , type1 );
497
+ mov (cb , REG0 , opnd1 );
498
+ mov (cb , dst1 , REG0 );
499
+
500
+ x86opnd_t dst0 = ctx_stack_push (ctx , type0 );
501
+ mov (cb , REG0 , opnd0 );
502
+ mov (cb , dst0 , REG0 );
503
+
504
+ return YJIT_KEEP_COMPILING ;
505
+ }
506
+
479
507
// set Nth stack entry to stack top
480
508
static codegen_status_t
481
509
gen_setn (jitstate_t * jit , ctx_t * ctx )
@@ -503,6 +531,15 @@ gen_pop(jitstate_t* jit, ctx_t* ctx)
503
531
return YJIT_KEEP_COMPILING ;
504
532
}
505
533
534
+ // Pop n values off the stack
535
+ static codegen_status_t
536
+ gen_adjuststack (jitstate_t * jit , ctx_t * ctx )
537
+ {
538
+ rb_num_t n = (rb_num_t )jit_get_arg (jit , 0 );
539
+ ctx_stack_pop (ctx , n );
540
+ return YJIT_KEEP_COMPILING ;
541
+ }
542
+
506
543
static codegen_status_t
507
544
gen_putnil (jitstate_t * jit , ctx_t * ctx )
508
545
{
@@ -2259,8 +2296,10 @@ yjit_init_codegen(void)
2259
2296
// Map YARV opcodes to the corresponding codegen functions
2260
2297
yjit_reg_op (BIN (nop ), gen_nop );
2261
2298
yjit_reg_op (BIN (dup ), gen_dup );
2299
+ yjit_reg_op (BIN (dupn ), gen_dupn );
2262
2300
yjit_reg_op (BIN (setn ), gen_setn );
2263
2301
yjit_reg_op (BIN (pop ), gen_pop );
2302
+ yjit_reg_op (BIN (adjuststack ), gen_adjuststack );
2264
2303
yjit_reg_op (BIN (putnil ), gen_putnil );
2265
2304
yjit_reg_op (BIN (putobject ), gen_putobject );
2266
2305
yjit_reg_op (BIN (putobject_INT2FIX_0_ ), gen_putobject_int2fix );
0 commit comments