File: bits.cl

package info (click to toggle)
intel-graphics-compiler 1.0.17791.18-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 102,312 kB
  • sloc: cpp: 935,343; lisp: 286,143; ansic: 16,196; python: 3,279; yacc: 2,487; lex: 1,642; pascal: 300; sh: 174; makefile: 27
file content (258 lines) | stat: -rw-r--r-- 18,245 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/*========================== begin_copyright_notice ============================

Copyright (C) 2017-2021 Intel Corporation

SPDX-License-Identifier: MIT

============================= end_copyright_notice ===========================*/

#define GENERATE_VECTOR_FUNCTIONS_3ARGS_2TYPES_T1_T2_T2( __func, __rettype, __argtype1, __argtype2, __abbrargtype1, __abbrargtype2 ) \
    __rettype##2 SPIRV_OVERLOADABLE SPIRV_BUILTIN(__func, _v2##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )( __argtype1##2 a, __argtype2 b, __argtype2 c) { \
        return ( __rettype##2 )( SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s0, b, c), \
                                 SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s1, b, c) ); \
    } \
    __rettype##3 SPIRV_OVERLOADABLE SPIRV_BUILTIN(__func, _v3##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )( __argtype1##3 a, __argtype2 b, __argtype2 c) { \
        return ( __rettype##3 )( SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s0, b, c), \
                                 SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s1, b, c), \
                                 SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s2, b, c) ); \
    } \
    __rettype##4 SPIRV_OVERLOADABLE SPIRV_BUILTIN(__func, _v4##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )( __argtype1##4 a, __argtype2 b, __argtype2 c) { \
        return ( __rettype##4 )( SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s0, b, c), \
                                 SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s1, b, c), \
                                 SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s2, b, c), \
                                 SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s3, b, c) ); \
    } \
    __rettype##8 SPIRV_OVERLOADABLE SPIRV_BUILTIN(__func, _v8##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )( __argtype1##8 a, __argtype2 b, __argtype2 c) { \
        return ( __rettype##8 )( SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s0, b, c), \
                                 SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s1, b, c), \
                                 SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s2, b, c), \
                                 SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s3, b, c), \
                                 SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s4, b, c), \
                                 SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s5, b, c), \
                                 SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s6, b, c), \
                                 SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s7, b, c) ); \
    } \
    __rettype##16 SPIRV_OVERLOADABLE SPIRV_BUILTIN(__func, _v16##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )( __argtype1##16 a, __argtype2 b, __argtype2 c) { \
        return ( __rettype##16 )( SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s0, b, c), \
                                  SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s1, b, c), \
                                  SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s2, b, c), \
                                  SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s3, b, c), \
                                  SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s4, b, c), \
                                  SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s5, b, c), \
                                  SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s6, b, c), \
                                  SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s7, b, c), \
                                  SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s8, b, c), \
                                  SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s9, b, c), \
                                  SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.sa, b, c), \
                                  SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.sb, b, c), \
                                  SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.sc, b, c), \
                                  SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.sd, b, c), \
                                  SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.se, b, c), \
                                  SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.sf, b, c) ); \
    }

