From a903c1fa36a418621f076115d9c43793bc66dd90 Mon Sep 17 00:00:00 2001 From: cacao Date: Tue, 6 Oct 1998 20:36:04 +0000 Subject: [PATCH] jBYTEmark optimizations added --- alpha/ngen.c | 161 ++++++++++++++++++++++++++++++++++++++++++++++- alpha/ngen.h | 1 + ncomp/ncompdef.h | 12 ++-- ncomp/nparse.c | 14 +---- ncomp/nreg.c | 4 ++ ncomp/nstack.c | 128 ++++++++++++++++++++++++++++++++++++- 6 files changed, 301 insertions(+), 19 deletions(-) diff --git a/alpha/ngen.c b/alpha/ngen.c index 7fd8cd9ba..0bba6098e 100644 --- a/alpha/ngen.c +++ b/alpha/ngen.c @@ -207,7 +207,7 @@ void catch_NullPointerException(int sig, int code, void *sigctx) signal(sig, (void*) catch_NullPointerException); sigemptyset(&nsig); sigaddset(&nsig, sig); - sigprocmask(SIG_UNBLOCK, &nsig, 0); + sigprocmask(SIG_UNBLOCK, &nsig, NULL); asm_signal_exception(proto_java_lang_NullPointerException, sigctx); } @@ -244,6 +244,7 @@ ieee_set_fp_control(ieee_get_fp_control() } } + /*************************** function gen_mcode ******************************** generates machine code @@ -989,10 +990,68 @@ static void gen_mcode() if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) { M_AND(s1, iptr->val.i, d, 1); } + else if (iptr->val.i == 0xffff) { + M_ZAPNOT(s1, 0x03, d, 1); + } + else if (iptr->val.i == 0xffffff) { + M_ZAPNOT(s1, 0x07, d, 1); + } + else { + ICONST(REG_ITMP2, iptr->val.i); + M_AND(s1, REG_ITMP2, d, 0); + } + store_reg_to_var_int(iptr->dst, d); + break; + case ICMD_IREMPOW2: + var_to_reg_int(s1, src, REG_ITMP1); + d = reg_of_var(iptr->dst, REG_ITMP3); + if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) { + M_AND(s1, iptr->val.i, d, 1); + M_BGEZ(s1, 3); + M_ISUB(REG_ZERO, s1, d, 0); + M_AND(d, iptr->val.i, d, 1); + } + else if (iptr->val.i == 0xffff) { + M_ZAPNOT(s1, 0x03, d, 1); + M_BGEZ(s1, 3); + M_ISUB(REG_ZERO, s1, d, 0); + M_ZAPNOT(d, 0x03, d, 1); + } + else if (iptr->val.i == 0xffffff) { + M_ZAPNOT(s1, 0x07, d, 1); + M_BGEZ(s1, 3); + M_ISUB(REG_ZERO, s1, d, 0); + M_ZAPNOT(d, 0x07, d, 1); + } else { ICONST(REG_ITMP2, iptr->val.i); M_AND(s1, REG_ITMP2, d, 0); + M_BGEZ(s1, 3); + M_ISUB(REG_ZERO, s1, d, 0); + M_AND(d, REG_ITMP2, d, 0); } + M_ISUB(REG_ZERO, d, d, 0); + store_reg_to_var_int(iptr->dst, d); + break; + case ICMD_IREM0X10001: + var_to_reg_int(s1, src, REG_ITMP1); + d = reg_of_var(iptr->dst, REG_ITMP3); + M_ZAPNOT(s1, 0x03, REG_ITMP2, 1); + M_SRA(s1, 16, d, 1); + M_CMPLT(REG_ITMP2, d, REG_ITMP1, 0); + M_ISUB(REG_ITMP2, d, d, 0); + M_IADD(d, REG_ITMP1, d, 0); + M_BGEZ(s1, 10); + M_ISUB(REG_ZERO, s1, REG_ITMP1, 0); + M_ZAPNOT(REG_ITMP1, 0x03, REG_ITMP2, 1); + M_SRA(REG_ITMP1, 16, d, 1); + M_CMPLT(REG_ITMP2, d, REG_ITMP1, 0); + M_ISUB(REG_ITMP2, d, d, 0); + M_IADD(d, REG_ITMP1, d, 0); + M_ISUB(REG_ZERO, d, d, 0); + M_SLL(s1, 33, REG_ITMP2, 1); + M_CMPEQ(REG_ITMP2, REG_ZERO, REG_ITMP2, 0); + M_ISUB(d, REG_ITMP2, d, 0); store_reg_to_var_int(iptr->dst, d); break; case ICMD_LANDCONST: @@ -1001,10 +1060,108 @@ static void gen_mcode() if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) { M_AND(s1, iptr->val.l, d, 1); } + else if (iptr->val.l == 0xffffL) { + M_ZAPNOT(s1, 0x03, d, 1); + } + else if (iptr->val.l == 0xffffffL) { + M_ZAPNOT(s1, 0x07, d, 1); + } + else if (iptr->val.l == 0xffffffffL) { + M_ZAPNOT(s1, 0x0f, d, 1); + } + else if (iptr->val.l == 0xffffffffffL) { + M_ZAPNOT(s1, 0x1f, d, 1); + } + else if (iptr->val.l == 0xffffffffffffL) { + M_ZAPNOT(s1, 0x3f, d, 1); + } + else if (iptr->val.l == 0xffffffffffffffL) { + M_ZAPNOT(s1, 0x7f, d, 1); + } + else { + LCONST(REG_ITMP2, iptr->val.l); + M_AND(s1, REG_ITMP2, d, 0); + } + store_reg_to_var_int(iptr->dst, d); + break; + case ICMD_LREMPOW2: + var_to_reg_int(s1, src, REG_ITMP1); + d = reg_of_var(iptr->dst, REG_ITMP3); + if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) { + M_AND(s1, iptr->val.l, d, 1); + M_BGEZ(s1, 3); + M_LSUB(REG_ZERO, s1, d, 0); + M_AND(d, iptr->val.l, d, 1); + } + else if (iptr->val.l == 0xffffL) { + M_ZAPNOT(s1, 0x03, d, 1); + M_BGEZ(s1, 3); + M_LSUB(REG_ZERO, s1, d, 0); + M_ZAPNOT(d, 0x03, d, 1); + } + else if (iptr->val.l == 0xffffffL) { + M_ZAPNOT(s1, 0x07, d, 1); + M_BGEZ(s1, 3); + M_LSUB(REG_ZERO, s1, d, 0); + M_ZAPNOT(d, 0x07, d, 1); + } + else if (iptr->val.l == 0xffffffffL) { + M_ZAPNOT(s1, 0x0f, d, 1); + M_BGEZ(s1, 3); + M_LSUB(REG_ZERO, s1, d, 0); + M_ZAPNOT(d, 0x0f, d, 1); + } + else if (iptr->val.l == 0xffffffffffL) { + M_ZAPNOT(s1, 0x1f, d, 1); + M_BGEZ(s1, 3); + M_LSUB(REG_ZERO, s1, d, 0); + M_ZAPNOT(d, 0x1f, d, 1); + } + else if (iptr->val.l == 0xffffffffffffL) { + M_ZAPNOT(s1, 0x3f, d, 1); + M_BGEZ(s1, 3); + M_LSUB(REG_ZERO, s1, d, 0); + M_ZAPNOT(d, 0x3f, d, 1); + } + else if (iptr->val.l == 0xffffffffffffffL) { + M_ZAPNOT(s1, 0x7f, d, 1); + M_BGEZ(s1, 3); + M_LSUB(REG_ZERO, s1, d, 0); + M_ZAPNOT(d, 0x7f, d, 1); + } else { LCONST(REG_ITMP2, iptr->val.l); M_AND(s1, REG_ITMP2, d, 0); + M_BGEZ(s1, 3); + M_LSUB(REG_ZERO, s1, d, 0); + M_AND(d, REG_ITMP2, d, 0); } + M_LSUB(REG_ZERO, d, d, 0); + store_reg_to_var_int(iptr->dst, d); + break; + case ICMD_LREM0X10001: + var_to_reg_int(s1, src, REG_ITMP1); + d = reg_of_var(iptr->dst, REG_ITMP3); + M_ZAPNOT(s1, 0x03, REG_ITMP2, 1); + M_SRA(s1, 16, d, 1); + M_CMPLT(REG_ITMP2, d, REG_ITMP1, 0); + M_LSUB(REG_ITMP2, d, d, 0); + M_LADD(d, REG_ITMP1, d, 0); + M_LDA(REG_ITMP2, REG_ZERO, -1); + M_SRL(REG_ITMP2, 33, REG_ITMP2, 1); + M_CMPULT(s1, REG_ITMP2, REG_ITMP2, 0); + M_BNEZ(REG_ITMP2, 11); + M_LDA(d, REG_ZERO, -257); + M_ZAPNOT(d, 0xcd, d, 1); + M_LSUB(REG_ZERO, s1, REG_ITMP2, 0); + M_CMOVGE(s1, s1, REG_ITMP2, 0); + M_UMULH(REG_ITMP2, d, REG_ITMP2, 0); + M_SRL(REG_ITMP2, 16, REG_ITMP2, 1); + M_LSUB(REG_ZERO, REG_ITMP2, d, 0); + M_CMOVGE(s1, REG_ITMP2, d, 0); + M_SLL(d, 16, REG_ITMP2, 1); + M_LADD(d, REG_ITMP2, d, 0); + M_LSUB(s1, d, d, 0); store_reg_to_var_int(iptr->dst, d); break; @@ -2483,6 +2640,8 @@ makeactualcall: } } /* for basic block */ + bptr -> mpc = (int)((u1*) mcodeptr - mcodebase); + { s4 *xcodeptr = NULL; diff --git a/alpha/ngen.h b/alpha/ngen.h index 5b3239cd1..37a82a4ea 100644 --- a/alpha/ngen.h +++ b/alpha/ngen.h @@ -283,6 +283,7 @@ int parentargs_base; /* offset in stackframe for the parameter from the caller*/ #define M_MSKLH(a,b,c,const) M_OP3 (0x12,0x62, a,b,c,const) #define M_MSKQH(a,b,c,const) M_OP3 (0x12,0x72, a,b,c,const) +#define M_UMULH(a,b,c,const) M_OP3 (0x13,0x30, a,b,c,const) /* 64 umulh */ /****** macros for unused commands (see an Alpha-manual for description) ******/ diff --git a/ncomp/ncompdef.h b/ncomp/ncompdef.h index c44953f4d..3906fcd1e 100644 --- a/ncomp/ncompdef.h +++ b/ncomp/ncompdef.h @@ -156,6 +156,7 @@ static int jcommandsize[256] = { #define ICMD_ICONST 3 /* op1 = 0, val.i = constant */ 1, #define JAVA_ICONST_1 4 +#define ICMD_IREM0X10001 4 1, #define JAVA_ICONST_2 5 1, @@ -164,6 +165,7 @@ static int jcommandsize[256] = { #define JAVA_ICONST_4 7 1, #define JAVA_ICONST_5 8 +#define ICMD_LREM0X10001 8 1, #define JAVA_LCONST_0 9 #define ICMD_LCONST 9 /* op1 = 0, val.l = constant */ @@ -238,6 +240,7 @@ static int jcommandsize[256] = { #define ICMD_IUSHRCONST 34 1, #define JAVA_FLOAD_1 35 +#define ICMD_IREMPOW2 35 1, #define JAVA_FLOAD_2 36 #define ICMD_LADDCONST 36 @@ -267,6 +270,7 @@ static int jcommandsize[256] = { #define ICMD_LUSHRCONST 44 1, #define JAVA_ALOAD_3 45 +#define ICMD_LREMPOW2 45 1, #define JAVA_IALOAD 46 #define ICMD_IALOAD 46 @@ -860,11 +864,11 @@ static char *icmd_names[256] = { "ACONST ", /* 1 */ "NULLCHECKPOP ", /* ICONST_M1 2 */ "ICONST ", /* 3 */ - "UNDEF__4 ", /* ICONST_1 4 */ + "IREM0X10001 ", /* ICONST_1 4 */ "UNDEF__5 ", /* ICONST_2 5 */ "UNDEF__6 ", /* ICONST_3 6 */ "UNDEF__7 ", /* ICONST_4 7 */ - "UNDEF__8 ", /* ICONST_5 8 */ + "LREM0X10001 ", /* ICONST_5 8 */ "LCONST ", /* 9 */ "LCMPCONST ", /* LCONST_1 10 */ "FCONST ", /* 11 */ @@ -891,7 +895,7 @@ static char *icmd_names[256] = { "ISHLCONST ", /* LLOAD_2 32 */ "ISHRCONST ", /* LLOAD_3 33 */ "IUSHRCONST ", /* FLOAD_0 34 */ - "UNDEF_35 ", /* FLOAD_1 35 */ + "IREMPOW2 ", /* FLOAD_1 35 */ "LADDCONST ", /* FLOAD_2 36 */ "LSUBCONST ", /* FLOAD_3 37 */ "LMULCONST ", /* DLOAD_0 38 */ @@ -901,7 +905,7 @@ static char *icmd_names[256] = { "LSHLCONST ", /* ALOAD_0 42 */ "LSHRCONST ", /* ALOAD_1 43 */ "LUSHRCONST ", /* ALOAD_2 44 */ - "UNDEF_45 ", /* ALOAD_3 45 */ + "LREMPOW2 ", /* ALOAD_3 45 */ "IALOAD ", /* 46 */ "LALOAD ", /* 47 */ "FALOAD ", /* 48 */ diff --git a/ncomp/nparse.c b/ncomp/nparse.c index 993e305f0..393a25341 100644 --- a/ncomp/nparse.c +++ b/ncomp/nparse.c @@ -775,12 +775,7 @@ static void parse() break; case JAVA_IREM: - if (SUPPORT_DIVISION) { - OP(opcode); - } - else { - BUILTIN2((functionptr) new_builtin_irem, TYPE_INT); - } + OP(opcode); break; case JAVA_LDIV: @@ -793,12 +788,7 @@ static void parse() break; case JAVA_LREM: - if (SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_MULDIV) { - OP(opcode); - } - else { - BUILTIN2((functionptr) new_builtin_lrem, TYPE_LONG); - } + OP(opcode); break; case JAVA_FREM: diff --git a/ncomp/nreg.c b/ncomp/nreg.c index 6b8bfc5f1..43c652832 100644 --- a/ncomp/nreg.c +++ b/ncomp/nreg.c @@ -865,6 +865,8 @@ static void allocate_scratch_registers() case ICMD_IADDCONST: case ICMD_ISUBCONST: case ICMD_IMULCONST: + case ICMD_IREMPOW2: + case ICMD_IREM0X10001: case ICMD_IANDCONST: case ICMD_IORCONST: case ICMD_IXORCONST: @@ -875,6 +877,8 @@ static void allocate_scratch_registers() case ICMD_LADDCONST: case ICMD_LSUBCONST: case ICMD_LMULCONST: + case ICMD_LREMPOW2: + case ICMD_LREM0X10001: case ICMD_LANDCONST: case ICMD_LORCONST: case ICMD_LXORCONST: diff --git a/ncomp/nstack.c b/ncomp/nstack.c index eeeeacbe5..67ae89f9f 100644 --- a/ncomp/nstack.c +++ b/ncomp/nstack.c @@ -1,3 +1,4 @@ +/* -*- mode: c; tab-width: 4; c-basic-offset: 4 -*- */ /****************************** ncomp/nstack.c ********************************* Copyright (c) 1997 A. Krall, R. Grafl, M. Gschwind, M. Probst @@ -252,6 +253,48 @@ icmd_iconst_tail: case ICMD_IMUL: iptr[0].opc = ICMD_IMULCONST; goto icmd_iconst_tail; + case ICMD_IREM: + if (iptr[0].val.i == 0x10001) { + iptr[0].opc = ICMD_IREM0X10001; + goto icmd_iconst_tail; + } + if ((iptr[0].val.i == 0x00000002) || + (iptr[0].val.i == 0x00000004) || + (iptr[0].val.i == 0x00000008) || + (iptr[0].val.i == 0x00000010) || + (iptr[0].val.i == 0x00000020) || + (iptr[0].val.i == 0x00000040) || + (iptr[0].val.i == 0x00000080) || + (iptr[0].val.i == 0x00000100) || + (iptr[0].val.i == 0x00000200) || + (iptr[0].val.i == 0x00000400) || + (iptr[0].val.i == 0x00000800) || + (iptr[0].val.i == 0x00001000) || + (iptr[0].val.i == 0x00002000) || + (iptr[0].val.i == 0x00004000) || + (iptr[0].val.i == 0x00008000) || + (iptr[0].val.i == 0x00010000) || + (iptr[0].val.i == 0x00020000) || + (iptr[0].val.i == 0x00040000) || + (iptr[0].val.i == 0x00080000) || + (iptr[0].val.i == 0x00100000) || + (iptr[0].val.i == 0x00200000) || + (iptr[0].val.i == 0x00400000) || + (iptr[0].val.i == 0x00800000) || + (iptr[0].val.i == 0x01000000) || + (iptr[0].val.i == 0x02000000) || + (iptr[0].val.i == 0x04000000) || + (iptr[0].val.i == 0x08000000) || + (iptr[0].val.i == 0x10000000) || + (iptr[0].val.i == 0x20000000) || + (iptr[0].val.i == 0x40000000) || + (iptr[0].val.i == 0x80000000)) { + iptr[0].opc = ICMD_IREMPOW2; + iptr[0].val.i -= 1; + goto icmd_iconst_tail; + } + CONST(TYPE_INT); + break; case ICMD_IAND: iptr[0].opc = ICMD_IANDCONST; goto icmd_iconst_tail; @@ -319,6 +362,48 @@ icmd_lconst_tail: case ICMD_LMUL: iptr[0].opc = ICMD_LMULCONST; goto icmd_lconst_tail; + case ICMD_LREM: + if (iptr[0].val.l == 0x10001) { + iptr[0].opc = ICMD_LREM0X10001; + goto icmd_lconst_tail; + } + if ((iptr[0].val.l == 0x00000002) || + (iptr[0].val.l == 0x00000004) || + (iptr[0].val.l == 0x00000008) || + (iptr[0].val.l == 0x00000010) || + (iptr[0].val.l == 0x00000020) || + (iptr[0].val.l == 0x00000040) || + (iptr[0].val.l == 0x00000080) || + (iptr[0].val.l == 0x00000100) || + (iptr[0].val.l == 0x00000200) || + (iptr[0].val.l == 0x00000400) || + (iptr[0].val.l == 0x00000800) || + (iptr[0].val.l == 0x00001000) || + (iptr[0].val.l == 0x00002000) || + (iptr[0].val.l == 0x00004000) || + (iptr[0].val.l == 0x00008000) || + (iptr[0].val.l == 0x00010000) || + (iptr[0].val.l == 0x00020000) || + (iptr[0].val.l == 0x00040000) || + (iptr[0].val.l == 0x00080000) || + (iptr[0].val.l == 0x00100000) || + (iptr[0].val.l == 0x00200000) || + (iptr[0].val.l == 0x00400000) || + (iptr[0].val.l == 0x00800000) || + (iptr[0].val.l == 0x01000000) || + (iptr[0].val.l == 0x02000000) || + (iptr[0].val.l == 0x04000000) || + (iptr[0].val.l == 0x08000000) || + (iptr[0].val.l == 0x10000000) || + (iptr[0].val.l == 0x20000000) || + (iptr[0].val.l == 0x40000000) || + (iptr[0].val.l == 0x80000000)) { + iptr[0].opc = ICMD_LREMPOW2; + iptr[0].val.l -= 1; + goto icmd_lconst_tail; + } + CONST(TYPE_LNG); + break; case ICMD_LAND: iptr[0].opc = ICMD_LANDCONST; goto icmd_lconst_tail; @@ -737,11 +822,28 @@ icmd_lconst_lcmp_tail: /* pop 2 push 1 */ + case ICMD_IREM: + if (!(SUPPORT_DIVISION)) { + iptr[0].opc = ICMD_BUILTIN2; + iptr[0].op1 = TYPE_INT; + iptr[0].val.a = (functionptr) new_builtin_irem; + isleafmethod = false; + goto builtin2; + } + + case ICMD_LREM: + if (!(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_MULDIV)) { + iptr[0].opc = ICMD_BUILTIN2; + iptr[0].op1 = TYPE_LNG; + iptr[0].val.a = (functionptr) new_builtin_lrem; + isleafmethod = false; + goto builtin2; + } + case ICMD_IADD: case ICMD_ISUB: case ICMD_IMUL: case ICMD_IDIV: - case ICMD_IREM: case ICMD_ISHL: case ICMD_ISHR: @@ -757,7 +859,6 @@ icmd_lconst_lcmp_tail: case ICMD_LSUB: case ICMD_LMUL: case ICMD_LDIV: - case ICMD_LREM: case ICMD_LOR: case ICMD_LAND: @@ -989,6 +1090,7 @@ icmd_lcmp_if_tail: } OP1_0ANY; case ICMD_BUILTIN2: +builtin2: if (! (curstack->flags & SAVEDVAR)) { curstack->varkind = ARGVAR; curstack->varnum = 1; @@ -1302,6 +1404,15 @@ static void show_icmd_method() } } printf("\n"); + + if (showdisassemble) { + s4ptr = (s4 *) (method->mcode + dseglen); + for (i = 0; i < block[0].mpc; i += 4, s4ptr++) { + disasscmd (*s4ptr, i); + } + printf("\n"); + } + for (b = 0; b < block_count; b++) { deadcode = block[b].flags <= BBREACHED; printf("["); @@ -1324,6 +1435,8 @@ static void show_icmd_method() case ICMD_IADDCONST: case ICMD_ISUBCONST: case ICMD_IMULCONST: + case ICMD_IREMPOW2: + case ICMD_IREM0X10001: case ICMD_IANDCONST: case ICMD_IORCONST: case ICMD_IXORCONST: @@ -1338,6 +1451,7 @@ static void show_icmd_method() case ICMD_LADDCONST: case ICMD_LSUBCONST: case ICMD_LMULCONST: + case ICMD_LREMPOW2: case ICMD_LANDCONST: case ICMD_LORCONST: case ICMD_LXORCONST: @@ -1494,5 +1608,15 @@ static void show_icmd_method() } printf("\n"); } + + if (showdisassemble) { + printf("\n"); + i = block[b].mpc; + s4ptr = (s4 *) (method->mcode + dseglen + i); + for (; i < block[b + 1].mpc; i += 4, s4ptr++) { + disasscmd (*s4ptr, i); + } + printf("\n"); + } } } -- 2.25.1