Author: leo
Date: Sun Feb 5 13:51:50 2006
New Revision: 11429
Modified:
trunk/src/jit.c
trunk/src/jit/i386/core.jit
trunk/src/jit/i386/jit_emit.h
Log:
PIC/JIT - -Ofun / x86
* implement set_returns and returncc in JIT/x86
* create a JIT function for .sub __pic_test ; return(x) ; .end
Modified: trunk/src/jit.c
==============================================================================
--- trunk/src/jit.c (original)
+++ trunk/src/jit.c Sun Feb 5 13:51:50 2006
@@ -1331,7 +1331,9 @@ parrot_build_asm(Interp *interpreter,
op_info_t *op_info;
int n;
const jit_arch_info *arch_info;
+ int needs_fs; /* fetch/store */
+ needs_fs = jit_type != JIT_CODE_SUB_REGS_ONLY;
jit_info = interpreter->code->jit_info =
mem_sys_allocate(sizeof(Parrot_jit_info_t));
@@ -1452,7 +1454,7 @@ parrot_build_asm(Interp *interpreter,
set_reg_usage(interpreter, cur_op);
/* Load mapped registers for this section, if JIT */
- if (!jit_seg && cur_section->isjit) {
+ if (!jit_seg && cur_section->isjit && needs_fs) {
Parrot_jit_load_registers(jit_info, interpreter, 0);
}
@@ -1497,21 +1499,23 @@ parrot_build_asm(Interp *interpreter,
* save also, if we have a jitted sections and encounter
* an "end" opcode, e.g. in evaled code
*/
- if ((((map[cur_op - code_start] == JIT_BRANCH_SOURCE) &&
+ if (needs_fs) {
+ if ((((map[cur_op - code_start] == JIT_BRANCH_SOURCE) &&
(cur_section->branch_target != cur_section)) ||
- !cur_opcode_byte) &&
- cur_section->isjit &&
- !jit_seg) {
- Parrot_jit_save_registers(jit_info, interpreter, 0);
- }
- else if (CALLS_C_CODE(cur_opcode_byte)) {
- /*
- * a JITted function with a function call, we have to
- * save volatile registers but
- * TODO not if the previous opcode was also one
- * that called C code
- */
- Parrot_jit_save_registers(jit_info, interpreter, 1);
+ !cur_opcode_byte) &&
+ cur_section->isjit &&
+ !jit_seg) {
+ Parrot_jit_save_registers(jit_info, interpreter, 0);
+ }
+ else if (CALLS_C_CODE(cur_opcode_byte)) {
+ /*
+ * a JITted function with a function call, we have to
+ * save volatile registers but
+ * TODO not if the previous opcode was also one
+ * that called C code
+ */
+ Parrot_jit_save_registers(jit_info, interpreter, 1);
+ }
}
/* Generate native code for current op */
@@ -1520,7 +1524,7 @@ parrot_build_asm(Interp *interpreter,
}
(op_func[cur_opcode_byte].fn) (jit_info, interpreter);
- if (CALLS_C_CODE(cur_opcode_byte)) {
+ if (CALLS_C_CODE(cur_opcode_byte) && needs_fs) {
/*
* restore volatiles only - and TODO only if next
* wouldn't load registers anyway
@@ -1556,7 +1560,7 @@ parrot_build_asm(Interp *interpreter,
}
/* Save mapped registers back to the Parrot registers */
- if (!jit_seg && cur_section->isjit)
+ if (!jit_seg && cur_section->isjit && needs_fs)
Parrot_jit_save_registers(jit_info, interpreter, 0);
/* update the offset for saved registers */
Modified: trunk/src/jit/i386/core.jit
==============================================================================
--- trunk/src/jit/i386/core.jit (original)
+++ trunk/src/jit/i386/core.jit Sun Feb 5 13:51:50 2006
@@ -1432,7 +1432,42 @@ Parrot_set_args_pc {
}
extern Parrot_set_returns_pc {
- Parrot_jit_normal_op(jit_info, interpreter);
+ if (jit_info->code_type == JIT_CODE_FILE)
+ Parrot_jit_normal_op(jit_info, interpreter);
+ else {
+ PMC *sig_pmc;
+ INTVAL *sig_bits, sig;
+
+ sig_pmc = CONTEXT(interpreter->ctx)->constants[CUR_OPCODE[1]]->u.key;
+ sig_bits = PMC_data(sig_pmc);
+ sig = sig_bits[0];
+ /* mov 16(%ebp), %eax - fetch args ptr */
+ emitm_movl_m_r(NATIVECODE, emit_EAX, emit_EBP, emit_None, 1, 16);
+ emitm_movl_m_r(NATIVECODE, emit_EAX, emit_EAX, emit_None, 1, 0);
+ switch (sig & (PARROT_ARG_TYPE_MASK|PARROT_ARG_CONSTANT)) {
+ case PARROT_ARG_INTVAL:
+ emitm_movl_r_m(NATIVECODE, MAP(2), emit_EAX, 0, 1, 0);
+ break;
+ case PARROT_ARG_INTVAL|PARROT_ARG_CONSTANT:
+ emitm_movl_i_m(NATIVECODE, *INT_CONST[2], emit_EAX, 0, 1, 0);
+ break;
+ default:
+ internal_exception(1, "set_returns_jit - unknown tyep");
+ break;
+ }
+ }
+}
+
+extern Parrot_returncc {
+ if (jit_info->code_type == JIT_CODE_FILE)
+ Parrot_jit_restart_op(jit_info, interpreter);
+ else {
+ emitm_movl_m_r(NATIVECODE, emit_EAX, emit_EBP, emit_None, 1, 16);
+ /* TODO 4 + n_args * 4 */
+ emitm_movl_m_r(NATIVECODE, emit_EAX, emit_EAX, emit_None, 1, 4);
+ jit_emit_stack_frame_leave(NATIVECODE);
+ emitm_ret(NATIVECODE);
+ }
}
extern Parrot_get_params_pc {
Modified: trunk/src/jit/i386/jit_emit.h
==============================================================================
--- trunk/src/jit/i386/jit_emit.h (original)
+++ trunk/src/jit/i386/jit_emit.h Sun Feb 5 13:51:50 2006
@@ -2957,22 +2957,6 @@ Parrot_jit_begin_sub_regs(Parrot_jit_inf
emitm_pushl_r(jit_info->native_ptr, emit_ESI);
emitm_pushl_r(jit_info->native_ptr, emit_EDI);
#endif
- /* XXX just a quick test */
-
- /* mov 16(%ebp), %eax - fetch args ptr */
- emitm_movl_m_r(jit_info->native_ptr, emit_EAX, emit_EBP, emit_None, 1, 16);
-
- /* code emitted by set_returns */
- /* mov 0(%eax), %ecx
- * mov $42, (%ecx) - return 42 */
- emitm_movl_m_r(jit_info->native_ptr, emit_ECX, emit_EAX, emit_None, 1, 0);
- emitm_movl_i_m(jit_info->native_ptr, 42, emit_ECX, emit_None, 1, 0);
-
- /* code emitted by returncc */
- /* fetch retval pc -> %eax i.e. return it */
- emitm_movl_m_r(jit_info->native_ptr, emit_EAX, emit_EAX, emit_None, 1, 4);
- jit_emit_stack_frame_leave(jit_info->native_ptr);
- emitm_ret(jit_info->native_ptr);
}