cvsuser     02/11/16 02:36:11

  Modified:    .        interpreter.c jit.c
               include/parrot jit.h
               jit/alpha jit_emit.h
               jit/arm  jit_emit.h
               jit/i386 jit_emit.h
               jit/ppc  jit_emit.h
               jit/sun4 jit_emit.h
  Log:
  JIT restart code
  
  Revision  Changes    Path
  1.117     +2 -8      parrot/interpreter.c
  
  Index: interpreter.c
  ===================================================================
  RCS file: /cvs/public/parrot/interpreter.c,v
  retrieving revision 1.116
  retrieving revision 1.117
  diff -u -w -r1.116 -r1.117
  --- interpreter.c     15 Nov 2002 05:26:36 -0000      1.116
  +++ interpreter.c     16 Nov 2002 10:35:58 -0000      1.117
  @@ -1,7 +1,7 @@
   /* interpreter.c
    *  Copyright: (When this is determined...it will go here)
    *  CVS Info
  - *     $Id: interpreter.c,v 1.116 2002/11/15 05:26:36 sfink Exp $
  + *     $Id: interpreter.c,v 1.117 2002/11/16 10:35:58 leo Exp $
    *  Overview:
    *     The interpreter api handles running the operations
    *  Data Structure and Algorithms:
  @@ -229,13 +229,7 @@
       code_end = interpreter->code->byte_code + code_size;
   
       jit_code = build_asm(interpreter, pc, code_start, code_end);
  -    (jit_code) (interpreter);
  -    /* if we fall out of runloop with restart, there is
  -     * currently no way, to continue in JIT, so stop it
  -     *
  -     * This is broken too, but better as endless loops
  -     */
  -/*    Interp_flags_CLEAR(interpreter, PARROT_JIT_FLAG); */
  +    (jit_code) (interpreter, pc);
   #endif
   }
   
  
  
  
  1.39      +3 -2      parrot/jit.c
  
  Index: jit.c
  ===================================================================
  RCS file: /cvs/public/parrot/jit.c,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -w -r1.38 -r1.39
  --- jit.c     13 Nov 2002 11:07:25 -0000      1.38
  +++ jit.c     16 Nov 2002 10:35:58 -0000      1.39
  @@ -1,7 +1,7 @@
   /*
    * jit.c
    *
  - * $Id: jit.c,v 1.38 2002/11/13 11:07:25 leo Exp $
  + * $Id: jit.c,v 1.39 2002/11/16 10:35:58 leo Exp $
    */
   
   #include <parrot/parrot.h>
  @@ -445,8 +445,9 @@
       opcode_t cur_opcode_byte;
   
   
  +    /* XXX assume, we restart */
       if (pc != code_start && interpreter->jit_info)
  -        return Parrot_jit_restart(interpreter, pc - code_start);
  +        return (jit_f)D2FPTR(jit_info.arena.start);
   
       interpreter->jit_info = &jit_info;
       jit_info.optimizer = optimize_jit(interpreter, pc, code_start, code_end);
  
  
  
  1.21      +2 -3      parrot/include/parrot/jit.h
  
  Index: jit.h
  ===================================================================
  RCS file: /cvs/public/parrot/include/parrot/jit.h,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -w -r1.20 -r1.21
  --- jit.h     12 Nov 2002 14:47:15 -0000      1.20
  +++ jit.h     16 Nov 2002 10:36:02 -0000      1.21
  @@ -1,17 +1,16 @@
   /*
    * jit.h
    *
  - * $Id: jit.h,v 1.20 2002/11/12 14:47:15 leo Exp $
  + * $Id: jit.h,v 1.21 2002/11/16 10:36:02 leo Exp $
    */
   
   #ifndef JIT_H_GUARD
   #define JIT_H_GUARD
   
  -typedef void (*jit_f)(struct Parrot_Interp *interpreter);
  +typedef void (*jit_f)(struct Parrot_Interp *interpreter, opcode_t *pc);
   
   jit_f build_asm(struct Parrot_Interp *interpreter, opcode_t *pc,
                   opcode_t *code_start, opcode_t *code_end);
  -jit_f Parrot_jit_restart(struct Parrot_Interp * interpreter, opcode_t pc);
   
   /*  Parrot_jit_fixup_t
    *      Platform generic fixup information
  
  
  
  1.10      +2 -6      parrot/jit/alpha/jit_emit.h
  
  Index: jit_emit.h
  ===================================================================
  RCS file: /cvs/public/parrot/jit/alpha/jit_emit.h,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -w -r1.9 -r1.10
  --- jit_emit.h        12 Nov 2002 14:47:20 -0000      1.9
  +++ jit_emit.h        16 Nov 2002 10:36:04 -0000      1.10
  @@ -3,7 +3,7 @@
    *
    * ALPHA
    *
  - * $Id: jit_emit.h,v 1.9 2002/11/12 14:47:20 leo Exp $
  + * $Id: jit_emit.h,v 1.10 2002/11/16 10:36:04 leo Exp $
    */
   
   /*  Register usage:
  @@ -366,11 +366,7 @@
       emit_lda_b(jit_info->native_ptr, REG15_s6, -0x7ff8, REG15_s6);
       emit_lc(jit_info->native_ptr, REG10_s1, interpreter->code->byte_code);
       emit_lc(jit_info->native_ptr, REG11_s2, jit_info->arena.op_map);
  -}
  -
  -jit_f
  -Parrot_jit_restart(struct Parrot_Interp * interpreter, opcode_t pc)
  -{
  +    /* TODO emit restart code, s. i386 */
   }
   
   void
  
  
  
  1.13      +6 -6      parrot/jit/arm/jit_emit.h
  
  Index: jit_emit.h
  ===================================================================
  RCS file: /cvs/public/parrot/jit/arm/jit_emit.h,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -w -r1.12 -r1.13
  --- jit_emit.h        12 Nov 2002 14:47:22 -0000      1.12
  +++ jit_emit.h        16 Nov 2002 10:36:05 -0000      1.13
  @@ -3,7 +3,7 @@
    *
    * ARM (I think this is all ARM2 or later, although it is APCS-32)
    *
  - * $Id: jit_emit.h,v 1.12 2002/11/12 14:47:22 leo Exp $
  + * $Id: jit_emit.h,v 1.13 2002/11/16 10:36:05 leo Exp $
    */
   
   #ifdef ARM
  @@ -859,11 +859,11 @@
                                                    SUB, 0, REG11_fp, REG12_ip,
                                                    4, 0);
       jit_info->native_ptr = emit_mov (jit_info->native_ptr, 4, 0);
  -}
  -
  -jit_f
  -Parrot_jit_restart(struct Parrot_Interp * interpreter, opcode_t pc)
  -{
  +    /* TODO emit restart code s. i386
  +     *
  +     * emit get r0 from stack
  +     * Parrot_jump_to_op_in_reg(jit_info, interpreter, r0);
  +     */
   }
   
   /* I'm going to load registers to call functions in general like this:
  
  
  
  1.15      +41 -44    parrot/jit/i386/jit_emit.h
  
  Index: jit_emit.h
  ===================================================================
  RCS file: /cvs/public/parrot/jit/i386/jit_emit.h,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -w -r1.14 -r1.15
  --- jit_emit.h        15 Nov 2002 13:42:52 -0000      1.14
  +++ jit_emit.h        16 Nov 2002 10:36:08 -0000      1.15
  @@ -3,7 +3,7 @@
    *
    * i386
    *
  - * $Id: jit_emit.h,v 1.14 2002/11/15 13:42:52 leo Exp $
  + * $Id: jit_emit.h,v 1.15 2002/11/16 10:36:08 leo Exp $
    */
   
   /* Register codes */
  @@ -477,6 +477,7 @@
   /* AND */
   
   #define emit_andl_r_r(pc, reg1, reg2) emitm_alul_r_r(pc, 0x21, reg1, reg2)
  +#define emit_test_r_r(pc, reg1, reg2) emitm_alul_r_r(pc, 0x85, reg1, reg2)
   
   #define emitm_andl_i_r(pc, imm, reg) \
     emitm_alul_i_r(pc, 0x81, emit_b100, imm, reg)
  @@ -937,23 +938,42 @@
       jit_info->arena.fixups = NULL;
   }
   
  +static void
  +Parrot_emit_jump_to_eax(Parrot_jit_info_t *jit_info,
  +                   struct Parrot_Interp * interpreter)
  +{
  +
  +    /* This calculates (INDEX into op_map * 4) */
  +    emitm_subl_i_r(jit_info->native_ptr, interpreter->code->byte_code,emit_EAX);
  +
  +    /* This jumps to the address in op_map[EBP + sizeof(void *) * INDEX] */
  +    *jit_info->native_ptr++ = 0x3e;     /* DS:0(EBP, EAX, 1) */
  +    emitm_jumpm(jit_info->native_ptr, emit_EBP, emit_EAX,
  +                        sizeof(*jit_info->arena.op_map) / 4, 0);
  +}
   void
   Parrot_jit_begin(Parrot_jit_info_t *jit_info,
                    struct Parrot_Interp * interpreter)
   {
  -    int i;
  +    /* the generated code gets called as:
  +     * (jit_code)(interpreter, pc)
  +     * jumping to pc is the same code as used in Parrot_jit_cpcf_op()
  +     */
   
       /* Maintain the stack frame pointer for the sake of gdb */
       emit_pushl_r(jit_info->native_ptr, emit_EBP);
       emitm_movl_r_r(jit_info->native_ptr, emit_ESP, emit_EBP);
  +    /* stack:
  +     * 12   pc
  +     *  8   interpreter
  +     *  4   retaddr
  +     *  0   ebp <----- ebp
  +     */
   
  -    /* Save ESI, as it's value is clobbered by jit_cpcf_op */
  -    emit_pushl_r(jit_info->native_ptr, emit_ESI);
  -
  -    /* Save EBX and EDI, since they are callee-saved in cdecl (so are
  -     * ESI and EBP, but they have already been saved for other
  -     * reasons.) */
  +    /* Save all callee-saved registers (cdecl)
  +     */
       emit_pushl_r(jit_info->native_ptr, emit_EBX);
  +    emit_pushl_r(jit_info->native_ptr, emit_ESI);
       emit_pushl_r(jit_info->native_ptr, emit_EDI);
   
       /* Cheat on op function calls by writing the interpreter arg on the stack
  @@ -961,36 +981,18 @@
        * the stack this will stop working !!! */
       emitm_pushl_i(jit_info->native_ptr, interpreter);
   
  -    /* Point EBP to the opcode-native code map array */
  +    /* get the pc from stack:  mov 12(%ebx), %eax */
  +    emitm_movl_m_r(jit_info->native_ptr, emit_EAX, emit_EBP, emit_None, 1, 12);
  +
  +    /* Point EBP to the opcode-native code map array - this destroy above
  +     * stack frame. If we have debugging, we should change this */
       emitm_movl_i_r(jit_info->native_ptr, jit_info->arena.op_map, emit_EBP);
   
  -    /* emit 5 noops. when JIT restarts a long jump will be patched in here */
  -    for (i = 0; i < 5; i++)
  -        emit_nop(jit_info->native_ptr);
  -}
  -
  -jit_f
  -Parrot_jit_restart(struct Parrot_Interp * interpreter, opcode_t pc)
  -{
  -    char *ptr;
  -    Parrot_jit_info_t *jit_info = (Parrot_jit_info_t *) interpreter->jit_info;
  -
  -    /* the 5 nops above are at native_ptr -5 of 1. instruction */
  -    jit_info->native_ptr = (char*)jit_info->arena.op_map[0].ptr - 5;
  -    /* pretend, we are at pc */
  -    jit_info->op_i = pc;
  -    /* op_map.ptr & op_map.offset are a union, which are absolute adr's
  -     * now -- fake offset */
  -    ptr = jit_info->arena.op_map[pc].ptr;
  -    jit_info->arena.op_map[pc].offset = ptr - jit_info->arena.start;
  -    /* emit jump with offset 0 */
  -    emit_jump(jit_info, 0);
  -    /* restore ptr */
  -    jit_info->arena.op_map[pc].ptr = ptr;
  -    /* return start of JIT code */
  -    return (jit_f)D2FPTR(jit_info->arena.start);
  +    /* jump to restart pos or first op */
  +    Parrot_emit_jump_to_eax(jit_info, interpreter);
   }
   
  +
   void
   Parrot_jit_normal_op(Parrot_jit_info_t *jit_info,
                        struct Parrot_Interp * interpreter)
  @@ -1015,13 +1017,14 @@
   
       Parrot_jit_normal_op(jit_info, interpreter);
       /* test eax, if zero (e.g after restart), return from JIT */
  -    emit_andl_r_r(jit_info->native_ptr, emit_EAX, emit_EAX);
  +    emit_test_r_r(jit_info->native_ptr, emit_EAX, emit_EAX);
       /* remember PC */
       jmp_ptr = jit_info->native_ptr;
       /* emit jump past exit code, dummy offset
        * this assumes exit code is in reach of a short jump (126 bytes) */
       emitm_jxs(jit_info->native_ptr, emitm_jnz, 0);
  -    /* emit exit code */
  +    /* emit exit code XXX: it would be better, to emit the exit code
  +     * only once and emit a jump to this code here */
       Parrot_end_jit(jit_info, interpreter);
       /* fixup above jump */
       sav_ptr = jit_info->native_ptr;
  @@ -1029,15 +1032,9 @@
       emitm_jxs(jit_info->native_ptr, emitm_jnz, (long)(sav_ptr - jmp_ptr) - 2);
       /* restore PC */
       jit_info->native_ptr = sav_ptr;
  -
  -    /* This calculates (INDEX into op_map * 4) */
  -    emitm_subl_i_r(jit_info->native_ptr, interpreter->code->byte_code,emit_EAX);
  -
  -    /* This jumps to the address in op_map[EBP + sizeof(void *) * INDEX] */
  -    *jit_info->native_ptr++ = 0x3e;     /* DS:0(EBP, EAX, 1) */
  -    emitm_jumpm(jit_info->native_ptr, emit_EBP, emit_EAX,
  -                        sizeof(*jit_info->arena.op_map) / 4, 0);
  +    Parrot_emit_jump_to_eax(jit_info, interpreter);
   }
  +
   
   /* Load registers for the current section */
   void
  
  
  
  1.13      +2 -7      parrot/jit/ppc/jit_emit.h
  
  Index: jit_emit.h
  ===================================================================
  RCS file: /cvs/public/parrot/jit/ppc/jit_emit.h,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -w -r1.12 -r1.13
  --- jit_emit.h        12 Nov 2002 14:47:34 -0000      1.12
  +++ jit_emit.h        16 Nov 2002 10:36:10 -0000      1.13
  @@ -3,7 +3,7 @@
    *
    * PPC
    *
  - * $Id: jit_emit.h,v 1.12 2002/11/12 14:47:34 leo Exp $
  + * $Id: jit_emit.h,v 1.13 2002/11/16 10:36:10 leo Exp $
    */
   
   #include <unistd.h>
  @@ -555,13 +555,8 @@
       emit_mr(jit_info->native_ptr, r13, r3);
       emit_imm32(jit_info->native_ptr, r14, jit_info->arena.op_map);
       emit_imm32(jit_info->native_ptr, r15, interpreter->code->byte_code);
  +    /* TODO emit restart code s. i386 */
   }
  -
  -jit_f
  -Parrot_jit_restart(struct Parrot_Interp * interpreter, opcode_t pc)
  -{
  -}
  -
   
   void
   Parrot_jit_normal_op(Parrot_jit_info_t *jit_info,
  
  
  
  1.14      +2 -6      parrot/jit/sun4/jit_emit.h
  
  Index: jit_emit.h
  ===================================================================
  RCS file: /cvs/public/parrot/jit/sun4/jit_emit.h,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -w -r1.13 -r1.14
  --- jit_emit.h        12 Nov 2002 14:47:42 -0000      1.13
  +++ jit_emit.h        16 Nov 2002 10:36:11 -0000      1.14
  @@ -3,7 +3,7 @@
   **
   ** SPARC
   **
  -** $Id: jit_emit.h,v 1.13 2002/11/12 14:47:42 leo Exp $
  +** $Id: jit_emit.h,v 1.14 2002/11/16 10:36:11 leo Exp $
   **/
   
   /*
  @@ -532,11 +532,7 @@
           emitm_hi22(jit_info->arena.op_map), Parrot_jit_opmap);
       emitm_or_i(jit_info->native_ptr,
           emitm_i(3), emitm_lo10(jit_info->arena.op_map), Parrot_jit_opmap);
  -}
  -
  -jit_f
  -Parrot_jit_restart(struct Parrot_Interp * interpreter, opcode_t pc)
  -{
  +    /* TODO emit restart code s. i386 */
   }
   
   void Parrot_jit_normal_op(Parrot_jit_info_t *jit_info,
  
  
  


Reply via email to