#define GENERATE_VECTOR_FUNCTIONS_4ARGS_2TYPES_T1_T1_T2_T2( __func, __rettype, __argtype1, __argtype2, __abbrargtype1, __abbrargtype2 ) \
    __rettype##2  SPIRV_OVERLOADABLE SPIRV_BUILTIN(__func, _v2##__abbrargtype1##_v2##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, ) \
    ( __argtype1##2 a, __argtype1##2 b, u##__argtype2 c, u##__argtype2 d) { \
        return ( __rettype##2 )( SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s0, b.s0, c, d), \
                                 SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s1, b.s1, c, d) ); \
    } \
    __rettype##3 SPIRV_OVERLOADABLE SPIRV_BUILTIN(__func, _v3##__abbrargtype1##_v3##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, ) \
    ( __argtype1##3 a, __argtype1##3 b, u##__argtype2 c, u##__argtype2 d) { \
        return ( __rettype##3 )( SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s0, b.s0, c, d), \
                                 SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s1, b.s1, c, d), \
                                 SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s2, b.s2, c, d) ); \
    } \
    __rettype##4 SPIRV_OVERLOADABLE SPIRV_BUILTIN(__func, _v4##__abbrargtype1##_v4##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, ) \
    ( __argtype1##4 a, __argtype1##4 b, u##__argtype2 c, u##__argtype2 d) { \
        return ( __rettype##4 )( SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s0, b.s0, c, d), \
                                 SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s1, b.s1, c, d), \
                                 SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s2, b.s2, c, d), \
                                 SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s3, b.s3, c, d) ); \
    } \
    __rettype##8 SPIRV_OVERLOADABLE SPIRV_BUILTIN(__func, _v8##__abbrargtype1##_v8##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, ) \
    ( __argtype1##8 a, __argtype1##8 b, u##__argtype2 c, u##__argtype2 d) { \
        return ( __rettype##8 )( SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s0, b.s0, c, d), \
                                 SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s1, b.s1, c, d), \
                                 SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s2, b.s2, c, d), \
                                 SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s3, b.s3, c, d), \
                                 SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s4, b.s4, c, d), \
                                 SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s5, b.s5, c, d), \
                                 SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s6, b.s6, c, d), \
                                 SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s7, b.s7, c, d) ); \
    } \
    __rettype##16 SPIRV_OVERLOADABLE SPIRV_BUILTIN(__func, _v16##__abbrargtype1##_v16##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, ) \
    ( __argtype1##16 a, __argtype1##16 b, u##__argtype2 c, u##__argtype2 d) { \
        return ( __rettype##16 )( SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s0, b.s0, c, d), \
                                  SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s1, b.s1, c, d), \
                                  SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s2, b.s2, c, d), \
                                  SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s3, b.s3, c, d), \
                                  SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s4, b.s4, c, d), \
                                  SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s5, b.s5, c, d), \
                                  SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s6, b.s6, c, d), \
                                  SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s7, b.s7, c, d), \
                                  SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s8, b.s8, c, d), \
                                  SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.s9, b.s9, c, d), \
                                  SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.sa, b.sa, c, d), \
                                  SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.sb, b.sb, c, d), \
                                  SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.sc, b.sc, c, d), \
                                  SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.sd, b.sd, c, d), \
                                  SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.se, b.se, c, d), \
                                  SPIRV_BUILTIN(__func, _##__abbrargtype1##_##__abbrargtype1##_##__abbrargtype2##_##__abbrargtype2, )(a.sf, b.sf, c, d) ); \
    }

// Bit Instructions

char SPIRV_OVERLOADABLE SPIRV_BUILTIN(BitFieldInsert, _i8_i8_i32_i32, )(char Base, char Insert, uint Offset, uint Count)
{
    return __builtin_IB_bfi(Count, Offset, (uint)Insert, (uint)Base);
}

short SPIRV_OVERLOADABLE SPIRV_BUILTIN(BitFieldInsert, _i16_i16_i32_i32, )(short Base, short Insert, uint Offset, uint Count)
{
    return __builtin_IB_bfi(Count, Offset, (uint)Insert, (uint)Base);
}

int SPIRV_OVERLOADABLE SPIRV_BUILTIN(BitFieldInsert, _i32_i32_i32_i32, )(int Base, int Insert, uint Offset, uint Count)
{
    // edge case: hardware reads width (count) from 5 bits, so it's unable to achieve 32
    const uint Result = __builtin_IB_bfi(Count, Offset, Insert, Base);
    return (Count == 32 && Offset == 0) ? Insert : Result;
}

