1#include <clc/clc.h> 2 3#include "../../../generic/lib/clcmacro.h" 4 5_CLC_DEF _CLC_OVERLOAD float fmax(float x, float y) 6{ 7 /* fcanonicalize removes sNaNs and flushes denormals if not enabled. 8 * Otherwise fmax instruction flushes the values for comparison, 9 * but outputs original denormal */ 10 x = __builtin_canonicalizef(x); 11 y = __builtin_canonicalizef(y); 12 return __builtin_fmaxf(x, y); 13} 14_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, fmax, float, float) 15 16#ifdef cl_khr_fp64 17 18#pragma OPENCL EXTENSION cl_khr_fp64 : enable 19 20_CLC_DEF _CLC_OVERLOAD double fmax(double x, double y) 21{ 22 x = __builtin_canonicalize(x); 23 y = __builtin_canonicalize(y); 24 return __builtin_fmax(x, y); 25} 26_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, fmax, double, double) 27 28#endif 29#ifdef cl_khr_fp16 30 31#pragma OPENCL EXTENSION cl_khr_fp16 : enable 32 33_CLC_DEF _CLC_OVERLOAD half fmax(half x, half y) 34{ 35 if (isnan(x)) 36 return y; 37 if (isnan(y)) 38 return x; 39 return (y < x) ? x : y; 40} 41_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, half, fmax, half, half) 42 43#endif 44 45#define __CLC_BODY <../../../generic/lib/math/fmax.inc> 46#include <clc/math/gentype.inc> 47