diff options
author | Tom Stellard <thomas.stellard@amd.com> | 2013-10-10 19:08:51 +0000 |
---|---|---|
committer | Tom Stellard <thomas.stellard@amd.com> | 2013-10-10 19:08:51 +0000 |
commit | 6c7b86c1061994c07c9a0dc608f979b3a10fa9da (patch) | |
tree | 0bc0ed8b6dc5ef1ef103b73fb3ad5369f2384b79 /libclc | |
parent | e36e9dec65626dcf54eb0ec2ac1bef6fd605a8f0 (diff) | |
download | bcm5719-llvm-6c7b86c1061994c07c9a0dc608f979b3a10fa9da.tar.gz bcm5719-llvm-6c7b86c1061994c07c9a0dc608f979b3a10fa9da.zip |
Implement nextafter() builtin
There are two implementations of nextafter():
1. Using clang's __builtin_nextafter. Clang replaces this builtin with
a call to nextafter which is part of libm. Therefore, this
implementation will only work for targets with an implementation of
libm (e.g. most CPU targets).
2. The other implementation is written in OpenCL C. This function is
known internally as __clc_nextafter and can be used by targets that
don't have access to libm.
llvm-svn: 192383
Diffstat (limited to 'libclc')
-rwxr-xr-x | libclc/configure.py | 1 | ||||
-rw-r--r-- | libclc/generic/include/clc/clc.h | 6 | ||||
-rw-r--r-- | libclc/generic/include/clc/clcmacro.h | 6 | ||||
-rw-r--r-- | libclc/generic/include/clc/math/clc_nextafter.h | 11 | ||||
-rw-r--r-- | libclc/generic/include/clc/math/nextafter.h | 5 | ||||
-rw-r--r-- | libclc/generic/include/math/clc_nextafter.h | 7 | ||||
-rw-r--r-- | libclc/generic/lib/SOURCES | 2 | ||||
-rw-r--r-- | libclc/generic/lib/math/clc_nextafter.cl | 42 | ||||
-rw-r--r-- | libclc/generic/lib/math/nextafter.cl | 11 | ||||
-rw-r--r-- | libclc/r600/lib/SOURCES | 1 | ||||
-rw-r--r-- | libclc/r600/lib/math/nextafter.cl | 3 |
11 files changed, 95 insertions, 0 deletions
diff --git a/libclc/configure.py b/libclc/configure.py index 1a986475ab2..dbb578bbdb6 100755 --- a/libclc/configure.py +++ b/libclc/configure.py @@ -145,6 +145,7 @@ for target in targets: clang_bc_flags = "-target %s -I`dirname $in` %s " \ "-Dcl_clang_storage_class_specifiers " \ "-Dcl_khr_fp64 " \ + "-D__CLC_INTERNAL " \ "-emit-llvm" % (target, clang_cl_includes) if device['gpu'] != '': clang_bc_flags += ' -mcpu=' + device['gpu'] diff --git a/libclc/generic/include/clc/clc.h b/libclc/generic/include/clc/clc.h index fce9f6edc80..0e87ec78f09 100644 --- a/libclc/generic/include/clc/clc.h +++ b/libclc/generic/include/clc/clc.h @@ -45,6 +45,7 @@ #include <clc/math/log.h> #include <clc/math/log2.h> #include <clc/math/mad.h> +#include <clc/math/nextafter.h> #include <clc/math/pow.h> #include <clc/math/rint.h> #include <clc/math/sin.h> @@ -107,4 +108,9 @@ #include <clc/atomic/atomic_inc.h> #include <clc/atomic/atomic_sub.h> +/* libclc internal defintions */ +#ifdef __CLC_INTERNAL +#include <math/clc_nextafter.h> +#endif + #pragma OPENCL EXTENSION all : disable diff --git a/libclc/generic/include/clc/clcmacro.h b/libclc/generic/include/clc/clcmacro.h index ece0d3b67d5..730073ae1f9 100644 --- a/libclc/generic/include/clc/clcmacro.h +++ b/libclc/generic/include/clc/clcmacro.h @@ -41,6 +41,12 @@ return (RET_TYPE##16)(FUNCTION(x.lo, y.lo), FUNCTION(x.hi, y.hi)); \ } +#define _CLC_DEFINE_BINARY_BUILTIN(RET_TYPE, FUNCTION, BUILTIN, ARG1_TYPE, ARG2_TYPE) \ +_CLC_DEF _CLC_OVERLOAD RET_TYPE FUNCTION(ARG1_TYPE x, ARG2_TYPE y) { \ + return BUILTIN(x, y); \ +} \ +_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, RET_TYPE, FUNCTION, ARG1_TYPE, ARG2_TYPE) + #define _CLC_DEFINE_UNARY_BUILTIN(RET_TYPE, FUNCTION, BUILTIN, ARG1_TYPE) \ _CLC_DEF _CLC_OVERLOAD RET_TYPE FUNCTION(ARG1_TYPE x) { \ return BUILTIN(x); \ diff --git a/libclc/generic/include/clc/math/clc_nextafter.h b/libclc/generic/include/clc/math/clc_nextafter.h new file mode 100644 index 00000000000..81c8f369c3b --- /dev/null +++ b/libclc/generic/include/clc/math/clc_nextafter.h @@ -0,0 +1,11 @@ +#define __CLC_BODY <clc/math/binary_decl.inc> + +#define __CLC_FUNCTION nextafter +#include <clc/math/gentype.inc> +#undef __CLC_FUNCTION + +#define __CLC_FUNCTION __clc_nextafter +#include <clc/math/gentype.inc> +#undef __CLC_FUNCTION + +#undef __CLC_BODY diff --git a/libclc/generic/include/clc/math/nextafter.h b/libclc/generic/include/clc/math/nextafter.h new file mode 100644 index 00000000000..06e1b2a53c5 --- /dev/null +++ b/libclc/generic/include/clc/math/nextafter.h @@ -0,0 +1,5 @@ +#define __CLC_BODY <clc/math/binary_decl.inc> +#define __CLC_FUNCTION nextafter +#include <clc/math/gentype.inc> +#undef __CLC_FUNCTION +#undef __CLC_BODY diff --git a/libclc/generic/include/math/clc_nextafter.h b/libclc/generic/include/math/clc_nextafter.h new file mode 100644 index 00000000000..2b674b70795 --- /dev/null +++ b/libclc/generic/include/math/clc_nextafter.h @@ -0,0 +1,7 @@ +#define __CLC_BODY <clc/math/binary_decl.inc> +#define __CLC_FUNCTION __clc_nextafter + +#include <clc/math/gentype.inc> + +#undef __CLC_BODY +#undef __CLC_FUNCTION diff --git a/libclc/generic/lib/SOURCES b/libclc/generic/lib/SOURCES index 383a66e8ad3..e1a29729776 100644 --- a/libclc/generic/lib/SOURCES +++ b/libclc/generic/lib/SOURCES @@ -26,6 +26,8 @@ math/fmax.cl math/fmin.cl math/hypot.cl math/mad.cl +math/clc_nextafter.cl +math/nextafter.cl relational/any.cl relational/isnan.cl shared/clamp.cl diff --git a/libclc/generic/lib/math/clc_nextafter.cl b/libclc/generic/lib/math/clc_nextafter.cl new file mode 100644 index 00000000000..92b990d1383 --- /dev/null +++ b/libclc/generic/lib/math/clc_nextafter.cl @@ -0,0 +1,42 @@ +#include <clc/clc.h> + +// This file provides OpenCL C implementations of nextafter for targets that +// don't support the clang builtin. + +#define FLT_NAN 0.0f/0.0f + +#define NEXTAFTER(FLOAT_TYPE, UINT_TYPE, NAN, ZERO, NEXTAFTER_ZERO) \ +_CLC_OVERLOAD _CLC_DEF FLOAT_TYPE __clc_nextafter(FLOAT_TYPE x, FLOAT_TYPE y) { \ + union { \ + FLOAT_TYPE f; \ + UINT_TYPE i; \ + } next; \ + if (isnan(x) || isnan(y)) { \ + return NAN; \ + } \ + if (x == y) { \ + return y; \ + } \ + next.f = x; \ + if (x < y) { \ + next.i++; \ + } else { \ + if (next.f == ZERO) { \ + next.i = NEXTAFTER_ZERO; \ + } else { \ + next.i--; \ + } \ + } \ + return next.f; \ +} + +NEXTAFTER(float, uint, FLT_NAN, 0.0f, 0x80000001) +_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, __clc_nextafter, float, float) + +#ifdef cl_khr_fp64 +#pragma OPENCL EXTENSION cl_khr_fp64 : enable +#define DBL_NAN 0.0/0.0 + +NEXTAFTER(double, ulong, DBL_NAN, 0.0, 0x8000000000000001) +_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, __clc_nextafter, double, double) +#endif diff --git a/libclc/generic/lib/math/nextafter.cl b/libclc/generic/lib/math/nextafter.cl new file mode 100644 index 00000000000..1a7f1699bdc --- /dev/null +++ b/libclc/generic/lib/math/nextafter.cl @@ -0,0 +1,11 @@ +#include <clc/clc.h> + +_CLC_DEFINE_BINARY_BUILTIN(float, nextafter, __builtin_nextafterf, float, float) + +#ifdef cl_khr_fp64 + +#pragma OPENCL EXTENSION cl_khr_fp64 : enable + +_CLC_DEFINE_BINARY_BUILTIN(double, nextafter, __builtin_nextafter, double, double) + +#endif diff --git a/libclc/r600/lib/SOURCES b/libclc/r600/lib/SOURCES index de30f6e0038..aac6d8f9a74 100644 --- a/libclc/r600/lib/SOURCES +++ b/libclc/r600/lib/SOURCES @@ -1,4 +1,5 @@ atomic/atomic.cl +math/nextafter.cl workitem/get_num_groups.ll workitem/get_group_id.ll workitem/get_local_size.ll diff --git a/libclc/r600/lib/math/nextafter.cl b/libclc/r600/lib/math/nextafter.cl new file mode 100644 index 00000000000..54bed5f04a0 --- /dev/null +++ b/libclc/r600/lib/math/nextafter.cl @@ -0,0 +1,3 @@ +#include <clc/clc.h> + +_CLC_DEFINE_BINARY_BUILTIN(float, nextafter, __clc_nextafter, float, float) |