[Mesa-dev] [PATCH 3/3] mesa: clean-up LOG2() function

Brian Paul brian.e.paul at gmail.com
Thu Aug 30 19:16:31 PDT 2012


From: Brian Paul <brianp at vmware.com>

---
 src/mesa/main/imports.h |   34 ++++++++++++++++------------------
 1 files changed, 16 insertions(+), 18 deletions(-)

diff --git a/src/mesa/main/imports.h b/src/mesa/main/imports.h
index 5e526f1..3bb7bb1 100644
--- a/src/mesa/main/imports.h
+++ b/src/mesa/main/imports.h
@@ -159,41 +159,39 @@ static inline int isblank(int ch) { return ch == ' ' || ch == '\t'; }
 /***
  *** LOG2: Log base 2 of float
  ***/
-#ifdef USE_IEEE
-#if 0
-/* This is pretty fast, but not accurate enough (only 2 fractional bits).
- * Based on code from http://www.stereopsis.com/log2.html
- */
 static inline GLfloat LOG2(GLfloat x)
 {
+#ifdef USE_IEEE
+#if 0
+   /* This is pretty fast, but not accurate enough (only 2 fractional bits).
+    * Based on code from http://www.stereopsis.com/log2.html
+    */
    const GLfloat y = x * x * x * x;
    const GLuint ix = *((GLuint *) &y);
    const GLuint exp = (ix >> 23) & 0xFF;
    const GLint log2 = ((GLint) exp) - 127;
    return (GLfloat) log2 * (1.0 / 4.0);  /* 4, because of x^4 above */
-}
 #endif
-/* Pretty fast, and accurate.
- * Based on code from http://www.flipcode.com/totd/
- */
-static inline GLfloat LOG2(GLfloat val)
-{
+   /* Pretty fast, and accurate.
+    * Based on code from http://www.flipcode.com/totd/
+    */
    fi_type num;
    GLint log_2;
-   num.f = val;
+   num.f = x;
    log_2 = ((num.i >> 23) & 255) - 128;
    num.i &= ~(255 << 23);
    num.i += 127 << 23;
    num.f = ((-1.0f/3) * num.f + 2) * num.f - 2.0f/3;
    return num.f + log_2;
-}
 #else
-/*
- * NOTE: log_base_2(x) = log(x) / log(2)
- * NOTE: 1.442695 = 1/log(2).
- */
-#define LOG2(x)  ((GLfloat) (log(x) * 1.442695F))
+   /*
+    * NOTE: log_base_2(x) = log(x) / log(2)
+    * NOTE: 1.442695 = 1/log(2).
+    */
+   return (GLfloat) (log(x) * 1.442695F);
 #endif
+}
+
 
 
 /***
-- 
1.7.4.1



More information about the mesa-dev mailing list