Skip to content

Commit 37f93d9

Browse files
committed
[libclc] Move relational functions to the CLC library (#115171)
The OpenCL relational functions now call their CLC counterparts, and the CLC relational functions are defined identically to how the OpenCL functions were defined. As usual, clspv and spir-v targets bypass these. No observable changes to any libclc target (measured with llvm-diff).
1 parent 4e20b3e commit 37f93d9

File tree

9 files changed

+49
-72
lines changed

9 files changed

+49
-72
lines changed

libclc/clc/lib/generic/SOURCES

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
geometric/clc_dot.cl
22
integer/clc_abs.cl
33
integer/clc_abs_diff.cl
4+
relational/clc_all.cl
5+
relational/clc_any.cl
6+
relational/clc_bitselect.cl
7+
relational/clc_isequal.cl
8+
relational/clc_isfinite.cl
9+
relational/clc_isgreater.cl
10+
relational/clc_isgreaterequal.cl
11+
relational/clc_isinf.cl
12+
relational/clc_isless.cl
13+
relational/clc_islessequal.cl
14+
relational/clc_islessgreater.cl
15+
relational/clc_isnan.cl
16+
relational/clc_isnormal.cl
17+
relational/clc_isnotequal.cl
18+
relational/clc_isordered.cl
19+
relational/clc_isunordered.cl
20+
relational/clc_select.cl
21+
relational/clc_signbit.cl
422
shared/clc_clamp.cl
523
shared/clc_max.cl
624
shared/clc_min.cl

libclc/generic/lib/math/clc_ldexp.cl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
* THE SOFTWARE.
2121
*/
2222

23-
#include "../clcmacro.h"
2423
#include "config.h"
2524
#include "math.h"
2625
#include <clc/clc.h>
26+
#include <clc/clcmacro.h>
27+
#include <clc/relational/clc_isinf.h>
28+
#include <clc/relational/clc_isnan.h>
2729
#include <clc/shared/clc_clamp.h>
2830

2931
_CLC_DEF _CLC_OVERLOAD float __clc_ldexp(float x, int n) {
Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,7 @@
11
#include <clc/clc.h>
2-
#include <spirv/spirv.h>
3-
#include "relational.h"
2+
#include <clc/relational/clc_isinf.h>
43

5-
_CLC_DEFINE_RELATIONAL_UNARY(int, isinf, __spirv_IsInf, float)
4+
#define FUNCTION isinf
5+
#define __CLC_BODY "unary_def.inc"
66

7-
#ifdef cl_khr_fp64
8-
9-
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
10-
11-
// The scalar version of isinf(double) returns an int, but the vector versions
12-
// return long.
13-
_CLC_DEF _CLC_OVERLOAD int isinf(double x) {
14-
return __spirv_IsInf(x);
15-
}
16-
17-
_CLC_DEFINE_RELATIONAL_UNARY_VEC_ALL(long, isinf, double)
18-
#endif
19-
20-
#ifdef cl_khr_fp16
21-
22-
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
23-
24-
// The scalar version of isinf(half) returns an int, but the vector versions
25-
// return short.
26-
_CLC_DEF _CLC_OVERLOAD int isinf(half x) {
27-
return __spirv_IsInf(x);
28-
}
29-
30-
_CLC_DEFINE_RELATIONAL_UNARY_VEC_ALL(short, isinf, half)
31-
#endif
7+
#include <clc/relational/floatn.inc>
Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,7 @@
11
#include <clc/clc.h>
2-
#include <spirv/spirv.h>
3-
#include "relational.h"
2+
#include <clc/relational/clc_isnan.h>
43

5-
_CLC_DEFINE_RELATIONAL_UNARY(int, isnan, __spirv_IsNan, float)
4+
#define FUNCTION isnan
5+
#define __CLC_BODY "unary_def.inc"
66

7-
#ifdef cl_khr_fp64
8-
9-
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
10-
11-
// The scalar version of isnan(double) returns an int, but the vector versions
12-
// return long.
13-
_CLC_DEF _CLC_OVERLOAD int isnan(double x) {
14-
return __spirv_IsNan(x);
15-
}
16-
17-
_CLC_DEFINE_RELATIONAL_UNARY_VEC_ALL(long, isnan, double)
18-
19-
#endif
20-
21-
#ifdef cl_khr_fp16
22-
23-
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
24-
25-
// The scalar version of isnan(half) returns an int, but the vector versions
26-
// return short.
27-
_CLC_DEF _CLC_OVERLOAD int isnan(half x) {
28-
return __spirv_IsNan(x);
29-
}
30-
31-
_CLC_DEFINE_RELATIONAL_UNARY_VEC_ALL(short, isnan, half)
32-
33-
#endif
7+
#include <clc/relational/floatn.inc>

libclc/generic/libspirv/math/clc_exp10.cl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ _CLC_DEF _CLC_OVERLOAD float __clc_exp10(float x)
6464
const float R_LOG10_2_BY_64_TL = 0x1.04d426p-18f; // log2/(64 * log10) tail : 0.00000388665057
6565
const float R_LN10 = 0x1.26bb1cp+1f;
6666

67-
int return_nan = __spirv_IsNan(x);
67+
int return_nan = __clc_isnan(x);
6868
int return_inf = x > X_MAX;
6969
int return_zero = x < X_MIN;
7070

@@ -143,7 +143,7 @@ _CLC_DEF _CLC_OVERLOAD double __clc_exp10(double x)
143143
z2 = __spirv_ocl_ldexp(z2, m);
144144
z2 = small_value ? z3: z2;
145145

146-
z2 = __spirv_IsNan(x) ? x : z2;
146+
z2 = __clc_isnan(x) ? x : z2;
147147

148148
z2 = x > X_MAX ? as_double(PINFBITPATT_DP64) : z2;
149149
z2 = x < X_MIN ? 0.0 : z2;

libclc/generic/libspirv/math/clc_fma.cl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
#include <clc/clcmacro.h>
2424
#include <clc/integer/clc_abs.h>
25+
#include <clc/relational/clc_isinf.h>
26+
#include <clc/relational/clc_isnan.h>
27+
#include <clc/shared/clc_max.h>
2528
#include <config.h>
2629
#include <core/clc_core.h>
2730
#include <math/math.h>
@@ -35,12 +38,12 @@ struct fp {
3538

3639
_CLC_DEF _CLC_OVERLOAD float __clc_sw_fma(float a, float b, float c) {
3740
/* special cases */
38-
if (__spirv_IsNan(a) || __spirv_IsNan(b) || __spirv_IsNan(c) ||
39-
__spirv_IsInf(a) || __spirv_IsInf(b))
41+
if (__clc_isnan(a) || __clc_isnan(b) || __clc_isnan(c) || __clc_isinf(a) ||
42+
__clc_isinf(b))
4043
return __spirv_ocl_mad(a, b, c);
4144

4245
/* If only c is inf, and both a,b are regular numbers, the result is c*/
43-
if (__spirv_IsInf(c))
46+
if (__clc_isinf(c))
4447
return c;
4548

4649
a = __clc_flush_denormal_if_not_supported(a);

libclc/generic/libspirv/math/clc_hypot.cl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <clc/clc.h>
1212
#include <clc/clcmacro.h>
1313
#include <clc/integer/clc_abs.h>
14+
#include <clc/relational/clc_isnan.h>
1415
#include <clc/shared/clc_clamp.h>
1516
#include <config.h>
1617
#include <math/clc_hypot.h>
@@ -75,7 +76,7 @@ _CLC_DEF _CLC_OVERLOAD double __clc_hypot(double x, double y) {
7576

7677
// Check for NaN
7778
// c = x != x | y != y;
78-
c = __spirv_IsNan(x) | __spirv_IsNan(y);
79+
c = __clc_isnan(x) | __clc_isnan(y);
7980
r = c ? as_double(QNANBITPATT_DP64) : r;
8081

8182
// If either is Inf, we must return Inf

libclc/generic/libspirv/math/clc_ldexp.cl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
#include "tables.h"
2727
#include <clc/clcmacro.h>
28+
#include <clc/relational/clc_isinf.h>
29+
#include <clc/relational/clc_isnan.h>
2830
#include <config.h>
2931
#include <math/math.h>
3032

@@ -92,7 +94,7 @@ _CLC_DEF _CLC_OVERLOAD float __clc_ldexp(float x, int n) {
9294
val_ui = dexp == 0 ? dval_ui : val_ui;
9395
val_f = as_float(val_ui);
9496

95-
val_f = __spirv_IsNan(x) || __spirv_IsInf(x) || val_x == 0 ? x : val_f;
97+
val_f = __clc_isnan(x) || __clc_isinf(x) || val_x == 0 ? x : val_f;
9698
return val_f;
9799
}
98100

@@ -125,7 +127,7 @@ _CLC_DEF _CLC_OVERLOAD double __clc_ldexp(double x, int n) {
125127
mr = v == 0x7ff ? as_double(s | PINFBITPATT_DP64) : mr;
126128
mr = v < -53 ? as_double(s) : mr;
127129

128-
mr = ((n == 0) | __spirv_IsInf(x) | (x == 0)) ? x : mr;
130+
mr = ((n == 0) | __clc_isinf(x) | (x == 0)) ? x : mr;
129131
return mr;
130132
}
131133

libclc/generic/libspirv/math/clc_tan.cl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
#include <clc/clc.h>
2323
#include <clc/clcmacro.h>
2424
#include <clc/math/clc_fabs.h>
25-
#include <spirv/spirv.h>
25+
#include <clc/relational/clc_isinf.h>
26+
#include <clc/relational/clc_isnan.h>
2627

2728
#include "sincos_helpers.h"
2829
#include "tables.h"
@@ -49,9 +50,8 @@ _CLC_UNARY_VECTORIZE(_CLC_DEF _CLC_OVERLOAD, float, __clc_tan, float);
4950
#ifdef cl_khr_fp64
5051
#include "sincosD_piby4.h"
5152

52-
_CLC_DEF _CLC_OVERLOAD double __clc_tan(double x)
53-
{
54-
double y = __spirv_ocl_fabs(x);
53+
_CLC_DEF _CLC_OVERLOAD double __clc_tan(double x) {
54+
double y = __clc_fabs(x);
5555

5656
double r, rr;
5757
int regn;
@@ -66,7 +66,8 @@ _CLC_DEF _CLC_OVERLOAD double __clc_tan(double x)
6666
int2 t = as_int2(regn & 1 ? tt.y : tt.x);
6767
t.hi ^= (x < 0.0) << 31;
6868

69-
return __spirv_IsNan(x) || __spirv_IsInf(x) ? as_double(QNANBITPATT_DP64) : as_double(t);
69+
return __clc_isnan(x) || __clc_isinf(x) ? as_double(QNANBITPATT_DP64)
70+
: as_double(t);
7071
}
7172
_CLC_UNARY_VECTORIZE(_CLC_DEF _CLC_OVERLOAD, double, __clc_tan, double);
7273

0 commit comments

Comments
 (0)