Skip to content

Commit

Permalink
Port over setlocal and getglobal
Browse files Browse the repository at this point in the history
  • Loading branch information
maximecb authored and k0kubun committed Aug 26, 2022
1 parent f27b957 commit 6462c0d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 24 deletions.
12 changes: 12 additions & 0 deletions bootstraptest/test_yjit_new_backend.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Run can run this test file directly with:
# make -j miniruby && RUST_BACKTRACE=1 ruby --disable=gems bootstraptest/runner.rb --ruby="./miniruby -I./lib -I. -I.ext/common --disable-gems --yjit-call-threshold=1 --yjit-verify-ctx" bootstraptest/test_yjit_new_backend.rb
#
# To look up Ruby snippets using specific instructions, see:
# https://kddnewton.com/yarv/

assert_equal '1', %q{
def foo()
Expand Down Expand Up @@ -114,3 +117,12 @@ def foo()
end
foo()
}

# getglobal
assert_equal '333', %q{
$bar = 333
def foo()
$bar
end
foo()
}
46 changes: 22 additions & 24 deletions yjit/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1625,71 +1625,68 @@ fn gen_setlocal_wc0(
KeepCompiling
}

/*
fn gen_setlocal_generic(
jit: &mut JITState,
ctx: &mut Context,
cb: &mut CodeBlock,
asm: &mut Assembler,
ocb: &mut OutlinedCb,
local_idx: i32,
level: u32,
) -> CodegenStatus {
let value_type = ctx.get_opnd_type(StackOpnd(0));

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

// 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, uimm_opnd(VM_ENV_FLAG_WB_REQUIRED.into()));
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());
}

// 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 = -(SIZEOF_VALUE as i32 * local_idx);
mov(cb, mem_opnd(64, REG0, offs), REG1);
asm.mov(Opnd::mem(64, ep_opnd, offs), stack_top);

KeepCompiling
}

fn gen_setlocal(
jit: &mut JITState,
ctx: &mut Context,
cb: &mut CodeBlock,
asm: &mut Assembler,
ocb: &mut OutlinedCb,
) -> CodegenStatus {
let idx = jit_get_arg(jit, 0).as_i32();
let level = jit_get_arg(jit, 1).as_u32();
gen_setlocal_generic(jit, ctx, cb, ocb, idx, level)
gen_setlocal_generic(jit, ctx, asm, ocb, idx, level)
}

fn gen_setlocal_wc1(
jit: &mut JITState,
ctx: &mut Context,
cb: &mut CodeBlock,
asm: &mut Assembler,
ocb: &mut OutlinedCb,
) -> CodegenStatus {
let idx = jit_get_arg(jit, 0).as_i32();
gen_setlocal_generic(jit, ctx, cb, ocb, idx, 1)
gen_setlocal_generic(jit, ctx, asm, ocb, idx, 1)
}
*/

// new hash initialized from top N values
fn gen_newhash(
Expand Down Expand Up @@ -5290,28 +5287,29 @@ fn gen_leave(
EndBlock
}

/*
fn gen_getglobal(
jit: &mut JITState,
ctx: &mut Context,
cb: &mut CodeBlock,
asm: &mut Assembler,
_ocb: &mut OutlinedCb,
) -> CodegenStatus {
let gid = jit_get_arg(jit, 0);

// Save the PC and SP because we might make a Ruby call for warning
jit_prepare_routine_call(jit, ctx, cb, REG0);
mov(cb, C_ARG_REGS[0], imm_opnd(gid.as_i64()));
jit_prepare_routine_call(jit, ctx, asm);

call_ptr(cb, REG0, rb_gvar_get as *const u8);
let val_opnd = asm.ccall(
rb_gvar_get as *const u8,
vec![ gid.into() ]
);

let top = ctx.stack_push(Type::Unknown);
mov(cb, top, RAX);
asm.mov(top, val_opnd);

KeepCompiling
}

/*
fn gen_setglobal(
jit: &mut JITState,
ctx: &mut Context,
Expand Down Expand Up @@ -5974,9 +5972,9 @@ fn get_gen_fn(opcode: VALUE) -> Option<InsnGenFn> {
YARVINSN_getlocal => Some(gen_getlocal),
YARVINSN_getlocal_WC_0 => Some(gen_getlocal_wc0),
YARVINSN_getlocal_WC_1 => Some(gen_getlocal_wc1),
//YARVINSN_setlocal => Some(gen_setlocal),
YARVINSN_setlocal => Some(gen_setlocal),
YARVINSN_setlocal_WC_0 => Some(gen_setlocal_wc0),
//YARVINSN_setlocal_WC_1 => Some(gen_setlocal_wc1),
YARVINSN_setlocal_WC_1 => Some(gen_setlocal_wc1),
YARVINSN_opt_plus => Some(gen_opt_plus),
/*
YARVINSN_opt_minus => Some(gen_opt_minus),
Expand Down Expand Up @@ -6040,8 +6038,8 @@ fn get_gen_fn(opcode: VALUE) -> Option<InsnGenFn> {
//YARVINSN_invokesuper => Some(gen_invokesuper),
YARVINSN_leave => Some(gen_leave),

/*
YARVINSN_getglobal => Some(gen_getglobal),
/*
YARVINSN_setglobal => Some(gen_setglobal),
YARVINSN_anytostring => Some(gen_anytostring),
YARVINSN_objtostring => Some(gen_objtostring),
Expand Down

0 comments on commit 6462c0d

Please sign in to comment.