[libclc] r227585 - Implement log10
Jan Vesely
jan.vesely at rutgers.edu
Fri Jan 30 10:00:35 PST 2015
Author: jvesely
Date: Fri Jan 30 12:00:34 2015
New Revision: 227585
URL: http://llvm.org/viewvc/llvm-project?rev=227585&view=rev
Log:
Implement log10
v2: Use constant and multiplication instead of division
v3: Use hex constants
Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
Added:
libclc/trunk/generic/include/clc/math/log10.h
libclc/trunk/generic/lib/math/log10.cl
libclc/trunk/generic/lib/math/log10.inc
Modified:
libclc/trunk/generic/include/clc/clc.h
libclc/trunk/generic/lib/SOURCES
Modified: libclc/trunk/generic/include/clc/clc.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/clc.h?rev=227585&r1=227584&r2=227585&view=diff
==============================================================================
--- libclc/trunk/generic/include/clc/clc.h (original)
+++ libclc/trunk/generic/include/clc/clc.h Fri Jan 30 12:00:34 2015
@@ -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>
Added: libclc/trunk/generic/include/clc/math/log10.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/log10.h?rev=227585&view=auto
==============================================================================
--- libclc/trunk/generic/include/clc/math/log10.h (added)
+++ libclc/trunk/generic/include/clc/math/log10.h Fri Jan 30 12:00:34 2015
@@ -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
Modified: libclc/trunk/generic/lib/SOURCES
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=227585&r1=227584&r2=227585&view=diff
==============================================================================
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Fri Jan 30 12:00:34 2015
@@ -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
Added: libclc/trunk/generic/lib/math/log10.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/log10.cl?rev=227585&view=auto
==============================================================================
--- libclc/trunk/generic/lib/math/log10.cl (added)
+++ libclc/trunk/generic/lib/math/log10.cl Fri Jan 30 12:00:34 2015
@@ -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>
Added: libclc/trunk/generic/lib/math/log10.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/log10.inc?rev=227585&view=auto
==============================================================================
--- libclc/trunk/generic/lib/math/log10.inc (added)
+++ libclc/trunk/generic/lib/math/log10.inc Fri Jan 30 12:00:34 2015
@@ -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
+}
More information about the cfe-commits
mailing list