summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2012-05-29 13:35:28 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2012-05-29 13:35:28 +0000
commit0d9bead544e7bd9b7312989dffe9e73c95810542 (patch)
treeb59aa359d8813b54be8fa9a4b918fc1d08e73ec5
parent33a274aec50983bd9fc96f0e1a302bfdf5b473cd (diff)
Add fma, hypot builtins.
git-svn-id: https://llvm.org/svn/llvm-project/libclc/trunk@157613 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--generic/include/clc/clc.h2
-rw-r--r--generic/include/clc/math/fma.h6
-rw-r--r--generic/include/clc/math/hypot.h2
-rw-r--r--generic/include/clc/math/hypot.inc1
-rw-r--r--generic/include/clc/math/ternary_intrin.inc18
-rw-r--r--generic/lib/SOURCES1
-rw-r--r--generic/lib/math/hypot.cl8
-rw-r--r--generic/lib/math/hypot.inc3
8 files changed, 41 insertions, 0 deletions
diff --git a/generic/include/clc/clc.h b/generic/include/clc/clc.h
index 3b78d29..65e4090 100644
--- a/generic/include/clc/clc.h
+++ b/generic/include/clc/clc.h
@@ -36,6 +36,8 @@
#include <clc/math/exp.h>
#include <clc/math/exp2.h>
#include <clc/math/fabs.h>
+#include <clc/math/fma.h>
+#include <clc/math/hypot.h>
#include <clc/math/log.h>
#include <clc/math/log2.h>
#include <clc/math/mad.h>
diff --git a/generic/include/clc/math/fma.h b/generic/include/clc/math/fma.h
new file mode 100644
index 0000000..8d862fa
--- /dev/null
+++ b/generic/include/clc/math/fma.h
@@ -0,0 +1,6 @@
+#undef fma
+#define fma __clc_fma
+
+#define FUNCTION __clc_fma
+#define INTRINSIC "llvm.fma"
+#include <clc/math/ternary_intrin.inc>
diff --git a/generic/include/clc/math/hypot.h b/generic/include/clc/math/hypot.h
new file mode 100644
index 0000000..9ffda48
--- /dev/null
+++ b/generic/include/clc/math/hypot.h
@@ -0,0 +1,2 @@
+#define BODY <clc/math/hypot.inc>
+#include <clc/math/gentype.inc>
diff --git a/generic/include/clc/math/hypot.inc b/generic/include/clc/math/hypot.inc
new file mode 100644
index 0000000..2f97ee5
--- /dev/null
+++ b/generic/include/clc/math/hypot.inc
@@ -0,0 +1 @@
+_CLC_OVERLOAD _CLC_DECL GENTYPE hypot(GENTYPE x, GENTYPE y);
diff --git a/generic/include/clc/math/ternary_intrin.inc b/generic/include/clc/math/ternary_intrin.inc
new file mode 100644
index 0000000..7d451e9
--- /dev/null
+++ b/generic/include/clc/math/ternary_intrin.inc
@@ -0,0 +1,18 @@
+_CLC_OVERLOAD float FUNCTION(float, float, float) __asm(INTRINSIC ".f32");
+_CLC_OVERLOAD float2 FUNCTION(float2, float2, float2) __asm(INTRINSIC ".v2f32");
+_CLC_OVERLOAD float3 FUNCTION(float3, float3, float3) __asm(INTRINSIC ".v3f32");
+_CLC_OVERLOAD float4 FUNCTION(float4, float4, float4) __asm(INTRINSIC ".v4f32");
+_CLC_OVERLOAD float8 FUNCTION(float8, float8, float8) __asm(INTRINSIC ".v8f32");
+_CLC_OVERLOAD float16 FUNCTION(float16, float16, float16) __asm(INTRINSIC ".v16f32");
+
+#ifdef cl_khr_fp64
+_CLC_OVERLOAD double FUNCTION(double, double, double) __asm(INTRINSIC ".f64");
+_CLC_OVERLOAD double2 FUNCTION(double2, double2, double2) __asm(INTRINSIC ".v2f64");
+_CLC_OVERLOAD double3 FUNCTION(double3, double3, double3) __asm(INTRINSIC ".v3f64");
+_CLC_OVERLOAD double4 FUNCTION(double4, double4, double4) __asm(INTRINSIC ".v4f64");
+_CLC_OVERLOAD double8 FUNCTION(double8, double8, double8) __asm(INTRINSIC ".v8f64");
+_CLC_OVERLOAD double16 FUNCTION(double16, double16, double16) __asm(INTRINSIC ".v16f64");
+#endif
+
+#undef FUNCTION
+#undef INTRINSIC
diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES
index 1da1c91..0608116 100644
--- a/generic/lib/SOURCES
+++ b/generic/lib/SOURCES
@@ -7,4 +7,5 @@ integer/abs.cl
integer/add_sat.cl
integer/add_sat.ll
integer/add_sat_impl.ll
+math/hypot.cl
math/mad.cl
diff --git a/generic/lib/math/hypot.cl b/generic/lib/math/hypot.cl
new file mode 100644
index 0000000..dcdc1ed
--- /dev/null
+++ b/generic/lib/math/hypot.cl
@@ -0,0 +1,8 @@
+#include <clc/clc.h>
+
+#ifdef cl_khr_fp64
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+#endif
+
+#define BODY <hypot.inc>
+#include <clc/math/gentype.inc>
diff --git a/generic/lib/math/hypot.inc b/generic/lib/math/hypot.inc
new file mode 100644
index 0000000..3f529c8
--- /dev/null
+++ b/generic/lib/math/hypot.inc
@@ -0,0 +1,3 @@
+_CLC_OVERLOAD _CLC_DEF GENTYPE hypot(GENTYPE x, GENTYPE y) {
+ return sqrt(x*x + y*y);
+}