8000 Merge pull request #72 from jhawthorn/getlocal_generic · eileencodes/ruby@8263fa1 · GitHub
[go: up one dir, main page]

< 8000 div class="position-relative header-wrapper js-header-wrapper "> Skip to content

Commit 8263fa1

Browse files
authored
Merge pull request ruby#72 from jhawthorn/getlocal_generic
Implement gen_getlocal
2 parents a0a7f50 + 5ce332b commit 8263fa1

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

bootstraptest/test_yjit.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,3 +1021,17 @@ def make_str(foo, bar)
10211021
make_str("foo", 123)
10221022
make_str("foo", 123)
10231023
}
1024+
1025+
# getlocal with 2 levels
1026+
assert_equal '7', %q{
1027+
def foo(foo, bar)
1028+
while foo > 0
1029+
while bar > 0
1030+
return foo + bar
1031+
end
1032+
end
1033+
end
1034+
1035+
foo(5,2)
1036+
foo(5,2)
1037+
}

yjit_codegen.c

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -785,22 +785,21 @@ gen_getlocal_wc0(jitstate_t* jit, ctx_t* ctx)
785785
}
786786

787787
static codegen_status_t
788-
gen_getlocal_wc1(jitstate_t* jit, ctx_t* ctx)
788+
gen_getlocal_generic(ctx_t* ctx, uint32_t local_idx, uint32_t level)
789789
{
790-
//fprintf(stderr, "gen_getlocal_wc1\n");
791-
792790
// Load environment pointer EP from CFP
793791
mov(cb, REG0, member_opnd(REG_CFP, rb_control_frame_t, ep));
794792

795-
// Get the previous EP from the current EP
796-
// See GET_PREV_EP(ep) macro
797-
// VALUE* prev_ep = ((VALUE *)((ep)[VM_ENV_DATA_INDEX_SPECVAL] & ~0x03))
798-
mov(cb, REG0, mem_opnd(64, REG0, SIZEOF_VALUE * VM_ENV_DATA_INDEX_SPECVAL));
799-
and(cb, REG0, imm_opnd(~0x03));
793+
while (level--) {
794+
// Get the previous EP from the current EP
795+
// See GET_PREV_EP(ep) macro
796+
// VALUE* prev_ep = ((VALUE *)((ep)[VM_ENV_DATA_INDEX_SPECVAL] & ~0x03))
797+
mov(cb, REG0, mem_opnd(64, REG0, SIZEOF_VALUE * VM_ENV_DATA_INDEX_SPECVAL));
798+
and(cb, REG0, imm_opnd(~0x03));
799+
}
800800

801801
// Load the local from the block
802802
// val = *(vm_get_ep(GET_EP(), level) - idx);
803-
int32_t local_idx = (int32_t)jit_get_arg(jit, 0);
804803
const int32_t offs = -(SIZEOF_VALUE * local_idx);
805804
mov(cb, REG0, mem_opnd(64, REG0, offs));
806805

@@ -811,6 +810,21 @@ gen_getlocal_wc1(jitstate_t* jit, ctx_t* ctx)
811810
return YJIT_KEEP_COMPILING;
812811
}
813812

813+
static codegen_status_t
814+
gen_getlocal(jitstate_t* jit, ctx_t* ctx)
815+
{
816+
int32_t idx = (int32_t)jit_get_arg(jit, 0);
817+
int32_t level = (int32_t)jit_get_arg(jit, 1);
818+
return gen_getlocal_generic(ctx, idx, level);
819+
}
820+
821+
static codegen_status_t
822+
gen_getlocal_wc1(jitstate_t* jit, ctx_t* ctx)
823+
{
824+
int32_t idx = (int32_t)jit_get_arg(jit, 0);
825+
return gen_getlocal_generic(ctx, idx, 1);
826+
}
827+
814828
static codegen_status_t
815829
gen_setlocal_wc0(jitstate_t* jit, ctx_t* ctx)
816830
{
@@ -3057,6 +3071,7 @@ yjit_init_codegen(void)
30573071
yjit_reg_op(BIN(putobject_INT2FIX_0_), gen_putobject_int2fix);
30583072
yjit_reg_op(BIN(putobject_INT2FIX_1_), gen_putobject_int2fix);
30593073
yjit_reg_op(BIN(putself), gen_putself);
3074+
yjit_reg_op(BIN(getlocal), gen_getlocal);
30603075
yjit_reg_op(BIN(getlocal_WC_0), gen_getlocal_wc0);
30613076
yjit_reg_op(BIN(getlocal_WC_1), gen_getlocal_wc1);
30623077
yjit_reg_op(BIN(setlocal_WC_0), gen_setlocal_wc0);

0 commit comments

Comments
 (0)
0