Skip to content

Commit

Permalink
Port over setlocal_wc0
Browse files Browse the repository at this point in the history
  • Loading branch information
maximecb authored and k0kubun committed Aug 26, 2022
1 parent c7c6dcf commit 46d4912
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
11 changes: 11 additions & 0 deletions bootstraptest/test_yjit_new_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,31 @@ def foo(n)
foo(7)
}

# newarray
assert_equal '[7]', %q{
def foo(n)
[n]
end
foo(7)
}

# newarray, opt_plus
assert_equal '[8]', %q{
def foo(n)
[n+1]
end
foo(7)
}

# setlocal, getlocal, opt_plus
assert_equal '10', %q{
def foo(n)
m = 3
n + m
end
foo(7)
}

# TODO: progress towards getting branches and calls working
=begin
def foo(n)
Expand Down
8 changes: 7 additions & 1 deletion yjit/src/backend/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl From<u64> for Opnd {

impl From<i64> for Opnd {
fn from(value: i64) -> Self {
Opnd::Imm(value.try_into().unwrap())
Opnd::Imm(value)
}
}

Expand All @@ -263,6 +263,12 @@ impl From<i32> for Opnd {
}
}

impl From<u32> for Opnd {
fn from(value: u32) -> Self {
Opnd::UImm(value as u64)
}
}

impl From<VALUE> for Opnd {
fn from(value: VALUE) -> Self {
let VALUE(uimm) = value;
Expand Down
23 changes: 11 additions & 12 deletions yjit/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1584,11 +1584,10 @@ fn gen_getlocal_wc1(
gen_getlocal_generic(ctx, asm, idx.as_u32(), 1)
}

/*
fn gen_setlocal_wc0(
jit: &mut JITState,
ctx: &mut Context,
cb: &mut CodeBlock,
asm: &mut Assembler,
ocb: &mut OutlinedCb,
) -> CodegenStatus {
/*
Expand All @@ -1609,41 +1608,41 @@ fn gen_setlocal_wc0(
let value_type = ctx.get_opnd_type(StackOpnd(0));

// Load environment pointer EP (level 0) from CFP
gen_get_ep(cb, REG0, 0);
let ep_opnd = gen_get_ep(asm, 0);

// Write barriers may be required when VM_ENV_FLAG_WB_REQUIRED is set, however write barriers
// only affect heap objects being written. If we know an immediate value is being written we
// can skip this check.
if !value_type.is_imm() {
// flags & VM_ENV_FLAG_WB_REQUIRED
let flags_opnd = mem_opnd(
let flags_opnd = Opnd::mem(
64,
REG0,
ep_opnd,
SIZEOF_VALUE as i32 * VM_ENV_DATA_INDEX_FLAGS as i32,
);
test(cb, flags_opnd, imm_opnd(VM_ENV_FLAG_WB_REQUIRED as i64));
asm.test(flags_opnd, VM_ENV_FLAG_WB_REQUIRED.into());

// Create a side-exit to fall back to the interpreter
let side_exit = get_side_exit(jit, ocb, ctx);

// if (flags & VM_ENV_FLAG_WB_REQUIRED) != 0
jnz_ptr(cb, side_exit);
asm.jnz(side_exit.into());
}

// Set the type of the local variable in the context
ctx.set_local_type(local_idx, value_type);

// Pop the value to write from the stack
let stack_top = ctx.stack_pop(1);
mov(cb, REG1, stack_top);

// Write the value at the environment pointer
let offs: i32 = -8 * slot_idx;
mov(cb, mem_opnd(64, REG0, offs), REG1);
asm.mov(Opnd::mem(64, ep_opnd, offs), stack_top);

KeepCompiling
}

/*
fn gen_setlocal_generic(
jit: &mut JITState,
ctx: &mut Context,
Expand Down Expand Up @@ -5992,11 +5991,11 @@ fn get_gen_fn(opcode: VALUE) -> Option<InsnGenFn> {
YARVINSN_topn => Some(gen_topn),
YARVINSN_adjuststack => Some(gen_adjuststack),

//YARVINSN_getlocal => Some(gen_getlocal),
YARVINSN_getlocal => Some(gen_getlocal),
YARVINSN_getlocal_WC_0 => Some(gen_getlocal_wc0),
//YARVINSN_getlocal_WC_1 => Some(gen_getlocal_wc1),
YARVINSN_getlocal_WC_1 => Some(gen_getlocal_wc1),
//YARVINSN_setlocal => Some(gen_setlocal),
//YARVINSN_setlocal_WC_0 => Some(gen_setlocal_wc0),
YARVINSN_setlocal_WC_0 => Some(gen_setlocal_wc0),
//YARVINSN_setlocal_WC_1 => Some(gen_setlocal_wc1),
YARVINSN_opt_plus => Some(gen_opt_plus),
/*
Expand Down

0 comments on commit 46d4912

Please sign in to comment.