[libclc] r332677 - Add initial support for half precision builtins
Jan Vesely via cfe-commits
cfe-commits at lists.llvm.org
Thu May 17 15:55:30 PDT 2018
Author: jvesely
Date: Thu May 17 15:55:30 2018
New Revision: 332677
URL: http://llvm.org/viewvc/llvm-project?rev=332677&view=rev
Log:
Add initial support for half precision builtins
v2: fix fmax implementation
use consistent checks for __CLC_FP_SIZE
add missing TODOs
fix whitespace in definitions.h
v3: undef ZERO in modf.inc
Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
reviewer: Jeroen Ketema <j.ketema at xs4all.nl>
Reviewed-by: Aaron Watry <awatry at gmail.com>
Tested-by: Aaron Watry <awatry at gmail.com>
Modified:
libclc/trunk/amdgcn/lib/math/fmax.cl
libclc/trunk/amdgcn/lib/math/fmin.cl
libclc/trunk/amdgpu/lib/math/nextafter.cl
libclc/trunk/amdgpu/lib/math/sqrt.cl
libclc/trunk/generic/include/clc/as_type.h
libclc/trunk/generic/include/clc/async/gentype.inc
libclc/trunk/generic/include/clc/float/definitions.h
libclc/trunk/generic/include/clc/geometric/floatn.inc
libclc/trunk/generic/include/clc/math/binary_intrin.inc
libclc/trunk/generic/include/clc/math/gentype.inc
libclc/trunk/generic/include/clc/math/nan.inc
libclc/trunk/generic/include/clc/math/ternary_intrin.inc
libclc/trunk/generic/include/clc/math/unary_intrin.inc
libclc/trunk/generic/include/clc/relational/floatn.inc
libclc/trunk/generic/include/clc/relational/isequal.h
libclc/trunk/generic/include/clc/relational/isinf.h
libclc/trunk/generic/include/clc/relational/isnan.h
libclc/trunk/generic/include/math/clc_ldexp.h
libclc/trunk/generic/lib/geometric/dot.cl
libclc/trunk/generic/lib/geometric/length.cl
libclc/trunk/generic/lib/math/acos.inc
libclc/trunk/generic/lib/math/asin.inc
libclc/trunk/generic/lib/math/clc_nextafter.cl
libclc/trunk/generic/lib/math/clc_sqrt_impl.inc
libclc/trunk/generic/lib/math/clc_sw_binary.inc
libclc/trunk/generic/lib/math/clc_sw_unary.inc
libclc/trunk/generic/lib/math/copysign.cl
libclc/trunk/generic/lib/math/fmax.cl
libclc/trunk/generic/lib/math/fmax.inc
libclc/trunk/generic/lib/math/fmin.cl
libclc/trunk/generic/lib/math/fmin.inc
libclc/trunk/generic/lib/math/fract.inc
libclc/trunk/generic/lib/math/ldexp.cl
libclc/trunk/generic/lib/math/ldexp.inc
libclc/trunk/generic/lib/math/lgamma_r.inc
libclc/trunk/generic/lib/math/modf.inc
libclc/trunk/generic/lib/math/nan.inc
libclc/trunk/generic/lib/math/pown.inc
libclc/trunk/generic/lib/math/remquo.inc
libclc/trunk/generic/lib/math/rootn.inc
libclc/trunk/generic/lib/math/sincos.inc
libclc/trunk/generic/lib/math/sqrt.cl
libclc/trunk/generic/lib/relational/isequal.cl
libclc/trunk/generic/lib/relational/isfinite.cl
libclc/trunk/generic/lib/relational/isgreater.cl
libclc/trunk/generic/lib/relational/isgreaterequal.cl
libclc/trunk/generic/lib/relational/isinf.cl
libclc/trunk/generic/lib/relational/isless.cl
libclc/trunk/generic/lib/relational/islessequal.cl
libclc/trunk/generic/lib/relational/islessgreater.cl
libclc/trunk/generic/lib/relational/isnan.cl
libclc/trunk/generic/lib/relational/isnormal.cl
libclc/trunk/generic/lib/relational/isnotequal.cl
libclc/trunk/generic/lib/relational/isordered.cl
libclc/trunk/generic/lib/relational/isunordered.cl
libclc/trunk/generic/lib/relational/signbit.cl
libclc/trunk/generic/lib/shared/vstore_half.inc
Modified: libclc/trunk/amdgcn/lib/math/fmax.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/amdgcn/lib/math/fmax.cl?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/amdgcn/lib/math/fmax.cl (original)
+++ libclc/trunk/amdgcn/lib/math/fmax.cl Thu May 17 15:55:30 2018
@@ -26,6 +26,21 @@ _CLC_DEF _CLC_OVERLOAD double fmax(doubl
_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, fmax, double, double)
#endif
+#ifdef cl_khr_fp16
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+_CLC_DEF _CLC_OVERLOAD half fmax(half x, half y)
+{
+ if (isnan(x))
+ return y;
+ if (isnan(y))
+ return x;
+ return (y < x) ? x : y;
+}
+_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, half, fmax, half, half)
+
+#endif
#define __CLC_BODY <../../../generic/lib/math/fmax.inc>
#include <clc/math/gentype.inc>
Modified: libclc/trunk/amdgcn/lib/math/fmin.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/amdgcn/lib/math/fmin.cl?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/amdgcn/lib/math/fmin.cl (original)
+++ libclc/trunk/amdgcn/lib/math/fmin.cl Thu May 17 15:55:30 2018
@@ -26,6 +26,21 @@ _CLC_DEF _CLC_OVERLOAD double fmin(doubl
_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, fmin, double, double)
#endif
+#ifdef cl_khr_fp16
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+_CLC_DEF _CLC_OVERLOAD half fmin(half x, half y)
+{
+ if (isnan(x))
+ return y;
+ if (isnan(y))
+ return x;
+ return (y < x) ? y : x;
+}
+_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, half, fmin, half, half)
+
+#endif
#define __CLC_BODY <../../../generic/lib/math/fmin.inc>
#include <clc/math/gentype.inc>
Modified: libclc/trunk/amdgpu/lib/math/nextafter.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/amdgpu/lib/math/nextafter.cl?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/amdgpu/lib/math/nextafter.cl (original)
+++ libclc/trunk/amdgpu/lib/math/nextafter.cl Thu May 17 15:55:30 2018
@@ -8,3 +8,8 @@ _CLC_DEFINE_BINARY_BUILTIN(float, nextaf
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
_CLC_DEFINE_BINARY_BUILTIN(double, nextafter, __clc_nextafter, double, double)
#endif
+
+#ifdef cl_khr_fp16
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+_CLC_DEFINE_BINARY_BUILTIN(half, nextafter, __clc_nextafter, half, half)
+#endif
Modified: libclc/trunk/amdgpu/lib/math/sqrt.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/amdgpu/lib/math/sqrt.cl?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/amdgpu/lib/math/sqrt.cl (original)
+++ libclc/trunk/amdgpu/lib/math/sqrt.cl Thu May 17 15:55:30 2018
@@ -26,6 +26,13 @@
_CLC_DEFINE_UNARY_BUILTIN(float, sqrt, __clc_sqrt, float)
+#ifdef cl_khr_fp16
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+_CLC_DEFINE_UNARY_BUILTIN(half, sqrt, __clc_sqrt, half)
+
+#endif
+
#ifdef cl_khr_fp64
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
Modified: libclc/trunk/generic/include/clc/as_type.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/as_type.h?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/include/clc/as_type.h (original)
+++ libclc/trunk/generic/include/clc/as_type.h Thu May 17 15:55:30 2018
@@ -66,3 +66,12 @@
#define as_double8(x) __builtin_astype(x, double8)
#define as_double16(x) __builtin_astype(x, double16)
#endif
+
+#ifdef cl_khr_fp16
+#define as_half(x) __builtin_astype(x, half)
+#define as_half2(x) __builtin_astype(x, half2)
+#define as_half3(x) __builtin_astype(x, half3)
+#define as_half4(x) __builtin_astype(x, half4)
+#define as_half8(x) __builtin_astype(x, half8)
+#define as_half16(x) __builtin_astype(x, half16)
+#endif
Modified: libclc/trunk/generic/include/clc/async/gentype.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/async/gentype.inc?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/include/clc/async/gentype.inc (original)
+++ libclc/trunk/generic/include/clc/async/gentype.inc Thu May 17 15:55:30 2018
@@ -204,4 +204,29 @@
#endif
+#ifdef cl_khr_fp16
+#pragma OPENCL EXTENSION cl_khr_fp16: enable
+
+#define __CLC_GENTYPE half
+#include __CLC_BODY
+#undef __CLC_GENTYPE
+
+#define __CLC_GENTYPE half2
+#include __CLC_BODY
+#undef __CLC_GENTYPE
+
+#define __CLC_GENTYPE half4
+#include __CLC_BODY
+#undef __CLC_GENTYPE
+
+#define __CLC_GENTYPE half8
+#include __CLC_BODY
+#undef __CLC_GENTYPE
+
+#define __CLC_GENTYPE half16
+#include __CLC_BODY
+#undef __CLC_GENTYPE
+
+#endif
+
#undef __CLC_BODY
Modified: libclc/trunk/generic/include/clc/float/definitions.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/float/definitions.h?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/include/clc/float/definitions.h (original)
+++ libclc/trunk/generic/include/clc/float/definitions.h Thu May 17 15:55:30 2018
@@ -64,7 +64,7 @@
#define M_SQRT1_2 0x1.6a09e667f3bcdp-1
#ifdef __CLC_INTERNAL
-#define M_LOG210 0x1.a934f0979a371p+1
+#define M_LOG210 0x1.a934f0979a371p+1
#endif
#endif
@@ -80,6 +80,11 @@
#define HALF_MIN_10_EXP -4
#define HALF_MIN_EXP -13
+#define HALF_RADIX 2
+#define HALF_MAX 0x1.ffcp15h
+#define HALF_MIN 0x1.0p-14h
+#define HALF_EPSILON 0x1.0p-10h
+
#endif
#endif
Modified: libclc/trunk/generic/include/clc/geometric/floatn.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/geometric/floatn.inc?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/include/clc/geometric/floatn.inc (original)
+++ libclc/trunk/generic/include/clc/geometric/floatn.inc Thu May 17 15:55:30 2018
@@ -53,4 +53,35 @@
#endif
#endif
+#ifndef __FLOAT_ONLY
+#ifdef cl_khr_fp16
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+#define __CLC_FLOAT half
+#define __CLC_FPSIZE 16
+
+#define __CLC_FLOATN half
+#define __CLC_SCALAR
+#include __CLC_BODY
+#undef __CLC_FLOATN
+#undef __CLC_SCALAR
+
+#define __CLC_FLOATN half2
+#include __CLC_BODY
+#undef __CLC_FLOATN
+
+#define __CLC_FLOATN half3
+#include __CLC_BODY
+#undef __CLC_FLOATN
+
+#define __CLC_FLOATN half4
+#include __CLC_BODY
+#undef __CLC_FLOATN
+
+#undef __CLC_FLOAT
+#undef __CLC_FPSIZE
+
+#endif
+#endif
+
#undef __CLC_BODY
Modified: libclc/trunk/generic/include/clc/math/binary_intrin.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/binary_intrin.inc?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/include/clc/math/binary_intrin.inc (original)
+++ libclc/trunk/generic/include/clc/math/binary_intrin.inc Thu May 17 15:55:30 2018
@@ -15,5 +15,15 @@ _CLC_OVERLOAD double8 __CLC_FUNCTION(dou
_CLC_OVERLOAD double16 __CLC_FUNCTION(double16, double16) __asm(__CLC_INTRINSIC ".v16f64");
#endif
+#ifdef cl_khr_fp16
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+_CLC_OVERLOAD half __CLC_FUNCTION(half, half) __asm(__CLC_INTRINSIC ".f16");
+_CLC_OVERLOAD half2 __CLC_FUNCTION(half2, half2) __asm(__CLC_INTRINSIC ".v2f16");
+_CLC_OVERLOAD half3 __CLC_FUNCTION(half3, half3) __asm(__CLC_INTRINSIC ".v3f16");
+_CLC_OVERLOAD half4 __CLC_FUNCTION(half4, half4) __asm(__CLC_INTRINSIC ".v4f16");
+_CLC_OVERLOAD half8 __CLC_FUNCTION(half8, half8) __asm(__CLC_INTRINSIC ".v8f16");
+_CLC_OVERLOAD half16 __CLC_FUNCTION(half16, half16) __asm(__CLC_INTRINSIC ".v16f16");
+#endif
+
#undef __CLC_FUNCTION
#undef __CLC_INTRINSIC
Modified: libclc/trunk/generic/include/clc/math/gentype.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/gentype.inc?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/include/clc/math/gentype.inc (original)
+++ libclc/trunk/generic/include/clc/math/gentype.inc Thu May 17 15:55:30 2018
@@ -110,6 +110,66 @@
#undef __CLC_FPSIZE
#undef __CLC_SCALAR_GENTYPE
#endif
+#endif
-#undef __CLC_BODY
+#ifndef __FLOAT_ONLY
+#ifdef cl_khr_fp16
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+#define __CLC_SCALAR_GENTYPE half
+#define __CLC_FPSIZE 16
+
+#define __CLC_SCALAR
+#define __CLC_GENTYPE half
+#define __CLC_INTN int
+#include __CLC_BODY
+#undef __CLC_GENTYPE
+#undef __CLC_INTN
+#undef __CLC_SCALAR
+
+#define __CLC_GENTYPE half2
+#define __CLC_INTN int2
+#define __CLC_VECSIZE 2
+#include __CLC_BODY
+#undef __CLC_VECSIZE
+#undef __CLC_GENTYPE
+#undef __CLC_INTN
+
+#define __CLC_GENTYPE half3
+#define __CLC_INTN int3
+#define __CLC_VECSIZE 3
+#include __CLC_BODY
+#undef __CLC_VECSIZE
+#undef __CLC_GENTYPE
+#undef __CLC_INTN
+
+#define __CLC_GENTYPE half4
+#define __CLC_INTN int4
+#define __CLC_VECSIZE 4
+#include __CLC_BODY
+#undef __CLC_VECSIZE
+#undef __CLC_GENTYPE
+#undef __CLC_INTN
+
+#define __CLC_GENTYPE half8
+#define __CLC_INTN int8
+#define __CLC_VECSIZE 8
+#include __CLC_BODY
+#undef __CLC_VECSIZE
+#undef __CLC_GENTYPE
+#undef __CLC_INTN
+
+#define __CLC_GENTYPE half16
+#define __CLC_INTN int16
+#define __CLC_VECSIZE 16
+#include __CLC_BODY
+#undef __CLC_VECSIZE
+#undef __CLC_GENTYPE
+#undef __CLC_INTN
+
+#undef __CLC_FPSIZE
+#undef __CLC_SCALAR_GENTYPE
#endif
+#endif
+
+#undef __CLC_BODY
Modified: libclc/trunk/generic/include/clc/math/nan.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/nan.inc?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/include/clc/math/nan.inc (original)
+++ libclc/trunk/generic/include/clc/math/nan.inc Thu May 17 15:55:30 2018
@@ -4,8 +4,10 @@
#if __CLC_FPSIZE == 64
#define __CLC_NATN __CLC_XCONCAT(ulong, __CLC_VECSIZE)
-#else
+#elif __CLC_FPSIZE == 32
#define __CLC_NATN __CLC_XCONCAT(uint, __CLC_VECSIZE)
+#elif __CLC_FPSIZE == 16
+#define __CLC_NATN __CLC_XCONCAT(ushort, __CLC_VECSIZE)
#endif
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE nan(__CLC_NATN code);
Modified: libclc/trunk/generic/include/clc/math/ternary_intrin.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/ternary_intrin.inc?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/include/clc/math/ternary_intrin.inc (original)
+++ libclc/trunk/generic/include/clc/math/ternary_intrin.inc Thu May 17 15:55:30 2018
@@ -15,5 +15,16 @@ _CLC_OVERLOAD double8 __CLC_FUNCTION(dou
_CLC_OVERLOAD double16 __CLC_FUNCTION(double16, double16, double16) __asm(__CLC_INTRINSIC ".v16f64");
#endif
+#ifdef cl_khr_fp16
+#pragma OPENCL EXTENSION cl_khr_fp16: enable
+_CLC_OVERLOAD half __CLC_FUNCTION(half, half, half) __asm(__CLC_INTRINSIC ".f16");
+_CLC_OVERLOAD half2 __CLC_FUNCTION(half2, half2, half2) __asm(__CLC_INTRINSIC ".v2f16");
+_CLC_OVERLOAD half3 __CLC_FUNCTION(half3, half3, half3) __asm(__CLC_INTRINSIC ".v3f16");
+_CLC_OVERLOAD half4 __CLC_FUNCTION(half4, half4, half4) __asm(__CLC_INTRINSIC ".v4f16");
+_CLC_OVERLOAD half8 __CLC_FUNCTION(half8, half8, half8) __asm(__CLC_INTRINSIC ".v8f16");
+_CLC_OVERLOAD half16 __CLC_FUNCTION(half16, half16, half16) __asm(__CLC_INTRINSIC ".v16f16");
+#endif
+
+
#undef __CLC_FUNCTION
#undef __CLC_INTRINSIC
Modified: libclc/trunk/generic/include/clc/math/unary_intrin.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/unary_intrin.inc?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/include/clc/math/unary_intrin.inc (original)
+++ libclc/trunk/generic/include/clc/math/unary_intrin.inc Thu May 17 15:55:30 2018
@@ -15,5 +15,15 @@ _CLC_OVERLOAD double8 __CLC_FUNCTION(dou
_CLC_OVERLOAD double16 __CLC_FUNCTION(double16 d) __asm(__CLC_INTRINSIC ".v16f64");
#endif
+#ifdef cl_khr_fp16
+#pragma OPENCL EXTENSION cl_khr_fp16: enable
+_CLC_OVERLOAD half __CLC_FUNCTION(half d) __asm(__CLC_INTRINSIC ".f16");
+_CLC_OVERLOAD half2 __CLC_FUNCTION(half2 d) __asm(__CLC_INTRINSIC ".v2f16");
+_CLC_OVERLOAD half3 __CLC_FUNCTION(half3 d) __asm(__CLC_INTRINSIC ".v3f16");
+_CLC_OVERLOAD half4 __CLC_FUNCTION(half4 d) __asm(__CLC_INTRINSIC ".v4f16");
+_CLC_OVERLOAD half8 __CLC_FUNCTION(half8 d) __asm(__CLC_INTRINSIC ".v8f16");
+_CLC_OVERLOAD half16 __CLC_FUNCTION(half16 d) __asm(__CLC_INTRINSIC ".v16f16");
+#endif
+
#undef __CLC_FUNCTION
#undef __CLC_INTRINSIC
Modified: libclc/trunk/generic/include/clc/relational/floatn.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/relational/floatn.inc?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/include/clc/relational/floatn.inc (original)
+++ libclc/trunk/generic/include/clc/relational/floatn.inc Thu May 17 15:55:30 2018
@@ -39,6 +39,7 @@
#undef __CLC_INT
#ifdef cl_khr_fp64
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
#define __CLC_FLOATN double
#define __CLC_INTN int
@@ -75,6 +76,46 @@
#include __CLC_BODY
#undef __CLC_INTN
#undef __CLC_FLOATN
+
+#endif
+#ifdef cl_khr_fp16
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+#define __CLC_FLOATN half
+#define __CLC_INTN int
+#include __CLC_BODY
+#undef __CLC_INTN
+#undef __CLC_FLOATN
+
+#define __CLC_FLOATN half2
+#define __CLC_INTN short2
+#include __CLC_BODY
+#undef __CLC_INTN
+#undef __CLC_FLOATN
+
+#define __CLC_FLOATN half3
+#define __CLC_INTN short3
+#include __CLC_BODY
+#undef __CLC_INTN
+#undef __CLC_FLOATN
+
+#define __CLC_FLOATN half4
+#define __CLC_INTN short4
+#include __CLC_BODY
+#undef __CLC_INTN
+#undef __CLC_FLOATN
+
+#define __CLC_FLOATN half8
+#define __CLC_INTN short8
+#include __CLC_BODY
+#undef __CLC_INTN
+#undef __CLC_FLOATN
+
+#define __CLC_FLOATN half16
+#define __CLC_INTN short16
+#include __CLC_BODY
+#undef __CLC_INTN
+#undef __CLC_FLOATN
#endif
Modified: libclc/trunk/generic/include/clc/relational/isequal.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/relational/isequal.h?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/include/clc/relational/isequal.h (original)
+++ libclc/trunk/generic/include/clc/relational/isequal.h Thu May 17 15:55:30 2018
@@ -15,6 +15,10 @@ _CLC_VECTOR_ISEQUAL_DECL(float, int)
_CLC_ISEQUAL_DECL(double, int)
_CLC_VECTOR_ISEQUAL_DECL(double, long)
#endif
+#ifdef cl_khr_fp16
+_CLC_ISEQUAL_DECL(half, int)
+_CLC_VECTOR_ISEQUAL_DECL(half, short)
+#endif
#undef _CLC_ISEQUAL_DECL
#undef _CLC_VECTOR_ISEQUAL_DEC
Modified: libclc/trunk/generic/include/clc/relational/isinf.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/relational/isinf.h?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/include/clc/relational/isinf.h (original)
+++ libclc/trunk/generic/include/clc/relational/isinf.h Thu May 17 15:55:30 2018
@@ -17,5 +17,10 @@ _CLC_ISINF_DECL(int, double)
_CLC_VECTOR_ISINF_DECL(long, double)
#endif
+#ifdef cl_khr_fp16
+_CLC_ISINF_DECL(int, half)
+_CLC_VECTOR_ISINF_DECL(short, half)
+#endif
+
#undef _CLC_ISINF_DECL
#undef _CLC_VECTOR_ISINF_DECL
Modified: libclc/trunk/generic/include/clc/relational/isnan.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/relational/isnan.h?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/include/clc/relational/isnan.h (original)
+++ libclc/trunk/generic/include/clc/relational/isnan.h Thu May 17 15:55:30 2018
@@ -17,5 +17,10 @@ _CLC_ISNAN_DECL(int, double)
_CLC_VECTOR_ISNAN_DECL(long, double)
#endif
+#ifdef cl_khr_fp16
+_CLC_ISNAN_DECL(int, half)
+_CLC_VECTOR_ISNAN_DECL(short, half)
+#endif
+
#undef _CLC_ISNAN_DECL
#undef _CLC_VECTOR_ISNAN_DECL
Modified: libclc/trunk/generic/include/math/clc_ldexp.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/math/clc_ldexp.h?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/include/math/clc_ldexp.h (original)
+++ libclc/trunk/generic/include/math/clc_ldexp.h Thu May 17 15:55:30 2018
@@ -1,6 +1,11 @@
_CLC_DEF _CLC_OVERLOAD float __clc_ldexp(float, int);
#ifdef cl_khr_fp64
- #pragma OPENCL EXTENSION cl_khr_fp64 : enable
- _CLC_DEF _CLC_OVERLOAD double __clc_ldexp(double, int);
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+_CLC_DEF _CLC_OVERLOAD double __clc_ldexp(double, int);
+#endif
+
+#ifdef cl_khr_fp16
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+_CLC_DEF _CLC_OVERLOAD float __clc_ldexp(half, int);
#endif
Modified: libclc/trunk/generic/lib/geometric/dot.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/geometric/dot.cl?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/geometric/dot.cl (original)
+++ libclc/trunk/generic/lib/geometric/dot.cl Thu May 17 15:55:30 2018
@@ -37,3 +37,25 @@ _CLC_OVERLOAD _CLC_DEF double dot(double
}
#endif
+
+#ifdef cl_khr_fp16
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+_CLC_OVERLOAD _CLC_DEF half dot(half p0, half p1) {
+ return p0*p1;
+}
+
+_CLC_OVERLOAD _CLC_DEF half dot(half2 p0, half2 p1) {
+ return p0.x*p1.x + p0.y*p1.y;
+}
+
+_CLC_OVERLOAD _CLC_DEF half dot(half3 p0, half3 p1) {
+ return p0.x*p1.x + p0.y*p1.y + p0.z*p1.z;
+}
+
+_CLC_OVERLOAD _CLC_DEF half dot(half4 p0, half4 p1) {
+ return p0.x*p1.x + p0.y*p1.y + p0.z*p1.z + p0.w*p1.w;
+}
+
+#endif
Modified: libclc/trunk/generic/lib/geometric/length.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/geometric/length.cl?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/geometric/length.cl (original)
+++ libclc/trunk/generic/lib/geometric/length.cl Thu May 17 15:55:30 2018
@@ -79,9 +79,47 @@ _CLC_OVERLOAD _CLC_DEF double length(dou
V_DLENGTH(p);
}
-_CLC_OVERLOAD _CLC_DEF double
-length(double4 p) {
+_CLC_OVERLOAD _CLC_DEF double length(double4 p) {
V_DLENGTH(p);
}
#endif
+
+#ifdef cl_khr_fp16
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+_CLC_OVERLOAD _CLC_DEF half length(half p){
+ return fabs(p);
+}
+
+// Only available in CLC1.2
+#ifndef HALF_MIN
+#define HALF_MIN 0x1.0p-14h
+#endif
+
+#define V_HLENGTH(p) \
+ half l2 = dot(p, p); \
+ \
+ if (l2 < HALF_MIN) { \
+ p *= 0x1.0p+12h; \
+ return sqrt(dot(p, p)) * 0x1.0p-12h; \
+ } else if (l2 == INFINITY) { \
+ p *= 0x1.0p-7h; \
+ return sqrt(dot(p, p)) * 0x1.0p+7h; \
+ } \
+ \
+ return sqrt(l2);
+
+_CLC_OVERLOAD _CLC_DEF half length(half2 p) {
+ V_HLENGTH(p);
+}
+
+_CLC_OVERLOAD _CLC_DEF half length(half3 p) {
+ V_HLENGTH(p);
+}
+
+_CLC_OVERLOAD _CLC_DEF half length(half4 p) {
+ V_HLENGTH(p);
+}
+
+#endif
Modified: libclc/trunk/generic/lib/math/acos.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/acos.inc?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/math/acos.inc (original)
+++ libclc/trunk/generic/lib/math/acos.inc Thu May 17 15:55:30 2018
@@ -11,10 +11,15 @@
* precision of #4 may be better.
*/
-#if __CLC_FPSIZE == 32
-#define __CLC_CONST(x) x ## f
-#else
+// TODO: Enable half precision when atan2 is implemented
+#if __CLC_FPSIZE > 16
+
+#if __CLC_FPSIZE == 64
#define __CLC_CONST(x) x
+#elif __CLC_FPSIZE == 32
+#define __CLC_CONST(x) x ## f
+#elif __CLC_FPSIZE == 16
+#define __CLC_CONST(x) x ## h
#endif
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE acos(__CLC_GENTYPE x) {
@@ -27,3 +32,5 @@ _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE aco
}
#undef __CLC_CONST
+
+#endif
Modified: libclc/trunk/generic/lib/math/asin.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/asin.inc?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/math/asin.inc (original)
+++ libclc/trunk/generic/lib/math/asin.inc Thu May 17 15:55:30 2018
@@ -1,12 +1,18 @@
+// TODO: Enable half precision when atan2 is implemented
+#if __CLC_FPSIZE > 16
-#if __CLC_FPSIZE == 32
-#define __CLC_CONST(x) x ## f
-#else
+#if __CLC_FPSIZE == 64
#define __CLC_CONST(x) x
+#elif __CLC_FPSIZE == 32
+#define __CLC_CONST(x) x ## f
+#elif __CLC_FPSIZE == 16
+#define __CLC_CONST(x) x ## h
#endif
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE asin(__CLC_GENTYPE x) {
- return atan2(x, sqrt( (__CLC_GENTYPE)__CLC_CONST(1.0) -(x*x) ));
+ return atan2(x, sqrt( (__CLC_GENTYPE)__CLC_CONST(1.0) - (x*x) ));
}
#undef __CLC_CONST
+
+#endif
Modified: libclc/trunk/generic/lib/math/clc_nextafter.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/clc_nextafter.cl?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/math/clc_nextafter.cl (original)
+++ libclc/trunk/generic/lib/math/clc_nextafter.cl Thu May 17 15:55:30 2018
@@ -37,3 +37,10 @@ _CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC
NEXTAFTER(double, ulong, long)
_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, __clc_nextafter, double, double)
#endif
+
+#ifdef cl_khr_fp16
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+NEXTAFTER(half, ushort, short)
+_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, half, __clc_nextafter, half, half)
+#endif
Modified: libclc/trunk/generic/lib/math/clc_sqrt_impl.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/clc_sqrt_impl.inc?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/math/clc_sqrt_impl.inc (original)
+++ libclc/trunk/generic/lib/math/clc_sqrt_impl.inc Thu May 17 15:55:30 2018
@@ -20,14 +20,15 @@
* THE SOFTWARE.
*/
-#if __CLC_FPSIZE == 32
-#define __CLC_NAN NAN
-#define ZERO 0.0f
-#elif __CLC_FPSIZE == 64
+#if __CLC_FPSIZE == 64
#define __CLC_NAN __builtin_nan("")
#define ZERO 0.0
-#else
-#error "Invalid value for __CLC_FPSIZE"
+#elif __CLC_FPSIZE == 32
+#define __CLC_NAN NAN
+#define ZERO 0.0f
+#elif __CLC_FPSIZE == 16
+#define __CLC_NAN (half)NAN
+#define ZERO 0.0h
#endif
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_sqrt(__CLC_GENTYPE val) {
Modified: libclc/trunk/generic/lib/math/clc_sw_binary.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/clc_sw_binary.inc?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/math/clc_sw_binary.inc (original)
+++ libclc/trunk/generic/lib/math/clc_sw_binary.inc Thu May 17 15:55:30 2018
@@ -2,8 +2,11 @@
#define __CLC_SW_FUNC(x) __CLC_CONCAT(__clc_, x)
+// TODO: Enable half precision when the sw routine is implemented
+#if __CLC_FPSIZE > 16
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __CLC_FUNC(__CLC_GENTYPE x, __CLC_GENTYPE y) {
return __CLC_SW_FUNC(__CLC_FUNC)(x, y);
}
+#endif
#undef __CLC_SW_FUNC
Modified: libclc/trunk/generic/lib/math/clc_sw_unary.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/clc_sw_unary.inc?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/math/clc_sw_unary.inc (original)
+++ libclc/trunk/generic/lib/math/clc_sw_unary.inc Thu May 17 15:55:30 2018
@@ -2,8 +2,11 @@
#define __CLC_SW_FUNC(x) __CLC_CONCAT(__clc_, x)
+// TODO: Enable half precision when the sw routine is implemented
+#if __CLC_FPSIZE > 16
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __CLC_FUNC(__CLC_GENTYPE x) {
return __CLC_SW_FUNC(__CLC_FUNC)(x);
}
+#endif
#undef __CLC_SW_FUNC
Modified: libclc/trunk/generic/lib/math/copysign.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/copysign.cl?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/math/copysign.cl (original)
+++ libclc/trunk/generic/lib/math/copysign.cl Thu May 17 15:55:30 2018
@@ -10,3 +10,18 @@ _CLC_DEFINE_BINARY_BUILTIN(float, copysi
_CLC_DEFINE_BINARY_BUILTIN(double, copysign, __builtin_copysign, double, double)
#endif
+
+#ifdef cl_khr_fp16
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+_CLC_DEF _CLC_OVERLOAD half copysign(half x, half y)
+{
+ ushort sign_x = as_ushort(x) & 0x8000u;
+ ushort unsigned_y = as_ushort(y) & 0x7ffffu;
+
+ return as_half((ushort)(sign_x | unsigned_y));
+}
+_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, half, copysign, half, half)
+
+#endif
Modified: libclc/trunk/generic/lib/math/fmax.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/fmax.cl?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/math/fmax.cl (original)
+++ libclc/trunk/generic/lib/math/fmax.cl Thu May 17 15:55:30 2018
@@ -12,5 +12,21 @@ _CLC_DEFINE_BINARY_BUILTIN(double, fmax,
#endif
+#ifdef cl_khr_fp16
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+_CLC_DEF _CLC_OVERLOAD half fmax(half x, half y)
+{
+ if (isnan(x))
+ return y;
+ if (isnan(y))
+ return x;
+ return (x < y) ? y : x;
+}
+_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, half, fmax, half, half)
+
+#endif
+
#define __CLC_BODY <fmax.inc>
#include <clc/math/gentype.inc>
Modified: libclc/trunk/generic/lib/math/fmax.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/fmax.inc?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/math/fmax.inc (original)
+++ libclc/trunk/generic/lib/math/fmax.inc Thu May 17 15:55:30 2018
@@ -15,4 +15,14 @@ _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE fma
#endif // ifdef cl_khr_fp64
+#ifdef cl_khr_fp16
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE fmax(__CLC_GENTYPE x, half y) {
+ return fmax(x, (__CLC_GENTYPE)((__CLC_SCALAR_GENTYPE)y));
+}
+
+#endif // ifdef cl_khr_fp16
+
#endif // !defined(__CLC_SCALAR)
Modified: libclc/trunk/generic/lib/math/fmin.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/fmin.cl?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/math/fmin.cl (original)
+++ libclc/trunk/generic/lib/math/fmin.cl Thu May 17 15:55:30 2018
@@ -11,6 +11,21 @@ _CLC_DEFINE_BINARY_BUILTIN(float, fmin,
_CLC_DEFINE_BINARY_BUILTIN(double, fmin, __builtin_fmin, double, double);
#endif
+#ifdef cl_khr_fp16
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+_CLC_DEF _CLC_OVERLOAD half fmin(half x, half y)
+{
+ if (isnan(x))
+ return y;
+ if (isnan(y))
+ return x;
+ return (y < x) ? y : x;
+}
+_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, half, fmin, half, half)
+
+#endif
#define __CLC_BODY <fmin.inc>
#include <clc/math/gentype.inc>
Modified: libclc/trunk/generic/lib/math/fmin.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/fmin.inc?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/math/fmin.inc (original)
+++ libclc/trunk/generic/lib/math/fmin.inc Thu May 17 15:55:30 2018
@@ -15,4 +15,14 @@ _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE fmi
#endif // ifdef cl_khr_fp64
+#ifdef cl_khr_fp16
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE fmin(__CLC_GENTYPE x, half y) {
+ return fmin(x, (__CLC_GENTYPE)((__CLC_SCALAR_GENTYPE)y));
+}
+
+#endif // ifdef cl_khr_fp16
+
#endif // !defined(__CLC_SCALAR)
Modified: libclc/trunk/generic/lib/math/fract.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/fract.inc?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/math/fract.inc (original)
+++ libclc/trunk/generic/lib/math/fract.inc Thu May 17 15:55:30 2018
@@ -20,16 +20,21 @@
* THE SOFTWARE.
*/
-#if __CLC_FPSIZE == 32
-#define MIN_CONSTANT 0x1.fffffep-1f
-#else
+#if __CLC_FPSIZE == 64
#define MIN_CONSTANT 0x1.fffffffffffffp-1
+#define ZERO 0.0
+#elif __CLC_FPSIZE == 32
+#define MIN_CONSTANT 0x1.fffffep-1f
+#define ZERO 0.0f
+#elif __CLC_FPSIZE == 16
+#define MIN_CONSTANT 0x1.ffcp-1h
+#define ZERO 0.0h
#endif
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE fract(__CLC_GENTYPE x, private __CLC_GENTYPE *iptr) {
*iptr = floor(x);
__CLC_GENTYPE r = fmin(x - *iptr, MIN_CONSTANT);
- r = isinf(x) ? 0.0f : r;
+ r = isinf(x) ? ZERO : r;
r = isnan(x) ? x : r;
return r;
}
@@ -47,3 +52,4 @@ FRACT_DEF(local);
FRACT_DEF(global);
#undef MIN_CONSTANT
+#undef ZERO
Modified: libclc/trunk/generic/lib/math/ldexp.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/ldexp.cl?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/math/ldexp.cl (original)
+++ libclc/trunk/generic/lib/math/ldexp.cl Thu May 17 15:55:30 2018
@@ -33,7 +33,13 @@ _CLC_DEFINE_BINARY_BUILTIN(float, ldexp,
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
_CLC_DEFINE_BINARY_BUILTIN(double, ldexp, __clc_ldexp, double, int)
+#endif
+
+#ifdef cl_khr_fp16
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+_CLC_DEFINE_BINARY_BUILTIN(half, ldexp, __clc_ldexp, half, int)
#endif
// This defines all the ldexp(GENTYPE, int) variants
Modified: libclc/trunk/generic/lib/math/ldexp.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/ldexp.inc?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/math/ldexp.inc (original)
+++ libclc/trunk/generic/lib/math/ldexp.inc Thu May 17 15:55:30 2018
@@ -20,6 +20,9 @@
* THE SOFTWARE.
*/
+// TODO: Enable half precision when ldexp is implemented.
+#if __CLC_FPSIZE > 16
+
#ifndef __CLC_SCALAR
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE ldexp(__CLC_GENTYPE x, int n) {
@@ -27,3 +30,5 @@ _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE lde
}
#endif
+
+#endif
Modified: libclc/trunk/generic/lib/math/lgamma_r.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/lgamma_r.inc?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/math/lgamma_r.inc (original)
+++ libclc/trunk/generic/lib/math/lgamma_r.inc Thu May 17 15:55:30 2018
@@ -21,10 +21,12 @@
* THE SOFTWARE.
*/
-
+// TODO: Enable half precision when the base version is implemented.
+#if __CLC_FPSIZE > 16
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE lgamma_r(__CLC_GENTYPE x, __CLC_ADDRSPACE __CLC_INTN *iptr) {
__CLC_INTN private_iptr;
__CLC_GENTYPE ret = lgamma_r(x, &private_iptr);
*iptr = private_iptr;
return ret;
}
+#endif
Modified: libclc/trunk/generic/lib/math/modf.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/modf.inc?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/math/modf.inc (original)
+++ libclc/trunk/generic/lib/math/modf.inc Thu May 17 15:55:30 2018
@@ -20,9 +20,17 @@
* THE SOFTWARE.
*/
+#if __CLC_FPSIZE == 64
+#define ZERO 0.0
+#elif __CLC_FPSIZE == 32
+#define ZERO 0.0f
+#elif __CLC_FPSIZE == 16
+#define ZERO 0.0h
+#endif
+
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE modf(__CLC_GENTYPE x, __CLC_GENTYPE *iptr) {
*iptr = trunc(x);
- return copysign(isinf(x) ? 0.0f : x - *iptr, x);
+ return copysign(isinf(x) ? ZERO : x - *iptr, x);
}
#define MODF_DEF(addrspace) \
@@ -35,3 +43,5 @@ _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE mod
MODF_DEF(local);
MODF_DEF(global);
+
+#undef ZERO
Modified: libclc/trunk/generic/lib/math/nan.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/nan.inc?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/math/nan.inc (original)
+++ libclc/trunk/generic/lib/math/nan.inc Thu May 17 15:55:30 2018
@@ -7,11 +7,18 @@ _CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE nan
{
return __CLC_AS_GENTYPE(code | 0x7ff0000000000000ul);
}
-#else
+#elif __CLC_FPSIZE == 32
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE nan(__CLC_XCONCAT(uint, __CLC_VECSIZE) code)
{
return __CLC_AS_GENTYPE(code | 0x7fc00000);
}
+#elif __CLC_FPSIZE == 16
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE nan(__CLC_XCONCAT(ushort, __CLC_VECSIZE) code)
+{
+ const ushort mask = 0x7e00;
+ const __CLC_XCONCAT(ushort, __CLC_VECSIZE) res = code | mask;
+ return __CLC_AS_GENTYPE(res);
+}
#endif
Modified: libclc/trunk/generic/lib/math/pown.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/pown.inc?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/math/pown.inc (original)
+++ libclc/trunk/generic/lib/math/pown.inc Thu May 17 15:55:30 2018
@@ -1,3 +1,6 @@
+// TODO: Enable half precision when the sw routine is implemented
+#if __CLC_FPSIZE > 16
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE pown(__CLC_GENTYPE x, __CLC_INTN y) {
return __clc_pown(x, y);
}
+#endif
Modified: libclc/trunk/generic/lib/math/remquo.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/remquo.inc?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/math/remquo.inc (original)
+++ libclc/trunk/generic/lib/math/remquo.inc Thu May 17 15:55:30 2018
@@ -1,6 +1,9 @@
+// TODO: Enable half precision when the sw routine is implemented
+#if __CLC_FPSIZE > 16
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE remquo(__CLC_GENTYPE x, __CLC_GENTYPE y, __CLC_ADDRESS_SPACE __CLC_INTN *q) {
__CLC_INTN local_q;
__CLC_GENTYPE ret = __clc_remquo(x, y, &local_q);
*q = local_q;
return ret;
}
+#endif
Modified: libclc/trunk/generic/lib/math/rootn.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/rootn.inc?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/math/rootn.inc (original)
+++ libclc/trunk/generic/lib/math/rootn.inc Thu May 17 15:55:30 2018
@@ -1,3 +1,6 @@
+// TODO: Enable half precision when the sw routine is implemented
+#if __CLC_FPSIZE > 16
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE rootn(__CLC_GENTYPE x, __CLC_INTN y) {
return __clc_rootn(x, y);
}
+#endif
Modified: libclc/trunk/generic/lib/math/sincos.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/sincos.inc?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/math/sincos.inc (original)
+++ libclc/trunk/generic/lib/math/sincos.inc Thu May 17 15:55:30 2018
@@ -1,3 +1,5 @@
+// TODO: Enable half precision when sin/cos is implemented
+#if __CLC_FPSIZE > 16
#define __CLC_DECLARE_SINCOS(ADDRSPACE, TYPE) \
_CLC_OVERLOAD _CLC_DEF TYPE sincos (TYPE x, ADDRSPACE TYPE * cosval) { \
*cosval = cos(x); \
@@ -9,3 +11,4 @@ __CLC_DECLARE_SINCOS(local, __CLC_GENTYP
__CLC_DECLARE_SINCOS(private, __CLC_GENTYPE)
#undef __CLC_DECLARE_SINCOS
+#endif
Modified: libclc/trunk/generic/lib/math/sqrt.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/sqrt.cl?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/math/sqrt.cl (original)
+++ libclc/trunk/generic/lib/math/sqrt.cl Thu May 17 15:55:30 2018
@@ -33,3 +33,11 @@ _CLC_DEFINE_UNARY_BUILTIN(float, sqrt, _
_CLC_DEFINE_UNARY_BUILTIN(double, sqrt, __clc_sqrt, double)
#endif
+
+#ifdef cl_khr_fp16
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+_CLC_DEFINE_UNARY_BUILTIN(half, sqrt, __clc_sqrt, half)
+
+#endif
Modified: libclc/trunk/generic/lib/relational/isequal.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/relational/isequal.cl?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/relational/isequal.cl (original)
+++ libclc/trunk/generic/lib/relational/isequal.cl Thu May 17 15:55:30 2018
@@ -26,5 +26,19 @@ _CLC_DEFINE_ISEQUAL(long8, isequal, doub
_CLC_DEFINE_ISEQUAL(long16, isequal, double16, double16)
#endif
+#ifdef cl_khr_fp16
-#undef _CLC_DEFINE_ISEQUAL
\ No newline at end of file
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+// The scalar version of isequal(half) returns an int, but the vector versions
+// return short.
+_CLC_DEFINE_ISEQUAL(int, isequal, half, half)
+_CLC_DEFINE_ISEQUAL(short2, isequal, half2, half2)
+_CLC_DEFINE_ISEQUAL(short3, isequal, half3, half3)
+_CLC_DEFINE_ISEQUAL(short4, isequal, half4, half4)
+_CLC_DEFINE_ISEQUAL(short8, isequal, half8, half8)
+_CLC_DEFINE_ISEQUAL(short16, isequal, half16, half16)
+
+#endif
+
+#undef _CLC_DEFINE_ISEQUAL
Modified: libclc/trunk/generic/lib/relational/isfinite.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/relational/isfinite.cl?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/relational/isfinite.cl (original)
+++ libclc/trunk/generic/lib/relational/isfinite.cl Thu May 17 15:55:30 2018
@@ -16,3 +16,16 @@ _CLC_DEF _CLC_OVERLOAD int isfinite(doub
_CLC_DEFINE_RELATIONAL_UNARY_VEC_ALL(long, isfinite, double)
#endif
+#ifdef cl_khr_fp16
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+// The scalar version of isfinite(half) returns an int, but the vector versions
+// return short.
+_CLC_DEF _CLC_OVERLOAD int isfinite(half x) {
+ return __builtin_isfinite(x);
+}
+
+_CLC_DEFINE_RELATIONAL_UNARY_VEC_ALL(short, isfinite, half)
+
+#endif
Modified: libclc/trunk/generic/lib/relational/isgreater.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/relational/isgreater.cl?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/relational/isgreater.cl (original)
+++ libclc/trunk/generic/lib/relational/isgreater.cl Thu May 17 15:55:30 2018
@@ -20,3 +20,18 @@ _CLC_DEF _CLC_OVERLOAD int isgreater(dou
_CLC_DEFINE_RELATIONAL_BINARY_VEC_ALL(long, isgreater, double, double)
#endif
+
+#ifdef cl_khr_fp16
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+// The scalar version of isgreater(half, half) returns an int, but the vector versions
+// return short.
+
+_CLC_DEF _CLC_OVERLOAD int isgreater(half x, half y){
+ return __builtin_isgreater(x, y);
+}
+
+_CLC_DEFINE_RELATIONAL_BINARY_VEC_ALL(short, isgreater, half, half)
+
+#endif
Modified: libclc/trunk/generic/lib/relational/isgreaterequal.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/relational/isgreaterequal.cl?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/relational/isgreaterequal.cl (original)
+++ libclc/trunk/generic/lib/relational/isgreaterequal.cl Thu May 17 15:55:30 2018
@@ -20,3 +20,17 @@ _CLC_DEF _CLC_OVERLOAD int isgreaterequa
_CLC_DEFINE_RELATIONAL_BINARY_VEC_ALL(long, isgreaterequal, double, double)
#endif
+#ifdef cl_khr_fp16
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+// The scalar version of isgreaterequal(half, half) returns an int, but the vector versions
+// return short.
+
+_CLC_DEF _CLC_OVERLOAD int isgreaterequal(half x, half y){
+ return __builtin_isgreaterequal(x, y);
+}
+
+_CLC_DEFINE_RELATIONAL_BINARY_VEC_ALL(short, isgreaterequal, half, half)
+
+#endif
Modified: libclc/trunk/generic/lib/relational/isinf.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/relational/isinf.cl?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/relational/isinf.cl (original)
+++ libclc/trunk/generic/lib/relational/isinf.cl Thu May 17 15:55:30 2018
@@ -14,5 +14,17 @@ _CLC_DEF _CLC_OVERLOAD int isinf(double
}
_CLC_DEFINE_RELATIONAL_UNARY_VEC_ALL(long, isinf, double)
+#endif
+
+#ifdef cl_khr_fp16
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+// The scalar version of isinf(half) returns an int, but the vector versions
+// return short.
+_CLC_DEF _CLC_OVERLOAD int isinf(half x) {
+ return __builtin_isinf(x);
+}
+_CLC_DEFINE_RELATIONAL_UNARY_VEC_ALL(short, isinf, half)
#endif
Modified: libclc/trunk/generic/lib/relational/isless.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/relational/isless.cl?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/relational/isless.cl (original)
+++ libclc/trunk/generic/lib/relational/isless.cl Thu May 17 15:55:30 2018
@@ -20,3 +20,17 @@ _CLC_DEF _CLC_OVERLOAD int isless(double
_CLC_DEFINE_RELATIONAL_BINARY_VEC_ALL(long, isless, double, double)
#endif
+#ifdef cl_khr_fp16
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+// The scalar version of isless(half, half) returns an int, but the vector versions
+// return short.
+
+_CLC_DEF _CLC_OVERLOAD int isless(half x, half y){
+ return __builtin_isless(x, y);
+}
+
+_CLC_DEFINE_RELATIONAL_BINARY_VEC_ALL(short, isless, half, half)
+
+#endif
Modified: libclc/trunk/generic/lib/relational/islessequal.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/relational/islessequal.cl?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/relational/islessequal.cl (original)
+++ libclc/trunk/generic/lib/relational/islessequal.cl Thu May 17 15:55:30 2018
@@ -20,3 +20,17 @@ _CLC_DEF _CLC_OVERLOAD int islessequal(d
_CLC_DEFINE_RELATIONAL_BINARY_VEC_ALL(long, islessequal, double, double)
#endif
+#ifdef cl_khr_fp16
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+// The scalar version of islessequal(half, half) returns an int, but the vector versions
+// return short.
+
+_CLC_DEF _CLC_OVERLOAD int islessequal(half x, half y){
+ return __builtin_islessequal(x, y);
+}
+
+_CLC_DEFINE_RELATIONAL_BINARY_VEC_ALL(short, islessequal, half, half)
+
+#endif
Modified: libclc/trunk/generic/lib/relational/islessgreater.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/relational/islessgreater.cl?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/relational/islessgreater.cl (original)
+++ libclc/trunk/generic/lib/relational/islessgreater.cl Thu May 17 15:55:30 2018
@@ -20,3 +20,17 @@ _CLC_DEF _CLC_OVERLOAD int islessgreater
_CLC_DEFINE_RELATIONAL_BINARY_VEC_ALL(long, islessgreater, double, double)
#endif
+#ifdef cl_khr_fp16
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+// The scalar version of islessgreater(half, half) returns an int, but the vector versions
+// return short.
+
+_CLC_DEF _CLC_OVERLOAD int islessgreater(half x, half y){
+ return __builtin_islessgreater(x, y);
+}
+
+_CLC_DEFINE_RELATIONAL_BINARY_VEC_ALL(short, islessgreater, half, half)
+
+#endif
Modified: libclc/trunk/generic/lib/relational/isnan.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/relational/isnan.cl?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/relational/isnan.cl (original)
+++ libclc/trunk/generic/lib/relational/isnan.cl Thu May 17 15:55:30 2018
@@ -16,3 +16,17 @@ _CLC_DEF _CLC_OVERLOAD int isnan(double
_CLC_DEFINE_RELATIONAL_UNARY_VEC_ALL(long, isnan, double)
#endif
+
+#ifdef cl_khr_fp16
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+// The scalar version of isnan(half) returns an int, but the vector versions
+// return short.
+_CLC_DEF _CLC_OVERLOAD int isnan(half x) {
+ return __builtin_isnan(x);
+}
+
+_CLC_DEFINE_RELATIONAL_UNARY_VEC_ALL(short, isnan, half)
+
+#endif
Modified: libclc/trunk/generic/lib/relational/isnormal.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/relational/isnormal.cl?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/relational/isnormal.cl (original)
+++ libclc/trunk/generic/lib/relational/isnormal.cl Thu May 17 15:55:30 2018
@@ -16,3 +16,16 @@ _CLC_DEF _CLC_OVERLOAD int isnormal(doub
_CLC_DEFINE_RELATIONAL_UNARY_VEC_ALL(long, isnormal, double)
#endif
+#ifdef cl_khr_fp16
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+// The scalar version of isnormal(half) returns an int, but the vector versions
+// return short.
+_CLC_DEF _CLC_OVERLOAD int isnormal(half x) {
+ return __builtin_isnormal(x);
+}
+
+_CLC_DEFINE_RELATIONAL_UNARY_VEC_ALL(short, isnormal, half)
+
+#endif
Modified: libclc/trunk/generic/lib/relational/isnotequal.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/relational/isnotequal.cl?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/relational/isnotequal.cl (original)
+++ libclc/trunk/generic/lib/relational/isnotequal.cl Thu May 17 15:55:30 2018
@@ -19,5 +19,15 @@ _CLC_DEFINE_ISNOTEQUAL(int, isnotequal,
_CLC_DEFINE_RELATIONAL_BINARY_VEC_ALL(long, isnotequal, double, double)
#endif
+#ifdef cl_khr_fp16
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+// The scalar version of isnotequal(half, half) returns an int, but the vector versions
+// return short.
+
+_CLC_DEFINE_ISNOTEQUAL(int, isnotequal, half, half)
+_CLC_DEFINE_RELATIONAL_BINARY_VEC_ALL(short, isnotequal, half, half)
+
+#endif
#undef _CLC_DEFINE_ISNOTEQUAL
Modified: libclc/trunk/generic/lib/relational/isordered.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/relational/isordered.cl?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/relational/isordered.cl (original)
+++ libclc/trunk/generic/lib/relational/isordered.cl Thu May 17 15:55:30 2018
@@ -19,5 +19,15 @@ _CLC_DEFINE_ISORDERED(int, isordered, do
_CLC_DEFINE_RELATIONAL_BINARY_VEC_ALL(long, isordered, double, double)
#endif
+#ifdef cl_khr_fp16
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+// The scalar version of isordered(half, half) returns an int, but the vector versions
+// return short.
+
+_CLC_DEFINE_ISORDERED(int, isordered, half, half)
+_CLC_DEFINE_RELATIONAL_BINARY_VEC_ALL(short, isordered, half, half)
+
+#endif
#undef _CLC_DEFINE_ISORDERED
Modified: libclc/trunk/generic/lib/relational/isunordered.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/relational/isunordered.cl?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/relational/isunordered.cl (original)
+++ libclc/trunk/generic/lib/relational/isunordered.cl Thu May 17 15:55:30 2018
@@ -20,3 +20,17 @@ _CLC_DEF _CLC_OVERLOAD int isunordered(d
_CLC_DEFINE_RELATIONAL_BINARY_VEC_ALL(long, isunordered, double, double)
#endif
+#ifdef cl_khr_fp16
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+// The scalar version of isunordered(half, half) returns an int, but the vector versions
+// return short.
+
+_CLC_DEF _CLC_OVERLOAD int isunordered(half x, half y){
+ return __builtin_isunordered(x, y);
+}
+
+_CLC_DEFINE_RELATIONAL_BINARY_VEC_ALL(short, isunordered, half, half)
+
+#endif
Modified: libclc/trunk/generic/lib/relational/signbit.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/relational/signbit.cl?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/relational/signbit.cl (original)
+++ libclc/trunk/generic/lib/relational/signbit.cl Thu May 17 15:55:30 2018
@@ -17,3 +17,17 @@ _CLC_DEF _CLC_OVERLOAD int signbit(doubl
_CLC_DEFINE_RELATIONAL_UNARY_VEC_ALL(long, signbit, double)
#endif
+#ifdef cl_khr_fp16
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+// The scalar version of signbit(half) returns an int, but the vector versions
+// return short.
+
+_CLC_DEF _CLC_OVERLOAD int signbit(half x){
+ return __builtin_signbit(x);
+}
+
+_CLC_DEFINE_RELATIONAL_UNARY_VEC_ALL(short, signbit, half)
+
+#endif
Modified: libclc/trunk/generic/lib/shared/vstore_half.inc
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/shared/vstore_half.inc?rev=332677&r1=332676&r2=332677&view=diff
==============================================================================
--- libclc/trunk/generic/lib/shared/vstore_half.inc (original)
+++ libclc/trunk/generic/lib/shared/vstore_half.inc Thu May 17 15:55:30 2018
@@ -1,4 +1,5 @@
-
+// This does not exist for fp16
+#if __CLC_FPSIZE > 16
#ifdef __CLC_VECSIZE
#if __CLC_VECSIZE == 3
@@ -17,3 +18,4 @@
FUNC(, 1, 1, __CLC_GENTYPE, __CLC_SCALAR_GENTYPE, __local);
FUNC(, 1, 1, __CLC_GENTYPE, __CLC_SCALAR_GENTYPE, __global);
#endif
+#endif
More information about the cfe-commits
mailing list