long SPIRV_OVERLOADABLE SPIRV_BUILTIN(BitFieldInsert, _i64_i64_i32_i32, )(long Base, long Insert, uint Offset, uint Count)
{
    const int Size = 64;
    const uint OffsetPlusCount = Offset + Count;
    const uint SizeMinusOffset = Size - Offset;
    const uint SizeMinusCount = Size - Count;
    const uint Rest = Size - OffsetPlusCount;
    ulong xoo = (as_ulong(Base) >> OffsetPlusCount) << OffsetPlusCount;
    xoo = OffsetPlusCount == Size ? 0 : xoo;
    ulong oox = (as_ulong(Base) << SizeMinusOffset) >> SizeMinusOffset;
    oox = SizeMinusOffset == Size ? 0 : oox;
    ulong oxo = as_ulong(Insert) << SizeMinusCount;
    oxo = SizeMinusCount == Size ? 0 : oxo;
    oxo >>= Rest;
    oxo = Rest == Size ? 0 : oxo;
    const ulong Result = ( xoo | oxo | oox );
    return Count == 0 ? Base : Result;
}

GENERATE_VECTOR_FUNCTIONS_4ARGS_2TYPES_T1_T1_T2_T2( BitFieldInsert, char,  char,  int, i8,  i32 )
GENERATE_VECTOR_FUNCTIONS_4ARGS_2TYPES_T1_T1_T2_T2( BitFieldInsert, short, short, int, i16, i32 )
GENERATE_VECTOR_FUNCTIONS_4ARGS_2TYPES_T1_T1_T2_T2( BitFieldInsert, int,   int,   int, i32, i32 )
GENERATE_VECTOR_FUNCTIONS_4ARGS_2TYPES_T1_T1_T2_T2( BitFieldInsert, long,  long,  int, i64, i32 )

char SPIRV_OVERLOADABLE SPIRV_BUILTIN(BitFieldSExtract, _i8_i32_i32, )(char Base, uint Offset, uint Count)
{
    return __builtin_IB_ibfe(Count, Offset, (uint)Base);
}

short SPIRV_OVERLOADABLE SPIRV_BUILTIN(BitFieldSExtract, _i16_i32_i32, )(short Base, uint Offset, uint Count)
{
    return __builtin_IB_ibfe(Count, Offset, (uint)Base);
}

int SPIRV_OVERLOADABLE SPIRV_BUILTIN(BitFieldSExtract, _i32_i32_i32, )(int Base, uint Offset, uint Count)
{
    // edge case: hardware reads width (count) from 5 bits, so it's unable to achieve 32
    const int Result = __builtin_IB_ibfe(Count, Offset, Base);
    return (Count == 32 && Offset == 0) ? Base : Result;
}

long SPIRV_OVERLOADABLE SPIRV_BUILTIN(BitFieldSExtract, _i64_i32_i32, )(long Base, uint Offset, uint Count)
{
    const int Size = 64;
    const int Rest = Size - Offset - Count;
    const long Result = ((Base << Rest) >> (Size - Count));
    return Count == 0 ? 0 : Result;
}

GENERATE_VECTOR_FUNCTIONS_3ARGS_2TYPES_T1_T2_T2( BitFieldSExtract, char,  char,  uint, i8,  i32 )
GENERATE_VECTOR_FUNCTIONS_3ARGS_2TYPES_T1_T2_T2( BitFieldSExtract, short, short, uint, i16, i32 )
GENERATE_VECTOR_FUNCTIONS_3ARGS_2TYPES_T1_T2_T2( BitFieldSExtract, int,   int,   uint, i32, i32 )
GENERATE_VECTOR_FUNCTIONS_3ARGS_2TYPES_T1_T2_T2( BitFieldSExtract, long,  long,  uint, i64, i32 )

uchar SPIRV_OVERLOADABLE SPIRV_BUILTIN(BitFieldUExtract, _i8_i32_i32, )(uchar Base, uint Offset, uint Count)
{
    return __builtin_IB_ubfe(Count, Offset, (uint)Base);
}

ushort SPIRV_OVERLOADABLE SPIRV_BUILTIN(BitFieldUExtract, _i16_i32_i32, )(ushort Base, uint Offset, uint Count)
{
    return __builtin_IB_ubfe(Count, Offset, (uint)Base);
}

