Mesa (master): Remove _mesa_sqrt* in favor of plain sqrt

Matt Turner mattst88 at kemper.freedesktop.org
Sat Jul 21 15:22:54 UTC 2012


Module: Mesa
Branch: master
Commit: 948b1c541f32b12e8264b1eeb79ccbb696661f54
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=948b1c541f32b12e8264b1eeb79ccbb696661f54

Author: Matt Turner <mattst88 at gmail.com>
Date:   Fri Jul 20 09:55:47 2012 -0700

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 <brianp at vmware.com>
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

---

 src/mesa/main/context.c |    2 -
 src/mesa/main/imports.c |  101 -----------------------------------------------
 src/mesa/main/imports.h |   15 +------
 3 files changed, 1 insertions(+), 117 deletions(-)

diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index d5ccce0..1546c88 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 2d592a6..fc30a6e 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 c0b6cec..e825f21 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




More information about the mesa-commit mailing list