[Mesa-dev] [PATCH 11/28] replace LOG2 with util_fast_log2
Dylan Baker
dylan at pnwbakers.com
Fri Nov 9 18:40:04 UTC 2018
The implementation is somewhat different, although if you go back in
time far enough they're the same, but the one in u_math was changed a
long time back to be faster.
---
src/mesa/main/imports.h | 29 -----------------------------
src/mesa/swrast/s_span.c | 4 ++--
src/mesa/swrast/s_texfilter.c | 2 +-
3 files changed, 3 insertions(+), 32 deletions(-)
diff --git a/src/mesa/main/imports.h b/src/mesa/main/imports.h
index 7e067dd23e3..461e801bc31 100644
--- a/src/mesa/main/imports.h
+++ b/src/mesa/main/imports.h
@@ -88,35 +88,6 @@ typedef union { GLfloat f; GLint i; GLuint u; } fi_type;
/*@}*/
-/***
- *** LOG2: Log base 2 of float
- ***/
-static inline GLfloat LOG2(GLfloat x)
-{
-#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/
- */
- fi_type num;
- GLint log_2;
- 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;
-}
-
-
/**
* finite macro.
diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c
index f50b549a97f..e0d60deea7b 100644
--- a/src/mesa/swrast/s_span.c
+++ b/src/mesa/swrast/s_span.c
@@ -426,7 +426,7 @@ _swrast_compute_lambda(GLfloat dsdx, GLfloat dsdy, GLfloat dtdx, GLfloat dtdy,
GLfloat x = sqrtf(dudx * dudx + dvdx * dvdx);
GLfloat y = sqrtf(dudy * dudy + dvdy * dvdy);
GLfloat rho = MAX2(x, y);
- GLfloat lambda = LOG2(rho);
+ GLfloat lambda = util_fast_log2(rho);
return lambda;
}
@@ -453,7 +453,7 @@ _swrast_compute_lambda(GLfloat dsdx, GLfloat dsdy, GLfloat dtdx, GLfloat dtdy,
maxU = MAX2(dsdx2, dsdy2) * texW;
maxV = MAX2(dtdx2, dtdy2) * texH;
rho = MAX2(maxU, maxV);
- lambda = LOG2(rho);
+ lambda = util_fast_log2(rho);
return lambda;
}
#endif
diff --git a/src/mesa/swrast/s_texfilter.c b/src/mesa/swrast/s_texfilter.c
index 314170fc751..acc470f46ef 100644
--- a/src/mesa/swrast/s_texfilter.c
+++ b/src/mesa/swrast/s_texfilter.c
@@ -1961,7 +1961,7 @@ sample_lambda_2d_aniso(struct gl_context *ctx,
/* note: we need to have Pmin=sqrt(Pmin2) here, but we can avoid
* this since 0.5*log(x) = log(sqrt(x))
*/
- lod = 0.5f * LOG2(Pmin2);
+ lod = 0.5f * util_fast_log2(Pmin2);
if (adjustLOD) {
/* from swrast/s_texcombine.c _swrast_texture_span */
--
2.19.1
More information about the mesa-dev
mailing list