Skip to content

Commit 9743b99

Browse files
authored
[libclc] Explicitly qualify private address spaces (#127823)
Doing so provides stability when compiling the builtins in a mode in which unqualified pointers may be interpreted as being in the generic address space, such as in OpenCL 3.0. We eventually want to provide 'generic' overloads of the builtins in libclc so this prepares the ground a little better. It could be argued that having the internal CLC helper functions be unqualified is more flexible, in case it's better for a target to have the pointers in the generic address space. This commits to the private address space for more stability across different OpenCL environments.
1 parent fc5849d commit 9743b99

File tree

5 files changed

+35
-25
lines changed

5 files changed

+35
-25
lines changed

libclc/generic/lib/math/ep_log.cl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
#define LF1 1.24999999978138668903e-02
3939
#define LF2 2.23219810758559851206e-03
4040

41-
_CLC_DEF void __clc_ep_log(double x, int *xexp, double *r1, double *r2) {
41+
_CLC_DEF void __clc_ep_log(double x, private int *xexp, private double *r1,
42+
private double *r2) {
4243
// Computes natural log(x). Algorithm based on:
4344
// Ping-Tak Peter Tang
4445
// "Table-driven implementation of the logarithm function in IEEE

libclc/generic/lib/math/ep_log.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
2828

29-
_CLC_DECL void __clc_ep_log(double x, int *xexp, double *r1, double *r2);
29+
_CLC_DECL void __clc_ep_log(double x, private int *xexp, private double *r1,
30+
private double *r2);
3031

3132
#endif

libclc/generic/lib/math/modf.inc

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,20 @@
2828
#define ZERO 0.0h
2929
#endif
3030

31-
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE modf(__CLC_GENTYPE x, __CLC_GENTYPE *iptr) {
31+
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE modf(__CLC_GENTYPE x,
32+
private __CLC_GENTYPE *iptr) {
3233
*iptr = trunc(x);
3334
return copysign(isinf(x) ? ZERO : x - *iptr, x);
3435
}
3536

36-
#define MODF_DEF(addrspace) \
37-
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE modf(__CLC_GENTYPE x, addrspace __CLC_GENTYPE *iptr) { \
38-
__CLC_GENTYPE private_iptr; \
39-
__CLC_GENTYPE ret = modf(x, &private_iptr); \
40-
*iptr = private_iptr; \
41-
return ret; \
42-
}
37+
#define MODF_DEF(addrspace) \
38+
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE modf(__CLC_GENTYPE x, \
39+
addrspace __CLC_GENTYPE *iptr) { \
40+
__CLC_GENTYPE private_iptr; \
41+
__CLC_GENTYPE ret = modf(x, &private_iptr); \
42+
*iptr = private_iptr; \
43+
return ret; \
44+
}
4345

4446
MODF_DEF(local);
4547
MODF_DEF(global);

libclc/generic/lib/math/sincos_helpers.cl

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ _CLC_DEF float __clc_tanf_piby4(float x, int regn) {
119119
return regn & 1 ? tr : t;
120120
}
121121

122-
_CLC_DEF void __clc_fullMulS(float *hi, float *lo, float a, float b, float bh,
123-
float bt) {
122+
_CLC_DEF void __clc_fullMulS(private float *hi, private float *lo, float a,
123+
float b, float bh, float bt) {
124124
if (HAVE_HW_FMA32()) {
125125
float ph = a * b;
126126
*hi = ph;
@@ -136,7 +136,7 @@ _CLC_DEF void __clc_fullMulS(float *hi, float *lo, float a, float b, float bh,
136136
}
137137
}
138138

139-
_CLC_DEF float __clc_removePi2S(float *hi, float *lo, float x) {
139+
_CLC_DEF float __clc_removePi2S(private float *hi, private float *lo, float x) {
140140
// 72 bits of pi/2
141141
const float fpiby2_1 = (float)0xC90FDA / 0x1.0p+23f;
142142
const float fpiby2_1_h = (float)0xC90 / 0x1.0p+11f;
@@ -174,7 +174,8 @@ _CLC_DEF float __clc_removePi2S(float *hi, float *lo, float x) {
174174
return fnpi2;
175175
}
176176

177-
_CLC_DEF int __clc_argReductionSmallS(float *r, float *rr, float x) {
177+
_CLC_DEF int __clc_argReductionSmallS(private float *r, private float *rr,
178+
float x) {
178179
float fnpi2 = __clc_removePi2S(r, rr, x);
179180
return (int)fnpi2 & 0x3;
180181
}
@@ -188,7 +189,8 @@ _CLC_DEF int __clc_argReductionSmallS(float *r, float *rr, float x) {
188189
HI = __clc_mul_hi(A, B); \
189190
HI += LO < C
190191

191-
_CLC_DEF int __clc_argReductionLargeS(float *r, float *rr, float x) {
192+
_CLC_DEF int __clc_argReductionLargeS(private float *r, private float *rr,
193+
float x) {
192194
int xe = (int)(as_uint(x) >> 23) - 127;
193195
uint xm = 0x00800000U | (as_uint(x) & 0x7fffffU);
194196

@@ -330,7 +332,7 @@ _CLC_DEF int __clc_argReductionLargeS(float *r, float *rr, float x) {
330332
return ((i >> 1) + (i & 1)) & 0x3;
331333
}
332334

333-
_CLC_DEF int __clc_argReductionS(float *r, float *rr, float x) {
335+
_CLC_DEF int __clc_argReductionS(private float *r, private float *rr, float x) {
334336
if (x < 0x1.0p+23f)
335337
return __clc_argReductionSmallS(r, rr, x);
336338
else
@@ -342,8 +344,9 @@ _CLC_DEF int __clc_argReductionS(float *r, float *rr, float x) {
342344
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
343345

344346
// Reduction for medium sized arguments
345-
_CLC_DEF void __clc_remainder_piby2_medium(double x, double *r, double *rr,
346-
int *regn) {
347+
_CLC_DEF void __clc_remainder_piby2_medium(double x, private double *r,
348+
private double *rr,
349+
private int *regn) {
347350
// How many pi/2 is x a multiple of?
348351
const double two_by_pi = 0x1.45f306dc9c883p-1;
349352
double dnpi2 = __clc_trunc(fma(x, two_by_pi, 0.5));
@@ -387,8 +390,9 @@ _CLC_DEF void __clc_remainder_piby2_medium(double x, double *r, double *rr,
387390
// Return value "regn" tells how many lots of pi/2 were subtracted
388391
// from x to put it in the range [-pi/4,pi/4], mod 4.
389392

390-
_CLC_DEF void __clc_remainder_piby2_large(double x, double *r, double *rr,
391-
int *regn) {
393+
_CLC_DEF void __clc_remainder_piby2_large(double x, private double *r,
394+
private double *rr,
395+
private int *regn) {
392396

393397
long ux = as_long(x);
394398
int e = (int)(ux >> 52) - 1023;

libclc/generic/lib/math/sincos_helpers.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,18 @@
2626
_CLC_DECL float __clc_sinf_piby4(float x, float y);
2727
_CLC_DECL float __clc_cosf_piby4(float x, float y);
2828
_CLC_DECL float __clc_tanf_piby4(float x, int y);
29-
_CLC_DECL int __clc_argReductionS(float *r, float *rr, float x);
29+
_CLC_DECL int __clc_argReductionS(private float *r, private float *rr, float x);
3030

3131
#ifdef cl_khr_fp64
3232

3333
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
3434

35-
_CLC_DECL void __clc_remainder_piby2_medium(double x, double *r, double *rr,
36-
int *regn);
37-
_CLC_DECL void __clc_remainder_piby2_large(double x, double *r, double *rr,
38-
int *regn);
35+
_CLC_DECL void __clc_remainder_piby2_medium(double x, private double *r,
36+
private double *rr,
37+
private int *regn);
38+
_CLC_DECL void __clc_remainder_piby2_large(double x, private double *r,
39+
private double *rr,
40+
private int *regn);
3941
_CLC_DECL double2 __clc_sincos_piby4(double x, double xx);
4042

4143
#endif

0 commit comments

Comments
 (0)