Skip to content

Commit b231647

Browse files
authored
[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 cff2199 commit b231647

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1565
-638
lines changed

libclc/clc/include/clc/clc_as_type.h

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#ifndef __CLC_CLC_AS_TYPE_H__
2+
#define __CLC_CLC_AS_TYPE_H__
3+
4+
#define __clc_as_char(x) __builtin_astype(x, char)
5+
#define __clc_as_uchar(x) __builtin_astype(x, uchar)
6+
#define __clc_as_short(x) __builtin_astype(x, short)
7+
#define __clc_as_ushort(x) __builtin_astype(x, ushort)
8+
#define __clc_as_int(x) __builtin_astype(x, int)
9+
#define __clc_as_uint(x) __builtin_astype(x, uint)
10+
#define __clc_as_long(x) __builtin_astype(x, long)
11+
#define __clc_as_ulong(x) __builtin_astype(x, ulong)
12+
#define __clc_as_float(x) __builtin_astype(x, float)
13+
14+
#define __clc_as_char2(x) __builtin_astype(x, char2)
15+
#define __clc_as_uchar2(x) __builtin_astype(x, uchar2)
16+
#define __clc_as_short2(x) __builtin_astype(x, short2)
17+
#define __clc_as_ushort2(x) __builtin_astype(x, ushort2)
18+
#define __clc_as_int2(x) __builtin_astype(x, int2)
19+
#define __clc_as_uint2(x) __builtin_astype(x, uint2)
20+
#define __clc_as_long2(x) __builtin_astype(x, long2)
21+
#define __clc_as_ulong2(x) __builtin_astype(x, ulong2)
22+
#define __clc_as_float2(x) __builtin_astype(x, float2)
23+
24+
#define __clc_as_char3(x) __builtin_astype(x, char3)
25+
#define __clc_as_uchar3(x) __builtin_astype(x, uchar3)
26+
#define __clc_as_short3(x) __builtin_astype(x, short3)
27+
#define __clc_as_ushort3(x) __builtin_astype(x, ushort3)
28+
#define __clc_as_int3(x) __builtin_astype(x, int3)
29+
#define __clc_as_uint3(x) __builtin_astype(x, uint3)
30+
#define __clc_as_long3(x) __builtin_astype(x, long3)
31+
#define __clc_as_ulong3(x) __builtin_astype(x, ulong3)
32+
#define __clc_as_float3(x) __builtin_astype(x, float3)
33+
34+
#define __clc_as_char4(x) __builtin_astype(x, char4)
35+
#define __clc_as_uchar4(x) __builtin_astype(x, uchar4)
36+
#define __clc_as_short4(x) __builtin_astype(x, short4)
37+
#define __clc_as_ushort4(x) __builtin_astype(x, ushort4)
38+
#define __clc_as_int4(x) __builtin_astype(x, int4)
39+
#define __clc_as_uint4(x) __builtin_astype(x, uint4)
40+
#define __clc_as_long4(x) __builtin_astype(x, long4)
41+
#define __clc_as_ulong4(x) __builtin_astype(x, ulong4)
42+
#define __clc_as_float4(x) __builtin_astype(x, float4)
43+
44+
#define __clc_as_char8(x) __builtin_astype(x, char8)
45+
#define __clc_as_uchar8(x) __builtin_astype(x, uchar8)
46+
#define __clc_as_short8(x) __builtin_astype(x, short8)
47+
#define __clc_as_ushort8(x) __builtin_astype(x, ushort8)
48+
#define __clc_as_int8(x) __builtin_astype(x, int8)
49+
#define __clc_as_uint8(x) __builtin_astype(x, uint8)
50+
#define __clc_as_long8(x) __builtin_astype(x, long8)
51+
#define __clc_as_ulong8(x) __builtin_astype(x, ulong8)
52+
#define __clc_as_float8(x) __builtin_astype(x, float8)
53+
54+
#define __clc_as_char16(x) __builtin_astype(x, char16)
55+
#define __clc_as_uchar16(x) __builtin_astype(x, uchar16)
56+
#define __clc_as_short16(x) __builtin_astype(x, short16)
57+
#define __clc_as_ushort16(x) __builtin_astype(x, ushort16)
58+
#define __clc_as_int16(x) __builtin_astype(x, int16)
59+
#define __clc_as_uint16(x) __builtin_astype(x, uint16)
60+
#define __clc_as_long16(x) __builtin_astype(x, long16)
61+
#define __clc_as_ulong16(x) __builtin_astype(x, ulong16)
62+
#define __clc_as_float16(x) __builtin_astype(x, float16)
63+
64+
#ifdef cl_khr_fp64
65+
#define __clc_as_double(x) __builtin_astype(x, double)
66+
#define __clc_as_double2(x) __builtin_astype(x, double2)
67+
#define __clc_as_double3(x) __builtin_astype(x, double3)
68+
#define __clc_as_double4(x) __builtin_astype(x, double4)
69+
#define __clc_as_double8(x) __builtin_astype(x, double8)
70+
#define __clc_as_double16(x) __builtin_astype(x, double16)
71+
#endif
72+
73+
#ifdef cl_khr_fp16
74+
#define __clc_as_half(x) __builtin_astype(x, half)
75+
#define __clc_as_half2(x) __builtin_astype(x, half2)
76+
#define __clc_as_half3(x) __builtin_astype(x, half3)
77+
#define __clc_as_half4(x) __builtin_astype(x, half4)
78+
#define __clc_as_half8(x) __builtin_astype(x, half8)
79+
#define __clc_as_half16(x) __builtin_astype(x, half16)
80+
#endif
81+
82+
#endif // __CLC_CLC_AS_TYPE_H__

libclc/clc/include/clc/internal/clc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
/* 6.1 Supported Data Types */
2222
#include <clc/clctypes.h>
2323

24+
/* 6.2.4.2 Reinterpreting Types Using __clc_as_type() and __clc_as_typen() */
25+
#include <clc/clc_as_type.h>
26+
2427
#pragma OPENCL EXTENSION all : disable
2528

2629
#endif // __CLC_INTERNAL_CLC_H_
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
_CLC_OVERLOAD _CLC_DECL __CLC_INTN __CLC_FUNCTION(__CLC_FLOATN a,
2+
__CLC_FLOATN b);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#ifndef __CLC_RELATIONAL_CLC_ALL_H__
2+
#define __CLC_RELATIONAL_CLC_ALL_H__
3+
4+
#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
5+
// clspv and spir-v targets provide their own OpenCL-compatible all
6+
#define __clc_all all
7+
#else
8+
9+
#include <clc/clcfunc.h>
10+
11+
#define _CLC_ALL_DECL(TYPE) _CLC_OVERLOAD _CLC_DECL int __clc_all(TYPE v);
12+
13+
#define _CLC_VECTOR_ALL_DECL(TYPE) \
14+
_CLC_ALL_DECL(TYPE) \
15+
_CLC_ALL_DECL(TYPE##2) \
16+
_CLC_ALL_DECL(TYPE##3) \
17+
_CLC_ALL_DECL(TYPE##4) \
18+
_CLC_ALL_DECL(TYPE##8) \
19+
_CLC_ALL_DECL(TYPE##16)
20+
21+
_CLC_VECTOR_ALL_DECL(char)
22+
_CLC_VECTOR_ALL_DECL(short)
23+
_CLC_VECTOR_ALL_DECL(int)
24+
_CLC_VECTOR_ALL_DECL(long)
25+
26+
#undef _CLC_ALL_DECL
27+
#undef _CLC_VECTOR_ALL_DECL
28+
29+
#endif
30+
31+
#endif // __CLC_RELATIONAL_CLC_ALL_H__
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#ifndef __CLC_RELATIONAL_CLC_ANY_H__
2+
#define __CLC_RELATIONAL_CLC_ANY_H__
3+
4+
#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
5+
// clspv and spir-v targets provide their own OpenCL-compatible any
6+
#define __clc_any any
7+
#else
8+
9+
#include <clc/clcfunc.h>
10+
11+
#define _CLC_ANY_DECL(TYPE) _CLC_OVERLOAD _CLC_DECL int __clc_any(TYPE v);
12+
13+
#define _CLC_VECTOR_ANY_DECL(TYPE) \
14+
_CLC_ANY_DECL(TYPE) \
15+
_CLC_ANY_DECL(TYPE##2) \
16+
_CLC_ANY_DECL(TYPE##3) \
17+
_CLC_ANY_DECL(TYPE##4) \
18+
_CLC_ANY_DECL(TYPE##8) \
19+
_CLC_ANY_DECL(TYPE##16)
20+
21+
_CLC_VECTOR_ANY_DECL(char)
22+
_CLC_VECTOR_ANY_DECL(short)
23+
_CLC_VECTOR_ANY_DECL(int)
24+
_CLC_VECTOR_ANY_DECL(long)
25+
26+
#undef _CLC_ANY_DECL
27+
#undef _CLC_VECTOR_ANY_DECL
28+
29+
#endif
30+
31+
#endif // __CLC_RELATIONAL_CLC_ANY_H__
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2015 Advanced Micro Devices, Inc.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*/
22+
23+
#ifndef __CLC_RELATIONAL_CLC_BITSELECT_H__
24+
#define __CLC_RELATIONAL_CLC_BITSELECT_H__
25+
26+
#define __CLC_BODY <clc/relational/clc_bitselect.inc>
27+
#include <clc/math/gentype.inc>
28+
#define __CLC_BODY <clc/relational/clc_bitselect.inc>
29+
#include <clc/integer/gentype.inc>
30+
31+
#undef __CLC_BODY
32+
33+
#endif // __CLC_RELATIONAL_CLC_BITSELECT_H__
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) 2015 Advanced Micro Devices, Inc.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*/
22+
23+
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __clc_bitselect(__CLC_GENTYPE x,
24+
__CLC_GENTYPE y,
25+
__CLC_GENTYPE z);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#ifndef __CLC_RELATIONAL_CLC_ISEQUAL_H__
2+
#define __CLC_RELATIONAL_CLC_ISEQUAL_H__
3+
4+
#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
5+
// clspv and spir-v targets provide their own OpenCL-compatible isequal
6+
#define __clc_isequal isequal
7+
#else
8+
9+
#include <clc/clcfunc.h>
10+
11+
#define _CLC_ISEQUAL_DECL(TYPE, RETTYPE) \
12+
_CLC_OVERLOAD _CLC_DECL RETTYPE __clc_isequal(TYPE x, TYPE y);
13+
14+
#define _CLC_VECTOR_ISEQUAL_DECL(TYPE, RETTYPE) \
15+
_CLC_ISEQUAL_DECL(TYPE##2, RETTYPE##2) \
16+
_CLC_ISEQUAL_DECL(TYPE##3, RETTYPE##3) \
17+
_CLC_ISEQUAL_DECL(TYPE##4, RETTYPE##4) \
18+
_CLC_ISEQUAL_DECL(TYPE##8, RETTYPE##8) \
19+
_CLC_ISEQUAL_DECL(TYPE##16, RETTYPE##16)
20+
21+
_CLC_ISEQUAL_DECL(float, int)
22+
_CLC_VECTOR_ISEQUAL_DECL(float, int)
23+
24+
#ifdef cl_khr_fp64
25+
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
26+
_CLC_ISEQUAL_DECL(double, int)
27+
_CLC_VECTOR_ISEQUAL_DECL(double, long)
28+
#endif
29+
30+
#ifdef cl_khr_fp16
31+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
32+
_CLC_ISEQUAL_DECL(half, int)
33+
_CLC_VECTOR_ISEQUAL_DECL(half, short)
34+
#endif
35+
36+
#undef _CLC_ISEQUAL_DECL
37+
#undef _CLC_VECTOR_ISEQUAL_DECL
38+
39+
#endif
40+
41+
#endif // __CLC_RELATIONAL_CLC_ISEQUAL_H__
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef __CLC_RELATIONAL_CLC_ISFINITE_H__
2+
#define __CLC_RELATIONAL_CLC_ISFINITE_H__
3+
4+
#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
5+
// clspv and spir-v targets provide their own OpenCL-compatible isfinite
6+
#define __clc_isfinite isfinite
7+
#else
8+
9+
#define __CLC_FUNCTION __clc_isfinite
10+
#define __CLC_BODY <clc/relational/unary_decl.inc>
11+
12+
#include <clc/relational/floatn.inc>
13+
14+
#undef __CLC_BODY
15+
#undef __CLC_FUNCTION
16+
17+
#endif
18+
19+
#endif // __CLC_RELATIONAL_CLC_ISFINITE_H__
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef __CLC_RELATIONAL_CLC_ISGREATER_H__
2+
#define __CLC_RELATIONAL_CLC_ISGREATER_H__
3+
4+
#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
5+
// clspv and spir-v targets provide their own OpenCL-compatible isgreater
6+
#define __clc_isgreater isgreater
7+
#else
8+
9+
#define __CLC_FUNCTION __clc_isgreater
10+
#define __CLC_BODY <clc/relational/binary_decl.inc>
11+
12+
#include <clc/relational/floatn.inc>
13+
14+
#undef __CLC_BODY
15+
#undef __CLC_FUNCTION
16+
17+
#endif
18+
19+
#endif // __CLC_RELATIONAL_CLC_ISGREATER_H__

0 commit comments

Comments
 (0)