diff options
author | Brian Paul <[email protected]> | 2012-08-31 08:33:31 -0600 |
---|---|---|
committer | Brian Paul <[email protected]> | 2012-09-01 07:41:26 -0600 |
commit | 36f3f7ebfa345460bfd89d6e471b655385efc739 (patch) | |
tree | 7e28a774ff337b7918844ff2db4fd9e5b6840a95 | |
parent | c8a86f717f8e30204c615d06bcec159410ac06c5 (diff) |
mesa: clean-up LOG2() function
-rw-r--r-- | 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 d851ee56a46..2f854e57400 100644 --- a/src/mesa/main/imports.h +++ b/src/mesa/main/imports.h @@ -164,41 +164,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 +} + /*** |