1 //
2 // Copyright (c) 2017 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 #include "harness/compat.h"
17 #include "harness/errorHelpers.h"
18
19 #include <stdio.h>
20 #include "test_select.h"
21
22
23 //-----------------------------------------
24 // Definitions and initializations
25 //-----------------------------------------
26
27
28 const char *type_name[kTypeCount] = {
29 "uchar", "char",
30 "ushort", "short",
31 "uint", "int",
32 "float", "ulong", "long", "double" };
33
34 const size_t type_size[kTypeCount] = {
35 sizeof(cl_uchar), sizeof(cl_char),
36 sizeof(cl_ushort), sizeof(cl_short),
37 sizeof(cl_uint), sizeof(cl_int),
38 sizeof(cl_float), sizeof(cl_ulong), sizeof(cl_long), sizeof( cl_double ) };
39
40 const Type ctype[kTypeCount][2] = {
41 { kuchar, kchar }, // uchar
42 { kuchar, kchar }, // char
43 { kushort, kshort}, // ushort
44 { kushort, kshort}, // short
45 { kuint, kint }, // uint
46 { kuint, kint }, // int
47 { kuint, kint }, // float
48 { kulong, klong }, // ulong
49 { kulong, klong }, // long
50 { kulong, klong } // double
51 };
52
53
54 //-----------------------------------------
55 // Reference functions
56 //-----------------------------------------
57
refselect_1i8(void * dest,void * src1,void * src2,void * cmp,size_t count)58 void refselect_1i8(void *dest, void *src1, void *src2, void *cmp, size_t count) {
59 size_t i;
60 cl_char *d, *x, *y, *m;
61 d = (cl_char*) dest;
62 x = (cl_char*) src1;
63 y = (cl_char*) src2;
64 m = (cl_char*) cmp;
65 for (i=0; i < count; ++i) {
66 d[i] = m[i] ? y[i] : x[i];
67 }
68 }
69
refselect_1u8(void * dest,void * src1,void * src2,void * cmp,size_t count)70 void refselect_1u8(void *dest, void *src1, void *src2, void *cmp, size_t count) {
71 size_t i;
72 cl_uchar *d, *x, *y;
73 cl_char *m;
74 d = (cl_uchar*) dest;
75 x = (cl_uchar*) src1;
76 y = (cl_uchar*) src2;
77 m = (cl_char*) cmp;
78 for (i=0; i < count; ++i) {
79 d[i] = m[i] ? y[i] : x[i];
80 }
81 }
82
refselect_1i16(void * dest,void * src1,void * src2,void * cmp,size_t count)83 void refselect_1i16(void *dest, void *src1, void *src2, void *cmp, size_t count) {
84 size_t i;
85 cl_short *d, *x, *y, *m;
86 d = (cl_short*) dest;
87 x = (cl_short*) src1;
88 y = (cl_short*) src2;
89 m = (cl_short*) cmp;
90
91 for (i=0; i < count; ++i)
92 d[i] = m[i] ? y[i] : x[i];
93 }
94
refselect_1u16(void * dest,void * src1,void * src2,void * cmp,size_t count)95 void refselect_1u16(void *dest, void *src1, void *src2, void *cmp, size_t count) {
96 size_t i;
97 cl_ushort *d, *x, *y;
98 cl_short *m;
99 d = (cl_ushort*) dest;
100 x = (cl_ushort*) src1;
101 y = (cl_ushort*) src2;
102 m = (cl_short*) cmp;
103 for (i=0; i < count; ++i)
104 d[i] = m[i] ? y[i] : x[i];
105 }
106
refselect_1i32(void * dest,void * src1,void * src2,void * cmp,size_t count)107 void refselect_1i32(void *dest, void *src1, void *src2, void *cmp, size_t count) {
108 size_t i;
109 cl_int *d, *x, *y, *m;
110 d = (cl_int*)dest;
111 x = (cl_int*)src1;
112 y = (cl_int*)src2;
113 m = (cl_int*)cmp;
114 for (i=0; i < count; ++i)
115 d[i] = m[i] ? y[i] : x[i];
116 }
117
refselect_1u32(void * dest,void * src1,void * src2,void * cmp,size_t count)118 void refselect_1u32(void *dest, void *src1, void *src2, void *cmp, size_t count){
119 size_t i;
120 cl_uint *d, *x, *y;
121 cl_int *m;
122 d = (cl_uint*)dest;
123 x = (cl_uint*)src1;
124 y = (cl_uint*)src2;
125 m = (cl_int*)cmp;
126 for (i=0; i < count; ++i)
127 d[i] = m[i] ? y[i] : x[i];
128 }
129
refselect_1i64(void * dest,void * src1,void * src2,void * cmp,size_t count)130 void refselect_1i64(void *dest, void *src1, void *src2, void *cmp, size_t count) {
131 size_t i;
132 cl_long *d, *x, *y, *m;
133 d = (cl_long*) dest;
134 x = (cl_long*) src1;
135 y = (cl_long*) src2;
136 m = (cl_long*) cmp;
137 for (i=0; i < count; ++i)
138 d[i] = m[i] ? y[i] : x[i];
139 }
140
refselect_1u64(void * dest,void * src1,void * src2,void * cmp,size_t count)141 void refselect_1u64(void *dest, void *src1, void *src2, void *cmp, size_t count) {
142 size_t i;
143 cl_ulong *d, *x, *y;
144 cl_long *m;
145 d = (cl_ulong*) dest;
146 x = (cl_ulong*) src1;
147 y = (cl_ulong*) src2;
148 m = (cl_long*) cmp;
149 for (i=0; i < count; ++i)
150 d[i] = m[i] ? y[i] : x[i];
151 }
152
refselect_1i8u(void * dest,void * src1,void * src2,void * cmp,size_t count)153 void refselect_1i8u(void *dest, void *src1, void *src2, void *cmp, size_t count) {
154 size_t i;
155 cl_char *d, *x, *y;
156 cl_uchar *m;
157 d = (cl_char*) dest;
158 x = (cl_char*) src1;
159 y = (cl_char*) src2;
160 m = (cl_uchar*) cmp;
161 for (i=0; i < count; ++i)
162 d[i] = m[i] ? y[i] : x[i];
163 }
164
refselect_1u8u(void * dest,void * src1,void * src2,void * cmp,size_t count)165 void refselect_1u8u(void *dest, void *src1, void *src2, void *cmp, size_t count) {
166 size_t i;
167 cl_uchar *d, *x, *y, *m;
168 d = (cl_uchar*) dest;
169 x = (cl_uchar*) src1;
170 y = (cl_uchar*) src2;
171 m = (cl_uchar*) cmp;
172 for (i=0; i < count; ++i)
173 d[i] = m[i] ? y[i] : x[i];
174 }
175
refselect_1i16u(void * dest,void * src1,void * src2,void * cmp,size_t count)176 void refselect_1i16u(void *dest, void *src1, void *src2, void *cmp, size_t count) {
177 size_t i;
178 cl_short *d, *x, *y;
179 cl_ushort *m;
180 d = (cl_short*) dest;
181 x = (cl_short*) src1;
182 y = (cl_short*) src2;
183 m = (cl_ushort*) cmp;
184 for (i=0; i < count; ++i)
185 d[i] = m[i] ? y[i] : x[i];
186 }
187
refselect_1u16u(void * dest,void * src1,void * src2,void * cmp,size_t count)188 void refselect_1u16u(void *dest, void *src1, void *src2, void *cmp, size_t count) {
189 size_t i;
190 cl_ushort *d, *x, *y, *m;
191 d = (cl_ushort*) dest;
192 x = (cl_ushort*) src1;
193 y = (cl_ushort*) src2;
194 m = (cl_ushort*) cmp;
195 for (i=0; i < count; ++i)
196 d[i] = m[i] ? y[i] : x[i];
197 }
198
refselect_1i32u(void * dest,void * src1,void * src2,void * cmp,size_t count)199 void refselect_1i32u(void *dest, void *src1, void *src2, void *cmp, size_t count) {
200 size_t i;
201 cl_int *d, *x, *y;
202 cl_uint *m;
203 d = (cl_int*) dest;
204 x = (cl_int*) src1;
205 y = (cl_int*) src2;
206 m = (cl_uint*) cmp;
207 for (i=0; i < count; ++i)
208 d[i] = m[i] ? y[i] : x[i];
209 }
210
refselect_1u32u(void * dest,void * src1,void * src2,void * cmp,size_t count)211 void refselect_1u32u(void *dest, void *src1, void *src2, void *cmp, size_t count) {
212 size_t i;
213 cl_uint *d, *x, *y, *m;
214 d = (cl_uint*) dest;
215 x = (cl_uint*) src1;
216 y = (cl_uint*) src2;
217 m = (cl_uint*) cmp;
218 for (i=0; i < count; ++i)
219 d[i] = m[i] ? y[i] : x[i];
220 }
221
refselect_1i64u(void * dest,void * src1,void * src2,void * cmp,size_t count)222 void refselect_1i64u(void *dest, void *src1, void *src2, void *cmp, size_t count) {
223 size_t i;
224 cl_long *d, *x, *y;
225 cl_ulong *m;
226 d = (cl_long*) dest;
227 x = (cl_long*) src1;
228 y = (cl_long*) src2;
229 m = (cl_ulong*) cmp;
230 for (i=0; i < count; ++i)
231 d[i] = m[i] ? y[i] : x[i];
232 }
233
refselect_1u64u(void * dest,void * src1,void * src2,void * cmp,size_t count)234 void refselect_1u64u(void *dest, void *src1, void *src2, void *cmp, size_t count) {
235 size_t i;
236 cl_ulong *d, *x, *y, *m;
237 d = (cl_ulong*) dest;
238 x = (cl_ulong*) src1;
239 y = (cl_ulong*) src2;
240 m = (cl_ulong*) cmp;
241 for (i=0; i < count; ++i)
242 d[i] = m[i] ? y[i] : x[i];
243 }
244
refselect_ffi(void * dest,void * src1,void * src2,void * cmp,size_t count)245 void refselect_ffi(void *dest, void *src1, void *src2, void *cmp, size_t count) {
246 size_t i;
247 cl_int *d, *x, *y;
248 cl_int *m;
249 d = (cl_int*) dest;
250 x = (cl_int*) src1;
251 y = (cl_int*) src2;
252 m = (cl_int*) cmp;
253 for (i=0; i < count; ++i)
254 d[i] = m[i] ? y[i] : x[i];
255 }
256
refselect_ffu(void * dest,void * src1,void * src2,void * cmp,size_t count)257 void refselect_ffu(void *dest, void *src1, void *src2, void *cmp, size_t count) {
258 size_t i;
259 cl_uint *d, *x, *y;
260 cl_uint *m;
261 d = (cl_uint*) dest;
262 x = (cl_uint*) src1;
263 y = (cl_uint*) src2;
264 m = (cl_uint*) cmp;
265 for (i=0; i < count; ++i)
266 d[i] = m[i] ? y[i] : x[i];
267 }
268
refselect_ddi(void * dest,void * src1,void * src2,void * cmp,size_t count)269 void refselect_ddi(void *dest, void *src1, void *src2, void *cmp, size_t count) {
270 size_t i;
271 cl_long *d, *x, *y;
272 cl_long *m;
273 d = (cl_long*) dest;
274 x = (cl_long*) src1;
275 y = (cl_long*) src2;
276 m = (cl_long*) cmp;
277 for (i=0; i < count; ++i)
278 d[i] = m[i] ? y[i] : x[i];
279 }
280
refselect_ddu(void * dest,void * src1,void * src2,void * cmp,size_t count)281 void refselect_ddu(void *dest, void *src1, void *src2, void *cmp, size_t count) {
282 size_t i;
283 cl_long *d, *x, *y;
284 cl_ulong *m;
285 d = (cl_long*) dest;
286 x = (cl_long*) src1;
287 y = (cl_long*) src2;
288 m = (cl_ulong*) cmp;
289 for (i=0; i < count; ++i)
290 d[i] = m[i] ? y[i] : x[i];
291 }
292
vrefselect_1i8(void * dest,void * src1,void * src2,void * cmp,size_t count)293 void vrefselect_1i8(void *dest, void *src1, void *src2, void *cmp, size_t count) {
294 size_t i;
295 cl_char *d, *x, *y, *m;
296 d = (cl_char*) dest;
297 x = (cl_char*) src1;
298 y = (cl_char*) src2;
299 m = (cl_char*) cmp;
300 for (i=0; i < count; ++i)
301 d[i] = (m[i] & 0x80) ? y[i] : x[i];
302 }
303
vrefselect_1u8(void * dest,void * src1,void * src2,void * cmp,size_t count)304 void vrefselect_1u8(void *dest, void *src1, void *src2, void *cmp, size_t count) {
305 size_t i;
306 cl_uchar *d, *x, *y;
307 cl_char *m;
308 d = (cl_uchar*) dest;
309 x = (cl_uchar*) src1;
310 y = (cl_uchar*) src2;
311 m = (cl_char*) cmp;
312 for (i=0; i < count; ++i)
313 d[i] = (m[i] & 0x80) ? y[i] : x[i];
314 }
315
vrefselect_1i16(void * dest,void * src1,void * src2,void * cmp,size_t count)316 void vrefselect_1i16(void *dest, void *src1, void *src2, void *cmp, size_t count) {
317 size_t i;
318 cl_short *d, *x, *y, *m;
319 d = (cl_short*) dest;
320 x = (cl_short*) src1;
321 y = (cl_short*) src2;
322 m = (cl_short*) cmp;
323
324 for (i=0; i < count; ++i)
325 d[i] = (m[i] & 0x8000) ? y[i] : x[i];
326 }
327
vrefselect_1u16(void * dest,void * src1,void * src2,void * cmp,size_t count)328 void vrefselect_1u16(void *dest, void *src1, void *src2, void *cmp, size_t count) {
329 size_t i;
330 cl_ushort *d, *x, *y;
331 cl_short *m;
332 d = (cl_ushort*) dest;
333 x = (cl_ushort*)src1;
334 y = (cl_ushort*)src2;
335 m = (cl_short*)cmp;
336 for (i=0; i < count; ++i)
337 d[i] = (m[i] & 0x8000) ? y[i] : x[i];
338 }
339
vrefselect_1i32(void * dest,void * src1,void * src2,void * cmp,size_t count)340 void vrefselect_1i32(void *dest, void *src1, void *src2, void *cmp, size_t count) {
341 size_t i;
342 cl_int *d, *x, *y, *m;
343 d = (cl_int*) dest;
344 x = (cl_int*) src1;
345 y = (cl_int*) src2;
346 m = (cl_int*) cmp;
347 for (i=0; i < count; ++i)
348 d[i] = (m[i] & 0x80000000) ? y[i] : x[i];
349 }
350
vrefselect_1u32(void * dest,void * src1,void * src2,void * cmp,size_t count)351 void vrefselect_1u32(void *dest, void *src1, void *src2, void *cmp, size_t count){
352 size_t i;
353 cl_uint *d, *x, *y;
354 cl_int *m;
355 d = (cl_uint*) dest;
356 x = (cl_uint*) src1;
357 y = (cl_uint*) src2;
358 m = (cl_int*) cmp;
359
360 for (i=0; i < count; ++i)
361 d[i] = (m[i] & 0x80000000) ? y[i] : x[i];
362 }
363
vrefselect_1i64(void * dest,void * src1,void * src2,void * cmp,size_t count)364 void vrefselect_1i64(void *dest, void *src1, void *src2, void *cmp, size_t count) {
365 size_t i;
366 cl_long *d, *x, *y, *m;
367 d = (cl_long*) dest;
368 x = (cl_long*) src1;
369 y = (cl_long*) src2;
370 m = (cl_long*) cmp;
371 for (i=0; i < count; ++i)
372 d[i] = (m[i] & 0x8000000000000000LL) ? y[i] : x[i];
373 }
374
vrefselect_1u64(void * dest,void * src1,void * src2,void * cmp,size_t count)375 void vrefselect_1u64(void *dest, void *src1, void *src2, void *cmp, size_t count) {
376 size_t i;
377 cl_ulong *d, *x, *y;
378 cl_long *m;
379 d = (cl_ulong*) dest;
380 x = (cl_ulong*) src1;
381 y = (cl_ulong*) src2;
382 m = (cl_long*) cmp;
383 for (i=0; i < count; ++i)
384 d[i] = (m[i] & 0x8000000000000000LL) ? y[i] : x[i];
385 }
386
vrefselect_1i8u(void * dest,void * src1,void * src2,void * cmp,size_t count)387 void vrefselect_1i8u(void *dest, void *src1, void *src2, void *cmp, size_t count) {
388 size_t i;
389 cl_char *d, *x, *y;
390 cl_uchar *m;
391 d = (cl_char*) dest;
392 x = (cl_char*) src1;
393 y = (cl_char*) src2;
394 m = (cl_uchar*) cmp;
395 for (i=0; i < count; ++i)
396 d[i] = (m[i] & 0x80U) ? y[i] : x[i];
397 }
398
vrefselect_1u8u(void * dest,void * src1,void * src2,void * cmp,size_t count)399 void vrefselect_1u8u(void *dest, void *src1, void *src2, void *cmp, size_t count) {
400 size_t i;
401 cl_uchar *d, *x, *y, *m;
402 d = (cl_uchar*) dest;
403 x = (cl_uchar*) src1;
404 y = (cl_uchar*) src2;
405 m = (cl_uchar*) cmp;
406 for (i=0; i < count; ++i)
407 d[i] = (m[i] & 0x80U) ? y[i] : x[i];
408 }
409
vrefselect_1i16u(void * dest,void * src1,void * src2,void * cmp,size_t count)410 void vrefselect_1i16u(void *dest, void *src1, void *src2, void *cmp, size_t count) {
411 size_t i;
412 cl_short *d, *x, *y;
413 cl_ushort *m;
414 d = (cl_short*) dest;
415 x = (cl_short*) src1;
416 y = (cl_short*) src2;
417 m = (cl_ushort*) cmp;
418 for (i=0; i < count; ++i)
419 d[i] = (m[i] & 0x8000U) ? y[i] : x[i];
420 }
421
vrefselect_1u16u(void * dest,void * src1,void * src2,void * cmp,size_t count)422 void vrefselect_1u16u(void *dest, void *src1, void *src2, void *cmp, size_t count) {
423 size_t i;
424 cl_ushort *d, *x, *y, *m;
425 d = (cl_ushort*) dest;
426 x = (cl_ushort*) src1;
427 y = (cl_ushort*) src2;
428 m = (cl_ushort*) cmp;
429 for (i=0; i < count; ++i)
430 d[i] = (m[i] & 0x8000U) ? y[i] : x[i];
431 }
432
vrefselect_1i32u(void * dest,void * src1,void * src2,void * cmp,size_t count)433 void vrefselect_1i32u(void *dest, void *src1, void *src2, void *cmp, size_t count) {
434 size_t i;
435 cl_int *d, *x, *y;
436 cl_uint *m;
437 d = (cl_int*) dest;
438 x = (cl_int*) src1;
439 y = (cl_int*) src2;
440 m = (cl_uint*) cmp;
441 for (i=0; i < count; ++i)
442 d[i] = (m[i] & 0x80000000U) ? y[i] : x[i];
443 }
444
vrefselect_1u32u(void * dest,void * src1,void * src2,void * cmp,size_t count)445 void vrefselect_1u32u(void *dest, void *src1, void *src2, void *cmp, size_t count) {
446 size_t i;
447 cl_uint *d, *x, *y, *m;
448 d = (cl_uint*) dest;
449 x = (cl_uint*) src1;
450 y = (cl_uint*) src2;
451 m = (cl_uint*) cmp;
452 for (i=0; i < count; ++i)
453 d[i] = (m[i] & 0x80000000U) ? y[i] : x[i];
454 }
455
vrefselect_1i64u(void * dest,void * src1,void * src2,void * cmp,size_t count)456 void vrefselect_1i64u(void *dest, void *src1, void *src2, void *cmp, size_t count) {
457 size_t i;
458 cl_long *d, *x, *y;
459 cl_ulong *m;
460 d = (cl_long*) dest;
461 x = (cl_long*) src1;
462 y = (cl_long*) src2;
463 m = (cl_ulong*) cmp;
464 for (i=0; i < count; ++i)
465 d[i] = (m[i] & 0x8000000000000000ULL) ? y[i] : x[i];
466 }
467
vrefselect_1u64u(void * dest,void * src1,void * src2,void * cmp,size_t count)468 void vrefselect_1u64u(void *dest, void *src1, void *src2, void *cmp, size_t count) {
469 size_t i;
470 cl_ulong *d, *x, *y, *m;
471 d = (cl_ulong*) dest;
472 x = (cl_ulong*) src1;
473 y = (cl_ulong*) src2;
474 m = (cl_ulong*) cmp;
475 for (i=0; i < count; ++i)
476 d[i] = (m[i] & 0x8000000000000000ULL) ? y[i] : x[i];
477 }
478
vrefselect_ffi(void * dest,void * src1,void * src2,void * cmp,size_t count)479 void vrefselect_ffi(void *dest, void *src1, void *src2, void *cmp, size_t count) {
480 size_t i;
481 cl_uint *d, *x, *y;
482 cl_int *m;
483 d = (cl_uint*) dest;
484 x = (cl_uint*) src1;
485 y = (cl_uint*) src2;
486 m = (cl_int*) cmp;
487 for (i=0; i < count; ++i)
488 d[i] = (m[i] & 0x80000000) ? y[i] : x[i];
489 }
490
vrefselect_ffu(void * dest,void * src1,void * src2,void * cmp,size_t count)491 void vrefselect_ffu(void *dest, void *src1, void *src2, void *cmp, size_t count) {
492 size_t i;
493 cl_uint *d, *x, *y;
494 cl_uint *m;
495 d = (cl_uint*) dest;
496 x = (cl_uint*) src1;
497 y = (cl_uint*) src2;
498 m = (cl_uint*) cmp;
499 for (i=0; i < count; ++i)
500 d[i] = (m[i] & 0x80000000U) ? y[i] : x[i];
501 }
502
vrefselect_ddi(void * dest,void * src1,void * src2,void * cmp,size_t count)503 void vrefselect_ddi(void *dest, void *src1, void *src2, void *cmp, size_t count) {
504 size_t i;
505 cl_ulong *d, *x, *y;
506 cl_long *m;
507 d = (cl_ulong*) dest;
508 x = (cl_ulong*) src1;
509 y = (cl_ulong*) src2;
510 m = (cl_long*) cmp;
511 for (i=0; i < count; ++i)
512 d[i] = (m[i] & 0x8000000000000000LL) ? y[i] : x[i];
513 }
514
vrefselect_ddu(void * dest,void * src1,void * src2,void * cmp,size_t count)515 void vrefselect_ddu(void *dest, void *src1, void *src2, void *cmp, size_t count) {
516 size_t i;
517 cl_ulong *d, *x, *y;
518 cl_ulong *m;
519 d = (cl_ulong*) dest;
520 x = (cl_ulong*) src1;
521 y = (cl_ulong*) src2;
522 m = (cl_ulong*) cmp;
523 for (i=0; i < count; ++i)
524 d[i] = (m[i] & 0x8000000000000000ULL) ? y[i] : x[i];
525 }
526
527 // Define refSelects
528 Select refSelects[kTypeCount][2] = {
529 { refselect_1u8u, refselect_1u8 }, // cl_uchar
530 { refselect_1i8u, refselect_1i8 }, // char
531 { refselect_1u16u, refselect_1u16 }, // ushort
532 { refselect_1i16u, refselect_1i16 }, // short
533 { refselect_1u32u, refselect_1u32 }, // uint
534 { refselect_1i32u, refselect_1i32 }, // int
535 { refselect_ffu, refselect_ffi }, // float
536 { refselect_1u64u, refselect_1u64 }, // ulong
537 { refselect_1i64u, refselect_1i64 }, // long
538 { refselect_ddu, refselect_ddi } // double
539 };
540
541 // Define vrefSelects (vector refSelects)
542 Select vrefSelects[kTypeCount][2] = {
543 { vrefselect_1u8u, vrefselect_1u8 }, // cl_uchar
544 { vrefselect_1i8u, vrefselect_1i8 }, // char
545 { vrefselect_1u16u, vrefselect_1u16 }, // ushort
546 { vrefselect_1i16u, vrefselect_1i16 }, // short
547 { vrefselect_1u32u, vrefselect_1u32 }, // uint
548 { vrefselect_1i32u, vrefselect_1i32 }, // int
549 { vrefselect_ffu, vrefselect_ffi }, // float
550 { vrefselect_1u64u, vrefselect_1u64 }, // ulong
551 { vrefselect_1i64u, vrefselect_1i64 }, // long
552 { vrefselect_ddu, vrefselect_ddi } // double
553 };
554
555
556 //-----------------------------------------
557 // Check functions
558 //-----------------------------------------
check_uchar(void * test,void * correct,size_t count,size_t vector_size)559 size_t check_uchar(void *test, void *correct, size_t count, size_t vector_size) {
560 const cl_uchar *t = (const cl_uchar *) test;
561 const cl_uchar *c = (const cl_uchar *) correct;
562 size_t i;
563
564 if (memcmp(t, c, count * sizeof(c[0])) != 0)
565 {
566 for (i = 0; i < count; i++)
567 if (t[i] != c[i])
568 {
569 log_error("\n(check_uchar) Error for vector size %ld found at "
570 "0x%8.8lx (of 0x%8.8lx): "
571 "*0x%2.2x vs 0x%2.2x\n",
572 vector_size, i, count, c[i], t[i]);
573 return i + 1;
574 }
575 }
576 return 0;
577 }
578
check_char(void * test,void * correct,size_t count,size_t vector_size)579 size_t check_char(void *test, void *correct, size_t count, size_t vector_size) {
580 const cl_char *t = (const cl_char *) test;
581 const cl_char *c = (const cl_char *) correct;
582 size_t i;
583
584 if (memcmp(t, c, count * sizeof(c[0])) != 0)
585 {
586 for (i = 0; i < count; i++)
587 if (t[i] != c[i])
588 {
589 log_error("\n(check_char) Error for vector size %ld found at "
590 "0x%8.8lx (of 0x%8.8lx): "
591 "*0x%2.2x vs 0x%2.2x\n",
592 vector_size, i, count, c[i], t[i]);
593 return i + 1;
594 }
595 }
596
597 return 0;
598 }
599
check_ushort(void * test,void * correct,size_t count,size_t vector_size)600 size_t check_ushort(void *test, void *correct, size_t count, size_t vector_size) {
601 const cl_ushort *t = (const cl_ushort *) test;
602 const cl_ushort *c = (const cl_ushort *) correct;
603 size_t i;
604
605 if (memcmp(t, c, count * sizeof(c[0])) != 0)
606 {
607 for (i = 0; i < count; i++)
608 if (t[i] != c[i])
609 {
610 log_error("\n(check_ushort) Error for vector size %ld found at "
611 "0x%8.8lx (of 0x%8.8lx): "
612 "*0x%4.4x vs 0x%4.4x\n",
613 vector_size, i, count, c[i], t[i]);
614 return i + 1;
615 }
616 }
617
618 return 0;
619 }
620
check_short(void * test,void * correct,size_t count,size_t vector_size)621 size_t check_short(void *test, void *correct, size_t count, size_t vector_size) {
622 const cl_short *t = (const cl_short *) test;
623 const cl_short *c = (const cl_short *) correct;
624 size_t i;
625
626 if (memcmp(t, c, count * sizeof(c[0])) != 0)
627 {
628 for (i = 0; i < count; i++)
629 if (t[i] != c[i])
630 {
631 log_error("\n(check_short) Error for vector size %ld found at "
632 "0x%8.8lx (of 0x%8.8lx): "
633 "*0x%8.8x vs 0x%8.8x\n",
634 vector_size, i, count, c[i], t[i]);
635 return i + 1;
636 }
637 }
638
639 return 0;
640 }
641
check_uint(void * test,void * correct,size_t count,size_t vector_size)642 size_t check_uint(void *test, void *correct, size_t count, size_t vector_size) {
643 const cl_uint *t = (const cl_uint *) test;
644 const cl_uint *c = (const cl_uint *) correct;
645 size_t i;
646
647 if (memcmp(t, c, count * sizeof(c[0])) != 0)
648 {
649 for (i = 0; i < count; i++)
650 if (t[i] != c[i])
651 {
652 log_error("\n(check_uint) Error for vector size %ld found at "
653 "0x%8.8lx (of 0x%8.8lx): "
654 "*0x%8.8x vs 0x%8.8x\n",
655 vector_size, i, count, c[i], t[i]);
656 return i + 1;
657 }
658 }
659
660 return 0;
661 }
662
check_int(void * test,void * correct,size_t count,size_t vector_size)663 size_t check_int(void *test, void *correct, size_t count, size_t vector_size) {
664 const cl_int *t = (const cl_int *) test;
665 const cl_int *c = (const cl_int *) correct;
666 size_t i;
667
668 if (memcmp(t, c, count * sizeof(c[0])) != 0)
669 {
670 for (i = 0; i < count; i++)
671 if (t[i] != c[i])
672 {
673
674 log_error("\n(check_int) Error for vector size %ld found at "
675 "0x%8.8lx (of 0x%8.8lx): "
676 "*0x%8.8x vs 0x%8.8x\n",
677 vector_size, i, count, c[i], t[i]);
678 return i + 1;
679 }
680 }
681
682 return 0;
683 }
684
check_ulong(void * test,void * correct,size_t count,size_t vector_size)685 size_t check_ulong(void *test, void *correct, size_t count, size_t vector_size) {
686 const cl_ulong *t = (const cl_ulong *) test;
687 const cl_ulong *c = (const cl_ulong *) correct;
688 size_t i;
689
690 if (memcmp(t, c, count * sizeof(c[0])) != 0)
691 {
692 for (i = 0; i < count; i++)
693 if (t[i] != c[i])
694 {
695 log_error("\n(check_ulong) Error for vector size %ld found at "
696 "0x%8.8lx (of 0x%8.8lx): "
697 "*0x%16.16llx vs 0x%16.16llx\n",
698 vector_size, i, count, c[i], t[i]);
699 return i + 1;
700 }
701 }
702
703 return 0;
704 }
705
check_long(void * test,void * correct,size_t count,size_t vector_size)706 size_t check_long(void *test, void *correct, size_t count, size_t vector_size) {
707 const cl_long *t = (const cl_long *) test;
708 const cl_long *c = (const cl_long *) correct;
709 size_t i;
710
711 if (memcmp(t, c, count * sizeof(c[0])) != 0)
712 {
713 for (i = 0; i < count; i++)
714 if (t[i] != c[i])
715 {
716 log_error("\n(check_long) Error for vector size %ld found at "
717 "0x%8.8lx (of 0x%8.8lx): "
718 "*0x%16.16llx vs 0x%16.16llx\n",
719 vector_size, i, count, c[i], t[i]);
720 return i + 1;
721 }
722 }
723
724 return 0;
725 }
726
check_float(void * test,void * correct,size_t count,size_t vector_size)727 size_t check_float( void *test, void *correct, size_t count, size_t vector_size ) {
728 const cl_uint *t = (const cl_uint *) test;
729 const cl_uint *c = (const cl_uint *) correct;
730 size_t i;
731
732 if (memcmp(t, c, count * sizeof(c[0])) != 0)
733 {
734 for (i = 0; i < count; i++) /* Allow nans to be binary different */
735 if ((t[i] != c[i])
736 && !(isnan(((float *)correct)[i]) && isnan(((float *)test)[i])))
737 {
738 log_error("\n(check_float) Error for vector size %ld found at "
739 "0x%8.8lx (of 0x%8.8lx): "
740 "*0x%8.8x vs 0x%8.8x\n",
741 vector_size, i, count, c[i], t[i]);
742 return i + 1;
743 }
744 }
745
746 return 0;
747 }
748
check_double(void * test,void * correct,size_t count,size_t vector_size)749 size_t check_double( void *test, void *correct, size_t count, size_t vector_size ) {
750 const cl_ulong *t = (const cl_ulong *) test;
751 const cl_ulong *c = (const cl_ulong *) correct;
752 size_t i;
753
754 if (memcmp(t, c, count * sizeof(c[0])) != 0)
755 {
756 for (i = 0; i < count; i++) /* Allow nans to be binary different */
757 if ((t[i] != c[i])
758 && !(isnan(((double *)correct)[i])
759 && isnan(((double *)test)[i])))
760 {
761 log_error("\n(check_double) Error for vector size %ld found at "
762 "0x%8.8lx (of 0x%8.8lx): "
763 "*0x%16.16llx vs 0x%16.16llx\n",
764 vector_size, i, count, c[i], t[i]);
765 return i + 1;
766 }
767 }
768
769 return 0;
770 }
771
772 CheckResults checkResults[kTypeCount] = {
773 check_uchar, check_char, check_ushort, check_short, check_uint,
774 check_int, check_float, check_ulong, check_long, check_double };
775