blob: d2fe5dfe4f03da2a1f34df7843b6520b1fe2321c [file] [log] [blame]
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Don't edit this file! It is auto-generated by frameworks/rs/api/generate.sh.
package android.renderscript.cts;
import android.renderscript.Allocation;
import android.renderscript.RSRuntimeException;
import android.renderscript.Element;
import java.util.Arrays;
public class TestClz extends RSBaseCompute {
private ScriptC_TestClz script;
private ScriptC_TestClzRelaxed scriptRelaxed;
@Override
protected void setUp() throws Exception {
super.setUp();
script = new ScriptC_TestClz(mRS);
scriptRelaxed = new ScriptC_TestClzRelaxed(mRS);
}
public class ArgumentsCharChar {
public byte inValue;
public byte out;
}
private void checkClzCharChar() {
Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 1, 0x2f7765afl, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 1), INPUTSIZE);
script.forEach_testClzCharChar(inValue, out);
verifyResultsClzCharChar(inValue, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzCharChar: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 1), INPUTSIZE);
scriptRelaxed.forEach_testClzCharChar(inValue, out);
verifyResultsClzCharChar(inValue, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzCharChar: " + e.toString());
}
}
private void verifyResultsClzCharChar(Allocation inValue, Allocation out, boolean relaxed) {
byte[] arrayInValue = new byte[INPUTSIZE * 1];
Arrays.fill(arrayInValue, (byte) 42);
inValue.copyTo(arrayInValue);
byte[] arrayOut = new byte[INPUTSIZE * 1];
Arrays.fill(arrayOut, (byte) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 1 ; j++) {
// Extract the inputs.
ArgumentsCharChar args = new ArgumentsCharChar();
args.inValue = arrayInValue[i];
// Figure out what the outputs should have been.
CoreMathVerifier.computeClz(args);
// Validate the outputs.
boolean valid = true;
if (args.out != arrayOut[i * 1 + j]) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inValue: ");
appendVariableToMessage(message, args.inValue);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 1 + j]);
if (args.out != arrayOut[i * 1 + j]) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkClzCharChar" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkClzChar2Char2() {
Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 2, 0xcaca5e93l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 2), INPUTSIZE);
script.forEach_testClzChar2Char2(inValue, out);
verifyResultsClzChar2Char2(inValue, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzChar2Char2: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 2), INPUTSIZE);
scriptRelaxed.forEach_testClzChar2Char2(inValue, out);
verifyResultsClzChar2Char2(inValue, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzChar2Char2: " + e.toString());
}
}
private void verifyResultsClzChar2Char2(Allocation inValue, Allocation out, boolean relaxed) {
byte[] arrayInValue = new byte[INPUTSIZE * 2];
Arrays.fill(arrayInValue, (byte) 42);
inValue.copyTo(arrayInValue);
byte[] arrayOut = new byte[INPUTSIZE * 2];
Arrays.fill(arrayOut, (byte) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 2 ; j++) {
// Extract the inputs.
ArgumentsCharChar args = new ArgumentsCharChar();
args.inValue = arrayInValue[i * 2 + j];
// Figure out what the outputs should have been.
CoreMathVerifier.computeClz(args);
// Validate the outputs.
boolean valid = true;
if (args.out != arrayOut[i * 2 + j]) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inValue: ");
appendVariableToMessage(message, args.inValue);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 2 + j]);
if (args.out != arrayOut[i * 2 + j]) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkClzChar2Char2" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkClzChar3Char3() {
Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 3, 0xc7099347l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 3), INPUTSIZE);
script.forEach_testClzChar3Char3(inValue, out);
verifyResultsClzChar3Char3(inValue, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzChar3Char3: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 3), INPUTSIZE);
scriptRelaxed.forEach_testClzChar3Char3(inValue, out);
verifyResultsClzChar3Char3(inValue, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzChar3Char3: " + e.toString());
}
}
private void verifyResultsClzChar3Char3(Allocation inValue, Allocation out, boolean relaxed) {
byte[] arrayInValue = new byte[INPUTSIZE * 4];
Arrays.fill(arrayInValue, (byte) 42);
inValue.copyTo(arrayInValue);
byte[] arrayOut = new byte[INPUTSIZE * 4];
Arrays.fill(arrayOut, (byte) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 3 ; j++) {
// Extract the inputs.
ArgumentsCharChar args = new ArgumentsCharChar();
args.inValue = arrayInValue[i * 4 + j];
// Figure out what the outputs should have been.
CoreMathVerifier.computeClz(args);
// Validate the outputs.
boolean valid = true;
if (args.out != arrayOut[i * 4 + j]) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inValue: ");
appendVariableToMessage(message, args.inValue);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 4 + j]);
if (args.out != arrayOut[i * 4 + j]) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkClzChar3Char3" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkClzChar4Char4() {
Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_8, 4, 0xc348c7fbl, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 4), INPUTSIZE);
script.forEach_testClzChar4Char4(inValue, out);
verifyResultsClzChar4Char4(inValue, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzChar4Char4: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 4), INPUTSIZE);
scriptRelaxed.forEach_testClzChar4Char4(inValue, out);
verifyResultsClzChar4Char4(inValue, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzChar4Char4: " + e.toString());
}
}
private void verifyResultsClzChar4Char4(Allocation inValue, Allocation out, boolean relaxed) {
byte[] arrayInValue = new byte[INPUTSIZE * 4];
Arrays.fill(arrayInValue, (byte) 42);
inValue.copyTo(arrayInValue);
byte[] arrayOut = new byte[INPUTSIZE * 4];
Arrays.fill(arrayOut, (byte) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 4 ; j++) {
// Extract the inputs.
ArgumentsCharChar args = new ArgumentsCharChar();
args.inValue = arrayInValue[i * 4 + j];
// Figure out what the outputs should have been.
CoreMathVerifier.computeClz(args);
// Validate the outputs.
boolean valid = true;
if (args.out != arrayOut[i * 4 + j]) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inValue: ");
appendVariableToMessage(message, args.inValue);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 4 + j]);
if (args.out != arrayOut[i * 4 + j]) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkClzChar4Char4" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
public class ArgumentsUcharUchar {
public byte inValue;
public byte out;
}
private void checkClzUcharUchar() {
Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 1, 0x8b84f57fl, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 1), INPUTSIZE);
script.forEach_testClzUcharUchar(inValue, out);
verifyResultsClzUcharUchar(inValue, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUcharUchar: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 1), INPUTSIZE);
scriptRelaxed.forEach_testClzUcharUchar(inValue, out);
verifyResultsClzUcharUchar(inValue, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUcharUchar: " + e.toString());
}
}
private void verifyResultsClzUcharUchar(Allocation inValue, Allocation out, boolean relaxed) {
byte[] arrayInValue = new byte[INPUTSIZE * 1];
Arrays.fill(arrayInValue, (byte) 42);
inValue.copyTo(arrayInValue);
byte[] arrayOut = new byte[INPUTSIZE * 1];
Arrays.fill(arrayOut, (byte) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 1 ; j++) {
// Extract the inputs.
ArgumentsUcharUchar args = new ArgumentsUcharUchar();
args.inValue = arrayInValue[i];
// Figure out what the outputs should have been.
CoreMathVerifier.computeClz(args);
// Validate the outputs.
boolean valid = true;
if (args.out != arrayOut[i * 1 + j]) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inValue: ");
appendVariableToMessage(message, args.inValue);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 1 + j]);
if (args.out != arrayOut[i * 1 + j]) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkClzUcharUchar" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkClzUchar2Uchar2() {
Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 2, 0xf47ebc85l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE);
script.forEach_testClzUchar2Uchar2(inValue, out);
verifyResultsClzUchar2Uchar2(inValue, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUchar2Uchar2: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE);
scriptRelaxed.forEach_testClzUchar2Uchar2(inValue, out);
verifyResultsClzUchar2Uchar2(inValue, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUchar2Uchar2: " + e.toString());
}
}
private void verifyResultsClzUchar2Uchar2(Allocation inValue, Allocation out, boolean relaxed) {
byte[] arrayInValue = new byte[INPUTSIZE * 2];
Arrays.fill(arrayInValue, (byte) 42);
inValue.copyTo(arrayInValue);
byte[] arrayOut = new byte[INPUTSIZE * 2];
Arrays.fill(arrayOut, (byte) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 2 ; j++) {
// Extract the inputs.
ArgumentsUcharUchar args = new ArgumentsUcharUchar();
args.inValue = arrayInValue[i * 2 + j];
// Figure out what the outputs should have been.
CoreMathVerifier.computeClz(args);
// Validate the outputs.
boolean valid = true;
if (args.out != arrayOut[i * 2 + j]) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inValue: ");
appendVariableToMessage(message, args.inValue);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 2 + j]);
if (args.out != arrayOut[i * 2 + j]) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkClzUchar2Uchar2" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkClzUchar3Uchar3() {
Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 3, 0x3dbce203l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE);
script.forEach_testClzUchar3Uchar3(inValue, out);
verifyResultsClzUchar3Uchar3(inValue, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUchar3Uchar3: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE);
scriptRelaxed.forEach_testClzUchar3Uchar3(inValue, out);
verifyResultsClzUchar3Uchar3(inValue, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUchar3Uchar3: " + e.toString());
}
}
private void verifyResultsClzUchar3Uchar3(Allocation inValue, Allocation out, boolean relaxed) {
byte[] arrayInValue = new byte[INPUTSIZE * 4];
Arrays.fill(arrayInValue, (byte) 42);
inValue.copyTo(arrayInValue);
byte[] arrayOut = new byte[INPUTSIZE * 4];
Arrays.fill(arrayOut, (byte) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 3 ; j++) {
// Extract the inputs.
ArgumentsUcharUchar args = new ArgumentsUcharUchar();
args.inValue = arrayInValue[i * 4 + j];
// Figure out what the outputs should have been.
CoreMathVerifier.computeClz(args);
// Validate the outputs.
boolean valid = true;
if (args.out != arrayOut[i * 4 + j]) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inValue: ");
appendVariableToMessage(message, args.inValue);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 4 + j]);
if (args.out != arrayOut[i * 4 + j]) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkClzUchar3Uchar3" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkClzUchar4Uchar4() {
Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_8, 4, 0x86fb0781l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE);
script.forEach_testClzUchar4Uchar4(inValue, out);
verifyResultsClzUchar4Uchar4(inValue, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUchar4Uchar4: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE);
scriptRelaxed.forEach_testClzUchar4Uchar4(inValue, out);
verifyResultsClzUchar4Uchar4(inValue, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUchar4Uchar4: " + e.toString());
}
}
private void verifyResultsClzUchar4Uchar4(Allocation inValue, Allocation out, boolean relaxed) {
byte[] arrayInValue = new byte[INPUTSIZE * 4];
Arrays.fill(arrayInValue, (byte) 42);
inValue.copyTo(arrayInValue);
byte[] arrayOut = new byte[INPUTSIZE * 4];
Arrays.fill(arrayOut, (byte) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 4 ; j++) {
// Extract the inputs.
ArgumentsUcharUchar args = new ArgumentsUcharUchar();
args.inValue = arrayInValue[i * 4 + j];
// Figure out what the outputs should have been.
CoreMathVerifier.computeClz(args);
// Validate the outputs.
boolean valid = true;
if (args.out != arrayOut[i * 4 + j]) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inValue: ");
appendVariableToMessage(message, args.inValue);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 4 + j]);
if (args.out != arrayOut[i * 4 + j]) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkClzUchar4Uchar4" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
public class ArgumentsShortShort {
public short inValue;
public short out;
}
private void checkClzShortShort() {
Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 1, 0xd8ad53l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 1), INPUTSIZE);
script.forEach_testClzShortShort(inValue, out);
verifyResultsClzShortShort(inValue, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzShortShort: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 1), INPUTSIZE);
scriptRelaxed.forEach_testClzShortShort(inValue, out);
verifyResultsClzShortShort(inValue, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzShortShort: " + e.toString());
}
}
private void verifyResultsClzShortShort(Allocation inValue, Allocation out, boolean relaxed) {
short[] arrayInValue = new short[INPUTSIZE * 1];
Arrays.fill(arrayInValue, (short) 42);
inValue.copyTo(arrayInValue);
short[] arrayOut = new short[INPUTSIZE * 1];
Arrays.fill(arrayOut, (short) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 1 ; j++) {
// Extract the inputs.
ArgumentsShortShort args = new ArgumentsShortShort();
args.inValue = arrayInValue[i];
// Figure out what the outputs should have been.
CoreMathVerifier.computeClz(args);
// Validate the outputs.
boolean valid = true;
if (args.out != arrayOut[i * 1 + j]) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inValue: ");
appendVariableToMessage(message, args.inValue);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 1 + j]);
if (args.out != arrayOut[i * 1 + j]) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkClzShortShort" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkClzShort2Short2() {
Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 2, 0x42dd6ebfl, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 2), INPUTSIZE);
script.forEach_testClzShort2Short2(inValue, out);
verifyResultsClzShort2Short2(inValue, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzShort2Short2: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 2), INPUTSIZE);
scriptRelaxed.forEach_testClzShort2Short2(inValue, out);
verifyResultsClzShort2Short2(inValue, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzShort2Short2: " + e.toString());
}
}
private void verifyResultsClzShort2Short2(Allocation inValue, Allocation out, boolean relaxed) {
short[] arrayInValue = new short[INPUTSIZE * 2];
Arrays.fill(arrayInValue, (short) 42);
inValue.copyTo(arrayInValue);
short[] arrayOut = new short[INPUTSIZE * 2];
Arrays.fill(arrayOut, (short) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 2 ; j++) {
// Extract the inputs.
ArgumentsShortShort args = new ArgumentsShortShort();
args.inValue = arrayInValue[i * 2 + j];
// Figure out what the outputs should have been.
CoreMathVerifier.computeClz(args);
// Validate the outputs.
boolean valid = true;
if (args.out != arrayOut[i * 2 + j]) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inValue: ");
appendVariableToMessage(message, args.inValue);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 2 + j]);
if (args.out != arrayOut[i * 2 + j]) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkClzShort2Short2" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkClzShort3Short3() {
Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 3, 0x8c1b943dl, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 3), INPUTSIZE);
script.forEach_testClzShort3Short3(inValue, out);
verifyResultsClzShort3Short3(inValue, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzShort3Short3: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 3), INPUTSIZE);
scriptRelaxed.forEach_testClzShort3Short3(inValue, out);
verifyResultsClzShort3Short3(inValue, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzShort3Short3: " + e.toString());
}
}
private void verifyResultsClzShort3Short3(Allocation inValue, Allocation out, boolean relaxed) {
short[] arrayInValue = new short[INPUTSIZE * 4];
Arrays.fill(arrayInValue, (short) 42);
inValue.copyTo(arrayInValue);
short[] arrayOut = new short[INPUTSIZE * 4];
Arrays.fill(arrayOut, (short) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 3 ; j++) {
// Extract the inputs.
ArgumentsShortShort args = new ArgumentsShortShort();
args.inValue = arrayInValue[i * 4 + j];
// Figure out what the outputs should have been.
CoreMathVerifier.computeClz(args);
// Validate the outputs.
boolean valid = true;
if (args.out != arrayOut[i * 4 + j]) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inValue: ");
appendVariableToMessage(message, args.inValue);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 4 + j]);
if (args.out != arrayOut[i * 4 + j]) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkClzShort3Short3" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkClzShort4Short4() {
Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_16, 4, 0xd559b9bbl, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 4), INPUTSIZE);
script.forEach_testClzShort4Short4(inValue, out);
verifyResultsClzShort4Short4(inValue, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzShort4Short4: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 4), INPUTSIZE);
scriptRelaxed.forEach_testClzShort4Short4(inValue, out);
verifyResultsClzShort4Short4(inValue, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzShort4Short4: " + e.toString());
}
}
private void verifyResultsClzShort4Short4(Allocation inValue, Allocation out, boolean relaxed) {
short[] arrayInValue = new short[INPUTSIZE * 4];
Arrays.fill(arrayInValue, (short) 42);
inValue.copyTo(arrayInValue);
short[] arrayOut = new short[INPUTSIZE * 4];
Arrays.fill(arrayOut, (short) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 4 ; j++) {
// Extract the inputs.
ArgumentsShortShort args = new ArgumentsShortShort();
args.inValue = arrayInValue[i * 4 + j];
// Figure out what the outputs should have been.
CoreMathVerifier.computeClz(args);
// Validate the outputs.
boolean valid = true;
if (args.out != arrayOut[i * 4 + j]) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inValue: ");
appendVariableToMessage(message, args.inValue);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 4 + j]);
if (args.out != arrayOut[i * 4 + j]) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkClzShort4Short4" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
public class ArgumentsUshortUshort {
public short inValue;
public short out;
}
private void checkClzUshortUshort() {
Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 1, 0x2c0103a5l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 1), INPUTSIZE);
script.forEach_testClzUshortUshort(inValue, out);
verifyResultsClzUshortUshort(inValue, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUshortUshort: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 1), INPUTSIZE);
scriptRelaxed.forEach_testClzUshortUshort(inValue, out);
verifyResultsClzUshortUshort(inValue, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUshortUshort: " + e.toString());
}
}
private void verifyResultsClzUshortUshort(Allocation inValue, Allocation out, boolean relaxed) {
short[] arrayInValue = new short[INPUTSIZE * 1];
Arrays.fill(arrayInValue, (short) 42);
inValue.copyTo(arrayInValue);
short[] arrayOut = new short[INPUTSIZE * 1];
Arrays.fill(arrayOut, (short) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 1 ; j++) {
// Extract the inputs.
ArgumentsUshortUshort args = new ArgumentsUshortUshort();
args.inValue = arrayInValue[i];
// Figure out what the outputs should have been.
CoreMathVerifier.computeClz(args);
// Validate the outputs.
boolean valid = true;
if (args.out != arrayOut[i * 1 + j]) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inValue: ");
appendVariableToMessage(message, args.inValue);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 1 + j]);
if (args.out != arrayOut[i * 1 + j]) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkClzUshortUshort" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkClzUshort2Ushort2() {
Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 2, 0xb2913837l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE);
script.forEach_testClzUshort2Ushort2(inValue, out);
verifyResultsClzUshort2Ushort2(inValue, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUshort2Ushort2: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE);
scriptRelaxed.forEach_testClzUshort2Ushort2(inValue, out);
verifyResultsClzUshort2Ushort2(inValue, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUshort2Ushort2: " + e.toString());
}
}
private void verifyResultsClzUshort2Ushort2(Allocation inValue, Allocation out, boolean relaxed) {
short[] arrayInValue = new short[INPUTSIZE * 2];
Arrays.fill(arrayInValue, (short) 42);
inValue.copyTo(arrayInValue);
short[] arrayOut = new short[INPUTSIZE * 2];
Arrays.fill(arrayOut, (short) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 2 ; j++) {
// Extract the inputs.
ArgumentsUshortUshort args = new ArgumentsUshortUshort();
args.inValue = arrayInValue[i * 2 + j];
// Figure out what the outputs should have been.
CoreMathVerifier.computeClz(args);
// Validate the outputs.
boolean valid = true;
if (args.out != arrayOut[i * 2 + j]) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inValue: ");
appendVariableToMessage(message, args.inValue);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 2 + j]);
if (args.out != arrayOut[i * 2 + j]) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkClzUshort2Ushort2" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkClzUshort3Ushort3() {
Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 3, 0xeaa1cfa3l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE);
script.forEach_testClzUshort3Ushort3(inValue, out);
verifyResultsClzUshort3Ushort3(inValue, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUshort3Ushort3: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE);
scriptRelaxed.forEach_testClzUshort3Ushort3(inValue, out);
verifyResultsClzUshort3Ushort3(inValue, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUshort3Ushort3: " + e.toString());
}
}
private void verifyResultsClzUshort3Ushort3(Allocation inValue, Allocation out, boolean relaxed) {
short[] arrayInValue = new short[INPUTSIZE * 4];
Arrays.fill(arrayInValue, (short) 42);
inValue.copyTo(arrayInValue);
short[] arrayOut = new short[INPUTSIZE * 4];
Arrays.fill(arrayOut, (short) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 3 ; j++) {
// Extract the inputs.
ArgumentsUshortUshort args = new ArgumentsUshortUshort();
args.inValue = arrayInValue[i * 4 + j];
// Figure out what the outputs should have been.
CoreMathVerifier.computeClz(args);
// Validate the outputs.
boolean valid = true;
if (args.out != arrayOut[i * 4 + j]) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inValue: ");
appendVariableToMessage(message, args.inValue);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 4 + j]);
if (args.out != arrayOut[i * 4 + j]) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkClzUshort3Ushort3" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkClzUshort4Ushort4() {
Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_16, 4, 0x22b2670fl, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE);
script.forEach_testClzUshort4Ushort4(inValue, out);
verifyResultsClzUshort4Ushort4(inValue, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUshort4Ushort4: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE);
scriptRelaxed.forEach_testClzUshort4Ushort4(inValue, out);
verifyResultsClzUshort4Ushort4(inValue, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUshort4Ushort4: " + e.toString());
}
}
private void verifyResultsClzUshort4Ushort4(Allocation inValue, Allocation out, boolean relaxed) {
short[] arrayInValue = new short[INPUTSIZE * 4];
Arrays.fill(arrayInValue, (short) 42);
inValue.copyTo(arrayInValue);
short[] arrayOut = new short[INPUTSIZE * 4];
Arrays.fill(arrayOut, (short) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 4 ; j++) {
// Extract the inputs.
ArgumentsUshortUshort args = new ArgumentsUshortUshort();
args.inValue = arrayInValue[i * 4 + j];
// Figure out what the outputs should have been.
CoreMathVerifier.computeClz(args);
// Validate the outputs.
boolean valid = true;
if (args.out != arrayOut[i * 4 + j]) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inValue: ");
appendVariableToMessage(message, args.inValue);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 4 + j]);
if (args.out != arrayOut[i * 4 + j]) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkClzUshort4Ushort4" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
public class ArgumentsIntInt {
public int inValue;
public int out;
}
private void checkClzIntInt() {
Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 1, 0x3142eb97l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 1), INPUTSIZE);
script.forEach_testClzIntInt(inValue, out);
verifyResultsClzIntInt(inValue, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzIntInt: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 1), INPUTSIZE);
scriptRelaxed.forEach_testClzIntInt(inValue, out);
verifyResultsClzIntInt(inValue, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzIntInt: " + e.toString());
}
}
private void verifyResultsClzIntInt(Allocation inValue, Allocation out, boolean relaxed) {
int[] arrayInValue = new int[INPUTSIZE * 1];
Arrays.fill(arrayInValue, (int) 42);
inValue.copyTo(arrayInValue);
int[] arrayOut = new int[INPUTSIZE * 1];
Arrays.fill(arrayOut, (int) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 1 ; j++) {
// Extract the inputs.
ArgumentsIntInt args = new ArgumentsIntInt();
args.inValue = arrayInValue[i];
// Figure out what the outputs should have been.
CoreMathVerifier.computeClz(args);
// Validate the outputs.
boolean valid = true;
if (args.out != arrayOut[i * 1 + j]) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inValue: ");
appendVariableToMessage(message, args.inValue);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 1 + j]);
if (args.out != arrayOut[i * 1 + j]) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkClzIntInt" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkClzInt2Int2() {
Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 2, 0x27fe3ad5l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE);
script.forEach_testClzInt2Int2(inValue, out);
verifyResultsClzInt2Int2(inValue, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzInt2Int2: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE);
scriptRelaxed.forEach_testClzInt2Int2(inValue, out);
verifyResultsClzInt2Int2(inValue, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzInt2Int2: " + e.toString());
}
}
private void verifyResultsClzInt2Int2(Allocation inValue, Allocation out, boolean relaxed) {
int[] arrayInValue = new int[INPUTSIZE * 2];
Arrays.fill(arrayInValue, (int) 42);
inValue.copyTo(arrayInValue);
int[] arrayOut = new int[INPUTSIZE * 2];
Arrays.fill(arrayOut, (int) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 2 ; j++) {
// Extract the inputs.
ArgumentsIntInt args = new ArgumentsIntInt();
args.inValue = arrayInValue[i * 2 + j];
// Figure out what the outputs should have been.
CoreMathVerifier.computeClz(args);
// Validate the outputs.
boolean valid = true;
if (args.out != arrayOut[i * 2 + j]) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inValue: ");
appendVariableToMessage(message, args.inValue);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 2 + j]);
if (args.out != arrayOut[i * 2 + j]) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkClzInt2Int2" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkClzInt3Int3() {
Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 3, 0xf2d24c2bl, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE);
script.forEach_testClzInt3Int3(inValue, out);
verifyResultsClzInt3Int3(inValue, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzInt3Int3: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE);
scriptRelaxed.forEach_testClzInt3Int3(inValue, out);
verifyResultsClzInt3Int3(inValue, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzInt3Int3: " + e.toString());
}
}
private void verifyResultsClzInt3Int3(Allocation inValue, Allocation out, boolean relaxed) {
int[] arrayInValue = new int[INPUTSIZE * 4];
Arrays.fill(arrayInValue, (int) 42);
inValue.copyTo(arrayInValue);
int[] arrayOut = new int[INPUTSIZE * 4];
Arrays.fill(arrayOut, (int) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 3 ; j++) {
// Extract the inputs.
ArgumentsIntInt args = new ArgumentsIntInt();
args.inValue = arrayInValue[i * 4 + j];
// Figure out what the outputs should have been.
CoreMathVerifier.computeClz(args);
// Validate the outputs.
boolean valid = true;
if (args.out != arrayOut[i * 4 + j]) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inValue: ");
appendVariableToMessage(message, args.inValue);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 4 + j]);
if (args.out != arrayOut[i * 4 + j]) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkClzInt3Int3" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkClzInt4Int4() {
Allocation inValue = createRandomAllocation(mRS, Element.DataType.SIGNED_32, 4, 0xbda65d81l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE);
script.forEach_testClzInt4Int4(inValue, out);
verifyResultsClzInt4Int4(inValue, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzInt4Int4: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE);
scriptRelaxed.forEach_testClzInt4Int4(inValue, out);
verifyResultsClzInt4Int4(inValue, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzInt4Int4: " + e.toString());
}
}
private void verifyResultsClzInt4Int4(Allocation inValue, Allocation out, boolean relaxed) {
int[] arrayInValue = new int[INPUTSIZE * 4];
Arrays.fill(arrayInValue, (int) 42);
inValue.copyTo(arrayInValue);
int[] arrayOut = new int[INPUTSIZE * 4];
Arrays.fill(arrayOut, (int) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 4 ; j++) {
// Extract the inputs.
ArgumentsIntInt args = new ArgumentsIntInt();
args.inValue = arrayInValue[i * 4 + j];
// Figure out what the outputs should have been.
CoreMathVerifier.computeClz(args);
// Validate the outputs.
boolean valid = true;
if (args.out != arrayOut[i * 4 + j]) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inValue: ");
appendVariableToMessage(message, args.inValue);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 4 + j]);
if (args.out != arrayOut[i * 4 + j]) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkClzInt4Int4" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
public class ArgumentsUintUint {
public int inValue;
public int out;
}
private void checkClzUintUint() {
Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 1, 0x75ac502fl, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 1), INPUTSIZE);
script.forEach_testClzUintUint(inValue, out);
verifyResultsClzUintUint(inValue, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUintUint: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 1), INPUTSIZE);
scriptRelaxed.forEach_testClzUintUint(inValue, out);
verifyResultsClzUintUint(inValue, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUintUint: " + e.toString());
}
}
private void verifyResultsClzUintUint(Allocation inValue, Allocation out, boolean relaxed) {
int[] arrayInValue = new int[INPUTSIZE * 1];
Arrays.fill(arrayInValue, (int) 42);
inValue.copyTo(arrayInValue);
int[] arrayOut = new int[INPUTSIZE * 1];
Arrays.fill(arrayOut, (int) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 1 ; j++) {
// Extract the inputs.
ArgumentsUintUint args = new ArgumentsUintUint();
args.inValue = arrayInValue[i];
// Figure out what the outputs should have been.
CoreMathVerifier.computeClz(args);
// Validate the outputs.
boolean valid = true;
if (args.out != arrayOut[i * 1 + j]) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inValue: ");
appendVariableToMessage(message, args.inValue);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 1 + j]);
if (args.out != arrayOut[i * 1 + j]) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkClzUintUint" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkClzUint2Uint2() {
Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 2, 0x29344f93l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE);
script.forEach_testClzUint2Uint2(inValue, out);
verifyResultsClzUint2Uint2(inValue, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUint2Uint2: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE);
scriptRelaxed.forEach_testClzUint2Uint2(inValue, out);
verifyResultsClzUint2Uint2(inValue, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUint2Uint2: " + e.toString());
}
}
private void verifyResultsClzUint2Uint2(Allocation inValue, Allocation out, boolean relaxed) {
int[] arrayInValue = new int[INPUTSIZE * 2];
Arrays.fill(arrayInValue, (int) 42);
inValue.copyTo(arrayInValue);
int[] arrayOut = new int[INPUTSIZE * 2];
Arrays.fill(arrayOut, (int) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 2 ; j++) {
// Extract the inputs.
ArgumentsUintUint args = new ArgumentsUintUint();
args.inValue = arrayInValue[i * 2 + j];
// Figure out what the outputs should have been.
CoreMathVerifier.computeClz(args);
// Validate the outputs.
boolean valid = true;
if (args.out != arrayOut[i * 2 + j]) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inValue: ");
appendVariableToMessage(message, args.inValue);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 2 + j]);
if (args.out != arrayOut[i * 2 + j]) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkClzUint2Uint2" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkClzUint3Uint3() {
Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 3, 0x25738447l, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE);
script.forEach_testClzUint3Uint3(inValue, out);
verifyResultsClzUint3Uint3(inValue, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUint3Uint3: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE);
scriptRelaxed.forEach_testClzUint3Uint3(inValue, out);
verifyResultsClzUint3Uint3(inValue, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUint3Uint3: " + e.toString());
}
}
private void verifyResultsClzUint3Uint3(Allocation inValue, Allocation out, boolean relaxed) {
int[] arrayInValue = new int[INPUTSIZE * 4];
Arrays.fill(arrayInValue, (int) 42);
inValue.copyTo(arrayInValue);
int[] arrayOut = new int[INPUTSIZE * 4];
Arrays.fill(arrayOut, (int) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 3 ; j++) {
// Extract the inputs.
ArgumentsUintUint args = new ArgumentsUintUint();
args.inValue = arrayInValue[i * 4 + j];
// Figure out what the outputs should have been.
CoreMathVerifier.computeClz(args);
// Validate the outputs.
boolean valid = true;
if (args.out != arrayOut[i * 4 + j]) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inValue: ");
appendVariableToMessage(message, args.inValue);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 4 + j]);
if (args.out != arrayOut[i * 4 + j]) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkClzUint3Uint3" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
private void checkClzUint4Uint4() {
Allocation inValue = createRandomAllocation(mRS, Element.DataType.UNSIGNED_32, 4, 0x21b2b8fbl, false);
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE);
script.forEach_testClzUint4Uint4(inValue, out);
verifyResultsClzUint4Uint4(inValue, out, false);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUint4Uint4: " + e.toString());
}
try {
Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE);
scriptRelaxed.forEach_testClzUint4Uint4(inValue, out);
verifyResultsClzUint4Uint4(inValue, out, true);
} catch (Exception e) {
throw new RSRuntimeException("RenderScript. Can't invoke forEach_testClzUint4Uint4: " + e.toString());
}
}
private void verifyResultsClzUint4Uint4(Allocation inValue, Allocation out, boolean relaxed) {
int[] arrayInValue = new int[INPUTSIZE * 4];
Arrays.fill(arrayInValue, (int) 42);
inValue.copyTo(arrayInValue);
int[] arrayOut = new int[INPUTSIZE * 4];
Arrays.fill(arrayOut, (int) 42);
out.copyTo(arrayOut);
StringBuilder message = new StringBuilder();
boolean errorFound = false;
for (int i = 0; i < INPUTSIZE; i++) {
for (int j = 0; j < 4 ; j++) {
// Extract the inputs.
ArgumentsUintUint args = new ArgumentsUintUint();
args.inValue = arrayInValue[i * 4 + j];
// Figure out what the outputs should have been.
CoreMathVerifier.computeClz(args);
// Validate the outputs.
boolean valid = true;
if (args.out != arrayOut[i * 4 + j]) {
valid = false;
}
if (!valid) {
if (!errorFound) {
errorFound = true;
message.append("Input inValue: ");
appendVariableToMessage(message, args.inValue);
message.append("\n");
message.append("Expected output out: ");
appendVariableToMessage(message, args.out);
message.append("\n");
message.append("Actual output out: ");
appendVariableToMessage(message, arrayOut[i * 4 + j]);
if (args.out != arrayOut[i * 4 + j]) {
message.append(" FAIL");
}
message.append("\n");
message.append("Errors at");
}
message.append(" [");
message.append(Integer.toString(i));
message.append(", ");
message.append(Integer.toString(j));
message.append("]");
}
}
}
assertFalse("Incorrect output for checkClzUint4Uint4" +
(relaxed ? "_relaxed" : "") + ":\n" + message.toString(), errorFound);
}
public void testClz() {
checkClzCharChar();
checkClzChar2Char2();
checkClzChar3Char3();
checkClzChar4Char4();
checkClzUcharUchar();
checkClzUchar2Uchar2();
checkClzUchar3Uchar3();
checkClzUchar4Uchar4();
checkClzShortShort();
checkClzShort2Short2();
checkClzShort3Short3();
checkClzShort4Short4();
checkClzUshortUshort();
checkClzUshort2Ushort2();
checkClzUshort3Ushort3();
checkClzUshort4Ushort4();
checkClzIntInt();
checkClzInt2Int2();
checkClzInt3Int3();
checkClzInt4Int4();
checkClzUintUint();
checkClzUint2Uint2();
checkClzUint3Uint3();
checkClzUint4Uint4();
}
}