[analyzer][NFC] Factor out SymbolManager::get<*> (#121781)
[llvm-project.git] / libclc / generic / lib / math / clc_nextafter.cl
blob623eb11c18c3b18aa17e2791b7c520a44a7f6b21
1 #include <clc/clc.h>
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, \
12 FLOAT_TYPE y) { \
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; \
25 r = t < 0 ? r : 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,
34 float)
36 #ifdef cl_khr_fp64
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,
41 double)
42 #endif
44 #ifdef cl_khr_fp16
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)
49 #endif