This is the mail archive of the
java-discuss@sourceware.cygnus.com
mailing list for the Java project.
Re: [PATCH] Java: expand divide, expand conversions
- To: java-discuss@sourceware.cygnus.com
- Subject: Re: [PATCH] Java: expand divide, expand conversions
- From: Andrew Haley <aph@pasanda.cygnus.co.uk>
- Date: 19 Jul 1999 17:08:17 -0000
These are support routines for the previous compiler patch.
Andrew.
1999-07-19 Andrew Haley <aph@cygnus.com>
* prims.cc (JvRunMain): Always initialize arithexception.
(_Jv_divI): New function.
(_Jv_remI): New function.
(_Jv_divJ): New function.
(_Jv_remI): New function.
* include/jvm.h: Add these new functions.
Makefile.am: add DIVIDESPEC.
aclocal.m4: ditto.
configure.host: set DIVIDESPEC.
libgcj.spec.in: pass DIVIDESPEC to compiler.
Index: Makefile.am
===================================================================
RCS file: /cvs/java/libgcj/libjava/Makefile.am,v
retrieving revision 1.24
diff -p -2 -c -r1.24 Makefile.am
*** Makefile.am 1999/06/21 13:03:44 1.24
--- Makefile.am 1999/07/19 17:04:25
*************** INCLUDES = -Iinclude -I$(top_srcdir)/inc
*** 81,84 ****
--- 81,86 ----
$(EH_COMMON_INCLUDE) $(ZINCS)
+ DIVIDESPEC = @DIVIDESPEC@
+
## ################################################################
Index: aclocal.m4
===================================================================
RCS file: /cvs/java/libgcj/libjava/aclocal.m4,v
retrieving revision 1.4
diff -p -2 -c -r1.4 aclocal.m4
*** aclocal.m4 1999/05/19 12:55:13 1.4
--- aclocal.m4 1999/07/19 17:04:26
*************** AC_SUBST(LIBGCJ_CFLAGS)
*** 168,171 ****
--- 168,174 ----
AC_SUBST(LIBGCJ_CXXFLAGS)
AC_SUBST(LIBGCJ_JAVAFLAGS)
+
+ AC_SUBST(DIVIDESPEC)
+
])dnl
Index: configure.host
===================================================================
RCS file: /cvs/java/libgcj/libjava/configure.host,v
retrieving revision 1.1.1.1
diff -p -2 -c -r1.1.1.1 configure.host
*** configure.host 1999/04/07 14:52:32 1.1.1.1
--- configure.host 1999/07/19 17:04:26
*************** AM_RUNTESTFLAGS=
*** 44,55 ****
echo "$target"
case "${host}" in
mips-tx39-*|mipstx39-unknown-*)
libgcj_flags="${libgcj_flags} -G 0"
LDFLAGS="$LDFLAGS -Tjmr3904dram.ld"
! AM_RUNTESTFLAGS="--target_board=jmr3904-sim"
;;
i686-*|i586-*)
libgcj_flags="${libgcj_flags} -ffloat-store"
;;
*)
--- 44,58 ----
echo "$target"
+ DIVIDESPEC=-fuse-divide-subroutine
+
case "${host}" in
mips-tx39-*|mipstx39-unknown-*)
libgcj_flags="${libgcj_flags} -G 0"
LDFLAGS="$LDFLAGS -Tjmr3904dram.ld"
! AM_RUNTESTFLAGS="--target_board=jmr3904-sim"
;;
i686-*|i586-*)
libgcj_flags="${libgcj_flags} -ffloat-store"
+ DIVIDESPEC=-fno-use-divide-subroutine
;;
*)
Index: libgcj.spec.in
===================================================================
RCS file: /cvs/java/libgcj/libjava/libgcj.spec.in,v
retrieving revision 1.2
diff -p -2 -c -r1.2 libgcj.spec.in
*** libgcj.spec.in 1999/05/11 13:03:47 1.2
--- libgcj.spec.in 1999/07/19 17:04:26
***************
*** 6,7 ****
--- 6,10 ----
%rename lib liborig
*lib: -lgcj -lm @GCSPEC@ @THREADSPEC@ @ZLIBSPEC@ @SYSTEMSPEC@ %(liborig)
+
+ %rename cc1 cc1orig
+ *cc1: @DIVIDESPEC@ %(cc1orig)
Index: prims.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/prims.cc,v
retrieving revision 1.5
diff -p -2 -c -r1.5 prims.cc
*** prims.cc 1999/05/20 08:26:51 1.5
--- prims.cc 1999/07/19 17:04:26
*************** SIGNAL_HANDLER (catch_segv)
*** 65,70 ****
#endif
- #ifdef HANDLE_FPE
static java::lang::ArithmeticException *arithexception;
SIGNAL_HANDLER (catch_fpe)
{
--- 65,71 ----
#endif
static java::lang::ArithmeticException *arithexception;
+
+ #ifdef HANDLE_FPE
SIGNAL_HANDLER (catch_fpe)
{
*************** JvRunMain (jclass klass, int argc, const
*** 575,579 ****
--- 576,585 ----
{
INIT_SEGV;
+ #ifdef HANDLE_FPE
INIT_FPE;
+ #else
+ arithexception = new java::lang::ArithmeticException
+ (JvNewStringLatin1 ("/ by zero"));
+ #endif
no_memory = new java::lang::OutOfMemoryError;
*************** _Jv_Free (void* ptr)
*** 611,612 ****
--- 617,674 ----
return free (ptr);
}
+
+
+
+ // In theory, these routines can be #ifdef'd away on machines which
+ // support divide overflow signals. However, we never know if some
+ // code might have been compiled with "-fuse-divide-subroutine", so we
+ // always include them in libgcj.
+
+ jint
+ _Jv_divI (jint dividend, jint divisor)
+ {
+ if (divisor == 0)
+ _Jv_Throw (arithexception);
+
+ if (dividend == 0x80000000L && divisor == -1)
+ return dividend;
+
+ return dividend / divisor;
+ }
+
+ jint
+ _Jv_remI (jint dividend, jint divisor)
+ {
+ if (divisor == 0)
+ _Jv_Throw (arithexception);
+
+ if (dividend == 0x80000000L && divisor == -1)
+ return 0;
+
+ return dividend % divisor;
+ }
+
+ jlong
+ _Jv_divJ (jlong dividend, jlong divisor)
+ {
+ if (divisor == 0)
+ _Jv_Throw (arithexception);
+
+ if (dividend == 0x8000000000000000LL && divisor == -1)
+ return dividend;
+
+ return dividend / divisor;
+ }
+
+ jlong
+ _Jv_remJ (jlong dividend, jlong divisor)
+ {
+ if (divisor == 0)
+ _Jv_Throw (arithexception);
+
+ if (dividend == 0x8000000000000000LL && divisor == -1)
+ return 0;
+
+ return dividend % divisor;
+ }
+
Index: include/jvm.h
===================================================================
RCS file: /cvs/java/libgcj/libjava/include/jvm.h,v
retrieving revision 1.1.1.1
diff -p -2 -c -r1.1.1.1 jvm.h
*** jvm.h 1999/04/07 14:52:35 1.1.1.1
--- jvm.h 1999/07/19 17:04:26
*************** extern jclass _Jv_FindClassFromSignature
*** 99,101 ****
--- 99,110 ----
extern jobject _Jv_NewMultiArray (jclass, jint ndims, jint* dims);
+ /* Checked divide subroutines. */
+ extern "C"
+ {
+ jint _Jv_divI (jint, jint);
+ jint _Jv_remI (jint, jint);
+ jlong _Jv_divJ (jlong, jlong);
+ jlong _Jv_remJ (jlong, jlong);
+ }
+
#endif /* __JAVA_JVM_H__ */
Index: testsuite/lib/libjava.exp
===================================================================
RCS file: /cvs/java/libgcj/libjava/testsuite/lib/libjava.exp,v
retrieving revision 1.10
diff -p -2 -c -r1.10 libjava.exp
*** libjava.exp 1999/07/15 09:14:20 1.10
--- libjava.exp 1999/07/19 17:04:26
*************** proc test_libjava_from_source { options
*** 279,282 ****
--- 279,285 ----
}
}
+
+ # Use exact-fp for pedantic Java compatibility
+ lappend args "additional_flags=-fexact-fp"
regsub "^.*/(\[^/.\]+)\[.\]\[^/]*$" "$srcfile" "\\1" out