This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Evil reduction in include/i386-signal.h


Divide overflows now fixed: no need to divide subroutine on i386.
This leaves the way open to do the same thing on other architectures,
so we can junk the divide subroutine altogether.

The divide overflow testcase is now much more thorough and should
catch the things I missed before.

Andrew.


2001-07-06  Andrew Haley  <aph@cambridge.redhat.com>

        * include/i386-signal.h: Don't do anything with unsigned divide
        overflow except throw an exception.

2001-07-06  Andrew Haley  <aph@cambridge.redhat.com>

        * libjava.lang/Divide_1.java: Add many more test cases.
        * libjava.lang/Divide_1.out: Likewise.

Index: include/i386-signal.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/i386-signal.h,v
retrieving revision 1.11
diff -p -2 -c -r1.11 i386-signal.h
*** i386-signal.h	2001/05/29 17:50:50	1.11
--- i386-signal.h	2001/07/06 16:13:50
*************** do									\
*** 89,107 ****
  	  return;							\
  	}								\
-       else if (((_modrm >> 3) & 7) == 6) /* Unsigned divide */		\
- 	{								\
- 	  /* We assume that unsigned divisions are in library code, so	\
- 	   * we throw one level down the stack, which was hopefully	\
- 	   * the place that called the library routine.  This will	\
- 	   * break if the library is ever compiled with			\
- 	   * -fomit-frame-pointer, but at least this way we've got a	\
- 	   * good chance of finding the exception handler. */		\
- 									\
- 	  _eip = (unsigned char *)_ebp[1];				\
- 	  _ebp = (unsigned long *)_ebp[0];				\
- 									\
- 	  asm volatile ("mov %0, (%%ebp); mov %1, 4(%%ebp)"		\
- 			: : "r"(_ebp), "r"(_eip));			\
- 	}								\
        else								\
  	{								\
--- 89,92 ----
Index: testsuite/libjava.lang/Divide_1.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/testsuite/libjava.lang/Divide_1.java,v
retrieving revision 1.1
diff -p -2 -c -r1.1 Divide_1.java
*** Divide_1.java	1999/05/20 08:26:55	1.1
--- Divide_1.java	2001/07/06 16:13:50
*************** public class Divide_1
*** 5,9 ****
    static int zero = Integer.parseInt ("0");
  
!   void probe ()
    {
       try {
--- 5,9 ----
    static int zero = Integer.parseInt ("0");
  
!   void probe_1 ()
    {
       try {
*************** public class Divide_1
*** 99,105 ****
      }
    }
   
!   public static void main (String[] args) {
!     new Divide_1 ().probe ();
    }
  }
--- 99,203 ----
      }
    }
+ 
+   void probe_2 ()
+   {
+     try {
+       int a = -0x80000000;
+       int c = a/b;
+       System.out.println (c);
+     } catch (Exception _) {
+       System.out.println (_);
+     }
+   
+     try {
+       int a = -0x80000000;
+       int c = a/-1;
+       System.out.println (c);
+     } catch (Exception _) {
+       System.out.println (_);
+     }
+  
+     try {
+       int a = -0x80000000;
+       int c = a%b;
+       System.out.println (c);
+     } catch (Exception _) {
+       System.out.println (_);
+     }
+  
+     try {
+       int a = -0x80000000;
+       int c = a%b1;
+       System.out.println (c);
+     } catch (Exception _) {
+       System.out.println (_);
+     }
+  
+     try {
+       int a = -0x80000000;
+       int c = a%-1;
+       System.out.println (c);
+     } catch (Exception _) {
+       System.out.println (_);
+     }
+  
+     try {
+       int a = 0x8000;
+       int b = 0;
+       int c = a/b;
+       System.out.println (c);
+     } catch (Exception _) {
+       System.out.println (_);
+     }
+  
+     try {
+       int a = 0x8000;
+       int b = 0;
+       int c = a%b;
+       System.out.println (c);
+     } catch (Exception _) {
+       System.out.println (_);
+     }
+  
+     try {
+       long a = -0x7fffffffffffffffL - 1;
+       long c = a/b;
+       System.out.println (c);
+     } catch (Exception _) {
+       System.out.println (_);
+     }
+  
+     try {
+       long a = -0x7fffffffffffffffL - 1;
+       long c = a%b;
+       System.out.println (c);
+     } catch (Exception _) {
+       System.out.println (_);
+     }
+ 
+     try {
+       long a = 0x8000;
+       long b = 0;
+       long c = a/b;
+       System.out.println (c);
+     } catch (Exception _) {
+       System.out.println (_);
+     }
+  
+     try {
+       long a = 0x8000;
+       long b = 0;
+       long c = a%b;
+       System.out.println (c);
+     } catch (Exception _) {
+       System.out.println (_);
+     }
+   }
   
!   public static void main (String[] args) 
!   {
!     Divide_1 d = new Divide_1 ();
!     d.probe_1 ();
!     d.probe_2 ();
    }
  }
Index: testsuite/libjava.lang/Divide_1.out
===================================================================
RCS file: /cvs/gcc/gcc/libjava/testsuite/libjava.lang/Divide_1.out,v
retrieving revision 1.1
diff -p -2 -c -r1.1 Divide_1.out
*** Divide_1.out	1999/05/20 08:26:55	1.1
--- Divide_1.out	2001/07/06 16:13:50
*************** java.lang.ArithmeticException: / by zero
*** 10,11 ****
--- 10,22 ----
  java.lang.ArithmeticException: / by zero
  java.lang.ArithmeticException: / by zero
+ -2147483648
+ -2147483648
+ 0
+ 0
+ 0
+ java.lang.ArithmeticException: / by zero
+ java.lang.ArithmeticException: / by zero
+ -9223372036854775808
+ 0
+ java.lang.ArithmeticException: / by zero
+ java.lang.ArithmeticException: / by zero


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]