Branch: Tag:

2001-08-15

2001-08-15 17:44:05 by Marcus Comstedt <marcus@mc.pp.se>

Cleanup and optimization.

Rev: src/code/ppc32.c:1.6
Rev: src/code/ppc32.h:1.6

1:   /* -  * $Id: ppc32.h,v 1.5 2001/08/14 01:26:09 marcus Exp $ +  * $Id: ppc32.h,v 1.6 2001/08/15 17:44:05 marcus Exp $    */      #define PIKE_OPCODE_T unsigned INT32    -  + #define PPC_INSTR_B_FORM(OPCD,BO,BI,BD,AA,LK) \ +  add_to_program(((OPCD)<<26)|((BO)<<21)|((BI)<<16)| \ +  (((BD)&0x3fff)<<2)|((AA)<<1)|(LK)) + #define PPC_INSTR_D_FORM(OPCD,S,A,d) \ +  add_to_program(((OPCD)<<26)|((S)<<21)|((A)<<16)|((d)&0xffff)) + #define PPC_INSTR_M_FORM(OPCD,S,A,SH,MB,ME,Rc) \ +  add_to_program(((OPCD)<<26)|((S)<<21)|((A)<<16)|((SH)<<11)| \ +  ((MB)<<6)|((ME)<<1)|(Rc)) +  + #define BC(BO,BI,BD) PPC_INSTR_B_FORM(16,BO,BI,BD,0,0) +  + #define CMPLI(crfD,A,UIMM) PPC_INSTR_D_FORM(10,crfD,A,UIMM) + #define ADDIC(D,A,SIMM) PPC_INSTR_D_FORM(12,D,A,SIMM) + #define ADDI(D,A,SIMM) PPC_INSTR_D_FORM(14,D,A,SIMM) + #define ADDIS(D,A,SIMM) PPC_INSTR_D_FORM(15,D,A,SIMM) + #define ORI(D,A,UIMM) PPC_INSTR_D_FORM(24,D,A,UIMM) + #define LWZ(D,A,d) PPC_INSTR_D_FORM(32,D,A,d) + #define STW(S,A,d) PPC_INSTR_D_FORM(36,S,A,d) +  + #define RLWINM(S,A,SH,MB,ME) PPC_INSTR_M_FORM(21,S,A,SH,MB,ME,0) +  +    #define LOW_GET_JUMP() (PROG_COUNTER[0])   #define LOW_SKIPJUMP() (SET_PROG_COUNTER(PROG_COUNTER + 1))   #define PROG_COUNTER (((INT32 **)__builtin_frame_address(1))[2])
13:    INT32 reg_ = REG; \    if ((-32768 <= val_) && (val_ <= 32767)) { \    /* addi reg,0,val */ \ -  add_to_program(0x38000000|(reg_<<21)|(val_ & 0xffff)); \ +  ADDI(reg_, 0, val_); \    } else { \    /* addis reg,0,%hi(val) */ \ -  add_to_program(0x3c000000|(reg_<<21)|((val_ >> 16) & 0xffff)); \ +  ADDIS(reg_, 0, val_ >> 16); \    if (val_ & 0xffff) { \    /* ori reg,reg,%lo(val) */ \ -  add_to_program(0x60000000|(reg_<<21)|(reg_<<16)|(val_ & 0xffff)); \ +  ORI(reg_, reg_, val_); \    } \    } \    } while(0)    - #define UPDATE_PC() do { \ -  INT32 tmp = PIKE_PC; \ -  /* lwz 11,frame_pointer(31) */ \ -  add_to_program(0x80000000|(11<<21)|(31<<16)| \ -  OFFSETOF(Pike_interpreter, frame_pointer)); \ -  SET_REG(0, tmp); \ -  /* stw 0,pc(11) */ \ -  add_to_program(0x90000000|(0<<21)|(11<<16)| \ -  OFFSETOF(pike_frame, pc)); \ + #define PPC_REG_ARG1 3 + #define PPC_REG_ARG2 4 +  + #define PPC_REG_PIKE_FP 9 + #define PPC_REG_PIKE_SP 10 +  + #define PPC_REG_PIKE_INTERP 31 +  + extern int ppc32_codegen_state; + void ppc32_flush_code_generator_state(void); + #define FLUSH_CODE_GENERATOR_STATE ppc32_flush_code_generator_state +  + #define PPC_CODEGEN_FP_ISSET 1 + #define PPC_CODEGEN_SP_ISSET 2 + #define PPC_CODEGEN_SP_NEEDSSTORE 4 +  + #define LOAD_FP_REG() do { \ +  if(!(ppc32_codegen_state & PPC_CODEGEN_FP_ISSET)) { \ +  /* lwz pike_fp,frame_pointer(pike_interpreter) */ \ +  LWZ(PPC_REG_PIKE_FP, PPC_REG_PIKE_INTERP, \ +  OFFSETOF(Pike_interpreter, frame_pointer)); \ +  ppc32_codegen_state |= PPC_CODEGEN_FP_ISSET; \ +  } \    } while(0)    -  + #define LOAD_SP_REG() do { \ +  if(!(ppc32_codegen_state & PPC_CODEGEN_SP_ISSET)) { \ +  /* lwz pike_sp,stack_pointer(pike_interpreter) */ \ +  LWZ(PPC_REG_PIKE_SP, PPC_REG_PIKE_INTERP, \ +  OFFSETOF(Pike_interpreter, stack_pointer)); \ +  ppc32_codegen_state |= PPC_CODEGEN_SP_ISSET; \ +  } \ +  } while(0) +  + #define INCR_SP_REG(n) do { \ +  /* addi pike_sp,pike_sp,n */ \ +  ADDI(PPC_REG_PIKE_SP, PPC_REG_PIKE_SP, n); \ +  ppc32_codegen_state |= PPC_CODEGEN_SP_NEEDSSTORE; \ +  } while(0) +  + #define UPDATE_PC() do { \ +  INT32 tmp = PIKE_PC; \ +  LOAD_FP_REG(); \ +  SET_REG(0, tmp); \ +  /* stw r0,pc(pike_fp) */ \ +  STW(0, PPC_REG_PIKE_FP, OFFSETOF(pike_frame, pc)); \ +  } while(0) +    #define ins_pointer(PTR) add_to_program((INT32)(PTR))   #define read_pointer(OFF) (Pike_compiler->new_program->program[(INT32)(OFF)])   #define upd_pointer(OFF,PTR) (Pike_compiler->new_program->program[(INT32)(OFF)] = (INT32)(PTR))
44:      #define READ_INCR_BYTE(PC) (((PC)++)[0])    + #if 0   #define RELOCATE_program(P, NEW) do { \    PIKE_OPCODE_T *op_ = NEW; \    struct program *p_ = P; \
63:    0x03ffffff); \    } \    } while(0) + #endif      extern void ppc32_flush_instruction_cache(void *addr, size_t len);   #define FLUSH_INSTRUCTION_CACHE ppc32_flush_instruction_cache
77:   #define DECODE_PROGRAM(P) ppc32_decode_program(p)   */    - /* FIXME: should be autoconf test for regname syntax */ - #ifdef _AIX - #define PPC_REGNAME(n) #n + #ifdef PIKE_CPU_REG_PREFIX + #define PPC_REGNAME(n) PIKE_CPU_REG_PREFIX #n   #else - #define PPC_REGNAME(n) "r"#n + #define PPC_REGNAME(n) #n   #endif    - #define CALL_MACHINE_CODE(pc) \ -  __asm__ __volatile__( " mtctr %0\n" \ -  " mr "PPC_REGNAME(31)",%1\n" \ -  " bctr" \ -  : \ -  : "r" (pc), "r" (&Pike_interpreter) \ -  : "ctr", "lr", "cc", "memory", "r31", "r0", \ -  "r3", "r4", "r5", "r6", "r7", "r8", "r9", \ + #define CALL_MACHINE_CODE(pc) \ +  __asm__ __volatile__( " mtctr %0\n" \ +  " mr "PPC_REGNAME(31)",%1\n" \ +  " bctr" \ +  : \ +  : "r" (pc), "r" (&Pike_interpreter) \ +  : "ctr", "lr", "cc", "memory", "r31", "r0", \ +  "r3", "r4", "r5", "r6", "r7", "r8", "r9", \    "r10", "r11", "r12")