[Libclc-dev] [PATCH 1/1] Implement trunc builtin.

Jan Vesely jan.vesely at rutgers.edu
Mon Dec 16 15:37:16 PST 2013


OpenCL C lang says that trunc rounds towards zero.
llvm.trunc.* intrinsic rounds to integer not larger in magnitude.
These definitions are equivalent.

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

 I tested this (with follow up patch to llvm) on AMD Turks, and gegl test 'posterize' that uses trunc passes.

 generic/include/clc/clc.h        | 1 +
 generic/include/clc/math/trunc.h | 9 +++++++++
 2 files changed, 10 insertions(+)
 create mode 100644 generic/include/clc/math/trunc.h

diff --git a/generic/include/clc/clc.h b/generic/include/clc/clc.h
index 8f0dbd3..c14d072 100644
--- a/generic/include/clc/clc.h
+++ b/generic/include/clc/clc.h
@@ -51,6 +51,7 @@
 #include <clc/math/round.h>
 #include <clc/math/sin.h>
 #include <clc/math/sqrt.h>
+#include <clc/math/trunc.h>
 #include <clc/math/native_cos.h>
 #include <clc/math/native_divide.h>
 #include <clc/math/native_exp.h>
diff --git a/generic/include/clc/math/trunc.h b/generic/include/clc/math/trunc.h
new file mode 100644
index 0000000..d34f661
--- /dev/null
+++ b/generic/include/clc/math/trunc.h
@@ -0,0 +1,9 @@
+#undef trunc
+#define trunc __clc_trunc
+
+#define __CLC_FUNCTION __clc_trunc
+#define __CLC_INTRINSIC "llvm.trunc"
+#include <clc/math/unary_intrin.inc>
+
+#undef __CLC_FUNCTION
+#undef __CLC_INTRINSIC
-- 
1.8.3.1





More information about the Libclc-dev mailing list