mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
Remove PC argument from ujit instructions
This commit is contained in:
parent
ca47899ccf
commit
3739588811
7 changed files with 32 additions and 12 deletions
|
@ -1,5 +1,5 @@
|
||||||
def get_example_instruction_id
|
def get_example_instruction_id
|
||||||
# TODO we could get this from the script that generates vm.inc instead of dothings this song and dance
|
# TODO we could get this from the script that generates vm.inc instead of doing this song and dance
|
||||||
`dwarfdump --name='YARVINSN_ujit_call_example' vm.o`.each_line do |line|
|
`dwarfdump --name='YARVINSN_ujit_call_example' vm.o`.each_line do |line|
|
||||||
if (id = line[/DW_AT_const_value\s\((\d+\))/, 1])
|
if (id = line[/DW_AT_const_value\s\((\d+\))/, 1])
|
||||||
p [__method__, line] if $DEBUG
|
p [__method__, line] if $DEBUG
|
||||||
|
@ -108,4 +108,3 @@ p offset_to_insn_in_tc_table if $DEBUG
|
||||||
offset_to_handler_code_from_vm_exec_core = readint8b(offset_to_insn_in_tc_table)
|
offset_to_handler_code_from_vm_exec_core = readint8b(offset_to_insn_in_tc_table)
|
||||||
p offset_to_handler_code_from_vm_exec_core if $DEBUG
|
p offset_to_handler_code_from_vm_exec_core if $DEBUG
|
||||||
disassemble(vm_exec_core_offset + offset_to_handler_code_from_vm_exec_core)
|
disassemble(vm_exec_core_offset + offset_to_handler_code_from_vm_exec_core)
|
||||||
|
|
||||||
|
|
2
iseq.c
2
iseq.c
|
@ -3465,7 +3465,7 @@ trace_set_i(void *vstart, void *vend, size_t stride, void *data)
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE *
|
VALUE *
|
||||||
rb_ujit_empty_func(rb_control_frame_t *cfp, const VALUE *pc)
|
rb_ujit_empty_func(rb_control_frame_t *cfp)
|
||||||
{
|
{
|
||||||
// okay, not really empty, so maybe think of another name.
|
// okay, not really empty, so maybe think of another name.
|
||||||
// it's put in this file instead of say, compile.c to dodge long C compile time.
|
// it's put in this file instead of say, compile.c to dodge long C compile time.
|
||||||
|
|
2
iseq.h
2
iseq.h
|
@ -313,7 +313,7 @@ VALUE rb_iseq_defined_string(enum defined_type type);
|
||||||
/* vm.c */
|
/* vm.c */
|
||||||
VALUE rb_iseq_local_variables(const rb_iseq_t *iseq);
|
VALUE rb_iseq_local_variables(const rb_iseq_t *iseq);
|
||||||
|
|
||||||
NOINLINE(VALUE *rb_ujit_empty_func(rb_control_frame_t *cfp, const VALUE *pc));
|
NOINLINE(VALUE *rb_ujit_empty_func(rb_control_frame_t *cfp));
|
||||||
|
|
||||||
|
|
||||||
RUBY_SYMBOL_EXPORT_END
|
RUBY_SYMBOL_EXPORT_END
|
||||||
|
|
|
@ -34,7 +34,7 @@ INSN_ENTRY(<%= insn.name %>)
|
||||||
START_OF_ORIGINAL_INSN(<%= insn.name %>);
|
START_OF_ORIGINAL_INSN(<%= insn.name %>);
|
||||||
// assumes USE_MACHINE_REGS, aka reg_pc setup,
|
// assumes USE_MACHINE_REGS, aka reg_pc setup,
|
||||||
// aka #define SET_PC(x) (reg_cfp->pc = reg_pc = (x))
|
// aka #define SET_PC(x) (reg_cfp->pc = reg_pc = (x))
|
||||||
reg_pc = rb_ujit_empty_func(GET_CFP(), reg_pc);
|
reg_pc = rb_ujit_empty_func(GET_CFP());
|
||||||
END_INSN(<%= insn.name %>);
|
END_INSN(<%= insn.name %>);
|
||||||
}
|
}
|
||||||
% end
|
% end
|
||||||
|
|
11
ujit_asm.c
11
ujit_asm.c
|
@ -97,6 +97,17 @@ x86opnd_t imm_opnd(int64_t imm)
|
||||||
return opnd;
|
return opnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
x86opnd_t const_ptr_opnd(void* ptr)
|
||||||
|
{
|
||||||
|
x86opnd_t opnd = {
|
||||||
|
OPND_IMM,
|
||||||
|
64,
|
||||||
|
.unsig_imm = (uint64_t)ptr
|
||||||
|
};
|
||||||
|
|
||||||
|
return opnd;
|
||||||
|
}
|
||||||
|
|
||||||
void cb_init(codeblock_t* cb, size_t mem_size)
|
void cb_init(codeblock_t* cb, size_t mem_size)
|
||||||
{
|
{
|
||||||
// Map the memory as executable
|
// Map the memory as executable
|
||||||
|
|
|
@ -127,7 +127,7 @@ typedef struct X86Opnd
|
||||||
int64_t imm;
|
int64_t imm;
|
||||||
|
|
||||||
// Unsigned immediate value
|
// Unsigned immediate value
|
||||||
uint64_t unsigImm;
|
uint64_t unsig_imm;
|
||||||
};
|
};
|
||||||
|
|
||||||
} x86opnd_t;
|
} x86opnd_t;
|
||||||
|
@ -177,6 +177,9 @@ x86opnd_t mem_opnd(size_t num_bits, x86opnd_t base_reg, int32_t disp);
|
||||||
// Immediate number operand
|
// Immediate number operand
|
||||||
x86opnd_t imm_opnd(int64_t val);
|
x86opnd_t imm_opnd(int64_t val);
|
||||||
|
|
||||||
|
// Constant pointer operand
|
||||||
|
x86opnd_t const_ptr_opnd(void* ptr);
|
||||||
|
|
||||||
void cb_init(codeblock_t* cb, size_t mem_size);
|
void cb_init(codeblock_t* cb, size_t mem_size);
|
||||||
void cb_set_pos(codeblock_t* cb, size_t pos);
|
void cb_set_pos(codeblock_t* cb, size_t pos);
|
||||||
uint8_t* cb_get_ptr(codeblock_t* cb, size_t index);
|
uint8_t* cb_get_ptr(codeblock_t* cb, size_t index);
|
||||||
|
|
|
@ -63,9 +63,13 @@ ujit_compile_insn(rb_iseq_t *iseq, size_t insn_idx)
|
||||||
}
|
}
|
||||||
|
|
||||||
int insn = (int)iseq->body->iseq_encoded[insn_idx];
|
int insn = (int)iseq->body->iseq_encoded[insn_idx];
|
||||||
|
int len = insn_len(insn);
|
||||||
//const char* name = insn_name(insn);
|
//const char* name = insn_name(insn);
|
||||||
//printf("%s\n", name);
|
//printf("%s\n", name);
|
||||||
|
|
||||||
|
// Compute the address of the next instruction
|
||||||
|
void* next_pc = &iseq->body->iseq_encoded[insn_idx + len];
|
||||||
|
|
||||||
// Get a pointer to the current write position in the code block
|
// Get a pointer to the current write position in the code block
|
||||||
uint8_t* code_ptr = &cb->mem_block[cb->write_pos];
|
uint8_t* code_ptr = &cb->mem_block[cb->write_pos];
|
||||||
//printf("write pos: %ld\n", cb->write_pos);
|
//printf("write pos: %ld\n", cb->write_pos);
|
||||||
|
@ -80,9 +84,12 @@ ujit_compile_insn(rb_iseq_t *iseq, size_t insn_idx)
|
||||||
// Write the pre call bytes
|
// Write the pre call bytes
|
||||||
ujit_instr_entry(cb);
|
ujit_instr_entry(cb);
|
||||||
|
|
||||||
add(cb, RSI, imm_opnd(8)); // increment PC
|
//add(cb, RSI, imm_opnd(8)); // increment PC
|
||||||
mov(cb, mem_opnd(64, RDI, 0), RSI); // write new PC to EC object, not necessary for nop bytecode?
|
//mov(cb, mem_opnd(64, RDI, 0), RSI); // write new PC to EC object, not necessary for nop bytecode?
|
||||||
mov(cb, RAX, RSI); // return new PC
|
//mov(cb, RAX, RSI); // return new PC
|
||||||
|
|
||||||
|
// Directly return the next PC, which is a constant
|
||||||
|
mov(cb, RAX, const_ptr_opnd(next_pc));
|
||||||
|
|
||||||
// Write the post call bytes
|
// Write the post call bytes
|
||||||
ujit_instr_exit(cb);
|
ujit_instr_exit(cb);
|
||||||
|
@ -98,9 +105,9 @@ ujit_compile_insn(rb_iseq_t *iseq, size_t insn_idx)
|
||||||
ujit_instr_entry(cb);
|
ujit_instr_entry(cb);
|
||||||
|
|
||||||
sub(cb, mem_opnd(64, RDI, 8), imm_opnd(8)); // decrement SP
|
sub(cb, mem_opnd(64, RDI, 8), imm_opnd(8)); // decrement SP
|
||||||
add(cb, RSI, imm_opnd(8)); // increment PC
|
|
||||||
mov(cb, mem_opnd(64, RDI, 0), RSI); // write new PC to EC object, not necessary for pop bytecode?
|
// Directly return the next PC, which is a constant
|
||||||
mov(cb, RAX, RSI); // return new PC
|
mov(cb, RAX, const_ptr_opnd(next_pc));
|
||||||
|
|
||||||
// Write the post call bytes
|
// Write the post call bytes
|
||||||
ujit_instr_exit(cb);
|
ujit_instr_exit(cb);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue