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