narray first check in
[cacao.git] / alpha / ngen.c
index 5babc8a4010e977e1a9fc2831fa7bc2291c7018c..69771a08159665e56a6f9889cef324d7965b679d 100644 (file)
        Authors: Andreas  Krall      EMAIL: cacao@complang.tuwien.ac.at
                 Reinhard Grafl      EMAIL: cacao@complang.tuwien.ac.at
 
-       Last Change: 1998/08/10
+       Last Change: $Id: ngen.c 132 1999-09-27 15:54:42Z chris $
 
 *******************************************************************************/
 
-
+#include "jitdef.h"   /* phil */
 
 /* *****************************************************************************
 
@@ -45,7 +45,9 @@ in the documention file: calling.doc
 
 /* additional functions and macros to generate code ***************************/
 
-#define BlockPtrOfPC(pc)        block+block_index[pc]
+/* #define BlockPtrOfPC(pc)        block+block_index[pc] */
+#define BlockPtrOfPC(pc)  ((basicblock *) iptr->target)
+
 
 #ifdef STATISTICS
 #define COUNT_SPILLS count_spills++
@@ -326,6 +328,7 @@ static void gen_mcode()
        varinfo     *var;
        basicblock  *bptr;
        instruction *iptr;
+       xtable *ex;
 
        {
        int p, pa, t, l, r;
@@ -373,14 +376,45 @@ static void gen_mcode()
        (void) dseg_adds4(exceptiontablelength);                /* ExTableSize    */
 
        /* create exception table */
-       
-       for (len = 0; len < exceptiontablelength; len++) {
-               dseg_addtarget(BlockPtrOfPC(extable[len].startpc));
-               dseg_addtarget(BlockPtrOfPC(extable[len].endpc));
-               dseg_addtarget(BlockPtrOfPC(extable[len].handlerpc));
-               (void) dseg_addaddress(extable[len].catchtype);
+
+       for (ex = extable; ex != NULL; ex = ex->down) {
+
+#ifdef LOOP_DEBUG      
+               if (ex->start != NULL)
+                       printf("adding start - %d - ", ex->start->debug_nr);
+               else {
+                       printf("PANIC - start is NULL");
+                       exit(-1);
+               }
+#endif
+
+               dseg_addtarget(ex->start);
+
+#ifdef LOOP_DEBUG                      
+               if (ex->end != NULL)
+                       printf("adding end - %d - ", ex->end->debug_nr);
+               else {
+                       printf("PANIC - end is NULL");
+                       exit(-1);
+               }
+#endif
+
+               dseg_addtarget(ex->end);
+
+#ifdef LOOP_DEBUG              
+               if (ex->handler != NULL)
+                       printf("adding handler - %d\n", ex->handler->debug_nr);
+               else {
+                       printf("PANIC - handler is NULL");
+                       exit(-1);
                }
+#endif
 
+               dseg_addtarget(ex->handler);
+          
+               (void) dseg_addaddress(ex->catchtype);
+               }
+       
        /* initialize mcode variables */
        
        mcodeptr = (s4*) mcodebase;
@@ -542,8 +576,8 @@ static void gen_mcode()
        /* end of header generation */
 
        /* walk through all basic blocks */
+       for (/* bbs = block_count, */ bptr = block; /* --bbs >= 0 */ bptr != NULL; bptr = bptr->next) {
 
-       for (bbs = block_count, bptr = block; --bbs >= 0; bptr++) {
                bptr -> mpc = (int)((u1*) mcodeptr - mcodebase);
 
                if (bptr->flags >= BBREACHED) {
@@ -600,7 +634,7 @@ static void gen_mcode()
                        }
 
                /* walk through all instructions */
-
+               
                src = bptr->instack;
                len = bptr->icount;
                for (iptr = bptr->iinstr;
@@ -1848,13 +1882,22 @@ static void gen_mcode()
 
                /* memory operations **************************************************/
 
-#define gen_bound_check \
+                       /* #define gen_bound_check \
                        if (checkbounds) {\
                                M_ILD(REG_ITMP3, s1, OFFSET(java_arrayheader, size));\
                                M_CMPULT(s2, REG_ITMP3, REG_ITMP3);\
                                M_BEQZ(REG_ITMP3, 0);\
                                mcode_addxboundrefs(mcodeptr);\
                                }
+                       */
+
+#define gen_bound_check \
+            if (checkbounds) { \
+                               M_ILD(REG_ITMP3, s1, OFFSET(java_arrayheader, size));\
+                               M_CMPULT(s2, REG_ITMP3, REG_ITMP3);\
+                               M_BEQZ(REG_ITMP3, 0);\
+                               mcode_addxboundrefs(mcodeptr); \
+                }
 
                case ICMD_ARRAYLENGTH: /* ..., arrayref  ==> ..., length              */
 
@@ -1870,8 +1913,10 @@ static void gen_mcode()
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
                        d = reg_of_var(iptr->dst, REG_ITMP3);
-                       gen_nullptr_check(s1);
-                       gen_bound_check;
+                       if (iptr->op1 == 0) {
+                               gen_nullptr_check(s1);
+                               gen_bound_check;
+                               }
                        M_SAADDQ(s2, s1, REG_ITMP1);
                        M_ALD( d, REG_ITMP1, OFFSET(java_objectarray, data[0]));
                        store_reg_to_var_int(iptr->dst, d);
@@ -1882,8 +1927,10 @@ static void gen_mcode()
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
                        d = reg_of_var(iptr->dst, REG_ITMP3);
-                       gen_nullptr_check(s1);
-                       gen_bound_check;
+                       if (iptr->op1 == 0) {
+                               gen_nullptr_check(s1);
+                               gen_bound_check;
+                               }
                        M_S8ADDQ(s2, s1, REG_ITMP1);
                        M_LLD(d, REG_ITMP1, OFFSET(java_longarray, data[0]));
                        store_reg_to_var_int(iptr->dst, d);
@@ -1894,8 +1941,11 @@ static void gen_mcode()
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
                        d = reg_of_var(iptr->dst, REG_ITMP3);
-                       gen_nullptr_check(s1);
-                       gen_bound_check;
+                       if (iptr->op1 == 0) {
+                               gen_nullptr_check(s1);
+                               gen_bound_check;
+                               }
+                 
                        M_S4ADDQ(s2, s1, REG_ITMP1);
                        M_ILD(d, REG_ITMP1, OFFSET(java_intarray, data[0]));
                        store_reg_to_var_int(iptr->dst, d);
@@ -1906,8 +1956,10 @@ static void gen_mcode()
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
                        d = reg_of_var(iptr->dst, REG_FTMP3);
-                       gen_nullptr_check(s1);
-                       gen_bound_check;
+                       if (iptr->op1 == 0) {
+                               gen_nullptr_check(s1);
+                               gen_bound_check;
+                               }
                        M_S4ADDQ(s2, s1, REG_ITMP1);
                        M_FLD(d, REG_ITMP1, OFFSET(java_floatarray, data[0]));
                        store_reg_to_var_flt(iptr->dst, d);
@@ -1918,8 +1970,10 @@ static void gen_mcode()
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
                        d = reg_of_var(iptr->dst, REG_FTMP3);
-                       gen_nullptr_check(s1);
-                       gen_bound_check;
+                       if (iptr->op1 == 0) {
+                               gen_nullptr_check(s1);
+                               gen_bound_check;
+                               }
                        M_S8ADDQ(s2, s1, REG_ITMP1);
                        M_DLD(d, REG_ITMP1, OFFSET(java_doublearray, data[0]));
                        store_reg_to_var_flt(iptr->dst, d);
@@ -1930,8 +1984,10 @@ static void gen_mcode()
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
                        d = reg_of_var(iptr->dst, REG_ITMP3);
-                       gen_nullptr_check(s1);
-                       gen_bound_check;
+                       if (iptr->op1 == 0) {
+                               gen_nullptr_check(s1);
+                               gen_bound_check;
+                               }
                        if (has_ext_instr_set) {
                                M_LADD(s2, s1, REG_ITMP1);
                                M_LADD(s2, REG_ITMP1, REG_ITMP1);
@@ -1952,8 +2008,10 @@ static void gen_mcode()
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
                        d = reg_of_var(iptr->dst, REG_ITMP3);
-                       gen_nullptr_check(s1);
-                       gen_bound_check;
+                       if (iptr->op1 == 0) {
+                               gen_nullptr_check(s1);
+                               gen_bound_check;
+                               }
                        if (has_ext_instr_set) {
                                M_LADD(s2, s1, REG_ITMP1);
                                M_LADD(s2, REG_ITMP1, REG_ITMP1);
@@ -1976,8 +2034,10 @@ static void gen_mcode()
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
                        d = reg_of_var(iptr->dst, REG_ITMP3);
-                       gen_nullptr_check(s1);
-                       gen_bound_check;
+                       if (iptr->op1 == 0) {
+                               gen_nullptr_check(s1);
+                               gen_bound_check;
+                               }
                        if (has_ext_instr_set) {
                                M_LADD   (s2, s1, REG_ITMP1);
                                M_BLDU   (d, REG_ITMP1, OFFSET (java_shortarray, data[0]));
@@ -1998,8 +2058,10 @@ static void gen_mcode()
 
                        var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
                        var_to_reg_int(s2, src->prev, REG_ITMP2);
-                       gen_nullptr_check(s1);
-                       gen_bound_check;
+                       if (iptr->op1 == 0) {
+                               gen_nullptr_check(s1);
+                               gen_bound_check;
+                               }
                        var_to_reg_int(s3, src, REG_ITMP3);
                        M_SAADDQ(s2, s1, REG_ITMP1);
                        M_AST   (s3, REG_ITMP1, OFFSET(java_objectarray, data[0]));
@@ -2009,8 +2071,10 @@ static void gen_mcode()
 
                        var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
                        var_to_reg_int(s2, src->prev, REG_ITMP2);
-                       gen_nullptr_check(s1);
-                       gen_bound_check;
+                       if (iptr->op1 == 0) {
+                               gen_nullptr_check(s1);
+                               gen_bound_check;
+                               }
                        var_to_reg_int(s3, src, REG_ITMP3);
                        M_S8ADDQ(s2, s1, REG_ITMP1);
                        M_LST   (s3, REG_ITMP1, OFFSET(java_longarray, data[0]));
@@ -2020,8 +2084,11 @@ static void gen_mcode()
 
                        var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
                        var_to_reg_int(s2, src->prev, REG_ITMP2);
-                       gen_nullptr_check(s1);
-                       gen_bound_check;
+                       if (iptr->op1 == 0) {
+                               gen_nullptr_check(s1);
+                               gen_bound_check;
+                               }
+
                        var_to_reg_int(s3, src, REG_ITMP3);
                        M_S4ADDQ(s2, s1, REG_ITMP1);
                        M_IST   (s3, REG_ITMP1, OFFSET(java_intarray, data[0]));
@@ -2031,8 +2098,10 @@ static void gen_mcode()
 
                        var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
                        var_to_reg_int(s2, src->prev, REG_ITMP2);
-                       gen_nullptr_check(s1);
-                       gen_bound_check;
+                       if (iptr->op1 == 0) {
+                               gen_nullptr_check(s1);
+                               gen_bound_check;
+                               }
                        var_to_reg_flt(s3, src, REG_FTMP3);
                        M_S4ADDQ(s2, s1, REG_ITMP1);
                        M_FST   (s3, REG_ITMP1, OFFSET(java_floatarray, data[0]));
@@ -2042,8 +2111,10 @@ static void gen_mcode()
 
                        var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
                        var_to_reg_int(s2, src->prev, REG_ITMP2);
-                       gen_nullptr_check(s1);
-                       gen_bound_check;
+                       if (iptr->op1 == 0) {
+                               gen_nullptr_check(s1);
+                               gen_bound_check;
+                               }
                        var_to_reg_flt(s3, src, REG_FTMP3);
                        M_S8ADDQ(s2, s1, REG_ITMP1);
                        M_DST   (s3, REG_ITMP1, OFFSET(java_doublearray, data[0]));
@@ -2053,8 +2124,10 @@ static void gen_mcode()
 
                        var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
                        var_to_reg_int(s2, src->prev, REG_ITMP2);
-                       gen_nullptr_check(s1);
-                       gen_bound_check;
+                       if (iptr->op1 == 0) {
+                               gen_nullptr_check(s1);
+                               gen_bound_check;
+                               }
                        var_to_reg_int(s3, src, REG_ITMP3);
                        if (has_ext_instr_set) {
                                M_LADD(s2, s1, REG_ITMP1);
@@ -2077,8 +2150,10 @@ static void gen_mcode()
 
                        var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
                        var_to_reg_int(s2, src->prev, REG_ITMP2);
-                       gen_nullptr_check(s1);
-                       gen_bound_check;
+                       if (iptr->op1 == 0) {
+                               gen_nullptr_check(s1);
+                               gen_bound_check;
+                               }
                        var_to_reg_int(s3, src, REG_ITMP3);
                        if (has_ext_instr_set) {
                                M_LADD(s2, s1, REG_ITMP1);
@@ -2101,8 +2176,10 @@ static void gen_mcode()
 
                        var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
                        var_to_reg_int(s2, src->prev, REG_ITMP2);
-                       gen_nullptr_check(s1);
-                       gen_bound_check;
+                       if (iptr->op1 == 0) {
+                               gen_nullptr_check(s1);
+                               gen_bound_check;
+                               }
                        var_to_reg_int(s3, src, REG_ITMP3);
                        if (has_ext_instr_set) {
                                M_LADD(s2, s1, REG_ITMP1);
@@ -2639,14 +2716,14 @@ static void gen_mcode()
 
                        var_to_reg_int(s1, src, REG_ITMP1);
                        d = reg_of_var(iptr->dst, REG_ITMP3);
-                       a = iptr->val.i;
+                       s3 = iptr->val.i;
                        if (iptr[1].opc == ICMD_ELSE_ICONST) {
-                               if ((a == 1) && (iptr[1].val.i == 0)) {
+                               if ((s3 == 1) && (iptr[1].val.i == 0)) {
                                        M_CMPEQ(s1, REG_ZERO, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
                                        }
-                               if ((a == 0) && (iptr[1].val.i == 1)) {
+                               if ((s3 == 0) && (iptr[1].val.i == 1)) {
                                        M_CMPEQ(s1, REG_ZERO, d);
                                        M_XOR_IMM(d, 1, d);
                                        store_reg_to_var_int(iptr->dst, d);
@@ -2658,11 +2735,11 @@ static void gen_mcode()
                                        }
                                ICONST(d, iptr[1].val.i);
                                }
-                       if ((a >= 0) && (a <= 255)) {
-                               M_CMOVEQ_IMM(s1, a, d);
+                       if ((s3 >= 0) && (s3 <= 255)) {
+                               M_CMOVEQ_IMM(s1, s3, d);
                                }
                        else {
-                               ICONST(REG_ITMP2, a);
+                               ICONST(REG_ITMP2, s3);
                                M_CMOVEQ(s1, REG_ITMP2, d);
                                }
                        store_reg_to_var_int(iptr->dst, d);
@@ -2673,14 +2750,14 @@ static void gen_mcode()
 
                        var_to_reg_int(s1, src, REG_ITMP1);
                        d = reg_of_var(iptr->dst, REG_ITMP3);
-                       a = iptr->val.i;
+                       s3 = iptr->val.i;
                        if (iptr[1].opc == ICMD_ELSE_ICONST) {
-                               if ((a == 0) && (iptr[1].val.i == 1)) {
+                               if ((s3 == 0) && (iptr[1].val.i == 1)) {
                                        M_CMPEQ(s1, REG_ZERO, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
                                        }
-                               if ((a == 1) && (iptr[1].val.i == 0)) {
+                               if ((s3 == 1) && (iptr[1].val.i == 0)) {
                                        M_CMPEQ(s1, REG_ZERO, d);
                                        M_XOR_IMM(d, 1, d);
                                        store_reg_to_var_int(iptr->dst, d);
@@ -2692,11 +2769,11 @@ static void gen_mcode()
                                        }
                                ICONST(d, iptr[1].val.i);
                                }
-                       if ((a >= 0) && (a <= 255)) {
-                               M_CMOVNE_IMM(s1, a, d);
+                       if ((s3 >= 0) && (s3 <= 255)) {
+                               M_CMOVNE_IMM(s1, s3, d);
                                }
                        else {
-                               ICONST(REG_ITMP2, a);
+                               ICONST(REG_ITMP2, s3);
                                M_CMOVNE(s1, REG_ITMP2, d);
                                }
                        store_reg_to_var_int(iptr->dst, d);
@@ -2707,14 +2784,14 @@ static void gen_mcode()
 
                        var_to_reg_int(s1, src, REG_ITMP1);
                        d = reg_of_var(iptr->dst, REG_ITMP3);
-                       a = iptr->val.i;
+                       s3 = iptr->val.i;
                        if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
-                               if ((a == 1) && (iptr[1].val.i == 0)) {
+                               if ((s3 == 1) && (iptr[1].val.i == 0)) {
                                        M_CMPLT(s1, REG_ZERO, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
                                        }
-                               if ((a == 0) && (iptr[1].val.i == 1)) {
+                               if ((s3 == 0) && (iptr[1].val.i == 1)) {
                                        M_CMPLE(REG_ZERO, s1, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
@@ -2725,11 +2802,11 @@ static void gen_mcode()
                                        }
                                ICONST(d, iptr[1].val.i);
                                }
-                       if ((a >= 0) && (a <= 255)) {
-                               M_CMOVLT_IMM(s1, a, d);
+                       if ((s3 >= 0) && (s3 <= 255)) {
+                               M_CMOVLT_IMM(s1, s3, d);
                                }
                        else {
-                               ICONST(REG_ITMP2, a);
+                               ICONST(REG_ITMP2, s3);
                                M_CMOVLT(s1, REG_ITMP2, d);
                                }
                        store_reg_to_var_int(iptr->dst, d);
@@ -2740,14 +2817,14 @@ static void gen_mcode()
 
                        var_to_reg_int(s1, src, REG_ITMP1);
                        d = reg_of_var(iptr->dst, REG_ITMP3);
-                       a = iptr->val.i;
+                       s3 = iptr->val.i;
                        if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
-                               if ((a == 1) && (iptr[1].val.i == 0)) {
+                               if ((s3 == 1) && (iptr[1].val.i == 0)) {
                                        M_CMPLE(REG_ZERO, s1, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
                                        }
-                               if ((a == 0) && (iptr[1].val.i == 1)) {
+                               if ((s3 == 0) && (iptr[1].val.i == 1)) {
                                        M_CMPLT(s1, REG_ZERO, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
@@ -2758,11 +2835,11 @@ static void gen_mcode()
                                        }
                                ICONST(d, iptr[1].val.i);
                                }
-                       if ((a >= 0) && (a <= 255)) {
-                               M_CMOVGE_IMM(s1, a, d);
+                       if ((s3 >= 0) && (s3 <= 255)) {
+                               M_CMOVGE_IMM(s1, s3, d);
                                }
                        else {
-                               ICONST(REG_ITMP2, a);
+                               ICONST(REG_ITMP2, s3);
                                M_CMOVGE(s1, REG_ITMP2, d);
                                }
                        store_reg_to_var_int(iptr->dst, d);
@@ -2773,14 +2850,14 @@ static void gen_mcode()
 
                        var_to_reg_int(s1, src, REG_ITMP1);
                        d = reg_of_var(iptr->dst, REG_ITMP3);
-                       a = iptr->val.i;
+                       s3 = iptr->val.i;
                        if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
-                               if ((a == 1) && (iptr[1].val.i == 0)) {
+                               if ((s3 == 1) && (iptr[1].val.i == 0)) {
                                        M_CMPLT(REG_ZERO, s1, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
                                        }
-                               if ((a == 0) && (iptr[1].val.i == 1)) {
+                               if ((s3 == 0) && (iptr[1].val.i == 1)) {
                                        M_CMPLE(s1, REG_ZERO, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
@@ -2791,11 +2868,11 @@ static void gen_mcode()
                                        }
                                ICONST(d, iptr[1].val.i);
                                }
-                       if ((a >= 0) && (a <= 255)) {
-                               M_CMOVGT_IMM(s1, a, d);
+                       if ((s3 >= 0) && (s3 <= 255)) {
+                               M_CMOVGT_IMM(s1, s3, d);
                                }
                        else {
-                               ICONST(REG_ITMP2, a);
+                               ICONST(REG_ITMP2, s3);
                                M_CMOVGT(s1, REG_ITMP2, d);
                                }
                        store_reg_to_var_int(iptr->dst, d);
@@ -2806,14 +2883,14 @@ static void gen_mcode()
 
                        var_to_reg_int(s1, src, REG_ITMP1);
                        d = reg_of_var(iptr->dst, REG_ITMP3);
-                       a = iptr->val.i;
+                       s3 = iptr->val.i;
                        if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
-                               if ((a == 1) && (iptr[1].val.i == 0)) {
+                               if ((s3 == 1) && (iptr[1].val.i == 0)) {
                                        M_CMPLE(s1, REG_ZERO, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
                                        }
-                               if ((a == 0) && (iptr[1].val.i == 1)) {
+                               if ((s3 == 0) && (iptr[1].val.i == 1)) {
                                        M_CMPLT(REG_ZERO, s1, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
@@ -2824,11 +2901,11 @@ static void gen_mcode()
                                        }
                                ICONST(d, iptr[1].val.i);
                                }
-                       if ((a >= 0) && (a <= 255)) {
-                               M_CMOVLE_IMM(s1, a, d);
+                       if ((s3 >= 0) && (s3 <= 255)) {
+                               M_CMOVLE_IMM(s1, s3, d);
                                }
                        else {
-                               ICONST(REG_ITMP2, a);
+                               ICONST(REG_ITMP2, s3);
                                M_CMOVLE(s1, REG_ITMP2, d);
                                }
                        store_reg_to_var_int(iptr->dst, d);
@@ -2940,6 +3017,9 @@ nowperformreturn:
                case ICMD_TABLESWITCH:  /* ..., index ==> ...                         */
                        {
                        s4 i, l, *s4ptr;
+                       void **tptr;
+
+                       tptr = (void **) iptr->target;
 
                        s4ptr = iptr->val.a;
                        l = s4ptr[1];                          /* low     */
@@ -2948,8 +3028,13 @@ nowperformreturn:
                        var_to_reg_int(s1, src, REG_ITMP1);
                        if (l == 0)
                                {M_INTMOVE(s1, REG_ITMP1);}
-                       else
+                       else if (l <= 32768) {
                                M_LDA(REG_ITMP1, s1, -l);
+                               }
+                       else {
+                               ICONST(REG_ITMP2, l);
+                               M_ISUB(s1, REG_ITMP2, REG_ITMP1);
+                               }
                        i = i - l + 1;
 
                        /* range check */
@@ -2961,13 +3046,20 @@ nowperformreturn:
                                M_CMPULE(REG_ITMP1, REG_ITMP2, REG_ITMP2);
                                }
                        M_BEQZ(REG_ITMP2, 0);
-                       mcode_addreference(BlockPtrOfPC(s4ptr[0]), mcodeptr);
+
+
+                       /* mcode_addreference(BlockPtrOfPC(s4ptr[0]), mcodeptr); */
+                       mcode_addreference((basicblock *) tptr[0], mcodeptr);
 
                        /* build jump table top down and use address of lowest entry */
 
-                       s4ptr += 3 + i;
+                       /* s4ptr += 3 + i; */
+                       tptr += i;
+
                        while (--i >= 0) {
-                               dseg_addtarget(BlockPtrOfPC(*--s4ptr));
+                               /* dseg_addtarget(BlockPtrOfPC(*--s4ptr)); */
+                               dseg_addtarget((basicblock *) tptr[0]); 
+                               --tptr;
                                }
                        }
 
@@ -2983,6 +3075,9 @@ nowperformreturn:
                case ICMD_LOOKUPSWITCH: /* ..., key ==> ...                           */
                        {
                        s4 i, l, val, *s4ptr;
+                       void **tptr;
+
+                       tptr = (void **) iptr->target;
 
                        s4ptr = iptr->val.a;
                        l = s4ptr[0];                          /* default  */
@@ -2992,6 +3087,8 @@ nowperformreturn:
                        var_to_reg_int(s1, src, REG_ITMP1);
                        while (--i >= 0) {
                                s4ptr += 2;
+                               ++tptr;
+
                                val = s4ptr[0];
                                if ((val >= 0) && (val <= 255)) {
                                        M_CMPEQ_IMM(s1, val, REG_ITMP2);
@@ -3007,11 +3104,16 @@ nowperformreturn:
                                        M_CMPEQ(s1, REG_ITMP2, REG_ITMP2);
                                        }
                                M_BNEZ(REG_ITMP2, 0);
-                               mcode_addreference(BlockPtrOfPC(s4ptr[1]), mcodeptr);
+                               /* mcode_addreference(BlockPtrOfPC(s4ptr[1]), mcodeptr); */
+                               mcode_addreference((basicblock *) tptr[0], mcodeptr); 
                                }
 
                        M_BR(0);
-                       mcode_addreference(BlockPtrOfPC(l), mcodeptr);
+                       /* mcode_addreference(BlockPtrOfPC(l), mcodeptr); */
+                       
+                       tptr = (void **) iptr->target;
+                       mcode_addreference((basicblock *) tptr[0], mcodeptr);
+
                        ALIGNCODENOP;
                        break;
                        }
@@ -3318,7 +3420,7 @@ makeactualcall:
 
                        /* a0 = dimension count */
 
-                       M_LDA(argintregs[0], REG_ZERO, iptr->op1);
+                       ICONST(argintregs[0], iptr->op1);
 
                        /* a1 = arraydescriptor */
 
@@ -3340,7 +3442,7 @@ makeactualcall:
                                while (ml < -32768) {ml += 65536; mh--;}
                                M_LDA(REG_PV, REG_RA, ml);
                                M_LDAH(REG_PV, REG_PV, mh);
-                               }
+                           }
                        s1 = reg_of_var(iptr->dst, REG_RESULT);
                        M_INTMOVE(REG_RESULT, s1);
                        store_reg_to_var_int(iptr->dst, s1);
@@ -3349,9 +3451,13 @@ makeactualcall:
 
                default: sprintf (logtext, "Unknown pseudo command: %d", iptr->opc);
                         error();
+       
+   
+
        } /* switch */
+               
        } /* for instruction */
-
+               
        /* copy values to interface registers */
 
        src = bptr->outstack;
@@ -3385,7 +3491,7 @@ makeactualcall:
        } /* if (bptr -> flags >= BBREACHED) */
        } /* for basic block */
 
-       bptr -> mpc = (int)((u1*) mcodeptr - mcodebase);
+       /* bptr -> mpc = (int)((u1*) mcodeptr - mcodebase); */
 
        {
        /* generate bound check stubs */
@@ -3399,12 +3505,13 @@ makeactualcall:
                        continue;
                        }
 
+
                gen_resolvebranch((u1*) mcodebase + xboundrefs->branchpos, 
                                  xboundrefs->branchpos, (u1*) mcodeptr - mcodebase);
 
                MCODECHECK(8);
 
-               M_LDA(REG_ITMP2_XPC, REG_PV, xboundrefs->branchpos);
+               M_LDA(REG_ITMP2_XPC, REG_PV, xboundrefs->branchpos - 4);
 
                if (xcodeptr != NULL) {
                        M_BR((xcodeptr-mcodeptr)-1);
@@ -3438,7 +3545,7 @@ makeactualcall:
 
                MCODECHECK(8);
 
-               M_LDA(REG_ITMP2_XPC, REG_PV, xcheckarefs->branchpos);
+               M_LDA(REG_ITMP2_XPC, REG_PV, xcheckarefs->branchpos - 4);
 
                if (xcodeptr != NULL) {
                        M_BR((xcodeptr-mcodeptr)-1);
@@ -3472,7 +3579,7 @@ makeactualcall:
 
                MCODECHECK(8);
 
-               M_LDA(REG_ITMP2_XPC, REG_PV, xcastrefs->branchpos);
+               M_LDA(REG_ITMP2_XPC, REG_PV, xcastrefs->branchpos - 4);
 
                if (xcodeptr != NULL) {
                        M_BR((xcodeptr-mcodeptr)-1);