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
43 lines
1.3 KiB
Common Lisp
43 lines
1.3 KiB
Common Lisp
#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
|