From ffb371a1632b2b2014e95ea12c3903726986b0ff Mon Sep 17 00:00:00 2001 From: "Clifford T. Matthews" Date: Wed, 17 Jun 2009 18:29:59 -0600 Subject: [PATCH] Fixed floating point in Mac OS X ppc --- README | 4 +--- TODO | 4 ---- src/include/rsys/floatconv.h | 43 +++++++++++++++++++++++++++--------- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/README b/README index 27e31c9..9803320 100644 --- a/README +++ b/README @@ -71,9 +71,7 @@ the SDL-based version of Executor on Mac OS X Intel, you can try: make If you have SDL installed and would like to play with the SDL-based -version of Executor on Mac OS X PPC, you can try the following. Be aware that -the Mac OS X PPC port is the most recent port and is likely to have problems -above and beyond those of the other ports. +version of Executor on Mac OS X PPC, you can try the following. mkdir -p build/debug-macosx-sdl cd build/debug-macosx-sdl diff --git a/TODO b/TODO index 98c6e83..4f0fdc1 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,3 @@ - Look into Mac OS X PPC glitches - - cards don't work right in Eric's Ultimate Solitaire demo - Yank all the misleading RCS strings Update the copyright notices to make it that the code is under diff --git a/src/include/rsys/floatconv.h b/src/include/rsys/floatconv.h index 77a71f6..8c7affe 100644 --- a/src/include/rsys/floatconv.h +++ b/src/include/rsys/floatconv.h @@ -23,14 +23,38 @@ #include #include "rsys/float.h" -/* - * Unlike most of the rest of Executor's source, we're not using __ppc__ - * in our tests below, because the code involved won't compile on Mac OS X - * 10.5.7, with gcc 4.0.1. - */ - #if defined (powerpc) #include +#elif defined (__ppc__) + +/* + * This comes from gcc's ieee754.h, + * which does not come with gcc with Apple's XCode. + */ + +union ieee754_double +{ + long double d; + struct { + unsigned int negative:1; + unsigned int exponent:11; + /* Together these comprise the mantissa. */ + unsigned int mantissa0:20; + unsigned int mantissa1:32; + + } ieee; + struct { + unsigned int negative:1; + unsigned int exponent:11; + unsigned int quiet_nan:1; + /* Together these comprise the mantissa. */ + unsigned int mantissa0:19; + unsigned int mantissa1:32; + } ieee_nan; +}; + +#define IEEE754_DOUBLE_BIAS 0x3ff /* Added to exponent. */ + #endif @@ -92,7 +116,7 @@ x80_to_ieee (const x80_t *x) } retval = *(double *)&temp64; -#elif defined (powerpc) +#elif defined (powerpc) || defined (__ppc__) union ieee754_double d; long long f; /* see SANE 2-18 for names */ @@ -103,7 +127,7 @@ x80_to_ieee (const x80_t *x) s = GET_X80_SGN (x); e = GET_X80_EXP (x); i = x->man.man >> 63; - f = x->man.man & 0x7fffffffffffffff; + f = x->man.man & 0x7fffffffffffffffULL; if (e == 32767) { @@ -163,7 +187,6 @@ x80_to_ieee (const x80_t *x) } #warning using 8 byte to represent x80; precision will be lost retval = d.d; - #else # warning x80_to_ieee not yet supported on this architecture. #endif @@ -330,7 +353,7 @@ ieee_to_x80 (ieee_t n, x80_t *x) templ = temp64p->man_lo; x->man.hilo.man_hi = CL(0x80000000 | ((temp64p->man_hi) << 11) | (templ >> 21)); x->man.hilo.man_lo = CL(templ << 11); -#elif defined (powerpc) +#elif defined (powerpc) || defined (__ppc__) union ieee754_double d; d.d = n;