summaryrefslogtreecommitdiff
path: root/src/gallium/auxiliary/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallium/auxiliary/util')
-rw-r--r--src/gallium/auxiliary/util/u_math.c6
-rw-r--r--src/gallium/auxiliary/util/u_math.h8
2 files changed, 8 insertions, 6 deletions
diff --git a/src/gallium/auxiliary/util/u_math.c b/src/gallium/auxiliary/util/u_math.c
index 9c5f616ceb..2811475fa0 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] */
+/** 2^x, for x in [-1.0, 1.0) */
float pow2_table[POW2_TABLE_SIZE];
@@ -43,7 +43,7 @@ init_pow2_table(void)
}
-/** log2(x), for x in [1.0, 2.0] */
+/** log2(x), for x in [1.0, 2.0) */
float log2_table[LOG2_TABLE_SIZE];
@@ -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 fdaec8df82..653d79ccd5 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;
}