Christian Ullrich
Edwin Steiner
- $Id: codegen.c 4863 2006-04-30 16:17:44Z edwin $
+ $Id: codegen.c 4898 2006-05-10 15:51:46Z twisti $
*/
/* walk through all basic blocks */
for (bptr = m->basicblocks; bptr != NULL; bptr = bptr->next) {
- bptr->mpc = (s4) ((u1 *) cd->mcodeptr - cd->mcodebase);
+ bptr->mpc = (s4) (cd->mcodeptr - cd->mcodebase);
if (bptr->flags >= BBREACHED) {
{
int tempreg = false;
int dreg;
- u4 *br1;
+ u1 *br1;
if (src->prev->flags & INMEMORY) {
tempreg = tempreg || (d == REG_ITMP3) || (d == REG_ITMP2);
M_BEQ(1);
M_IADD_IMM(dreg, -1, dreg);
M_IADD_IMM(dreg, -1, dreg);
- gen_resolvebranch(br1, (u1*) br1, (u1*) cd->mcodeptr);
- gen_resolvebranch(br1+1, (u1*) (br1+1), (u1*) (cd->mcodeptr-2));
+ gen_resolvebranch(br1, br1, cd->mcodeptr);
+ gen_resolvebranch(br1 + 1 * 4, br1 + 1 * 4, cd->mcodeptr - 2 * 4);
M_INTMOVE(dreg, d);
}
emit_store(jd, iptr, iptr->dst, d);
M_ALD(REG_PV, REG_PV, disp); /* pointer to built-in-function */
M_MTCTR(REG_PV);
M_JSR;
- disp = (s4) ((u1 *) cd->mcodeptr - cd->mcodebase);
+ disp = (s4) (cd->mcodeptr - cd->mcodebase);
M_MFLR(REG_ITMP1);
M_LDA(REG_PV, REG_ITMP1, -disp);
M_ALD(REG_PV, REG_PV, disp);
M_MTCTR(REG_PV);
M_JSR;
- disp = (s4) ((u1 *) cd->mcodeptr - cd->mcodebase);
+ disp = (s4) (cd->mcodeptr - cd->mcodebase);
M_MFLR(REG_ITMP1);
M_LDA(REG_PV, REG_ITMP1, -disp);
break;
M_ALD(REG_PV, REG_METHODPTR, s1);
M_MTCTR(REG_PV);
M_JSR;
- disp = (s4) ((u1 *) cd->mcodeptr - cd->mcodebase);
+ disp = (s4) (cd->mcodeptr - cd->mcodebase);
M_MFLR(REG_ITMP1);
M_LDA(REG_PV, REG_ITMP1, -disp);
break;
M_ALD(REG_PV, REG_METHODPTR, s2);
M_MTCTR(REG_PV);
M_JSR;
- disp = (s4) ((u1 *) cd->mcodeptr - cd->mcodebase);
+ disp = (s4) (cd->mcodeptr - cd->mcodebase);
M_MFLR(REG_ITMP1);
M_LDA(REG_PV, REG_ITMP1, -disp);
break;
}
#if defined(USE_THREADS) && defined(NATIVE_THREADS)
- codegen_threadcritrestart(cd, (u1 *) cd->mcodeptr - cd->mcodebase);
+ codegen_threadcritrestart(cd, cd->mcodeptr - cd->mcodebase);
#endif
s1 = emit_load_s1(jd, iptr, src, REG_ITMP1);
M_ALD(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
#if defined(USE_THREADS) && defined(NATIVE_THREADS)
- codegen_threadcritstart(cd, (u1 *) cd->mcodeptr - cd->mcodebase);
+ codegen_threadcritstart(cd, cd->mcodeptr - cd->mcodebase);
#endif
M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
M_ALD(REG_ITMP2, REG_PV, disp);
M_ILD(REG_ITMP1, REG_ITMP2, OFFSET(vftbl_t, baseval));
M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
#if defined(USE_THREADS) && defined(NATIVE_THREADS)
- codegen_threadcritstop(cd, (u1 *) cd->mcodeptr - cd->mcodebase);
+ codegen_threadcritstop(cd, cd->mcodeptr - cd->mcodebase);
#endif
M_ISUB(REG_ITMP3, REG_ITMP1, REG_ITMP3);
} else {
M_ALD(REG_ITMP2, REG_PV, disp);
M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
#if defined(USE_THREADS) && defined(NATIVE_THREADS)
- codegen_threadcritstop(cd, (u1 *) cd->mcodeptr - cd->mcodebase);
+ codegen_threadcritstop(cd, cd->mcodeptr - cd->mcodebase);
#endif
}
M_CMPU(REG_ITMP3, REG_ITMP2);
}
#if defined(USE_THREADS) && defined(NATIVE_THREADS)
- codegen_threadcritrestart(cd, (u1*) cd->mcodeptr - cd->mcodebase);
+ codegen_threadcritrestart(cd, cd->mcodeptr - cd->mcodebase);
#endif
s1 = emit_load_s1(jd, iptr, src, REG_ITMP1);
d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, REG_ITMP2);
M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
M_ALD(REG_ITMP2, REG_PV, disp);
#if defined(USE_THREADS) && defined(NATIVE_THREADS)
- codegen_threadcritstart(cd, (u1 *) cd->mcodeptr - cd->mcodebase);
+ codegen_threadcritstart(cd, cd->mcodeptr - cd->mcodebase);
#endif
M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
#if defined(USE_THREADS) && defined(NATIVE_THREADS)
- codegen_threadcritstop(cd, (u1 *) cd->mcodeptr - cd->mcodebase);
+ codegen_threadcritstop(cd, cd->mcodeptr - cd->mcodebase);
#endif
M_ISUB(REG_ITMP1, REG_ITMP3, REG_ITMP1);
M_CMPU(REG_ITMP1, REG_ITMP2);
exceptionref *eref;
patchref *pref;
u4 mcode;
- u4 *savedmcodeptr;
- u4 *tmpmcodeptr;
+ u1 *savedmcodeptr;
+ u1 *tmpmcodeptr;
savedmcodeptr = NULL;
/* generate exception stubs */
for (eref = cd->exceptionrefs; eref != NULL; eref = eref->next) {
- gen_resolvebranch((u1 *) cd->mcodebase + eref->branchpos,
- eref->branchpos,
- (u1 *) cd->mcodeptr - cd->mcodebase);
+ gen_resolvebranch(cd->mcodebase + eref->branchpos,
+ eref->branchpos, cd->mcodeptr - cd->mcodebase);
MCODECHECK(100);
M_ALD(REG_ITMP3, REG_PV, disp);
if (savedmcodeptr != NULL) {
- disp = savedmcodeptr - (cd->mcodeptr + 1);
+ disp = ((u4 *) savedmcodeptr) - (((u4 *) cd->mcodeptr) + 1);
M_BR(disp);
} else {
/* Get machine code which is patched back in later. The
call is 1 instruction word long. */
- savedmcodeptr = (u4 *) (cd->mcodebase + pref->branchpos);
- mcode = *savedmcodeptr;
+ tmpmcodeptr = (u1 *) (cd->mcodebase + pref->branchpos);
+
+ mcode = *((u4 *) tmpmcodeptr);
/* Patch in the call to call the following code (done at
compile time). */
- tmpmcodeptr = cd->mcodeptr; /* save current mcodeptr */
- cd->mcodeptr = savedmcodeptr; /* set mcodeptr to patch position */
+ savedmcodeptr = cd->mcodeptr; /* save current mcodeptr */
+ cd->mcodeptr = tmpmcodeptr; /* set mcodeptr to patch position */
- M_BR(tmpmcodeptr - (savedmcodeptr + 1));
+ disp = ((u4 *) savedmcodeptr) - (((u4 *) tmpmcodeptr) + 1);
+ M_BR(disp);
- cd->mcodeptr = tmpmcodeptr; /* restore the current mcodeptr */
+ cd->mcodeptr = savedmcodeptr; /* restore the current mcodeptr */
/* create stack frame - keep stack 16-byte aligned */
/* note start of stub code */
- replacementpoint->outcode = (u1*) (ptrint)((u1*)cd->mcodeptr - cd->mcodebase);
+ replacementpoint->outcode = (u1 *) (cd->mcodeptr - cd->mcodebase);
/* make machine code for patching */
tmpmcodeptr = cd->mcodeptr;
- cd->mcodeptr = (u4 *) &(replacementpoint->mcode) + 1 /* big-endian */;
+ cd->mcodeptr = (u1 *) &(replacementpoint->mcode) + 1 /* big-endian */;
disp = (ptrint)((s4*)replacementpoint->outcode - (s4*)replacementpoint->pc) - 1;
M_BR(disp);
dumpsize = dump_size();
cd = DNEW(codegendata);
- cd->mcodeptr = (u4 *) s;
+ cd->mcodeptr = s;
/* Store the methodinfo* in the same place as in the methodheader
for compiled methods. */
{
patchref *pref;
u4 mcode;
- u4 *savedmcodeptr;
- u4 *tmpmcodeptr;
+ u1 *savedmcodeptr;
+ u1 *tmpmcodeptr;
for (pref = cd->patchrefs; pref != NULL; pref = pref->next) {
/* Get machine code which is patched back in later. The
call is 1 instruction word long. */
- savedmcodeptr = (u4 *) (cd->mcodebase + pref->branchpos);
- mcode = (u4) *savedmcodeptr;
+ tmpmcodeptr = cd->mcodebase + pref->branchpos;
+
+ mcode = *((u4 *) tmpmcodeptr);
/* Patch in the call to call the following code (done at
compile time). */
- tmpmcodeptr = cd->mcodeptr; /* save current mcodeptr */
- cd->mcodeptr = savedmcodeptr; /* set mcodeptr to patch position */
+ savedmcodeptr = cd->mcodeptr; /* save current mcodeptr */
+ cd->mcodeptr = tmpmcodeptr; /* set mcodeptr to patch position */
- M_BL(tmpmcodeptr - (savedmcodeptr + 1));
+ disp = ((u4 *) savedmcodeptr) - (((u4 *) tmpmcodeptr) + 1);
+ M_BL(disp);
- cd->mcodeptr = tmpmcodeptr; /* restore the current mcodeptr */
+ cd->mcodeptr = savedmcodeptr; /* restore the current mcodeptr */
- /* create stack frame - keep stack 16-byte aligned */
+ /* create stack frame - keep stack 16-byte aligned */
M_AADD_IMM(REG_SP, -8 * 4, REG_SP);
Changes: Christian Thalinger
Christian Ullrich
- $Id: codegen.h 4826 2006-04-24 16:06:16Z twisti $
+ $Id: codegen.h 4898 2006-05-10 15:51:46Z twisti $
*/
#define MCODECHECK(icnt) \
do { \
- if ((cd->mcodeptr + (icnt)) > (u4 *) cd->mcodeend) \
+ if ((cd->mcodeptr + (icnt) * 4) > cd->mcodeend) \
codegen_increase(cd); \
} while (0)
/* macros to create code ******************************************************/
#define M_OP3(opcode,y,oe,rc,d,a,b) \
- *(cd->mcodeptr++) = (((opcode) << 26) | ((d) << 21) | ((a) << 16) | ((b) << 11) | ((oe) << 10) | ((y) << 1) | (rc))
+ do { \
+ *((u4 *) cd->mcodeptr) = (((opcode) << 26) | ((d) << 21) | ((a) << 16) | ((b) << 11) | ((oe) << 10) | ((y) << 1) | (rc)); \
+ cd->mcodeptr += 4; \
+ } while (0)
#define M_OP4(x,y,rc,d,a,b,c) \
- *(cd->mcodeptr++) = (((x) << 26) | ((d) << 21) | ((a) << 16) | ((b) << 11) | ((c) << 6) | ((y) << 1) | (rc))
+ do { \
+ *((u4 *) cd->mcodeptr) = (((x) << 26) | ((d) << 21) | ((a) << 16) | ((b) << 11) | ((c) << 6) | ((y) << 1) | (rc)); \
+ cd->mcodeptr += 4; \
+ } while (0)
#define M_OP2_IMM(x,d,a,i) \
- *(cd->mcodeptr++) = (((x) << 26) | ((d) << 21) | ((a) << 16) | ((i) & 0xffff))
+ do { \
+ *((u4 *) cd->mcodeptr) = (((x) << 26) | ((d) << 21) | ((a) << 16) | ((i) & 0xffff)); \
+ cd->mcodeptr += 4; \
+ } while (0)
#define M_BRMASK 0x0000fffc /* (((1 << 16) - 1) & ~3) */
#define M_BRAMASK 0x03fffffc /* (((1 << 26) - 1) & ~3) */
#define M_BRA(x,i,a,l) \
- *(cd->mcodeptr++) = (((x) << 26) | ((((i) * 4) + 4) & M_BRAMASK) | ((a) << 1) | (l))
+ do { \
+ *((u4 *) cd->mcodeptr) = (((x) << 26) | ((((i) * 4) + 4) & M_BRAMASK) | ((a) << 1) | (l)); \
+ cd->mcodeptr += 4; \
+ } while (0)
#define M_BRAC(x,bo,bi,i,a,l) \
- *(cd->mcodeptr++) = (((x) << 26) | ((bo) << 21) | ((bi) << 16) | (((i) * 4 + 4) & M_BRMASK) | ((a) << 1) | (l))
+ do { \
+ *((u4 *) cd->mcodeptr) = (((x) << 26) | ((bo) << 21) | ((bi) << 16) | (((i) * 4 + 4) & M_BRMASK) | ((a) << 1) | (l)); \
+ cd->mcodeptr += 4; \
+ } while (0)
/* instruction macros *********************************************************/