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