[Libclc-dev] [PATCH 11/14] math: Use precomputed constant for log2(10.0)

Jan Vesely via Libclc-dev libclc-dev at lists.llvm.org
Fri Nov 3 16:07:23 PDT 2017


exp10 CTS fails with or withoput this change

Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
---
 generic/include/clc/float/definitions.h | 8 ++++++++
 generic/lib/math/exp10.inc              | 4 ++--
 generic/lib/math/native_exp10.inc       | 2 +-
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/generic/include/clc/float/definitions.h b/generic/include/clc/float/definitions.h
index 6010ed2..84a102e 100644
--- a/generic/include/clc/float/definitions.h
+++ b/generic/include/clc/float/definitions.h
@@ -31,6 +31,10 @@
 #define M_SQRT2_F       0x1.6a09e6p+0f
 #define M_SQRT1_2_F     0x1.6a09e6p-1f
 
+#ifdef __CLC_INTERNAL
+#define M_LOG210_F      0x1.a934f0p+1f
+#endif
+
 #ifdef cl_khr_fp64
 
 #define HUGE_VAL        __builtin_huge_val()
@@ -59,6 +63,10 @@
 #define M_SQRT2         0x1.6a09e667f3bcdp+0
 #define M_SQRT1_2       0x1.6a09e667f3bcdp-1
 
+#ifdef __CLC_INTERNAL
+#define M_LOG210	0x1.a934f0979a371p+1
+#endif
+
 #endif
 
 #ifdef cl_khr_fp16
diff --git a/generic/lib/math/exp10.inc b/generic/lib/math/exp10.inc
index a592c19..f5482e4 100644
--- a/generic/lib/math/exp10.inc
+++ b/generic/lib/math/exp10.inc
@@ -1,9 +1,9 @@
 _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE exp10(__CLC_GENTYPE val) {
   // exp10(x) = exp2(x * log2(10))
 #if __CLC_FPSIZE == 32
-  return exp2(val * log2(10.0f));
+  return exp2(val * M_LOG210_F);
 #elif __CLC_FPSIZE == 64
-  return exp2(val * log2(10.0));
+  return exp2(val * M_LOG210);
 #else
 #error unknown _CLC_FPSIZE
 #endif
diff --git a/generic/lib/math/native_exp10.inc b/generic/lib/math/native_exp10.inc
index 7f9cb15..9826b4e 100644
--- a/generic/lib/math/native_exp10.inc
+++ b/generic/lib/math/native_exp10.inc
@@ -1,3 +1,3 @@
 _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE native_exp10(__CLC_GENTYPE val) {
-  return native_exp2(val * M_LOG10E_F);
+  return native_exp2(val * M_LOG210_F);
 }
-- 
2.13.6



More information about the Libclc-dev mailing list