summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/util/u_math.c
diff options
context:
space:
mode:
authorJosé Fonseca <[email protected]>2008-10-01 01:13:40 +0900
committerJosé Fonseca <[email protected]>2008-10-01 01:13:40 +0900
commit8415d06d90a197e16554dab98d160334fd9f9f93 (patch)
tree25d004929ecac18de0e4b8bf4180bb2b33ba45f7 /src/gallium/auxiliary/util/u_math.c
parent5dc8e67078be8b8c42a809311debd275ac7d64a7 (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.
Diffstat (limited to 'src/gallium/auxiliary/util/u_math.c')
-rw-r--r--src/gallium/auxiliary/util/u_math.c21
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;
}
}