1 /*
2  * Copyright (C) 2016 The Android Open Source Project
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 // Don't edit this file!  It is auto-generated by frameworks/rs/api/generate.sh.
18 
19 package android.renderscript.cts;
20 
21 import android.renderscript.Allocation;
22 import android.renderscript.RSRuntimeException;
23 import android.renderscript.Element;
24 import android.renderscript.cts.Target;
25 
26 import java.util.Arrays;
27 
28 public class TestClz extends RSBaseCompute {
29 
30     private ScriptC_TestClz script;
31     private ScriptC_TestClzRelaxed scriptRelaxed;
32 
33     @Override
setUp()34     protected void setUp() throws Exception {
35         super.setUp();
36         script = new ScriptC_TestClz(mRS);
37         scriptRelaxed = new ScriptC_TestClzRelaxed(mRS);
38     }
39 
40     @Override
tearDown()41     protected void tearDown() throws Exception {
42         script.destroy();
43         scriptRelaxed.destroy();
44         super.tearDown();
45     }
46 
47     public class ArgumentsCharChar {
48         public byte inValue;
49         public byte out;
50     }
51 
checkClzCharChar()52     private void checkClzCharChar() {
53         Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 1, 0xf6f3a15e2f7765afl, false);
54         try {
55             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 1), INPUTSIZE);
56             script.forEach_testClzCharChar(inValue, out);
57             verifyResultsClzCharChar(inValue, out, false);
58             out.destroy();
59         } catch (Exception e) {
60             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzCharChar: " + e.toString());
61         }
62         try {
63             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 1), INPUTSIZE);
64             scriptRelaxed.forEach_testClzCharChar(inValue, out);
65             verifyResultsClzCharChar(inValue, out, true);
66             out.destroy();
67         } catch (Exception e) {
68             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzCharChar: " + e.toString());
69         }
70         inValue.destroy();
71     }
72 
verifyResultsClzCharChar(Allocation inValue, Allocation out, boolean relaxed)73     private void verifyResultsClzCharChar(Allocation inValue, Allocation out, boolean relaxed) {
74         byte[] arrayInValue = new byte[INPUTSIZE * 1];
75         Arrays.fill(arrayInValue, (byte) 42);
76         inValue.copyTo(arrayInValue);
77         byte[] arrayOut = new byte[INPUTSIZE * 1];
78         Arrays.fill(arrayOut, (byte) 42);
79         out.copyTo(arrayOut);
80         StringBuilder message = new StringBuilder();
81         boolean errorFound = false;
82         for (int i = 0; i < INPUTSIZE; i++) {
83             for (int j = 0; j < 1 ; j++) {
84                 // Extract the inputs.
85                 ArgumentsCharChar args = new ArgumentsCharChar();
86                 args.inValue = arrayInValue[i];
87                 // Figure out what the outputs should have been.
88                 CoreMathVerifier.computeClz(args);
89                 // Validate the outputs.
90                 boolean valid = true;
91                 if (args.out != arrayOut[i * 1 + j]) {
92                     valid = false;
93                 }
94                 if (!valid) {
95                     if (!errorFound) {
96                         errorFound = true;
97                         message.append("Input inValue: ");
98                         appendVariableToMessage(message, args.inValue);
99                         message.append("\n");
100                         message.append("Expected output out: ");
101                         appendVariableToMessage(message, args.out);
102                         message.append("\n");
103                         message.append("Actual   output out: ");
104                         appendVariableToMessage(message, arrayOut[i * 1 + j]);
105                         if (args.out != arrayOut[i * 1 + j]) {
106                             message.append(" FAIL");
107                         }
108                         message.append("\n");
109                         message.append("Errors at");
110                     }
111                     message.append(" [");
112                     message.append(Integer.toString(i));
113                     message.append(", ");
114                     message.append(Integer.toString(j));
115                     message.append("]");
116                 }
117             }
118         }
119         assertFalse("Incorrect output for checkClzCharChar" +
120                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
121     }
122 
checkClzChar2Char2()123     private void checkClzChar2Char2() {
124         Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 2, 0xf718b99dcaca5e93l, false);
125         try {
126             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 2), INPUTSIZE);
127             script.forEach_testClzChar2Char2(inValue, out);
128             verifyResultsClzChar2Char2(inValue, out, false);
129             out.destroy();
130         } catch (Exception e) {
131             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzChar2Char2: " + e.toString());
132         }
133         try {
134             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 2), INPUTSIZE);
135             scriptRelaxed.forEach_testClzChar2Char2(inValue, out);
136             verifyResultsClzChar2Char2(inValue, out, true);
137             out.destroy();
138         } catch (Exception e) {
139             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzChar2Char2: " + e.toString());
140         }
141         inValue.destroy();
142     }
143 
verifyResultsClzChar2Char2(Allocation inValue, Allocation out, boolean relaxed)144     private void verifyResultsClzChar2Char2(Allocation inValue, Allocation out, boolean relaxed) {
145         byte[] arrayInValue = new byte[INPUTSIZE * 2];
146         Arrays.fill(arrayInValue, (byte) 42);
147         inValue.copyTo(arrayInValue);
148         byte[] arrayOut = new byte[INPUTSIZE * 2];
149         Arrays.fill(arrayOut, (byte) 42);
150         out.copyTo(arrayOut);
151         StringBuilder message = new StringBuilder();
152         boolean errorFound = false;
153         for (int i = 0; i < INPUTSIZE; i++) {
154             for (int j = 0; j < 2 ; j++) {
155                 // Extract the inputs.
156                 ArgumentsCharChar args = new ArgumentsCharChar();
157                 args.inValue = arrayInValue[i * 2 + j];
158                 // Figure out what the outputs should have been.
159                 CoreMathVerifier.computeClz(args);
160                 // Validate the outputs.
161                 boolean valid = true;
162                 if (args.out != arrayOut[i * 2 + j]) {
163                     valid = false;
164                 }
165                 if (!valid) {
166                     if (!errorFound) {
167                         errorFound = true;
168                         message.append("Input inValue: ");
169                         appendVariableToMessage(message, args.inValue);
170                         message.append("\n");
171                         message.append("Expected output out: ");
172                         appendVariableToMessage(message, args.out);
173                         message.append("\n");
174                         message.append("Actual   output out: ");
175                         appendVariableToMessage(message, arrayOut[i * 2 + j]);
176                         if (args.out != arrayOut[i * 2 + j]) {
177                             message.append(" FAIL");
178                         }
179                         message.append("\n");
180                         message.append("Errors at");
181                     }
182                     message.append(" [");
183                     message.append(Integer.toString(i));
184                     message.append(", ");
185                     message.append(Integer.toString(j));
186                     message.append("]");
187                 }
188             }
189         }
190         assertFalse("Incorrect output for checkClzChar2Char2" +
191                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
192     }
193 
checkClzChar3Char3()194     private void checkClzChar3Char3() {
195         Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 3, 0x21a5da5bc7099347l, false);
196         try {
197             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 3), INPUTSIZE);
198             script.forEach_testClzChar3Char3(inValue, out);
199             verifyResultsClzChar3Char3(inValue, out, false);
200             out.destroy();
201         } catch (Exception e) {
202             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzChar3Char3: " + e.toString());
203         }
204         try {
205             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 3), INPUTSIZE);
206             scriptRelaxed.forEach_testClzChar3Char3(inValue, out);
207             verifyResultsClzChar3Char3(inValue, out, true);
208             out.destroy();
209         } catch (Exception e) {
210             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzChar3Char3: " + e.toString());
211         }
212         inValue.destroy();
213     }
214 
verifyResultsClzChar3Char3(Allocation inValue, Allocation out, boolean relaxed)215     private void verifyResultsClzChar3Char3(Allocation inValue, Allocation out, boolean relaxed) {
216         byte[] arrayInValue = new byte[INPUTSIZE * 4];
217         Arrays.fill(arrayInValue, (byte) 42);
218         inValue.copyTo(arrayInValue);
219         byte[] arrayOut = new byte[INPUTSIZE * 4];
220         Arrays.fill(arrayOut, (byte) 42);
221         out.copyTo(arrayOut);
222         StringBuilder message = new StringBuilder();
223         boolean errorFound = false;
224         for (int i = 0; i < INPUTSIZE; i++) {
225             for (int j = 0; j < 3 ; j++) {
226                 // Extract the inputs.
227                 ArgumentsCharChar args = new ArgumentsCharChar();
228                 args.inValue = arrayInValue[i * 4 + j];
229                 // Figure out what the outputs should have been.
230                 CoreMathVerifier.computeClz(args);
231                 // Validate the outputs.
232                 boolean valid = true;
233                 if (args.out != arrayOut[i * 4 + j]) {
234                     valid = false;
235                 }
236                 if (!valid) {
237                     if (!errorFound) {
238                         errorFound = true;
239                         message.append("Input inValue: ");
240                         appendVariableToMessage(message, args.inValue);
241                         message.append("\n");
242                         message.append("Expected output out: ");
243                         appendVariableToMessage(message, args.out);
244                         message.append("\n");
245                         message.append("Actual   output out: ");
246                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
247                         if (args.out != arrayOut[i * 4 + j]) {
248                             message.append(" FAIL");
249                         }
250                         message.append("\n");
251                         message.append("Errors at");
252                     }
253                     message.append(" [");
254                     message.append(Integer.toString(i));
255                     message.append(", ");
256                     message.append(Integer.toString(j));
257                     message.append("]");
258                 }
259             }
260         }
261         assertFalse("Incorrect output for checkClzChar3Char3" +
262                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
263     }
264 
checkClzChar4Char4()265     private void checkClzChar4Char4() {
266         Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 4, 0x4c32fb19c348c7fbl, false);
267         try {
268             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 4), INPUTSIZE);
269             script.forEach_testClzChar4Char4(inValue, out);
270             verifyResultsClzChar4Char4(inValue, out, false);
271             out.destroy();
272         } catch (Exception e) {
273             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzChar4Char4: " + e.toString());
274         }
275         try {
276             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 4), INPUTSIZE);
277             scriptRelaxed.forEach_testClzChar4Char4(inValue, out);
278             verifyResultsClzChar4Char4(inValue, out, true);
279             out.destroy();
280         } catch (Exception e) {
281             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzChar4Char4: " + e.toString());
282         }
283         inValue.destroy();
284     }
285 
verifyResultsClzChar4Char4(Allocation inValue, Allocation out, boolean relaxed)286     private void verifyResultsClzChar4Char4(Allocation inValue, Allocation out, boolean relaxed) {
287         byte[] arrayInValue = new byte[INPUTSIZE * 4];
288         Arrays.fill(arrayInValue, (byte) 42);
289         inValue.copyTo(arrayInValue);
290         byte[] arrayOut = new byte[INPUTSIZE * 4];
291         Arrays.fill(arrayOut, (byte) 42);
292         out.copyTo(arrayOut);
293         StringBuilder message = new StringBuilder();
294         boolean errorFound = false;
295         for (int i = 0; i < INPUTSIZE; i++) {
296             for (int j = 0; j < 4 ; j++) {
297                 // Extract the inputs.
298                 ArgumentsCharChar args = new ArgumentsCharChar();
299                 args.inValue = arrayInValue[i * 4 + j];
300                 // Figure out what the outputs should have been.
301                 CoreMathVerifier.computeClz(args);
302                 // Validate the outputs.
303                 boolean valid = true;
304                 if (args.out != arrayOut[i * 4 + j]) {
305                     valid = false;
306                 }
307                 if (!valid) {
308                     if (!errorFound) {
309                         errorFound = true;
310                         message.append("Input inValue: ");
311                         appendVariableToMessage(message, args.inValue);
312                         message.append("\n");
313                         message.append("Expected output out: ");
314                         appendVariableToMessage(message, args.out);
315                         message.append("\n");
316                         message.append("Actual   output out: ");
317                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
318                         if (args.out != arrayOut[i * 4 + j]) {
319                             message.append(" FAIL");
320                         }
321                         message.append("\n");
322                         message.append("Errors at");
323                     }
324                     message.append(" [");
325                     message.append(Integer.toString(i));
326                     message.append(", ");
327                     message.append(Integer.toString(j));
328                     message.append("]");
329                 }
330             }
331         }
332         assertFalse("Incorrect output for checkClzChar4Char4" +
333                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
334     }
335 
336     public class ArgumentsUcharUchar {
337         public byte inValue;
338         public byte out;
339     }
340 
checkClzUcharUchar()341     private void checkClzUcharUchar() {
342         Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 1, 0xd2e451b48b84f57fl, false);
343         try {
344             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 1), INPUTSIZE);
345             script.forEach_testClzUcharUchar(inValue, out);
346             verifyResultsClzUcharUchar(inValue, out, false);
347             out.destroy();
348         } catch (Exception e) {
349             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUcharUchar: " + e.toString());
350         }
351         try {
352             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 1), INPUTSIZE);
353             scriptRelaxed.forEach_testClzUcharUchar(inValue, out);
354             verifyResultsClzUcharUchar(inValue, out, true);
355             out.destroy();
356         } catch (Exception e) {
357             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUcharUchar: " + e.toString());
358         }
359         inValue.destroy();
360     }
361 
verifyResultsClzUcharUchar(Allocation inValue, Allocation out, boolean relaxed)362     private void verifyResultsClzUcharUchar(Allocation inValue, Allocation out, boolean relaxed) {
363         byte[] arrayInValue = new byte[INPUTSIZE * 1];
364         Arrays.fill(arrayInValue, (byte) 42);
365         inValue.copyTo(arrayInValue);
366         byte[] arrayOut = new byte[INPUTSIZE * 1];
367         Arrays.fill(arrayOut, (byte) 42);
368         out.copyTo(arrayOut);
369         StringBuilder message = new StringBuilder();
370         boolean errorFound = false;
371         for (int i = 0; i < INPUTSIZE; i++) {
372             for (int j = 0; j < 1 ; j++) {
373                 // Extract the inputs.
374                 ArgumentsUcharUchar args = new ArgumentsUcharUchar();
375                 args.inValue = arrayInValue[i];
376                 // Figure out what the outputs should have been.
377                 CoreMathVerifier.computeClz(args);
378                 // Validate the outputs.
379                 boolean valid = true;
380                 if (args.out != arrayOut[i * 1 + j]) {
381                     valid = false;
382                 }
383                 if (!valid) {
384                     if (!errorFound) {
385                         errorFound = true;
386                         message.append("Input inValue: ");
387                         appendVariableToMessage(message, args.inValue);
388                         message.append("\n");
389                         message.append("Expected output out: ");
390                         appendVariableToMessage(message, args.out);
391                         message.append("\n");
392                         message.append("Actual   output out: ");
393                         appendVariableToMessage(message, arrayOut[i * 1 + j]);
394                         if (args.out != arrayOut[i * 1 + j]) {
395                             message.append(" FAIL");
396                         }
397                         message.append("\n");
398                         message.append("Errors at");
399                     }
400                     message.append(" [");
401                     message.append(Integer.toString(i));
402                     message.append(", ");
403                     message.append(Integer.toString(j));
404                     message.append("]");
405                 }
406             }
407         }
408         assertFalse("Incorrect output for checkClzUcharUchar" +
409                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
410     }
411 
checkClzUchar2Uchar2()412     private void checkClzUchar2Uchar2() {
413         Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 2, 0x792e2970f47ebc85l, false);
414         try {
415             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE);
416             script.forEach_testClzUchar2Uchar2(inValue, out);
417             verifyResultsClzUchar2Uchar2(inValue, out, false);
418             out.destroy();
419         } catch (Exception e) {
420             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUchar2Uchar2: " + e.toString());
421         }
422         try {
423             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE);
424             scriptRelaxed.forEach_testClzUchar2Uchar2(inValue, out);
425             verifyResultsClzUchar2Uchar2(inValue, out, true);
426             out.destroy();
427         } catch (Exception e) {
428             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUchar2Uchar2: " + e.toString());
429         }
430         inValue.destroy();
431     }
432 
verifyResultsClzUchar2Uchar2(Allocation inValue, Allocation out, boolean relaxed)433     private void verifyResultsClzUchar2Uchar2(Allocation inValue, Allocation out, boolean relaxed) {
434         byte[] arrayInValue = new byte[INPUTSIZE * 2];
435         Arrays.fill(arrayInValue, (byte) 42);
436         inValue.copyTo(arrayInValue);
437         byte[] arrayOut = new byte[INPUTSIZE * 2];
438         Arrays.fill(arrayOut, (byte) 42);
439         out.copyTo(arrayOut);
440         StringBuilder message = new StringBuilder();
441         boolean errorFound = false;
442         for (int i = 0; i < INPUTSIZE; i++) {
443             for (int j = 0; j < 2 ; j++) {
444                 // Extract the inputs.
445                 ArgumentsUcharUchar args = new ArgumentsUcharUchar();
446                 args.inValue = arrayInValue[i * 2 + j];
447                 // Figure out what the outputs should have been.
448                 CoreMathVerifier.computeClz(args);
449                 // Validate the outputs.
450                 boolean valid = true;
451                 if (args.out != arrayOut[i * 2 + j]) {
452                     valid = false;
453                 }
454                 if (!valid) {
455                     if (!errorFound) {
456                         errorFound = true;
457                         message.append("Input inValue: ");
458                         appendVariableToMessage(message, args.inValue);
459                         message.append("\n");
460                         message.append("Expected output out: ");
461                         appendVariableToMessage(message, args.out);
462                         message.append("\n");
463                         message.append("Actual   output out: ");
464                         appendVariableToMessage(message, arrayOut[i * 2 + j]);
465                         if (args.out != arrayOut[i * 2 + j]) {
466                             message.append(" FAIL");
467                         }
468                         message.append("\n");
469                         message.append("Errors at");
470                     }
471                     message.append(" [");
472                     message.append(Integer.toString(i));
473                     message.append(", ");
474                     message.append(Integer.toString(j));
475                     message.append("]");
476                 }
477             }
478         }
479         assertFalse("Incorrect output for checkClzUchar2Uchar2" +
480                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
481     }
482 
checkClzUchar3Uchar3()483     private void checkClzUchar3Uchar3() {
484         Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 3, 0x9ee29ef83dbce203l, false);
485         try {
486             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE);
487             script.forEach_testClzUchar3Uchar3(inValue, out);
488             verifyResultsClzUchar3Uchar3(inValue, out, false);
489             out.destroy();
490         } catch (Exception e) {
491             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUchar3Uchar3: " + e.toString());
492         }
493         try {
494             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE);
495             scriptRelaxed.forEach_testClzUchar3Uchar3(inValue, out);
496             verifyResultsClzUchar3Uchar3(inValue, out, true);
497             out.destroy();
498         } catch (Exception e) {
499             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUchar3Uchar3: " + e.toString());
500         }
501         inValue.destroy();
502     }
503 
verifyResultsClzUchar3Uchar3(Allocation inValue, Allocation out, boolean relaxed)504     private void verifyResultsClzUchar3Uchar3(Allocation inValue, Allocation out, boolean relaxed) {
505         byte[] arrayInValue = new byte[INPUTSIZE * 4];
506         Arrays.fill(arrayInValue, (byte) 42);
507         inValue.copyTo(arrayInValue);
508         byte[] arrayOut = new byte[INPUTSIZE * 4];
509         Arrays.fill(arrayOut, (byte) 42);
510         out.copyTo(arrayOut);
511         StringBuilder message = new StringBuilder();
512         boolean errorFound = false;
513         for (int i = 0; i < INPUTSIZE; i++) {
514             for (int j = 0; j < 3 ; j++) {
515                 // Extract the inputs.
516                 ArgumentsUcharUchar args = new ArgumentsUcharUchar();
517                 args.inValue = arrayInValue[i * 4 + j];
518                 // Figure out what the outputs should have been.
519                 CoreMathVerifier.computeClz(args);
520                 // Validate the outputs.
521                 boolean valid = true;
522                 if (args.out != arrayOut[i * 4 + j]) {
523                     valid = false;
524                 }
525                 if (!valid) {
526                     if (!errorFound) {
527                         errorFound = true;
528                         message.append("Input inValue: ");
529                         appendVariableToMessage(message, args.inValue);
530                         message.append("\n");
531                         message.append("Expected output out: ");
532                         appendVariableToMessage(message, args.out);
533                         message.append("\n");
534                         message.append("Actual   output out: ");
535                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
536                         if (args.out != arrayOut[i * 4 + j]) {
537                             message.append(" FAIL");
538                         }
539                         message.append("\n");
540                         message.append("Errors at");
541                     }
542                     message.append(" [");
543                     message.append(Integer.toString(i));
544                     message.append(", ");
545                     message.append(Integer.toString(j));
546                     message.append("]");
547                 }
548             }
549         }
550         assertFalse("Incorrect output for checkClzUchar3Uchar3" +
551                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
552     }
553 
checkClzUchar4Uchar4()554     private void checkClzUchar4Uchar4() {
555         Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 4, 0xc497147f86fb0781l, false);
556         try {
557             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE);
558             script.forEach_testClzUchar4Uchar4(inValue, out);
559             verifyResultsClzUchar4Uchar4(inValue, out, false);
560             out.destroy();
561         } catch (Exception e) {
562             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUchar4Uchar4: " + e.toString());
563         }
564         try {
565             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE);
566             scriptRelaxed.forEach_testClzUchar4Uchar4(inValue, out);
567             verifyResultsClzUchar4Uchar4(inValue, out, true);
568             out.destroy();
569         } catch (Exception e) {
570             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUchar4Uchar4: " + e.toString());
571         }
572         inValue.destroy();
573     }
574 
verifyResultsClzUchar4Uchar4(Allocation inValue, Allocation out, boolean relaxed)575     private void verifyResultsClzUchar4Uchar4(Allocation inValue, Allocation out, boolean relaxed) {
576         byte[] arrayInValue = new byte[INPUTSIZE * 4];
577         Arrays.fill(arrayInValue, (byte) 42);
578         inValue.copyTo(arrayInValue);
579         byte[] arrayOut = new byte[INPUTSIZE * 4];
580         Arrays.fill(arrayOut, (byte) 42);
581         out.copyTo(arrayOut);
582         StringBuilder message = new StringBuilder();
583         boolean errorFound = false;
584         for (int i = 0; i < INPUTSIZE; i++) {
585             for (int j = 0; j < 4 ; j++) {
586                 // Extract the inputs.
587                 ArgumentsUcharUchar args = new ArgumentsUcharUchar();
588                 args.inValue = arrayInValue[i * 4 + j];
589                 // Figure out what the outputs should have been.
590                 CoreMathVerifier.computeClz(args);
591                 // Validate the outputs.
592                 boolean valid = true;
593                 if (args.out != arrayOut[i * 4 + j]) {
594                     valid = false;
595                 }
596                 if (!valid) {
597                     if (!errorFound) {
598                         errorFound = true;
599                         message.append("Input inValue: ");
600                         appendVariableToMessage(message, args.inValue);
601                         message.append("\n");
602                         message.append("Expected output out: ");
603                         appendVariableToMessage(message, args.out);
604                         message.append("\n");
605                         message.append("Actual   output out: ");
606                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
607                         if (args.out != arrayOut[i * 4 + j]) {
608                             message.append(" FAIL");
609                         }
610                         message.append("\n");
611                         message.append("Errors at");
612                     }
613                     message.append(" [");
614                     message.append(Integer.toString(i));
615                     message.append(", ");
616                     message.append(Integer.toString(j));
617                     message.append("]");
618                 }
619             }
620         }
621         assertFalse("Incorrect output for checkClzUchar4Uchar4" +
622                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
623     }
624 
625     public class ArgumentsShortShort {
626         public short inValue;
627         public short out;
628     }
629 
checkClzShortShort()630     private void checkClzShortShort() {
631         Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 1, 0x3290aea900d8ad53l, false);
632         try {
633             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 1), INPUTSIZE);
634             script.forEach_testClzShortShort(inValue, out);
635             verifyResultsClzShortShort(inValue, out, false);
636             out.destroy();
637         } catch (Exception e) {
638             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzShortShort: " + e.toString());
639         }
640         try {
641             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 1), INPUTSIZE);
642             scriptRelaxed.forEach_testClzShortShort(inValue, out);
643             verifyResultsClzShortShort(inValue, out, true);
644             out.destroy();
645         } catch (Exception e) {
646             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzShortShort: " + e.toString());
647         }
648         inValue.destroy();
649     }
650 
verifyResultsClzShortShort(Allocation inValue, Allocation out, boolean relaxed)651     private void verifyResultsClzShortShort(Allocation inValue, Allocation out, boolean relaxed) {
652         short[] arrayInValue = new short[INPUTSIZE * 1];
653         Arrays.fill(arrayInValue, (short) 42);
654         inValue.copyTo(arrayInValue);
655         short[] arrayOut = new short[INPUTSIZE * 1];
656         Arrays.fill(arrayOut, (short) 42);
657         out.copyTo(arrayOut);
658         StringBuilder message = new StringBuilder();
659         boolean errorFound = false;
660         for (int i = 0; i < INPUTSIZE; i++) {
661             for (int j = 0; j < 1 ; j++) {
662                 // Extract the inputs.
663                 ArgumentsShortShort args = new ArgumentsShortShort();
664                 args.inValue = arrayInValue[i];
665                 // Figure out what the outputs should have been.
666                 CoreMathVerifier.computeClz(args);
667                 // Validate the outputs.
668                 boolean valid = true;
669                 if (args.out != arrayOut[i * 1 + j]) {
670                     valid = false;
671                 }
672                 if (!valid) {
673                     if (!errorFound) {
674                         errorFound = true;
675                         message.append("Input inValue: ");
676                         appendVariableToMessage(message, args.inValue);
677                         message.append("\n");
678                         message.append("Expected output out: ");
679                         appendVariableToMessage(message, args.out);
680                         message.append("\n");
681                         message.append("Actual   output out: ");
682                         appendVariableToMessage(message, arrayOut[i * 1 + j]);
683                         if (args.out != arrayOut[i * 1 + j]) {
684                             message.append(" FAIL");
685                         }
686                         message.append("\n");
687                         message.append("Errors at");
688                     }
689                     message.append(" [");
690                     message.append(Integer.toString(i));
691                     message.append(", ");
692                     message.append(Integer.toString(j));
693                     message.append("]");
694                 }
695             }
696         }
697         assertFalse("Incorrect output for checkClzShortShort" +
698                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
699     }
700 
checkClzShort2Short2()701     private void checkClzShort2Short2() {
702         Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 2, 0x81f69d4442dd6ebfl, false);
703         try {
704             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 2), INPUTSIZE);
705             script.forEach_testClzShort2Short2(inValue, out);
706             verifyResultsClzShort2Short2(inValue, out, false);
707             out.destroy();
708         } catch (Exception e) {
709             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzShort2Short2: " + e.toString());
710         }
711         try {
712             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 2), INPUTSIZE);
713             scriptRelaxed.forEach_testClzShort2Short2(inValue, out);
714             verifyResultsClzShort2Short2(inValue, out, true);
715             out.destroy();
716         } catch (Exception e) {
717             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzShort2Short2: " + e.toString());
718         }
719         inValue.destroy();
720     }
721 
verifyResultsClzShort2Short2(Allocation inValue, Allocation out, boolean relaxed)722     private void verifyResultsClzShort2Short2(Allocation inValue, Allocation out, boolean relaxed) {
723         short[] arrayInValue = new short[INPUTSIZE * 2];
724         Arrays.fill(arrayInValue, (short) 42);
725         inValue.copyTo(arrayInValue);
726         short[] arrayOut = new short[INPUTSIZE * 2];
727         Arrays.fill(arrayOut, (short) 42);
728         out.copyTo(arrayOut);
729         StringBuilder message = new StringBuilder();
730         boolean errorFound = false;
731         for (int i = 0; i < INPUTSIZE; i++) {
732             for (int j = 0; j < 2 ; j++) {
733                 // Extract the inputs.
734                 ArgumentsShortShort args = new ArgumentsShortShort();
735                 args.inValue = arrayInValue[i * 2 + j];
736                 // Figure out what the outputs should have been.
737                 CoreMathVerifier.computeClz(args);
738                 // Validate the outputs.
739                 boolean valid = true;
740                 if (args.out != arrayOut[i * 2 + j]) {
741                     valid = false;
742                 }
743                 if (!valid) {
744                     if (!errorFound) {
745                         errorFound = true;
746                         message.append("Input inValue: ");
747                         appendVariableToMessage(message, args.inValue);
748                         message.append("\n");
749                         message.append("Expected output out: ");
750                         appendVariableToMessage(message, args.out);
751                         message.append("\n");
752                         message.append("Actual   output out: ");
753                         appendVariableToMessage(message, arrayOut[i * 2 + j]);
754                         if (args.out != arrayOut[i * 2 + j]) {
755                             message.append(" FAIL");
756                         }
757                         message.append("\n");
758                         message.append("Errors at");
759                     }
760                     message.append(" [");
761                     message.append(Integer.toString(i));
762                     message.append(", ");
763                     message.append(Integer.toString(j));
764                     message.append("]");
765                 }
766             }
767         }
768         assertFalse("Incorrect output for checkClzShort2Short2" +
769                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
770     }
771 
checkClzShort3Short3()772     private void checkClzShort3Short3() {
773         Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 3, 0xa7ab12cb8c1b943dl, false);
774         try {
775             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 3), INPUTSIZE);
776             script.forEach_testClzShort3Short3(inValue, out);
777             verifyResultsClzShort3Short3(inValue, out, false);
778             out.destroy();
779         } catch (Exception e) {
780             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzShort3Short3: " + e.toString());
781         }
782         try {
783             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 3), INPUTSIZE);
784             scriptRelaxed.forEach_testClzShort3Short3(inValue, out);
785             verifyResultsClzShort3Short3(inValue, out, true);
786             out.destroy();
787         } catch (Exception e) {
788             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzShort3Short3: " + e.toString());
789         }
790         inValue.destroy();
791     }
792 
verifyResultsClzShort3Short3(Allocation inValue, Allocation out, boolean relaxed)793     private void verifyResultsClzShort3Short3(Allocation inValue, Allocation out, boolean relaxed) {
794         short[] arrayInValue = new short[INPUTSIZE * 4];
795         Arrays.fill(arrayInValue, (short) 42);
796         inValue.copyTo(arrayInValue);
797         short[] arrayOut = new short[INPUTSIZE * 4];
798         Arrays.fill(arrayOut, (short) 42);
799         out.copyTo(arrayOut);
800         StringBuilder message = new StringBuilder();
801         boolean errorFound = false;
802         for (int i = 0; i < INPUTSIZE; i++) {
803             for (int j = 0; j < 3 ; j++) {
804                 // Extract the inputs.
805                 ArgumentsShortShort args = new ArgumentsShortShort();
806                 args.inValue = arrayInValue[i * 4 + j];
807                 // Figure out what the outputs should have been.
808                 CoreMathVerifier.computeClz(args);
809                 // Validate the outputs.
810                 boolean valid = true;
811                 if (args.out != arrayOut[i * 4 + j]) {
812                     valid = false;
813                 }
814                 if (!valid) {
815                     if (!errorFound) {
816                         errorFound = true;
817                         message.append("Input inValue: ");
818                         appendVariableToMessage(message, args.inValue);
819                         message.append("\n");
820                         message.append("Expected output out: ");
821                         appendVariableToMessage(message, args.out);
822                         message.append("\n");
823                         message.append("Actual   output out: ");
824                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
825                         if (args.out != arrayOut[i * 4 + j]) {
826                             message.append(" FAIL");
827                         }
828                         message.append("\n");
829                         message.append("Errors at");
830                     }
831                     message.append(" [");
832                     message.append(Integer.toString(i));
833                     message.append(", ");
834                     message.append(Integer.toString(j));
835                     message.append("]");
836                 }
837             }
838         }
839         assertFalse("Incorrect output for checkClzShort3Short3" +
840                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
841     }
842 
checkClzShort4Short4()843     private void checkClzShort4Short4() {
844         Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 4, 0xcd5f8852d559b9bbl, false);
845         try {
846             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 4), INPUTSIZE);
847             script.forEach_testClzShort4Short4(inValue, out);
848             verifyResultsClzShort4Short4(inValue, out, false);
849             out.destroy();
850         } catch (Exception e) {
851             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzShort4Short4: " + e.toString());
852         }
853         try {
854             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 4), INPUTSIZE);
855             scriptRelaxed.forEach_testClzShort4Short4(inValue, out);
856             verifyResultsClzShort4Short4(inValue, out, true);
857             out.destroy();
858         } catch (Exception e) {
859             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzShort4Short4: " + e.toString());
860         }
861         inValue.destroy();
862     }
863 
verifyResultsClzShort4Short4(Allocation inValue, Allocation out, boolean relaxed)864     private void verifyResultsClzShort4Short4(Allocation inValue, Allocation out, boolean relaxed) {
865         short[] arrayInValue = new short[INPUTSIZE * 4];
866         Arrays.fill(arrayInValue, (short) 42);
867         inValue.copyTo(arrayInValue);
868         short[] arrayOut = new short[INPUTSIZE * 4];
869         Arrays.fill(arrayOut, (short) 42);
870         out.copyTo(arrayOut);
871         StringBuilder message = new StringBuilder();
872         boolean errorFound = false;
873         for (int i = 0; i < INPUTSIZE; i++) {
874             for (int j = 0; j < 4 ; j++) {
875                 // Extract the inputs.
876                 ArgumentsShortShort args = new ArgumentsShortShort();
877                 args.inValue = arrayInValue[i * 4 + j];
878                 // Figure out what the outputs should have been.
879                 CoreMathVerifier.computeClz(args);
880                 // Validate the outputs.
881                 boolean valid = true;
882                 if (args.out != arrayOut[i * 4 + j]) {
883                     valid = false;
884                 }
885                 if (!valid) {
886                     if (!errorFound) {
887                         errorFound = true;
888                         message.append("Input inValue: ");
889                         appendVariableToMessage(message, args.inValue);
890                         message.append("\n");
891                         message.append("Expected output out: ");
892                         appendVariableToMessage(message, args.out);
893                         message.append("\n");
894                         message.append("Actual   output out: ");
895                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
896                         if (args.out != arrayOut[i * 4 + j]) {
897                             message.append(" FAIL");
898                         }
899                         message.append("\n");
900                         message.append("Errors at");
901                     }
902                     message.append(" [");
903                     message.append(Integer.toString(i));
904                     message.append(", ");
905                     message.append(Integer.toString(j));
906                     message.append("]");
907                 }
908             }
909         }
910         assertFalse("Incorrect output for checkClzShort4Short4" +
911                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
912     }
913 
914     public class ArgumentsUshortUshort {
915         public short inValue;
916         public short out;
917     }
918 
checkClzUshortUshort()919     private void checkClzUshortUshort() {
920         Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 1, 0x97bdeee92c0103a5l, false);
921         try {
922             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 1), INPUTSIZE);
923             script.forEach_testClzUshortUshort(inValue, out);
924             verifyResultsClzUshortUshort(inValue, out, false);
925             out.destroy();
926         } catch (Exception e) {
927             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUshortUshort: " + e.toString());
928         }
929         try {
930             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 1), INPUTSIZE);
931             scriptRelaxed.forEach_testClzUshortUshort(inValue, out);
932             verifyResultsClzUshortUshort(inValue, out, true);
933             out.destroy();
934         } catch (Exception e) {
935             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUshortUshort: " + e.toString());
936         }
937         inValue.destroy();
938     }
939 
verifyResultsClzUshortUshort(Allocation inValue, Allocation out, boolean relaxed)940     private void verifyResultsClzUshortUshort(Allocation inValue, Allocation out, boolean relaxed) {
941         short[] arrayInValue = new short[INPUTSIZE * 1];
942         Arrays.fill(arrayInValue, (short) 42);
943         inValue.copyTo(arrayInValue);
944         short[] arrayOut = new short[INPUTSIZE * 1];
945         Arrays.fill(arrayOut, (short) 42);
946         out.copyTo(arrayOut);
947         StringBuilder message = new StringBuilder();
948         boolean errorFound = false;
949         for (int i = 0; i < INPUTSIZE; i++) {
950             for (int j = 0; j < 1 ; j++) {
951                 // Extract the inputs.
952                 ArgumentsUshortUshort args = new ArgumentsUshortUshort();
953                 args.inValue = arrayInValue[i];
954                 // Figure out what the outputs should have been.
955                 CoreMathVerifier.computeClz(args);
956                 // Validate the outputs.
957                 boolean valid = true;
958                 if (args.out != arrayOut[i * 1 + j]) {
959                     valid = false;
960                 }
961                 if (!valid) {
962                     if (!errorFound) {
963                         errorFound = true;
964                         message.append("Input inValue: ");
965                         appendVariableToMessage(message, args.inValue);
966                         message.append("\n");
967                         message.append("Expected output out: ");
968                         appendVariableToMessage(message, args.out);
969                         message.append("\n");
970                         message.append("Actual   output out: ");
971                         appendVariableToMessage(message, arrayOut[i * 1 + j]);
972                         if (args.out != arrayOut[i * 1 + j]) {
973                             message.append(" FAIL");
974                         }
975                         message.append("\n");
976                         message.append("Errors at");
977                     }
978                     message.append(" [");
979                     message.append(Integer.toString(i));
980                     message.append(", ");
981                     message.append(Integer.toString(j));
982                     message.append("]");
983                 }
984             }
985         }
986         assertFalse("Incorrect output for checkClzUshortUshort" +
987                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
988     }
989 
checkClzUshort2Ushort2()990     private void checkClzUshort2Ushort2() {
991         Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 2, 0x5ea7a024b2913837l, false);
992         try {
993             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE);
994             script.forEach_testClzUshort2Ushort2(inValue, out);
995             verifyResultsClzUshort2Ushort2(inValue, out, false);
996             out.destroy();
997         } catch (Exception e) {
998             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUshort2Ushort2: " + e.toString());
999         }
1000         try {
1001             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE);
1002             scriptRelaxed.forEach_testClzUshort2Ushort2(inValue, out);
1003             verifyResultsClzUshort2Ushort2(inValue, out, true);
1004             out.destroy();
1005         } catch (Exception e) {
1006             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUshort2Ushort2: " + e.toString());
1007         }
1008         inValue.destroy();
1009     }
1010 
verifyResultsClzUshort2Ushort2(Allocation inValue, Allocation out, boolean relaxed)1011     private void verifyResultsClzUshort2Ushort2(Allocation inValue, Allocation out, boolean relaxed) {
1012         short[] arrayInValue = new short[INPUTSIZE * 2];
1013         Arrays.fill(arrayInValue, (short) 42);
1014         inValue.copyTo(arrayInValue);
1015         short[] arrayOut = new short[INPUTSIZE * 2];
1016         Arrays.fill(arrayOut, (short) 42);
1017         out.copyTo(arrayOut);
1018         StringBuilder message = new StringBuilder();
1019         boolean errorFound = false;
1020         for (int i = 0; i < INPUTSIZE; i++) {
1021             for (int j = 0; j < 2 ; j++) {
1022                 // Extract the inputs.
1023                 ArgumentsUshortUshort args = new ArgumentsUshortUshort();
1024                 args.inValue = arrayInValue[i * 2 + j];
1025                 // Figure out what the outputs should have been.
1026                 CoreMathVerifier.computeClz(args);
1027                 // Validate the outputs.
1028                 boolean valid = true;
1029                 if (args.out != arrayOut[i * 2 + j]) {
1030                     valid = false;
1031                 }
1032                 if (!valid) {
1033                     if (!errorFound) {
1034                         errorFound = true;
1035                         message.append("Input inValue: ");
1036                         appendVariableToMessage(message, args.inValue);
1037                         message.append("\n");
1038                         message.append("Expected output out: ");
1039                         appendVariableToMessage(message, args.out);
1040                         message.append("\n");
1041                         message.append("Actual   output out: ");
1042                         appendVariableToMessage(message, arrayOut[i * 2 + j]);
1043                         if (args.out != arrayOut[i * 2 + j]) {
1044                             message.append(" FAIL");
1045                         }
1046                         message.append("\n");
1047                         message.append("Errors at");
1048                     }
1049                     message.append(" [");
1050                     message.append(Integer.toString(i));
1051                     message.append(", ");
1052                     message.append(Integer.toString(j));
1053                     message.append("]");
1054                 }
1055             }
1056         }
1057         assertFalse("Incorrect output for checkClzUshort2Ushort2" +
1058                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
1059     }
1060 
checkClzUshort3Ushort3()1061     private void checkClzUshort3Ushort3() {
1062         Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 3, 0xb3f7537beaa1cfa3l, false);
1063         try {
1064             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE);
1065             script.forEach_testClzUshort3Ushort3(inValue, out);
1066             verifyResultsClzUshort3Ushort3(inValue, out, false);
1067             out.destroy();
1068         } catch (Exception e) {
1069             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUshort3Ushort3: " + e.toString());
1070         }
1071         try {
1072             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE);
1073             scriptRelaxed.forEach_testClzUshort3Ushort3(inValue, out);
1074             verifyResultsClzUshort3Ushort3(inValue, out, true);
1075             out.destroy();
1076         } catch (Exception e) {
1077             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUshort3Ushort3: " + e.toString());
1078         }
1079         inValue.destroy();
1080     }
1081 
verifyResultsClzUshort3Ushort3(Allocation inValue, Allocation out, boolean relaxed)1082     private void verifyResultsClzUshort3Ushort3(Allocation inValue, Allocation out, boolean relaxed) {
1083         short[] arrayInValue = new short[INPUTSIZE * 4];
1084         Arrays.fill(arrayInValue, (short) 42);
1085         inValue.copyTo(arrayInValue);
1086         short[] arrayOut = new short[INPUTSIZE * 4];
1087         Arrays.fill(arrayOut, (short) 42);
1088         out.copyTo(arrayOut);
1089         StringBuilder message = new StringBuilder();
1090         boolean errorFound = false;
1091         for (int i = 0; i < INPUTSIZE; i++) {
1092             for (int j = 0; j < 3 ; j++) {
1093                 // Extract the inputs.
1094                 ArgumentsUshortUshort args = new ArgumentsUshortUshort();
1095                 args.inValue = arrayInValue[i * 4 + j];
1096                 // Figure out what the outputs should have been.
1097                 CoreMathVerifier.computeClz(args);
1098                 // Validate the outputs.
1099                 boolean valid = true;
1100                 if (args.out != arrayOut[i * 4 + j]) {
1101                     valid = false;
1102                 }
1103                 if (!valid) {
1104                     if (!errorFound) {
1105                         errorFound = true;
1106                         message.append("Input inValue: ");
1107                         appendVariableToMessage(message, args.inValue);
1108                         message.append("\n");
1109                         message.append("Expected output out: ");
1110                         appendVariableToMessage(message, args.out);
1111                         message.append("\n");
1112                         message.append("Actual   output out: ");
1113                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
1114                         if (args.out != arrayOut[i * 4 + j]) {
1115                             message.append(" FAIL");
1116                         }
1117                         message.append("\n");
1118                         message.append("Errors at");
1119                     }
1120                     message.append(" [");
1121                     message.append(Integer.toString(i));
1122                     message.append(", ");
1123                     message.append(Integer.toString(j));
1124                     message.append("]");
1125                 }
1126             }
1127         }
1128         assertFalse("Incorrect output for checkClzUshort3Ushort3" +
1129                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
1130     }
1131 
checkClzUshort4Ushort4()1132     private void checkClzUshort4Ushort4() {
1133         Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 4, 0x94706d322b2670fl, false);
1134         try {
1135             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE);
1136             script.forEach_testClzUshort4Ushort4(inValue, out);
1137             verifyResultsClzUshort4Ushort4(inValue, out, false);
1138             out.destroy();
1139         } catch (Exception e) {
1140             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUshort4Ushort4: " + e.toString());
1141         }
1142         try {
1143             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE);
1144             scriptRelaxed.forEach_testClzUshort4Ushort4(inValue, out);
1145             verifyResultsClzUshort4Ushort4(inValue, out, true);
1146             out.destroy();
1147         } catch (Exception e) {
1148             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUshort4Ushort4: " + e.toString());
1149         }
1150         inValue.destroy();
1151     }
1152 
verifyResultsClzUshort4Ushort4(Allocation inValue, Allocation out, boolean relaxed)1153     private void verifyResultsClzUshort4Ushort4(Allocation inValue, Allocation out, boolean relaxed) {
1154         short[] arrayInValue = new short[INPUTSIZE * 4];
1155         Arrays.fill(arrayInValue, (short) 42);
1156         inValue.copyTo(arrayInValue);
1157         short[] arrayOut = new short[INPUTSIZE * 4];
1158         Arrays.fill(arrayOut, (short) 42);
1159         out.copyTo(arrayOut);
1160         StringBuilder message = new StringBuilder();
1161         boolean errorFound = false;
1162         for (int i = 0; i < INPUTSIZE; i++) {
1163             for (int j = 0; j < 4 ; j++) {
1164                 // Extract the inputs.
1165                 ArgumentsUshortUshort args = new ArgumentsUshortUshort();
1166                 args.inValue = arrayInValue[i * 4 + j];
1167                 // Figure out what the outputs should have been.
1168                 CoreMathVerifier.computeClz(args);
1169                 // Validate the outputs.
1170                 boolean valid = true;
1171                 if (args.out != arrayOut[i * 4 + j]) {
1172                     valid = false;
1173                 }
1174                 if (!valid) {
1175                     if (!errorFound) {
1176                         errorFound = true;
1177                         message.append("Input inValue: ");
1178                         appendVariableToMessage(message, args.inValue);
1179                         message.append("\n");
1180                         message.append("Expected output out: ");
1181                         appendVariableToMessage(message, args.out);
1182                         message.append("\n");
1183                         message.append("Actual   output out: ");
1184                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
1185                         if (args.out != arrayOut[i * 4 + j]) {
1186                             message.append(" FAIL");
1187                         }
1188                         message.append("\n");
1189                         message.append("Errors at");
1190                     }
1191                     message.append(" [");
1192                     message.append(Integer.toString(i));
1193                     message.append(", ");
1194                     message.append(Integer.toString(j));
1195                     message.append("]");
1196                 }
1197             }
1198         }
1199         assertFalse("Incorrect output for checkClzUshort4Ushort4" +
1200                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
1201     }
1202 
1203     public class ArgumentsIntInt {
1204         public int inValue;
1205         public int out;
1206     }
1207 
checkClzIntInt()1208     private void checkClzIntInt() {
1209         Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 1, 0xb13809da3142eb97l, false);
1210         try {
1211             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 1), INPUTSIZE);
1212             script.forEach_testClzIntInt(inValue, out);
1213             verifyResultsClzIntInt(inValue, out, false);
1214             out.destroy();
1215         } catch (Exception e) {
1216             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzIntInt: " + e.toString());
1217         }
1218         try {
1219             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 1), INPUTSIZE);
1220             scriptRelaxed.forEach_testClzIntInt(inValue, out);
1221             verifyResultsClzIntInt(inValue, out, true);
1222             out.destroy();
1223         } catch (Exception e) {
1224             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzIntInt: " + e.toString());
1225         }
1226         inValue.destroy();
1227     }
1228 
verifyResultsClzIntInt(Allocation inValue, Allocation out, boolean relaxed)1229     private void verifyResultsClzIntInt(Allocation inValue, Allocation out, boolean relaxed) {
1230         int[] arrayInValue = new int[INPUTSIZE * 1];
1231         Arrays.fill(arrayInValue, (int) 42);
1232         inValue.copyTo(arrayInValue);
1233         int[] arrayOut = new int[INPUTSIZE * 1];
1234         Arrays.fill(arrayOut, (int) 42);
1235         out.copyTo(arrayOut);
1236         StringBuilder message = new StringBuilder();
1237         boolean errorFound = false;
1238         for (int i = 0; i < INPUTSIZE; i++) {
1239             for (int j = 0; j < 1 ; j++) {
1240                 // Extract the inputs.
1241                 ArgumentsIntInt args = new ArgumentsIntInt();
1242                 args.inValue = arrayInValue[i];
1243                 // Figure out what the outputs should have been.
1244                 CoreMathVerifier.computeClz(args);
1245                 // Validate the outputs.
1246                 boolean valid = true;
1247                 if (args.out != arrayOut[i * 1 + j]) {
1248                     valid = false;
1249                 }
1250                 if (!valid) {
1251                     if (!errorFound) {
1252                         errorFound = true;
1253                         message.append("Input inValue: ");
1254                         appendVariableToMessage(message, args.inValue);
1255                         message.append("\n");
1256                         message.append("Expected output out: ");
1257                         appendVariableToMessage(message, args.out);
1258                         message.append("\n");
1259                         message.append("Actual   output out: ");
1260                         appendVariableToMessage(message, arrayOut[i * 1 + j]);
1261                         if (args.out != arrayOut[i * 1 + j]) {
1262                             message.append(" FAIL");
1263                         }
1264                         message.append("\n");
1265                         message.append("Errors at");
1266                     }
1267                     message.append(" [");
1268                     message.append(Integer.toString(i));
1269                     message.append(", ");
1270                     message.append(Integer.toString(j));
1271                     message.append("]");
1272                 }
1273             }
1274         }
1275         assertFalse("Incorrect output for checkClzIntInt" +
1276                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
1277     }
1278 
checkClzInt2Int2()1279     private void checkClzInt2Int2() {
1280         Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 2, 0xc9fd2c1a27fe3ad5l, false);
1281         try {
1282             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE);
1283             script.forEach_testClzInt2Int2(inValue, out);
1284             verifyResultsClzInt2Int2(inValue, out, false);
1285             out.destroy();
1286         } catch (Exception e) {
1287             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzInt2Int2: " + e.toString());
1288         }
1289         try {
1290             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE);
1291             scriptRelaxed.forEach_testClzInt2Int2(inValue, out);
1292             verifyResultsClzInt2Int2(inValue, out, true);
1293             out.destroy();
1294         } catch (Exception e) {
1295             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzInt2Int2: " + e.toString());
1296         }
1297         inValue.destroy();
1298     }
1299 
verifyResultsClzInt2Int2(Allocation inValue, Allocation out, boolean relaxed)1300     private void verifyResultsClzInt2Int2(Allocation inValue, Allocation out, boolean relaxed) {
1301         int[] arrayInValue = new int[INPUTSIZE * 2];
1302         Arrays.fill(arrayInValue, (int) 42);
1303         inValue.copyTo(arrayInValue);
1304         int[] arrayOut = new int[INPUTSIZE * 2];
1305         Arrays.fill(arrayOut, (int) 42);
1306         out.copyTo(arrayOut);
1307         StringBuilder message = new StringBuilder();
1308         boolean errorFound = false;
1309         for (int i = 0; i < INPUTSIZE; i++) {
1310             for (int j = 0; j < 2 ; j++) {
1311                 // Extract the inputs.
1312                 ArgumentsIntInt args = new ArgumentsIntInt();
1313                 args.inValue = arrayInValue[i * 2 + j];
1314                 // Figure out what the outputs should have been.
1315                 CoreMathVerifier.computeClz(args);
1316                 // Validate the outputs.
1317                 boolean valid = true;
1318                 if (args.out != arrayOut[i * 2 + j]) {
1319                     valid = false;
1320                 }
1321                 if (!valid) {
1322                     if (!errorFound) {
1323                         errorFound = true;
1324                         message.append("Input inValue: ");
1325                         appendVariableToMessage(message, args.inValue);
1326                         message.append("\n");
1327                         message.append("Expected output out: ");
1328                         appendVariableToMessage(message, args.out);
1329                         message.append("\n");
1330                         message.append("Actual   output out: ");
1331                         appendVariableToMessage(message, arrayOut[i * 2 + j]);
1332                         if (args.out != arrayOut[i * 2 + j]) {
1333                             message.append(" FAIL");
1334                         }
1335                         message.append("\n");
1336                         message.append("Errors at");
1337                     }
1338                     message.append(" [");
1339                     message.append(Integer.toString(i));
1340                     message.append(", ");
1341                     message.append(Integer.toString(j));
1342                     message.append("]");
1343                 }
1344             }
1345         }
1346         assertFalse("Incorrect output for checkClzInt2Int2" +
1347                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
1348     }
1349 
checkClzInt3Int3()1350     private void checkClzInt3Int3() {
1351         Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 3, 0xd6e2b014f2d24c2bl, false);
1352         try {
1353             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE);
1354             script.forEach_testClzInt3Int3(inValue, out);
1355             verifyResultsClzInt3Int3(inValue, out, false);
1356             out.destroy();
1357         } catch (Exception e) {
1358             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzInt3Int3: " + e.toString());
1359         }
1360         try {
1361             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE);
1362             scriptRelaxed.forEach_testClzInt3Int3(inValue, out);
1363             verifyResultsClzInt3Int3(inValue, out, true);
1364             out.destroy();
1365         } catch (Exception e) {
1366             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzInt3Int3: " + e.toString());
1367         }
1368         inValue.destroy();
1369     }
1370 
verifyResultsClzInt3Int3(Allocation inValue, Allocation out, boolean relaxed)1371     private void verifyResultsClzInt3Int3(Allocation inValue, Allocation out, boolean relaxed) {
1372         int[] arrayInValue = new int[INPUTSIZE * 4];
1373         Arrays.fill(arrayInValue, (int) 42);
1374         inValue.copyTo(arrayInValue);
1375         int[] arrayOut = new int[INPUTSIZE * 4];
1376         Arrays.fill(arrayOut, (int) 42);
1377         out.copyTo(arrayOut);
1378         StringBuilder message = new StringBuilder();
1379         boolean errorFound = false;
1380         for (int i = 0; i < INPUTSIZE; i++) {
1381             for (int j = 0; j < 3 ; j++) {
1382                 // Extract the inputs.
1383                 ArgumentsIntInt args = new ArgumentsIntInt();
1384                 args.inValue = arrayInValue[i * 4 + j];
1385                 // Figure out what the outputs should have been.
1386                 CoreMathVerifier.computeClz(args);
1387                 // Validate the outputs.
1388                 boolean valid = true;
1389                 if (args.out != arrayOut[i * 4 + j]) {
1390                     valid = false;
1391                 }
1392                 if (!valid) {
1393                     if (!errorFound) {
1394                         errorFound = true;
1395                         message.append("Input inValue: ");
1396                         appendVariableToMessage(message, args.inValue);
1397                         message.append("\n");
1398                         message.append("Expected output out: ");
1399                         appendVariableToMessage(message, args.out);
1400                         message.append("\n");
1401                         message.append("Actual   output out: ");
1402                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
1403                         if (args.out != arrayOut[i * 4 + j]) {
1404                             message.append(" FAIL");
1405                         }
1406                         message.append("\n");
1407                         message.append("Errors at");
1408                     }
1409                     message.append(" [");
1410                     message.append(Integer.toString(i));
1411                     message.append(", ");
1412                     message.append(Integer.toString(j));
1413                     message.append("]");
1414                 }
1415             }
1416         }
1417         assertFalse("Incorrect output for checkClzInt3Int3" +
1418                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
1419     }
1420 
checkClzInt4Int4()1421     private void checkClzInt4Int4() {
1422         Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 4, 0xe3c8340fbda65d81l, false);
1423         try {
1424             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE);
1425             script.forEach_testClzInt4Int4(inValue, out);
1426             verifyResultsClzInt4Int4(inValue, out, false);
1427             out.destroy();
1428         } catch (Exception e) {
1429             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzInt4Int4: " + e.toString());
1430         }
1431         try {
1432             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE);
1433             scriptRelaxed.forEach_testClzInt4Int4(inValue, out);
1434             verifyResultsClzInt4Int4(inValue, out, true);
1435             out.destroy();
1436         } catch (Exception e) {
1437             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzInt4Int4: " + e.toString());
1438         }
1439         inValue.destroy();
1440     }
1441 
verifyResultsClzInt4Int4(Allocation inValue, Allocation out, boolean relaxed)1442     private void verifyResultsClzInt4Int4(Allocation inValue, Allocation out, boolean relaxed) {
1443         int[] arrayInValue = new int[INPUTSIZE * 4];
1444         Arrays.fill(arrayInValue, (int) 42);
1445         inValue.copyTo(arrayInValue);
1446         int[] arrayOut = new int[INPUTSIZE * 4];
1447         Arrays.fill(arrayOut, (int) 42);
1448         out.copyTo(arrayOut);
1449         StringBuilder message = new StringBuilder();
1450         boolean errorFound = false;
1451         for (int i = 0; i < INPUTSIZE; i++) {
1452             for (int j = 0; j < 4 ; j++) {
1453                 // Extract the inputs.
1454                 ArgumentsIntInt args = new ArgumentsIntInt();
1455                 args.inValue = arrayInValue[i * 4 + j];
1456                 // Figure out what the outputs should have been.
1457                 CoreMathVerifier.computeClz(args);
1458                 // Validate the outputs.
1459                 boolean valid = true;
1460                 if (args.out != arrayOut[i * 4 + j]) {
1461                     valid = false;
1462                 }
1463                 if (!valid) {
1464                     if (!errorFound) {
1465                         errorFound = true;
1466                         message.append("Input inValue: ");
1467                         appendVariableToMessage(message, args.inValue);
1468                         message.append("\n");
1469                         message.append("Expected output out: ");
1470                         appendVariableToMessage(message, args.out);
1471                         message.append("\n");
1472                         message.append("Actual   output out: ");
1473                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
1474                         if (args.out != arrayOut[i * 4 + j]) {
1475                             message.append(" FAIL");
1476                         }
1477                         message.append("\n");
1478                         message.append("Errors at");
1479                     }
1480                     message.append(" [");
1481                     message.append(Integer.toString(i));
1482                     message.append(", ");
1483                     message.append(Integer.toString(j));
1484                     message.append("]");
1485                 }
1486             }
1487         }
1488         assertFalse("Incorrect output for checkClzInt4Int4" +
1489                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
1490     }
1491 
1492     public class ArgumentsUintUint {
1493         public int inValue;
1494         public int out;
1495     }
1496 
checkClzUintUint()1497     private void checkClzUintUint() {
1498         Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 1, 0x64a0b78a75ac502fl, false);
1499         try {
1500             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 1), INPUTSIZE);
1501             script.forEach_testClzUintUint(inValue, out);
1502             verifyResultsClzUintUint(inValue, out, false);
1503             out.destroy();
1504         } catch (Exception e) {
1505             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUintUint: " + e.toString());
1506         }
1507         try {
1508             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 1), INPUTSIZE);
1509             scriptRelaxed.forEach_testClzUintUint(inValue, out);
1510             verifyResultsClzUintUint(inValue, out, true);
1511             out.destroy();
1512         } catch (Exception e) {
1513             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUintUint: " + e.toString());
1514         }
1515         inValue.destroy();
1516     }
1517 
verifyResultsClzUintUint(Allocation inValue, Allocation out, boolean relaxed)1518     private void verifyResultsClzUintUint(Allocation inValue, Allocation out, boolean relaxed) {
1519         int[] arrayInValue = new int[INPUTSIZE * 1];
1520         Arrays.fill(arrayInValue, (int) 42);
1521         inValue.copyTo(arrayInValue);
1522         int[] arrayOut = new int[INPUTSIZE * 1];
1523         Arrays.fill(arrayOut, (int) 42);
1524         out.copyTo(arrayOut);
1525         StringBuilder message = new StringBuilder();
1526         boolean errorFound = false;
1527         for (int i = 0; i < INPUTSIZE; i++) {
1528             for (int j = 0; j < 1 ; j++) {
1529                 // Extract the inputs.
1530                 ArgumentsUintUint args = new ArgumentsUintUint();
1531                 args.inValue = arrayInValue[i];
1532                 // Figure out what the outputs should have been.
1533                 CoreMathVerifier.computeClz(args);
1534                 // Validate the outputs.
1535                 boolean valid = true;
1536                 if (args.out != arrayOut[i * 1 + j]) {
1537                     valid = false;
1538                 }
1539                 if (!valid) {
1540                     if (!errorFound) {
1541                         errorFound = true;
1542                         message.append("Input inValue: ");
1543                         appendVariableToMessage(message, args.inValue);
1544                         message.append("\n");
1545                         message.append("Expected output out: ");
1546                         appendVariableToMessage(message, args.out);
1547                         message.append("\n");
1548                         message.append("Actual   output out: ");
1549                         appendVariableToMessage(message, arrayOut[i * 1 + j]);
1550                         if (args.out != arrayOut[i * 1 + j]) {
1551                             message.append(" FAIL");
1552                         }
1553                         message.append("\n");
1554                         message.append("Errors at");
1555                     }
1556                     message.append(" [");
1557                     message.append(Integer.toString(i));
1558                     message.append(", ");
1559                     message.append(Integer.toString(j));
1560                     message.append("]");
1561                 }
1562             }
1563         }
1564         assertFalse("Incorrect output for checkClzUintUint" +
1565                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
1566     }
1567 
checkClzUint2Uint2()1568     private void checkClzUint2Uint2() {
1569         Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 2, 0xf809b50329344f93l, false);
1570         try {
1571             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE);
1572             script.forEach_testClzUint2Uint2(inValue, out);
1573             verifyResultsClzUint2Uint2(inValue, out, false);
1574             out.destroy();
1575         } catch (Exception e) {
1576             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUint2Uint2: " + e.toString());
1577         }
1578         try {
1579             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE);
1580             scriptRelaxed.forEach_testClzUint2Uint2(inValue, out);
1581             verifyResultsClzUint2Uint2(inValue, out, true);
1582             out.destroy();
1583         } catch (Exception e) {
1584             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUint2Uint2: " + e.toString());
1585         }
1586         inValue.destroy();
1587     }
1588 
verifyResultsClzUint2Uint2(Allocation inValue, Allocation out, boolean relaxed)1589     private void verifyResultsClzUint2Uint2(Allocation inValue, Allocation out, boolean relaxed) {
1590         int[] arrayInValue = new int[INPUTSIZE * 2];
1591         Arrays.fill(arrayInValue, (int) 42);
1592         inValue.copyTo(arrayInValue);
1593         int[] arrayOut = new int[INPUTSIZE * 2];
1594         Arrays.fill(arrayOut, (int) 42);
1595         out.copyTo(arrayOut);
1596         StringBuilder message = new StringBuilder();
1597         boolean errorFound = false;
1598         for (int i = 0; i < INPUTSIZE; i++) {
1599             for (int j = 0; j < 2 ; j++) {
1600                 // Extract the inputs.
1601                 ArgumentsUintUint args = new ArgumentsUintUint();
1602                 args.inValue = arrayInValue[i * 2 + j];
1603                 // Figure out what the outputs should have been.
1604                 CoreMathVerifier.computeClz(args);
1605                 // Validate the outputs.
1606                 boolean valid = true;
1607                 if (args.out != arrayOut[i * 2 + j]) {
1608                     valid = false;
1609                 }
1610                 if (!valid) {
1611                     if (!errorFound) {
1612                         errorFound = true;
1613                         message.append("Input inValue: ");
1614                         appendVariableToMessage(message, args.inValue);
1615                         message.append("\n");
1616                         message.append("Expected output out: ");
1617                         appendVariableToMessage(message, args.out);
1618                         message.append("\n");
1619                         message.append("Actual   output out: ");
1620                         appendVariableToMessage(message, arrayOut[i * 2 + j]);
1621                         if (args.out != arrayOut[i * 2 + j]) {
1622                             message.append(" FAIL");
1623                         }
1624                         message.append("\n");
1625                         message.append("Errors at");
1626                     }
1627                     message.append(" [");
1628                     message.append(Integer.toString(i));
1629                     message.append(", ");
1630                     message.append(Integer.toString(j));
1631                     message.append("]");
1632                 }
1633             }
1634         }
1635         assertFalse("Incorrect output for checkClzUint2Uint2" +
1636                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
1637     }
1638 
checkClzUint3Uint3()1639     private void checkClzUint3Uint3() {
1640         Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 3, 0x2296d5c125738447l, false);
1641         try {
1642             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE);
1643             script.forEach_testClzUint3Uint3(inValue, out);
1644             verifyResultsClzUint3Uint3(inValue, out, false);
1645             out.destroy();
1646         } catch (Exception e) {
1647             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUint3Uint3: " + e.toString());
1648         }
1649         try {
1650             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE);
1651             scriptRelaxed.forEach_testClzUint3Uint3(inValue, out);
1652             verifyResultsClzUint3Uint3(inValue, out, true);
1653             out.destroy();
1654         } catch (Exception e) {
1655             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUint3Uint3: " + e.toString());
1656         }
1657         inValue.destroy();
1658     }
1659 
verifyResultsClzUint3Uint3(Allocation inValue, Allocation out, boolean relaxed)1660     private void verifyResultsClzUint3Uint3(Allocation inValue, Allocation out, boolean relaxed) {
1661         int[] arrayInValue = new int[INPUTSIZE * 4];
1662         Arrays.fill(arrayInValue, (int) 42);
1663         inValue.copyTo(arrayInValue);
1664         int[] arrayOut = new int[INPUTSIZE * 4];
1665         Arrays.fill(arrayOut, (int) 42);
1666         out.copyTo(arrayOut);
1667         StringBuilder message = new StringBuilder();
1668         boolean errorFound = false;
1669         for (int i = 0; i < INPUTSIZE; i++) {
1670             for (int j = 0; j < 3 ; j++) {
1671                 // Extract the inputs.
1672                 ArgumentsUintUint args = new ArgumentsUintUint();
1673                 args.inValue = arrayInValue[i * 4 + j];
1674                 // Figure out what the outputs should have been.
1675                 CoreMathVerifier.computeClz(args);
1676                 // Validate the outputs.
1677                 boolean valid = true;
1678                 if (args.out != arrayOut[i * 4 + j]) {
1679                     valid = false;
1680                 }
1681                 if (!valid) {
1682                     if (!errorFound) {
1683                         errorFound = true;
1684                         message.append("Input inValue: ");
1685                         appendVariableToMessage(message, args.inValue);
1686                         message.append("\n");
1687                         message.append("Expected output out: ");
1688                         appendVariableToMessage(message, args.out);
1689                         message.append("\n");
1690                         message.append("Actual   output out: ");
1691                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
1692                         if (args.out != arrayOut[i * 4 + j]) {
1693                             message.append(" FAIL");
1694                         }
1695                         message.append("\n");
1696                         message.append("Errors at");
1697                     }
1698                     message.append(" [");
1699                     message.append(Integer.toString(i));
1700                     message.append(", ");
1701                     message.append(Integer.toString(j));
1702                     message.append("]");
1703                 }
1704             }
1705         }
1706         assertFalse("Incorrect output for checkClzUint3Uint3" +
1707                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
1708     }
1709 
checkClzUint4Uint4()1710     private void checkClzUint4Uint4() {
1711         Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 4, 0x4d23f67f21b2b8fbl, false);
1712         try {
1713             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE);
1714             script.forEach_testClzUint4Uint4(inValue, out);
1715             verifyResultsClzUint4Uint4(inValue, out, false);
1716             out.destroy();
1717         } catch (Exception e) {
1718             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUint4Uint4: " + e.toString());
1719         }
1720         try {
1721             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE);
1722             scriptRelaxed.forEach_testClzUint4Uint4(inValue, out);
1723             verifyResultsClzUint4Uint4(inValue, out, true);
1724             out.destroy();
1725         } catch (Exception e) {
1726             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUint4Uint4: " + e.toString());
1727         }
1728         inValue.destroy();
1729     }
1730 
verifyResultsClzUint4Uint4(Allocation inValue, Allocation out, boolean relaxed)1731     private void verifyResultsClzUint4Uint4(Allocation inValue, Allocation out, boolean relaxed) {
1732         int[] arrayInValue = new int[INPUTSIZE * 4];
1733         Arrays.fill(arrayInValue, (int) 42);
1734         inValue.copyTo(arrayInValue);
1735         int[] arrayOut = new int[INPUTSIZE * 4];
1736         Arrays.fill(arrayOut, (int) 42);
1737         out.copyTo(arrayOut);
1738         StringBuilder message = new StringBuilder();
1739         boolean errorFound = false;
1740         for (int i = 0; i < INPUTSIZE; i++) {
1741             for (int j = 0; j < 4 ; j++) {
1742                 // Extract the inputs.
1743                 ArgumentsUintUint args = new ArgumentsUintUint();
1744                 args.inValue = arrayInValue[i * 4 + j];
1745                 // Figure out what the outputs should have been.
1746                 CoreMathVerifier.computeClz(args);
1747                 // Validate the outputs.
1748                 boolean valid = true;
1749                 if (args.out != arrayOut[i * 4 + j]) {
1750                     valid = false;
1751                 }
1752                 if (!valid) {
1753                     if (!errorFound) {
1754                         errorFound = true;
1755                         message.append("Input inValue: ");
1756                         appendVariableToMessage(message, args.inValue);
1757                         message.append("\n");
1758                         message.append("Expected output out: ");
1759                         appendVariableToMessage(message, args.out);
1760                         message.append("\n");
1761                         message.append("Actual   output out: ");
1762                         appendVariableToMessage(message, arrayOut[i * 4 + j]);
1763                         if (args.out != arrayOut[i * 4 + j]) {
1764                             message.append(" FAIL");
1765                         }
1766                         message.append("\n");
1767                         message.append("Errors at");
1768                     }
1769                     message.append(" [");
1770                     message.append(Integer.toString(i));
1771                     message.append(", ");
1772                     message.append(Integer.toString(j));
1773                     message.append("]");
1774                 }
1775             }
1776         }
1777         assertFalse("Incorrect output for checkClzUint4Uint4" +
1778                 (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
1779     }
1780 
testClz()1781     public void testClz() {
1782         checkClzCharChar();
1783         checkClzChar2Char2();
1784         checkClzChar3Char3();
1785         checkClzChar4Char4();
1786         checkClzUcharUchar();
1787         checkClzUchar2Uchar2();
1788         checkClzUchar3Uchar3();
1789         checkClzUchar4Uchar4();
1790         checkClzShortShort();
1791         checkClzShort2Short2();
1792         checkClzShort3Short3();
1793         checkClzShort4Short4();
1794         checkClzUshortUshort();
1795         checkClzUshort2Ushort2();
1796         checkClzUshort3Ushort3();
1797         checkClzUshort4Ushort4();
1798         checkClzIntInt();
1799         checkClzInt2Int2();
1800         checkClzInt3Int3();
1801         checkClzInt4Int4();
1802         checkClzUintUint();
1803         checkClzUint2Uint2();
1804         checkClzUint3Uint3();
1805         checkClzUint4Uint4();
1806     }
1807 }
1808