8000 Implement dupn for n==2 (only case used in RDoc/railsbench) (#20) · github/ruby@2c17906 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2c17906

Browse files
authored
Implement dupn for n==2 (only case used in RDoc/railsbench) (#20)
* Implement dupn for n==2 (only case used in RDoc/railsbench) * Implement adjuststack bytecode
1 parent cc8984f commit 2c17906

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

yjit_codegen.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,34 @@ gen_dup(jitstate_t* jit, ctx_t* ctx)
476476
return YJIT_KEEP_COMPILING;
477477
}
478478

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+
479507
// set Nth stack entry to stack top
480508
static codegen_status_t
481509
gen_setn(jitstate_t* jit, ctx_t* ctx)
@@ -503,6 +531,15 @@ gen_pop(jitstate_t* jit, ctx_t* ctx)
503531
return YJIT_KEEP_COMPILING;
504532
}
505533

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+
506543
static codegen_status_t
507544
gen_putnil(jitstate_t* jit, ctx_t* ctx)
508545
{
@@ -2259,8 +2296,10 @@ yjit_init_codegen(void)
22592296
// Map YARV opcodes to the corresponding codegen functions
22602297
yjit_reg_op(BIN(nop), gen_nop);
22612298
yjit_reg_op(BIN(dup), gen_dup);
2299+
yjit_reg_op(BIN(dupn), gen_dupn);
22622300
yjit_reg_op(BIN(setn), gen_setn);
22632301
yjit_reg_op(BIN(pop), gen_pop);
2302+
yjit_reg_op(BIN(adjuststack), gen_adjuststack);
22642303
yjit_reg_op(BIN(putnil), gen_putnil);
22652304
yjit_reg_op(BIN(putobject), gen_putobject);
22662305
yjit_reg_op(BIN(putobject_INT2FIX_0_), gen_putobject_int2fix);

0 commit comments

Comments
 (0)
0