diff options
author | Brian <[email protected]> | 2008-11-09 10:15:32 -0700 |
---|---|---|
committer | Brian <[email protected]> | 2008-11-09 10:17:43 -0700 |
commit | 325cbeb29a63e3d71da00baeab864970fe3aa595 (patch) | |
tree | c7a63e26acb56b146dfb0c66995b19fff30a656a /src/gallium/auxiliary/util/u_math.c | |
parent | 7e8315701945ec807b2b5a9d01250b5ab74ae183 (diff) |
util: Fix util_fast_pow/exp2/log2.
- Use a lookup table for log2.
- Compute (float) (1 << ipart) by tweaking with the exponent directly to
avoid integer overflow and float conversion.
- Also table negative exponents to avoid float division and branching.
- Implement util_fast_exp as function of util_fast_exp2.
--------
Cherry-picked from gallium-0.2: 8415d06d90a197e16554dab98d160334fd9f9f93
This fixes some pow() glitches seen in fslight.c, spectex.c, etc.
Conflicts:
src/gallium/auxiliary/util/u_math.h
Diffstat (limited to 'src/gallium/auxiliary/util/u_math.c')
-rw-r--r-- | src/gallium/auxiliary/util/u_math.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/gallium/auxiliary/util/u_math.c b/src/gallium/auxiliary/util/u_math.c index 0729114d6a1..5b3cab4642a 100644 --- a/src/gallium/auxiliary/util/u_math.c +++ b/src/gallium/auxiliary/util/u_math.c @@ -30,7 +30,7 @@ #include "util/u_math.h" - +/** 2^x, for x in [-1.0, 1.0[ */ float pow2_table[POW2_TABLE_SIZE]; @@ -38,9 +38,21 @@ static void init_pow2_table(void) { int i; - for (i = 0; i < POW2_TABLE_SIZE; i++) { - pow2_table[i] = (float) pow(2.0, i / POW2_TABLE_SCALE); - } + for (i = 0; i < POW2_TABLE_SIZE; i++) + pow2_table[i] = (float) pow(2.0, (i - POW2_TABLE_OFFSET) / POW2_TABLE_SCALE); +} + + +/** log2(x), for x in [1.0, 2.0[ */ +float log2_table[LOG2_TABLE_SIZE]; + + +static void +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)); } @@ -53,6 +65,7 @@ util_init_math(void) static boolean initialized = FALSE; if (!initialized) { init_pow2_table(); + init_log2_table(); initialized = TRUE; } } |