Add fma, hypot builtins.
authorPeter Collingbourne <peter@pcc.me.uk>
Tue, 29 May 2012 13:35:28 +0000 (13:35 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Tue, 29 May 2012 13:35:28 +0000 (13:35 +0000)
llvm-svn: 157613

libclc/generic/include/clc/clc.h
libclc/generic/include/clc/math/fma.h [new file with mode: 0644]
libclc/generic/include/clc/math/hypot.h [new file with mode: 0644]
libclc/generic/include/clc/math/hypot.inc [new file with mode: 0644]
libclc/generic/include/clc/math/ternary_intrin.inc [new file with mode: 0644]
libclc/generic/lib/SOURCES
libclc/generic/lib/math/hypot.cl [new file with mode: 0644]
libclc/generic/lib/math/hypot.inc [new file with mode: 0644]

index 3b78d29..65e4090 100644 (file)
@@ -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/libclc/generic/include/clc/math/fma.h b/libclc/generic/include/clc/math/fma.h
new file mode 100644 (file)
index 0000000..8d862fa
--- /dev/null
@@ -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/libclc/generic/include/clc/math/hypot.h b/libclc/generic/include/clc/math/hypot.h
new file mode 100644 (file)
index 0000000..9ffda48
--- /dev/null
@@ -0,0 +1,2 @@
+#define BODY <clc/math/hypot.inc>
+#include <clc/math/gentype.inc>
diff --git a/libclc/generic/include/clc/math/hypot.inc b/libclc/generic/include/clc/math/hypot.inc
new file mode 100644 (file)
index 0000000..2f97ee5
--- /dev/null
@@ -0,0 +1 @@
+_CLC_OVERLOAD _CLC_DECL GENTYPE hypot(GENTYPE x, GENTYPE y);
diff --git a/libclc/generic/include/clc/math/ternary_intrin.inc b/libclc/generic/include/clc/math/ternary_intrin.inc
new file mode 100644 (file)
index 0000000..7d451e9
--- /dev/null
@@ -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
index 1da1c91..0608116 100644 (file)
@@ -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/libclc/generic/lib/math/hypot.cl b/libclc/generic/lib/math/hypot.cl
new file mode 100644 (file)
index 0000000..dcdc1ed
--- /dev/null
@@ -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/libclc/generic/lib/math/hypot.inc b/libclc/generic/lib/math/hypot.inc
new file mode 100644 (file)
index 0000000..3f529c8
--- /dev/null
@@ -0,0 +1,3 @@
+_CLC_OVERLOAD _CLC_DEF GENTYPE hypot(GENTYPE x, GENTYPE y) {
+  return sqrt(x*x + y*y);
+}