From 9cc4185fa22d15ff603e81508e091bfb226cbda2 Mon Sep 17 00:00:00 2001 From: gbeauche <> Date: Mon, 16 Sep 2002 12:03:07 +0000 Subject: [PATCH] - Make "ieee" core default, where applicable - Import gcc configury to determine HOST_FLOAT_FORMAT --- BasiliskII/src/Unix/configure.in | 217 +++++++++++++++++++++++++------ BasiliskII/src/Unix/sysdeps.h | 8 ++ 2 files changed, 185 insertions(+), 40 deletions(-) diff --git a/BasiliskII/src/Unix/configure.in b/BasiliskII/src/Unix/configure.in index 241573d5..97ab983d 100644 --- a/BasiliskII/src/Unix/configure.in +++ b/BasiliskII/src/Unix/configure.in @@ -13,16 +13,17 @@ AC_ARG_ENABLE(vosf, [ --enable-vosf enable video on SEGV sig dnl FPU emulation core. AC_ARG_ENABLE(fpe, -[ --enable-fpe=which specify which fpu emulator to use [default=opt]], +[ --enable-fpe=FPE specify which fpu emulator to use [default=auto]], [ case "$enableval" in - dnl default is fpu_x86.cpp if i386 architecture, fpu_uae.cpp otherwise - default) FPE_CORE="default";; - ieee) FPE_CORE="ieee";; - uae) FPE_CORE="uae";; - *) AC_MSG_ERROR([--enable-fpe takes only one of the following values: default, uae, ieee]);; + dnl default is always ieee, if architecture has this fp format + auto) FPE_CORE_TEST_ORDER="ieee uae";; + ieee) FPE_CORE_TEST_ORDER="ieee";; + uae) FPE_CORE_TEST_ORDER="uae";; + x86) FPE_CORE_TEST_ORDER="x86";; + *) AC_MSG_ERROR([--enable-fpe takes only one of the following values: auto, x86, ieee, uae]);; esac ], -[ FPE_CORE="default" +[ FPE_CORE_TEST_ORDER="ieee uae" ]) dnl Addressing modes. @@ -795,7 +796,6 @@ fi dnl Select appropriate CPU source and REGPARAM define. ASM_OPTIMIZATIONS=none CPUSRCS="cpuemu1.cpp cpuemu2.cpp cpuemu3.cpp cpuemu4.cpp cpuemu5.cpp cpuemu6.cpp cpuemu7.cpp cpuemu8.cpp" -FPUSRCS="../uae_cpu/fpu/fpu_uae.cpp" if [[ "x$HAVE_GCC27" = "xyes" -a "x$HAVE_I386" = "xyes" -a "x$OS_TYPE" != "xfreebsd" ]]; then dnl i386 CPU DEFINES="$DEFINES -DREGPARAM=\"__attribute__((regparm(3)))\"" @@ -803,7 +803,6 @@ if [[ "x$HAVE_GCC27" = "xyes" -a "x$HAVE_I386" = "xyes" -a "x$OS_TYPE" != "xfree ASM_OPTIMIZATIONS=i386 DEFINES="$DEFINES -DX86_ASSEMBLY -DUNALIGNED_PROFITABLE -DOPTIMIZED_FLAGS" CPUSRCS="cpufast1.s cpufast2.s cpufast3.s cpufast4.s cpufast5.s cpufast6.s cpufast7.s cpufast8.s" - FPUSRCS="../uae_cpu/fpu_x86.cpp" fi elif [[ "x$HAVE_GCC27" = "xyes" -a "x$HAVE_SPARC" = "xyes" -a "x$HAVE_GAS" = "xyes" ]]; then dnl SPARC CPU @@ -834,40 +833,178 @@ elif [[ "x$WANT_NATIVE_M68K" = "xyes" ]]; then CPUSRCS="asm_support.s" fi -dnl Select appropriate FPU source. -dnl 1. Optimized X86 assembly core if target is i386 architecture. -SAVED_DEFINES=$DEFINES -if [[ "x$FPE_CORE" = "xdefault" ]]; then - if [[ "x$HAVE_GCC27" = "xyes" -a "x$HAVE_I386" = "xyes" -a "x$HAVE_GAS" = "xyes" ]]; then - DEFINES="$DEFINES -DFPU_X86" - FPE_CORE_STR="i386 optimized core" - FPUSRCS="../uae_cpu/fpu/fpu_x86.cpp" - FPE_CORE="i386" +dnl Utility macro used by next two tests. +dnl AC_EXAMINE_OBJECT(C source code, +dnl commands examining object file, +dnl [commands to run if compile failed]): +dnl +dnl Compile the source code to an object file; then convert it into a +dnl printable representation. All unprintable characters and +dnl asterisks (*) are replaced by dots (.). All white space is +dnl deleted. Newlines (ASCII 0x10) in the input are preserved in the +dnl output, but runs of newlines are compressed to a single newline. +dnl Finally, line breaks are forcibly inserted so that no line is +dnl longer than 80 columns and the file ends with a newline. The +dnl result of all this processing is in the file conftest.dmp, which +dnl may be examined by the commands in the second argument. +dnl +AC_DEFUN([gcc_AC_EXAMINE_OBJECT], +[AC_LANG_SAVE +AC_LANG_C +dnl Next bit cribbed from AC_TRY_COMPILE. +cat > conftest.$ac_ext < conftest.dmp + $2 +ifelse($3, , , else + $3 +)dnl +fi +rm -rf conftest* +AC_LANG_RESTORE]) + +dnl Floating point format probe. +dnl The basic concept is the same as the above: grep the object +dnl file for an interesting string. We have to watch out for +dnl rounding changing the values in the object, however; this is +dnl handled by ignoring the least significant byte of the float. +dnl +dnl Does not know about VAX G-float or C4x idiosyncratic format. +dnl It does know about PDP-10 idiosyncratic format, but this is +dnl not presently supported by GCC. S/390 "binary floating point" +dnl is in fact IEEE (but maybe we should have that in EBCDIC as well +dnl as ASCII?) +dnl +AC_DEFUN([gcc_AC_C_FLOAT_FORMAT], +[AC_CACHE_CHECK(floating point format, ac_cv_c_float_format, +[gcc_AC_EXAMINE_OBJECT( +[/* This will not work unless sizeof(double) == 8. */ +extern char sizeof_double_must_be_8 [sizeof(double) == 8 ? 1 : -1]; + +/* This structure must have no internal padding. */ +struct possibility { + char prefix[8]; + double candidate; + char postfix[8]; +}; + +#define C(cand) { "\nformat:", cand, ":tamrof\n" } +struct possibility table [] = +{ + C( 3.25724264705901305206e+01), /* @@IEEEFP - IEEE 754 */ + C( 3.53802595280598432000e+18), /* D__float - VAX */ + C( 5.32201830133125317057e-19), /* D.PDP-10 - PDP-10 - the dot is 0x13a */ + C( 1.77977764695171661377e+10), /* IBMHEXFP - s/390 format, ascii */ + C(-5.22995989424860458374e+10) /* IBMHEXFP - s/390 format, EBCDIC */ +};], + [if grep 'format:.@IEEEF.:tamrof' conftest.dmp >/dev/null 2>&1; then + ac_cv_c_float_format='IEEE (big-endian)' + elif grep 'format:.I@@PFE.:tamrof' conftest.dmp >/dev/null 2>&1; then + ac_cv_c_float_format='IEEE (big-endian)' + elif grep 'format:.FEEEI@.:tamrof' conftest.dmp >/dev/null 2>&1; then + ac_cv_c_float_format='IEEE (little-endian)' + elif grep 'format:.EFP@@I.:tamrof' conftest.dmp >/dev/null 2>&1; then + ac_cv_c_float_format='IEEE (little-endian)' + elif grep 'format:.__floa.:tamrof' conftest.dmp >/dev/null 2>&1; then + ac_cv_c_float_format='VAX D-float' + elif grep 'format:..PDP-1.:tamrof' conftest.dmp >/dev/null 2>&1; then + ac_cv_c_float_format='PDP-10' + elif grep 'format:.BMHEXF.:tamrof' conftest.dmp >/dev/null 2>&1; then + ac_cv_c_float_format='IBM 370 hex' else - FPE_CORE="uae" - fi -fi + AC_MSG_ERROR(Unknown floating point format) + fi], + [AC_MSG_ERROR(compile failed)]) +]) +# IEEE is the default format. If the float endianness isn't the same +# as the integer endianness, we have to set FLOAT_WORDS_BIG_ENDIAN +# (which is a tristate: yes, no, default). This is only an issue with +# IEEE; the other formats are only supported by a few machines each, +# all with the same endianness. +format=IEEE_FLOAT_FORMAT +fbigend= +case $ac_cv_c_float_format in + 'IEEE (big-endian)' ) + if test $ac_cv_c_bigendian = no; then + fbigend=1 + fi + ;; + 'IEEE (little-endian)' ) + if test $ac_cv_c_bigendian = yes; then + fbigend=0 + fi + ;; + 'VAX D-float' ) + format=VAX_FLOAT_FORMAT + ;; + 'PDP-10' ) + format=PDP10_FLOAT_FORMAT + ;; + 'IBM 370 hex' ) + format=IBM_FLOAT_FORMAT + ;; +esac +AC_DEFINE_UNQUOTED(HOST_FLOAT_FORMAT, $format, + [Define to the floating point format of the host machine.]) +if test -n "$fbigend"; then + AC_DEFINE_UNQUOTED(HOST_FLOAT_WORDS_BIG_ENDIAN, $fbigend, + [Define to 1 if the host machine stores floating point numbers in + memory with the word containing the sign bit at the lowest address, + or to 0 if it does it the other way around. -dnl 2. JIT-FPU only supports IEEE-based implementation. -if [[ "x$WANT_JIT_FPU" = "xyes" -a "x$FPE_CORE" != "xieee" ]]; then - AC_MSG_WARN([Sorry, JIT-FPU supports only the "ieee" FPE implementation]) - FPE_CORE="ieee" - dnl Restore previous variables. FPE_CORE_STR and FPUSRCS are overwritten - DEFINES=$SAVED_DEFINES + This macro should not be defined if the ordering is the same as for + multi-word integers.]) fi +]) -dnl 3. Choose either IEEE-based implementation or the old UAE core. -if [[ "x$FPE_CORE" = "xieee" ]]; then - AC_CHECK_HEADERS(fenv.h) - AC_CHECK_FUNCS(feclearexcept fegetexceptflag feraiseexcept fesetexceptflag fetestexcept) - AC_CHECK_FUNCS(fegetround fesetround) - DEFINES="$DEFINES -DFPU_IEEE" - FPE_CORE_STR="ieee-based fpu core" - FPUSRCS="../uae_cpu/fpu/fpu_ieee.cpp" -elif [[ "x$FPE_CORE" = "xuae" ]]; then - DEFINES="$DEFINES -DFPU_UAE" - FPE_CORE_STR="original uae core" - FPUSRCS="../uae_cpu/fpu/fpu_uae.cpp" +dnl Select appropriate FPU source. +gcc_AC_C_FLOAT_FORMAT +AC_CHECK_HEADERS(ieee754.h ieeefp.h floatingpoint.h nan.h) + +for fpe in $FPE_CORE_TEST_ORDER; do + case $fpe in + ieee) + if echo "$ac_cv_c_float_format" | grep -q IEEE; then + FPE_CORE="IEEE fpu core" + DEFINES="$DEFINES -DFPU_IEEE" + FPUSRCS="../uae_cpu/fpu/fpu_ieee.cpp" + break + fi + ;; + x86) + if [[ ":$HAVE_GCC27:$HAVE_I386:$HAVE_GAS:" = ":yes:yes:yes:" ]]; then + FPE_CORE="i387 fpu core" + DEFINES="$DEFINES -DFPU_X86" + FPUSRCS="../uae_cpu/fpu/fpu_x86.cpp" + break + fi + ;; + uae) + FPE_CORE="uae fpu core" + DEFINES="$DEFINES -DFPU_UAE" + FPUSRCS="../uae_cpu/fpu/fpu_uae.cpp" + break + ;; + *) + AC_MSG_ERROR([Internal configure.in script error for $fpe fpu core]) + ;; + esac +done +if [[ "x$FPE_CORE" = "x" ]]; then + AC_MSG_ERROR([Sorry, no suitable FPU core found in $FPE_CORE_TEST_ORDER]) fi dnl Check for certain math functions @@ -914,7 +1051,7 @@ echo ESD sound support ...................... : $WANT_ESD echo GTK user interface ..................... : $WANT_GTK echo mon debugger support ................... : $WANT_MON echo Running m68k code natively ............. : $WANT_NATIVE_M68K -echo Floating-Point emulation core .......... : $FPE_CORE_STR +echo Floating-Point emulation core .......... : $FPE_CORE echo Assembly optimizations ................. : $ASM_OPTIMIZATIONS echo Addressing mode ........................ : $ADDRESSING_MODE echo diff --git a/BasiliskII/src/Unix/sysdeps.h b/BasiliskII/src/Unix/sysdeps.h index be537a27..8c295f33 100644 --- a/BasiliskII/src/Unix/sysdeps.h +++ b/BasiliskII/src/Unix/sysdeps.h @@ -158,6 +158,14 @@ typedef struct timespec tm_time_t; typedef struct timeval tm_time_t; #endif +/* Define codes for all the float formats that we know of. + * Though we only handle IEEE format. */ +#define UNKNOWN_FLOAT_FORMAT 0 +#define IEEE_FLOAT_FORMAT 1 +#define VAX_FLOAT_FORMAT 2 +#define IBM_FLOAT_FORMAT 3 +#define C4X_FLOAT_FORMAT 4 + /* UAE CPU data types */ #define uae_s8 int8 #define uae_u8 uint8