From f447eea4de9cab5de295c717d35824cf92b9f322 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Wed, 12 Nov 2008 17:14:07 +0100 Subject: util: Add log2() definition for MSC. --- src/gallium/auxiliary/util/u_math.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/gallium/auxiliary/util/u_math.h') diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h index be7303e550..c7bbebc428 100644 --- a/src/gallium/auxiliary/util/u_math.h +++ b/src/gallium/auxiliary/util/u_math.h @@ -161,6 +161,11 @@ static INLINE float logf( float f ) return (float) log( (double) f ); } +static INLINE double log2( double x ) +{ + return log( x ) / log( 2.0 ); +} + #else /* Work-around an extra semi-colon in VS 2005 logf definition */ #ifdef logf -- cgit v1.2.3 From 0d8637451b7bf1aac164dba6d269d1a665160ea3 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Wed, 12 Nov 2008 19:02:41 +0100 Subject: util: Optimise log2(). --- src/gallium/auxiliary/util/u_math.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/gallium/auxiliary/util/u_math.h') diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h index c7bbebc428..aee69ab7ba 100644 --- a/src/gallium/auxiliary/util/u_math.h +++ b/src/gallium/auxiliary/util/u_math.h @@ -163,7 +163,8 @@ static INLINE float logf( float f ) static INLINE double log2( double x ) { - return log( x ) / log( 2.0 ); + const double invln2 = 1.442695041; + return log( x ) * invln2; } #else -- cgit v1.2.3 From 7e584a70c492698be18bf4d6372b50d1a1c38385 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 14 Nov 2008 12:55:05 -0700 Subject: gallium: increase table size for fast log/pow functions The various conformance tests pass now. --- src/gallium/auxiliary/util/u_math.c | 2 +- src/gallium/auxiliary/util/u_math.h | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src/gallium/auxiliary/util/u_math.h') diff --git a/src/gallium/auxiliary/util/u_math.c b/src/gallium/auxiliary/util/u_math.c index d1571cd1fc..2811475fa0 100644 --- a/src/gallium/auxiliary/util/u_math.c +++ b/src/gallium/auxiliary/util/u_math.c @@ -52,7 +52,7 @@ init_log2_table(void) { unsigned i; for (i = 0; i < LOG2_TABLE_SIZE; i++) - log2_table[i] = (float) log2(1.0 + i * (1.0 / LOG2_TABLE_SIZE)); + log2_table[i] = (float) log2(1.0 + i * (1.0 / LOG2_TABLE_SCALE)); } diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h index aee69ab7ba..ac11d7001b 100644 --- a/src/gallium/auxiliary/util/u_math.h +++ b/src/gallium/auxiliary/util/u_math.h @@ -246,8 +246,9 @@ util_fast_exp(float x) } -#define LOG2_TABLE_SIZE_LOG2 8 -#define LOG2_TABLE_SIZE (1 << LOG2_TABLE_SIZE_LOG2) +#define LOG2_TABLE_SIZE_LOG2 16 +#define LOG2_TABLE_SCALE (1 << LOG2_TABLE_SIZE_LOG2) +#define LOG2_TABLE_SIZE (LOG2_TABLE_SCALE + 1) extern float log2_table[LOG2_TABLE_SIZE]; @@ -258,7 +259,8 @@ util_fast_log2(float x) float epart, mpart; num.f = x; epart = (float)(((num.i & 0x7f800000) >> 23) - 127); - mpart = log2_table[(num.i & 0x007fffff) >> (23 - LOG2_TABLE_SIZE_LOG2)]; + /* mpart = log2_table[mantissa*LOG2_TABLE_SCALE + 0.5] */ + mpart = log2_table[((num.i & 0x007fffff) + (1 << (22 - LOG2_TABLE_SIZE_LOG2))) >> (23 - LOG2_TABLE_SIZE_LOG2)]; return epart + mpart; } -- cgit v1.2.3