[libclc] r318063 - math: Use precomputed constant for log2(10.0)

Jan Vesely via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 13 10:28:45 PST 2017


Author: jvesely
Date: Mon Nov 13 10:28:45 2017
New Revision: 318063

URL: http://llvm.org/viewvc/llvm-project?rev=318063&view=rev
Log:
math: Use precomputed constant for log2(10.0)

exp10 CTS fails with or without this change

Reviewer: Jeroen Ketema
Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>

Modified:
    libclc/trunk/generic/include/clc/float/definitions.h
    libclc/trunk/generic/lib/math/exp10.inc
    libclc/trunk/generic/lib/math/native_exp10.inc

Modified: libclc/trunk/generic/include/clc/float/definitions.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/float/definitions.h?rev=318063&r1=318062&r2=318063&view=diff
==============================================================================
--- libclc/trunk/generic/include/clc/float/definitions.h (original)
+++ libclc/trunk/generic/include/clc/float/definitions.h Mon Nov 13 10:28:45 2017
@@ -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

Modified: libclc/trunk/generic/lib/math/exp10.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/exp10.inc?rev=318063&r1=318062&r2=318063&view=diff
==============================================================================
--- libclc/trunk/generic/lib/math/exp10.inc (original)
+++ libclc/trunk/generic/lib/math/exp10.inc Mon Nov 13 10:28:45 2017
@@ -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

Modified: libclc/trunk/generic/lib/math/native_exp10.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/native_exp10.inc?rev=318063&r1=318062&r2=318063&view=diff
==============================================================================
--- libclc/trunk/generic/lib/math/native_exp10.inc (original)
+++ libclc/trunk/generic/lib/math/native_exp10.inc Mon Nov 13 10:28:45 2017
@@ -1,3 +1,3 @@
 _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE native_exp10(__CLC_GENTYPE val) {
-  return native_exp2(val * native_log2(10));
+  return native_exp2(val * M_LOG210_F);
 }




More information about the cfe-commits mailing list