* src/vm/jit/sparc64/codegen.h: Improved overflow checking.
authorajordan <none@none>
Thu, 16 Aug 2007 22:10:43 +0000 (22:10 +0000)
committerajordan <none@none>
Thu, 16 Aug 2007 22:10:43 +0000 (22:10 +0000)
* src/vm/jit/sparc64/codegen.c (check_13bit_imm): Likewise.
(codegen_emit): Fixed ICDM_TABLESWITCH for large negative values.

src/vm/jit/sparc64/codegen.c
src/vm/jit/sparc64/codegen.h

index b136e2b62972bf6643c8bd0f14e6f0e28dc375cf..4cab71f4028cf2cb558be3af3c9da0c8bbf44e17 100644 (file)
@@ -102,11 +102,15 @@ s4 get_lopart_disp(disp)
 #ifndef NDEBUG
 bool check_13bit_imm(s8 imm)
 {
-       s4 check = imm & ~0x1fff;
-       if (check == 0) return true; /* pos imm. */
-       if (check + 0x1fff == -1) return true; /* neg imm. */
+       s4 sign = (imm >> 12) & 0x1;
+
+       if (sign == 0) {
+               if ((imm & ~0xfff) == 0) return true; /* pos imm. */
+       }
+       else
+               if ((imm & ~0xfff) + 0xfff == -1) return true; /* neg imm. */
        
-       printf("immediate out-of-bounds: %d\n", imm);
+       printf("immediate out-of-bounds: %ld\n", imm);
        return false;
 }
 #endif
@@ -2333,15 +2337,15 @@ nowperformreturn:
                        if (l == 0) {
                                M_INTMOVE(s1, REG_ITMP1);
                        }
-                       else if (l <= 4095) {
+                       else if (-l >= 4096 && -l <= 4095) {
                                M_ADD_IMM(s1, -l, REG_ITMP1);
                        }
                        else {
                                ICONST(REG_ITMP2, l);
-                               /* XXX: do I need to truncate s1 to 32-bit ? */
                                M_SUB(s1, REG_ITMP2, REG_ITMP1);
                        }
-                       i = i - l + 1;
+
+                       i = i - l + 1; /* number of targets (>0) */
 
 
                        /* range check */
index 6686a772b726c5c74793860e769ef8f9e021a406..e46299737c42277f3a3c52e83d91668c46a739e3 100644 (file)
@@ -41,9 +41,9 @@
 
 /* debug defines **************************************************************/
 #ifndef NDEBUG
-# define PASS13BIT(imm) (imm) & 0x1fff
+# define PASS13BIT(imm) ((((s4)(imm)&0x1fff)<<19)>>19)
 #else
-# define PASS13BIT(imm)
+# define PASS13BIT(imm) imm
 #endif
 
 
@@ -470,7 +470,7 @@ s4   get_lopart_disp(s4 disp);
         } \
         else { \
                DO_SETHI_PART(disp,rs,rd); \
-               M_LDX_INTERN(rd,rd,get_lopart_disp(disp)); \
+               M_LDX_INTERN(rd,rd,PASS13BIT(get_lopart_disp(disp))); \
         } \
     } while (0)
 
@@ -482,7 +482,7 @@ s4   get_lopart_disp(s4 disp);
        } \
         else { \
             DO_SETHI_PART(disp,rs,rd); \
-            M_ILD_INTERN(rd,rd,get_lopart_disp(disp)); \
+            M_ILD_INTERN(rd,rd,PASS13BIT(get_lopart_disp(disp))); \
         } \
     } while (0)
 
@@ -503,7 +503,7 @@ s4   get_lopart_disp(s4 disp);
         } \
         else { \
             DO_SETHI_PART(disp,rs,REG_ITMP3); \
-            M_STX_INTERN(rd,REG_ITMP3,get_lopart_disp(disp)); \
+            M_STX_INTERN(rd,REG_ITMP3,PASS13BIT(get_lopart_disp(disp))); \
         } \
     } while (0)
 
@@ -516,7 +516,7 @@ s4   get_lopart_disp(s4 disp);
        } \
         else { \
             DO_SETHI_PART(disp,rs,REG_ITMP3); \
-            M_IST_INTERN(rd,REG_ITMP3,get_lopart_disp(disp)); \
+            M_IST_INTERN(rd,REG_ITMP3,PASS13BIT(get_lopart_disp(disp))); \
         } \
     } while (0)