summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libclc/generic/include/clc/clc.h1
-rw-r--r--libclc/generic/include/clc/math/log10.h9
-rw-r--r--libclc/generic/lib/SOURCES1
-rw-r--r--libclc/generic/lib/math/log10.cl8
-rw-r--r--libclc/generic/lib/math/log10.inc13
5 files changed, 32 insertions, 0 deletions
diff --git a/libclc/generic/include/clc/clc.h b/libclc/generic/include/clc/clc.h
index bd92fdb12b5..29c185500c2 100644
--- a/libclc/generic/include/clc/clc.h
+++ b/libclc/generic/include/clc/clc.h
@@ -50,6 +50,7 @@
#include <clc/math/fmod.h>
#include <clc/math/hypot.h>
#include <clc/math/log.h>
+#include <clc/math/log10.h>
#include <clc/math/log1p.h>
#include <clc/math/log2.h>
#include <clc/math/mad.h>
diff --git a/libclc/generic/include/clc/math/log10.h b/libclc/generic/include/clc/math/log10.h
new file mode 100644
index 00000000000..ec4e4ae9362
--- /dev/null
+++ b/libclc/generic/include/clc/math/log10.h
@@ -0,0 +1,9 @@
+#undef log10
+
+#define __CLC_BODY <clc/math/unary_decl.inc>
+#define __CLC_FUNCTION log10
+
+#include <clc/math/gentype.inc>
+
+#undef __CLC_BODY
+#undef __CLC_FUNCTION
diff --git a/libclc/generic/lib/SOURCES b/libclc/generic/lib/SOURCES
index b76fec98f63..1032606c518 100644
--- a/libclc/generic/lib/SOURCES
+++ b/libclc/generic/lib/SOURCES
@@ -63,6 +63,7 @@ math/fmax.cl
math/fmin.cl
math/fmod.cl
math/hypot.cl
+math/log10.cl
math/log1p.cl
math/mad.cl
math/mix.cl
diff --git a/libclc/generic/lib/math/log10.cl b/libclc/generic/lib/math/log10.cl
new file mode 100644
index 00000000000..d65764a894b
--- /dev/null
+++ b/libclc/generic/lib/math/log10.cl
@@ -0,0 +1,8 @@
+#include <clc/clc.h>
+
+#ifdef cl_khr_fp64
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+#endif
+
+#define __CLC_BODY <log10.inc>
+#include <clc/math/gentype.inc>
diff --git a/libclc/generic/lib/math/log10.inc b/libclc/generic/lib/math/log10.inc
new file mode 100644
index 00000000000..423308a05ad
--- /dev/null
+++ b/libclc/generic/lib/math/log10.inc
@@ -0,0 +1,13 @@
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE log10(__CLC_GENTYPE val) {
+ // log10(x) = log2(x) / log2(10)
+ // 1 / log2(10) = 0.30102999566 = log10(2)
+ // SP representation is 0.30103 (0x1.344136p-2)
+ // DP representation is 0.301029995659999993762312442414(0x1.34413509E61D8p-2)
+#if __CLC_FPSIZE == 32
+ return log2(val) * 0x1.344136p-2f;
+#elif __CLC_FPSIZE == 64
+ return log2(val) * 0x1.34413509E61D8p-2;
+#else
+#error unknown _CLC_FPSIZE
+#endif
+}
OpenPOWER on IntegriCloud