Skip to content

Commit 375735f

Browse files
authored
[libclc][libspirv] Move degrees to CLC library (#16625)
This commit follows the general framework we want to achieve upstream; we now have a new __clc_degrees builtin, which the OpenCL and SPIR-V builtins both call for implementation. This marks a change from having the OpenCL builtin call the SPIR-V builtin for its implementation.
1 parent 2add39f commit 375735f

File tree

6 files changed

+63
-52
lines changed

6 files changed

+63
-52
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef __CLC_COMMON_CLC_DEGREES_H__
2+
#define __CLC_COMMON_CLC_DEGREES_H__
3+
4+
#define __CLC_BODY <clc/math/unary_decl.inc>
5+
#define __CLC_FUNCTION __clc_degrees
6+
7+
#include <clc/math/gentype.inc>
8+
9+
#undef __CLC_BODY
10+
#undef __CLC_FUNCTION
11+
12+
#endif // __CLC_COMMON_CLC_DEGREES_H__
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <clc/utils.h>
2+
3+
#ifndef __CLC_FUNCTION
4+
#define __CLC_FUNCTION(x) __CLC_CONCAT(__clc_, x)
5+
#endif
6+
7+
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE FUNCTION(__CLC_GENTYPE a) {
8+
return __CLC_FUNCTION(FUNCTION)(a);
9+
}

libclc/clc/lib/generic/SOURCES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
common/clc_degrees.cl
12
geometric/clc_dot.cl
23
integer/clc_abs.cl
34
integer/clc_abs_diff.cl
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <clc/clcmacro.h>
2+
3+
_CLC_OVERLOAD _CLC_DEF float __clc_degrees(float radians) {
4+
// 180/pi = ~57.29577951308232087685 or 0x1.ca5dc1a63c1f8p+5 or 0x1.ca5dc2p+5F
5+
return 0x1.ca5dc2p+5F * radians;
6+
}
7+
8+
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, __clc_degrees, float);
9+
10+
#ifdef cl_khr_fp64
11+
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
12+
13+
_CLC_OVERLOAD _CLC_DEF double __clc_degrees(double radians) {
14+
// 180/pi = ~57.29577951308232087685 or 0x1.ca5dc1a63c1f8p+5 or 0x1.ca5dc2p+5F
15+
return 0x1.ca5dc1a63c1f8p+5 * radians;
16+
}
17+
18+
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, __clc_degrees, double);
19+
20+
#endif
21+
22+
#ifdef cl_khr_fp16
23+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
24+
25+
_CLC_OVERLOAD _CLC_DEF half __clc_degrees(half radians) {
26+
return __clc_degrees((float)radians);
27+
}
28+
29+
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, half, __clc_degrees, half);
30+
31+
#endif

libclc/generic/lib/common/degrees.cl

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,8 @@
2121
*/
2222

2323
#include <clc/clc.h>
24-
#include <clc/clcmacro.h>
25-
#include <libspirv/spirv.h>
24+
#include <clc/common/clc_degrees.h>
2625

27-
_CLC_OVERLOAD _CLC_DEF float degrees(float radians) {
28-
return __spirv_ocl_degrees(radians);
29-
}
30-
31-
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, degrees, float);
32-
33-
34-
#ifdef cl_khr_fp64
35-
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
36-
37-
_CLC_OVERLOAD _CLC_DEF double degrees(double radians) {
38-
return __spirv_ocl_degrees(radians);
39-
}
40-
41-
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, degrees, double);
42-
43-
#endif
26+
#define FUNCTION degrees
27+
#define __CLC_BODY <clc/common/unary_def.inc>
28+
#include <clc/math/gentype.inc>

libclc/libspirv/lib/generic/common/degrees.cl

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,11 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include <clc/clc.h>
10+
#include <clc/common/clc_degrees.h>
911
#include <libspirv/spirv.h>
1012

11-
#include <clc/clcmacro.h>
12-
13-
_CLC_OVERLOAD _CLC_DEF float __spirv_ocl_degrees(float radians) {
14-
// 180/pi = ~57.29577951308232087685 or 0x1.ca5dc1a63c1f8p+5 or 0x1.ca5dc2p+5F
15-
return 0x1.ca5dc2p+5F * radians;
16-
}
17-
18-
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, __spirv_ocl_degrees, float);
19-
20-
21-
#ifdef cl_khr_fp64
22-
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
23-
24-
_CLC_OVERLOAD _CLC_DEF double __spirv_ocl_degrees(double radians) {
25-
// 180/pi = ~57.29577951308232087685 or 0x1.ca5dc1a63c1f8p+5 or 0x1.ca5dc2p+5F
26-
return 0x1.ca5dc1a63c1f8p+5 * radians;
27-
}
28-
29-
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, __spirv_ocl_degrees,
30-
double);
31-
32-
#endif
33-
34-
#ifdef cl_khr_fp16
35-
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
36-
37-
_CLC_OVERLOAD _CLC_DEF half __spirv_ocl_degrees(half radians) {
38-
return __spirv_ocl_degrees((float)radians);
39-
}
40-
41-
_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, half, __spirv_ocl_degrees, half);
42-
43-
#endif
13+
#define FUNCTION __spirv_ocl_degrees
14+
#define __CLC_FUNCTION(x) __clc_degrees
15+
#define __CLC_BODY <clc/common/unary_def.inc>
16+
#include <clc/math/gentype.inc>

0 commit comments

Comments
 (0)