]> git.unchartedbackwaters.co.uk Git - francis/libjit.git/commitdiff
floating point changes
authorAleksey Demakov <ademakov@gmail.com>
Tue, 13 Dec 2005 16:43:51 +0000 (16:43 +0000)
committerAleksey Demakov <ademakov@gmail.com>
Tue, 13 Dec 2005 16:43:51 +0000 (16:43 +0000)
ChangeLog
configure.in
jit/jit-apply-x86.h
tools/gen-apply.c

index f350294338c28ca9eab2c1f57f7eb5d274d0113e..019f08c4a7d784b814642bf40f309a0753eaabee 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,18 +1,32 @@
+2005-12-13  Aleksey Demakov  <ademakov@gmail.com>
+
+       * configure.in: Added --enable-long-double option that forces
+       jit_nfloat to be long double.
+
+       * jit/jit-apply-x86.h (jit_builtin_apply, jit_builtin_return_float):
+       In gcc/Win32 and gcc/non-Win32 versions of the macros check the size
+       of jit_nfloat and use fstpl/fldl or fstpt/fldt instructions
+       accordingly.
+
+       * tools/gen-apply.c (detect_float_return): On x86 only the first
+       10 bytes of 12 byte long doubles are significant and are used for
+       comparison.
+
 2005-12-12  Aleksey Demakov  <ademakov@gmail.com>
 
-       * jit/jit-dump.c (dump_object_code): in order to make dump work on cygwin
-       call "as" and "objdump" in two separate system() calls because it looks
-       like the ';' separator between commands does not work there. Also on Win32
-       use TMP and TEMP environment variables as the tmp directory names and
-       fallback to "c:/tmp".
+       * jit/jit-dump.c (dump_object_code): in order to make dump work on
+       cygwin call "as" and "objdump" in two separate system() calls because
+       it looks like the ';' separator between commands does not work there.
+       Also on Win32 use TMP and TEMP environment variables as the tmp
+       directory names and fallback to "c:/tmp".
 
-       * jit/jit-gen-x86.h (jit_assert): change definition to resolve problems
-       introduced at 2005-12-10.
+       * jit/jit-gen-x86.h (jit_assert): change the macro definition to
+       resolve problems introduced at 2005-12-10.
 
 2005-12-10  Aleksey Demakov  <ademakov@gmail.com>
 
-       * jit/jit-gen-x86.h: Merged changes from the latest Mono project's version
-       of this file.
+       * jit/jit-gen-x86.h: Merged changes from the latest Mono project's
+       version of this file.
 
        * jit/jit-rules-x86.sel: Done the following rules:
        JIT_OP_LOAD_ELEMENT_FLOAT32, JIT_OP_LOAD_ELEMENT_FLOAT64,
index bd97aabd611f11f7270f5fad5f2adf1aa8836bec..e3497545e51320cbfb9a08090e48a3a497fe1581 100644 (file)
@@ -63,6 +63,11 @@ if test x$interp = xtrue; then
        AC_DEFINE(USE_LIBJIT_INTERPRETER, 1, [Define if you want to use the libjit interpreter])
 fi
 
+dnl The "--enable-long-double" option forces the use of long double for
+dnl jit_nfloat.
+AC_ARG_ENABLE(long-double,
+[  --enable-long-double    Enable the use of long double for jit_nfloat])
+
 dnl Checks for programs.
 AC_PROG_AWK
 AC_PROG_CC
@@ -260,13 +265,13 @@ fi
 AC_MSG_RESULT($JITFLOAT64)
 AC_MSG_CHECKING(for the native floating-point type)
 JITNFLOATISDOUBLE=''
-if test "x$platform_win32" = "xyes" ; then
+if test "$ac_cv_sizeof_long_double" != 0 ; then
        dnl MSVC's "long double" is the same as "double", so we make sure
-       dnl to preserve compatibility between MSVC and gcc.
-       JITNATIVEFLOAT='double'
-       JITNFLOATISDOUBLE='#define JIT_NFLOAT_IS_DOUBLE 1'
-elif test "$ac_cv_sizeof_long_double" != 0 ; then
-       if test "$ac_cv_sizeof_long_double" = "$ac_cv_sizeof_double" ; then
+       dnl to preserve compatibility between MSVC and gcc unless the
+       dnl --enable-long-double option is provided.
+       if test "x$enable_long_double" = "xyes" ; then
+               JITNATIVEFLOAT='long double'
+       elif test "x$enable_long_double" = "xno" -o "$ac_cv_sizeof_long_double" = "$ac_cv_sizeof_double" -o "x$platform_win32" = "xyes" ; then
                JITNATIVEFLOAT='double'
                JITNFLOATISDOUBLE='#define JIT_NFLOAT_IS_DOUBLE 1'
        else
