2 #include
<clc
/clcmacro.h
>
3 #include
<clc
/relational
/clc_isnan.h
>
5 // This file provides OpenCL C implementations of nextafter for
6 // targets that don
't support the clang builtin.
8 #define AS_TYPE
(x) as_
##x
10 #define NEXTAFTER
(FLOAT_TYPE, UINT_TYPE
, INT_TYPE
) \
11 _CLC_OVERLOAD _CLC_DEF FLOAT_TYPE __clc_nextafter
(FLOAT_TYPE x
, \
13 const UINT_TYPE sign_bit
= (UINT_TYPE)1 << (sizeof(INT_TYPE) * 8 -
1); \
14 const UINT_TYPE sign_bit_mask
= sign_bit -
1; \
15 INT_TYPE ix
= AS_TYPE
(INT_TYPE)(x); \
16 INT_TYPE ax
= ix
& sign_bit_mask
; \
17 INT_TYPE mx
= sign_bit - ix
; \
18 mx
= ix
< 0 ? mx
: ix
; \
19 INT_TYPE iy
= AS_TYPE
(INT_TYPE)(y); \
20 INT_TYPE ay
= iy
& sign_bit_mask
; \
21 INT_TYPE my
= sign_bit - iy
; \
22 my
= iy
< 0 ? my
: iy
; \
23 INT_TYPE t
= mx
+ (mx < my ?
1 : -
1); \
24 INT_TYPE r
= sign_bit - t
; \
26 r
= __clc_isnan
(x) ? ix
: r
; \
27 r
= __clc_isnan
(y) ? iy
: r
; \
28 r
= ((ax | ay
) == 0 | ix
== iy
) ? iy
: r
; \
29 return AS_TYPE
(FLOAT_TYPE)(r); \
32 NEXTAFTER
(float, uint
, int
)
33 _CLC_BINARY_VECTORIZE
(_CLC_OVERLOAD _CLC_DEF
, float
, __clc_nextafter
, float
,
37 #pragma OPENCL EXTENSION cl_khr_fp64
: enable
39 NEXTAFTER
(double, ulong
, long
)
40 _CLC_BINARY_VECTORIZE
(_CLC_OVERLOAD _CLC_DEF
, double
, __clc_nextafter
, double
,
45 #pragma OPENCL EXTENSION cl_khr_fp16
: enable
47 NEXTAFTER
(half, ushort
, short
)
48 _CLC_BINARY_VECTORIZE
(_CLC_OVERLOAD _CLC_DEF
, half
, __clc_nextafter
, half
, half
)