mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Added ujit_save_regs() and ujit_load_regs() helper functions
This commit is contained in:
parent
1a937dd196
commit
fff6d642b3
1 changed files with 32 additions and 40 deletions
|
@ -76,6 +76,26 @@ jit_mov_gc_ptr(jitstate_t* jit, codeblock_t* cb, x86opnd_t reg, VALUE ptr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save uJIT registers prior to a C call
|
||||||
|
static void
|
||||||
|
ujit_save_regs(codeblock_t* cb)
|
||||||
|
{
|
||||||
|
push(cb, REG_CFP);
|
||||||
|
push(cb, REG_EC);
|
||||||
|
push(cb, REG_SP);
|
||||||
|
push(cb, REG_SP); // Maintain 16-byte RSP alignment
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restore uJIT registers after a C call
|
||||||
|
static void
|
||||||
|
ujit_load_regs(codeblock_t* cb)
|
||||||
|
{
|
||||||
|
pop(cb, REG_SP); // Maintain 16-byte RSP alignment
|
||||||
|
pop(cb, REG_SP);
|
||||||
|
pop(cb, REG_EC);
|
||||||
|
pop(cb, REG_CFP);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Generate an inline exit to return to the interpreter
|
Generate an inline exit to return to the interpreter
|
||||||
*/
|
*/
|
||||||
|
@ -769,22 +789,15 @@ gen_opt_aref(jitstate_t* jit, ctx_t* ctx)
|
||||||
jz_ptr(cb, side_exit);
|
jz_ptr(cb, side_exit);
|
||||||
|
|
||||||
// Save uJIT registers
|
// Save uJIT registers
|
||||||
push(cb, REG_CFP);
|
ujit_save_regs(cb);
|
||||||
push(cb, REG_EC);
|
|
||||||
push(cb, REG_SP);
|
|
||||||
// Maintain 16-byte RSP alignment
|
|
||||||
sub(cb, RSP, imm_opnd(8));
|
|
||||||
|
|
||||||
mov(cb, RDI, recv_opnd);
|
mov(cb, RDI, recv_opnd);
|
||||||
sar(cb, REG1, imm_opnd(1)); // Convert fixnum to int
|
sar(cb, REG1, imm_opnd(1)); // Convert fixnum to int
|
||||||
mov(cb, RSI, REG1);
|
mov(cb, RSI, REG1);
|
||||||
call_ptr(cb, REG0, (void *)rb_ary_entry_internal);
|
call_ptr(cb, REG0, (void *)rb_ary_entry_internal);
|
||||||
|
|
||||||
// Restore registers
|
// Restore uJIT registers
|
||||||
add(cb, RSP, imm_opnd(8));
|
ujit_load_regs(cb);
|
||||||
pop(cb, REG_SP);
|
|
||||||
pop(cb, REG_EC);
|
|
||||||
pop(cb, REG_CFP);
|
|
||||||
|
|
||||||
x86opnd_t stack_ret = ctx_stack_push(ctx, T_NONE);
|
x86opnd_t stack_ret = ctx_stack_push(ctx, T_NONE);
|
||||||
mov(cb, stack_ret, RAX);
|
mov(cb, stack_ret, RAX);
|
||||||
|
@ -1166,14 +1179,10 @@ gen_oswb_cfunc(jitstate_t* jit, ctx_t* ctx, struct rb_call_data * cd, const rb_c
|
||||||
mov(cb, member_opnd(REG1, rb_control_frame_t, self), REG0);
|
mov(cb, member_opnd(REG1, rb_control_frame_t, self), REG0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify that we are calling the right function
|
||||||
if (UJIT_CHECK_MODE > 0) {
|
if (UJIT_CHECK_MODE > 0) {
|
||||||
// Verify that we are calling the right function
|
// Save uJIT registers
|
||||||
// Save MicroJIT registers
|
ujit_save_regs(cb);
|
||||||
push(cb, REG_CFP);
|
|
||||||
push(cb, REG_EC);
|
|
||||||
push(cb, REG_SP);
|
|
||||||
// Maintain 16-byte RSP alignment
|
|
||||||
sub(cb, RSP, imm_opnd(8));
|
|
||||||
|
|
||||||
// Call check_cfunc_dispatch
|
// Call check_cfunc_dispatch
|
||||||
mov(cb, RDI, recv);
|
mov(cb, RDI, recv);
|
||||||
|
@ -1182,20 +1191,12 @@ gen_oswb_cfunc(jitstate_t* jit, ctx_t* ctx, struct rb_call_data * cd, const rb_c
|
||||||
jit_mov_gc_ptr(jit, cb, RCX, (VALUE)cme);
|
jit_mov_gc_ptr(jit, cb, RCX, (VALUE)cme);
|
||||||
call_ptr(cb, REG0, (void *)&check_cfunc_dispatch);
|
call_ptr(cb, REG0, (void *)&check_cfunc_dispatch);
|
||||||
|
|
||||||
// Restore registers
|
// Load uJIT registers
|
||||||
add(cb, RSP, imm_opnd(8));
|
ujit_load_regs(cb);
|
||||||
pop(cb, REG_SP);
|
|
||||||
pop(cb, REG_EC);
|
|
||||||
pop(cb, REG_CFP);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the MicroJIT registers
|
// Save uJIT registers
|
||||||
push(cb, REG_CFP);
|
ujit_save_regs(cb);
|
||||||
push(cb, REG_EC);
|
|
||||||
push(cb, REG_SP);
|
|
||||||
|
|
||||||
// Maintain 16-byte RSP alignment
|
|
||||||
sub(cb, RSP, imm_opnd(8));
|
|
||||||
|
|
||||||
// Copy SP into RAX because REG_SP will get overwritten
|
// Copy SP into RAX because REG_SP will get overwritten
|
||||||
lea(cb, RAX, ctx_sp_opnd(ctx, 0));
|
lea(cb, RAX, ctx_sp_opnd(ctx, 0));
|
||||||
|
@ -1212,23 +1213,14 @@ gen_oswb_cfunc(jitstate_t* jit, ctx_t* ctx, struct rb_call_data * cd, const rb_c
|
||||||
// Pop the C function arguments from the stack (in the caller)
|
// Pop the C function arguments from the stack (in the caller)
|
||||||
ctx_stack_pop(ctx, argc + 1);
|
ctx_stack_pop(ctx, argc + 1);
|
||||||
|
|
||||||
//print_str(cb, "before C call");
|
|
||||||
|
|
||||||
// Call the C function
|
// Call the C function
|
||||||
// VALUE ret = (cfunc->func)(recv, argv[0], argv[1]);
|
// VALUE ret = (cfunc->func)(recv, argv[0], argv[1]);
|
||||||
// cfunc comes from compile-time cme->def, which we assume to be stable.
|
// cfunc comes from compile-time cme->def, which we assume to be stable.
|
||||||
// Invalidation logic is in rb_ujit_method_lookup_change()
|
// Invalidation logic is in rb_ujit_method_lookup_change()
|
||||||
call_ptr(cb, REG0, (void*)cfunc->func);
|
call_ptr(cb, REG0, (void*)cfunc->func);
|
||||||
|
|
||||||
//print_str(cb, "after C call");
|
// Load uJIT registers
|
||||||
|
ujit_load_regs(cb);
|
||||||
// Maintain 16-byte RSP alignment
|
|
||||||
add(cb, RSP, imm_opnd(8));
|
|
||||||
|
|
||||||
// Restore MicroJIT registers
|
|
||||||
pop(cb, REG_SP);
|
|
||||||
pop(cb, REG_EC);
|
|
||||||
pop(cb, REG_CFP);
|
|
||||||
|
|
||||||
// Push the return value on the Ruby stack
|
// Push the return value on the Ruby stack
|
||||||
x86opnd_t stack_ret = ctx_stack_push(ctx, T_NONE);
|
x86opnd_t stack_ret = ctx_stack_push(ctx, T_NONE);
|
||||||
|
|
Loading…
Add table
Reference in a new issue