index 1467e1d36647078a60967e7f1be24a95e6d0bf8b..76733636d7fa2cc26b231273b773d326843cde2f 100644 (file)
                        ); \
                        if((return_float)) \
                        { \
-                               __asm__ ( \
-                                       "movl %0, %%ecx\n\t" \
-                                       "fstpt 8(%%ecx)\n\t" \
-                                       : : "m"(__return_buf) \
-                                       : "ecx", "st" \
-                               ); \
-                       } \
+                               if(sizeof(jit_nfloat) == sizeof(double)) \
+                               { \
+                                       __asm__ ( \
+                                               "movl %0, %%ecx\n\t" \
+                                               "fstpl 8(%%ecx)\n\t" \
+                                               : : "m"(__return_buf) \
+                                               : "ecx", "st" \
+                                       ); \
+                               } \
+                               else \
+                               { \
+                                       __asm__ ( \
+                                               "movl %0, %%ecx\n\t" \
+                                               "fstpt 8(%%ecx)\n\t" \
+                                               : : "m"(__return_buf) \
+                                               : "ecx", "st" \
+                                       ); \
+                               } \
+                       } \
                } while (0)
 
 #define        jit_builtin_apply_args(type,args)       \
                        ); \
                        if((return_float)) \
                        { \
-                               __asm__ ( \
-                                       "movl %0, %%ecx\n\t" \
-                                       "fstpt 8(%%ecx)\n\t" \
-                                       : : "m"(__return_buf) \
-                                       : "ecx", "st" \
-                               ); \
+                               if(sizeof(jit_nfloat) == sizeof(double)) \
+                               { \
+                                       __asm__ ( \
+                                               "movl %0, %%ecx\n\t" \
+                                               "fstpl 8(%%ecx)\n\t" \
+                                               : : "m"(__return_buf) \
+                                               : "ecx", "st" \
+                                       ); \
+                               } \
+                               else \
+                               { \
+                                       __asm__ ( \
+                                               "movl %0, %%ecx\n\t" \
+                                               "fstpt 8(%%ecx)\n\t" \
+                                               : : "m"(__return_buf) \
+                                               : "ecx", "st" \
+                                       ); \
+                               } \
                        } \
                } while (0)
 
 
 #define        jit_builtin_return_float(return_buf)    \
                do { \
-                       double __value = \
+                       jit_nfloat __value = \
                                ((jit_apply_return *)(return_buf))-> \
                                        f_value.inner_value.nfloat_value; \
-                       __asm__ ( \
-                               "leal %0, %%ecx\n\t" \
-                               "fldl (%%ecx)\n\t" \
-                               : : "m"(__value) \
-                               : "ecx", "st" \
-                       ); \
+                       if(sizeof(jit_nfloat) == sizeof(double)) \
+                       { \
+                               __asm__ ( \
+                                       "leal %0, %%ecx\n\t" \
+                                       "fldl (%%ecx)\n\t" \
+                                       : : "m"(__value) \
+                                       : "ecx", "st" \
+                               ); \
+                       } \
+                       else \
+                       { \
+                               __asm__ ( \
+                                       "leal %0, %%ecx\n\t" \
+                                       "fldt (%%ecx)\n\t" \
+                                       : : "m"(__value) \
+                                       : "ecx", "st" \
+                               ); \
+                       } \
                        return; \
                } while (0)
 
index 3a50bed6c7f1ff7dd25e801f1dc3957ea60968f4..3de45e90cb734c8c94848cdc774599b5ace35cd0 100644 (file)
@@ -56,6 +56,17 @@ the "jit-apply-rules.h" file.
        #define PLATFORM_IS_X86_64      1
 #endif
 
+/*
+ * On x86 the extended precision numbers are 10 bytes long. However certain
+ * ABIs define the long double size equal to 12 bytes. The extra 2 bytes are
+ * for alignment purposes only and has no significance in computations.
+ */
+#if PLATFORM_IS_X86
+#define NFLOAT_SIGNIFICANT_BYTES (sizeof(jit_nfloat) != 12 ? sizeof(jit_nfloat) : 10)
+#else
+#define NFLOAT_SIGNIFICANT_BYTES sizeof(jit_nfloat)
+#endif
+
 #if defined(PLATFORM_IS_GCC) || defined(PLATFORM_IS_WIN32)
 
 /*
@@ -717,7 +728,7 @@ void detect_float_return(void)
                                mem_copy(&nfloat_value, return_value + offset,
                                                 sizeof(jit_nfloat));
                                temp_nfloat = (jit_nfloat)123.0;
-                               if(!mem_cmp(&nfloat_value, &temp_nfloat, sizeof(jit_nfloat)))
+                               if(!mem_cmp(&nfloat_value, &temp_nfloat, NFLOAT_SIGNIFICANT_BYTES))
                                {
                                        break;
                                }