1 //
2 // Copyright (c) 2020-2022 The Khronos Group Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /*
18 Some versions of inttypes.h required defining the macro __STDC_FORMAT_MACROS to
19 use the format macros for C++ compiles, but not all. To improve robustness we
20 will use inttypes.h for C compiles and cinttypes for C++ compiles.
21 */
22 #if defined(__cplusplus)
23 #include <cinttypes>
24 #else
25 #include <inttypes.h>
26 #endif
27
28 #include <stdio.h>
29
30 #include "CL/cl.h"
31
test_char()32 int test_char()
33 {
34 /* char */
35 /* Constructor */
36 cl_char a = 0;
37 cl_char2 a2 = {{ 0, 1 }};
38 cl_char4 a4 = {{ 0, 1, 2, 3 }};
39 cl_char8 a8 = {{ 0, 1, 2, 3, 4, 5, 6, 7 }};
40 cl_char16 a16 = {{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }};
41
42 /* assignment */
43 cl_char b = a;
44 cl_char2 b2 = a2;
45 cl_char4 b4 = a4;
46 cl_char8 b8 = a8;
47 cl_char16 b16 = a16;
48
49 printf("\nVerifying assignment:\n" );
50 printf("b: %d\n", b );
51 printf("b2: %d %d \n", b2.s[0], b2.s[1] );
52 printf("b4: %d %d %d %d\n", b4.s[0], b4.s[1], b4.s[2], b4.s[3] );
53 printf("b8: %d %d %d %d %d %d %d %d\n", b8.s[0], b8.s[1], b8.s[2], b8.s[3], b8.s[4], b8.s[5], b8.s[6], b8.s[7] );
54 printf("b16: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", b16.s[0], b16.s[1], b16.s[2], b16.s[3], b16.s[4], b16.s[5], b16.s[6], b16.s[7],
55 b16.s[8], b16.s[9], b16.s[10], b16.s[11], b16.s[12], b16.s[13], b16.s[14], b16.s[15]);
56
57 /* vector access */
58 printf("\nVerifying vector access:\n" );
59 #if defined( __CL_CHAR2__ )
60 __cl_char2 v2 = b2.v2;
61 printf("__cl_char2: %d %d \n", ((cl_char*)&v2)[0], ((cl_char*)&v2)[1] );
62 #else
63 printf( "__cl_char2 SIMD vectors not supported on this architecture.\n" );
64 #endif
65
66 #if defined( __CL_CHAR4__ )
67 __cl_char4 v4 = b4.v4;
68 printf("__cl_char4: %d %d %d %d \n", ((cl_char*)&v4)[0], ((cl_char*)&v4)[1], ((cl_char*)&v4)[2], ((cl_char*)&v4)[3] );
69 #else
70 printf( "__cl_char4 SIMD vectors not supported on this architecture.\n" );
71 #endif
72
73 #if defined( __CL_CHAR8__ )
74 __cl_char8 v8 = b8.v8;
75 printf("__cl_char8: %d %d %d %d %d %d %d %d \n", ((cl_char*)&v8)[0], ((cl_char*)&v8)[1], ((cl_char*)&v8)[2], ((cl_char*)&v8)[3], ((cl_char*)&v8)[4], ((cl_char*)&v8)[5], ((cl_char*)&v8)[6], ((cl_char*)&v8)[7] );
76 #else
77 printf( "__cl_char8 SIMD vectors not supported on this architecture.\n" );
78 #endif
79
80 #if defined( __CL_CHAR16__ )
81 __cl_char16 v16 = b16.v16;
82 printf("__cl_char16: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d \n", ((cl_char*)&v16)[0], ((cl_char*)&v16)[1], ((cl_char*)&v16)[2], ((cl_char*)&v16)[3], ((cl_char*)&v16)[4], ((cl_char*)&v16)[5], ((cl_char*)&v16)[6], ((cl_char*)&v16)[7],
83 ((cl_char*)&v16)[8], ((cl_char*)&v16)[9], ((cl_char*)&v16)[10], ((cl_char*)&v16)[11], ((cl_char*)&v16)[12], ((cl_char*)&v16)[13], ((cl_char*)&v16)[14], ((cl_char*)&v16)[15]);
84 #else
85 printf( "__cl_char16 SIMD vectors not supported on this architecture.\n" );
86 #endif
87
88 printf( "\n" );
89 return 0;
90 }
91
test_uchar()92 int test_uchar()
93 {
94 /* uchar */
95 /* Constructor */
96 cl_uchar a = 0;
97 cl_uchar2 a2 = {{ 0, 1 }};
98 cl_uchar4 a4 = {{ 0, 1, 2, 3 }};
99 cl_uchar8 a8 = {{ 0, 1, 2, 3, 4, 5, 6, 7 }};
100 cl_uchar16 a16 = {{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }};
101
102 /* assignment */
103 cl_uchar b = a;
104 cl_uchar2 b2 = a2;
105 cl_uchar4 b4 = a4;
106 cl_uchar8 b8 = a8;
107 cl_uchar16 b16 = a16;
108
109 printf("\nVerifying assignment:\n" );
110 printf("b: %d\n", b );
111 printf("b2: %d %d \n", b2.s[0], b2.s[1] );
112 printf("b4: %d %d %d %d\n", b4.s[0], b4.s[1], b4.s[2], b4.s[3] );
113 printf("b8: %d %d %d %d %d %d %d %d\n", b8.s[0], b8.s[1], b8.s[2], b8.s[3], b8.s[4], b8.s[5], b8.s[6], b8.s[7] );
114 printf("b16: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", b16.s[0], b16.s[1], b16.s[2], b16.s[3], b16.s[4], b16.s[5], b16.s[6], b16.s[7],
115 b16.s[8], b16.s[9], b16.s[10], b16.s[11], b16.s[12], b16.s[13], b16.s[14], b16.s[15]);
116
117 /* vector access */
118 printf("\nVerifying vector access:\n" );
119 #if defined( __CL_UCHAR2__ )
120 __cl_uchar2 v2 = b2.v2;
121 printf("__cl_uchar2: %d %d \n", ((uchar*)&v2)[0], ((cl_uchar*)&v2)[1] );
122 #else
123 printf( "__cl_uchar2 SIMD vectors not supported on this architecture.\n" );
124 #endif
125
126 #if defined( __CL_UCHAR4__ )
127 __cl_uchar4 v4 = b4.v4;
128 printf("__cl_uchar4: %d %d %d %d \n", ((uchar*)&v4)[0], ((cl_uchar*)&v4)[1], ((cl_uchar*)&v4)[2], ((cl_uchar*)&v4)[3] );
129 #else
130 printf( "__cl_uchar4 SIMD vectors not supported on this architecture.\n" );
131 #endif
132
133 #if defined( __CL_UCHAR8__ )
134 __cl_uchar8 v8 = b8.v8;
135 printf("__cl_uchar8: %d %d %d %d %d %d %d %d \n", ((cl_uchar*)&v8)[0], ((cl_uchar*)&v8)[1], ((cl_uchar*)&v8)[2], ((cl_uchar*)&v8)[3], ((cl_uchar*)&v8)[4], ((cl_uchar*)&v8)[5], ((cl_uchar*)&v8)[6], ((cl_uchar*)&v8)[7] );
136 #else
137 printf( "__cl_uchar8 SIMD vectors not supported on this architecture.\n" );
138 #endif
139
140 #if defined( __CL_UCHAR16__ )
141 __cl_uchar16 v16 = b16.v16;
142 printf("__cl_uchar16: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d \n", ((cl_uchar*)&v16)[0], ((cl_uchar*)&v16)[1], ((cl_uchar*)&v16)[2], ((cl_uchar*)&v16)[3], ((cl_uchar*)&v16)[4], ((cl_uchar*)&v16)[5], ((cl_uchar*)&v16)[6], ((cl_uchar*)&v16)[7],
143 ((cl_uchar*)&v16)[8], ((cl_uchar*)&v16)[9], ((cl_uchar*)&v16)[10], ((cl_uchar*)&v16)[11], ((cl_uchar*)&v16)[12], ((cl_uchar*)&v16)[13], ((cl_uchar*)&v16)[14], ((cl_uchar*)&v16)[15]);
144 #else
145 printf( "__cl_uchar16 SIMD vectors not supported on this architecture.\n" );
146 #endif
147
148 printf( "\n" );
149 return 0;
150 }
151
test_short()152 int test_short()
153 {
154 /* short */
155 /* Constructor */
156 cl_short a = 0;
157 cl_short2 a2 = {{ 0, 1 }};
158 cl_short4 a4 = {{ 0, 1, 2, 3 }};
159 cl_short8 a8 = {{ 0, 1, 2, 3, 4, 5, 6, 7 }};
160 cl_short16 a16 = {{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }};
161
162 /* assignment */
163 cl_short b = a;
164 cl_short2 b2 = a2;
165 cl_short4 b4 = a4;
166 cl_short8 b8 = a8;
167 cl_short16 b16 = a16;
168
169 printf("\nVerifying assignment:\n" );
170 printf("b: %d\n", b );
171 printf("b2: %d %d \n", b2.s[0], b2.s[1] );
172 printf("b4: %d %d %d %d\n", b4.s[0], b4.s[1], b4.s[2], b4.s[3] );
173 printf("b8: %d %d %d %d %d %d %d %d\n", b8.s[0], b8.s[1], b8.s[2], b8.s[3], b8.s[4], b8.s[5], b8.s[6], b8.s[7] );
174 printf("b16: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", b16.s[0], b16.s[1], b16.s[2], b16.s[3], b16.s[4], b16.s[5], b16.s[6], b16.s[7],
175 b16.s[8], b16.s[9], b16.s[10], b16.s[11], b16.s[12], b16.s[13], b16.s[14], b16.s[15]);
176
177 /* vector access */
178 printf("\nVerifying vector access:\n" );
179 #if defined( __CL_SHORT2__ )
180 __cl_short2 v2 = b2.v2;
181 printf("__cl_short2: %d %d \n", ((cl_short*)&v2)[0], ((cl_short*)&v2)[1] );
182 #else
183 printf( "__cl_short2 SIMD vectors not supported on this architecture.\n" );
184 #endif
185
186 #if defined( __CL_SHORT4__ )
187 __cl_short4 v4 = b4.v4;
188 printf("__cl_short4: %d %d %d %d \n", ((cl_short*)&v4)[0], ((cl_short*)&v4)[1], ((cl_short*)&v4)[2], ((cl_short*)&v4)[3] );
189 #else
190 printf( "__cl_short4 SIMD vectors not supported on this architecture.\n" );
191 #endif
192
193 #if defined( __CL_SHORT8__ )
194 __cl_short8 v8 = b8.v8;
195 printf("__cl_short8: %d %d %d %d %d %d %d %d \n", ((cl_short*)&v8)[0], ((cl_short*)&v8)[1], ((cl_short*)&v8)[2], ((cl_short*)&v8)[3], ((cl_short*)&v8)[4], ((cl_short*)&v8)[5], ((cl_short*)&v8)[6], ((cl_short*)&v8)[7] );
196 #else
197 printf( "__cl_short8 SIMD vectors not supported on this architecture.\n" );
198 #endif
199
200 #if defined( __CL_SHORT16__ )
201 __cl_short16 v16 = b16.v16;
202 printf("__cl_short16: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d \n", ((cl_short*)&v16)[0], ((cl_short*)&v16)[1], ((cl_short*)&v16)[2], ((cl_short*)&v16)[3], ((cl_short*)&v16)[4], ((cl_short*)&v16)[5], ((cl_short*)&v16)[6], ((cl_short*)&v16)[7],
203 ((cl_short*)&v16)[8], ((cl_short*)&v16)[9], ((cl_short*)&v16)[10], ((cl_short*)&v16)[11], ((cl_short*)&v16)[12], ((cl_short*)&v16)[13], ((cl_short*)&v16)[14], ((cl_short*)&v16)[15]);
204 #else
205 printf( "__cl_short16 SIMD vectors not supported on this architecture.\n" );
206 #endif
207
208 printf( "\n" );
209 return 0;
210 }
211
test_ushort()212 int test_ushort()
213 {
214 /* ushort */
215 /* Constructor */
216 cl_ushort a = 0;
217 cl_ushort2 a2 = {{ 0, 1 }};
218 cl_ushort4 a4 = {{ 0, 1, 2, 3 }};
219 cl_ushort8 a8 = {{ 0, 1, 2, 3, 4, 5, 6, 7 }};
220 cl_ushort16 a16 = {{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }};
221
222 /* assignment */
223 cl_ushort b = a;
224 cl_ushort2 b2 = a2;
225 cl_ushort4 b4 = a4;
226 cl_ushort8 b8 = a8;
227 cl_ushort16 b16 = a16;
228
229 printf("\nVerifying assignment:\n" );
230 printf("b: %d\n", b );
231 printf("b2: %d %d \n", b2.s[0], b2.s[1] );
232 printf("b4: %d %d %d %d\n", b4.s[0], b4.s[1], b4.s[2], b4.s[3] );
233 printf("b8: %d %d %d %d %d %d %d %d\n", b8.s[0], b8.s[1], b8.s[2], b8.s[3], b8.s[4], b8.s[5], b8.s[6], b8.s[7] );
234 printf("b16: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", b16.s[0], b16.s[1], b16.s[2], b16.s[3], b16.s[4], b16.s[5], b16.s[6], b16.s[7],
235 b16.s[8], b16.s[9], b16.s[10], b16.s[11], b16.s[12], b16.s[13], b16.s[14], b16.s[15]);
236
237 /* vector access */
238 printf("\nVerifying vector access:\n" );
239 #if defined( __CL_USHORT2__ )
240 __cl_ushort2 v2 = b2.v2;
241 printf("__cl_ushort2: %d %d \n", ((unsigned short*)&v2)[0], ((unsigned short*)&v2)[1] );
242 #else
243 printf( "__cl_ushort2 SIMD vectors not supported on this architecture.\n" );
244 #endif
245
246 #if defined( __CL_USHORT4__ )
247 __cl_ushort4 v4 = b4.v4;
248 printf("__cl_ushort4: %d %d %d %d \n", ((unsigned short*)&v4)[0], ((unsigned short*)&v4)[1], ((unsigned short*)&v4)[2], ((unsigned short*)&v4)[3] );
249 #else
250 printf( "__cl_ushort4 SIMD vectors not supported on this architecture.\n" );
251 #endif
252
253 #if defined( __CL_USHORT8__ )
254 __cl_ushort8 v8 = b8.v8;
255 printf("__cl_ushort8: %d %d %d %d %d %d %d %d \n", ((unsigned short*)&v8)[0], ((unsigned short*)&v8)[1], ((unsigned short*)&v8)[2], ((unsigned short*)&v8)[3], ((unsigned short*)&v8)[4], ((unsigned short*)&v8)[5], ((unsigned short*)&v8)[6], ((unsigned short*)&v8)[7] );
256 #else
257 printf( "__cl_ushort8 SIMD vectors not supported on this architecture.\n" );
258 #endif
259
260 #if defined( __CL_USHORT16__ )
261 __cl_ushort16 v16 = b16.v16;
262 printf("__cl_ushort16: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d \n", ((unsigned short*)&v16)[0], ((unsigned short*)&v16)[1], ((unsigned short*)&v16)[2], ((unsigned short*)&v16)[3], ((unsigned short*)&v16)[4], ((unsigned short*)&v16)[5], ((unsigned short*)&v16)[6], ((unsigned short*)&v16)[7],
263 ((unsigned short*)&v16)[8], ((unsigned short*)&v16)[9], ((unsigned short*)&v16)[10], ((unsigned short*)&v16)[11], ((unsigned short*)&v16)[12], ((unsigned short*)&v16)[13], ((unsigned short*)&v16)[14], ((unsigned short*)&v16)[15]);
264 #else
265 printf( "__cl_ushort16 SIMD vectors not supported on this architecture.\n" );
266 #endif
267
268 printf( "\n" );
269 return 0;
270 }
271
test_int()272 int test_int()
273 {
274 /* int */
275 /* Constructor */
276 cl_int a = 0;
277 cl_int2 a2 = {{ 0, 1 }};
278 cl_int4 a4 = {{ 0, 1, 2, 3 }};
279 cl_int8 a8 = {{ 0, 1, 2, 3, 4, 5, 6, 7 }};
280 cl_int16 a16 = {{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }};
281
282 /* assignment */
283 cl_int b = a;
284 cl_int2 b2 = a2;
285 cl_int4 b4 = a4;
286 cl_int8 b8 = a8;
287 cl_int16 b16 = a16;
288
289 printf("\nVerifying assignment:\n" );
290 printf("b: %d\n", b );
291 printf("b2: %d %d \n", b2.s[0], b2.s[1] );
292 printf("b4: %d %d %d %d\n", b4.s[0], b4.s[1], b4.s[2], b4.s[3] );
293 printf("b8: %d %d %d %d %d %d %d %d\n", b8.s[0], b8.s[1], b8.s[2], b8.s[3], b8.s[4], b8.s[5], b8.s[6], b8.s[7] );
294 printf("b16: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", b16.s[0], b16.s[1], b16.s[2], b16.s[3], b16.s[4], b16.s[5], b16.s[6], b16.s[7],
295 b16.s[8], b16.s[9], b16.s[10], b16.s[11], b16.s[12], b16.s[13], b16.s[14], b16.s[15]);
296
297 /* vector access */
298 printf("\nVerifying vector access:\n" );
299 #if defined( __CL_INT2__ )
300 __cl_int2 v2 = b2.v2;
301 printf("__cl_int2: %d %d \n", ((cl_int*)&v2)[0], ((cl_int*)&v2)[1] );
302 #else
303 printf( "__cl_int2 SIMD vectors not supported on this architecture.\n" );
304 #endif
305
306 #if defined( __CL_INT4__ )
307 __cl_int4 v4 = b4.v4;
308 printf("__cl_int4: %d %d %d %d \n", ((cl_int*)&v4)[0], ((cl_int*)&v4)[1], ((cl_int*)&v4)[2], ((cl_int*)&v4)[3] );
309 #else
310 printf( "__cl_int4 SIMD vectors not supported on this architecture.\n" );
311 #endif
312
313 #if defined( __CL_INT8__ )
314 __cl_int8 v8 = b8.v8;
315 printf("__cl_int8: %d %d %d %d %d %d %d %d \n", ((cl_int*)&v8)[0], ((cl_int*)&v8)[1], ((cl_int*)&v8)[2], ((cl_int*)&v8)[3], ((cl_int*)&v8)[4], ((cl_int*)&v8)[5], ((cl_int*)&v8)[6], ((cl_int*)&v8)[7] );
316 #else
317 printf( "__cl_int8 SIMD vectors not supported on this architecture.\n" );
318 #endif
319
320 #if defined( __CL_INT16__ )
321 __cl_int16 v16 = b16.v16;
322 printf("__cl_int16: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d \n", ((cl_int*)&v16)[0], ((cl_int*)&v16)[1], ((cl_int*)&v16)[2], ((cl_int*)&v16)[3], ((cl_int*)&v16)[4], ((cl_int*)&v16)[5], ((cl_int*)&v16)[6], ((cl_int*)&v16)[7],
323 ((cl_int*)&v16)[8], ((cl_int*)&v16)[9], ((cl_int*)&v16)[10], ((cl_int*)&v16)[11], ((cl_int*)&v16)[12], ((cl_int*)&v16)[13], ((cl_int*)&v16)[14], ((cl_int*)&v16)[15]);
324 #else
325 printf( "__cl_int16 SIMD vectors not supported on this architecture.\n" );
326 #endif
327
328 printf( "\n" );
329 return 0;
330 }
331
test_uint()332 int test_uint()
333 {
334 /* uint */
335 /* Constructor */
336 cl_uint a = 0;
337 cl_uint2 a2 = {{ 0, 1 }};
338 cl_uint4 a4 = {{ 0, 1, 2, 3 }};
339 cl_uint8 a8 = {{ 0, 1, 2, 3, 4, 5, 6, 7 }};
340 cl_uint16 a16 = {{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }};
341
342 /* assignment */
343 cl_uint b = a;
344 cl_uint2 b2 = a2;
345 cl_uint4 b4 = a4;
346 cl_uint8 b8 = a8;
347 cl_uint16 b16 = a16;
348
349 printf("\nVerifying assignment:\n" );
350 printf("b: %d\n", b );
351 printf("b2: %d %d \n", b2.s[0], b2.s[1] );
352 printf("b4: %d %d %d %d\n", b4.s[0], b4.s[1], b4.s[2], b4.s[3] );
353 printf("b8: %d %d %d %d %d %d %d %d\n", b8.s[0], b8.s[1], b8.s[2], b8.s[3], b8.s[4], b8.s[5], b8.s[6], b8.s[7] );
354 printf("b16: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", b16.s[0], b16.s[1], b16.s[2], b16.s[3], b16.s[4], b16.s[5], b16.s[6], b16.s[7],
355 b16.s[8], b16.s[9], b16.s[10], b16.s[11], b16.s[12], b16.s[13], b16.s[14], b16.s[15]);
356
357 /* vector access */
358 printf("\nVerifying vector access:\n" );
359 #if defined( __CL_UINT2__ )
360 __cl_uint2 v2 = b2.v2;
361 printf("__cl_uint2: %d %d \n", ((cl_uint*)&v2)[0], ((cl_uint*)&v2)[1] );
362 #else
363 printf( "__cl_uint2 SIMD vectors not supported on this architecture.\n" );
364 #endif
365
366 #if defined( __CL_UINT4__ )
367 __cl_uint4 v4 = b4.v4;
368 printf("__cl_uint4: %d %d %d %d \n", ((cl_uint*)&v4)[0], ((cl_uint*)&v4)[1], ((cl_uint*)&v4)[2], ((cl_uint*)&v4)[3] );
369 #else
370 printf( "__cl_uint4 SIMD vectors not supported on this architecture.\n" );
371 #endif
372
373 #if defined( __CL_UINT8__ )
374 __cl_uint8 v8 = b8.v8;
375 printf("__cl_uint8: %d %d %d %d %d %d %d %d \n", ((cl_uint*)&v8)[0], ((cl_uint*)&v8)[1], ((cl_uint*)&v8)[2], ((cl_uint*)&v8)[3], ((cl_uint*)&v8)[4], ((cl_uint*)&v8)[5], ((cl_uint*)&v8)[6], ((cl_uint*)&v8)[7] );
376 #else
377 printf( "__cl_uint8 SIMD vectors not supported on this architecture.\n" );
378 #endif
379
380 #if defined( __CL_UINT16__ )
381 __cl_uint16 v16 = b16.v16;
382 printf("__cl_uint16: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d \n", ((cl_uint*)&v16)[0], ((cl_uint*)&v16)[1], ((cl_uint*)&v16)[2], ((cl_uint*)&v16)[3], ((cl_uint*)&v16)[4], ((cl_uint*)&v16)[5], ((cl_uint*)&v16)[6], ((cl_uint*)&v16)[7],
383 ((cl_uint*)&v16)[8], ((cl_uint*)&v16)[9], ((cl_uint*)&v16)[10], ((cl_uint*)&v16)[11], ((cl_uint*)&v16)[12], ((cl_uint*)&v16)[13], ((cl_uint*)&v16)[14], ((cl_uint*)&v16)[15]);
384 #else
385 printf( "__cl_uint16 SIMD vectors not supported on this architecture.\n" );
386 #endif
387
388 printf( "\n" );
389 return 0;
390 }
391
test_long()392 int test_long()
393 {
394 /* long */
395 /* Constructor */
396 cl_long a = 0;
397 cl_long2 a2 = {{ 0, 1 }};
398 cl_long4 a4 = {{ 0, 1, 2, 3 }};
399 cl_long8 a8 = {{ 0, 1, 2, 3, 4, 5, 6, 7 }};
400 cl_long16 a16 = {{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }};
401
402 /* assignment */
403 cl_long b = a;
404 cl_long2 b2 = a2;
405 cl_long4 b4 = a4;
406 cl_long8 b8 = a8;
407 cl_long16 b16 = a16;
408
409 printf("\nVerifying assignment:\n" );
410 printf("b: %" PRId64 "\n", b );
411 printf("b2: %" PRId64 " %" PRId64 " \n", b2.s[0], b2.s[1] );
412 printf("b4: %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 "\n", b4.s[0], b4.s[1], b4.s[2], b4.s[3] );
413 printf("b8: %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 "\n", b8.s[0], b8.s[1], b8.s[2], b8.s[3], b8.s[4], b8.s[5], b8.s[6], b8.s[7] );
414 printf("b16: %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 "\n", b16.s[0], b16.s[1], b16.s[2], b16.s[3], b16.s[4], b16.s[5], b16.s[6], b16.s[7],
415 b16.s[8], b16.s[9], b16.s[10], b16.s[11], b16.s[12], b16.s[13], b16.s[14], b16.s[15]);
416
417 /* vector access */
418 printf("\nVerifying vector access:\n" );
419 #if defined( __CL_LONG2__ )
420 __cl_long2 v2 = b2.v2;
421 printf("__cl_long2: %" PRId64 " %" PRId64 " \n", ((cl_long*)&v2)[0], ((cl_long*)&v2)[1] );
422 #else
423 printf( "__cl_long2 SIMD vectors not supported on this architecture.\n" );
424 #endif
425
426 #if defined( __CL_LONG4__ )
427 __cl_long4 v4 = b4.v4;
428 printf("__cl_long4: %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " \n", ((cl_long*)&v4)[0], ((cl_long*)&v4)[1], ((cl_long*)&v4)[2], ((cl_long*)&v4)[3] );
429 #else
430 printf( "__cl_long4 SIMD vectors not supported on this architecture.\n" );
431 #endif
432
433 #if defined( __CL_LONG8__ )
434 __cl_long8 v8 = b8.v8;
435 printf("__cl_long8: %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " \n", ((cl_long*)&v8)[0], ((cl_long*)&v8)[1], ((cl_long*)&v8)[2], ((cl_long*)&v8)[3], ((cl_long*)&v8)[4], ((cl_long*)&v8)[5], ((cl_long*)&v8)[6], ((cl_long*)&v8)[7] );
436 #else
437 printf( "__cl_long8 SIMD vectors not supported on this architecture.\n" );
438 #endif
439
440 #if defined( __CL_LONG16__ )
441 __cl_long16 v16 = b16.v16;
442 printf("__cl_long16: %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " \n", ((cl_long*)&v16)[0], ((cl_long*)&v16)[1], ((cl_long*)&v16)[2], ((cl_long*)&v16)[3], ((cl_long*)&v16)[4], ((cl_long*)&v16)[5], ((cl_long*)&v16)[6], ((cl_long*)&v16)[7],
443 ((cl_long*)&v16)[8], ((cl_long*)&v16)[9], ((cl_long*)&v16)[10], ((cl_long*)&v16)[11], ((cl_long*)&v16)[12], ((cl_long*)&v16)[13], ((cl_long*)&v16)[14], ((cl_long*)&v16)[15]);
444 #else
445 printf( "__cl_long16 SIMD vectors not supported on this architecture.\n" );
446 #endif
447
448 printf( "\n" );
449 return 0;
450 }
451
test_ulong()452 int test_ulong()
453 {
454 /* ulong */
455 /* Constructor */
456 cl_ulong a = 0;
457 cl_ulong2 a2 = {{ 0, 1 }};
458 cl_ulong4 a4 = {{ 0, 1, 2, 3 }};
459 cl_ulong8 a8 = {{ 0, 1, 2, 3, 4, 5, 6, 7 }};
460 cl_ulong16 a16 = {{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }};
461
462 /* assignment */
463 cl_ulong b = a;
464 cl_ulong2 b2 = a2;
465 cl_ulong4 b4 = a4;
466 cl_ulong8 b8 = a8;
467 cl_ulong16 b16 = a16;
468
469 printf("\nVerifying assignment:\n" );
470 printf("b: %" PRIu64 "\n", b );
471 printf("b2: %" PRIu64 " %" PRIu64 " \n", b2.s[0], b2.s[1] );
472 printf("b4: %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 "\n", b4.s[0], b4.s[1], b4.s[2], b4.s[3] );
473 printf("b8: %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 "\n", b8.s[0], b8.s[1], b8.s[2], b8.s[3], b8.s[4], b8.s[5], b8.s[6], b8.s[7] );
474 printf("b16: %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 "\n", b16.s[0], b16.s[1], b16.s[2], b16.s[3], b16.s[4], b16.s[5], b16.s[6], b16.s[7],
475 b16.s[8], b16.s[9], b16.s[10], b16.s[11], b16.s[12], b16.s[13], b16.s[14], b16.s[15]);
476
477 /* vector access */
478 printf("\nVerifying vector access:\n" );
479 #if defined( __CL_ULONG2__ )
480 __cl_ulong2 v2 = b2.v2;
481 printf("__cl_ulong2: %" PRIu64 " %" PRIu64 " \n", ((cl_ulong*)&v2)[0], ((cl_ulong*)&v2)[1] );
482 #else
483 printf( "__cl_ulong2 SIMD vectors not supported on this architecture.\n" );
484 #endif
485
486 #if defined( __CL_ULONG4__ )
487 __cl_ulong4 v4 = b4.v4;
488 printf("__cl_ulong4: %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " \n", ((cl_ulong*)&v4)[0], ((cl_ulong*)&v4)[1], ((cl_ulong*)&v4)[2], ((cl_ulong*)&v4)[3] );
489 #else
490 printf( "__cl_ulong4 SIMD vectors not supported on this architecture.\n" );
491 #endif
492
493 #if defined( __CL_ULONG8__ )
494 __cl_ulong8 v8 = b8.v8;
495 printf("__cl_ulong8: %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " \n", ((cl_ulong*)&v8)[0], ((cl_ulong*)&v8)[1], ((cl_ulong*)&v8)[2], ((cl_ulong*)&v8)[3], ((cl_ulong*)&v8)[4], ((cl_ulong*)&v8)[5], ((cl_ulong*)&v8)[6], ((cl_ulong*)&v8)[7] );
496 #else
497 printf( "__cl_ulong8 SIMD vectors not supported on this architecture.\n" );
498 #endif
499
500 #if defined( __CL_ULONG16__ )
501 __cl_ulong16 v16 = b16.v16;
502 printf("__cl_ulong16: %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " \n", ((cl_ulong*)&v16)[0], ((cl_ulong*)&v16)[1], ((cl_ulong*)&v16)[2], ((cl_ulong*)&v16)[3], ((cl_ulong*)&v16)[4], ((cl_ulong*)&v16)[5], ((cl_ulong*)&v16)[6], ((cl_ulong*)&v16)[7],
503 ((cl_ulong*)&v16)[8], ((cl_ulong*)&v16)[9], ((cl_ulong*)&v16)[10], ((cl_ulong*)&v16)[11], ((cl_ulong*)&v16)[12], ((cl_ulong*)&v16)[13], ((cl_ulong*)&v16)[14], ((cl_ulong*)&v16)[15]);
504 #else
505 printf( "__cl_ulong16 SIMD vectors not supported on this architecture.\n" );
506 #endif
507
508 printf( "\n" );
509 return 0;
510 }
511
test_float()512 int test_float()
513 {
514 /* float */
515 /* Constructor */
516 cl_float a = 0.0f;
517 cl_float2 a2 = {{ 0.0f, 1.0f }};
518 cl_float4 a4 = {{ 0.0f, 1.0f, 2.0f, 3.0f }};
519 cl_float8 a8 = {{ 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f }};
520 cl_float16 a16 = {{ 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f }};
521
522 /* assignment */
523 cl_float b = a;
524 cl_float2 b2 = a2;
525 cl_float4 b4 = a4;
526 cl_float8 b8 = a8;
527 cl_float16 b16 = a16;
528
529 printf("\nVerifying assignment:\n" );
530 printf("b: %f\n", b );
531 printf("b2: %f %f \n", b2.s[0], b2.s[1] );
532 printf("b4: %f %f %f %f\n", b4.s[0], b4.s[1], b4.s[2], b4.s[3] );
533 printf("b8: %f %f %f %f %f %f %f %f\n", b8.s[0], b8.s[1], b8.s[2], b8.s[3], b8.s[4], b8.s[5], b8.s[6], b8.s[7] );
534 printf("b16: %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f\n", b16.s[0], b16.s[1], b16.s[2], b16.s[3], b16.s[4], b16.s[5], b16.s[6], b16.s[7],
535 b16.s[8], b16.s[9], b16.s[10], b16.s[11], b16.s[12], b16.s[13], b16.s[14], b16.s[15]);
536
537 /* vector access */
538 printf("\nVerifying vector access:\n" );
539 #if defined( __CL_FLOAT2__ )
540 __cl_float2 v2 = b2.v2;
541 printf("__cl_float2: %f %f \n", ((cl_float*)&v2)[0], ((cl_float*)&v2)[1] );
542 #else
543 printf( "__cl_float2 SIMD vectors not supported on this architecture.\n" );
544 #endif
545
546 #if defined( __CL_FLOAT4__ )
547 {
548 __cl_float4 v4 = b4.v4;
549 printf("__cl_float4: %f %f %f %f \n", ((cl_float*)&v4)[0], ((cl_float*)&v4)[1], ((cl_float*)&v4)[2], ((cl_float*)&v4)[3] );
550 }
551 #else
552 printf( "__cl_float4 SIMD vectors not supported on this architecture.\n" );
553 #endif
554
555 #if defined( __CL_FLOAT8__ )
556 __cl_float8 v8 = b8.v8;
557 printf("__cl_float8: %f %f %f %f %f %f %f %f \n", ((cl_float*)&v8)[0], ((cl_float*)&v8)[1], ((cl_float*)&v8)[2], ((cl_float*)&v8)[3], ((cl_float*)&v8)[4], ((cl_float*)&v8)[5], ((cl_float*)&v8)[6], ((cl_float*)&v8)[7] );
558 #else
559 printf( "__cl_float8 SIMD vectors not supported on this architecture.\n" );
560 #endif
561
562 #if defined( __CL_FLOAT16__ )
563 __cl_float16 v16 = b16.v16;
564 printf("__cl_float16: %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f \n", ((cl_float*)&v16)[0], ((cl_float*)&v16)[1], ((cl_float*)&v16)[2], ((cl_float*)&v16)[3], ((cl_float*)&v16)[4], ((cl_float*)&v16)[5], ((cl_float*)&v16)[6], ((cl_float*)&v16)[7],
565 ((cl_float*)&v16)[8], ((cl_float*)&v16)[9], ((cl_float*)&v16)[10], ((cl_float*)&v16)[11], ((cl_float*)&v16)[12], ((cl_float*)&v16)[13], ((cl_float*)&v16)[14], ((cl_float*)&v16)[15]);
566 #else
567 printf( "__cl_float16 SIMD vectors not supported on this architecture.\n" );
568 #endif
569
570 printf( "\n" );
571 return 0;
572 }
573
test_double()574 int test_double()
575 {
576 /* double */
577 /* Constructor */
578 cl_double a = 0.0f;
579 cl_double2 a2 = {{ 0.0f, 1.0f }};
580 cl_double4 a4 = {{ 0.0f, 1.0f, 2.0f, 3.0f }};
581 cl_double8 a8 = {{ 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f }};
582 cl_double16 a16 = {{ 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f }};
583
584 /* assignment */
585 cl_double b = a;
586 cl_double2 b2 = a2;
587 cl_double4 b4 = a4;
588 cl_double8 b8 = a8;
589 cl_double16 b16 = a16;
590
591 printf("\nVerifying assignment:\n" );
592 printf("b: %f\n", b );
593 printf("b2: %f %f \n", b2.s[0], b2.s[1] );
594 printf("b4: %f %f %f %f\n", b4.s[0], b4.s[1], b4.s[2], b4.s[3] );
595 printf("b8: %f %f %f %f %f %f %f %f\n", b8.s[0], b8.s[1], b8.s[2], b8.s[3], b8.s[4], b8.s[5], b8.s[6], b8.s[7] );
596 printf("b16: %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f\n", b16.s[0], b16.s[1], b16.s[2], b16.s[3], b16.s[4], b16.s[5], b16.s[6], b16.s[7],
597 b16.s[8], b16.s[9], b16.s[10], b16.s[11], b16.s[12], b16.s[13], b16.s[14], b16.s[15]);
598
599 /* vector access */
600 printf("\nVerifying vector access:\n" );
601 #if defined( __CL_DOUBLE2__ )
602 __cl_double2 v2 = b2.v2;
603 printf("__cl_double2: %f %f \n", ((cl_double*)&v2)[0], ((cl_double*)&v2)[1] );
604 #else
605 printf( "__cl_double2 SIMD vectors not supported on this architecture.\n" );
606 #endif
607
608 #if defined( __CL_DOUBLE4__ )
609 __cl_double4 v4 = b4.v4;
610 printf("__cl_double4: %f %f %f %f \n", ((cl_double*)&v4)[0], ((cl_double*)&v4)[1], ((cl_double*)&v4)[2], ((cl_double*)&v4)[3] );
611 #else
612 printf( "__cl_double4 SIMD vectors not supported on this architecture.\n" );
613 #endif
614
615 #if defined( __CL_DOUBLE8__ )
616 __cl_double8 v8 = b8.v8;
617 printf("__cl_double8: %f %f %f %f %f %f %f %f \n", ((cl_double*)&v8)[0], ((cl_double*)&v8)[1], ((cl_double*)&v8)[2], ((cl_double*)&v8)[3], ((cl_double*)&v8)[4], ((cl_double*)&v8)[5], ((cl_double*)&v8)[6], ((cl_double*)&v8)[7] );
618 #else
619 printf( "__cl_double8 SIMD vectors not supported on this architecture.\n" );
620 #endif
621
622 #if defined( __CL_DOUBLE16__ )
623 __cl_double16 v16 = b16.v16;
624 printf("__cl_double16: %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f \n", ((cl_double*)&v16)[0], ((cl_double*)&v16)[1], ((cl_double*)&v16)[2], ((cl_double*)&v16)[3], ((cl_double*)&v16)[4], ((cl_double*)&v16)[5], ((cl_double*)&v16)[6], ((cl_double*)&v16)[7],
625 ((cl_double*)&v16)[8], ((cl_double*)&v16)[9], ((cl_double*)&v16)[10], ((cl_double*)&v16)[11], ((cl_double*)&v16)[12], ((cl_double*)&v16)[13], ((cl_double*)&v16)[14], ((cl_double*)&v16)[15]);
626 #else
627 printf( "__cl_double16 SIMD vectors not supported on this architecture.\n" );
628 #endif
629
630 printf( "\n" );
631 return 0;
632 }
633
main(void)634 int main(void)
635 {
636 printf( "\nChecking operations on cl_types.\nNumbers, where presented, should walk upward from 0, with step of 1:\n" );
637
638 test_char();
639 test_uchar();
640 test_short();
641 test_ushort();
642 test_long();
643 test_ulong();
644 test_float();
645 test_double();
646
647 return 0;
648 }
649