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
18 #include <stdio.h>
19 #include <string.h>
20 #include "procs.h"
21 #include "harness/testHarness.h"
22
23 #if !defined(_WIN32)
24 #include <unistd.h>
25 #endif
26
27 test_definition test_list[] = {
28 ADD_TEST( integer_clz ),
29 ADD_TEST_VERSION( integer_ctz, Version(2, 0)),
30 ADD_TEST( integer_hadd ),
31 ADD_TEST( integer_rhadd ),
32 ADD_TEST( integer_mul_hi ),
33 ADD_TEST( integer_rotate ),
34 ADD_TEST( integer_clamp ),
35 ADD_TEST( integer_mad_sat ),
36 ADD_TEST( integer_mad_hi ),
37 ADD_TEST( integer_min ),
38 ADD_TEST( integer_max ),
39 ADD_TEST( integer_upsample ),
40
41 ADD_TEST( integer_abs ),
42 ADD_TEST( integer_abs_diff ),
43 ADD_TEST( integer_add_sat ),
44 ADD_TEST( integer_sub_sat ),
45
46 ADD_TEST( integer_addAssign ),
47 ADD_TEST( integer_subtractAssign ),
48 ADD_TEST( integer_multiplyAssign ),
49 ADD_TEST( integer_divideAssign ),
50 ADD_TEST( integer_moduloAssign ),
51 ADD_TEST( integer_andAssign ),
52 ADD_TEST( integer_orAssign ),
53 ADD_TEST( integer_exclusiveOrAssign ),
54
55 ADD_TEST( unary_ops_increment ),
56 ADD_TEST( unary_ops_decrement ),
57 ADD_TEST( unary_ops_full ),
58
59 ADD_TEST( integer_mul24 ),
60 ADD_TEST( integer_mad24 ),
61
62 ADD_TEST( long_math ),
63 ADD_TEST( long_logic ),
64 ADD_TEST( long_shift ),
65 ADD_TEST( long_compare ),
66
67 ADD_TEST( ulong_math ),
68 ADD_TEST( ulong_logic ),
69 ADD_TEST( ulong_shift ),
70 ADD_TEST( ulong_compare ),
71
72 ADD_TEST( int_math ),
73 ADD_TEST( int_logic ),
74 ADD_TEST( int_shift ),
75 ADD_TEST( int_compare ),
76
77 ADD_TEST( uint_math ),
78 ADD_TEST( uint_logic ),
79 ADD_TEST( uint_shift ),
80 ADD_TEST( uint_compare ),
81
82 ADD_TEST( short_math ),
83 ADD_TEST( short_logic ),
84 ADD_TEST( short_shift ),
85 ADD_TEST( short_compare ),
86
87 ADD_TEST( ushort_math ),
88 ADD_TEST( ushort_logic ),
89 ADD_TEST( ushort_shift ),
90 ADD_TEST( ushort_compare ),
91
92 ADD_TEST( char_math ),
93 ADD_TEST( char_logic ),
94 ADD_TEST( char_shift ),
95 ADD_TEST( char_compare ),
96
97 ADD_TEST( uchar_math ),
98 ADD_TEST( uchar_logic ),
99 ADD_TEST( uchar_shift ),
100 ADD_TEST( uchar_compare ),
101
102 ADD_TEST( popcount ),
103
104 // Quick
105 ADD_TEST( quick_long_math ),
106 ADD_TEST( quick_long_logic ),
107 ADD_TEST( quick_long_shift ),
108 ADD_TEST( quick_long_compare ),
109
110 ADD_TEST( quick_ulong_math ),
111 ADD_TEST( quick_ulong_logic ),
112 ADD_TEST( quick_ulong_shift ),
113 ADD_TEST( quick_ulong_compare ),
114
115 ADD_TEST( quick_int_math ),
116 ADD_TEST( quick_int_logic ),
117 ADD_TEST( quick_int_shift ),
118 ADD_TEST( quick_int_compare ),
119
120 ADD_TEST( quick_uint_math ),
121 ADD_TEST( quick_uint_logic ),
122 ADD_TEST( quick_uint_shift ),
123 ADD_TEST( quick_uint_compare ),
124
125 ADD_TEST( quick_short_math ),
126 ADD_TEST( quick_short_logic ),
127 ADD_TEST( quick_short_shift ),
128 ADD_TEST( quick_short_compare ),
129
130 ADD_TEST( quick_ushort_math ),
131 ADD_TEST( quick_ushort_logic ),
132 ADD_TEST( quick_ushort_shift ),
133 ADD_TEST( quick_ushort_compare ),
134
135 ADD_TEST( quick_char_math ),
136 ADD_TEST( quick_char_logic ),
137 ADD_TEST( quick_char_shift ),
138 ADD_TEST( quick_char_compare ),
139
140 ADD_TEST( quick_uchar_math ),
141 ADD_TEST( quick_uchar_logic ),
142 ADD_TEST( quick_uchar_shift ),
143 ADD_TEST( quick_uchar_compare ),
144
145 ADD_TEST( vector_scalar ),
146 };
147
148 const int test_num = ARRAY_SIZE( test_list );
149
fill_test_values(cl_long * outBufferA,cl_long * outBufferB,size_t numElements,MTdata d)150 void fill_test_values( cl_long *outBufferA, cl_long *outBufferB, size_t numElements, MTdata d )
151 {
152 static const cl_long sUniqueValues[] = { 0x3333333333333333LL, 0x5555555555555555LL, 0x9999999999999999LL, 0xaaaaaaaaaaaaaaaaLL, 0xccccccccccccccccLL,
153 0x3030303030303030LL, 0x5050505050505050LL, 0x9090909090909090LL, 0xa0a0a0a0a0a0a0a0LL, 0xc0c0c0c0c0c0c0c0LL, 0xf0f0f0f0f0f0f0f0LL,
154 0x0303030303030303LL, 0x0505050505050505LL, 0x0909090909090909LL, 0x0a0a0a0a0a0a0a0aLL, 0x0c0c0c0c0c0c0c0cLL, 0x0f0f0f0f0f0f0f0fLL,
155 0x3300330033003300LL, 0x5500550055005500LL, 0x9900990099009900LL, 0xaa00aa00aa00aa00LL, 0xcc00cc00cc00cc00LL, 0xff00ff00ff00ff00LL,
156 0x0033003300330033LL, 0x0055005500550055LL, 0x0099009900990099LL, 0x00aa00aa00aa00aaLL, 0x00cc00cc00cc00ccLL, 0x00ff00ff00ff00ffLL,
157 0x3333333300000000LL, 0x5555555500000000LL, 0x9999999900000000LL, 0xaaaaaaaa00000000LL, 0xcccccccc00000000LL, 0xffffffff00000000LL,
158 0x0000000033333333LL, 0x0000000055555555LL, 0x0000000099999999LL, 0x00000000aaaaaaaaLL, 0x00000000ccccccccLL, 0x00000000ffffffffLL,
159 0x3333000000003333LL, 0x5555000000005555LL, 0x9999000000009999LL, 0xaaaa00000000aaaaLL, 0xcccc00000000ccccLL, 0xffff00000000ffffLL};
160 static cl_long sSpecialValues[ 128 + 128 + 128 + ( sizeof( sUniqueValues ) / sizeof( sUniqueValues[ 0 ] ) ) ] = { 0 };
161
162 if( sSpecialValues[ 0 ] == 0 )
163 {
164 // Init the power-of-two special values
165 for( size_t i = 0; i < 64; i++ )
166 {
167 sSpecialValues[ i ] = 1LL << i;
168 sSpecialValues[ i + 64 ] = -1LL << i;
169 sSpecialValues[ i + 128 ] = sSpecialValues[ i ] - 1;
170 sSpecialValues[ i + 128 + 64 ] = sSpecialValues[ i ] - 1;
171 sSpecialValues[ i + 256 ] = sSpecialValues[ i ] + 1;
172 sSpecialValues[ i + 256 + 64 ] = sSpecialValues[ i ] + 1;
173 }
174 memcpy( &sSpecialValues[ 128 + 128 + 128 ], sUniqueValues, sizeof( sUniqueValues ) );
175 }
176
177 size_t i, aIdx = 0, bIdx = 0;
178 size_t numSpecials = sizeof( sSpecialValues ) / sizeof( sSpecialValues[ 0 ] );
179
180 for( i = 0; i < numElements; i++ )
181 {
182 outBufferA[ i ] = sSpecialValues[ aIdx ];
183 outBufferB[ i ] = sSpecialValues[ bIdx ];
184 bIdx++;
185 if( bIdx == numSpecials )
186 {
187 bIdx = 0;
188 aIdx++;
189 if( aIdx == numSpecials )
190 break;
191 }
192 }
193 if( i < numElements )
194 {
195 // Fill remainder with random values
196 for( ; i < numElements; i++ )
197 {
198 int a = (int)genrand_int32(d);
199 int b = (int)genrand_int32(d);
200 outBufferA[ i ] = ((cl_long)a <<33 | (cl_long)b) ^ ((cl_long)b << 16);
201
202 a = (int)genrand_int32(d);
203 b = (int)genrand_int32(d);
204 outBufferB[ i ] = ((cl_long)a <<33 | (cl_long)b) ^ ((cl_long)b << 16);
205 }
206 }
207 else if( aIdx < numSpecials )
208 {
209 log_info( "WARNING: Not enough space to fill all special values for long test! (need %d additional elements)\n", (int)( ( numSpecials - aIdx ) * numSpecials ) );
210 }
211 }
212
main(int argc,const char * argv[])213 int main(int argc, const char *argv[])
214 {
215 return runTestHarness(argc, argv, test_num, test_list, false, 0);
216 }
217
218