From: Matt Turner Date: Fri, 20 Jul 2012 16:55:47 +0000 (-0700) Subject: Remove _mesa_sqrt* in favor of plain sqrt X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=948b1c541f32b12e8264b1eeb79ccbb696661f54;p=mesa.git Remove _mesa_sqrt* in favor of plain sqrt Temporarily disabled since 2003 (see 386578c5b). This saves us from calling sqrt() 128 times to generate the sqrttab in one_time_init(). Reviewed-by: Brian Paul Reviewed-by: Kenneth Graunke --- diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index d5ccce076b9..1546c886f8b 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -404,8 +404,6 @@ one_time_init( struct gl_context *ctx ) _mesa_get_cpu_features(); - _mesa_init_sqrt_table(); - /* context dependence is never a one-time thing... */ _mesa_init_get_hash(ctx); diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c index 2d592a68ecb..fc30a6eb671 100644 --- a/src/mesa/main/imports.c +++ b/src/mesa/main/imports.c @@ -243,107 +243,6 @@ _mesa_memset16( unsigned short *dst, unsigned short val, size_t n ) /** \name Math */ /*@{*/ -/** Wrapper around sqrt() */ -double -_mesa_sqrtd(double x) -{ - return sqrt(x); -} - - -/* - * A High Speed, Low Precision Square Root - * by Paul Lalonde and Robert Dawson - * from "Graphics Gems", Academic Press, 1990 - * - * SPARC implementation of a fast square root by table - * lookup. - * SPARC floating point format is as follows: - * - * BIT 31 30 23 22 0 - * sign exponent mantissa - */ -static short sqrttab[0x100]; /* declare table of square roots */ - -void -_mesa_init_sqrt_table(void) -{ -#if defined(USE_IEEE) && !defined(DEBUG) - unsigned short i; - fi_type fi; /* to access the bits of a float in C quickly */ - /* we use a union defined in glheader.h */ - - for(i=0; i<= 0x7f; i++) { - fi.i = 0; - - /* - * Build a float with the bit pattern i as mantissa - * and an exponent of 0, stored as 127 - */ - - fi.i = (i << 16) | (127 << 23); - fi.f = _mesa_sqrtd(fi.f); - - /* - * Take the square root then strip the first 7 bits of - * the mantissa into the table - */ - - sqrttab[i] = (fi.i & 0x7fffff) >> 16; - - /* - * Repeat the process, this time with an exponent of - * 1, stored as 128 - */ - - fi.i = 0; - fi.i = (i << 16) | (128 << 23); - fi.f = sqrt(fi.f); - sqrttab[i+0x80] = (fi.i & 0x7fffff) >> 16; - } -#else - (void) sqrttab; /* silence compiler warnings */ -#endif /*HAVE_FAST_MATH*/ -} - - -/** - * Single precision square root. - */ -float -_mesa_sqrtf( float x ) -{ -#if defined(USE_IEEE) && !defined(DEBUG) - fi_type num; - /* to access the bits of a float in C - * we use a union from glheader.h */ - - short e; /* the exponent */ - if (x == 0.0F) return 0.0F; /* check for square root of 0 */ - num.f = x; - e = (num.i >> 23) - 127; /* get the exponent - on a SPARC the */ - /* exponent is stored with 127 added */ - num.i &= 0x7fffff; /* leave only the mantissa */ - if (e & 0x01) num.i |= 0x800000; - /* the exponent is odd so we have to */ - /* look it up in the second half of */ - /* the lookup table, so we set the */ - /* high bit */ - e >>= 1; /* divide the exponent by two */ - /* note that in C the shift */ - /* operators are sign preserving */ - /* for signed operands */ - /* Do the table lookup, based on the quaternary mantissa, - * then reconstruct the result back into a float - */ - num.i = ((sqrttab[num.i >> 16]) << 16) | ((e + 127) << 23); - - return num.f; -#else - return (float) _mesa_sqrtd((double) x); -#endif -} - /** inv_sqrt - A single precision 1/sqrt routine for IEEE format floats. diff --git a/src/mesa/main/imports.h b/src/mesa/main/imports.h index c0b6ceceac6..e825f21801b 100644 --- a/src/mesa/main/imports.h +++ b/src/mesa/main/imports.h @@ -99,11 +99,7 @@ typedef union { GLfloat f; GLint i; } fi_type; /*** *** SQRTF: single-precision square root ***/ -#if 0 /* _mesa_sqrtf() not accurate enough - temporarily disabled */ -# define SQRTF(X) _mesa_sqrtf(X) -#else -# define SQRTF(X) (float) sqrt((float) (X)) -#endif +#define SQRTF(X) (float) sqrt((float) (X)) /*** @@ -569,18 +565,9 @@ _mesa_realloc( void *oldBuffer, size_t oldSize, size_t newSize ); extern void _mesa_memset16( unsigned short *dst, unsigned short val, size_t n ); -extern double -_mesa_sqrtd(double x); - -extern float -_mesa_sqrtf(float x); - extern float _mesa_inv_sqrtf(float x); -extern void -_mesa_init_sqrt_table(void); - #ifndef FFS_DEFINED #define FFS_DEFINED 1