uint SPIRV_OVERLOADABLE SPIRV_BUILTIN(BitFieldUExtract, _i32_i32_i32, )(uint Base, uint Offset, uint Count)
{
    // edge case: hardware reads width (count) from 5 bits, so it's unable to achieve 32
    const uint Result = __builtin_IB_ubfe(Count, Offset, Base);
    return (Count ==  32 && Offset == 0) ? Base : Result;
}

ulong SPIRV_OVERLOADABLE SPIRV_BUILTIN(BitFieldUExtract, _i64_i32_i32, )(ulong Base, uint Offset, uint Count)
{
    const int Size = 64;
    const int Rest = Size - Offset - Count;
    const ulong Result = ((Base << Rest) >> (Size - Count));
    return Count == 0 ? 0 : Result;
}

GENERATE_VECTOR_FUNCTIONS_3ARGS_2TYPES_T1_T2_T2( BitFieldUExtract, uchar,  uchar,  uint, i8,  i32 )
GENERATE_VECTOR_FUNCTIONS_3ARGS_2TYPES_T1_T2_T2( BitFieldUExtract, ushort, ushort, uint, i16, i32 )
GENERATE_VECTOR_FUNCTIONS_3ARGS_2TYPES_T1_T2_T2( BitFieldUExtract, uint,   uint,   uint, i32, i32 )
GENERATE_VECTOR_FUNCTIONS_3ARGS_2TYPES_T1_T2_T2( BitFieldUExtract, ulong,  ulong,  uint, i64, i32 )

char SPIRV_OVERLOADABLE SPIRV_BUILTIN(BitReverse, _i8, )(char Base)
{
    return  __builtin_IB_bfrev( (uint)Base) >> 24;
}

short SPIRV_OVERLOADABLE SPIRV_BUILTIN(BitReverse, _i16, )(short Base)
{
    return  __builtin_IB_bfrev( (uint)Base) >> 16;
}

int SPIRV_OVERLOADABLE SPIRV_BUILTIN(BitReverse, _i32, )(int Base)
{
    return __builtin_IB_bfrev(Base);
}

long SPIRV_OVERLOADABLE SPIRV_BUILTIN(BitReverse, _i64, )(long Base)
{
    return ((ulong)__builtin_IB_bfrev((uint)Base) << 32) | (ulong)__builtin_IB_bfrev((Base >> 32));
}

SPIRV_GENERATE_VECTOR_FUNCTIONS_1ARG( BitReverse, char,  char,  i8 )
SPIRV_GENERATE_VECTOR_FUNCTIONS_1ARG( BitReverse, short, short, i16 )
SPIRV_GENERATE_VECTOR_FUNCTIONS_1ARG( BitReverse, int,   int,   i32 )
SPIRV_GENERATE_VECTOR_FUNCTIONS_1ARG( BitReverse, long,  long,  i64 )


uchar SPIRV_OVERLOADABLE SPIRV_BUILTIN(BitCount, _i8, )(char Base)
{
    return __builtin_IB_popcount_1u8(as_uchar(Base));
}

ushort SPIRV_OVERLOADABLE SPIRV_BUILTIN(BitCount, _i16, )(short Base)
{
    return __builtin_IB_popcount_1u16(as_ushort(Base));
}

uint SPIRV_OVERLOADABLE SPIRV_BUILTIN(BitCount, _i32, )(int Base)
{
    return __builtin_IB_popcount_1u32(as_uint(Base));
}

ulong SPIRV_OVERLOADABLE SPIRV_BUILTIN(BitCount, _i64, )(long Base)
{
    return SPIRV_BUILTIN(BitCount, _i32, )((int)(as_ulong(Base) >> 32)) + SPIRV_BUILTIN(BitCount, _i32, )((int)Base);
}

SPIRV_GENERATE_VECTOR_FUNCTIONS_1ARG( BitCount, uchar,  char,  i8 )
SPIRV_GENERATE_VECTOR_FUNCTIONS_1ARG( BitCount, ushort, short, i16 )
SPIRV_GENERATE_VECTOR_FUNCTIONS_1ARG( BitCount, uint,   int,   i32 )
SPIRV_GENERATE_VECTOR_FUNCTIONS_1ARG( BitCount, ulong,  long,  i64 )