88
99#include <clc/clc_as_type.h>
1010#include <clc/float/definitions.h>
11+ #include <clc/math/clc_copysign.h>
12+ #include <clc/math/clc_fabs.h>
13+ #include <clc/math/clc_nextafter.h>
1114#include <clc/opencl/opencl-base.h>
15+ #include <clc/relational/clc_isinf.h>
16+ #include <clc/relational/clc_isnan.h>
17+ #include <clc/shared/clc_min.h>
1218
1319#pragma OPENCL EXTENSION cl_khr_byte_addressable_store : enable
1420
4854
4955_CLC_DEF _CLC_OVERLOAD float __clc_rtz (float x ) {
5056 /* Handle nan corner case */
51- if (isnan (x ))
57+ if (__clc_isnan (x ))
5258 return x ;
5359 /* RTZ does not produce Inf for large numbers */
54- if (fabs (x ) > 65504.0f && !isinf (x ))
55- return copysign (65504.0f , x );
60+ if (__clc_fabs (x ) > 65504.0f && !__clc_isinf (x ))
61+ return __clc_copysign (65504.0f , x );
5662
5763 const int exp = (__clc_as_uint (x ) >> 23 & 0xff ) - 127 ;
5864 /* Manage range rounded to +- zero explicitely */
5965 if (exp < -24 )
60- return copysign (0.0f , x );
66+ return __clc_copysign (0.0f , x );
6167
6268 /* Remove lower 13 bits to make sure the number is rounded down */
6369 int mask = 0xffffe000 ;
6470 /* Denormals cannot be flushed, and they use different bit for rounding */
6571 if (exp < -14 )
66- mask <<= min (- (exp + 14 ), 10 );
72+ mask <<= __clc_min (- (exp + 14 ), 10 );
6773
6874 return __clc_as_float (__clc_as_uint (x ) & mask );
6975}
7076
7177_CLC_DEF _CLC_OVERLOAD float __clc_rti (float x ) {
7278 /* Handle nan corner case */
73- if (isnan (x ))
79+ if (__clc_isnan (x ))
7480 return x ;
7581
76- const float inf = copysign (INFINITY , x );
82+ const float inf = __clc_copysign (INFINITY , x );
7783 uint ux = __clc_as_uint (x );
7884
7985 /* Manage +- infinity explicitely */
@@ -82,23 +88,23 @@ _CLC_DEF _CLC_OVERLOAD float __clc_rti(float x) {
8288 }
8389 /* Manage +- zero explicitely */
8490 if ((ux & 0x7fffffff ) == 0 ) {
85- return copysign (0.0f , x );
91+ return __clc_copysign (0.0f , x );
8692 }
8793
8894 const int exp = (__clc_as_uint (x ) >> 23 & 0xff ) - 127 ;
8995 /* Manage range rounded to smallest half denormal explicitely */
9096 if (exp < -24 ) {
91- return copysign (0x1.0p-24f , x );
97+ return __clc_copysign (0x1.0p-24f , x );
9298 }
9399
94100 /* Set lower 13 bits */
95101 int mask = (1 << 13 ) - 1 ;
96102 /* Denormals cannot be flushed, and they use different bit for rounding */
97103 if (exp < -14 ) {
98- mask = (1 << (13 + min (- (exp + 14 ), 10 ))) - 1 ;
104+ mask = (1 << (13 + __clc_min (- (exp + 14 ), 10 ))) - 1 ;
99105 }
100106
101- const float next = nextafter (__clc_as_float (ux | mask ), inf );
107+ const float next = __clc_nextafter (__clc_as_float (ux | mask ), inf );
102108 return ((ux & mask ) == 0 ) ? __clc_as_float (ux ) : next ;
103109}
104110_CLC_DEF _CLC_OVERLOAD float __clc_rtn (float x ) {
@@ -116,7 +122,7 @@ _CLC_DEF _CLC_OVERLOAD float __clc_rte(float x) {
116122 /* The default assumes lower 13 bits are rounded,
117123 * but it might be more for denormals.
118124 * Shifting beyond last == 0b, and qr == 00b is not necessary */
119- shift += min (- (exp + 14 ), 15 );
125+ shift += __clc_min (- (exp + 14 ), 15 );
120126 }
121127 int mask = (1 << shift ) - 1 ;
122128 const uint grs = mantissa & mask ;
0 commit comments