From: David Miller Date: Sat, 28 Feb 2009 07:34:41 +0000 (-0800) Subject: mesa: Sparc's IROUND() optimization is invalid. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ae5c06b9ce1191afaa95dd784d7315f25ec729ff;p=mesa.git mesa: Sparc's IROUND() optimization is invalid. We can't use the "fstoi" instruction like this. Unlike other floating point instructions, "fstoi" always rounds towards zero no matter what rounding mode the FPU has been set to. This was validated using the following test program: -------------------- static inline int iround(float f) { int r; __asm__ ("fstoi %1, %0" : "=f" (r) : "f" (f)); return r; } #define IROUND(x) iround(x) #define IROUND_REF(f) ((int) (((f) >= 0.0F) ? ((f) + 0.5F) : ((f) - 0.5F))) int main(void) { float f = -2.0; while (f < 3.0f) { int sparc_val = IROUND(f); int ref_val = IROUND_REF(f); if (sparc_val != ref_val) printf("DIFFERENT[%f]: REF==%d SPARC==%d\n", f, ref_val, sparc_val); f += 0.1f; } return 0; } -------------------- which prints out things like: -------------------- DIFFERENT[-1.900000]: REF==-2 SPARC==-1 DIFFERENT[-1.800000]: REF==-2 SPARC==-1 DIFFERENT[-1.700000]: REF==-2 SPARC==-1 DIFFERENT[-1.600000]: REF==-2 SPARC==-1 DIFFERENT[-1.000000]: REF==-1 SPARC==0 DIFFERENT[-0.900000]: REF==-1 SPARC==0 DIFFERENT[-0.800000]: REF==-1 SPARC==0 DIFFERENT[-0.700000]: REF==-1 SPARC==0 DIFFERENT[-0.600000]: REF==-1 SPARC==0 DIFFERENT[0.500000]: REF==1 SPARC==0 DIFFERENT[0.600000]: REF==1 SPARC==0 ... -------------------- So we have to remove Sparc's IROUND() definition, it's wrong. Signed-off-by: David S. Miller --- diff --git a/src/mesa/main/imports.h b/src/mesa/main/imports.h index 4192f037c00..7b61e22e932 100644 --- a/src/mesa/main/imports.h +++ b/src/mesa/main/imports.h @@ -256,15 +256,7 @@ static INLINE int GET_FLOAT_BITS( float x ) /*** *** IROUND: return (as an integer) float rounded to nearest integer ***/ -#if defined(USE_SPARC_ASM) && defined(__GNUC__) && defined(__sparc__) -static INLINE int iround(float f) -{ - int r; - __asm__ ("fstoi %1, %0" : "=f" (r) : "f" (f)); - return r; -} -#define IROUND(x) iround(x) -#elif defined(USE_X86_ASM) && defined(__GNUC__) && defined(__i386__) && \ +#if defined(USE_X86_ASM) && defined(__GNUC__) && defined(__i386__) && \ (!(defined(__BEOS__) || defined(__HAIKU__)) || \ (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95))) static INLINE int iround(float f)