From 39b6bce83ed029266869d0fd477641bee25b82be Mon Sep 17 00:00:00 2001 From: Aleksey Demakov Date: Tue, 13 Dec 2005 16:43:51 +0000 Subject: [PATCH] floating point changes --- ChangeLog | 32 +++++++++++++------ configure.in | 17 ++++++---- jit/jit-apply-x86.h | 76 +++++++++++++++++++++++++++++++++------------ tools/gen-apply.c | 13 +++++++- 4 files changed, 102 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index f350294..019f08c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,18 +1,32 @@ +2005-12-13 Aleksey Demakov + + * 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 - * 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 - * 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, diff --git a/configure.in b/configure.in index bd97aab..e349754 100644 --- a/configure.in +++ b/configure.in @@ -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 diff --git a/jit/jit-apply-x86.h b/jit/jit-apply-x86.h index 1467e1d..7673363 100644 --- a/jit/jit-apply-x86.h +++ b/jit/jit-apply-x86.h @@ -67,13 +67,25 @@ ); \ 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) \ @@ -163,12 +175,24 @@ ); \ 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) @@ -201,15 +225,27 @@ #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) diff --git a/tools/gen-apply.c b/tools/gen-apply.c index 3a50bed..3de45e9 100644 --- a/tools/gen-apply.c +++ b/tools/gen-apply.c @@ -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; } -- 2.47.3