Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2014 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/gen_runtime.
     18 
     19 package android.renderscript.cts;
     20 
     21 import android.renderscript.Allocation;
     22 import android.renderscript.RSRuntimeException;
     23 import android.renderscript.Element;
     24 
     25 public class TestConvert extends RSBaseCompute {
     26 
     27     private ScriptC_TestConvert script;
     28     private ScriptC_TestConvertRelaxed scriptRelaxed;
     29 
     30     @Override
     31     protected void setUp() throws Exception {
     32         super.setUp();
     33         script = new ScriptC_TestConvert(mRS);
     34         scriptRelaxed = new ScriptC_TestConvertRelaxed(mRS);
     35     }
     36 
     37     public class ArgumentsFloatFloat {
     38         public float inV;
     39         public Target.Floaty out;
     40     }
     41 
     42     private void checkConvertFloat2Float2() {
     43         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xfb5215c44e1f6ac6l, -1.6163412428744576259e+38, 1.6163412428744576259e+38);
     44         try {
     45             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
     46             script.forEach_testConvertFloat2Float2Float2(inV, out);
     47             verifyResultsConvertFloat2Float2(inV, out, false);
     48         } catch (Exception e) {
     49             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat2Float2Float2: " + e.toString());
     50         }
     51         try {
     52             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
     53             scriptRelaxed.forEach_testConvertFloat2Float2Float2(inV, out);
     54             verifyResultsConvertFloat2Float2(inV, out, true);
     55         } catch (Exception e) {
     56             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat2Float2Float2: " + e.toString());
     57         }
     58     }
     59 
     60     private void verifyResultsConvertFloat2Float2(Allocation inV, Allocation out, boolean relaxed) {
     61         float[] arrayInV = new float[INPUTSIZE * 2];
     62         inV.copyTo(arrayInV);
     63         float[] arrayOut = new float[INPUTSIZE * 2];
     64         out.copyTo(arrayOut);
     65         for (int i = 0; i < INPUTSIZE; i++) {
     66             for (int j = 0; j < 2 ; j++) {
     67                 // Extract the inputs.
     68                 ArgumentsFloatFloat args = new ArgumentsFloatFloat();
     69                 args.inV = arrayInV[i * 2 + j];
     70                 // Figure out what the outputs should have been.
     71                 Target target = new Target(relaxed);
     72                 CoreMathVerifier.computeConvert(args, target);
     73                 // Validate the outputs.
     74                 boolean valid = true;
     75                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
     76                     valid = false;
     77                 }
     78                 if (!valid) {
     79                     StringBuilder message = new StringBuilder();
     80                     message.append("Input inV: ");
     81                     message.append(String.format("%14.8g {%8x} %15a",
     82                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
     83                     message.append("\n");
     84                     message.append("Expected output out: ");
     85                     message.append(args.out.toString());
     86                     message.append("\n");
     87                     message.append("Actual   output out: ");
     88                     message.append(String.format("%14.8g {%8x} %15a",
     89                             arrayOut[i * 2 + j], Float.floatToRawIntBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j]));
     90                     if (!args.out.couldBe(arrayOut[i * 2 + j])) {
     91                         message.append(" FAIL");
     92                     }
     93                     message.append("\n");
     94                     assertTrue("Incorrect output for checkConvertFloat2Float2" +
     95                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
     96                 }
     97             }
     98         }
     99     }
    100 
    101     private void checkConvertFloat3Float3() {
    102         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xfb53dedf443a8ba4l, -1.6163412428744576259e+38, 1.6163412428744576259e+38);
    103         try {
    104             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
    105             script.forEach_testConvertFloat3Float3Float3(inV, out);
    106             verifyResultsConvertFloat3Float3(inV, out, false);
    107         } catch (Exception e) {
    108             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat3Float3Float3: " + e.toString());
    109         }
    110         try {
    111             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
    112             scriptRelaxed.forEach_testConvertFloat3Float3Float3(inV, out);
    113             verifyResultsConvertFloat3Float3(inV, out, true);
    114         } catch (Exception e) {
    115             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat3Float3Float3: " + e.toString());
    116         }
    117     }
    118 
    119     private void verifyResultsConvertFloat3Float3(Allocation inV, Allocation out, boolean relaxed) {
    120         float[] arrayInV = new float[INPUTSIZE * 4];
    121         inV.copyTo(arrayInV);
    122         float[] arrayOut = new float[INPUTSIZE * 4];
    123         out.copyTo(arrayOut);
    124         for (int i = 0; i < INPUTSIZE; i++) {
    125             for (int j = 0; j < 3 ; j++) {
    126                 // Extract the inputs.
    127                 ArgumentsFloatFloat args = new ArgumentsFloatFloat();
    128                 args.inV = arrayInV[i * 4 + j];
    129                 // Figure out what the outputs should have been.
    130                 Target target = new Target(relaxed);
    131                 CoreMathVerifier.computeConvert(args, target);
    132                 // Validate the outputs.
    133                 boolean valid = true;
    134                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    135                     valid = false;
    136                 }
    137                 if (!valid) {
    138                     StringBuilder message = new StringBuilder();
    139                     message.append("Input inV: ");
    140                     message.append(String.format("%14.8g {%8x} %15a",
    141                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
    142                     message.append("\n");
    143                     message.append("Expected output out: ");
    144                     message.append(args.out.toString());
    145                     message.append("\n");
    146                     message.append("Actual   output out: ");
    147                     message.append(String.format("%14.8g {%8x} %15a",
    148                             arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
    149                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    150                         message.append(" FAIL");
    151                     }
    152                     message.append("\n");
    153                     assertTrue("Incorrect output for checkConvertFloat3Float3" +
    154                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    155                 }
    156             }
    157         }
    158     }
    159 
    160     private void checkConvertFloat4Float4() {
    161         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xfb55a7fa3a55ac82l, -1.6163412428744576259e+38, 1.6163412428744576259e+38);
    162         try {
    163             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    164             script.forEach_testConvertFloat4Float4Float4(inV, out);
    165             verifyResultsConvertFloat4Float4(inV, out, false);
    166         } catch (Exception e) {
    167             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat4Float4Float4: " + e.toString());
    168         }
    169         try {
    170             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    171             scriptRelaxed.forEach_testConvertFloat4Float4Float4(inV, out);
    172             verifyResultsConvertFloat4Float4(inV, out, true);
    173         } catch (Exception e) {
    174             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat4Float4Float4: " + e.toString());
    175         }
    176     }
    177 
    178     private void verifyResultsConvertFloat4Float4(Allocation inV, Allocation out, boolean relaxed) {
    179         float[] arrayInV = new float[INPUTSIZE * 4];
    180         inV.copyTo(arrayInV);
    181         float[] arrayOut = new float[INPUTSIZE * 4];
    182         out.copyTo(arrayOut);
    183         for (int i = 0; i < INPUTSIZE; i++) {
    184             for (int j = 0; j < 4 ; j++) {
    185                 // Extract the inputs.
    186                 ArgumentsFloatFloat args = new ArgumentsFloatFloat();
    187                 args.inV = arrayInV[i * 4 + j];
    188                 // Figure out what the outputs should have been.
    189                 Target target = new Target(relaxed);
    190                 CoreMathVerifier.computeConvert(args, target);
    191                 // Validate the outputs.
    192                 boolean valid = true;
    193                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    194                     valid = false;
    195                 }
    196                 if (!valid) {
    197                     StringBuilder message = new StringBuilder();
    198                     message.append("Input inV: ");
    199                     message.append(String.format("%14.8g {%8x} %15a",
    200                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
    201                     message.append("\n");
    202                     message.append("Expected output out: ");
    203                     message.append(args.out.toString());
    204                     message.append("\n");
    205                     message.append("Actual   output out: ");
    206                     message.append(String.format("%14.8g {%8x} %15a",
    207                             arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
    208                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    209                         message.append(" FAIL");
    210                     }
    211                     message.append("\n");
    212                     assertTrue("Incorrect output for checkConvertFloat4Float4" +
    213                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    214                 }
    215             }
    216         }
    217     }
    218 
    219     public class ArgumentsCharFloat {
    220         public byte inV;
    221         public Target.Floaty out;
    222     }
    223 
    224     private void checkConvertChar2Float2() {
    225         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_8, 2, 0x5861e2161f489286l, true, 7);
    226         try {
    227             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
    228             script.forEach_testConvertFloat2Char2Float2(inV, out);
    229             verifyResultsConvertChar2Float2(inV, out, false);
    230         } catch (Exception e) {
    231             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat2Char2Float2: " + e.toString());
    232         }
    233         try {
    234             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
    235             scriptRelaxed.forEach_testConvertFloat2Char2Float2(inV, out);
    236             verifyResultsConvertChar2Float2(inV, out, true);
    237         } catch (Exception e) {
    238             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat2Char2Float2: " + e.toString());
    239         }
    240     }
    241 
    242     private void verifyResultsConvertChar2Float2(Allocation inV, Allocation out, boolean relaxed) {
    243         byte[] arrayInV = new byte[INPUTSIZE * 2];
    244         inV.copyTo(arrayInV);
    245         float[] arrayOut = new float[INPUTSIZE * 2];
    246         out.copyTo(arrayOut);
    247         for (int i = 0; i < INPUTSIZE; i++) {
    248             for (int j = 0; j < 2 ; j++) {
    249                 // Extract the inputs.
    250                 ArgumentsCharFloat args = new ArgumentsCharFloat();
    251                 args.inV = arrayInV[i * 2 + j];
    252                 // Figure out what the outputs should have been.
    253                 Target target = new Target(relaxed);
    254                 CoreMathVerifier.computeConvert(args, target);
    255                 // Validate the outputs.
    256                 boolean valid = true;
    257                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
    258                     valid = false;
    259                 }
    260                 if (!valid) {
    261                     StringBuilder message = new StringBuilder();
    262                     message.append("Input inV: ");
    263                     message.append(String.format("%d", args.inV));
    264                     message.append("\n");
    265                     message.append("Expected output out: ");
    266                     message.append(args.out.toString());
    267                     message.append("\n");
    268                     message.append("Actual   output out: ");
    269                     message.append(String.format("%14.8g {%8x} %15a",
    270                             arrayOut[i * 2 + j], Float.floatToRawIntBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j]));
    271                     if (!args.out.couldBe(arrayOut[i * 2 + j])) {
    272                         message.append(" FAIL");
    273                     }
    274                     message.append("\n");
    275                     assertTrue("Incorrect output for checkConvertChar2Float2" +
    276                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    277                 }
    278             }
    279         }
    280     }
    281 
    282     private void checkConvertChar3Float3() {
    283         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_8, 3, 0x5863ab311563b364l, true, 7);
    284         try {
    285             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
    286             script.forEach_testConvertFloat3Char3Float3(inV, out);
    287             verifyResultsConvertChar3Float3(inV, out, false);
    288         } catch (Exception e) {
    289             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat3Char3Float3: " + e.toString());
    290         }
    291         try {
    292             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
    293             scriptRelaxed.forEach_testConvertFloat3Char3Float3(inV, out);
    294             verifyResultsConvertChar3Float3(inV, out, true);
    295         } catch (Exception e) {
    296             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat3Char3Float3: " + e.toString());
    297         }
    298     }
    299 
    300     private void verifyResultsConvertChar3Float3(Allocation inV, Allocation out, boolean relaxed) {
    301         byte[] arrayInV = new byte[INPUTSIZE * 4];
    302         inV.copyTo(arrayInV);
    303         float[] arrayOut = new float[INPUTSIZE * 4];
    304         out.copyTo(arrayOut);
    305         for (int i = 0; i < INPUTSIZE; i++) {
    306             for (int j = 0; j < 3 ; j++) {
    307                 // Extract the inputs.
    308                 ArgumentsCharFloat args = new ArgumentsCharFloat();
    309                 args.inV = arrayInV[i * 4 + j];
    310                 // Figure out what the outputs should have been.
    311                 Target target = new Target(relaxed);
    312                 CoreMathVerifier.computeConvert(args, target);
    313                 // Validate the outputs.
    314                 boolean valid = true;
    315                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    316                     valid = false;
    317                 }
    318                 if (!valid) {
    319                     StringBuilder message = new StringBuilder();
    320                     message.append("Input inV: ");
    321                     message.append(String.format("%d", args.inV));
    322                     message.append("\n");
    323                     message.append("Expected output out: ");
    324                     message.append(args.out.toString());
    325                     message.append("\n");
    326                     message.append("Actual   output out: ");
    327                     message.append(String.format("%14.8g {%8x} %15a",
    328                             arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
    329                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    330                         message.append(" FAIL");
    331                     }
    332                     message.append("\n");
    333                     assertTrue("Incorrect output for checkConvertChar3Float3" +
    334                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    335                 }
    336             }
    337         }
    338     }
    339 
    340     private void checkConvertChar4Float4() {
    341         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_8, 4, 0x5865744c0b7ed442l, true, 7);
    342         try {
    343             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    344             script.forEach_testConvertFloat4Char4Float4(inV, out);
    345             verifyResultsConvertChar4Float4(inV, out, false);
    346         } catch (Exception e) {
    347             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat4Char4Float4: " + e.toString());
    348         }
    349         try {
    350             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    351             scriptRelaxed.forEach_testConvertFloat4Char4Float4(inV, out);
    352             verifyResultsConvertChar4Float4(inV, out, true);
    353         } catch (Exception e) {
    354             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat4Char4Float4: " + e.toString());
    355         }
    356     }
    357 
    358     private void verifyResultsConvertChar4Float4(Allocation inV, Allocation out, boolean relaxed) {
    359         byte[] arrayInV = new byte[INPUTSIZE * 4];
    360         inV.copyTo(arrayInV);
    361         float[] arrayOut = new float[INPUTSIZE * 4];
    362         out.copyTo(arrayOut);
    363         for (int i = 0; i < INPUTSIZE; i++) {
    364             for (int j = 0; j < 4 ; j++) {
    365                 // Extract the inputs.
    366                 ArgumentsCharFloat args = new ArgumentsCharFloat();
    367                 args.inV = arrayInV[i * 4 + j];
    368                 // Figure out what the outputs should have been.
    369                 Target target = new Target(relaxed);
    370                 CoreMathVerifier.computeConvert(args, target);
    371                 // Validate the outputs.
    372                 boolean valid = true;
    373                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    374                     valid = false;
    375                 }
    376                 if (!valid) {
    377                     StringBuilder message = new StringBuilder();
    378                     message.append("Input inV: ");
    379                     message.append(String.format("%d", args.inV));
    380                     message.append("\n");
    381                     message.append("Expected output out: ");
    382                     message.append(args.out.toString());
    383                     message.append("\n");
    384                     message.append("Actual   output out: ");
    385                     message.append(String.format("%14.8g {%8x} %15a",
    386                             arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
    387                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    388                         message.append(" FAIL");
    389                     }
    390                     message.append("\n");
    391                     assertTrue("Incorrect output for checkConvertChar4Float4" +
    392                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    393                 }
    394             }
    395         }
    396     }
    397 
    398     public class ArgumentsUcharFloat {
    399         public byte inV;
    400         public Target.Floaty out;
    401     }
    402 
    403     private void checkConvertUchar2Float2() {
    404         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_8, 2, 0x7d30021dbb20ac31l, false, 8);
    405         try {
    406             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
    407             script.forEach_testConvertFloat2Uchar2Float2(inV, out);
    408             verifyResultsConvertUchar2Float2(inV, out, false);
    409         } catch (Exception e) {
    410             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat2Uchar2Float2: " + e.toString());
    411         }
    412         try {
    413             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
    414             scriptRelaxed.forEach_testConvertFloat2Uchar2Float2(inV, out);
    415             verifyResultsConvertUchar2Float2(inV, out, true);
    416         } catch (Exception e) {
    417             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat2Uchar2Float2: " + e.toString());
    418         }
    419     }
    420 
    421     private void verifyResultsConvertUchar2Float2(Allocation inV, Allocation out, boolean relaxed) {
    422         byte[] arrayInV = new byte[INPUTSIZE * 2];
    423         inV.copyTo(arrayInV);
    424         float[] arrayOut = new float[INPUTSIZE * 2];
    425         out.copyTo(arrayOut);
    426         for (int i = 0; i < INPUTSIZE; i++) {
    427             for (int j = 0; j < 2 ; j++) {
    428                 // Extract the inputs.
    429                 ArgumentsUcharFloat args = new ArgumentsUcharFloat();
    430                 args.inV = arrayInV[i * 2 + j];
    431                 // Figure out what the outputs should have been.
    432                 Target target = new Target(relaxed);
    433                 CoreMathVerifier.computeConvert(args, target);
    434                 // Validate the outputs.
    435                 boolean valid = true;
    436                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
    437                     valid = false;
    438                 }
    439                 if (!valid) {
    440                     StringBuilder message = new StringBuilder();
    441                     message.append("Input inV: ");
    442                     message.append(String.format("0x%x", args.inV));
    443                     message.append("\n");
    444                     message.append("Expected output out: ");
    445                     message.append(args.out.toString());
    446                     message.append("\n");
    447                     message.append("Actual   output out: ");
    448                     message.append(String.format("%14.8g {%8x} %15a",
    449                             arrayOut[i * 2 + j], Float.floatToRawIntBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j]));
    450                     if (!args.out.couldBe(arrayOut[i * 2 + j])) {
    451                         message.append(" FAIL");
    452                     }
    453                     message.append("\n");
    454                     assertTrue("Incorrect output for checkConvertUchar2Float2" +
    455                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    456                 }
    457             }
    458         }
    459     }
    460 
    461     private void checkConvertUchar3Float3() {
    462         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_8, 3, 0x7d31cb38b13bcd0fl, false, 8);
    463         try {
    464             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
    465             script.forEach_testConvertFloat3Uchar3Float3(inV, out);
    466             verifyResultsConvertUchar3Float3(inV, out, false);
    467         } catch (Exception e) {
    468             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat3Uchar3Float3: " + e.toString());
    469         }
    470         try {
    471             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
    472             scriptRelaxed.forEach_testConvertFloat3Uchar3Float3(inV, out);
    473             verifyResultsConvertUchar3Float3(inV, out, true);
    474         } catch (Exception e) {
    475             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat3Uchar3Float3: " + e.toString());
    476         }
    477     }
    478 
    479     private void verifyResultsConvertUchar3Float3(Allocation inV, Allocation out, boolean relaxed) {
    480         byte[] arrayInV = new byte[INPUTSIZE * 4];
    481         inV.copyTo(arrayInV);
    482         float[] arrayOut = new float[INPUTSIZE * 4];
    483         out.copyTo(arrayOut);
    484         for (int i = 0; i < INPUTSIZE; i++) {
    485             for (int j = 0; j < 3 ; j++) {
    486                 // Extract the inputs.
    487                 ArgumentsUcharFloat args = new ArgumentsUcharFloat();
    488                 args.inV = arrayInV[i * 4 + j];
    489                 // Figure out what the outputs should have been.
    490                 Target target = new Target(relaxed);
    491                 CoreMathVerifier.computeConvert(args, target);
    492                 // Validate the outputs.
    493                 boolean valid = true;
    494                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    495                     valid = false;
    496                 }
    497                 if (!valid) {
    498                     StringBuilder message = new StringBuilder();
    499                     message.append("Input inV: ");
    500                     message.append(String.format("0x%x", args.inV));
    501                     message.append("\n");
    502                     message.append("Expected output out: ");
    503                     message.append(args.out.toString());
    504                     message.append("\n");
    505                     message.append("Actual   output out: ");
    506                     message.append(String.format("%14.8g {%8x} %15a",
    507                             arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
    508                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    509                         message.append(" FAIL");
    510                     }
    511                     message.append("\n");
    512                     assertTrue("Incorrect output for checkConvertUchar3Float3" +
    513                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    514                 }
    515             }
    516         }
    517     }
    518 
    519     private void checkConvertUchar4Float4() {
    520         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_8, 4, 0x7d339453a756ededl, false, 8);
    521         try {
    522             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    523             script.forEach_testConvertFloat4Uchar4Float4(inV, out);
    524             verifyResultsConvertUchar4Float4(inV, out, false);
    525         } catch (Exception e) {
    526             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat4Uchar4Float4: " + e.toString());
    527         }
    528         try {
    529             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    530             scriptRelaxed.forEach_testConvertFloat4Uchar4Float4(inV, out);
    531             verifyResultsConvertUchar4Float4(inV, out, true);
    532         } catch (Exception e) {
    533             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat4Uchar4Float4: " + e.toString());
    534         }
    535     }
    536 
    537     private void verifyResultsConvertUchar4Float4(Allocation inV, Allocation out, boolean relaxed) {
    538         byte[] arrayInV = new byte[INPUTSIZE * 4];
    539         inV.copyTo(arrayInV);
    540         float[] arrayOut = new float[INPUTSIZE * 4];
    541         out.copyTo(arrayOut);
    542         for (int i = 0; i < INPUTSIZE; i++) {
    543             for (int j = 0; j < 4 ; j++) {
    544                 // Extract the inputs.
    545                 ArgumentsUcharFloat args = new ArgumentsUcharFloat();
    546                 args.inV = arrayInV[i * 4 + j];
    547                 // Figure out what the outputs should have been.
    548                 Target target = new Target(relaxed);
    549                 CoreMathVerifier.computeConvert(args, target);
    550                 // Validate the outputs.
    551                 boolean valid = true;
    552                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    553                     valid = false;
    554                 }
    555                 if (!valid) {
    556                     StringBuilder message = new StringBuilder();
    557                     message.append("Input inV: ");
    558                     message.append(String.format("0x%x", args.inV));
    559                     message.append("\n");
    560                     message.append("Expected output out: ");
    561                     message.append(args.out.toString());
    562                     message.append("\n");
    563                     message.append("Actual   output out: ");
    564                     message.append(String.format("%14.8g {%8x} %15a",
    565                             arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
    566                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    567                         message.append(" FAIL");
    568                     }
    569                     message.append("\n");
    570                     assertTrue("Incorrect output for checkConvertUchar4Float4" +
    571                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    572                 }
    573             }
    574         }
    575     }
    576 
    577     public class ArgumentsShortFloat {
    578         public short inV;
    579         public Target.Floaty out;
    580     }
    581 
    582     private void checkConvertShort2Float2() {
    583         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_16, 2, 0x94ca184eff219172l, true, 15);
    584         try {
    585             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
    586             script.forEach_testConvertFloat2Short2Float2(inV, out);
    587             verifyResultsConvertShort2Float2(inV, out, false);
    588         } catch (Exception e) {
    589             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat2Short2Float2: " + e.toString());
    590         }
    591         try {
    592             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
    593             scriptRelaxed.forEach_testConvertFloat2Short2Float2(inV, out);
    594             verifyResultsConvertShort2Float2(inV, out, true);
    595         } catch (Exception e) {
    596             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat2Short2Float2: " + e.toString());
    597         }
    598     }
    599 
    600     private void verifyResultsConvertShort2Float2(Allocation inV, Allocation out, boolean relaxed) {
    601         short[] arrayInV = new short[INPUTSIZE * 2];
    602         inV.copyTo(arrayInV);
    603         float[] arrayOut = new float[INPUTSIZE * 2];
    604         out.copyTo(arrayOut);
    605         for (int i = 0; i < INPUTSIZE; i++) {
    606             for (int j = 0; j < 2 ; j++) {
    607                 // Extract the inputs.
    608                 ArgumentsShortFloat args = new ArgumentsShortFloat();
    609                 args.inV = arrayInV[i * 2 + j];
    610                 // Figure out what the outputs should have been.
    611                 Target target = new Target(relaxed);
    612                 CoreMathVerifier.computeConvert(args, target);
    613                 // Validate the outputs.
    614                 boolean valid = true;
    615                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
    616                     valid = false;
    617                 }
    618                 if (!valid) {
    619                     StringBuilder message = new StringBuilder();
    620                     message.append("Input inV: ");
    621                     message.append(String.format("%d", args.inV));
    622                     message.append("\n");
    623                     message.append("Expected output out: ");
    624                     message.append(args.out.toString());
    625                     message.append("\n");
    626                     message.append("Actual   output out: ");
    627                     message.append(String.format("%14.8g {%8x} %15a",
    628                             arrayOut[i * 2 + j], Float.floatToRawIntBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j]));
    629                     if (!args.out.couldBe(arrayOut[i * 2 + j])) {
    630                         message.append(" FAIL");
    631                     }
    632                     message.append("\n");
    633                     assertTrue("Incorrect output for checkConvertShort2Float2" +
    634                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    635                 }
    636             }
    637         }
    638     }
    639 
    640     private void checkConvertShort3Float3() {
    641         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_16, 3, 0x94cbe169f53cb250l, true, 15);
    642         try {
    643             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
    644             script.forEach_testConvertFloat3Short3Float3(inV, out);
    645             verifyResultsConvertShort3Float3(inV, out, false);
    646         } catch (Exception e) {
    647             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat3Short3Float3: " + e.toString());
    648         }
    649         try {
    650             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
    651             scriptRelaxed.forEach_testConvertFloat3Short3Float3(inV, out);
    652             verifyResultsConvertShort3Float3(inV, out, true);
    653         } catch (Exception e) {
    654             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat3Short3Float3: " + e.toString());
    655         }
    656     }
    657 
    658     private void verifyResultsConvertShort3Float3(Allocation inV, Allocation out, boolean relaxed) {
    659         short[] arrayInV = new short[INPUTSIZE * 4];
    660         inV.copyTo(arrayInV);
    661         float[] arrayOut = new float[INPUTSIZE * 4];
    662         out.copyTo(arrayOut);
    663         for (int i = 0; i < INPUTSIZE; i++) {
    664             for (int j = 0; j < 3 ; j++) {
    665                 // Extract the inputs.
    666                 ArgumentsShortFloat args = new ArgumentsShortFloat();
    667                 args.inV = arrayInV[i * 4 + j];
    668                 // Figure out what the outputs should have been.
    669                 Target target = new Target(relaxed);
    670                 CoreMathVerifier.computeConvert(args, target);
    671                 // Validate the outputs.
    672                 boolean valid = true;
    673                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    674                     valid = false;
    675                 }
    676                 if (!valid) {
    677                     StringBuilder message = new StringBuilder();
    678                     message.append("Input inV: ");
    679                     message.append(String.format("%d", args.inV));
    680                     message.append("\n");
    681                     message.append("Expected output out: ");
    682                     message.append(args.out.toString());
    683                     message.append("\n");
    684                     message.append("Actual   output out: ");
    685                     message.append(String.format("%14.8g {%8x} %15a",
    686                             arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
    687                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    688                         message.append(" FAIL");
    689                     }
    690                     message.append("\n");
    691                     assertTrue("Incorrect output for checkConvertShort3Float3" +
    692                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    693                 }
    694             }
    695         }
    696     }
    697 
    698     private void checkConvertShort4Float4() {
    699         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_16, 4, 0x94cdaa84eb57d32el, true, 15);
    700         try {
    701             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    702             script.forEach_testConvertFloat4Short4Float4(inV, out);
    703             verifyResultsConvertShort4Float4(inV, out, false);
    704         } catch (Exception e) {
    705             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat4Short4Float4: " + e.toString());
    706         }
    707         try {
    708             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    709             scriptRelaxed.forEach_testConvertFloat4Short4Float4(inV, out);
    710             verifyResultsConvertShort4Float4(inV, out, true);
    711         } catch (Exception e) {
    712             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat4Short4Float4: " + e.toString());
    713         }
    714     }
    715 
    716     private void verifyResultsConvertShort4Float4(Allocation inV, Allocation out, boolean relaxed) {
    717         short[] arrayInV = new short[INPUTSIZE * 4];
    718         inV.copyTo(arrayInV);
    719         float[] arrayOut = new float[INPUTSIZE * 4];
    720         out.copyTo(arrayOut);
    721         for (int i = 0; i < INPUTSIZE; i++) {
    722             for (int j = 0; j < 4 ; j++) {
    723                 // Extract the inputs.
    724                 ArgumentsShortFloat args = new ArgumentsShortFloat();
    725                 args.inV = arrayInV[i * 4 + j];
    726                 // Figure out what the outputs should have been.
    727                 Target target = new Target(relaxed);
    728                 CoreMathVerifier.computeConvert(args, target);
    729                 // Validate the outputs.
    730                 boolean valid = true;
    731                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    732                     valid = false;
    733                 }
    734                 if (!valid) {
    735                     StringBuilder message = new StringBuilder();
    736                     message.append("Input inV: ");
    737                     message.append(String.format("%d", args.inV));
    738                     message.append("\n");
    739                     message.append("Expected output out: ");
    740                     message.append(args.out.toString());
    741                     message.append("\n");
    742                     message.append("Actual   output out: ");
    743                     message.append(String.format("%14.8g {%8x} %15a",
    744                             arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
    745                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    746                         message.append(" FAIL");
    747                     }
    748                     message.append("\n");
    749                     assertTrue("Incorrect output for checkConvertShort4Float4" +
    750                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    751                 }
    752             }
    753         }
    754     }
    755 
    756     public class ArgumentsUshortFloat {
    757         public short inV;
    758         public Target.Floaty out;
    759     }
    760 
    761     private void checkConvertUshort2Float2() {
    762         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_16, 2, 0xc36979962c6de12bl, false, 16);
    763         try {
    764             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
    765             script.forEach_testConvertFloat2Ushort2Float2(inV, out);
    766             verifyResultsConvertUshort2Float2(inV, out, false);
    767         } catch (Exception e) {
    768             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat2Ushort2Float2: " + e.toString());
    769         }
    770         try {
    771             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
    772             scriptRelaxed.forEach_testConvertFloat2Ushort2Float2(inV, out);
    773             verifyResultsConvertUshort2Float2(inV, out, true);
    774         } catch (Exception e) {
    775             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat2Ushort2Float2: " + e.toString());
    776         }
    777     }
    778 
    779     private void verifyResultsConvertUshort2Float2(Allocation inV, Allocation out, boolean relaxed) {
    780         short[] arrayInV = new short[INPUTSIZE * 2];
    781         inV.copyTo(arrayInV);
    782         float[] arrayOut = new float[INPUTSIZE * 2];
    783         out.copyTo(arrayOut);
    784         for (int i = 0; i < INPUTSIZE; i++) {
    785             for (int j = 0; j < 2 ; j++) {
    786                 // Extract the inputs.
    787                 ArgumentsUshortFloat args = new ArgumentsUshortFloat();
    788                 args.inV = arrayInV[i * 2 + j];
    789                 // Figure out what the outputs should have been.
    790                 Target target = new Target(relaxed);
    791                 CoreMathVerifier.computeConvert(args, target);
    792                 // Validate the outputs.
    793                 boolean valid = true;
    794                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
    795                     valid = false;
    796                 }
    797                 if (!valid) {
    798                     StringBuilder message = new StringBuilder();
    799                     message.append("Input inV: ");
    800                     message.append(String.format("0x%x", args.inV));
    801                     message.append("\n");
    802                     message.append("Expected output out: ");
    803                     message.append(args.out.toString());
    804                     message.append("\n");
    805                     message.append("Actual   output out: ");
    806                     message.append(String.format("%14.8g {%8x} %15a",
    807                             arrayOut[i * 2 + j], Float.floatToRawIntBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j]));
    808                     if (!args.out.couldBe(arrayOut[i * 2 + j])) {
    809                         message.append(" FAIL");
    810                     }
    811                     message.append("\n");
    812                     assertTrue("Incorrect output for checkConvertUshort2Float2" +
    813                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    814                 }
    815             }
    816         }
    817     }
    818 
    819     private void checkConvertUshort3Float3() {
    820         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_16, 3, 0xc36b42b122890209l, false, 16);
    821         try {
    822             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
    823             script.forEach_testConvertFloat3Ushort3Float3(inV, out);
    824             verifyResultsConvertUshort3Float3(inV, out, false);
    825         } catch (Exception e) {
    826             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat3Ushort3Float3: " + e.toString());
    827         }
    828         try {
    829             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
    830             scriptRelaxed.forEach_testConvertFloat3Ushort3Float3(inV, out);
    831             verifyResultsConvertUshort3Float3(inV, out, true);
    832         } catch (Exception e) {
    833             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat3Ushort3Float3: " + e.toString());
    834         }
    835     }
    836 
    837     private void verifyResultsConvertUshort3Float3(Allocation inV, Allocation out, boolean relaxed) {
    838         short[] arrayInV = new short[INPUTSIZE * 4];
    839         inV.copyTo(arrayInV);
    840         float[] arrayOut = new float[INPUTSIZE * 4];
    841         out.copyTo(arrayOut);
    842         for (int i = 0; i < INPUTSIZE; i++) {
    843             for (int j = 0; j < 3 ; j++) {
    844                 // Extract the inputs.
    845                 ArgumentsUshortFloat args = new ArgumentsUshortFloat();
    846                 args.inV = arrayInV[i * 4 + j];
    847                 // Figure out what the outputs should have been.
    848                 Target target = new Target(relaxed);
    849                 CoreMathVerifier.computeConvert(args, target);
    850                 // Validate the outputs.
    851                 boolean valid = true;
    852                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    853                     valid = false;
    854                 }
    855                 if (!valid) {
    856                     StringBuilder message = new StringBuilder();
    857                     message.append("Input inV: ");
    858                     message.append(String.format("0x%x", args.inV));
    859                     message.append("\n");
    860                     message.append("Expected output out: ");
    861                     message.append(args.out.toString());
    862                     message.append("\n");
    863                     message.append("Actual   output out: ");
    864                     message.append(String.format("%14.8g {%8x} %15a",
    865                             arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
    866                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    867                         message.append(" FAIL");
    868                     }
    869                     message.append("\n");
    870                     assertTrue("Incorrect output for checkConvertUshort3Float3" +
    871                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    872                 }
    873             }
    874         }
    875     }
    876 
    877     private void checkConvertUshort4Float4() {
    878         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_16, 4, 0xc36d0bcc18a422e7l, false, 16);
    879         try {
    880             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    881             script.forEach_testConvertFloat4Ushort4Float4(inV, out);
    882             verifyResultsConvertUshort4Float4(inV, out, false);
    883         } catch (Exception e) {
    884             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat4Ushort4Float4: " + e.toString());
    885         }
    886         try {
    887             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
    888             scriptRelaxed.forEach_testConvertFloat4Ushort4Float4(inV, out);
    889             verifyResultsConvertUshort4Float4(inV, out, true);
    890         } catch (Exception e) {
    891             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat4Ushort4Float4: " + e.toString());
    892         }
    893     }
    894 
    895     private void verifyResultsConvertUshort4Float4(Allocation inV, Allocation out, boolean relaxed) {
    896         short[] arrayInV = new short[INPUTSIZE * 4];
    897         inV.copyTo(arrayInV);
    898         float[] arrayOut = new float[INPUTSIZE * 4];
    899         out.copyTo(arrayOut);
    900         for (int i = 0; i < INPUTSIZE; i++) {
    901             for (int j = 0; j < 4 ; j++) {
    902                 // Extract the inputs.
    903                 ArgumentsUshortFloat args = new ArgumentsUshortFloat();
    904                 args.inV = arrayInV[i * 4 + j];
    905                 // Figure out what the outputs should have been.
    906                 Target target = new Target(relaxed);
    907                 CoreMathVerifier.computeConvert(args, target);
    908                 // Validate the outputs.
    909                 boolean valid = true;
    910                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    911                     valid = false;
    912                 }
    913                 if (!valid) {
    914                     StringBuilder message = new StringBuilder();
    915                     message.append("Input inV: ");
    916                     message.append(String.format("0x%x", args.inV));
    917                     message.append("\n");
    918                     message.append("Expected output out: ");
    919                     message.append(args.out.toString());
    920                     message.append("\n");
    921                     message.append("Actual   output out: ");
    922                     message.append(String.format("%14.8g {%8x} %15a",
    923                             arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
    924                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
    925                         message.append(" FAIL");
    926                     }
    927                     message.append("\n");
    928                     assertTrue("Incorrect output for checkConvertUshort4Float4" +
    929                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    930                 }
    931             }
    932         }
    933     }
    934 
    935     public class ArgumentsIntFloat {
    936         public int inV;
    937         public Target.Floaty out;
    938     }
    939 
    940     private void checkConvertInt2Float2() {
    941         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_32, 2, 0x2a52c7eb7402bfc5l, true, 31);
    942         try {
    943             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
    944             script.forEach_testConvertFloat2Int2Float2(inV, out);
    945             verifyResultsConvertInt2Float2(inV, out, false);
    946         } catch (Exception e) {
    947             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat2Int2Float2: " + e.toString());
    948         }
    949         try {
    950             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
    951             scriptRelaxed.forEach_testConvertFloat2Int2Float2(inV, out);
    952             verifyResultsConvertInt2Float2(inV, out, true);
    953         } catch (Exception e) {
    954             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat2Int2Float2: " + e.toString());
    955         }
    956     }
    957 
    958     private void verifyResultsConvertInt2Float2(Allocation inV, Allocation out, boolean relaxed) {
    959         int[] arrayInV = new int[INPUTSIZE * 2];
    960         inV.copyTo(arrayInV);
    961         float[] arrayOut = new float[INPUTSIZE * 2];
    962         out.copyTo(arrayOut);
    963         for (int i = 0; i < INPUTSIZE; i++) {
    964             for (int j = 0; j < 2 ; j++) {
    965                 // Extract the inputs.
    966                 ArgumentsIntFloat args = new ArgumentsIntFloat();
    967                 args.inV = arrayInV[i * 2 + j];
    968                 // Figure out what the outputs should have been.
    969                 Target target = new Target(relaxed);
    970                 CoreMathVerifier.computeConvert(args, target);
    971                 // Validate the outputs.
    972                 boolean valid = true;
    973                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
    974                     valid = false;
    975                 }
    976                 if (!valid) {
    977                     StringBuilder message = new StringBuilder();
    978                     message.append("Input inV: ");
    979                     message.append(String.format("%d", args.inV));
    980                     message.append("\n");
    981                     message.append("Expected output out: ");
    982                     message.append(args.out.toString());
    983                     message.append("\n");
    984                     message.append("Actual   output out: ");
    985                     message.append(String.format("%14.8g {%8x} %15a",
    986                             arrayOut[i * 2 + j], Float.floatToRawIntBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j]));
    987                     if (!args.out.couldBe(arrayOut[i * 2 + j])) {
    988                         message.append(" FAIL");
    989                     }
    990                     message.append("\n");
    991                     assertTrue("Incorrect output for checkConvertInt2Float2" +
    992                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
    993                 }
    994             }
    995         }
    996     }
    997 
    998     private void checkConvertInt3Float3() {
    999         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_32, 3, 0x2a5491066a1de0a3l, true, 31);
   1000         try {
   1001             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
   1002             script.forEach_testConvertFloat3Int3Float3(inV, out);
   1003             verifyResultsConvertInt3Float3(inV, out, false);
   1004         } catch (Exception e) {
   1005             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat3Int3Float3: " + e.toString());
   1006         }
   1007         try {
   1008             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
   1009             scriptRelaxed.forEach_testConvertFloat3Int3Float3(inV, out);
   1010             verifyResultsConvertInt3Float3(inV, out, true);
   1011         } catch (Exception e) {
   1012             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat3Int3Float3: " + e.toString());
   1013         }
   1014     }
   1015 
   1016     private void verifyResultsConvertInt3Float3(Allocation inV, Allocation out, boolean relaxed) {
   1017         int[] arrayInV = new int[INPUTSIZE * 4];
   1018         inV.copyTo(arrayInV);
   1019         float[] arrayOut = new float[INPUTSIZE * 4];
   1020         out.copyTo(arrayOut);
   1021         for (int i = 0; i < INPUTSIZE; i++) {
   1022             for (int j = 0; j < 3 ; j++) {
   1023                 // Extract the inputs.
   1024                 ArgumentsIntFloat args = new ArgumentsIntFloat();
   1025                 args.inV = arrayInV[i * 4 + j];
   1026                 // Figure out what the outputs should have been.
   1027                 Target target = new Target(relaxed);
   1028                 CoreMathVerifier.computeConvert(args, target);
   1029                 // Validate the outputs.
   1030                 boolean valid = true;
   1031                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   1032                     valid = false;
   1033                 }
   1034                 if (!valid) {
   1035                     StringBuilder message = new StringBuilder();
   1036                     message.append("Input inV: ");
   1037                     message.append(String.format("%d", args.inV));
   1038                     message.append("\n");
   1039                     message.append("Expected output out: ");
   1040                     message.append(args.out.toString());
   1041                     message.append("\n");
   1042                     message.append("Actual   output out: ");
   1043                     message.append(String.format("%14.8g {%8x} %15a",
   1044                             arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
   1045                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   1046                         message.append(" FAIL");
   1047                     }
   1048                     message.append("\n");
   1049                     assertTrue("Incorrect output for checkConvertInt3Float3" +
   1050                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   1051                 }
   1052             }
   1053         }
   1054     }
   1055 
   1056     private void checkConvertInt4Float4() {
   1057         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_32, 4, 0x2a565a2160390181l, true, 31);
   1058         try {
   1059             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
   1060             script.forEach_testConvertFloat4Int4Float4(inV, out);
   1061             verifyResultsConvertInt4Float4(inV, out, false);
   1062         } catch (Exception e) {
   1063             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat4Int4Float4: " + e.toString());
   1064         }
   1065         try {
   1066             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
   1067             scriptRelaxed.forEach_testConvertFloat4Int4Float4(inV, out);
   1068             verifyResultsConvertInt4Float4(inV, out, true);
   1069         } catch (Exception e) {
   1070             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat4Int4Float4: " + e.toString());
   1071         }
   1072     }
   1073 
   1074     private void verifyResultsConvertInt4Float4(Allocation inV, Allocation out, boolean relaxed) {
   1075         int[] arrayInV = new int[INPUTSIZE * 4];
   1076         inV.copyTo(arrayInV);
   1077         float[] arrayOut = new float[INPUTSIZE * 4];
   1078         out.copyTo(arrayOut);
   1079         for (int i = 0; i < INPUTSIZE; i++) {
   1080             for (int j = 0; j < 4 ; j++) {
   1081                 // Extract the inputs.
   1082                 ArgumentsIntFloat args = new ArgumentsIntFloat();
   1083                 args.inV = arrayInV[i * 4 + j];
   1084                 // Figure out what the outputs should have been.
   1085                 Target target = new Target(relaxed);
   1086                 CoreMathVerifier.computeConvert(args, target);
   1087                 // Validate the outputs.
   1088                 boolean valid = true;
   1089                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   1090                     valid = false;
   1091                 }
   1092                 if (!valid) {
   1093                     StringBuilder message = new StringBuilder();
   1094                     message.append("Input inV: ");
   1095                     message.append(String.format("%d", args.inV));
   1096                     message.append("\n");
   1097                     message.append("Expected output out: ");
   1098                     message.append(args.out.toString());
   1099                     message.append("\n");
   1100                     message.append("Actual   output out: ");
   1101                     message.append(String.format("%14.8g {%8x} %15a",
   1102                             arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
   1103                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   1104                         message.append(" FAIL");
   1105                     }
   1106                     message.append("\n");
   1107                     assertTrue("Incorrect output for checkConvertInt4Float4" +
   1108                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   1109                 }
   1110             }
   1111         }
   1112     }
   1113 
   1114     public class ArgumentsUintFloat {
   1115         public int inV;
   1116         public Target.Floaty out;
   1117     }
   1118 
   1119     private void checkConvertUint2Float2() {
   1120         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_32, 2, 0xd1e081390684cc46l, false, 32);
   1121         try {
   1122             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
   1123             script.forEach_testConvertFloat2Uint2Float2(inV, out);
   1124             verifyResultsConvertUint2Float2(inV, out, false);
   1125         } catch (Exception e) {
   1126             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat2Uint2Float2: " + e.toString());
   1127         }
   1128         try {
   1129             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
   1130             scriptRelaxed.forEach_testConvertFloat2Uint2Float2(inV, out);
   1131             verifyResultsConvertUint2Float2(inV, out, true);
   1132         } catch (Exception e) {
   1133             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat2Uint2Float2: " + e.toString());
   1134         }
   1135     }
   1136 
   1137     private void verifyResultsConvertUint2Float2(Allocation inV, Allocation out, boolean relaxed) {
   1138         int[] arrayInV = new int[INPUTSIZE * 2];
   1139         inV.copyTo(arrayInV);
   1140         float[] arrayOut = new float[INPUTSIZE * 2];
   1141         out.copyTo(arrayOut);
   1142         for (int i = 0; i < INPUTSIZE; i++) {
   1143             for (int j = 0; j < 2 ; j++) {
   1144                 // Extract the inputs.
   1145                 ArgumentsUintFloat args = new ArgumentsUintFloat();
   1146                 args.inV = arrayInV[i * 2 + j];
   1147                 // Figure out what the outputs should have been.
   1148                 Target target = new Target(relaxed);
   1149                 CoreMathVerifier.computeConvert(args, target);
   1150                 // Validate the outputs.
   1151                 boolean valid = true;
   1152                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
   1153                     valid = false;
   1154                 }
   1155                 if (!valid) {
   1156                     StringBuilder message = new StringBuilder();
   1157                     message.append("Input inV: ");
   1158                     message.append(String.format("0x%x", args.inV));
   1159                     message.append("\n");
   1160                     message.append("Expected output out: ");
   1161                     message.append(args.out.toString());
   1162                     message.append("\n");
   1163                     message.append("Actual   output out: ");
   1164                     message.append(String.format("%14.8g {%8x} %15a",
   1165                             arrayOut[i * 2 + j], Float.floatToRawIntBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j]));
   1166                     if (!args.out.couldBe(arrayOut[i * 2 + j])) {
   1167                         message.append(" FAIL");
   1168                     }
   1169                     message.append("\n");
   1170                     assertTrue("Incorrect output for checkConvertUint2Float2" +
   1171                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   1172                 }
   1173             }
   1174         }
   1175     }
   1176 
   1177     private void checkConvertUint3Float3() {
   1178         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_32, 3, 0xd1e24a53fc9fed24l, false, 32);
   1179         try {
   1180             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
   1181             script.forEach_testConvertFloat3Uint3Float3(inV, out);
   1182             verifyResultsConvertUint3Float3(inV, out, false);
   1183         } catch (Exception e) {
   1184             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat3Uint3Float3: " + e.toString());
   1185         }
   1186         try {
   1187             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
   1188             scriptRelaxed.forEach_testConvertFloat3Uint3Float3(inV, out);
   1189             verifyResultsConvertUint3Float3(inV, out, true);
   1190         } catch (Exception e) {
   1191             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat3Uint3Float3: " + e.toString());
   1192         }
   1193     }
   1194 
   1195     private void verifyResultsConvertUint3Float3(Allocation inV, Allocation out, boolean relaxed) {
   1196         int[] arrayInV = new int[INPUTSIZE * 4];
   1197         inV.copyTo(arrayInV);
   1198         float[] arrayOut = new float[INPUTSIZE * 4];
   1199         out.copyTo(arrayOut);
   1200         for (int i = 0; i < INPUTSIZE; i++) {
   1201             for (int j = 0; j < 3 ; j++) {
   1202                 // Extract the inputs.
   1203                 ArgumentsUintFloat args = new ArgumentsUintFloat();
   1204                 args.inV = arrayInV[i * 4 + j];
   1205                 // Figure out what the outputs should have been.
   1206                 Target target = new Target(relaxed);
   1207                 CoreMathVerifier.computeConvert(args, target);
   1208                 // Validate the outputs.
   1209                 boolean valid = true;
   1210                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   1211                     valid = false;
   1212                 }
   1213                 if (!valid) {
   1214                     StringBuilder message = new StringBuilder();
   1215                     message.append("Input inV: ");
   1216                     message.append(String.format("0x%x", args.inV));
   1217                     message.append("\n");
   1218                     message.append("Expected output out: ");
   1219                     message.append(args.out.toString());
   1220                     message.append("\n");
   1221                     message.append("Actual   output out: ");
   1222                     message.append(String.format("%14.8g {%8x} %15a",
   1223                             arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
   1224                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   1225                         message.append(" FAIL");
   1226                     }
   1227                     message.append("\n");
   1228                     assertTrue("Incorrect output for checkConvertUint3Float3" +
   1229                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   1230                 }
   1231             }
   1232         }
   1233     }
   1234 
   1235     private void checkConvertUint4Float4() {
   1236         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_32, 4, 0xd1e4136ef2bb0e02l, false, 32);
   1237         try {
   1238             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
   1239             script.forEach_testConvertFloat4Uint4Float4(inV, out);
   1240             verifyResultsConvertUint4Float4(inV, out, false);
   1241         } catch (Exception e) {
   1242             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat4Uint4Float4: " + e.toString());
   1243         }
   1244         try {
   1245             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
   1246             scriptRelaxed.forEach_testConvertFloat4Uint4Float4(inV, out);
   1247             verifyResultsConvertUint4Float4(inV, out, true);
   1248         } catch (Exception e) {
   1249             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat4Uint4Float4: " + e.toString());
   1250         }
   1251     }
   1252 
   1253     private void verifyResultsConvertUint4Float4(Allocation inV, Allocation out, boolean relaxed) {
   1254         int[] arrayInV = new int[INPUTSIZE * 4];
   1255         inV.copyTo(arrayInV);
   1256         float[] arrayOut = new float[INPUTSIZE * 4];
   1257         out.copyTo(arrayOut);
   1258         for (int i = 0; i < INPUTSIZE; i++) {
   1259             for (int j = 0; j < 4 ; j++) {
   1260                 // Extract the inputs.
   1261                 ArgumentsUintFloat args = new ArgumentsUintFloat();
   1262                 args.inV = arrayInV[i * 4 + j];
   1263                 // Figure out what the outputs should have been.
   1264                 Target target = new Target(relaxed);
   1265                 CoreMathVerifier.computeConvert(args, target);
   1266                 // Validate the outputs.
   1267                 boolean valid = true;
   1268                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   1269                     valid = false;
   1270                 }
   1271                 if (!valid) {
   1272                     StringBuilder message = new StringBuilder();
   1273                     message.append("Input inV: ");
   1274                     message.append(String.format("0x%x", args.inV));
   1275                     message.append("\n");
   1276                     message.append("Expected output out: ");
   1277                     message.append(args.out.toString());
   1278                     message.append("\n");
   1279                     message.append("Actual   output out: ");
   1280                     message.append(String.format("%14.8g {%8x} %15a",
   1281                             arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
   1282                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   1283                         message.append(" FAIL");
   1284                     }
   1285                     message.append("\n");
   1286                     assertTrue("Incorrect output for checkConvertUint4Float4" +
   1287                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   1288                 }
   1289             }
   1290         }
   1291     }
   1292 
   1293     public class ArgumentsFloatChar {
   1294         public float inV;
   1295         public byte out;
   1296     }
   1297 
   1298     private void checkConvertFloat2Char2() {
   1299         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x239cb25829789662l, -1.2800000000000000000e+02, 1.2700000000000000000e+02);
   1300         try {
   1301             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 2), INPUTSIZE);
   1302             script.forEach_testConvertChar2Float2Char2(inV, out);
   1303             verifyResultsConvertFloat2Char2(inV, out, false);
   1304         } catch (Exception e) {
   1305             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar2Float2Char2: " + e.toString());
   1306         }
   1307         try {
   1308             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 2), INPUTSIZE);
   1309             scriptRelaxed.forEach_testConvertChar2Float2Char2(inV, out);
   1310             verifyResultsConvertFloat2Char2(inV, out, true);
   1311         } catch (Exception e) {
   1312             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar2Float2Char2: " + e.toString());
   1313         }
   1314     }
   1315 
   1316     private void verifyResultsConvertFloat2Char2(Allocation inV, Allocation out, boolean relaxed) {
   1317         float[] arrayInV = new float[INPUTSIZE * 2];
   1318         inV.copyTo(arrayInV);
   1319         byte[] arrayOut = new byte[INPUTSIZE * 2];
   1320         out.copyTo(arrayOut);
   1321         for (int i = 0; i < INPUTSIZE; i++) {
   1322             for (int j = 0; j < 2 ; j++) {
   1323                 // Extract the inputs.
   1324                 ArgumentsFloatChar args = new ArgumentsFloatChar();
   1325                 args.inV = arrayInV[i * 2 + j];
   1326                 // Figure out what the outputs should have been.
   1327                 CoreMathVerifier.computeConvert(args);
   1328                 // Validate the outputs.
   1329                 boolean valid = true;
   1330                 if (args.out != arrayOut[i * 2 + j]) {
   1331                     valid = false;
   1332                 }
   1333                 if (!valid) {
   1334                     StringBuilder message = new StringBuilder();
   1335                     message.append("Input inV: ");
   1336                     message.append(String.format("%14.8g {%8x} %15a",
   1337                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
   1338                     message.append("\n");
   1339                     message.append("Expected output out: ");
   1340                     message.append(String.format("%d", args.out));
   1341                     message.append("\n");
   1342                     message.append("Actual   output out: ");
   1343                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   1344                     if (args.out != arrayOut[i * 2 + j]) {
   1345                         message.append(" FAIL");
   1346                     }
   1347                     message.append("\n");
   1348                     assertTrue("Incorrect output for checkConvertFloat2Char2" +
   1349                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   1350                 }
   1351             }
   1352         }
   1353     }
   1354 
   1355     private void checkConvertFloat3Char3() {
   1356         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x239cbcf988805b56l, -1.2800000000000000000e+02, 1.2700000000000000000e+02);
   1357         try {
   1358             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 3), INPUTSIZE);
   1359             script.forEach_testConvertChar3Float3Char3(inV, out);
   1360             verifyResultsConvertFloat3Char3(inV, out, false);
   1361         } catch (Exception e) {
   1362             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar3Float3Char3: " + e.toString());
   1363         }
   1364         try {
   1365             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 3), INPUTSIZE);
   1366             scriptRelaxed.forEach_testConvertChar3Float3Char3(inV, out);
   1367             verifyResultsConvertFloat3Char3(inV, out, true);
   1368         } catch (Exception e) {
   1369             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar3Float3Char3: " + e.toString());
   1370         }
   1371     }
   1372 
   1373     private void verifyResultsConvertFloat3Char3(Allocation inV, Allocation out, boolean relaxed) {
   1374         float[] arrayInV = new float[INPUTSIZE * 4];
   1375         inV.copyTo(arrayInV);
   1376         byte[] arrayOut = new byte[INPUTSIZE * 4];
   1377         out.copyTo(arrayOut);
   1378         for (int i = 0; i < INPUTSIZE; i++) {
   1379             for (int j = 0; j < 3 ; j++) {
   1380                 // Extract the inputs.
   1381                 ArgumentsFloatChar args = new ArgumentsFloatChar();
   1382                 args.inV = arrayInV[i * 4 + j];
   1383                 // Figure out what the outputs should have been.
   1384                 CoreMathVerifier.computeConvert(args);
   1385                 // Validate the outputs.
   1386                 boolean valid = true;
   1387                 if (args.out != arrayOut[i * 4 + j]) {
   1388                     valid = false;
   1389                 }
   1390                 if (!valid) {
   1391                     StringBuilder message = new StringBuilder();
   1392                     message.append("Input inV: ");
   1393                     message.append(String.format("%14.8g {%8x} %15a",
   1394                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
   1395                     message.append("\n");
   1396                     message.append("Expected output out: ");
   1397                     message.append(String.format("%d", args.out));
   1398                     message.append("\n");
   1399                     message.append("Actual   output out: ");
   1400                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   1401                     if (args.out != arrayOut[i * 4 + j]) {
   1402                         message.append(" FAIL");
   1403                     }
   1404                     message.append("\n");
   1405                     assertTrue("Incorrect output for checkConvertFloat3Char3" +
   1406                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   1407                 }
   1408             }
   1409         }
   1410     }
   1411 
   1412     private void checkConvertFloat4Char4() {
   1413         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x239cc79ae788204al, -1.2800000000000000000e+02, 1.2700000000000000000e+02);
   1414         try {
   1415             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 4), INPUTSIZE);
   1416             script.forEach_testConvertChar4Float4Char4(inV, out);
   1417             verifyResultsConvertFloat4Char4(inV, out, false);
   1418         } catch (Exception e) {
   1419             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar4Float4Char4: " + e.toString());
   1420         }
   1421         try {
   1422             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 4), INPUTSIZE);
   1423             scriptRelaxed.forEach_testConvertChar4Float4Char4(inV, out);
   1424             verifyResultsConvertFloat4Char4(inV, out, true);
   1425         } catch (Exception e) {
   1426             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar4Float4Char4: " + e.toString());
   1427         }
   1428     }
   1429 
   1430     private void verifyResultsConvertFloat4Char4(Allocation inV, Allocation out, boolean relaxed) {
   1431         float[] arrayInV = new float[INPUTSIZE * 4];
   1432         inV.copyTo(arrayInV);
   1433         byte[] arrayOut = new byte[INPUTSIZE * 4];
   1434         out.copyTo(arrayOut);
   1435         for (int i = 0; i < INPUTSIZE; i++) {
   1436             for (int j = 0; j < 4 ; j++) {
   1437                 // Extract the inputs.
   1438                 ArgumentsFloatChar args = new ArgumentsFloatChar();
   1439                 args.inV = arrayInV[i * 4 + j];
   1440                 // Figure out what the outputs should have been.
   1441                 CoreMathVerifier.computeConvert(args);
   1442                 // Validate the outputs.
   1443                 boolean valid = true;
   1444                 if (args.out != arrayOut[i * 4 + j]) {
   1445                     valid = false;
   1446                 }
   1447                 if (!valid) {
   1448                     StringBuilder message = new StringBuilder();
   1449                     message.append("Input inV: ");
   1450                     message.append(String.format("%14.8g {%8x} %15a",
   1451                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
   1452                     message.append("\n");
   1453                     message.append("Expected output out: ");
   1454                     message.append(String.format("%d", args.out));
   1455                     message.append("\n");
   1456                     message.append("Actual   output out: ");
   1457                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   1458                     if (args.out != arrayOut[i * 4 + j]) {
   1459                         message.append(" FAIL");
   1460                     }
   1461                     message.append("\n");
   1462                     assertTrue("Incorrect output for checkConvertFloat4Char4" +
   1463                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   1464                 }
   1465             }
   1466         }
   1467     }
   1468 
   1469     public class ArgumentsCharChar {
   1470         public byte inV;
   1471         public byte out;
   1472     }
   1473 
   1474     private void checkConvertChar2Char2() {
   1475         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_8, 2, 0xd8618777d5086da2l, true, 7);
   1476         try {
   1477             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 2), INPUTSIZE);
   1478             script.forEach_testConvertChar2Char2Char2(inV, out);
   1479             verifyResultsConvertChar2Char2(inV, out, false);
   1480         } catch (Exception e) {
   1481             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar2Char2Char2: " + e.toString());
   1482         }
   1483         try {
   1484             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 2), INPUTSIZE);
   1485             scriptRelaxed.forEach_testConvertChar2Char2Char2(inV, out);
   1486             verifyResultsConvertChar2Char2(inV, out, true);
   1487         } catch (Exception e) {
   1488             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar2Char2Char2: " + e.toString());
   1489         }
   1490     }
   1491 
   1492     private void verifyResultsConvertChar2Char2(Allocation inV, Allocation out, boolean relaxed) {
   1493         byte[] arrayInV = new byte[INPUTSIZE * 2];
   1494         inV.copyTo(arrayInV);
   1495         byte[] arrayOut = new byte[INPUTSIZE * 2];
   1496         out.copyTo(arrayOut);
   1497         for (int i = 0; i < INPUTSIZE; i++) {
   1498             for (int j = 0; j < 2 ; j++) {
   1499                 // Extract the inputs.
   1500                 ArgumentsCharChar args = new ArgumentsCharChar();
   1501                 args.inV = arrayInV[i * 2 + j];
   1502                 // Figure out what the outputs should have been.
   1503                 CoreMathVerifier.computeConvert(args);
   1504                 // Validate the outputs.
   1505                 boolean valid = true;
   1506                 if (args.out != arrayOut[i * 2 + j]) {
   1507                     valid = false;
   1508                 }
   1509                 if (!valid) {
   1510                     StringBuilder message = new StringBuilder();
   1511                     message.append("Input inV: ");
   1512                     message.append(String.format("%d", args.inV));
   1513                     message.append("\n");
   1514                     message.append("Expected output out: ");
   1515                     message.append(String.format("%d", args.out));
   1516                     message.append("\n");
   1517                     message.append("Actual   output out: ");
   1518                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   1519                     if (args.out != arrayOut[i * 2 + j]) {
   1520                         message.append(" FAIL");
   1521                     }
   1522                     message.append("\n");
   1523                     assertTrue("Incorrect output for checkConvertChar2Char2" +
   1524                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   1525                 }
   1526             }
   1527         }
   1528     }
   1529 
   1530     private void checkConvertChar3Char3() {
   1531         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_8, 3, 0xd861921934103296l, true, 7);
   1532         try {
   1533             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 3), INPUTSIZE);
   1534             script.forEach_testConvertChar3Char3Char3(inV, out);
   1535             verifyResultsConvertChar3Char3(inV, out, false);
   1536         } catch (Exception e) {
   1537             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar3Char3Char3: " + e.toString());
   1538         }
   1539         try {
   1540             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 3), INPUTSIZE);
   1541             scriptRelaxed.forEach_testConvertChar3Char3Char3(inV, out);
   1542             verifyResultsConvertChar3Char3(inV, out, true);
   1543         } catch (Exception e) {
   1544             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar3Char3Char3: " + e.toString());
   1545         }
   1546     }
   1547 
   1548     private void verifyResultsConvertChar3Char3(Allocation inV, Allocation out, boolean relaxed) {
   1549         byte[] arrayInV = new byte[INPUTSIZE * 4];
   1550         inV.copyTo(arrayInV);
   1551         byte[] arrayOut = new byte[INPUTSIZE * 4];
   1552         out.copyTo(arrayOut);
   1553         for (int i = 0; i < INPUTSIZE; i++) {
   1554             for (int j = 0; j < 3 ; j++) {
   1555                 // Extract the inputs.
   1556                 ArgumentsCharChar args = new ArgumentsCharChar();
   1557                 args.inV = arrayInV[i * 4 + j];
   1558                 // Figure out what the outputs should have been.
   1559                 CoreMathVerifier.computeConvert(args);
   1560                 // Validate the outputs.
   1561                 boolean valid = true;
   1562                 if (args.out != arrayOut[i * 4 + j]) {
   1563                     valid = false;
   1564                 }
   1565                 if (!valid) {
   1566                     StringBuilder message = new StringBuilder();
   1567                     message.append("Input inV: ");
   1568                     message.append(String.format("%d", args.inV));
   1569                     message.append("\n");
   1570                     message.append("Expected output out: ");
   1571                     message.append(String.format("%d", args.out));
   1572                     message.append("\n");
   1573                     message.append("Actual   output out: ");
   1574                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   1575                     if (args.out != arrayOut[i * 4 + j]) {
   1576                         message.append(" FAIL");
   1577                     }
   1578                     message.append("\n");
   1579                     assertTrue("Incorrect output for checkConvertChar3Char3" +
   1580                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   1581                 }
   1582             }
   1583         }
   1584     }
   1585 
   1586     private void checkConvertChar4Char4() {
   1587         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_8, 4, 0xd8619cba9317f78al, true, 7);
   1588         try {
   1589             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 4), INPUTSIZE);
   1590             script.forEach_testConvertChar4Char4Char4(inV, out);
   1591             verifyResultsConvertChar4Char4(inV, out, false);
   1592         } catch (Exception e) {
   1593             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar4Char4Char4: " + e.toString());
   1594         }
   1595         try {
   1596             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 4), INPUTSIZE);
   1597             scriptRelaxed.forEach_testConvertChar4Char4Char4(inV, out);
   1598             verifyResultsConvertChar4Char4(inV, out, true);
   1599         } catch (Exception e) {
   1600             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar4Char4Char4: " + e.toString());
   1601         }
   1602     }
   1603 
   1604     private void verifyResultsConvertChar4Char4(Allocation inV, Allocation out, boolean relaxed) {
   1605         byte[] arrayInV = new byte[INPUTSIZE * 4];
   1606         inV.copyTo(arrayInV);
   1607         byte[] arrayOut = new byte[INPUTSIZE * 4];
   1608         out.copyTo(arrayOut);
   1609         for (int i = 0; i < INPUTSIZE; i++) {
   1610             for (int j = 0; j < 4 ; j++) {
   1611                 // Extract the inputs.
   1612                 ArgumentsCharChar args = new ArgumentsCharChar();
   1613                 args.inV = arrayInV[i * 4 + j];
   1614                 // Figure out what the outputs should have been.
   1615                 CoreMathVerifier.computeConvert(args);
   1616                 // Validate the outputs.
   1617                 boolean valid = true;
   1618                 if (args.out != arrayOut[i * 4 + j]) {
   1619                     valid = false;
   1620                 }
   1621                 if (!valid) {
   1622                     StringBuilder message = new StringBuilder();
   1623                     message.append("Input inV: ");
   1624                     message.append(String.format("%d", args.inV));
   1625                     message.append("\n");
   1626                     message.append("Expected output out: ");
   1627                     message.append(String.format("%d", args.out));
   1628                     message.append("\n");
   1629                     message.append("Actual   output out: ");
   1630                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   1631                     if (args.out != arrayOut[i * 4 + j]) {
   1632                         message.append(" FAIL");
   1633                     }
   1634                     message.append("\n");
   1635                     assertTrue("Incorrect output for checkConvertChar4Char4" +
   1636                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   1637                 }
   1638             }
   1639         }
   1640     }
   1641 
   1642     public class ArgumentsUcharChar {
   1643         public byte inV;
   1644         public byte out;
   1645     }
   1646 
   1647     private void checkConvertUchar2Char2() {
   1648         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_8, 2, 0x7fef40c5678a7a23l, false, 7);
   1649         try {
   1650             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 2), INPUTSIZE);
   1651             script.forEach_testConvertChar2Uchar2Char2(inV, out);
   1652             verifyResultsConvertUchar2Char2(inV, out, false);
   1653         } catch (Exception e) {
   1654             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar2Uchar2Char2: " + e.toString());
   1655         }
   1656         try {
   1657             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 2), INPUTSIZE);
   1658             scriptRelaxed.forEach_testConvertChar2Uchar2Char2(inV, out);
   1659             verifyResultsConvertUchar2Char2(inV, out, true);
   1660         } catch (Exception e) {
   1661             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar2Uchar2Char2: " + e.toString());
   1662         }
   1663     }
   1664 
   1665     private void verifyResultsConvertUchar2Char2(Allocation inV, Allocation out, boolean relaxed) {
   1666         byte[] arrayInV = new byte[INPUTSIZE * 2];
   1667         inV.copyTo(arrayInV);
   1668         byte[] arrayOut = new byte[INPUTSIZE * 2];
   1669         out.copyTo(arrayOut);
   1670         for (int i = 0; i < INPUTSIZE; i++) {
   1671             for (int j = 0; j < 2 ; j++) {
   1672                 // Extract the inputs.
   1673                 ArgumentsUcharChar args = new ArgumentsUcharChar();
   1674                 args.inV = arrayInV[i * 2 + j];
   1675                 // Figure out what the outputs should have been.
   1676                 CoreMathVerifier.computeConvert(args);
   1677                 // Validate the outputs.
   1678                 boolean valid = true;
   1679                 if (args.out != arrayOut[i * 2 + j]) {
   1680                     valid = false;
   1681                 }
   1682                 if (!valid) {
   1683                     StringBuilder message = new StringBuilder();
   1684                     message.append("Input inV: ");
   1685                     message.append(String.format("0x%x", args.inV));
   1686                     message.append("\n");
   1687                     message.append("Expected output out: ");
   1688                     message.append(String.format("%d", args.out));
   1689                     message.append("\n");
   1690                     message.append("Actual   output out: ");
   1691                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   1692                     if (args.out != arrayOut[i * 2 + j]) {
   1693                         message.append(" FAIL");
   1694                     }
   1695                     message.append("\n");
   1696                     assertTrue("Incorrect output for checkConvertUchar2Char2" +
   1697                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   1698                 }
   1699             }
   1700         }
   1701     }
   1702 
   1703     private void checkConvertUchar3Char3() {
   1704         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_8, 3, 0x7fef4b66c6923f17l, false, 7);
   1705         try {
   1706             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 3), INPUTSIZE);
   1707             script.forEach_testConvertChar3Uchar3Char3(inV, out);
   1708             verifyResultsConvertUchar3Char3(inV, out, false);
   1709         } catch (Exception e) {
   1710             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar3Uchar3Char3: " + e.toString());
   1711         }
   1712         try {
   1713             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 3), INPUTSIZE);
   1714             scriptRelaxed.forEach_testConvertChar3Uchar3Char3(inV, out);
   1715             verifyResultsConvertUchar3Char3(inV, out, true);
   1716         } catch (Exception e) {
   1717             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar3Uchar3Char3: " + e.toString());
   1718         }
   1719     }
   1720 
   1721     private void verifyResultsConvertUchar3Char3(Allocation inV, Allocation out, boolean relaxed) {
   1722         byte[] arrayInV = new byte[INPUTSIZE * 4];
   1723         inV.copyTo(arrayInV);
   1724         byte[] arrayOut = new byte[INPUTSIZE * 4];
   1725         out.copyTo(arrayOut);
   1726         for (int i = 0; i < INPUTSIZE; i++) {
   1727             for (int j = 0; j < 3 ; j++) {
   1728                 // Extract the inputs.
   1729                 ArgumentsUcharChar args = new ArgumentsUcharChar();
   1730                 args.inV = arrayInV[i * 4 + j];
   1731                 // Figure out what the outputs should have been.
   1732                 CoreMathVerifier.computeConvert(args);
   1733                 // Validate the outputs.
   1734                 boolean valid = true;
   1735                 if (args.out != arrayOut[i * 4 + j]) {
   1736                     valid = false;
   1737                 }
   1738                 if (!valid) {
   1739                     StringBuilder message = new StringBuilder();
   1740                     message.append("Input inV: ");
   1741                     message.append(String.format("0x%x", args.inV));
   1742                     message.append("\n");
   1743                     message.append("Expected output out: ");
   1744                     message.append(String.format("%d", args.out));
   1745                     message.append("\n");
   1746                     message.append("Actual   output out: ");
   1747                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   1748                     if (args.out != arrayOut[i * 4 + j]) {
   1749                         message.append(" FAIL");
   1750                     }
   1751                     message.append("\n");
   1752                     assertTrue("Incorrect output for checkConvertUchar3Char3" +
   1753                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   1754                 }
   1755             }
   1756         }
   1757     }
   1758 
   1759     private void checkConvertUchar4Char4() {
   1760         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_8, 4, 0x7fef5608259a040bl, false, 7);
   1761         try {
   1762             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 4), INPUTSIZE);
   1763             script.forEach_testConvertChar4Uchar4Char4(inV, out);
   1764             verifyResultsConvertUchar4Char4(inV, out, false);
   1765         } catch (Exception e) {
   1766             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar4Uchar4Char4: " + e.toString());
   1767         }
   1768         try {
   1769             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 4), INPUTSIZE);
   1770             scriptRelaxed.forEach_testConvertChar4Uchar4Char4(inV, out);
   1771             verifyResultsConvertUchar4Char4(inV, out, true);
   1772         } catch (Exception e) {
   1773             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar4Uchar4Char4: " + e.toString());
   1774         }
   1775     }
   1776 
   1777     private void verifyResultsConvertUchar4Char4(Allocation inV, Allocation out, boolean relaxed) {
   1778         byte[] arrayInV = new byte[INPUTSIZE * 4];
   1779         inV.copyTo(arrayInV);
   1780         byte[] arrayOut = new byte[INPUTSIZE * 4];
   1781         out.copyTo(arrayOut);
   1782         for (int i = 0; i < INPUTSIZE; i++) {
   1783             for (int j = 0; j < 4 ; j++) {
   1784                 // Extract the inputs.
   1785                 ArgumentsUcharChar args = new ArgumentsUcharChar();
   1786                 args.inV = arrayInV[i * 4 + j];
   1787                 // Figure out what the outputs should have been.
   1788                 CoreMathVerifier.computeConvert(args);
   1789                 // Validate the outputs.
   1790                 boolean valid = true;
   1791                 if (args.out != arrayOut[i * 4 + j]) {
   1792                     valid = false;
   1793                 }
   1794                 if (!valid) {
   1795                     StringBuilder message = new StringBuilder();
   1796                     message.append("Input inV: ");
   1797                     message.append(String.format("0x%x", args.inV));
   1798                     message.append("\n");
   1799                     message.append("Expected output out: ");
   1800                     message.append(String.format("%d", args.out));
   1801                     message.append("\n");
   1802                     message.append("Actual   output out: ");
   1803                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   1804                     if (args.out != arrayOut[i * 4 + j]) {
   1805                         message.append(" FAIL");
   1806                     }
   1807                     message.append("\n");
   1808                     assertTrue("Incorrect output for checkConvertUchar4Char4" +
   1809                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   1810                 }
   1811             }
   1812         }
   1813     }
   1814 
   1815     public class ArgumentsShortChar {
   1816         public short inV;
   1817         public byte out;
   1818     }
   1819 
   1820     private void checkConvertShort2Char2() {
   1821         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_16, 2, 0x68ab650215c60866l, true, 7);
   1822         try {
   1823             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 2), INPUTSIZE);
   1824             script.forEach_testConvertChar2Short2Char2(inV, out);
   1825             verifyResultsConvertShort2Char2(inV, out, false);
   1826         } catch (Exception e) {
   1827             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar2Short2Char2: " + e.toString());
   1828         }
   1829         try {
   1830             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 2), INPUTSIZE);
   1831             scriptRelaxed.forEach_testConvertChar2Short2Char2(inV, out);
   1832             verifyResultsConvertShort2Char2(inV, out, true);
   1833         } catch (Exception e) {
   1834             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar2Short2Char2: " + e.toString());
   1835         }
   1836     }
   1837 
   1838     private void verifyResultsConvertShort2Char2(Allocation inV, Allocation out, boolean relaxed) {
   1839         short[] arrayInV = new short[INPUTSIZE * 2];
   1840         inV.copyTo(arrayInV);
   1841         byte[] arrayOut = new byte[INPUTSIZE * 2];
   1842         out.copyTo(arrayOut);
   1843         for (int i = 0; i < INPUTSIZE; i++) {
   1844             for (int j = 0; j < 2 ; j++) {
   1845                 // Extract the inputs.
   1846                 ArgumentsShortChar args = new ArgumentsShortChar();
   1847                 args.inV = arrayInV[i * 2 + j];
   1848                 // Figure out what the outputs should have been.
   1849                 CoreMathVerifier.computeConvert(args);
   1850                 // Validate the outputs.
   1851                 boolean valid = true;
   1852                 if (args.out != arrayOut[i * 2 + j]) {
   1853                     valid = false;
   1854                 }
   1855                 if (!valid) {
   1856                     StringBuilder message = new StringBuilder();
   1857                     message.append("Input inV: ");
   1858                     message.append(String.format("%d", args.inV));
   1859                     message.append("\n");
   1860                     message.append("Expected output out: ");
   1861                     message.append(String.format("%d", args.out));
   1862                     message.append("\n");
   1863                     message.append("Actual   output out: ");
   1864                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   1865                     if (args.out != arrayOut[i * 2 + j]) {
   1866                         message.append(" FAIL");
   1867                     }
   1868                     message.append("\n");
   1869                     assertTrue("Incorrect output for checkConvertShort2Char2" +
   1870                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   1871                 }
   1872             }
   1873         }
   1874     }
   1875 
   1876     private void checkConvertShort3Char3() {
   1877         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_16, 3, 0x68ab6fa374cdcd5al, true, 7);
   1878         try {
   1879             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 3), INPUTSIZE);
   1880             script.forEach_testConvertChar3Short3Char3(inV, out);
   1881             verifyResultsConvertShort3Char3(inV, out, false);
   1882         } catch (Exception e) {
   1883             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar3Short3Char3: " + e.toString());
   1884         }
   1885         try {
   1886             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 3), INPUTSIZE);
   1887             scriptRelaxed.forEach_testConvertChar3Short3Char3(inV, out);
   1888             verifyResultsConvertShort3Char3(inV, out, true);
   1889         } catch (Exception e) {
   1890             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar3Short3Char3: " + e.toString());
   1891         }
   1892     }
   1893 
   1894     private void verifyResultsConvertShort3Char3(Allocation inV, Allocation out, boolean relaxed) {
   1895         short[] arrayInV = new short[INPUTSIZE * 4];
   1896         inV.copyTo(arrayInV);
   1897         byte[] arrayOut = new byte[INPUTSIZE * 4];
   1898         out.copyTo(arrayOut);
   1899         for (int i = 0; i < INPUTSIZE; i++) {
   1900             for (int j = 0; j < 3 ; j++) {
   1901                 // Extract the inputs.
   1902                 ArgumentsShortChar args = new ArgumentsShortChar();
   1903                 args.inV = arrayInV[i * 4 + j];
   1904                 // Figure out what the outputs should have been.
   1905                 CoreMathVerifier.computeConvert(args);
   1906                 // Validate the outputs.
   1907                 boolean valid = true;
   1908                 if (args.out != arrayOut[i * 4 + j]) {
   1909                     valid = false;
   1910                 }
   1911                 if (!valid) {
   1912                     StringBuilder message = new StringBuilder();
   1913                     message.append("Input inV: ");
   1914                     message.append(String.format("%d", args.inV));
   1915                     message.append("\n");
   1916                     message.append("Expected output out: ");
   1917                     message.append(String.format("%d", args.out));
   1918                     message.append("\n");
   1919                     message.append("Actual   output out: ");
   1920                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   1921                     if (args.out != arrayOut[i * 4 + j]) {
   1922                         message.append(" FAIL");
   1923                     }
   1924                     message.append("\n");
   1925                     assertTrue("Incorrect output for checkConvertShort3Char3" +
   1926                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   1927                 }
   1928             }
   1929         }
   1930     }
   1931 
   1932     private void checkConvertShort4Char4() {
   1933         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_16, 4, 0x68ab7a44d3d5924el, true, 7);
   1934         try {
   1935             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 4), INPUTSIZE);
   1936             script.forEach_testConvertChar4Short4Char4(inV, out);
   1937             verifyResultsConvertShort4Char4(inV, out, false);
   1938         } catch (Exception e) {
   1939             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar4Short4Char4: " + e.toString());
   1940         }
   1941         try {
   1942             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 4), INPUTSIZE);
   1943             scriptRelaxed.forEach_testConvertChar4Short4Char4(inV, out);
   1944             verifyResultsConvertShort4Char4(inV, out, true);
   1945         } catch (Exception e) {
   1946             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar4Short4Char4: " + e.toString());
   1947         }
   1948     }
   1949 
   1950     private void verifyResultsConvertShort4Char4(Allocation inV, Allocation out, boolean relaxed) {
   1951         short[] arrayInV = new short[INPUTSIZE * 4];
   1952         inV.copyTo(arrayInV);
   1953         byte[] arrayOut = new byte[INPUTSIZE * 4];
   1954         out.copyTo(arrayOut);
   1955         for (int i = 0; i < INPUTSIZE; i++) {
   1956             for (int j = 0; j < 4 ; j++) {
   1957                 // Extract the inputs.
   1958                 ArgumentsShortChar args = new ArgumentsShortChar();
   1959                 args.inV = arrayInV[i * 4 + j];
   1960                 // Figure out what the outputs should have been.
   1961                 CoreMathVerifier.computeConvert(args);
   1962                 // Validate the outputs.
   1963                 boolean valid = true;
   1964                 if (args.out != arrayOut[i * 4 + j]) {
   1965                     valid = false;
   1966                 }
   1967                 if (!valid) {
   1968                     StringBuilder message = new StringBuilder();
   1969                     message.append("Input inV: ");
   1970                     message.append(String.format("%d", args.inV));
   1971                     message.append("\n");
   1972                     message.append("Expected output out: ");
   1973                     message.append(String.format("%d", args.out));
   1974                     message.append("\n");
   1975                     message.append("Actual   output out: ");
   1976                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   1977                     if (args.out != arrayOut[i * 4 + j]) {
   1978                         message.append(" FAIL");
   1979                     }
   1980                     message.append("\n");
   1981                     assertTrue("Incorrect output for checkConvertShort4Char4" +
   1982                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   1983                 }
   1984             }
   1985         }
   1986     }
   1987 
   1988     public class ArgumentsUshortChar {
   1989         public short inV;
   1990         public byte out;
   1991     }
   1992 
   1993     private void checkConvertUshort2Char2() {
   1994         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_16, 2, 0x8d798509b19e2211l, false, 7);
   1995         try {
   1996             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 2), INPUTSIZE);
   1997             script.forEach_testConvertChar2Ushort2Char2(inV, out);
   1998             verifyResultsConvertUshort2Char2(inV, out, false);
   1999         } catch (Exception e) {
   2000             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar2Ushort2Char2: " + e.toString());
   2001         }
   2002         try {
   2003             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 2), INPUTSIZE);
   2004             scriptRelaxed.forEach_testConvertChar2Ushort2Char2(inV, out);
   2005             verifyResultsConvertUshort2Char2(inV, out, true);
   2006         } catch (Exception e) {
   2007             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar2Ushort2Char2: " + e.toString());
   2008         }
   2009     }
   2010 
   2011     private void verifyResultsConvertUshort2Char2(Allocation inV, Allocation out, boolean relaxed) {
   2012         short[] arrayInV = new short[INPUTSIZE * 2];
   2013         inV.copyTo(arrayInV);
   2014         byte[] arrayOut = new byte[INPUTSIZE * 2];
   2015         out.copyTo(arrayOut);
   2016         for (int i = 0; i < INPUTSIZE; i++) {
   2017             for (int j = 0; j < 2 ; j++) {
   2018                 // Extract the inputs.
   2019                 ArgumentsUshortChar args = new ArgumentsUshortChar();
   2020                 args.inV = arrayInV[i * 2 + j];
   2021                 // Figure out what the outputs should have been.
   2022                 CoreMathVerifier.computeConvert(args);
   2023                 // Validate the outputs.
   2024                 boolean valid = true;
   2025                 if (args.out != arrayOut[i * 2 + j]) {
   2026                     valid = false;
   2027                 }
   2028                 if (!valid) {
   2029                     StringBuilder message = new StringBuilder();
   2030                     message.append("Input inV: ");
   2031                     message.append(String.format("0x%x", args.inV));
   2032                     message.append("\n");
   2033                     message.append("Expected output out: ");
   2034                     message.append(String.format("%d", args.out));
   2035                     message.append("\n");
   2036                     message.append("Actual   output out: ");
   2037                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   2038                     if (args.out != arrayOut[i * 2 + j]) {
   2039                         message.append(" FAIL");
   2040                     }
   2041                     message.append("\n");
   2042                     assertTrue("Incorrect output for checkConvertUshort2Char2" +
   2043                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   2044                 }
   2045             }
   2046         }
   2047     }
   2048 
   2049     private void checkConvertUshort3Char3() {
   2050         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_16, 3, 0x8d798fab10a5e705l, false, 7);
   2051         try {
   2052             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 3), INPUTSIZE);
   2053             script.forEach_testConvertChar3Ushort3Char3(inV, out);
   2054             verifyResultsConvertUshort3Char3(inV, out, false);
   2055         } catch (Exception e) {
   2056             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar3Ushort3Char3: " + e.toString());
   2057         }
   2058         try {
   2059             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 3), INPUTSIZE);
   2060             scriptRelaxed.forEach_testConvertChar3Ushort3Char3(inV, out);
   2061             verifyResultsConvertUshort3Char3(inV, out, true);
   2062         } catch (Exception e) {
   2063             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar3Ushort3Char3: " + e.toString());
   2064         }
   2065     }
   2066 
   2067     private void verifyResultsConvertUshort3Char3(Allocation inV, Allocation out, boolean relaxed) {
   2068         short[] arrayInV = new short[INPUTSIZE * 4];
   2069         inV.copyTo(arrayInV);
   2070         byte[] arrayOut = new byte[INPUTSIZE * 4];
   2071         out.copyTo(arrayOut);
   2072         for (int i = 0; i < INPUTSIZE; i++) {
   2073             for (int j = 0; j < 3 ; j++) {
   2074                 // Extract the inputs.
   2075                 ArgumentsUshortChar args = new ArgumentsUshortChar();
   2076                 args.inV = arrayInV[i * 4 + j];
   2077                 // Figure out what the outputs should have been.
   2078                 CoreMathVerifier.computeConvert(args);
   2079                 // Validate the outputs.
   2080                 boolean valid = true;
   2081                 if (args.out != arrayOut[i * 4 + j]) {
   2082                     valid = false;
   2083                 }
   2084                 if (!valid) {
   2085                     StringBuilder message = new StringBuilder();
   2086                     message.append("Input inV: ");
   2087                     message.append(String.format("0x%x", args.inV));
   2088                     message.append("\n");
   2089                     message.append("Expected output out: ");
   2090                     message.append(String.format("%d", args.out));
   2091                     message.append("\n");
   2092                     message.append("Actual   output out: ");
   2093                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   2094                     if (args.out != arrayOut[i * 4 + j]) {
   2095                         message.append(" FAIL");
   2096                     }
   2097                     message.append("\n");
   2098                     assertTrue("Incorrect output for checkConvertUshort3Char3" +
   2099                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   2100                 }
   2101             }
   2102         }
   2103     }
   2104 
   2105     private void checkConvertUshort4Char4() {
   2106         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_16, 4, 0x8d799a4c6fadabf9l, false, 7);
   2107         try {
   2108             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 4), INPUTSIZE);
   2109             script.forEach_testConvertChar4Ushort4Char4(inV, out);
   2110             verifyResultsConvertUshort4Char4(inV, out, false);
   2111         } catch (Exception e) {
   2112             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar4Ushort4Char4: " + e.toString());
   2113         }
   2114         try {
   2115             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 4), INPUTSIZE);
   2116             scriptRelaxed.forEach_testConvertChar4Ushort4Char4(inV, out);
   2117             verifyResultsConvertUshort4Char4(inV, out, true);
   2118         } catch (Exception e) {
   2119             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar4Ushort4Char4: " + e.toString());
   2120         }
   2121     }
   2122 
   2123     private void verifyResultsConvertUshort4Char4(Allocation inV, Allocation out, boolean relaxed) {
   2124         short[] arrayInV = new short[INPUTSIZE * 4];
   2125         inV.copyTo(arrayInV);
   2126         byte[] arrayOut = new byte[INPUTSIZE * 4];
   2127         out.copyTo(arrayOut);
   2128         for (int i = 0; i < INPUTSIZE; i++) {
   2129             for (int j = 0; j < 4 ; j++) {
   2130                 // Extract the inputs.
   2131                 ArgumentsUshortChar args = new ArgumentsUshortChar();
   2132                 args.inV = arrayInV[i * 4 + j];
   2133                 // Figure out what the outputs should have been.
   2134                 CoreMathVerifier.computeConvert(args);
   2135                 // Validate the outputs.
   2136                 boolean valid = true;
   2137                 if (args.out != arrayOut[i * 4 + j]) {
   2138                     valid = false;
   2139                 }
   2140                 if (!valid) {
   2141                     StringBuilder message = new StringBuilder();
   2142                     message.append("Input inV: ");
   2143                     message.append(String.format("0x%x", args.inV));
   2144                     message.append("\n");
   2145                     message.append("Expected output out: ");
   2146                     message.append(String.format("%d", args.out));
   2147                     message.append("\n");
   2148                     message.append("Actual   output out: ");
   2149                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   2150                     if (args.out != arrayOut[i * 4 + j]) {
   2151                         message.append(" FAIL");
   2152                     }
   2153                     message.append("\n");
   2154                     assertTrue("Incorrect output for checkConvertUshort4Char4" +
   2155                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   2156                 }
   2157             }
   2158         }
   2159     }
   2160 
   2161     public class ArgumentsIntChar {
   2162         public int inV;
   2163         public byte out;
   2164     }
   2165 
   2166     private void checkConvertInt2Char2() {
   2167         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_32, 2, 0xd74f5147364256dfl, true, 7);
   2168         try {
   2169             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 2), INPUTSIZE);
   2170             script.forEach_testConvertChar2Int2Char2(inV, out);
   2171             verifyResultsConvertInt2Char2(inV, out, false);
   2172         } catch (Exception e) {
   2173             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar2Int2Char2: " + e.toString());
   2174         }
   2175         try {
   2176             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 2), INPUTSIZE);
   2177             scriptRelaxed.forEach_testConvertChar2Int2Char2(inV, out);
   2178             verifyResultsConvertInt2Char2(inV, out, true);
   2179         } catch (Exception e) {
   2180             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar2Int2Char2: " + e.toString());
   2181         }
   2182     }
   2183 
   2184     private void verifyResultsConvertInt2Char2(Allocation inV, Allocation out, boolean relaxed) {
   2185         int[] arrayInV = new int[INPUTSIZE * 2];
   2186         inV.copyTo(arrayInV);
   2187         byte[] arrayOut = new byte[INPUTSIZE * 2];
   2188         out.copyTo(arrayOut);
   2189         for (int i = 0; i < INPUTSIZE; i++) {
   2190             for (int j = 0; j < 2 ; j++) {
   2191                 // Extract the inputs.
   2192                 ArgumentsIntChar args = new ArgumentsIntChar();
   2193                 args.inV = arrayInV[i * 2 + j];
   2194                 // Figure out what the outputs should have been.
   2195                 CoreMathVerifier.computeConvert(args);
   2196                 // Validate the outputs.
   2197                 boolean valid = true;
   2198                 if (args.out != arrayOut[i * 2 + j]) {
   2199                     valid = false;
   2200                 }
   2201                 if (!valid) {
   2202                     StringBuilder message = new StringBuilder();
   2203                     message.append("Input inV: ");
   2204                     message.append(String.format("%d", args.inV));
   2205                     message.append("\n");
   2206                     message.append("Expected output out: ");
   2207                     message.append(String.format("%d", args.out));
   2208                     message.append("\n");
   2209                     message.append("Actual   output out: ");
   2210                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   2211                     if (args.out != arrayOut[i * 2 + j]) {
   2212                         message.append(" FAIL");
   2213                     }
   2214                     message.append("\n");
   2215                     assertTrue("Incorrect output for checkConvertInt2Char2" +
   2216                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   2217                 }
   2218             }
   2219         }
   2220     }
   2221 
   2222     private void checkConvertInt3Char3() {
   2223         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_32, 3, 0xd74f5be8954a1bd3l, true, 7);
   2224         try {
   2225             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 3), INPUTSIZE);
   2226             script.forEach_testConvertChar3Int3Char3(inV, out);
   2227             verifyResultsConvertInt3Char3(inV, out, false);
   2228         } catch (Exception e) {
   2229             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar3Int3Char3: " + e.toString());
   2230         }
   2231         try {
   2232             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 3), INPUTSIZE);
   2233             scriptRelaxed.forEach_testConvertChar3Int3Char3(inV, out);
   2234             verifyResultsConvertInt3Char3(inV, out, true);
   2235         } catch (Exception e) {
   2236             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar3Int3Char3: " + e.toString());
   2237         }
   2238     }
   2239 
   2240     private void verifyResultsConvertInt3Char3(Allocation inV, Allocation out, boolean relaxed) {
   2241         int[] arrayInV = new int[INPUTSIZE * 4];
   2242         inV.copyTo(arrayInV);
   2243         byte[] arrayOut = new byte[INPUTSIZE * 4];
   2244         out.copyTo(arrayOut);
   2245         for (int i = 0; i < INPUTSIZE; i++) {
   2246             for (int j = 0; j < 3 ; j++) {
   2247                 // Extract the inputs.
   2248                 ArgumentsIntChar args = new ArgumentsIntChar();
   2249                 args.inV = arrayInV[i * 4 + j];
   2250                 // Figure out what the outputs should have been.
   2251                 CoreMathVerifier.computeConvert(args);
   2252                 // Validate the outputs.
   2253                 boolean valid = true;
   2254                 if (args.out != arrayOut[i * 4 + j]) {
   2255                     valid = false;
   2256                 }
   2257                 if (!valid) {
   2258                     StringBuilder message = new StringBuilder();
   2259                     message.append("Input inV: ");
   2260                     message.append(String.format("%d", args.inV));
   2261                     message.append("\n");
   2262                     message.append("Expected output out: ");
   2263                     message.append(String.format("%d", args.out));
   2264                     message.append("\n");
   2265                     message.append("Actual   output out: ");
   2266                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   2267                     if (args.out != arrayOut[i * 4 + j]) {
   2268                         message.append(" FAIL");
   2269                     }
   2270                     message.append("\n");
   2271                     assertTrue("Incorrect output for checkConvertInt3Char3" +
   2272                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   2273                 }
   2274             }
   2275         }
   2276     }
   2277 
   2278     private void checkConvertInt4Char4() {
   2279         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_32, 4, 0xd74f6689f451e0c7l, true, 7);
   2280         try {
   2281             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 4), INPUTSIZE);
   2282             script.forEach_testConvertChar4Int4Char4(inV, out);
   2283             verifyResultsConvertInt4Char4(inV, out, false);
   2284         } catch (Exception e) {
   2285             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar4Int4Char4: " + e.toString());
   2286         }
   2287         try {
   2288             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 4), INPUTSIZE);
   2289             scriptRelaxed.forEach_testConvertChar4Int4Char4(inV, out);
   2290             verifyResultsConvertInt4Char4(inV, out, true);
   2291         } catch (Exception e) {
   2292             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar4Int4Char4: " + e.toString());
   2293         }
   2294     }
   2295 
   2296     private void verifyResultsConvertInt4Char4(Allocation inV, Allocation out, boolean relaxed) {
   2297         int[] arrayInV = new int[INPUTSIZE * 4];
   2298         inV.copyTo(arrayInV);
   2299         byte[] arrayOut = new byte[INPUTSIZE * 4];
   2300         out.copyTo(arrayOut);
   2301         for (int i = 0; i < INPUTSIZE; i++) {
   2302             for (int j = 0; j < 4 ; j++) {
   2303                 // Extract the inputs.
   2304                 ArgumentsIntChar args = new ArgumentsIntChar();
   2305                 args.inV = arrayInV[i * 4 + j];
   2306                 // Figure out what the outputs should have been.
   2307                 CoreMathVerifier.computeConvert(args);
   2308                 // Validate the outputs.
   2309                 boolean valid = true;
   2310                 if (args.out != arrayOut[i * 4 + j]) {
   2311                     valid = false;
   2312                 }
   2313                 if (!valid) {
   2314                     StringBuilder message = new StringBuilder();
   2315                     message.append("Input inV: ");
   2316                     message.append(String.format("%d", args.inV));
   2317                     message.append("\n");
   2318                     message.append("Expected output out: ");
   2319                     message.append(String.format("%d", args.out));
   2320                     message.append("\n");
   2321                     message.append("Actual   output out: ");
   2322                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   2323                     if (args.out != arrayOut[i * 4 + j]) {
   2324                         message.append(" FAIL");
   2325                     }
   2326                     message.append("\n");
   2327                     assertTrue("Incorrect output for checkConvertInt4Char4" +
   2328                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   2329                 }
   2330             }
   2331         }
   2332     }
   2333 
   2334     public class ArgumentsUintChar {
   2335         public int inV;
   2336         public byte out;
   2337     }
   2338 
   2339     private void checkConvertUint2Char2() {
   2340         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_32, 2, 0xe71d083133b67ae2l, false, 7);
   2341         try {
   2342             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 2), INPUTSIZE);
   2343             script.forEach_testConvertChar2Uint2Char2(inV, out);
   2344             verifyResultsConvertUint2Char2(inV, out, false);
   2345         } catch (Exception e) {
   2346             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar2Uint2Char2: " + e.toString());
   2347         }
   2348         try {
   2349             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 2), INPUTSIZE);
   2350             scriptRelaxed.forEach_testConvertChar2Uint2Char2(inV, out);
   2351             verifyResultsConvertUint2Char2(inV, out, true);
   2352         } catch (Exception e) {
   2353             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar2Uint2Char2: " + e.toString());
   2354         }
   2355     }
   2356 
   2357     private void verifyResultsConvertUint2Char2(Allocation inV, Allocation out, boolean relaxed) {
   2358         int[] arrayInV = new int[INPUTSIZE * 2];
   2359         inV.copyTo(arrayInV);
   2360         byte[] arrayOut = new byte[INPUTSIZE * 2];
   2361         out.copyTo(arrayOut);
   2362         for (int i = 0; i < INPUTSIZE; i++) {
   2363             for (int j = 0; j < 2 ; j++) {
   2364                 // Extract the inputs.
   2365                 ArgumentsUintChar args = new ArgumentsUintChar();
   2366                 args.inV = arrayInV[i * 2 + j];
   2367                 // Figure out what the outputs should have been.
   2368                 CoreMathVerifier.computeConvert(args);
   2369                 // Validate the outputs.
   2370                 boolean valid = true;
   2371                 if (args.out != arrayOut[i * 2 + j]) {
   2372                     valid = false;
   2373                 }
   2374                 if (!valid) {
   2375                     StringBuilder message = new StringBuilder();
   2376                     message.append("Input inV: ");
   2377                     message.append(String.format("0x%x", args.inV));
   2378                     message.append("\n");
   2379                     message.append("Expected output out: ");
   2380                     message.append(String.format("%d", args.out));
   2381                     message.append("\n");
   2382                     message.append("Actual   output out: ");
   2383                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   2384                     if (args.out != arrayOut[i * 2 + j]) {
   2385                         message.append(" FAIL");
   2386                     }
   2387                     message.append("\n");
   2388                     assertTrue("Incorrect output for checkConvertUint2Char2" +
   2389                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   2390                 }
   2391             }
   2392         }
   2393     }
   2394 
   2395     private void checkConvertUint3Char3() {
   2396         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_32, 3, 0xe71d12d292be3fd6l, false, 7);
   2397         try {
   2398             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 3), INPUTSIZE);
   2399             script.forEach_testConvertChar3Uint3Char3(inV, out);
   2400             verifyResultsConvertUint3Char3(inV, out, false);
   2401         } catch (Exception e) {
   2402             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar3Uint3Char3: " + e.toString());
   2403         }
   2404         try {
   2405             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 3), INPUTSIZE);
   2406             scriptRelaxed.forEach_testConvertChar3Uint3Char3(inV, out);
   2407             verifyResultsConvertUint3Char3(inV, out, true);
   2408         } catch (Exception e) {
   2409             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar3Uint3Char3: " + e.toString());
   2410         }
   2411     }
   2412 
   2413     private void verifyResultsConvertUint3Char3(Allocation inV, Allocation out, boolean relaxed) {
   2414         int[] arrayInV = new int[INPUTSIZE * 4];
   2415         inV.copyTo(arrayInV);
   2416         byte[] arrayOut = new byte[INPUTSIZE * 4];
   2417         out.copyTo(arrayOut);
   2418         for (int i = 0; i < INPUTSIZE; i++) {
   2419             for (int j = 0; j < 3 ; j++) {
   2420                 // Extract the inputs.
   2421                 ArgumentsUintChar args = new ArgumentsUintChar();
   2422                 args.inV = arrayInV[i * 4 + j];
   2423                 // Figure out what the outputs should have been.
   2424                 CoreMathVerifier.computeConvert(args);
   2425                 // Validate the outputs.
   2426                 boolean valid = true;
   2427                 if (args.out != arrayOut[i * 4 + j]) {
   2428                     valid = false;
   2429                 }
   2430                 if (!valid) {
   2431                     StringBuilder message = new StringBuilder();
   2432                     message.append("Input inV: ");
   2433                     message.append(String.format("0x%x", args.inV));
   2434                     message.append("\n");
   2435                     message.append("Expected output out: ");
   2436                     message.append(String.format("%d", args.out));
   2437                     message.append("\n");
   2438                     message.append("Actual   output out: ");
   2439                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   2440                     if (args.out != arrayOut[i * 4 + j]) {
   2441                         message.append(" FAIL");
   2442                     }
   2443                     message.append("\n");
   2444                     assertTrue("Incorrect output for checkConvertUint3Char3" +
   2445                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   2446                 }
   2447             }
   2448         }
   2449     }
   2450 
   2451     private void checkConvertUint4Char4() {
   2452         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_32, 4, 0xe71d1d73f1c604cal, false, 7);
   2453         try {
   2454             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 4), INPUTSIZE);
   2455             script.forEach_testConvertChar4Uint4Char4(inV, out);
   2456             verifyResultsConvertUint4Char4(inV, out, false);
   2457         } catch (Exception e) {
   2458             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar4Uint4Char4: " + e.toString());
   2459         }
   2460         try {
   2461             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 4), INPUTSIZE);
   2462             scriptRelaxed.forEach_testConvertChar4Uint4Char4(inV, out);
   2463             verifyResultsConvertUint4Char4(inV, out, true);
   2464         } catch (Exception e) {
   2465             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar4Uint4Char4: " + e.toString());
   2466         }
   2467     }
   2468 
   2469     private void verifyResultsConvertUint4Char4(Allocation inV, Allocation out, boolean relaxed) {
   2470         int[] arrayInV = new int[INPUTSIZE * 4];
   2471         inV.copyTo(arrayInV);
   2472         byte[] arrayOut = new byte[INPUTSIZE * 4];
   2473         out.copyTo(arrayOut);
   2474         for (int i = 0; i < INPUTSIZE; i++) {
   2475             for (int j = 0; j < 4 ; j++) {
   2476                 // Extract the inputs.
   2477                 ArgumentsUintChar args = new ArgumentsUintChar();
   2478                 args.inV = arrayInV[i * 4 + j];
   2479                 // Figure out what the outputs should have been.
   2480                 CoreMathVerifier.computeConvert(args);
   2481                 // Validate the outputs.
   2482                 boolean valid = true;
   2483                 if (args.out != arrayOut[i * 4 + j]) {
   2484                     valid = false;
   2485                 }
   2486                 if (!valid) {
   2487                     StringBuilder message = new StringBuilder();
   2488                     message.append("Input inV: ");
   2489                     message.append(String.format("0x%x", args.inV));
   2490                     message.append("\n");
   2491                     message.append("Expected output out: ");
   2492                     message.append(String.format("%d", args.out));
   2493                     message.append("\n");
   2494                     message.append("Actual   output out: ");
   2495                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   2496                     if (args.out != arrayOut[i * 4 + j]) {
   2497                         message.append(" FAIL");
   2498                     }
   2499                     message.append("\n");
   2500                     assertTrue("Incorrect output for checkConvertUint4Char4" +
   2501                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   2502                 }
   2503             }
   2504         }
   2505     }
   2506 
   2507     public class ArgumentsFloatUchar {
   2508         public float inV;
   2509         public byte out;
   2510     }
   2511 
   2512     private void checkConvertFloat2Uchar2() {
   2513         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xfb52b2f4fac15b79l, 0.0000000000000000000e+00, 2.5500000000000000000e+02);
   2514         try {
   2515             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE);
   2516             script.forEach_testConvertUchar2Float2Uchar2(inV, out);
   2517             verifyResultsConvertFloat2Uchar2(inV, out, false);
   2518         } catch (Exception e) {
   2519             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar2Float2Uchar2: " + e.toString());
   2520         }
   2521         try {
   2522             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE);
   2523             scriptRelaxed.forEach_testConvertUchar2Float2Uchar2(inV, out);
   2524             verifyResultsConvertFloat2Uchar2(inV, out, true);
   2525         } catch (Exception e) {
   2526             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar2Float2Uchar2: " + e.toString());
   2527         }
   2528     }
   2529 
   2530     private void verifyResultsConvertFloat2Uchar2(Allocation inV, Allocation out, boolean relaxed) {
   2531         float[] arrayInV = new float[INPUTSIZE * 2];
   2532         inV.copyTo(arrayInV);
   2533         byte[] arrayOut = new byte[INPUTSIZE * 2];
   2534         out.copyTo(arrayOut);
   2535         for (int i = 0; i < INPUTSIZE; i++) {
   2536             for (int j = 0; j < 2 ; j++) {
   2537                 // Extract the inputs.
   2538                 ArgumentsFloatUchar args = new ArgumentsFloatUchar();
   2539                 args.inV = arrayInV[i * 2 + j];
   2540                 // Figure out what the outputs should have been.
   2541                 CoreMathVerifier.computeConvert(args);
   2542                 // Validate the outputs.
   2543                 boolean valid = true;
   2544                 if (args.out != arrayOut[i * 2 + j]) {
   2545                     valid = false;
   2546                 }
   2547                 if (!valid) {
   2548                     StringBuilder message = new StringBuilder();
   2549                     message.append("Input inV: ");
   2550                     message.append(String.format("%14.8g {%8x} %15a",
   2551                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
   2552                     message.append("\n");
   2553                     message.append("Expected output out: ");
   2554                     message.append(String.format("0x%x", args.out));
   2555                     message.append("\n");
   2556                     message.append("Actual   output out: ");
   2557                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   2558                     if (args.out != arrayOut[i * 2 + j]) {
   2559                         message.append(" FAIL");
   2560                     }
   2561                     message.append("\n");
   2562                     assertTrue("Incorrect output for checkConvertFloat2Uchar2" +
   2563                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   2564                 }
   2565             }
   2566         }
   2567     }
   2568 
   2569     private void checkConvertFloat3Uchar3() {
   2570         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xfb547c0ff0dc7c57l, 0.0000000000000000000e+00, 2.5500000000000000000e+02);
   2571         try {
   2572             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE);
   2573             script.forEach_testConvertUchar3Float3Uchar3(inV, out);
   2574             verifyResultsConvertFloat3Uchar3(inV, out, false);
   2575         } catch (Exception e) {
   2576             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar3Float3Uchar3: " + e.toString());
   2577         }
   2578         try {
   2579             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE);
   2580             scriptRelaxed.forEach_testConvertUchar3Float3Uchar3(inV, out);
   2581             verifyResultsConvertFloat3Uchar3(inV, out, true);
   2582         } catch (Exception e) {
   2583             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar3Float3Uchar3: " + e.toString());
   2584         }
   2585     }
   2586 
   2587     private void verifyResultsConvertFloat3Uchar3(Allocation inV, Allocation out, boolean relaxed) {
   2588         float[] arrayInV = new float[INPUTSIZE * 4];
   2589         inV.copyTo(arrayInV);
   2590         byte[] arrayOut = new byte[INPUTSIZE * 4];
   2591         out.copyTo(arrayOut);
   2592         for (int i = 0; i < INPUTSIZE; i++) {
   2593             for (int j = 0; j < 3 ; j++) {
   2594                 // Extract the inputs.
   2595                 ArgumentsFloatUchar args = new ArgumentsFloatUchar();
   2596                 args.inV = arrayInV[i * 4 + j];
   2597                 // Figure out what the outputs should have been.
   2598                 CoreMathVerifier.computeConvert(args);
   2599                 // Validate the outputs.
   2600                 boolean valid = true;
   2601                 if (args.out != arrayOut[i * 4 + j]) {
   2602                     valid = false;
   2603                 }
   2604                 if (!valid) {
   2605                     StringBuilder message = new StringBuilder();
   2606                     message.append("Input inV: ");
   2607                     message.append(String.format("%14.8g {%8x} %15a",
   2608                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
   2609                     message.append("\n");
   2610                     message.append("Expected output out: ");
   2611                     message.append(String.format("0x%x", args.out));
   2612                     message.append("\n");
   2613                     message.append("Actual   output out: ");
   2614                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   2615                     if (args.out != arrayOut[i * 4 + j]) {
   2616                         message.append(" FAIL");
   2617                     }
   2618                     message.append("\n");
   2619                     assertTrue("Incorrect output for checkConvertFloat3Uchar3" +
   2620                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   2621                 }
   2622             }
   2623         }
   2624     }
   2625 
   2626     private void checkConvertFloat4Uchar4() {
   2627         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xfb56452ae6f79d35l, 0.0000000000000000000e+00, 2.5500000000000000000e+02);
   2628         try {
   2629             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE);
   2630             script.forEach_testConvertUchar4Float4Uchar4(inV, out);
   2631             verifyResultsConvertFloat4Uchar4(inV, out, false);
   2632         } catch (Exception e) {
   2633             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar4Float4Uchar4: " + e.toString());
   2634         }
   2635         try {
   2636             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE);
   2637             scriptRelaxed.forEach_testConvertUchar4Float4Uchar4(inV, out);
   2638             verifyResultsConvertFloat4Uchar4(inV, out, true);
   2639         } catch (Exception e) {
   2640             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar4Float4Uchar4: " + e.toString());
   2641         }
   2642     }
   2643 
   2644     private void verifyResultsConvertFloat4Uchar4(Allocation inV, Allocation out, boolean relaxed) {
   2645         float[] arrayInV = new float[INPUTSIZE * 4];
   2646         inV.copyTo(arrayInV);
   2647         byte[] arrayOut = new byte[INPUTSIZE * 4];
   2648         out.copyTo(arrayOut);
   2649         for (int i = 0; i < INPUTSIZE; i++) {
   2650             for (int j = 0; j < 4 ; j++) {
   2651                 // Extract the inputs.
   2652                 ArgumentsFloatUchar args = new ArgumentsFloatUchar();
   2653                 args.inV = arrayInV[i * 4 + j];
   2654                 // Figure out what the outputs should have been.
   2655                 CoreMathVerifier.computeConvert(args);
   2656                 // Validate the outputs.
   2657                 boolean valid = true;
   2658                 if (args.out != arrayOut[i * 4 + j]) {
   2659                     valid = false;
   2660                 }
   2661                 if (!valid) {
   2662                     StringBuilder message = new StringBuilder();
   2663                     message.append("Input inV: ");
   2664                     message.append(String.format("%14.8g {%8x} %15a",
   2665                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
   2666                     message.append("\n");
   2667                     message.append("Expected output out: ");
   2668                     message.append(String.format("0x%x", args.out));
   2669                     message.append("\n");
   2670                     message.append("Actual   output out: ");
   2671                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   2672                     if (args.out != arrayOut[i * 4 + j]) {
   2673                         message.append(" FAIL");
   2674                     }
   2675                     message.append("\n");
   2676                     assertTrue("Incorrect output for checkConvertFloat4Uchar4" +
   2677                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   2678                 }
   2679             }
   2680         }
   2681     }
   2682 
   2683     public class ArgumentsCharUchar {
   2684         public byte inV;
   2685         public byte out;
   2686     }
   2687 
   2688     private void checkConvertChar2Uchar2() {
   2689         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_8, 2, 0x58627f46cbea8339l, false, 7);
   2690         try {
   2691             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE);
   2692             script.forEach_testConvertUchar2Char2Uchar2(inV, out);
   2693             verifyResultsConvertChar2Uchar2(inV, out, false);
   2694         } catch (Exception e) {
   2695             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar2Char2Uchar2: " + e.toString());
   2696         }
   2697         try {
   2698             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE);
   2699             scriptRelaxed.forEach_testConvertUchar2Char2Uchar2(inV, out);
   2700             verifyResultsConvertChar2Uchar2(inV, out, true);
   2701         } catch (Exception e) {
   2702             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar2Char2Uchar2: " + e.toString());
   2703         }
   2704     }
   2705 
   2706     private void verifyResultsConvertChar2Uchar2(Allocation inV, Allocation out, boolean relaxed) {
   2707         byte[] arrayInV = new byte[INPUTSIZE * 2];
   2708         inV.copyTo(arrayInV);
   2709         byte[] arrayOut = new byte[INPUTSIZE * 2];
   2710         out.copyTo(arrayOut);
   2711         for (int i = 0; i < INPUTSIZE; i++) {
   2712             for (int j = 0; j < 2 ; j++) {
   2713                 // Extract the inputs.
   2714                 ArgumentsCharUchar args = new ArgumentsCharUchar();
   2715                 args.inV = arrayInV[i * 2 + j];
   2716                 // Figure out what the outputs should have been.
   2717                 CoreMathVerifier.computeConvert(args);
   2718                 // Validate the outputs.
   2719                 boolean valid = true;
   2720                 if (args.out != arrayOut[i * 2 + j]) {
   2721                     valid = false;
   2722                 }
   2723                 if (!valid) {
   2724                     StringBuilder message = new StringBuilder();
   2725                     message.append("Input inV: ");
   2726                     message.append(String.format("%d", args.inV));
   2727                     message.append("\n");
   2728                     message.append("Expected output out: ");
   2729                     message.append(String.format("0x%x", args.out));
   2730                     message.append("\n");
   2731                     message.append("Actual   output out: ");
   2732                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   2733                     if (args.out != arrayOut[i * 2 + j]) {
   2734                         message.append(" FAIL");
   2735                     }
   2736                     message.append("\n");
   2737                     assertTrue("Incorrect output for checkConvertChar2Uchar2" +
   2738                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   2739                 }
   2740             }
   2741         }
   2742     }
   2743 
   2744     private void checkConvertChar3Uchar3() {
   2745         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_8, 3, 0x58644861c205a417l, false, 7);
   2746         try {
   2747             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE);
   2748             script.forEach_testConvertUchar3Char3Uchar3(inV, out);
   2749             verifyResultsConvertChar3Uchar3(inV, out, false);
   2750         } catch (Exception e) {
   2751             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar3Char3Uchar3: " + e.toString());
   2752         }
   2753         try {
   2754             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE);
   2755             scriptRelaxed.forEach_testConvertUchar3Char3Uchar3(inV, out);
   2756             verifyResultsConvertChar3Uchar3(inV, out, true);
   2757         } catch (Exception e) {
   2758             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar3Char3Uchar3: " + e.toString());
   2759         }
   2760     }
   2761 
   2762     private void verifyResultsConvertChar3Uchar3(Allocation inV, Allocation out, boolean relaxed) {
   2763         byte[] arrayInV = new byte[INPUTSIZE * 4];
   2764         inV.copyTo(arrayInV);
   2765         byte[] arrayOut = new byte[INPUTSIZE * 4];
   2766         out.copyTo(arrayOut);
   2767         for (int i = 0; i < INPUTSIZE; i++) {
   2768             for (int j = 0; j < 3 ; j++) {
   2769                 // Extract the inputs.
   2770                 ArgumentsCharUchar args = new ArgumentsCharUchar();
   2771                 args.inV = arrayInV[i * 4 + j];
   2772                 // Figure out what the outputs should have been.
   2773                 CoreMathVerifier.computeConvert(args);
   2774                 // Validate the outputs.
   2775                 boolean valid = true;
   2776                 if (args.out != arrayOut[i * 4 + j]) {
   2777                     valid = false;
   2778                 }
   2779                 if (!valid) {
   2780                     StringBuilder message = new StringBuilder();
   2781                     message.append("Input inV: ");
   2782                     message.append(String.format("%d", args.inV));
   2783                     message.append("\n");
   2784                     message.append("Expected output out: ");
   2785                     message.append(String.format("0x%x", args.out));
   2786                     message.append("\n");
   2787                     message.append("Actual   output out: ");
   2788                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   2789                     if (args.out != arrayOut[i * 4 + j]) {
   2790                         message.append(" FAIL");
   2791                     }
   2792                     message.append("\n");
   2793                     assertTrue("Incorrect output for checkConvertChar3Uchar3" +
   2794                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   2795                 }
   2796             }
   2797         }
   2798     }
   2799 
   2800     private void checkConvertChar4Uchar4() {
   2801         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_8, 4, 0x5866117cb820c4f5l, false, 7);
   2802         try {
   2803             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE);
   2804             script.forEach_testConvertUchar4Char4Uchar4(inV, out);
   2805             verifyResultsConvertChar4Uchar4(inV, out, false);
   2806         } catch (Exception e) {
   2807             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar4Char4Uchar4: " + e.toString());
   2808         }
   2809         try {
   2810             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE);
   2811             scriptRelaxed.forEach_testConvertUchar4Char4Uchar4(inV, out);
   2812             verifyResultsConvertChar4Uchar4(inV, out, true);
   2813         } catch (Exception e) {
   2814             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar4Char4Uchar4: " + e.toString());
   2815         }
   2816     }
   2817 
   2818     private void verifyResultsConvertChar4Uchar4(Allocation inV, Allocation out, boolean relaxed) {
   2819         byte[] arrayInV = new byte[INPUTSIZE * 4];
   2820         inV.copyTo(arrayInV);
   2821         byte[] arrayOut = new byte[INPUTSIZE * 4];
   2822         out.copyTo(arrayOut);
   2823         for (int i = 0; i < INPUTSIZE; i++) {
   2824             for (int j = 0; j < 4 ; j++) {
   2825                 // Extract the inputs.
   2826                 ArgumentsCharUchar args = new ArgumentsCharUchar();
   2827                 args.inV = arrayInV[i * 4 + j];
   2828                 // Figure out what the outputs should have been.
   2829                 CoreMathVerifier.computeConvert(args);
   2830                 // Validate the outputs.
   2831                 boolean valid = true;
   2832                 if (args.out != arrayOut[i * 4 + j]) {
   2833                     valid = false;
   2834                 }
   2835                 if (!valid) {
   2836                     StringBuilder message = new StringBuilder();
   2837                     message.append("Input inV: ");
   2838                     message.append(String.format("%d", args.inV));
   2839                     message.append("\n");
   2840                     message.append("Expected output out: ");
   2841                     message.append(String.format("0x%x", args.out));
   2842                     message.append("\n");
   2843                     message.append("Actual   output out: ");
   2844                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   2845                     if (args.out != arrayOut[i * 4 + j]) {
   2846                         message.append(" FAIL");
   2847                     }
   2848                     message.append("\n");
   2849                     assertTrue("Incorrect output for checkConvertChar4Uchar4" +
   2850                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   2851                 }
   2852             }
   2853         }
   2854     }
   2855 
   2856     public class ArgumentsUcharUchar {
   2857         public byte inV;
   2858         public byte out;
   2859     }
   2860 
   2861     private void checkConvertUchar2Uchar2() {
   2862         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_8, 2, 0x7d309f4e67c29ce4l, false, 8);
   2863         try {
   2864             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE);
   2865             script.forEach_testConvertUchar2Uchar2Uchar2(inV, out);
   2866             verifyResultsConvertUchar2Uchar2(inV, out, false);
   2867         } catch (Exception e) {
   2868             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar2Uchar2Uchar2: " + e.toString());
   2869         }
   2870         try {
   2871             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE);
   2872             scriptRelaxed.forEach_testConvertUchar2Uchar2Uchar2(inV, out);
   2873             verifyResultsConvertUchar2Uchar2(inV, out, true);
   2874         } catch (Exception e) {
   2875             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar2Uchar2Uchar2: " + e.toString());
   2876         }
   2877     }
   2878 
   2879     private void verifyResultsConvertUchar2Uchar2(Allocation inV, Allocation out, boolean relaxed) {
   2880         byte[] arrayInV = new byte[INPUTSIZE * 2];
   2881         inV.copyTo(arrayInV);
   2882         byte[] arrayOut = new byte[INPUTSIZE * 2];
   2883         out.copyTo(arrayOut);
   2884         for (int i = 0; i < INPUTSIZE; i++) {
   2885             for (int j = 0; j < 2 ; j++) {
   2886                 // Extract the inputs.
   2887                 ArgumentsUcharUchar args = new ArgumentsUcharUchar();
   2888                 args.inV = arrayInV[i * 2 + j];
   2889                 // Figure out what the outputs should have been.
   2890                 CoreMathVerifier.computeConvert(args);
   2891                 // Validate the outputs.
   2892                 boolean valid = true;
   2893                 if (args.out != arrayOut[i * 2 + j]) {
   2894                     valid = false;
   2895                 }
   2896                 if (!valid) {
   2897                     StringBuilder message = new StringBuilder();
   2898                     message.append("Input inV: ");
   2899                     message.append(String.format("0x%x", args.inV));
   2900                     message.append("\n");
   2901                     message.append("Expected output out: ");
   2902                     message.append(String.format("0x%x", args.out));
   2903                     message.append("\n");
   2904                     message.append("Actual   output out: ");
   2905                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   2906                     if (args.out != arrayOut[i * 2 + j]) {
   2907                         message.append(" FAIL");
   2908                     }
   2909                     message.append("\n");
   2910                     assertTrue("Incorrect output for checkConvertUchar2Uchar2" +
   2911                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   2912                 }
   2913             }
   2914         }
   2915     }
   2916 
   2917     private void checkConvertUchar3Uchar3() {
   2918         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_8, 3, 0x7d3268695dddbdc2l, false, 8);
   2919         try {
   2920             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE);
   2921             script.forEach_testConvertUchar3Uchar3Uchar3(inV, out);
   2922             verifyResultsConvertUchar3Uchar3(inV, out, false);
   2923         } catch (Exception e) {
   2924             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar3Uchar3Uchar3: " + e.toString());
   2925         }
   2926         try {
   2927             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE);
   2928             scriptRelaxed.forEach_testConvertUchar3Uchar3Uchar3(inV, out);
   2929             verifyResultsConvertUchar3Uchar3(inV, out, true);
   2930         } catch (Exception e) {
   2931             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar3Uchar3Uchar3: " + e.toString());
   2932         }
   2933     }
   2934 
   2935     private void verifyResultsConvertUchar3Uchar3(Allocation inV, Allocation out, boolean relaxed) {
   2936         byte[] arrayInV = new byte[INPUTSIZE * 4];
   2937         inV.copyTo(arrayInV);
   2938         byte[] arrayOut = new byte[INPUTSIZE * 4];
   2939         out.copyTo(arrayOut);
   2940         for (int i = 0; i < INPUTSIZE; i++) {
   2941             for (int j = 0; j < 3 ; j++) {
   2942                 // Extract the inputs.
   2943                 ArgumentsUcharUchar args = new ArgumentsUcharUchar();
   2944                 args.inV = arrayInV[i * 4 + j];
   2945                 // Figure out what the outputs should have been.
   2946                 CoreMathVerifier.computeConvert(args);
   2947                 // Validate the outputs.
   2948                 boolean valid = true;
   2949                 if (args.out != arrayOut[i * 4 + j]) {
   2950                     valid = false;
   2951                 }
   2952                 if (!valid) {
   2953                     StringBuilder message = new StringBuilder();
   2954                     message.append("Input inV: ");
   2955                     message.append(String.format("0x%x", args.inV));
   2956                     message.append("\n");
   2957                     message.append("Expected output out: ");
   2958                     message.append(String.format("0x%x", args.out));
   2959                     message.append("\n");
   2960                     message.append("Actual   output out: ");
   2961                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   2962                     if (args.out != arrayOut[i * 4 + j]) {
   2963                         message.append(" FAIL");
   2964                     }
   2965                     message.append("\n");
   2966                     assertTrue("Incorrect output for checkConvertUchar3Uchar3" +
   2967                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   2968                 }
   2969             }
   2970         }
   2971     }
   2972 
   2973     private void checkConvertUchar4Uchar4() {
   2974         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_8, 4, 0x7d34318453f8dea0l, false, 8);
   2975         try {
   2976             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE);
   2977             script.forEach_testConvertUchar4Uchar4Uchar4(inV, out);
   2978             verifyResultsConvertUchar4Uchar4(inV, out, false);
   2979         } catch (Exception e) {
   2980             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar4Uchar4Uchar4: " + e.toString());
   2981         }
   2982         try {
   2983             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE);
   2984             scriptRelaxed.forEach_testConvertUchar4Uchar4Uchar4(inV, out);
   2985             verifyResultsConvertUchar4Uchar4(inV, out, true);
   2986         } catch (Exception e) {
   2987             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar4Uchar4Uchar4: " + e.toString());
   2988         }
   2989     }
   2990 
   2991     private void verifyResultsConvertUchar4Uchar4(Allocation inV, Allocation out, boolean relaxed) {
   2992         byte[] arrayInV = new byte[INPUTSIZE * 4];
   2993         inV.copyTo(arrayInV);
   2994         byte[] arrayOut = new byte[INPUTSIZE * 4];
   2995         out.copyTo(arrayOut);
   2996         for (int i = 0; i < INPUTSIZE; i++) {
   2997             for (int j = 0; j < 4 ; j++) {
   2998                 // Extract the inputs.
   2999                 ArgumentsUcharUchar args = new ArgumentsUcharUchar();
   3000                 args.inV = arrayInV[i * 4 + j];
   3001                 // Figure out what the outputs should have been.
   3002                 CoreMathVerifier.computeConvert(args);
   3003                 // Validate the outputs.
   3004                 boolean valid = true;
   3005                 if (args.out != arrayOut[i * 4 + j]) {
   3006                     valid = false;
   3007                 }
   3008                 if (!valid) {
   3009                     StringBuilder message = new StringBuilder();
   3010                     message.append("Input inV: ");
   3011                     message.append(String.format("0x%x", args.inV));
   3012                     message.append("\n");
   3013                     message.append("Expected output out: ");
   3014                     message.append(String.format("0x%x", args.out));
   3015                     message.append("\n");
   3016                     message.append("Actual   output out: ");
   3017                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   3018                     if (args.out != arrayOut[i * 4 + j]) {
   3019                         message.append(" FAIL");
   3020                     }
   3021                     message.append("\n");
   3022                     assertTrue("Incorrect output for checkConvertUchar4Uchar4" +
   3023                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   3024                 }
   3025             }
   3026         }
   3027     }
   3028 
   3029     public class ArgumentsShortUchar {
   3030         public short inV;
   3031         public byte out;
   3032     }
   3033 
   3034     private void checkConvertShort2Uchar2() {
   3035         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_16, 2, 0x94cab57fabc38225l, false, 8);
   3036         try {
   3037             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE);
   3038             script.forEach_testConvertUchar2Short2Uchar2(inV, out);
   3039             verifyResultsConvertShort2Uchar2(inV, out, false);
   3040         } catch (Exception e) {
   3041             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar2Short2Uchar2: " + e.toString());
   3042         }
   3043         try {
   3044             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE);
   3045             scriptRelaxed.forEach_testConvertUchar2Short2Uchar2(inV, out);
   3046             verifyResultsConvertShort2Uchar2(inV, out, true);
   3047         } catch (Exception e) {
   3048             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar2Short2Uchar2: " + e.toString());
   3049         }
   3050     }
   3051 
   3052     private void verifyResultsConvertShort2Uchar2(Allocation inV, Allocation out, boolean relaxed) {
   3053         short[] arrayInV = new short[INPUTSIZE * 2];
   3054         inV.copyTo(arrayInV);
   3055         byte[] arrayOut = new byte[INPUTSIZE * 2];
   3056         out.copyTo(arrayOut);
   3057         for (int i = 0; i < INPUTSIZE; i++) {
   3058             for (int j = 0; j < 2 ; j++) {
   3059                 // Extract the inputs.
   3060                 ArgumentsShortUchar args = new ArgumentsShortUchar();
   3061                 args.inV = arrayInV[i * 2 + j];
   3062                 // Figure out what the outputs should have been.
   3063                 CoreMathVerifier.computeConvert(args);
   3064                 // Validate the outputs.
   3065                 boolean valid = true;
   3066                 if (args.out != arrayOut[i * 2 + j]) {
   3067                     valid = false;
   3068                 }
   3069                 if (!valid) {
   3070                     StringBuilder message = new StringBuilder();
   3071                     message.append("Input inV: ");
   3072                     message.append(String.format("%d", args.inV));
   3073                     message.append("\n");
   3074                     message.append("Expected output out: ");
   3075                     message.append(String.format("0x%x", args.out));
   3076                     message.append("\n");
   3077                     message.append("Actual   output out: ");
   3078                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   3079                     if (args.out != arrayOut[i * 2 + j]) {
   3080                         message.append(" FAIL");
   3081                     }
   3082                     message.append("\n");
   3083                     assertTrue("Incorrect output for checkConvertShort2Uchar2" +
   3084                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   3085                 }
   3086             }
   3087         }
   3088     }
   3089 
   3090     private void checkConvertShort3Uchar3() {
   3091         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_16, 3, 0x94cc7e9aa1dea303l, false, 8);
   3092         try {
   3093             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE);
   3094             script.forEach_testConvertUchar3Short3Uchar3(inV, out);
   3095             verifyResultsConvertShort3Uchar3(inV, out, false);
   3096         } catch (Exception e) {
   3097             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar3Short3Uchar3: " + e.toString());
   3098         }
   3099         try {
   3100             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE);
   3101             scriptRelaxed.forEach_testConvertUchar3Short3Uchar3(inV, out);
   3102             verifyResultsConvertShort3Uchar3(inV, out, true);
   3103         } catch (Exception e) {
   3104             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar3Short3Uchar3: " + e.toString());
   3105         }
   3106     }
   3107 
   3108     private void verifyResultsConvertShort3Uchar3(Allocation inV, Allocation out, boolean relaxed) {
   3109         short[] arrayInV = new short[INPUTSIZE * 4];
   3110         inV.copyTo(arrayInV);
   3111         byte[] arrayOut = new byte[INPUTSIZE * 4];
   3112         out.copyTo(arrayOut);
   3113         for (int i = 0; i < INPUTSIZE; i++) {
   3114             for (int j = 0; j < 3 ; j++) {
   3115                 // Extract the inputs.
   3116                 ArgumentsShortUchar args = new ArgumentsShortUchar();
   3117                 args.inV = arrayInV[i * 4 + j];
   3118                 // Figure out what the outputs should have been.
   3119                 CoreMathVerifier.computeConvert(args);
   3120                 // Validate the outputs.
   3121                 boolean valid = true;
   3122                 if (args.out != arrayOut[i * 4 + j]) {
   3123                     valid = false;
   3124                 }
   3125                 if (!valid) {
   3126                     StringBuilder message = new StringBuilder();
   3127                     message.append("Input inV: ");
   3128                     message.append(String.format("%d", args.inV));
   3129                     message.append("\n");
   3130                     message.append("Expected output out: ");
   3131                     message.append(String.format("0x%x", args.out));
   3132                     message.append("\n");
   3133                     message.append("Actual   output out: ");
   3134                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   3135                     if (args.out != arrayOut[i * 4 + j]) {
   3136                         message.append(" FAIL");
   3137                     }
   3138                     message.append("\n");
   3139                     assertTrue("Incorrect output for checkConvertShort3Uchar3" +
   3140                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   3141                 }
   3142             }
   3143         }
   3144     }
   3145 
   3146     private void checkConvertShort4Uchar4() {
   3147         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_16, 4, 0x94ce47b597f9c3e1l, false, 8);
   3148         try {
   3149             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE);
   3150             script.forEach_testConvertUchar4Short4Uchar4(inV, out);
   3151             verifyResultsConvertShort4Uchar4(inV, out, false);
   3152         } catch (Exception e) {
   3153             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar4Short4Uchar4: " + e.toString());
   3154         }
   3155         try {
   3156             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE);
   3157             scriptRelaxed.forEach_testConvertUchar4Short4Uchar4(inV, out);
   3158             verifyResultsConvertShort4Uchar4(inV, out, true);
   3159         } catch (Exception e) {
   3160             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar4Short4Uchar4: " + e.toString());
   3161         }
   3162     }
   3163 
   3164     private void verifyResultsConvertShort4Uchar4(Allocation inV, Allocation out, boolean relaxed) {
   3165         short[] arrayInV = new short[INPUTSIZE * 4];
   3166         inV.copyTo(arrayInV);
   3167         byte[] arrayOut = new byte[INPUTSIZE * 4];
   3168         out.copyTo(arrayOut);
   3169         for (int i = 0; i < INPUTSIZE; i++) {
   3170             for (int j = 0; j < 4 ; j++) {
   3171                 // Extract the inputs.
   3172                 ArgumentsShortUchar args = new ArgumentsShortUchar();
   3173                 args.inV = arrayInV[i * 4 + j];
   3174                 // Figure out what the outputs should have been.
   3175                 CoreMathVerifier.computeConvert(args);
   3176                 // Validate the outputs.
   3177                 boolean valid = true;
   3178                 if (args.out != arrayOut[i * 4 + j]) {
   3179                     valid = false;
   3180                 }
   3181                 if (!valid) {
   3182                     StringBuilder message = new StringBuilder();
   3183                     message.append("Input inV: ");
   3184                     message.append(String.format("%d", args.inV));
   3185                     message.append("\n");
   3186                     message.append("Expected output out: ");
   3187                     message.append(String.format("0x%x", args.out));
   3188                     message.append("\n");
   3189                     message.append("Actual   output out: ");
   3190                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   3191                     if (args.out != arrayOut[i * 4 + j]) {
   3192                         message.append(" FAIL");
   3193                     }
   3194                     message.append("\n");
   3195                     assertTrue("Incorrect output for checkConvertShort4Uchar4" +
   3196                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   3197                 }
   3198             }
   3199         }
   3200     }
   3201 
   3202     public class ArgumentsUshortUchar {
   3203         public short inV;
   3204         public byte out;
   3205     }
   3206 
   3207     private void checkConvertUshort2Uchar2() {
   3208         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_16, 2, 0xc36a16c6d90fd1del, false, 8);
   3209         try {
   3210             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE);
   3211             script.forEach_testConvertUchar2Ushort2Uchar2(inV, out);
   3212             verifyResultsConvertUshort2Uchar2(inV, out, false);
   3213         } catch (Exception e) {
   3214             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar2Ushort2Uchar2: " + e.toString());
   3215         }
   3216         try {
   3217             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE);
   3218             scriptRelaxed.forEach_testConvertUchar2Ushort2Uchar2(inV, out);
   3219             verifyResultsConvertUshort2Uchar2(inV, out, true);
   3220         } catch (Exception e) {
   3221             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar2Ushort2Uchar2: " + e.toString());
   3222         }
   3223     }
   3224 
   3225     private void verifyResultsConvertUshort2Uchar2(Allocation inV, Allocation out, boolean relaxed) {
   3226         short[] arrayInV = new short[INPUTSIZE * 2];
   3227         inV.copyTo(arrayInV);
   3228         byte[] arrayOut = new byte[INPUTSIZE * 2];
   3229         out.copyTo(arrayOut);
   3230         for (int i = 0; i < INPUTSIZE; i++) {
   3231             for (int j = 0; j < 2 ; j++) {
   3232                 // Extract the inputs.
   3233                 ArgumentsUshortUchar args = new ArgumentsUshortUchar();
   3234                 args.inV = arrayInV[i * 2 + j];
   3235                 // Figure out what the outputs should have been.
   3236                 CoreMathVerifier.computeConvert(args);
   3237                 // Validate the outputs.
   3238                 boolean valid = true;
   3239                 if (args.out != arrayOut[i * 2 + j]) {
   3240                     valid = false;
   3241                 }
   3242                 if (!valid) {
   3243                     StringBuilder message = new StringBuilder();
   3244                     message.append("Input inV: ");
   3245                     message.append(String.format("0x%x", args.inV));
   3246                     message.append("\n");
   3247                     message.append("Expected output out: ");
   3248                     message.append(String.format("0x%x", args.out));
   3249                     message.append("\n");
   3250                     message.append("Actual   output out: ");
   3251                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   3252                     if (args.out != arrayOut[i * 2 + j]) {
   3253                         message.append(" FAIL");
   3254                     }
   3255                     message.append("\n");
   3256                     assertTrue("Incorrect output for checkConvertUshort2Uchar2" +
   3257                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   3258                 }
   3259             }
   3260         }
   3261     }
   3262 
   3263     private void checkConvertUshort3Uchar3() {
   3264         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_16, 3, 0xc36bdfe1cf2af2bcl, false, 8);
   3265         try {
   3266             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE);
   3267             script.forEach_testConvertUchar3Ushort3Uchar3(inV, out);
   3268             verifyResultsConvertUshort3Uchar3(inV, out, false);
   3269         } catch (Exception e) {
   3270             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar3Ushort3Uchar3: " + e.toString());
   3271         }
   3272         try {
   3273             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE);
   3274             scriptRelaxed.forEach_testConvertUchar3Ushort3Uchar3(inV, out);
   3275             verifyResultsConvertUshort3Uchar3(inV, out, true);
   3276         } catch (Exception e) {
   3277             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar3Ushort3Uchar3: " + e.toString());
   3278         }
   3279     }
   3280 
   3281     private void verifyResultsConvertUshort3Uchar3(Allocation inV, Allocation out, boolean relaxed) {
   3282         short[] arrayInV = new short[INPUTSIZE * 4];
   3283         inV.copyTo(arrayInV);
   3284         byte[] arrayOut = new byte[INPUTSIZE * 4];
   3285         out.copyTo(arrayOut);
   3286         for (int i = 0; i < INPUTSIZE; i++) {
   3287             for (int j = 0; j < 3 ; j++) {
   3288                 // Extract the inputs.
   3289                 ArgumentsUshortUchar args = new ArgumentsUshortUchar();
   3290                 args.inV = arrayInV[i * 4 + j];
   3291                 // Figure out what the outputs should have been.
   3292                 CoreMathVerifier.computeConvert(args);
   3293                 // Validate the outputs.
   3294                 boolean valid = true;
   3295                 if (args.out != arrayOut[i * 4 + j]) {
   3296                     valid = false;
   3297                 }
   3298                 if (!valid) {
   3299                     StringBuilder message = new StringBuilder();
   3300                     message.append("Input inV: ");
   3301                     message.append(String.format("0x%x", args.inV));
   3302                     message.append("\n");
   3303                     message.append("Expected output out: ");
   3304                     message.append(String.format("0x%x", args.out));
   3305                     message.append("\n");
   3306                     message.append("Actual   output out: ");
   3307                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   3308                     if (args.out != arrayOut[i * 4 + j]) {
   3309                         message.append(" FAIL");
   3310                     }
   3311                     message.append("\n");
   3312                     assertTrue("Incorrect output for checkConvertUshort3Uchar3" +
   3313                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   3314                 }
   3315             }
   3316         }
   3317     }
   3318 
   3319     private void checkConvertUshort4Uchar4() {
   3320         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_16, 4, 0xc36da8fcc546139al, false, 8);
   3321         try {
   3322             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE);
   3323             script.forEach_testConvertUchar4Ushort4Uchar4(inV, out);
   3324             verifyResultsConvertUshort4Uchar4(inV, out, false);
   3325         } catch (Exception e) {
   3326             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar4Ushort4Uchar4: " + e.toString());
   3327         }
   3328         try {
   3329             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE);
   3330             scriptRelaxed.forEach_testConvertUchar4Ushort4Uchar4(inV, out);
   3331             verifyResultsConvertUshort4Uchar4(inV, out, true);
   3332         } catch (Exception e) {
   3333             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar4Ushort4Uchar4: " + e.toString());
   3334         }
   3335     }
   3336 
   3337     private void verifyResultsConvertUshort4Uchar4(Allocation inV, Allocation out, boolean relaxed) {
   3338         short[] arrayInV = new short[INPUTSIZE * 4];
   3339         inV.copyTo(arrayInV);
   3340         byte[] arrayOut = new byte[INPUTSIZE * 4];
   3341         out.copyTo(arrayOut);
   3342         for (int i = 0; i < INPUTSIZE; i++) {
   3343             for (int j = 0; j < 4 ; j++) {
   3344                 // Extract the inputs.
   3345                 ArgumentsUshortUchar args = new ArgumentsUshortUchar();
   3346                 args.inV = arrayInV[i * 4 + j];
   3347                 // Figure out what the outputs should have been.
   3348                 CoreMathVerifier.computeConvert(args);
   3349                 // Validate the outputs.
   3350                 boolean valid = true;
   3351                 if (args.out != arrayOut[i * 4 + j]) {
   3352                     valid = false;
   3353                 }
   3354                 if (!valid) {
   3355                     StringBuilder message = new StringBuilder();
   3356                     message.append("Input inV: ");
   3357                     message.append(String.format("0x%x", args.inV));
   3358                     message.append("\n");
   3359                     message.append("Expected output out: ");
   3360                     message.append(String.format("0x%x", args.out));
   3361                     message.append("\n");
   3362                     message.append("Actual   output out: ");
   3363                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   3364                     if (args.out != arrayOut[i * 4 + j]) {
   3365                         message.append(" FAIL");
   3366                     }
   3367                     message.append("\n");
   3368                     assertTrue("Incorrect output for checkConvertUshort4Uchar4" +
   3369                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   3370                 }
   3371             }
   3372         }
   3373     }
   3374 
   3375     public class ArgumentsIntUchar {
   3376         public int inV;
   3377         public byte out;
   3378     }
   3379 
   3380     private void checkConvertInt2Uchar2() {
   3381         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_32, 2, 0x2a53651c20a4b078l, false, 8);
   3382         try {
   3383             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE);
   3384             script.forEach_testConvertUchar2Int2Uchar2(inV, out);
   3385             verifyResultsConvertInt2Uchar2(inV, out, false);
   3386         } catch (Exception e) {
   3387             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar2Int2Uchar2: " + e.toString());
   3388         }
   3389         try {
   3390             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE);
   3391             scriptRelaxed.forEach_testConvertUchar2Int2Uchar2(inV, out);
   3392             verifyResultsConvertInt2Uchar2(inV, out, true);
   3393         } catch (Exception e) {
   3394             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar2Int2Uchar2: " + e.toString());
   3395         }
   3396     }
   3397 
   3398     private void verifyResultsConvertInt2Uchar2(Allocation inV, Allocation out, boolean relaxed) {
   3399         int[] arrayInV = new int[INPUTSIZE * 2];
   3400         inV.copyTo(arrayInV);
   3401         byte[] arrayOut = new byte[INPUTSIZE * 2];
   3402         out.copyTo(arrayOut);
   3403         for (int i = 0; i < INPUTSIZE; i++) {
   3404             for (int j = 0; j < 2 ; j++) {
   3405                 // Extract the inputs.
   3406                 ArgumentsIntUchar args = new ArgumentsIntUchar();
   3407                 args.inV = arrayInV[i * 2 + j];
   3408                 // Figure out what the outputs should have been.
   3409                 CoreMathVerifier.computeConvert(args);
   3410                 // Validate the outputs.
   3411                 boolean valid = true;
   3412                 if (args.out != arrayOut[i * 2 + j]) {
   3413                     valid = false;
   3414                 }
   3415                 if (!valid) {
   3416                     StringBuilder message = new StringBuilder();
   3417                     message.append("Input inV: ");
   3418                     message.append(String.format("%d", args.inV));
   3419                     message.append("\n");
   3420                     message.append("Expected output out: ");
   3421                     message.append(String.format("0x%x", args.out));
   3422                     message.append("\n");
   3423                     message.append("Actual   output out: ");
   3424                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   3425                     if (args.out != arrayOut[i * 2 + j]) {
   3426                         message.append(" FAIL");
   3427                     }
   3428                     message.append("\n");
   3429                     assertTrue("Incorrect output for checkConvertInt2Uchar2" +
   3430                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   3431                 }
   3432             }
   3433         }
   3434     }
   3435 
   3436     private void checkConvertInt3Uchar3() {
   3437         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_32, 3, 0x2a552e3716bfd156l, false, 8);
   3438         try {
   3439             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE);
   3440             script.forEach_testConvertUchar3Int3Uchar3(inV, out);
   3441             verifyResultsConvertInt3Uchar3(inV, out, false);
   3442         } catch (Exception e) {
   3443             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar3Int3Uchar3: " + e.toString());
   3444         }
   3445         try {
   3446             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE);
   3447             scriptRelaxed.forEach_testConvertUchar3Int3Uchar3(inV, out);
   3448             verifyResultsConvertInt3Uchar3(inV, out, true);
   3449         } catch (Exception e) {
   3450             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar3Int3Uchar3: " + e.toString());
   3451         }
   3452     }
   3453 
   3454     private void verifyResultsConvertInt3Uchar3(Allocation inV, Allocation out, boolean relaxed) {
   3455         int[] arrayInV = new int[INPUTSIZE * 4];
   3456         inV.copyTo(arrayInV);
   3457         byte[] arrayOut = new byte[INPUTSIZE * 4];
   3458         out.copyTo(arrayOut);
   3459         for (int i = 0; i < INPUTSIZE; i++) {
   3460             for (int j = 0; j < 3 ; j++) {
   3461                 // Extract the inputs.
   3462                 ArgumentsIntUchar args = new ArgumentsIntUchar();
   3463                 args.inV = arrayInV[i * 4 + j];
   3464                 // Figure out what the outputs should have been.
   3465                 CoreMathVerifier.computeConvert(args);
   3466                 // Validate the outputs.
   3467                 boolean valid = true;
   3468                 if (args.out != arrayOut[i * 4 + j]) {
   3469                     valid = false;
   3470                 }
   3471                 if (!valid) {
   3472                     StringBuilder message = new StringBuilder();
   3473                     message.append("Input inV: ");
   3474                     message.append(String.format("%d", args.inV));
   3475                     message.append("\n");
   3476                     message.append("Expected output out: ");
   3477                     message.append(String.format("0x%x", args.out));
   3478                     message.append("\n");
   3479                     message.append("Actual   output out: ");
   3480                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   3481                     if (args.out != arrayOut[i * 4 + j]) {
   3482                         message.append(" FAIL");
   3483                     }
   3484                     message.append("\n");
   3485                     assertTrue("Incorrect output for checkConvertInt3Uchar3" +
   3486                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   3487                 }
   3488             }
   3489         }
   3490     }
   3491 
   3492     private void checkConvertInt4Uchar4() {
   3493         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_32, 4, 0x2a56f7520cdaf234l, false, 8);
   3494         try {
   3495             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE);
   3496             script.forEach_testConvertUchar4Int4Uchar4(inV, out);
   3497             verifyResultsConvertInt4Uchar4(inV, out, false);
   3498         } catch (Exception e) {
   3499             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar4Int4Uchar4: " + e.toString());
   3500         }
   3501         try {
   3502             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE);
   3503             scriptRelaxed.forEach_testConvertUchar4Int4Uchar4(inV, out);
   3504             verifyResultsConvertInt4Uchar4(inV, out, true);
   3505         } catch (Exception e) {
   3506             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar4Int4Uchar4: " + e.toString());
   3507         }
   3508     }
   3509 
   3510     private void verifyResultsConvertInt4Uchar4(Allocation inV, Allocation out, boolean relaxed) {
   3511         int[] arrayInV = new int[INPUTSIZE * 4];
   3512         inV.copyTo(arrayInV);
   3513         byte[] arrayOut = new byte[INPUTSIZE * 4];
   3514         out.copyTo(arrayOut);
   3515         for (int i = 0; i < INPUTSIZE; i++) {
   3516             for (int j = 0; j < 4 ; j++) {
   3517                 // Extract the inputs.
   3518                 ArgumentsIntUchar args = new ArgumentsIntUchar();
   3519                 args.inV = arrayInV[i * 4 + j];
   3520                 // Figure out what the outputs should have been.
   3521                 CoreMathVerifier.computeConvert(args);
   3522                 // Validate the outputs.
   3523                 boolean valid = true;
   3524                 if (args.out != arrayOut[i * 4 + j]) {
   3525                     valid = false;
   3526                 }
   3527                 if (!valid) {
   3528                     StringBuilder message = new StringBuilder();
   3529                     message.append("Input inV: ");
   3530                     message.append(String.format("%d", args.inV));
   3531                     message.append("\n");
   3532                     message.append("Expected output out: ");
   3533                     message.append(String.format("0x%x", args.out));
   3534                     message.append("\n");
   3535                     message.append("Actual   output out: ");
   3536                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   3537                     if (args.out != arrayOut[i * 4 + j]) {
   3538                         message.append(" FAIL");
   3539                     }
   3540                     message.append("\n");
   3541                     assertTrue("Incorrect output for checkConvertInt4Uchar4" +
   3542                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   3543                 }
   3544             }
   3545         }
   3546     }
   3547 
   3548     public class ArgumentsUintUchar {
   3549         public int inV;
   3550         public byte out;
   3551     }
   3552 
   3553     private void checkConvertUint2Uchar2() {
   3554         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_32, 2, 0xd1e11e69b326bcf9l, false, 8);
   3555         try {
   3556             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE);
   3557             script.forEach_testConvertUchar2Uint2Uchar2(inV, out);
   3558             verifyResultsConvertUint2Uchar2(inV, out, false);
   3559         } catch (Exception e) {
   3560             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar2Uint2Uchar2: " + e.toString());
   3561         }
   3562         try {
   3563             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE);
   3564             scriptRelaxed.forEach_testConvertUchar2Uint2Uchar2(inV, out);
   3565             verifyResultsConvertUint2Uchar2(inV, out, true);
   3566         } catch (Exception e) {
   3567             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar2Uint2Uchar2: " + e.toString());
   3568         }
   3569     }
   3570 
   3571     private void verifyResultsConvertUint2Uchar2(Allocation inV, Allocation out, boolean relaxed) {
   3572         int[] arrayInV = new int[INPUTSIZE * 2];
   3573         inV.copyTo(arrayInV);
   3574         byte[] arrayOut = new byte[INPUTSIZE * 2];
   3575         out.copyTo(arrayOut);
   3576         for (int i = 0; i < INPUTSIZE; i++) {
   3577             for (int j = 0; j < 2 ; j++) {
   3578                 // Extract the inputs.
   3579                 ArgumentsUintUchar args = new ArgumentsUintUchar();
   3580                 args.inV = arrayInV[i * 2 + j];
   3581                 // Figure out what the outputs should have been.
   3582                 CoreMathVerifier.computeConvert(args);
   3583                 // Validate the outputs.
   3584                 boolean valid = true;
   3585                 if (args.out != arrayOut[i * 2 + j]) {
   3586                     valid = false;
   3587                 }
   3588                 if (!valid) {
   3589                     StringBuilder message = new StringBuilder();
   3590                     message.append("Input inV: ");
   3591                     message.append(String.format("0x%x", args.inV));
   3592                     message.append("\n");
   3593                     message.append("Expected output out: ");
   3594                     message.append(String.format("0x%x", args.out));
   3595                     message.append("\n");
   3596                     message.append("Actual   output out: ");
   3597                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   3598                     if (args.out != arrayOut[i * 2 + j]) {
   3599                         message.append(" FAIL");
   3600                     }
   3601                     message.append("\n");
   3602                     assertTrue("Incorrect output for checkConvertUint2Uchar2" +
   3603                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   3604                 }
   3605             }
   3606         }
   3607     }
   3608 
   3609     private void checkConvertUint3Uchar3() {
   3610         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_32, 3, 0xd1e2e784a941ddd7l, false, 8);
   3611         try {
   3612             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE);
   3613             script.forEach_testConvertUchar3Uint3Uchar3(inV, out);
   3614             verifyResultsConvertUint3Uchar3(inV, out, false);
   3615         } catch (Exception e) {
   3616             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar3Uint3Uchar3: " + e.toString());
   3617         }
   3618         try {
   3619             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE);
   3620             scriptRelaxed.forEach_testConvertUchar3Uint3Uchar3(inV, out);
   3621             verifyResultsConvertUint3Uchar3(inV, out, true);
   3622         } catch (Exception e) {
   3623             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar3Uint3Uchar3: " + e.toString());
   3624         }
   3625     }
   3626 
   3627     private void verifyResultsConvertUint3Uchar3(Allocation inV, Allocation out, boolean relaxed) {
   3628         int[] arrayInV = new int[INPUTSIZE * 4];
   3629         inV.copyTo(arrayInV);
   3630         byte[] arrayOut = new byte[INPUTSIZE * 4];
   3631         out.copyTo(arrayOut);
   3632         for (int i = 0; i < INPUTSIZE; i++) {
   3633             for (int j = 0; j < 3 ; j++) {
   3634                 // Extract the inputs.
   3635                 ArgumentsUintUchar args = new ArgumentsUintUchar();
   3636                 args.inV = arrayInV[i * 4 + j];
   3637                 // Figure out what the outputs should have been.
   3638                 CoreMathVerifier.computeConvert(args);
   3639                 // Validate the outputs.
   3640                 boolean valid = true;
   3641                 if (args.out != arrayOut[i * 4 + j]) {
   3642                     valid = false;
   3643                 }
   3644                 if (!valid) {
   3645                     StringBuilder message = new StringBuilder();
   3646                     message.append("Input inV: ");
   3647                     message.append(String.format("0x%x", args.inV));
   3648                     message.append("\n");
   3649                     message.append("Expected output out: ");
   3650                     message.append(String.format("0x%x", args.out));
   3651                     message.append("\n");
   3652                     message.append("Actual   output out: ");
   3653                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   3654                     if (args.out != arrayOut[i * 4 + j]) {
   3655                         message.append(" FAIL");
   3656                     }
   3657                     message.append("\n");
   3658                     assertTrue("Incorrect output for checkConvertUint3Uchar3" +
   3659                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   3660                 }
   3661             }
   3662         }
   3663     }
   3664 
   3665     private void checkConvertUint4Uchar4() {
   3666         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_32, 4, 0xd1e4b09f9f5cfeb5l, false, 8);
   3667         try {
   3668             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE);
   3669             script.forEach_testConvertUchar4Uint4Uchar4(inV, out);
   3670             verifyResultsConvertUint4Uchar4(inV, out, false);
   3671         } catch (Exception e) {
   3672             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar4Uint4Uchar4: " + e.toString());
   3673         }
   3674         try {
   3675             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE);
   3676             scriptRelaxed.forEach_testConvertUchar4Uint4Uchar4(inV, out);
   3677             verifyResultsConvertUint4Uchar4(inV, out, true);
   3678         } catch (Exception e) {
   3679             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar4Uint4Uchar4: " + e.toString());
   3680         }
   3681     }
   3682 
   3683     private void verifyResultsConvertUint4Uchar4(Allocation inV, Allocation out, boolean relaxed) {
   3684         int[] arrayInV = new int[INPUTSIZE * 4];
   3685         inV.copyTo(arrayInV);
   3686         byte[] arrayOut = new byte[INPUTSIZE * 4];
   3687         out.copyTo(arrayOut);
   3688         for (int i = 0; i < INPUTSIZE; i++) {
   3689             for (int j = 0; j < 4 ; j++) {
   3690                 // Extract the inputs.
   3691                 ArgumentsUintUchar args = new ArgumentsUintUchar();
   3692                 args.inV = arrayInV[i * 4 + j];
   3693                 // Figure out what the outputs should have been.
   3694                 CoreMathVerifier.computeConvert(args);
   3695                 // Validate the outputs.
   3696                 boolean valid = true;
   3697                 if (args.out != arrayOut[i * 4 + j]) {
   3698                     valid = false;
   3699                 }
   3700                 if (!valid) {
   3701                     StringBuilder message = new StringBuilder();
   3702                     message.append("Input inV: ");
   3703                     message.append(String.format("0x%x", args.inV));
   3704                     message.append("\n");
   3705                     message.append("Expected output out: ");
   3706                     message.append(String.format("0x%x", args.out));
   3707                     message.append("\n");
   3708                     message.append("Actual   output out: ");
   3709                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   3710                     if (args.out != arrayOut[i * 4 + j]) {
   3711                         message.append(" FAIL");
   3712                     }
   3713                     message.append("\n");
   3714                     assertTrue("Incorrect output for checkConvertUint4Uchar4" +
   3715                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   3716                 }
   3717             }
   3718         }
   3719     }
   3720 
   3721     public class ArgumentsFloatShort {
   3722         public float inV;
   3723         public short out;
   3724     }
   3725 
   3726     private void checkConvertFloat2Short2() {
   3727         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xfb529ef98fcf2692l, -3.2768000000000000000e+04, 3.2767000000000000000e+04);
   3728         try {
   3729             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 2), INPUTSIZE);
   3730             script.forEach_testConvertShort2Float2Short2(inV, out);
   3731             verifyResultsConvertFloat2Short2(inV, out, false);
   3732         } catch (Exception e) {
   3733             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort2Float2Short2: " + e.toString());
   3734         }
   3735         try {
   3736             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 2), INPUTSIZE);
   3737             scriptRelaxed.forEach_testConvertShort2Float2Short2(inV, out);
   3738             verifyResultsConvertFloat2Short2(inV, out, true);
   3739         } catch (Exception e) {
   3740             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort2Float2Short2: " + e.toString());
   3741         }
   3742     }
   3743 
   3744     private void verifyResultsConvertFloat2Short2(Allocation inV, Allocation out, boolean relaxed) {
   3745         float[] arrayInV = new float[INPUTSIZE * 2];
   3746         inV.copyTo(arrayInV);
   3747         short[] arrayOut = new short[INPUTSIZE * 2];
   3748         out.copyTo(arrayOut);
   3749         for (int i = 0; i < INPUTSIZE; i++) {
   3750             for (int j = 0; j < 2 ; j++) {
   3751                 // Extract the inputs.
   3752                 ArgumentsFloatShort args = new ArgumentsFloatShort();
   3753                 args.inV = arrayInV[i * 2 + j];
   3754                 // Figure out what the outputs should have been.
   3755                 CoreMathVerifier.computeConvert(args);
   3756                 // Validate the outputs.
   3757                 boolean valid = true;
   3758                 if (args.out != arrayOut[i * 2 + j]) {
   3759                     valid = false;
   3760                 }
   3761                 if (!valid) {
   3762                     StringBuilder message = new StringBuilder();
   3763                     message.append("Input inV: ");
   3764                     message.append(String.format("%14.8g {%8x} %15a",
   3765                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
   3766                     message.append("\n");
   3767                     message.append("Expected output out: ");
   3768                     message.append(String.format("%d", args.out));
   3769                     message.append("\n");
   3770                     message.append("Actual   output out: ");
   3771                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   3772                     if (args.out != arrayOut[i * 2 + j]) {
   3773                         message.append(" FAIL");
   3774                     }
   3775                     message.append("\n");
   3776                     assertTrue("Incorrect output for checkConvertFloat2Short2" +
   3777                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   3778                 }
   3779             }
   3780         }
   3781     }
   3782 
   3783     private void checkConvertFloat3Short3() {
   3784         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xfb54681485ea4770l, -3.2768000000000000000e+04, 3.2767000000000000000e+04);
   3785         try {
   3786             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 3), INPUTSIZE);
   3787             script.forEach_testConvertShort3Float3Short3(inV, out);
   3788             verifyResultsConvertFloat3Short3(inV, out, false);
   3789         } catch (Exception e) {
   3790             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort3Float3Short3: " + e.toString());
   3791         }
   3792         try {
   3793             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 3), INPUTSIZE);
   3794             scriptRelaxed.forEach_testConvertShort3Float3Short3(inV, out);
   3795             verifyResultsConvertFloat3Short3(inV, out, true);
   3796         } catch (Exception e) {
   3797             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort3Float3Short3: " + e.toString());
   3798         }
   3799     }
   3800 
   3801     private void verifyResultsConvertFloat3Short3(Allocation inV, Allocation out, boolean relaxed) {
   3802         float[] arrayInV = new float[INPUTSIZE * 4];
   3803         inV.copyTo(arrayInV);
   3804         short[] arrayOut = new short[INPUTSIZE * 4];
   3805         out.copyTo(arrayOut);
   3806         for (int i = 0; i < INPUTSIZE; i++) {
   3807             for (int j = 0; j < 3 ; j++) {
   3808                 // Extract the inputs.
   3809                 ArgumentsFloatShort args = new ArgumentsFloatShort();
   3810                 args.inV = arrayInV[i * 4 + j];
   3811                 // Figure out what the outputs should have been.
   3812                 CoreMathVerifier.computeConvert(args);
   3813                 // Validate the outputs.
   3814                 boolean valid = true;
   3815                 if (args.out != arrayOut[i * 4 + j]) {
   3816                     valid = false;
   3817                 }
   3818                 if (!valid) {
   3819                     StringBuilder message = new StringBuilder();
   3820                     message.append("Input inV: ");
   3821                     message.append(String.format("%14.8g {%8x} %15a",
   3822                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
   3823                     message.append("\n");
   3824                     message.append("Expected output out: ");
   3825                     message.append(String.format("%d", args.out));
   3826                     message.append("\n");
   3827                     message.append("Actual   output out: ");
   3828                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   3829                     if (args.out != arrayOut[i * 4 + j]) {
   3830                         message.append(" FAIL");
   3831                     }
   3832                     message.append("\n");
   3833                     assertTrue("Incorrect output for checkConvertFloat3Short3" +
   3834                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   3835                 }
   3836             }
   3837         }
   3838     }
   3839 
   3840     private void checkConvertFloat4Short4() {
   3841         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xfb56312f7c05684el, -3.2768000000000000000e+04, 3.2767000000000000000e+04);
   3842         try {
   3843             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 4), INPUTSIZE);
   3844             script.forEach_testConvertShort4Float4Short4(inV, out);
   3845             verifyResultsConvertFloat4Short4(inV, out, false);
   3846         } catch (Exception e) {
   3847             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort4Float4Short4: " + e.toString());
   3848         }
   3849         try {
   3850             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 4), INPUTSIZE);
   3851             scriptRelaxed.forEach_testConvertShort4Float4Short4(inV, out);
   3852             verifyResultsConvertFloat4Short4(inV, out, true);
   3853         } catch (Exception e) {
   3854             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort4Float4Short4: " + e.toString());
   3855         }
   3856     }
   3857 
   3858     private void verifyResultsConvertFloat4Short4(Allocation inV, Allocation out, boolean relaxed) {
   3859         float[] arrayInV = new float[INPUTSIZE * 4];
   3860         inV.copyTo(arrayInV);
   3861         short[] arrayOut = new short[INPUTSIZE * 4];
   3862         out.copyTo(arrayOut);
   3863         for (int i = 0; i < INPUTSIZE; i++) {
   3864             for (int j = 0; j < 4 ; j++) {
   3865                 // Extract the inputs.
   3866                 ArgumentsFloatShort args = new ArgumentsFloatShort();
   3867                 args.inV = arrayInV[i * 4 + j];
   3868                 // Figure out what the outputs should have been.
   3869                 CoreMathVerifier.computeConvert(args);
   3870                 // Validate the outputs.
   3871                 boolean valid = true;
   3872                 if (args.out != arrayOut[i * 4 + j]) {
   3873                     valid = false;
   3874                 }
   3875                 if (!valid) {
   3876                     StringBuilder message = new StringBuilder();
   3877                     message.append("Input inV: ");
   3878                     message.append(String.format("%14.8g {%8x} %15a",
   3879                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
   3880                     message.append("\n");
   3881                     message.append("Expected output out: ");
   3882                     message.append(String.format("%d", args.out));
   3883                     message.append("\n");
   3884                     message.append("Actual   output out: ");
   3885                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   3886                     if (args.out != arrayOut[i * 4 + j]) {
   3887                         message.append(" FAIL");
   3888                     }
   3889                     message.append("\n");
   3890                     assertTrue("Incorrect output for checkConvertFloat4Short4" +
   3891                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   3892                 }
   3893             }
   3894         }
   3895     }
   3896 
   3897     public class ArgumentsCharShort {
   3898         public byte inV;
   3899         public short out;
   3900     }
   3901 
   3902     private void checkConvertChar2Short2() {
   3903         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_8, 2, 0x58626b4b60f84e52l, true, 7);
   3904         try {
   3905             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 2), INPUTSIZE);
   3906             script.forEach_testConvertShort2Char2Short2(inV, out);
   3907             verifyResultsConvertChar2Short2(inV, out, false);
   3908         } catch (Exception e) {
   3909             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort2Char2Short2: " + e.toString());
   3910         }
   3911         try {
   3912             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 2), INPUTSIZE);
   3913             scriptRelaxed.forEach_testConvertShort2Char2Short2(inV, out);
   3914             verifyResultsConvertChar2Short2(inV, out, true);
   3915         } catch (Exception e) {
   3916             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort2Char2Short2: " + e.toString());
   3917         }
   3918     }
   3919 
   3920     private void verifyResultsConvertChar2Short2(Allocation inV, Allocation out, boolean relaxed) {
   3921         byte[] arrayInV = new byte[INPUTSIZE * 2];
   3922         inV.copyTo(arrayInV);
   3923         short[] arrayOut = new short[INPUTSIZE * 2];
   3924         out.copyTo(arrayOut);
   3925         for (int i = 0; i < INPUTSIZE; i++) {
   3926             for (int j = 0; j < 2 ; j++) {
   3927                 // Extract the inputs.
   3928                 ArgumentsCharShort args = new ArgumentsCharShort();
   3929                 args.inV = arrayInV[i * 2 + j];
   3930                 // Figure out what the outputs should have been.
   3931                 CoreMathVerifier.computeConvert(args);
   3932                 // Validate the outputs.
   3933                 boolean valid = true;
   3934                 if (args.out != arrayOut[i * 2 + j]) {
   3935                     valid = false;
   3936                 }
   3937                 if (!valid) {
   3938                     StringBuilder message = new StringBuilder();
   3939                     message.append("Input inV: ");
   3940                     message.append(String.format("%d", args.inV));
   3941                     message.append("\n");
   3942                     message.append("Expected output out: ");
   3943                     message.append(String.format("%d", args.out));
   3944                     message.append("\n");
   3945                     message.append("Actual   output out: ");
   3946                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   3947                     if (args.out != arrayOut[i * 2 + j]) {
   3948                         message.append(" FAIL");
   3949                     }
   3950                     message.append("\n");
   3951                     assertTrue("Incorrect output for checkConvertChar2Short2" +
   3952                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   3953                 }
   3954             }
   3955         }
   3956     }
   3957 
   3958     private void checkConvertChar3Short3() {
   3959         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_8, 3, 0x5864346657136f30l, true, 7);
   3960         try {
   3961             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 3), INPUTSIZE);
   3962             script.forEach_testConvertShort3Char3Short3(inV, out);
   3963             verifyResultsConvertChar3Short3(inV, out, false);
   3964         } catch (Exception e) {
   3965             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort3Char3Short3: " + e.toString());
   3966         }
   3967         try {
   3968             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 3), INPUTSIZE);
   3969             scriptRelaxed.forEach_testConvertShort3Char3Short3(inV, out);
   3970             verifyResultsConvertChar3Short3(inV, out, true);
   3971         } catch (Exception e) {
   3972             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort3Char3Short3: " + e.toString());
   3973         }
   3974     }
   3975 
   3976     private void verifyResultsConvertChar3Short3(Allocation inV, Allocation out, boolean relaxed) {
   3977         byte[] arrayInV = new byte[INPUTSIZE * 4];
   3978         inV.copyTo(arrayInV);
   3979         short[] arrayOut = new short[INPUTSIZE * 4];
   3980         out.copyTo(arrayOut);
   3981         for (int i = 0; i < INPUTSIZE; i++) {
   3982             for (int j = 0; j < 3 ; j++) {
   3983                 // Extract the inputs.
   3984                 ArgumentsCharShort args = new ArgumentsCharShort();
   3985                 args.inV = arrayInV[i * 4 + j];
   3986                 // Figure out what the outputs should have been.
   3987                 CoreMathVerifier.computeConvert(args);
   3988                 // Validate the outputs.
   3989                 boolean valid = true;
   3990                 if (args.out != arrayOut[i * 4 + j]) {
   3991                     valid = false;
   3992                 }
   3993                 if (!valid) {
   3994                     StringBuilder message = new StringBuilder();
   3995                     message.append("Input inV: ");
   3996                     message.append(String.format("%d", args.inV));
   3997                     message.append("\n");
   3998                     message.append("Expected output out: ");
   3999                     message.append(String.format("%d", args.out));
   4000                     message.append("\n");
   4001                     message.append("Actual   output out: ");
   4002                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   4003                     if (args.out != arrayOut[i * 4 + j]) {
   4004                         message.append(" FAIL");
   4005                     }
   4006                     message.append("\n");
   4007                     assertTrue("Incorrect output for checkConvertChar3Short3" +
   4008                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   4009                 }
   4010             }
   4011         }
   4012     }
   4013 
   4014     private void checkConvertChar4Short4() {
   4015         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_8, 4, 0x5865fd814d2e900el, true, 7);
   4016         try {
   4017             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 4), INPUTSIZE);
   4018             script.forEach_testConvertShort4Char4Short4(inV, out);
   4019             verifyResultsConvertChar4Short4(inV, out, false);
   4020         } catch (Exception e) {
   4021             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort4Char4Short4: " + e.toString());
   4022         }
   4023         try {
   4024             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 4), INPUTSIZE);
   4025             scriptRelaxed.forEach_testConvertShort4Char4Short4(inV, out);
   4026             verifyResultsConvertChar4Short4(inV, out, true);
   4027         } catch (Exception e) {
   4028             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort4Char4Short4: " + e.toString());
   4029         }
   4030     }
   4031 
   4032     private void verifyResultsConvertChar4Short4(Allocation inV, Allocation out, boolean relaxed) {
   4033         byte[] arrayInV = new byte[INPUTSIZE * 4];
   4034         inV.copyTo(arrayInV);
   4035         short[] arrayOut = new short[INPUTSIZE * 4];
   4036         out.copyTo(arrayOut);
   4037         for (int i = 0; i < INPUTSIZE; i++) {
   4038             for (int j = 0; j < 4 ; j++) {
   4039                 // Extract the inputs.
   4040                 ArgumentsCharShort args = new ArgumentsCharShort();
   4041                 args.inV = arrayInV[i * 4 + j];
   4042                 // Figure out what the outputs should have been.
   4043                 CoreMathVerifier.computeConvert(args);
   4044                 // Validate the outputs.
   4045                 boolean valid = true;
   4046                 if (args.out != arrayOut[i * 4 + j]) {
   4047                     valid = false;
   4048                 }
   4049                 if (!valid) {
   4050                     StringBuilder message = new StringBuilder();
   4051                     message.append("Input inV: ");
   4052                     message.append(String.format("%d", args.inV));
   4053                     message.append("\n");
   4054                     message.append("Expected output out: ");
   4055                     message.append(String.format("%d", args.out));
   4056                     message.append("\n");
   4057                     message.append("Actual   output out: ");
   4058                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   4059                     if (args.out != arrayOut[i * 4 + j]) {
   4060                         message.append(" FAIL");
   4061                     }
   4062                     message.append("\n");
   4063                     assertTrue("Incorrect output for checkConvertChar4Short4" +
   4064                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   4065                 }
   4066             }
   4067         }
   4068     }
   4069 
   4070     public class ArgumentsUcharShort {
   4071         public byte inV;
   4072         public short out;
   4073     }
   4074 
   4075     private void checkConvertUchar2Short2() {
   4076         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_8, 2, 0x7d308b52fcd067fdl, false, 8);
   4077         try {
   4078             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 2), INPUTSIZE);
   4079             script.forEach_testConvertShort2Uchar2Short2(inV, out);
   4080             verifyResultsConvertUchar2Short2(inV, out, false);
   4081         } catch (Exception e) {
   4082             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort2Uchar2Short2: " + e.toString());
   4083         }
   4084         try {
   4085             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 2), INPUTSIZE);
   4086             scriptRelaxed.forEach_testConvertShort2Uchar2Short2(inV, out);
   4087             verifyResultsConvertUchar2Short2(inV, out, true);
   4088         } catch (Exception e) {
   4089             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort2Uchar2Short2: " + e.toString());
   4090         }
   4091     }
   4092 
   4093     private void verifyResultsConvertUchar2Short2(Allocation inV, Allocation out, boolean relaxed) {
   4094         byte[] arrayInV = new byte[INPUTSIZE * 2];
   4095         inV.copyTo(arrayInV);
   4096         short[] arrayOut = new short[INPUTSIZE * 2];
   4097         out.copyTo(arrayOut);
   4098         for (int i = 0; i < INPUTSIZE; i++) {
   4099             for (int j = 0; j < 2 ; j++) {
   4100                 // Extract the inputs.
   4101                 ArgumentsUcharShort args = new ArgumentsUcharShort();
   4102                 args.inV = arrayInV[i * 2 + j];
   4103                 // Figure out what the outputs should have been.
   4104                 CoreMathVerifier.computeConvert(args);
   4105                 // Validate the outputs.
   4106                 boolean valid = true;
   4107                 if (args.out != arrayOut[i * 2 + j]) {
   4108                     valid = false;
   4109                 }
   4110                 if (!valid) {
   4111                     StringBuilder message = new StringBuilder();
   4112                     message.append("Input inV: ");
   4113                     message.append(String.format("0x%x", args.inV));
   4114                     message.append("\n");
   4115                     message.append("Expected output out: ");
   4116                     message.append(String.format("%d", args.out));
   4117                     message.append("\n");
   4118                     message.append("Actual   output out: ");
   4119                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   4120                     if (args.out != arrayOut[i * 2 + j]) {
   4121                         message.append(" FAIL");
   4122                     }
   4123                     message.append("\n");
   4124                     assertTrue("Incorrect output for checkConvertUchar2Short2" +
   4125                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   4126                 }
   4127             }
   4128         }
   4129     }
   4130 
   4131     private void checkConvertUchar3Short3() {
   4132         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_8, 3, 0x7d32546df2eb88dbl, false, 8);
   4133         try {
   4134             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 3), INPUTSIZE);
   4135             script.forEach_testConvertShort3Uchar3Short3(inV, out);
   4136             verifyResultsConvertUchar3Short3(inV, out, false);
   4137         } catch (Exception e) {
   4138             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort3Uchar3Short3: " + e.toString());
   4139         }
   4140         try {
   4141             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 3), INPUTSIZE);
   4142             scriptRelaxed.forEach_testConvertShort3Uchar3Short3(inV, out);
   4143             verifyResultsConvertUchar3Short3(inV, out, true);
   4144         } catch (Exception e) {
   4145             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort3Uchar3Short3: " + e.toString());
   4146         }
   4147     }
   4148 
   4149     private void verifyResultsConvertUchar3Short3(Allocation inV, Allocation out, boolean relaxed) {
   4150         byte[] arrayInV = new byte[INPUTSIZE * 4];
   4151         inV.copyTo(arrayInV);
   4152         short[] arrayOut = new short[INPUTSIZE * 4];
   4153         out.copyTo(arrayOut);
   4154         for (int i = 0; i < INPUTSIZE; i++) {
   4155             for (int j = 0; j < 3 ; j++) {
   4156                 // Extract the inputs.
   4157                 ArgumentsUcharShort args = new ArgumentsUcharShort();
   4158                 args.inV = arrayInV[i * 4 + j];
   4159                 // Figure out what the outputs should have been.
   4160                 CoreMathVerifier.computeConvert(args);
   4161                 // Validate the outputs.
   4162                 boolean valid = true;
   4163                 if (args.out != arrayOut[i * 4 + j]) {
   4164                     valid = false;
   4165                 }
   4166                 if (!valid) {
   4167                     StringBuilder message = new StringBuilder();
   4168                     message.append("Input inV: ");
   4169                     message.append(String.format("0x%x", args.inV));
   4170                     message.append("\n");
   4171                     message.append("Expected output out: ");
   4172                     message.append(String.format("%d", args.out));
   4173                     message.append("\n");
   4174                     message.append("Actual   output out: ");
   4175                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   4176                     if (args.out != arrayOut[i * 4 + j]) {
   4177                         message.append(" FAIL");
   4178                     }
   4179                     message.append("\n");
   4180                     assertTrue("Incorrect output for checkConvertUchar3Short3" +
   4181                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   4182                 }
   4183             }
   4184         }
   4185     }
   4186 
   4187     private void checkConvertUchar4Short4() {
   4188         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_8, 4, 0x7d341d88e906a9b9l, false, 8);
   4189         try {
   4190             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 4), INPUTSIZE);
   4191             script.forEach_testConvertShort4Uchar4Short4(inV, out);
   4192             verifyResultsConvertUchar4Short4(inV, out, false);
   4193         } catch (Exception e) {
   4194             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort4Uchar4Short4: " + e.toString());
   4195         }
   4196         try {
   4197             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 4), INPUTSIZE);
   4198             scriptRelaxed.forEach_testConvertShort4Uchar4Short4(inV, out);
   4199             verifyResultsConvertUchar4Short4(inV, out, true);
   4200         } catch (Exception e) {
   4201             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort4Uchar4Short4: " + e.toString());
   4202         }
   4203     }
   4204 
   4205     private void verifyResultsConvertUchar4Short4(Allocation inV, Allocation out, boolean relaxed) {
   4206         byte[] arrayInV = new byte[INPUTSIZE * 4];
   4207         inV.copyTo(arrayInV);
   4208         short[] arrayOut = new short[INPUTSIZE * 4];
   4209         out.copyTo(arrayOut);
   4210         for (int i = 0; i < INPUTSIZE; i++) {
   4211             for (int j = 0; j < 4 ; j++) {
   4212                 // Extract the inputs.
   4213                 ArgumentsUcharShort args = new ArgumentsUcharShort();
   4214                 args.inV = arrayInV[i * 4 + j];
   4215                 // Figure out what the outputs should have been.
   4216                 CoreMathVerifier.computeConvert(args);
   4217                 // Validate the outputs.
   4218                 boolean valid = true;
   4219                 if (args.out != arrayOut[i * 4 + j]) {
   4220                     valid = false;
   4221                 }
   4222                 if (!valid) {
   4223                     StringBuilder message = new StringBuilder();
   4224                     message.append("Input inV: ");
   4225                     message.append(String.format("0x%x", args.inV));
   4226                     message.append("\n");
   4227                     message.append("Expected output out: ");
   4228                     message.append(String.format("%d", args.out));
   4229                     message.append("\n");
   4230                     message.append("Actual   output out: ");
   4231                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   4232                     if (args.out != arrayOut[i * 4 + j]) {
   4233                         message.append(" FAIL");
   4234                     }
   4235                     message.append("\n");
   4236                     assertTrue("Incorrect output for checkConvertUchar4Short4" +
   4237                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   4238                 }
   4239             }
   4240         }
   4241     }
   4242 
   4243     public class ArgumentsShortShort {
   4244         public short inV;
   4245         public short out;
   4246     }
   4247 
   4248     private void checkConvertShort2Short2() {
   4249         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_16, 2, 0x94caa18440d14d3el, true, 15);
   4250         try {
   4251             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 2), INPUTSIZE);
   4252             script.forEach_testConvertShort2Short2Short2(inV, out);
   4253             verifyResultsConvertShort2Short2(inV, out, false);
   4254         } catch (Exception e) {
   4255             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort2Short2Short2: " + e.toString());
   4256         }
   4257         try {
   4258             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 2), INPUTSIZE);
   4259             scriptRelaxed.forEach_testConvertShort2Short2Short2(inV, out);
   4260             verifyResultsConvertShort2Short2(inV, out, true);
   4261         } catch (Exception e) {
   4262             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort2Short2Short2: " + e.toString());
   4263         }
   4264     }
   4265 
   4266     private void verifyResultsConvertShort2Short2(Allocation inV, Allocation out, boolean relaxed) {
   4267         short[] arrayInV = new short[INPUTSIZE * 2];
   4268         inV.copyTo(arrayInV);
   4269         short[] arrayOut = new short[INPUTSIZE * 2];
   4270         out.copyTo(arrayOut);
   4271         for (int i = 0; i < INPUTSIZE; i++) {
   4272             for (int j = 0; j < 2 ; j++) {
   4273                 // Extract the inputs.
   4274                 ArgumentsShortShort args = new ArgumentsShortShort();
   4275                 args.inV = arrayInV[i * 2 + j];
   4276                 // Figure out what the outputs should have been.
   4277                 CoreMathVerifier.computeConvert(args);
   4278                 // Validate the outputs.
   4279                 boolean valid = true;
   4280                 if (args.out != arrayOut[i * 2 + j]) {
   4281                     valid = false;
   4282                 }
   4283                 if (!valid) {
   4284                     StringBuilder message = new StringBuilder();
   4285                     message.append("Input inV: ");
   4286                     message.append(String.format("%d", args.inV));
   4287                     message.append("\n");
   4288                     message.append("Expected output out: ");
   4289                     message.append(String.format("%d", args.out));
   4290                     message.append("\n");
   4291                     message.append("Actual   output out: ");
   4292                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   4293                     if (args.out != arrayOut[i * 2 + j]) {
   4294                         message.append(" FAIL");
   4295                     }
   4296                     message.append("\n");
   4297                     assertTrue("Incorrect output for checkConvertShort2Short2" +
   4298                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   4299                 }
   4300             }
   4301         }
   4302     }
   4303 
   4304     private void checkConvertShort3Short3() {
   4305         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_16, 3, 0x94cc6a9f36ec6e1cl, true, 15);
   4306         try {
   4307             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 3), INPUTSIZE);
   4308             script.forEach_testConvertShort3Short3Short3(inV, out);
   4309             verifyResultsConvertShort3Short3(inV, out, false);
   4310         } catch (Exception e) {
   4311             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort3Short3Short3: " + e.toString());
   4312         }
   4313         try {
   4314             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 3), INPUTSIZE);
   4315             scriptRelaxed.forEach_testConvertShort3Short3Short3(inV, out);
   4316             verifyResultsConvertShort3Short3(inV, out, true);
   4317         } catch (Exception e) {
   4318             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort3Short3Short3: " + e.toString());
   4319         }
   4320     }
   4321 
   4322     private void verifyResultsConvertShort3Short3(Allocation inV, Allocation out, boolean relaxed) {
   4323         short[] arrayInV = new short[INPUTSIZE * 4];
   4324         inV.copyTo(arrayInV);
   4325         short[] arrayOut = new short[INPUTSIZE * 4];
   4326         out.copyTo(arrayOut);
   4327         for (int i = 0; i < INPUTSIZE; i++) {
   4328             for (int j = 0; j < 3 ; j++) {
   4329                 // Extract the inputs.
   4330                 ArgumentsShortShort args = new ArgumentsShortShort();
   4331                 args.inV = arrayInV[i * 4 + j];
   4332                 // Figure out what the outputs should have been.
   4333                 CoreMathVerifier.computeConvert(args);
   4334                 // Validate the outputs.
   4335                 boolean valid = true;
   4336                 if (args.out != arrayOut[i * 4 + j]) {
   4337                     valid = false;
   4338                 }
   4339                 if (!valid) {
   4340                     StringBuilder message = new StringBuilder();
   4341                     message.append("Input inV: ");
   4342                     message.append(String.format("%d", args.inV));
   4343                     message.append("\n");
   4344                     message.append("Expected output out: ");
   4345                     message.append(String.format("%d", args.out));
   4346                     message.append("\n");
   4347                     message.append("Actual   output out: ");
   4348                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   4349                     if (args.out != arrayOut[i * 4 + j]) {
   4350                         message.append(" FAIL");
   4351                     }
   4352                     message.append("\n");
   4353                     assertTrue("Incorrect output for checkConvertShort3Short3" +
   4354                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   4355                 }
   4356             }
   4357         }
   4358     }
   4359 
   4360     private void checkConvertShort4Short4() {
   4361         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_16, 4, 0x94ce33ba2d078efal, true, 15);
   4362         try {
   4363             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 4), INPUTSIZE);
   4364             script.forEach_testConvertShort4Short4Short4(inV, out);
   4365             verifyResultsConvertShort4Short4(inV, out, false);
   4366         } catch (Exception e) {
   4367             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort4Short4Short4: " + e.toString());
   4368         }
   4369         try {
   4370             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 4), INPUTSIZE);
   4371             scriptRelaxed.forEach_testConvertShort4Short4Short4(inV, out);
   4372             verifyResultsConvertShort4Short4(inV, out, true);
   4373         } catch (Exception e) {
   4374             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort4Short4Short4: " + e.toString());
   4375         }
   4376     }
   4377 
   4378     private void verifyResultsConvertShort4Short4(Allocation inV, Allocation out, boolean relaxed) {
   4379         short[] arrayInV = new short[INPUTSIZE * 4];
   4380         inV.copyTo(arrayInV);
   4381         short[] arrayOut = new short[INPUTSIZE * 4];
   4382         out.copyTo(arrayOut);
   4383         for (int i = 0; i < INPUTSIZE; i++) {
   4384             for (int j = 0; j < 4 ; j++) {
   4385                 // Extract the inputs.
   4386                 ArgumentsShortShort args = new ArgumentsShortShort();
   4387                 args.inV = arrayInV[i * 4 + j];
   4388                 // Figure out what the outputs should have been.
   4389                 CoreMathVerifier.computeConvert(args);
   4390                 // Validate the outputs.
   4391                 boolean valid = true;
   4392                 if (args.out != arrayOut[i * 4 + j]) {
   4393                     valid = false;
   4394                 }
   4395                 if (!valid) {
   4396                     StringBuilder message = new StringBuilder();
   4397                     message.append("Input inV: ");
   4398                     message.append(String.format("%d", args.inV));
   4399                     message.append("\n");
   4400                     message.append("Expected output out: ");
   4401                     message.append(String.format("%d", args.out));
   4402                     message.append("\n");
   4403                     message.append("Actual   output out: ");
   4404                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   4405                     if (args.out != arrayOut[i * 4 + j]) {
   4406                         message.append(" FAIL");
   4407                     }
   4408                     message.append("\n");
   4409                     assertTrue("Incorrect output for checkConvertShort4Short4" +
   4410                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   4411                 }
   4412             }
   4413         }
   4414     }
   4415 
   4416     public class ArgumentsUshortShort {
   4417         public short inV;
   4418         public short out;
   4419     }
   4420 
   4421     private void checkConvertUshort2Short2() {
   4422         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_16, 2, 0xc36a02cb6e1d9cf7l, false, 15);
   4423         try {
   4424             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 2), INPUTSIZE);
   4425             script.forEach_testConvertShort2Ushort2Short2(inV, out);
   4426             verifyResultsConvertUshort2Short2(inV, out, false);
   4427         } catch (Exception e) {
   4428             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort2Ushort2Short2: " + e.toString());
   4429         }
   4430         try {
   4431             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 2), INPUTSIZE);
   4432             scriptRelaxed.forEach_testConvertShort2Ushort2Short2(inV, out);
   4433             verifyResultsConvertUshort2Short2(inV, out, true);
   4434         } catch (Exception e) {
   4435             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort2Ushort2Short2: " + e.toString());
   4436         }
   4437     }
   4438 
   4439     private void verifyResultsConvertUshort2Short2(Allocation inV, Allocation out, boolean relaxed) {
   4440         short[] arrayInV = new short[INPUTSIZE * 2];
   4441         inV.copyTo(arrayInV);
   4442         short[] arrayOut = new short[INPUTSIZE * 2];
   4443         out.copyTo(arrayOut);
   4444         for (int i = 0; i < INPUTSIZE; i++) {
   4445             for (int j = 0; j < 2 ; j++) {
   4446                 // Extract the inputs.
   4447                 ArgumentsUshortShort args = new ArgumentsUshortShort();
   4448                 args.inV = arrayInV[i * 2 + j];
   4449                 // Figure out what the outputs should have been.
   4450                 CoreMathVerifier.computeConvert(args);
   4451                 // Validate the outputs.
   4452                 boolean valid = true;
   4453                 if (args.out != arrayOut[i * 2 + j]) {
   4454                     valid = false;
   4455                 }
   4456                 if (!valid) {
   4457                     StringBuilder message = new StringBuilder();
   4458                     message.append("Input inV: ");
   4459                     message.append(String.format("0x%x", args.inV));
   4460                     message.append("\n");
   4461                     message.append("Expected output out: ");
   4462                     message.append(String.format("%d", args.out));
   4463                     message.append("\n");
   4464                     message.append("Actual   output out: ");
   4465                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   4466                     if (args.out != arrayOut[i * 2 + j]) {
   4467                         message.append(" FAIL");
   4468                     }
   4469                     message.append("\n");
   4470                     assertTrue("Incorrect output for checkConvertUshort2Short2" +
   4471                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   4472                 }
   4473             }
   4474         }
   4475     }
   4476 
   4477     private void checkConvertUshort3Short3() {
   4478         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_16, 3, 0xc36bcbe66438bdd5l, false, 15);
   4479         try {
   4480             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 3), INPUTSIZE);
   4481             script.forEach_testConvertShort3Ushort3Short3(inV, out);
   4482             verifyResultsConvertUshort3Short3(inV, out, false);
   4483         } catch (Exception e) {
   4484             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort3Ushort3Short3: " + e.toString());
   4485         }
   4486         try {
   4487             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 3), INPUTSIZE);
   4488             scriptRelaxed.forEach_testConvertShort3Ushort3Short3(inV, out);
   4489             verifyResultsConvertUshort3Short3(inV, out, true);
   4490         } catch (Exception e) {
   4491             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort3Ushort3Short3: " + e.toString());
   4492         }
   4493     }
   4494 
   4495     private void verifyResultsConvertUshort3Short3(Allocation inV, Allocation out, boolean relaxed) {
   4496         short[] arrayInV = new short[INPUTSIZE * 4];
   4497         inV.copyTo(arrayInV);
   4498         short[] arrayOut = new short[INPUTSIZE * 4];
   4499         out.copyTo(arrayOut);
   4500         for (int i = 0; i < INPUTSIZE; i++) {
   4501             for (int j = 0; j < 3 ; j++) {
   4502                 // Extract the inputs.
   4503                 ArgumentsUshortShort args = new ArgumentsUshortShort();
   4504                 args.inV = arrayInV[i * 4 + j];
   4505                 // Figure out what the outputs should have been.
   4506                 CoreMathVerifier.computeConvert(args);
   4507                 // Validate the outputs.
   4508                 boolean valid = true;
   4509                 if (args.out != arrayOut[i * 4 + j]) {
   4510                     valid = false;
   4511                 }
   4512                 if (!valid) {
   4513                     StringBuilder message = new StringBuilder();
   4514                     message.append("Input inV: ");
   4515                     message.append(String.format("0x%x", args.inV));
   4516                     message.append("\n");
   4517                     message.append("Expected output out: ");
   4518                     message.append(String.format("%d", args.out));
   4519                     message.append("\n");
   4520                     message.append("Actual   output out: ");
   4521                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   4522                     if (args.out != arrayOut[i * 4 + j]) {
   4523                         message.append(" FAIL");
   4524                     }
   4525                     message.append("\n");
   4526                     assertTrue("Incorrect output for checkConvertUshort3Short3" +
   4527                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   4528                 }
   4529             }
   4530         }
   4531     }
   4532 
   4533     private void checkConvertUshort4Short4() {
   4534         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_16, 4, 0xc36d95015a53deb3l, false, 15);
   4535         try {
   4536             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 4), INPUTSIZE);
   4537             script.forEach_testConvertShort4Ushort4Short4(inV, out);
   4538             verifyResultsConvertUshort4Short4(inV, out, false);
   4539         } catch (Exception e) {
   4540             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort4Ushort4Short4: " + e.toString());
   4541         }
   4542         try {
   4543             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 4), INPUTSIZE);
   4544             scriptRelaxed.forEach_testConvertShort4Ushort4Short4(inV, out);
   4545             verifyResultsConvertUshort4Short4(inV, out, true);
   4546         } catch (Exception e) {
   4547             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort4Ushort4Short4: " + e.toString());
   4548         }
   4549     }
   4550 
   4551     private void verifyResultsConvertUshort4Short4(Allocation inV, Allocation out, boolean relaxed) {
   4552         short[] arrayInV = new short[INPUTSIZE * 4];
   4553         inV.copyTo(arrayInV);
   4554         short[] arrayOut = new short[INPUTSIZE * 4];
   4555         out.copyTo(arrayOut);
   4556         for (int i = 0; i < INPUTSIZE; i++) {
   4557             for (int j = 0; j < 4 ; j++) {
   4558                 // Extract the inputs.
   4559                 ArgumentsUshortShort args = new ArgumentsUshortShort();
   4560                 args.inV = arrayInV[i * 4 + j];
   4561                 // Figure out what the outputs should have been.
   4562                 CoreMathVerifier.computeConvert(args);
   4563                 // Validate the outputs.
   4564                 boolean valid = true;
   4565                 if (args.out != arrayOut[i * 4 + j]) {
   4566                     valid = false;
   4567                 }
   4568                 if (!valid) {
   4569                     StringBuilder message = new StringBuilder();
   4570                     message.append("Input inV: ");
   4571                     message.append(String.format("0x%x", args.inV));
   4572                     message.append("\n");
   4573                     message.append("Expected output out: ");
   4574                     message.append(String.format("%d", args.out));
   4575                     message.append("\n");
   4576                     message.append("Actual   output out: ");
   4577                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   4578                     if (args.out != arrayOut[i * 4 + j]) {
   4579                         message.append(" FAIL");
   4580                     }
   4581                     message.append("\n");
   4582                     assertTrue("Incorrect output for checkConvertUshort4Short4" +
   4583                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   4584                 }
   4585             }
   4586         }
   4587     }
   4588 
   4589     public class ArgumentsIntShort {
   4590         public int inV;
   4591         public short out;
   4592     }
   4593 
   4594     private void checkConvertInt2Short2() {
   4595         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_32, 2, 0x2a535120b5b27b91l, true, 15);
   4596         try {
   4597             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 2), INPUTSIZE);
   4598             script.forEach_testConvertShort2Int2Short2(inV, out);
   4599             verifyResultsConvertInt2Short2(inV, out, false);
   4600         } catch (Exception e) {
   4601             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort2Int2Short2: " + e.toString());
   4602         }
   4603         try {
   4604             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 2), INPUTSIZE);
   4605             scriptRelaxed.forEach_testConvertShort2Int2Short2(inV, out);
   4606             verifyResultsConvertInt2Short2(inV, out, true);
   4607         } catch (Exception e) {
   4608             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort2Int2Short2: " + e.toString());
   4609         }
   4610     }
   4611 
   4612     private void verifyResultsConvertInt2Short2(Allocation inV, Allocation out, boolean relaxed) {
   4613         int[] arrayInV = new int[INPUTSIZE * 2];
   4614         inV.copyTo(arrayInV);
   4615         short[] arrayOut = new short[INPUTSIZE * 2];
   4616         out.copyTo(arrayOut);
   4617         for (int i = 0; i < INPUTSIZE; i++) {
   4618             for (int j = 0; j < 2 ; j++) {
   4619                 // Extract the inputs.
   4620                 ArgumentsIntShort args = new ArgumentsIntShort();
   4621                 args.inV = arrayInV[i * 2 + j];
   4622                 // Figure out what the outputs should have been.
   4623                 CoreMathVerifier.computeConvert(args);
   4624                 // Validate the outputs.
   4625                 boolean valid = true;
   4626                 if (args.out != arrayOut[i * 2 + j]) {
   4627                     valid = false;
   4628                 }
   4629                 if (!valid) {
   4630                     StringBuilder message = new StringBuilder();
   4631                     message.append("Input inV: ");
   4632                     message.append(String.format("%d", args.inV));
   4633                     message.append("\n");
   4634                     message.append("Expected output out: ");
   4635                     message.append(String.format("%d", args.out));
   4636                     message.append("\n");
   4637                     message.append("Actual   output out: ");
   4638                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   4639                     if (args.out != arrayOut[i * 2 + j]) {
   4640                         message.append(" FAIL");
   4641                     }
   4642                     message.append("\n");
   4643                     assertTrue("Incorrect output for checkConvertInt2Short2" +
   4644                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   4645                 }
   4646             }
   4647         }
   4648     }
   4649 
   4650     private void checkConvertInt3Short3() {
   4651         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_32, 3, 0x2a551a3babcd9c6fl, true, 15);
   4652         try {
   4653             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 3), INPUTSIZE);
   4654             script.forEach_testConvertShort3Int3Short3(inV, out);
   4655             verifyResultsConvertInt3Short3(inV, out, false);
   4656         } catch (Exception e) {
   4657             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort3Int3Short3: " + e.toString());
   4658         }
   4659         try {
   4660             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 3), INPUTSIZE);
   4661             scriptRelaxed.forEach_testConvertShort3Int3Short3(inV, out);
   4662             verifyResultsConvertInt3Short3(inV, out, true);
   4663         } catch (Exception e) {
   4664             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort3Int3Short3: " + e.toString());
   4665         }
   4666     }
   4667 
   4668     private void verifyResultsConvertInt3Short3(Allocation inV, Allocation out, boolean relaxed) {
   4669         int[] arrayInV = new int[INPUTSIZE * 4];
   4670         inV.copyTo(arrayInV);
   4671         short[] arrayOut = new short[INPUTSIZE * 4];
   4672         out.copyTo(arrayOut);
   4673         for (int i = 0; i < INPUTSIZE; i++) {
   4674             for (int j = 0; j < 3 ; j++) {
   4675                 // Extract the inputs.
   4676                 ArgumentsIntShort args = new ArgumentsIntShort();
   4677                 args.inV = arrayInV[i * 4 + j];
   4678                 // Figure out what the outputs should have been.
   4679                 CoreMathVerifier.computeConvert(args);
   4680                 // Validate the outputs.
   4681                 boolean valid = true;
   4682                 if (args.out != arrayOut[i * 4 + j]) {
   4683                     valid = false;
   4684                 }
   4685                 if (!valid) {
   4686                     StringBuilder message = new StringBuilder();
   4687                     message.append("Input inV: ");
   4688                     message.append(String.format("%d", args.inV));
   4689                     message.append("\n");
   4690                     message.append("Expected output out: ");
   4691                     message.append(String.format("%d", args.out));
   4692                     message.append("\n");
   4693                     message.append("Actual   output out: ");
   4694                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   4695                     if (args.out != arrayOut[i * 4 + j]) {
   4696                         message.append(" FAIL");
   4697                     }
   4698                     message.append("\n");
   4699                     assertTrue("Incorrect output for checkConvertInt3Short3" +
   4700                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   4701                 }
   4702             }
   4703         }
   4704     }
   4705 
   4706     private void checkConvertInt4Short4() {
   4707         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_32, 4, 0x2a56e356a1e8bd4dl, true, 15);
   4708         try {
   4709             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 4), INPUTSIZE);
   4710             script.forEach_testConvertShort4Int4Short4(inV, out);
   4711             verifyResultsConvertInt4Short4(inV, out, false);
   4712         } catch (Exception e) {
   4713             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort4Int4Short4: " + e.toString());
   4714         }
   4715         try {
   4716             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 4), INPUTSIZE);
   4717             scriptRelaxed.forEach_testConvertShort4Int4Short4(inV, out);
   4718             verifyResultsConvertInt4Short4(inV, out, true);
   4719         } catch (Exception e) {
   4720             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort4Int4Short4: " + e.toString());
   4721         }
   4722     }
   4723 
   4724     private void verifyResultsConvertInt4Short4(Allocation inV, Allocation out, boolean relaxed) {
   4725         int[] arrayInV = new int[INPUTSIZE * 4];
   4726         inV.copyTo(arrayInV);
   4727         short[] arrayOut = new short[INPUTSIZE * 4];
   4728         out.copyTo(arrayOut);
   4729         for (int i = 0; i < INPUTSIZE; i++) {
   4730             for (int j = 0; j < 4 ; j++) {
   4731                 // Extract the inputs.
   4732                 ArgumentsIntShort args = new ArgumentsIntShort();
   4733                 args.inV = arrayInV[i * 4 + j];
   4734                 // Figure out what the outputs should have been.
   4735                 CoreMathVerifier.computeConvert(args);
   4736                 // Validate the outputs.
   4737                 boolean valid = true;
   4738                 if (args.out != arrayOut[i * 4 + j]) {
   4739                     valid = false;
   4740                 }
   4741                 if (!valid) {
   4742                     StringBuilder message = new StringBuilder();
   4743                     message.append("Input inV: ");
   4744                     message.append(String.format("%d", args.inV));
   4745                     message.append("\n");
   4746                     message.append("Expected output out: ");
   4747                     message.append(String.format("%d", args.out));
   4748                     message.append("\n");
   4749                     message.append("Actual   output out: ");
   4750                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   4751                     if (args.out != arrayOut[i * 4 + j]) {
   4752                         message.append(" FAIL");
   4753                     }
   4754                     message.append("\n");
   4755                     assertTrue("Incorrect output for checkConvertInt4Short4" +
   4756                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   4757                 }
   4758             }
   4759         }
   4760     }
   4761 
   4762     public class ArgumentsUintShort {
   4763         public int inV;
   4764         public short out;
   4765     }
   4766 
   4767     private void checkConvertUint2Short2() {
   4768         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_32, 2, 0xd1e10a6e48348812l, false, 15);
   4769         try {
   4770             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 2), INPUTSIZE);
   4771             script.forEach_testConvertShort2Uint2Short2(inV, out);
   4772             verifyResultsConvertUint2Short2(inV, out, false);
   4773         } catch (Exception e) {
   4774             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort2Uint2Short2: " + e.toString());
   4775         }
   4776         try {
   4777             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 2), INPUTSIZE);
   4778             scriptRelaxed.forEach_testConvertShort2Uint2Short2(inV, out);
   4779             verifyResultsConvertUint2Short2(inV, out, true);
   4780         } catch (Exception e) {
   4781             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort2Uint2Short2: " + e.toString());
   4782         }
   4783     }
   4784 
   4785     private void verifyResultsConvertUint2Short2(Allocation inV, Allocation out, boolean relaxed) {
   4786         int[] arrayInV = new int[INPUTSIZE * 2];
   4787         inV.copyTo(arrayInV);
   4788         short[] arrayOut = new short[INPUTSIZE * 2];
   4789         out.copyTo(arrayOut);
   4790         for (int i = 0; i < INPUTSIZE; i++) {
   4791             for (int j = 0; j < 2 ; j++) {
   4792                 // Extract the inputs.
   4793                 ArgumentsUintShort args = new ArgumentsUintShort();
   4794                 args.inV = arrayInV[i * 2 + j];
   4795                 // Figure out what the outputs should have been.
   4796                 CoreMathVerifier.computeConvert(args);
   4797                 // Validate the outputs.
   4798                 boolean valid = true;
   4799                 if (args.out != arrayOut[i * 2 + j]) {
   4800                     valid = false;
   4801                 }
   4802                 if (!valid) {
   4803                     StringBuilder message = new StringBuilder();
   4804                     message.append("Input inV: ");
   4805                     message.append(String.format("0x%x", args.inV));
   4806                     message.append("\n");
   4807                     message.append("Expected output out: ");
   4808                     message.append(String.format("%d", args.out));
   4809                     message.append("\n");
   4810                     message.append("Actual   output out: ");
   4811                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   4812                     if (args.out != arrayOut[i * 2 + j]) {
   4813                         message.append(" FAIL");
   4814                     }
   4815                     message.append("\n");
   4816                     assertTrue("Incorrect output for checkConvertUint2Short2" +
   4817                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   4818                 }
   4819             }
   4820         }
   4821     }
   4822 
   4823     private void checkConvertUint3Short3() {
   4824         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_32, 3, 0xd1e2d3893e4fa8f0l, false, 15);
   4825         try {
   4826             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 3), INPUTSIZE);
   4827             script.forEach_testConvertShort3Uint3Short3(inV, out);
   4828             verifyResultsConvertUint3Short3(inV, out, false);
   4829         } catch (Exception e) {
   4830             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort3Uint3Short3: " + e.toString());
   4831         }
   4832         try {
   4833             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 3), INPUTSIZE);
   4834             scriptRelaxed.forEach_testConvertShort3Uint3Short3(inV, out);
   4835             verifyResultsConvertUint3Short3(inV, out, true);
   4836         } catch (Exception e) {
   4837             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort3Uint3Short3: " + e.toString());
   4838         }
   4839     }
   4840 
   4841     private void verifyResultsConvertUint3Short3(Allocation inV, Allocation out, boolean relaxed) {
   4842         int[] arrayInV = new int[INPUTSIZE * 4];
   4843         inV.copyTo(arrayInV);
   4844         short[] arrayOut = new short[INPUTSIZE * 4];
   4845         out.copyTo(arrayOut);
   4846         for (int i = 0; i < INPUTSIZE; i++) {
   4847             for (int j = 0; j < 3 ; j++) {
   4848                 // Extract the inputs.
   4849                 ArgumentsUintShort args = new ArgumentsUintShort();
   4850                 args.inV = arrayInV[i * 4 + j];
   4851                 // Figure out what the outputs should have been.
   4852                 CoreMathVerifier.computeConvert(args);
   4853                 // Validate the outputs.
   4854                 boolean valid = true;
   4855                 if (args.out != arrayOut[i * 4 + j]) {
   4856                     valid = false;
   4857                 }
   4858                 if (!valid) {
   4859                     StringBuilder message = new StringBuilder();
   4860                     message.append("Input inV: ");
   4861                     message.append(String.format("0x%x", args.inV));
   4862                     message.append("\n");
   4863                     message.append("Expected output out: ");
   4864                     message.append(String.format("%d", args.out));
   4865                     message.append("\n");
   4866                     message.append("Actual   output out: ");
   4867                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   4868                     if (args.out != arrayOut[i * 4 + j]) {
   4869                         message.append(" FAIL");
   4870                     }
   4871                     message.append("\n");
   4872                     assertTrue("Incorrect output for checkConvertUint3Short3" +
   4873                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   4874                 }
   4875             }
   4876         }
   4877     }
   4878 
   4879     private void checkConvertUint4Short4() {
   4880         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_32, 4, 0xd1e49ca4346ac9cel, false, 15);
   4881         try {
   4882             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 4), INPUTSIZE);
   4883             script.forEach_testConvertShort4Uint4Short4(inV, out);
   4884             verifyResultsConvertUint4Short4(inV, out, false);
   4885         } catch (Exception e) {
   4886             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort4Uint4Short4: " + e.toString());
   4887         }
   4888         try {
   4889             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 4), INPUTSIZE);
   4890             scriptRelaxed.forEach_testConvertShort4Uint4Short4(inV, out);
   4891             verifyResultsConvertUint4Short4(inV, out, true);
   4892         } catch (Exception e) {
   4893             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort4Uint4Short4: " + e.toString());
   4894         }
   4895     }
   4896 
   4897     private void verifyResultsConvertUint4Short4(Allocation inV, Allocation out, boolean relaxed) {
   4898         int[] arrayInV = new int[INPUTSIZE * 4];
   4899         inV.copyTo(arrayInV);
   4900         short[] arrayOut = new short[INPUTSIZE * 4];
   4901         out.copyTo(arrayOut);
   4902         for (int i = 0; i < INPUTSIZE; i++) {
   4903             for (int j = 0; j < 4 ; j++) {
   4904                 // Extract the inputs.
   4905                 ArgumentsUintShort args = new ArgumentsUintShort();
   4906                 args.inV = arrayInV[i * 4 + j];
   4907                 // Figure out what the outputs should have been.
   4908                 CoreMathVerifier.computeConvert(args);
   4909                 // Validate the outputs.
   4910                 boolean valid = true;
   4911                 if (args.out != arrayOut[i * 4 + j]) {
   4912                     valid = false;
   4913                 }
   4914                 if (!valid) {
   4915                     StringBuilder message = new StringBuilder();
   4916                     message.append("Input inV: ");
   4917                     message.append(String.format("0x%x", args.inV));
   4918                     message.append("\n");
   4919                     message.append("Expected output out: ");
   4920                     message.append(String.format("%d", args.out));
   4921                     message.append("\n");
   4922                     message.append("Actual   output out: ");
   4923                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   4924                     if (args.out != arrayOut[i * 4 + j]) {
   4925                         message.append(" FAIL");
   4926                     }
   4927                     message.append("\n");
   4928                     assertTrue("Incorrect output for checkConvertUint4Short4" +
   4929                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   4930                 }
   4931             }
   4932         }
   4933     }
   4934 
   4935     public class ArgumentsFloatUshort {
   4936         public float inV;
   4937         public short out;
   4938     }
   4939 
   4940     private void checkConvertFloat2Ushort2() {
   4941         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x36e4b950b708416fl, 0.0000000000000000000e+00, 6.5535000000000000000e+04);
   4942         try {
   4943             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE);
   4944             script.forEach_testConvertUshort2Float2Ushort2(inV, out);
   4945             verifyResultsConvertFloat2Ushort2(inV, out, false);
   4946         } catch (Exception e) {
   4947             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort2Float2Ushort2: " + e.toString());
   4948         }
   4949         try {
   4950             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE);
   4951             scriptRelaxed.forEach_testConvertUshort2Float2Ushort2(inV, out);
   4952             verifyResultsConvertFloat2Ushort2(inV, out, true);
   4953         } catch (Exception e) {
   4954             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort2Float2Ushort2: " + e.toString());
   4955         }
   4956     }
   4957 
   4958     private void verifyResultsConvertFloat2Ushort2(Allocation inV, Allocation out, boolean relaxed) {
   4959         float[] arrayInV = new float[INPUTSIZE * 2];
   4960         inV.copyTo(arrayInV);
   4961         short[] arrayOut = new short[INPUTSIZE * 2];
   4962         out.copyTo(arrayOut);
   4963         for (int i = 0; i < INPUTSIZE; i++) {
   4964             for (int j = 0; j < 2 ; j++) {
   4965                 // Extract the inputs.
   4966                 ArgumentsFloatUshort args = new ArgumentsFloatUshort();
   4967                 args.inV = arrayInV[i * 2 + j];
   4968                 // Figure out what the outputs should have been.
   4969                 CoreMathVerifier.computeConvert(args);
   4970                 // Validate the outputs.
   4971                 boolean valid = true;
   4972                 if (args.out != arrayOut[i * 2 + j]) {
   4973                     valid = false;
   4974                 }
   4975                 if (!valid) {
   4976                     StringBuilder message = new StringBuilder();
   4977                     message.append("Input inV: ");
   4978                     message.append(String.format("%14.8g {%8x} %15a",
   4979                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
   4980                     message.append("\n");
   4981                     message.append("Expected output out: ");
   4982                     message.append(String.format("0x%x", args.out));
   4983                     message.append("\n");
   4984                     message.append("Actual   output out: ");
   4985                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   4986                     if (args.out != arrayOut[i * 2 + j]) {
   4987                         message.append(" FAIL");
   4988                     }
   4989                     message.append("\n");
   4990                     assertTrue("Incorrect output for checkConvertFloat2Ushort2" +
   4991                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   4992                 }
   4993             }
   4994         }
   4995     }
   4996 
   4997     private void checkConvertFloat3Ushort3() {
   4998         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x373180d80d63d29bl, 0.0000000000000000000e+00, 6.5535000000000000000e+04);
   4999         try {
   5000             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE);
   5001             script.forEach_testConvertUshort3Float3Ushort3(inV, out);
   5002             verifyResultsConvertFloat3Ushort3(inV, out, false);
   5003         } catch (Exception e) {
   5004             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort3Float3Ushort3: " + e.toString());
   5005         }
   5006         try {
   5007             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE);
   5008             scriptRelaxed.forEach_testConvertUshort3Float3Ushort3(inV, out);
   5009             verifyResultsConvertFloat3Ushort3(inV, out, true);
   5010         } catch (Exception e) {
   5011             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort3Float3Ushort3: " + e.toString());
   5012         }
   5013     }
   5014 
   5015     private void verifyResultsConvertFloat3Ushort3(Allocation inV, Allocation out, boolean relaxed) {
   5016         float[] arrayInV = new float[INPUTSIZE * 4];
   5017         inV.copyTo(arrayInV);
   5018         short[] arrayOut = new short[INPUTSIZE * 4];
   5019         out.copyTo(arrayOut);
   5020         for (int i = 0; i < INPUTSIZE; i++) {
   5021             for (int j = 0; j < 3 ; j++) {
   5022                 // Extract the inputs.
   5023                 ArgumentsFloatUshort args = new ArgumentsFloatUshort();
   5024                 args.inV = arrayInV[i * 4 + j];
   5025                 // Figure out what the outputs should have been.
   5026                 CoreMathVerifier.computeConvert(args);
   5027                 // Validate the outputs.
   5028                 boolean valid = true;
   5029                 if (args.out != arrayOut[i * 4 + j]) {
   5030                     valid = false;
   5031                 }
   5032                 if (!valid) {
   5033                     StringBuilder message = new StringBuilder();
   5034                     message.append("Input inV: ");
   5035                     message.append(String.format("%14.8g {%8x} %15a",
   5036                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
   5037                     message.append("\n");
   5038                     message.append("Expected output out: ");
   5039                     message.append(String.format("0x%x", args.out));
   5040                     message.append("\n");
   5041                     message.append("Actual   output out: ");
   5042                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   5043                     if (args.out != arrayOut[i * 4 + j]) {
   5044                         message.append(" FAIL");
   5045                     }
   5046                     message.append("\n");
   5047                     assertTrue("Incorrect output for checkConvertFloat3Ushort3" +
   5048                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   5049                 }
   5050             }
   5051         }
   5052     }
   5053 
   5054     private void checkConvertFloat4Ushort4() {
   5055         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x377e485f63bf63c7l, 0.0000000000000000000e+00, 6.5535000000000000000e+04);
   5056         try {
   5057             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE);
   5058             script.forEach_testConvertUshort4Float4Ushort4(inV, out);
   5059             verifyResultsConvertFloat4Ushort4(inV, out, false);
   5060         } catch (Exception e) {
   5061             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort4Float4Ushort4: " + e.toString());
   5062         }
   5063         try {
   5064             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE);
   5065             scriptRelaxed.forEach_testConvertUshort4Float4Ushort4(inV, out);
   5066             verifyResultsConvertFloat4Ushort4(inV, out, true);
   5067         } catch (Exception e) {
   5068             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort4Float4Ushort4: " + e.toString());
   5069         }
   5070     }
   5071 
   5072     private void verifyResultsConvertFloat4Ushort4(Allocation inV, Allocation out, boolean relaxed) {
   5073         float[] arrayInV = new float[INPUTSIZE * 4];
   5074         inV.copyTo(arrayInV);
   5075         short[] arrayOut = new short[INPUTSIZE * 4];
   5076         out.copyTo(arrayOut);
   5077         for (int i = 0; i < INPUTSIZE; i++) {
   5078             for (int j = 0; j < 4 ; j++) {
   5079                 // Extract the inputs.
   5080                 ArgumentsFloatUshort args = new ArgumentsFloatUshort();
   5081                 args.inV = arrayInV[i * 4 + j];
   5082                 // Figure out what the outputs should have been.
   5083                 CoreMathVerifier.computeConvert(args);
   5084                 // Validate the outputs.
   5085                 boolean valid = true;
   5086                 if (args.out != arrayOut[i * 4 + j]) {
   5087                     valid = false;
   5088                 }
   5089                 if (!valid) {
   5090                     StringBuilder message = new StringBuilder();
   5091                     message.append("Input inV: ");
   5092                     message.append(String.format("%14.8g {%8x} %15a",
   5093                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
   5094                     message.append("\n");
   5095                     message.append("Expected output out: ");
   5096                     message.append(String.format("0x%x", args.out));
   5097                     message.append("\n");
   5098                     message.append("Actual   output out: ");
   5099                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   5100                     if (args.out != arrayOut[i * 4 + j]) {
   5101                         message.append(" FAIL");
   5102                     }
   5103                     message.append("\n");
   5104                     assertTrue("Incorrect output for checkConvertFloat4Ushort4" +
   5105                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   5106                 }
   5107             }
   5108         }
   5109     }
   5110 
   5111     public class ArgumentsCharUshort {
   5112         public byte inV;
   5113         public short out;
   5114     }
   5115 
   5116     private void checkConvertChar2Ushort2() {
   5117         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_8, 2, 0xd88c0b0ed8f1eeafl, false, 7);
   5118         try {
   5119             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE);
   5120             script.forEach_testConvertUshort2Char2Ushort2(inV, out);
   5121             verifyResultsConvertChar2Ushort2(inV, out, false);
   5122         } catch (Exception e) {
   5123             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort2Char2Ushort2: " + e.toString());
   5124         }
   5125         try {
   5126             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE);
   5127             scriptRelaxed.forEach_testConvertUshort2Char2Ushort2(inV, out);
   5128             verifyResultsConvertChar2Ushort2(inV, out, true);
   5129         } catch (Exception e) {
   5130             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort2Char2Ushort2: " + e.toString());
   5131         }
   5132     }
   5133 
   5134     private void verifyResultsConvertChar2Ushort2(Allocation inV, Allocation out, boolean relaxed) {
   5135         byte[] arrayInV = new byte[INPUTSIZE * 2];
   5136         inV.copyTo(arrayInV);
   5137         short[] arrayOut = new short[INPUTSIZE * 2];
   5138         out.copyTo(arrayOut);
   5139         for (int i = 0; i < INPUTSIZE; i++) {
   5140             for (int j = 0; j < 2 ; j++) {
   5141                 // Extract the inputs.
   5142                 ArgumentsCharUshort args = new ArgumentsCharUshort();
   5143                 args.inV = arrayInV[i * 2 + j];
   5144                 // Figure out what the outputs should have been.
   5145                 CoreMathVerifier.computeConvert(args);
   5146                 // Validate the outputs.
   5147                 boolean valid = true;
   5148                 if (args.out != arrayOut[i * 2 + j]) {
   5149                     valid = false;
   5150                 }
   5151                 if (!valid) {
   5152                     StringBuilder message = new StringBuilder();
   5153                     message.append("Input inV: ");
   5154                     message.append(String.format("%d", args.inV));
   5155                     message.append("\n");
   5156                     message.append("Expected output out: ");
   5157                     message.append(String.format("0x%x", args.out));
   5158                     message.append("\n");
   5159                     message.append("Actual   output out: ");
   5160                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   5161                     if (args.out != arrayOut[i * 2 + j]) {
   5162                         message.append(" FAIL");
   5163                     }
   5164                     message.append("\n");
   5165                     assertTrue("Incorrect output for checkConvertChar2Ushort2" +
   5166                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   5167                 }
   5168             }
   5169         }
   5170     }
   5171 
   5172     private void checkConvertChar3Ushort3() {
   5173         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_8, 3, 0xd8d8d2962f4d7fdbl, false, 7);
   5174         try {
   5175             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE);
   5176             script.forEach_testConvertUshort3Char3Ushort3(inV, out);
   5177             verifyResultsConvertChar3Ushort3(inV, out, false);
   5178         } catch (Exception e) {
   5179             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort3Char3Ushort3: " + e.toString());
   5180         }
   5181         try {
   5182             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE);
   5183             scriptRelaxed.forEach_testConvertUshort3Char3Ushort3(inV, out);
   5184             verifyResultsConvertChar3Ushort3(inV, out, true);
   5185         } catch (Exception e) {
   5186             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort3Char3Ushort3: " + e.toString());
   5187         }
   5188     }
   5189 
   5190     private void verifyResultsConvertChar3Ushort3(Allocation inV, Allocation out, boolean relaxed) {
   5191         byte[] arrayInV = new byte[INPUTSIZE * 4];
   5192         inV.copyTo(arrayInV);
   5193         short[] arrayOut = new short[INPUTSIZE * 4];
   5194         out.copyTo(arrayOut);
   5195         for (int i = 0; i < INPUTSIZE; i++) {
   5196             for (int j = 0; j < 3 ; j++) {
   5197                 // Extract the inputs.
   5198                 ArgumentsCharUshort args = new ArgumentsCharUshort();
   5199                 args.inV = arrayInV[i * 4 + j];
   5200                 // Figure out what the outputs should have been.
   5201                 CoreMathVerifier.computeConvert(args);
   5202                 // Validate the outputs.
   5203                 boolean valid = true;
   5204                 if (args.out != arrayOut[i * 4 + j]) {
   5205                     valid = false;
   5206                 }
   5207                 if (!valid) {
   5208                     StringBuilder message = new StringBuilder();
   5209                     message.append("Input inV: ");
   5210                     message.append(String.format("%d", args.inV));
   5211                     message.append("\n");
   5212                     message.append("Expected output out: ");
   5213                     message.append(String.format("0x%x", args.out));
   5214                     message.append("\n");
   5215                     message.append("Actual   output out: ");
   5216                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   5217                     if (args.out != arrayOut[i * 4 + j]) {
   5218                         message.append(" FAIL");
   5219                     }
   5220                     message.append("\n");
   5221                     assertTrue("Incorrect output for checkConvertChar3Ushort3" +
   5222                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   5223                 }
   5224             }
   5225         }
   5226     }
   5227 
   5228     private void checkConvertChar4Ushort4() {
   5229         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_8, 4, 0xd9259a1d85a91107l, false, 7);
   5230         try {
   5231             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE);
   5232             script.forEach_testConvertUshort4Char4Ushort4(inV, out);
   5233             verifyResultsConvertChar4Ushort4(inV, out, false);
   5234         } catch (Exception e) {
   5235             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort4Char4Ushort4: " + e.toString());
   5236         }
   5237         try {
   5238             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE);
   5239             scriptRelaxed.forEach_testConvertUshort4Char4Ushort4(inV, out);
   5240             verifyResultsConvertChar4Ushort4(inV, out, true);
   5241         } catch (Exception e) {
   5242             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort4Char4Ushort4: " + e.toString());
   5243         }
   5244     }
   5245 
   5246     private void verifyResultsConvertChar4Ushort4(Allocation inV, Allocation out, boolean relaxed) {
   5247         byte[] arrayInV = new byte[INPUTSIZE * 4];
   5248         inV.copyTo(arrayInV);
   5249         short[] arrayOut = new short[INPUTSIZE * 4];
   5250         out.copyTo(arrayOut);
   5251         for (int i = 0; i < INPUTSIZE; i++) {
   5252             for (int j = 0; j < 4 ; j++) {
   5253                 // Extract the inputs.
   5254                 ArgumentsCharUshort args = new ArgumentsCharUshort();
   5255                 args.inV = arrayInV[i * 4 + j];
   5256                 // Figure out what the outputs should have been.
   5257                 CoreMathVerifier.computeConvert(args);
   5258                 // Validate the outputs.
   5259                 boolean valid = true;
   5260                 if (args.out != arrayOut[i * 4 + j]) {
   5261                     valid = false;
   5262                 }
   5263                 if (!valid) {
   5264                     StringBuilder message = new StringBuilder();
   5265                     message.append("Input inV: ");
   5266                     message.append(String.format("%d", args.inV));
   5267                     message.append("\n");
   5268                     message.append("Expected output out: ");
   5269                     message.append(String.format("0x%x", args.out));
   5270                     message.append("\n");
   5271                     message.append("Actual   output out: ");
   5272                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   5273                     if (args.out != arrayOut[i * 4 + j]) {
   5274                         message.append(" FAIL");
   5275                     }
   5276                     message.append("\n");
   5277                     assertTrue("Incorrect output for checkConvertChar4Ushort4" +
   5278                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   5279                 }
   5280             }
   5281         }
   5282     }
   5283 
   5284     public class ArgumentsUcharUshort {
   5285         public byte inV;
   5286         public short out;
   5287     }
   5288 
   5289     private void checkConvertUchar2Ushort2() {
   5290         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_8, 2, 0x72b6c56063e3e68l, false, 8);
   5291         try {
   5292             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE);
   5293             script.forEach_testConvertUshort2Uchar2Ushort2(inV, out);
   5294             verifyResultsConvertUchar2Ushort2(inV, out, false);
   5295         } catch (Exception e) {
   5296             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort2Uchar2Ushort2: " + e.toString());
   5297         }
   5298         try {
   5299             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE);
   5300             scriptRelaxed.forEach_testConvertUshort2Uchar2Ushort2(inV, out);
   5301             verifyResultsConvertUchar2Ushort2(inV, out, true);
   5302         } catch (Exception e) {
   5303             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort2Uchar2Ushort2: " + e.toString());
   5304         }
   5305     }
   5306 
   5307     private void verifyResultsConvertUchar2Ushort2(Allocation inV, Allocation out, boolean relaxed) {
   5308         byte[] arrayInV = new byte[INPUTSIZE * 2];
   5309         inV.copyTo(arrayInV);
   5310         short[] arrayOut = new short[INPUTSIZE * 2];
   5311         out.copyTo(arrayOut);
   5312         for (int i = 0; i < INPUTSIZE; i++) {
   5313             for (int j = 0; j < 2 ; j++) {
   5314                 // Extract the inputs.
   5315                 ArgumentsUcharUshort args = new ArgumentsUcharUshort();
   5316                 args.inV = arrayInV[i * 2 + j];
   5317                 // Figure out what the outputs should have been.
   5318                 CoreMathVerifier.computeConvert(args);
   5319                 // Validate the outputs.
   5320                 boolean valid = true;
   5321                 if (args.out != arrayOut[i * 2 + j]) {
   5322                     valid = false;
   5323                 }
   5324                 if (!valid) {
   5325                     StringBuilder message = new StringBuilder();
   5326                     message.append("Input inV: ");
   5327                     message.append(String.format("0x%x", args.inV));
   5328                     message.append("\n");
   5329                     message.append("Expected output out: ");
   5330                     message.append(String.format("0x%x", args.out));
   5331                     message.append("\n");
   5332                     message.append("Actual   output out: ");
   5333                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   5334                     if (args.out != arrayOut[i * 2 + j]) {
   5335                         message.append(" FAIL");
   5336                     }
   5337                     message.append("\n");
   5338                     assertTrue("Incorrect output for checkConvertUchar2Ushort2" +
   5339                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   5340                 }
   5341             }
   5342         }
   5343     }
   5344 
   5345     private void checkConvertUchar3Ushort3() {
   5346         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_8, 3, 0x77833dd5c99cf94l, false, 8);
   5347         try {
   5348             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE);
   5349             script.forEach_testConvertUshort3Uchar3Ushort3(inV, out);
   5350             verifyResultsConvertUchar3Ushort3(inV, out, false);
   5351         } catch (Exception e) {
   5352             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort3Uchar3Ushort3: " + e.toString());
   5353         }
   5354         try {
   5355             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE);
   5356             scriptRelaxed.forEach_testConvertUshort3Uchar3Ushort3(inV, out);
   5357             verifyResultsConvertUchar3Ushort3(inV, out, true);
   5358         } catch (Exception e) {
   5359             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort3Uchar3Ushort3: " + e.toString());
   5360         }
   5361     }
   5362 
   5363     private void verifyResultsConvertUchar3Ushort3(Allocation inV, Allocation out, boolean relaxed) {
   5364         byte[] arrayInV = new byte[INPUTSIZE * 4];
   5365         inV.copyTo(arrayInV);
   5366         short[] arrayOut = new short[INPUTSIZE * 4];
   5367         out.copyTo(arrayOut);
   5368         for (int i = 0; i < INPUTSIZE; i++) {
   5369             for (int j = 0; j < 3 ; j++) {
   5370                 // Extract the inputs.
   5371                 ArgumentsUcharUshort args = new ArgumentsUcharUshort();
   5372                 args.inV = arrayInV[i * 4 + j];
   5373                 // Figure out what the outputs should have been.
   5374                 CoreMathVerifier.computeConvert(args);
   5375                 // Validate the outputs.
   5376                 boolean valid = true;
   5377                 if (args.out != arrayOut[i * 4 + j]) {
   5378                     valid = false;
   5379                 }
   5380                 if (!valid) {
   5381                     StringBuilder message = new StringBuilder();
   5382                     message.append("Input inV: ");
   5383                     message.append(String.format("0x%x", args.inV));
   5384                     message.append("\n");
   5385                     message.append("Expected output out: ");
   5386                     message.append(String.format("0x%x", args.out));
   5387                     message.append("\n");
   5388                     message.append("Actual   output out: ");
   5389                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   5390                     if (args.out != arrayOut[i * 4 + j]) {
   5391                         message.append(" FAIL");
   5392                     }
   5393                     message.append("\n");
   5394                     assertTrue("Incorrect output for checkConvertUchar3Ushort3" +
   5395                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   5396                 }
   5397             }
   5398         }
   5399     }
   5400 
   5401     private void checkConvertUchar4Ushort4() {
   5402         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_8, 4, 0x7c4fb64b2f560c0l, false, 8);
   5403         try {
   5404             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE);
   5405             script.forEach_testConvertUshort4Uchar4Ushort4(inV, out);
   5406             verifyResultsConvertUchar4Ushort4(inV, out, false);
   5407         } catch (Exception e) {
   5408             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort4Uchar4Ushort4: " + e.toString());
   5409         }
   5410         try {
   5411             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE);
   5412             scriptRelaxed.forEach_testConvertUshort4Uchar4Ushort4(inV, out);
   5413             verifyResultsConvertUchar4Ushort4(inV, out, true);
   5414         } catch (Exception e) {
   5415             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort4Uchar4Ushort4: " + e.toString());
   5416         }
   5417     }
   5418 
   5419     private void verifyResultsConvertUchar4Ushort4(Allocation inV, Allocation out, boolean relaxed) {
   5420         byte[] arrayInV = new byte[INPUTSIZE * 4];
   5421         inV.copyTo(arrayInV);
   5422         short[] arrayOut = new short[INPUTSIZE * 4];
   5423         out.copyTo(arrayOut);
   5424         for (int i = 0; i < INPUTSIZE; i++) {
   5425             for (int j = 0; j < 4 ; j++) {
   5426                 // Extract the inputs.
   5427                 ArgumentsUcharUshort args = new ArgumentsUcharUshort();
   5428                 args.inV = arrayInV[i * 4 + j];
   5429                 // Figure out what the outputs should have been.
   5430                 CoreMathVerifier.computeConvert(args);
   5431                 // Validate the outputs.
   5432                 boolean valid = true;
   5433                 if (args.out != arrayOut[i * 4 + j]) {
   5434                     valid = false;
   5435                 }
   5436                 if (!valid) {
   5437                     StringBuilder message = new StringBuilder();
   5438                     message.append("Input inV: ");
   5439                     message.append(String.format("0x%x", args.inV));
   5440                     message.append("\n");
   5441                     message.append("Expected output out: ");
   5442                     message.append(String.format("0x%x", args.out));
   5443                     message.append("\n");
   5444                     message.append("Actual   output out: ");
   5445                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   5446                     if (args.out != arrayOut[i * 4 + j]) {
   5447                         message.append(" FAIL");
   5448                     }
   5449                     message.append("\n");
   5450                     assertTrue("Incorrect output for checkConvertUchar4Ushort4" +
   5451                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   5452                 }
   5453             }
   5454         }
   5455     }
   5456 
   5457     public class ArgumentsShortUshort {
   5458         public short inV;
   5459         public short out;
   5460     }
   5461 
   5462     private void checkConvertShort2Ushort2() {
   5463         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_16, 2, 0xfe0d269c7264c053l, false, 15);
   5464         try {
   5465             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE);
   5466             script.forEach_testConvertUshort2Short2Ushort2(inV, out);
   5467             verifyResultsConvertShort2Ushort2(inV, out, false);
   5468         } catch (Exception e) {
   5469             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort2Short2Ushort2: " + e.toString());
   5470         }
   5471         try {
   5472             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE);
   5473             scriptRelaxed.forEach_testConvertUshort2Short2Ushort2(inV, out);
   5474             verifyResultsConvertShort2Ushort2(inV, out, true);
   5475         } catch (Exception e) {
   5476             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort2Short2Ushort2: " + e.toString());
   5477         }
   5478     }
   5479 
   5480     private void verifyResultsConvertShort2Ushort2(Allocation inV, Allocation out, boolean relaxed) {
   5481         short[] arrayInV = new short[INPUTSIZE * 2];
   5482         inV.copyTo(arrayInV);
   5483         short[] arrayOut = new short[INPUTSIZE * 2];
   5484         out.copyTo(arrayOut);
   5485         for (int i = 0; i < INPUTSIZE; i++) {
   5486             for (int j = 0; j < 2 ; j++) {
   5487                 // Extract the inputs.
   5488                 ArgumentsShortUshort args = new ArgumentsShortUshort();
   5489                 args.inV = arrayInV[i * 2 + j];
   5490                 // Figure out what the outputs should have been.
   5491                 CoreMathVerifier.computeConvert(args);
   5492                 // Validate the outputs.
   5493                 boolean valid = true;
   5494                 if (args.out != arrayOut[i * 2 + j]) {
   5495                     valid = false;
   5496                 }
   5497                 if (!valid) {
   5498                     StringBuilder message = new StringBuilder();
   5499                     message.append("Input inV: ");
   5500                     message.append(String.format("%d", args.inV));
   5501                     message.append("\n");
   5502                     message.append("Expected output out: ");
   5503                     message.append(String.format("0x%x", args.out));
   5504                     message.append("\n");
   5505                     message.append("Actual   output out: ");
   5506                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   5507                     if (args.out != arrayOut[i * 2 + j]) {
   5508                         message.append(" FAIL");
   5509                     }
   5510                     message.append("\n");
   5511                     assertTrue("Incorrect output for checkConvertShort2Ushort2" +
   5512                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   5513                 }
   5514             }
   5515         }
   5516     }
   5517 
   5518     private void checkConvertShort3Ushort3() {
   5519         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_16, 3, 0xfe59ee23c8c0517fl, false, 15);
   5520         try {
   5521             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE);
   5522             script.forEach_testConvertUshort3Short3Ushort3(inV, out);
   5523             verifyResultsConvertShort3Ushort3(inV, out, false);
   5524         } catch (Exception e) {
   5525             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort3Short3Ushort3: " + e.toString());
   5526         }
   5527         try {
   5528             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE);
   5529             scriptRelaxed.forEach_testConvertUshort3Short3Ushort3(inV, out);
   5530             verifyResultsConvertShort3Ushort3(inV, out, true);
   5531         } catch (Exception e) {
   5532             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort3Short3Ushort3: " + e.toString());
   5533         }
   5534     }
   5535 
   5536     private void verifyResultsConvertShort3Ushort3(Allocation inV, Allocation out, boolean relaxed) {
   5537         short[] arrayInV = new short[INPUTSIZE * 4];
   5538         inV.copyTo(arrayInV);
   5539         short[] arrayOut = new short[INPUTSIZE * 4];
   5540         out.copyTo(arrayOut);
   5541         for (int i = 0; i < INPUTSIZE; i++) {
   5542             for (int j = 0; j < 3 ; j++) {
   5543                 // Extract the inputs.
   5544                 ArgumentsShortUshort args = new ArgumentsShortUshort();
   5545                 args.inV = arrayInV[i * 4 + j];
   5546                 // Figure out what the outputs should have been.
   5547                 CoreMathVerifier.computeConvert(args);
   5548                 // Validate the outputs.
   5549                 boolean valid = true;
   5550                 if (args.out != arrayOut[i * 4 + j]) {
   5551                     valid = false;
   5552                 }
   5553                 if (!valid) {
   5554                     StringBuilder message = new StringBuilder();
   5555                     message.append("Input inV: ");
   5556                     message.append(String.format("%d", args.inV));
   5557                     message.append("\n");
   5558                     message.append("Expected output out: ");
   5559                     message.append(String.format("0x%x", args.out));
   5560                     message.append("\n");
   5561                     message.append("Actual   output out: ");
   5562                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   5563                     if (args.out != arrayOut[i * 4 + j]) {
   5564                         message.append(" FAIL");
   5565                     }
   5566                     message.append("\n");
   5567                     assertTrue("Incorrect output for checkConvertShort3Ushort3" +
   5568                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   5569                 }
   5570             }
   5571         }
   5572     }
   5573 
   5574     private void checkConvertShort4Ushort4() {
   5575         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_16, 4, 0xfea6b5ab1f1be2abl, false, 15);
   5576         try {
   5577             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE);
   5578             script.forEach_testConvertUshort4Short4Ushort4(inV, out);
   5579             verifyResultsConvertShort4Ushort4(inV, out, false);
   5580         } catch (Exception e) {
   5581             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort4Short4Ushort4: " + e.toString());
   5582         }
   5583         try {
   5584             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE);
   5585             scriptRelaxed.forEach_testConvertUshort4Short4Ushort4(inV, out);
   5586             verifyResultsConvertShort4Ushort4(inV, out, true);
   5587         } catch (Exception e) {
   5588             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort4Short4Ushort4: " + e.toString());
   5589         }
   5590     }
   5591 
   5592     private void verifyResultsConvertShort4Ushort4(Allocation inV, Allocation out, boolean relaxed) {
   5593         short[] arrayInV = new short[INPUTSIZE * 4];
   5594         inV.copyTo(arrayInV);
   5595         short[] arrayOut = new short[INPUTSIZE * 4];
   5596         out.copyTo(arrayOut);
   5597         for (int i = 0; i < INPUTSIZE; i++) {
   5598             for (int j = 0; j < 4 ; j++) {
   5599                 // Extract the inputs.
   5600                 ArgumentsShortUshort args = new ArgumentsShortUshort();
   5601                 args.inV = arrayInV[i * 4 + j];
   5602                 // Figure out what the outputs should have been.
   5603                 CoreMathVerifier.computeConvert(args);
   5604                 // Validate the outputs.
   5605                 boolean valid = true;
   5606                 if (args.out != arrayOut[i * 4 + j]) {
   5607                     valid = false;
   5608                 }
   5609                 if (!valid) {
   5610                     StringBuilder message = new StringBuilder();
   5611                     message.append("Input inV: ");
   5612                     message.append(String.format("%d", args.inV));
   5613                     message.append("\n");
   5614                     message.append("Expected output out: ");
   5615                     message.append(String.format("0x%x", args.out));
   5616                     message.append("\n");
   5617                     message.append("Actual   output out: ");
   5618                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   5619                     if (args.out != arrayOut[i * 4 + j]) {
   5620                         message.append(" FAIL");
   5621                     }
   5622                     message.append("\n");
   5623                     assertTrue("Incorrect output for checkConvertShort4Ushort4" +
   5624                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   5625                 }
   5626             }
   5627         }
   5628     }
   5629 
   5630     public class ArgumentsUshortUshort {
   5631         public short inV;
   5632         public short out;
   5633     }
   5634 
   5635     private void checkConvertUshort2Ushort2() {
   5636         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_16, 2, 0xd2d27d910e362466l, false, 16);
   5637         try {
   5638             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE);
   5639             script.forEach_testConvertUshort2Ushort2Ushort2(inV, out);
   5640             verifyResultsConvertUshort2Ushort2(inV, out, false);
   5641         } catch (Exception e) {
   5642             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort2Ushort2Ushort2: " + e.toString());
   5643         }
   5644         try {
   5645             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE);
   5646             scriptRelaxed.forEach_testConvertUshort2Ushort2Ushort2(inV, out);
   5647             verifyResultsConvertUshort2Ushort2(inV, out, true);
   5648         } catch (Exception e) {
   5649             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort2Ushort2Ushort2: " + e.toString());
   5650         }
   5651     }
   5652 
   5653     private void verifyResultsConvertUshort2Ushort2(Allocation inV, Allocation out, boolean relaxed) {
   5654         short[] arrayInV = new short[INPUTSIZE * 2];
   5655         inV.copyTo(arrayInV);
   5656         short[] arrayOut = new short[INPUTSIZE * 2];
   5657         out.copyTo(arrayOut);
   5658         for (int i = 0; i < INPUTSIZE; i++) {
   5659             for (int j = 0; j < 2 ; j++) {
   5660                 // Extract the inputs.
   5661                 ArgumentsUshortUshort args = new ArgumentsUshortUshort();
   5662                 args.inV = arrayInV[i * 2 + j];
   5663                 // Figure out what the outputs should have been.
   5664                 CoreMathVerifier.computeConvert(args);
   5665                 // Validate the outputs.
   5666                 boolean valid = true;
   5667                 if (args.out != arrayOut[i * 2 + j]) {
   5668                     valid = false;
   5669                 }
   5670                 if (!valid) {
   5671                     StringBuilder message = new StringBuilder();
   5672                     message.append("Input inV: ");
   5673                     message.append(String.format("0x%x", args.inV));
   5674                     message.append("\n");
   5675                     message.append("Expected output out: ");
   5676                     message.append(String.format("0x%x", args.out));
   5677                     message.append("\n");
   5678                     message.append("Actual   output out: ");
   5679                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   5680                     if (args.out != arrayOut[i * 2 + j]) {
   5681                         message.append(" FAIL");
   5682                     }
   5683                     message.append("\n");
   5684                     assertTrue("Incorrect output for checkConvertUshort2Ushort2" +
   5685                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   5686                 }
   5687             }
   5688         }
   5689     }
   5690 
   5691     private void checkConvertUshort3Ushort3() {
   5692         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_16, 3, 0xd31f45186491b592l, false, 16);
   5693         try {
   5694             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE);
   5695             script.forEach_testConvertUshort3Ushort3Ushort3(inV, out);
   5696             verifyResultsConvertUshort3Ushort3(inV, out, false);
   5697         } catch (Exception e) {
   5698             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort3Ushort3Ushort3: " + e.toString());
   5699         }
   5700         try {
   5701             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE);
   5702             scriptRelaxed.forEach_testConvertUshort3Ushort3Ushort3(inV, out);
   5703             verifyResultsConvertUshort3Ushort3(inV, out, true);
   5704         } catch (Exception e) {
   5705             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort3Ushort3Ushort3: " + e.toString());
   5706         }
   5707     }
   5708 
   5709     private void verifyResultsConvertUshort3Ushort3(Allocation inV, Allocation out, boolean relaxed) {
   5710         short[] arrayInV = new short[INPUTSIZE * 4];
   5711         inV.copyTo(arrayInV);
   5712         short[] arrayOut = new short[INPUTSIZE * 4];
   5713         out.copyTo(arrayOut);
   5714         for (int i = 0; i < INPUTSIZE; i++) {
   5715             for (int j = 0; j < 3 ; j++) {
   5716                 // Extract the inputs.
   5717                 ArgumentsUshortUshort args = new ArgumentsUshortUshort();
   5718                 args.inV = arrayInV[i * 4 + j];
   5719                 // Figure out what the outputs should have been.
   5720                 CoreMathVerifier.computeConvert(args);
   5721                 // Validate the outputs.
   5722                 boolean valid = true;
   5723                 if (args.out != arrayOut[i * 4 + j]) {
   5724                     valid = false;
   5725                 }
   5726                 if (!valid) {
   5727                     StringBuilder message = new StringBuilder();
   5728                     message.append("Input inV: ");
   5729                     message.append(String.format("0x%x", args.inV));
   5730                     message.append("\n");
   5731                     message.append("Expected output out: ");
   5732                     message.append(String.format("0x%x", args.out));
   5733                     message.append("\n");
   5734                     message.append("Actual   output out: ");
   5735                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   5736                     if (args.out != arrayOut[i * 4 + j]) {
   5737                         message.append(" FAIL");
   5738                     }
   5739                     message.append("\n");
   5740                     assertTrue("Incorrect output for checkConvertUshort3Ushort3" +
   5741                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   5742                 }
   5743             }
   5744         }
   5745     }
   5746 
   5747     private void checkConvertUshort4Ushort4() {
   5748         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_16, 4, 0xd36c0c9fbaed46bel, false, 16);
   5749         try {
   5750             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE);
   5751             script.forEach_testConvertUshort4Ushort4Ushort4(inV, out);
   5752             verifyResultsConvertUshort4Ushort4(inV, out, false);
   5753         } catch (Exception e) {
   5754             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort4Ushort4Ushort4: " + e.toString());
   5755         }
   5756         try {
   5757             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE);
   5758             scriptRelaxed.forEach_testConvertUshort4Ushort4Ushort4(inV, out);
   5759             verifyResultsConvertUshort4Ushort4(inV, out, true);
   5760         } catch (Exception e) {
   5761             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort4Ushort4Ushort4: " + e.toString());
   5762         }
   5763     }
   5764 
   5765     private void verifyResultsConvertUshort4Ushort4(Allocation inV, Allocation out, boolean relaxed) {
   5766         short[] arrayInV = new short[INPUTSIZE * 4];
   5767         inV.copyTo(arrayInV);
   5768         short[] arrayOut = new short[INPUTSIZE * 4];
   5769         out.copyTo(arrayOut);
   5770         for (int i = 0; i < INPUTSIZE; i++) {
   5771             for (int j = 0; j < 4 ; j++) {
   5772                 // Extract the inputs.
   5773                 ArgumentsUshortUshort args = new ArgumentsUshortUshort();
   5774                 args.inV = arrayInV[i * 4 + j];
   5775                 // Figure out what the outputs should have been.
   5776                 CoreMathVerifier.computeConvert(args);
   5777                 // Validate the outputs.
   5778                 boolean valid = true;
   5779                 if (args.out != arrayOut[i * 4 + j]) {
   5780                     valid = false;
   5781                 }
   5782                 if (!valid) {
   5783                     StringBuilder message = new StringBuilder();
   5784                     message.append("Input inV: ");
   5785                     message.append(String.format("0x%x", args.inV));
   5786                     message.append("\n");
   5787                     message.append("Expected output out: ");
   5788                     message.append(String.format("0x%x", args.out));
   5789                     message.append("\n");
   5790                     message.append("Actual   output out: ");
   5791                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   5792                     if (args.out != arrayOut[i * 4 + j]) {
   5793                         message.append(" FAIL");
   5794                     }
   5795                     message.append("\n");
   5796                     assertTrue("Incorrect output for checkConvertUshort4Ushort4" +
   5797                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   5798                 }
   5799             }
   5800         }
   5801     }
   5802 
   5803     public class ArgumentsIntUshort {
   5804         public int inV;
   5805         public short out;
   5806     }
   5807 
   5808     private void checkConvertInt2Ushort2() {
   5809         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_32, 2, 0x1c02a5e414378844l, false, 16);
   5810         try {
   5811             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE);
   5812             script.forEach_testConvertUshort2Int2Ushort2(inV, out);
   5813             verifyResultsConvertInt2Ushort2(inV, out, false);
   5814         } catch (Exception e) {
   5815             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort2Int2Ushort2: " + e.toString());
   5816         }
   5817         try {
   5818             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE);
   5819             scriptRelaxed.forEach_testConvertUshort2Int2Ushort2(inV, out);
   5820             verifyResultsConvertInt2Ushort2(inV, out, true);
   5821         } catch (Exception e) {
   5822             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort2Int2Ushort2: " + e.toString());
   5823         }
   5824     }
   5825 
   5826     private void verifyResultsConvertInt2Ushort2(Allocation inV, Allocation out, boolean relaxed) {
   5827         int[] arrayInV = new int[INPUTSIZE * 2];
   5828         inV.copyTo(arrayInV);
   5829         short[] arrayOut = new short[INPUTSIZE * 2];
   5830         out.copyTo(arrayOut);
   5831         for (int i = 0; i < INPUTSIZE; i++) {
   5832             for (int j = 0; j < 2 ; j++) {
   5833                 // Extract the inputs.
   5834                 ArgumentsIntUshort args = new ArgumentsIntUshort();
   5835                 args.inV = arrayInV[i * 2 + j];
   5836                 // Figure out what the outputs should have been.
   5837                 CoreMathVerifier.computeConvert(args);
   5838                 // Validate the outputs.
   5839                 boolean valid = true;
   5840                 if (args.out != arrayOut[i * 2 + j]) {
   5841                     valid = false;
   5842                 }
   5843                 if (!valid) {
   5844                     StringBuilder message = new StringBuilder();
   5845                     message.append("Input inV: ");
   5846                     message.append(String.format("%d", args.inV));
   5847                     message.append("\n");
   5848                     message.append("Expected output out: ");
   5849                     message.append(String.format("0x%x", args.out));
   5850                     message.append("\n");
   5851                     message.append("Actual   output out: ");
   5852                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   5853                     if (args.out != arrayOut[i * 2 + j]) {
   5854                         message.append(" FAIL");
   5855                     }
   5856                     message.append("\n");
   5857                     assertTrue("Incorrect output for checkConvertInt2Ushort2" +
   5858                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   5859                 }
   5860             }
   5861         }
   5862     }
   5863 
   5864     private void checkConvertInt3Ushort3() {
   5865         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_32, 3, 0x1c4f6d6b6a931970l, false, 16);
   5866         try {
   5867             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE);
   5868             script.forEach_testConvertUshort3Int3Ushort3(inV, out);
   5869             verifyResultsConvertInt3Ushort3(inV, out, false);
   5870         } catch (Exception e) {
   5871             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort3Int3Ushort3: " + e.toString());
   5872         }
   5873         try {
   5874             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE);
   5875             scriptRelaxed.forEach_testConvertUshort3Int3Ushort3(inV, out);
   5876             verifyResultsConvertInt3Ushort3(inV, out, true);
   5877         } catch (Exception e) {
   5878             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort3Int3Ushort3: " + e.toString());
   5879         }
   5880     }
   5881 
   5882     private void verifyResultsConvertInt3Ushort3(Allocation inV, Allocation out, boolean relaxed) {
   5883         int[] arrayInV = new int[INPUTSIZE * 4];
   5884         inV.copyTo(arrayInV);
   5885         short[] arrayOut = new short[INPUTSIZE * 4];
   5886         out.copyTo(arrayOut);
   5887         for (int i = 0; i < INPUTSIZE; i++) {
   5888             for (int j = 0; j < 3 ; j++) {
   5889                 // Extract the inputs.
   5890                 ArgumentsIntUshort args = new ArgumentsIntUshort();
   5891                 args.inV = arrayInV[i * 4 + j];
   5892                 // Figure out what the outputs should have been.
   5893                 CoreMathVerifier.computeConvert(args);
   5894                 // Validate the outputs.
   5895                 boolean valid = true;
   5896                 if (args.out != arrayOut[i * 4 + j]) {
   5897                     valid = false;
   5898                 }
   5899                 if (!valid) {
   5900                     StringBuilder message = new StringBuilder();
   5901                     message.append("Input inV: ");
   5902                     message.append(String.format("%d", args.inV));
   5903                     message.append("\n");
   5904                     message.append("Expected output out: ");
   5905                     message.append(String.format("0x%x", args.out));
   5906                     message.append("\n");
   5907                     message.append("Actual   output out: ");
   5908                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   5909                     if (args.out != arrayOut[i * 4 + j]) {
   5910                         message.append(" FAIL");
   5911                     }
   5912                     message.append("\n");
   5913                     assertTrue("Incorrect output for checkConvertInt3Ushort3" +
   5914                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   5915                 }
   5916             }
   5917         }
   5918     }
   5919 
   5920     private void checkConvertInt4Ushort4() {
   5921         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_32, 4, 0x1c9c34f2c0eeaa9cl, false, 16);
   5922         try {
   5923             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE);
   5924             script.forEach_testConvertUshort4Int4Ushort4(inV, out);
   5925             verifyResultsConvertInt4Ushort4(inV, out, false);
   5926         } catch (Exception e) {
   5927             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort4Int4Ushort4: " + e.toString());
   5928         }
   5929         try {
   5930             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE);
   5931             scriptRelaxed.forEach_testConvertUshort4Int4Ushort4(inV, out);
   5932             verifyResultsConvertInt4Ushort4(inV, out, true);
   5933         } catch (Exception e) {
   5934             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort4Int4Ushort4: " + e.toString());
   5935         }
   5936     }
   5937 
   5938     private void verifyResultsConvertInt4Ushort4(Allocation inV, Allocation out, boolean relaxed) {
   5939         int[] arrayInV = new int[INPUTSIZE * 4];
   5940         inV.copyTo(arrayInV);
   5941         short[] arrayOut = new short[INPUTSIZE * 4];
   5942         out.copyTo(arrayOut);
   5943         for (int i = 0; i < INPUTSIZE; i++) {
   5944             for (int j = 0; j < 4 ; j++) {
   5945                 // Extract the inputs.
   5946                 ArgumentsIntUshort args = new ArgumentsIntUshort();
   5947                 args.inV = arrayInV[i * 4 + j];
   5948                 // Figure out what the outputs should have been.
   5949                 CoreMathVerifier.computeConvert(args);
   5950                 // Validate the outputs.
   5951                 boolean valid = true;
   5952                 if (args.out != arrayOut[i * 4 + j]) {
   5953                     valid = false;
   5954                 }
   5955                 if (!valid) {
   5956                     StringBuilder message = new StringBuilder();
   5957                     message.append("Input inV: ");
   5958                     message.append(String.format("%d", args.inV));
   5959                     message.append("\n");
   5960                     message.append("Expected output out: ");
   5961                     message.append(String.format("0x%x", args.out));
   5962                     message.append("\n");
   5963                     message.append("Actual   output out: ");
   5964                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   5965                     if (args.out != arrayOut[i * 4 + j]) {
   5966                         message.append(" FAIL");
   5967                     }
   5968                     message.append("\n");
   5969                     assertTrue("Incorrect output for checkConvertInt4Ushort4" +
   5970                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   5971                 }
   5972             }
   5973         }
   5974     }
   5975 
   5976     public class ArgumentsUintUshort {
   5977         public int inV;
   5978         public short out;
   5979     }
   5980 
   5981     private void checkConvertUint2Ushort2() {
   5982         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_32, 2, 0x40d0c5ebb00fa1efl, false, 16);
   5983         try {
   5984             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE);
   5985             script.forEach_testConvertUshort2Uint2Ushort2(inV, out);
   5986             verifyResultsConvertUint2Ushort2(inV, out, false);
   5987         } catch (Exception e) {
   5988             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort2Uint2Ushort2: " + e.toString());
   5989         }
   5990         try {
   5991             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE);
   5992             scriptRelaxed.forEach_testConvertUshort2Uint2Ushort2(inV, out);
   5993             verifyResultsConvertUint2Ushort2(inV, out, true);
   5994         } catch (Exception e) {
   5995             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort2Uint2Ushort2: " + e.toString());
   5996         }
   5997     }
   5998 
   5999     private void verifyResultsConvertUint2Ushort2(Allocation inV, Allocation out, boolean relaxed) {
   6000         int[] arrayInV = new int[INPUTSIZE * 2];
   6001         inV.copyTo(arrayInV);
   6002         short[] arrayOut = new short[INPUTSIZE * 2];
   6003         out.copyTo(arrayOut);
   6004         for (int i = 0; i < INPUTSIZE; i++) {
   6005             for (int j = 0; j < 2 ; j++) {
   6006                 // Extract the inputs.
   6007                 ArgumentsUintUshort args = new ArgumentsUintUshort();
   6008                 args.inV = arrayInV[i * 2 + j];
   6009                 // Figure out what the outputs should have been.
   6010                 CoreMathVerifier.computeConvert(args);
   6011                 // Validate the outputs.
   6012                 boolean valid = true;
   6013                 if (args.out != arrayOut[i * 2 + j]) {
   6014                     valid = false;
   6015                 }
   6016                 if (!valid) {
   6017                     StringBuilder message = new StringBuilder();
   6018                     message.append("Input inV: ");
   6019                     message.append(String.format("0x%x", args.inV));
   6020                     message.append("\n");
   6021                     message.append("Expected output out: ");
   6022                     message.append(String.format("0x%x", args.out));
   6023                     message.append("\n");
   6024                     message.append("Actual   output out: ");
   6025                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   6026                     if (args.out != arrayOut[i * 2 + j]) {
   6027                         message.append(" FAIL");
   6028                     }
   6029                     message.append("\n");
   6030                     assertTrue("Incorrect output for checkConvertUint2Ushort2" +
   6031                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   6032                 }
   6033             }
   6034         }
   6035     }
   6036 
   6037     private void checkConvertUint3Ushort3() {
   6038         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_32, 3, 0x411d8d73066b331bl, false, 16);
   6039         try {
   6040             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE);
   6041             script.forEach_testConvertUshort3Uint3Ushort3(inV, out);
   6042             verifyResultsConvertUint3Ushort3(inV, out, false);
   6043         } catch (Exception e) {
   6044             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort3Uint3Ushort3: " + e.toString());
   6045         }
   6046         try {
   6047             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE);
   6048             scriptRelaxed.forEach_testConvertUshort3Uint3Ushort3(inV, out);
   6049             verifyResultsConvertUint3Ushort3(inV, out, true);
   6050         } catch (Exception e) {
   6051             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort3Uint3Ushort3: " + e.toString());
   6052         }
   6053     }
   6054 
   6055     private void verifyResultsConvertUint3Ushort3(Allocation inV, Allocation out, boolean relaxed) {
   6056         int[] arrayInV = new int[INPUTSIZE * 4];
   6057         inV.copyTo(arrayInV);
   6058         short[] arrayOut = new short[INPUTSIZE * 4];
   6059         out.copyTo(arrayOut);
   6060         for (int i = 0; i < INPUTSIZE; i++) {
   6061             for (int j = 0; j < 3 ; j++) {
   6062                 // Extract the inputs.
   6063                 ArgumentsUintUshort args = new ArgumentsUintUshort();
   6064                 args.inV = arrayInV[i * 4 + j];
   6065                 // Figure out what the outputs should have been.
   6066                 CoreMathVerifier.computeConvert(args);
   6067                 // Validate the outputs.
   6068                 boolean valid = true;
   6069                 if (args.out != arrayOut[i * 4 + j]) {
   6070                     valid = false;
   6071                 }
   6072                 if (!valid) {
   6073                     StringBuilder message = new StringBuilder();
   6074                     message.append("Input inV: ");
   6075                     message.append(String.format("0x%x", args.inV));
   6076                     message.append("\n");
   6077                     message.append("Expected output out: ");
   6078                     message.append(String.format("0x%x", args.out));
   6079                     message.append("\n");
   6080                     message.append("Actual   output out: ");
   6081                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   6082                     if (args.out != arrayOut[i * 4 + j]) {
   6083                         message.append(" FAIL");
   6084                     }
   6085                     message.append("\n");
   6086                     assertTrue("Incorrect output for checkConvertUint3Ushort3" +
   6087                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   6088                 }
   6089             }
   6090         }
   6091     }
   6092 
   6093     private void checkConvertUint4Ushort4() {
   6094         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_32, 4, 0x416a54fa5cc6c447l, false, 16);
   6095         try {
   6096             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE);
   6097             script.forEach_testConvertUshort4Uint4Ushort4(inV, out);
   6098             verifyResultsConvertUint4Ushort4(inV, out, false);
   6099         } catch (Exception e) {
   6100             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort4Uint4Ushort4: " + e.toString());
   6101         }
   6102         try {
   6103             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE);
   6104             scriptRelaxed.forEach_testConvertUshort4Uint4Ushort4(inV, out);
   6105             verifyResultsConvertUint4Ushort4(inV, out, true);
   6106         } catch (Exception e) {
   6107             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort4Uint4Ushort4: " + e.toString());
   6108         }
   6109     }
   6110 
   6111     private void verifyResultsConvertUint4Ushort4(Allocation inV, Allocation out, boolean relaxed) {
   6112         int[] arrayInV = new int[INPUTSIZE * 4];
   6113         inV.copyTo(arrayInV);
   6114         short[] arrayOut = new short[INPUTSIZE * 4];
   6115         out.copyTo(arrayOut);
   6116         for (int i = 0; i < INPUTSIZE; i++) {
   6117             for (int j = 0; j < 4 ; j++) {
   6118                 // Extract the inputs.
   6119                 ArgumentsUintUshort args = new ArgumentsUintUshort();
   6120                 args.inV = arrayInV[i * 4 + j];
   6121                 // Figure out what the outputs should have been.
   6122                 CoreMathVerifier.computeConvert(args);
   6123                 // Validate the outputs.
   6124                 boolean valid = true;
   6125                 if (args.out != arrayOut[i * 4 + j]) {
   6126                     valid = false;
   6127                 }
   6128                 if (!valid) {
   6129                     StringBuilder message = new StringBuilder();
   6130                     message.append("Input inV: ");
   6131                     message.append(String.format("0x%x", args.inV));
   6132                     message.append("\n");
   6133                     message.append("Expected output out: ");
   6134                     message.append(String.format("0x%x", args.out));
   6135                     message.append("\n");
   6136                     message.append("Actual   output out: ");
   6137                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   6138                     if (args.out != arrayOut[i * 4 + j]) {
   6139                         message.append(" FAIL");
   6140                     }
   6141                     message.append("\n");
   6142                     assertTrue("Incorrect output for checkConvertUint4Ushort4" +
   6143                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   6144                 }
   6145             }
   6146         }
   6147     }
   6148 
   6149     public class ArgumentsFloatInt {
   6150         public float inV;
   6151         public int out;
   6152     }
   6153 
   6154     private void checkConvertFloat2Int2() {
   6155         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x8fb63fb7c069dd5dl, -2.1474835210000000000e+09, 2.1474835200000000000e+09);
   6156         try {
   6157             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE);
   6158             script.forEach_testConvertInt2Float2Int2(inV, out);
   6159             verifyResultsConvertFloat2Int2(inV, out, false);
   6160         } catch (Exception e) {
   6161             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt2Float2Int2: " + e.toString());
   6162         }
   6163         try {
   6164             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE);
   6165             scriptRelaxed.forEach_testConvertInt2Float2Int2(inV, out);
   6166             verifyResultsConvertFloat2Int2(inV, out, true);
   6167         } catch (Exception e) {
   6168             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt2Float2Int2: " + e.toString());
   6169         }
   6170     }
   6171 
   6172     private void verifyResultsConvertFloat2Int2(Allocation inV, Allocation out, boolean relaxed) {
   6173         float[] arrayInV = new float[INPUTSIZE * 2];
   6174         inV.copyTo(arrayInV);
   6175         int[] arrayOut = new int[INPUTSIZE * 2];
   6176         out.copyTo(arrayOut);
   6177         for (int i = 0; i < INPUTSIZE; i++) {
   6178             for (int j = 0; j < 2 ; j++) {
   6179                 // Extract the inputs.
   6180                 ArgumentsFloatInt args = new ArgumentsFloatInt();
   6181                 args.inV = arrayInV[i * 2 + j];
   6182                 // Figure out what the outputs should have been.
   6183                 CoreMathVerifier.computeConvert(args);
   6184                 // Validate the outputs.
   6185                 boolean valid = true;
   6186                 if (args.out != arrayOut[i * 2 + j]) {
   6187                     valid = false;
   6188                 }
   6189                 if (!valid) {
   6190                     StringBuilder message = new StringBuilder();
   6191                     message.append("Input inV: ");
   6192                     message.append(String.format("%14.8g {%8x} %15a",
   6193                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
   6194                     message.append("\n");
   6195                     message.append("Expected output out: ");
   6196                     message.append(String.format("%d", args.out));
   6197                     message.append("\n");
   6198                     message.append("Actual   output out: ");
   6199                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   6200                     if (args.out != arrayOut[i * 2 + j]) {
   6201                         message.append(" FAIL");
   6202                     }
   6203                     message.append("\n");
   6204                     assertTrue("Incorrect output for checkConvertFloat2Int2" +
   6205                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   6206                 }
   6207             }
   6208         }
   6209     }
   6210 
   6211     private void checkConvertFloat3Int3() {
   6212         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x8fb63ff70a11ed93l, -2.1474835210000000000e+09, 2.1474835200000000000e+09);
   6213         try {
   6214             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE);
   6215             script.forEach_testConvertInt3Float3Int3(inV, out);
   6216             verifyResultsConvertFloat3Int3(inV, out, false);
   6217         } catch (Exception e) {
   6218             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt3Float3Int3: " + e.toString());
   6219         }
   6220         try {
   6221             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE);
   6222             scriptRelaxed.forEach_testConvertInt3Float3Int3(inV, out);
   6223             verifyResultsConvertFloat3Int3(inV, out, true);
   6224         } catch (Exception e) {
   6225             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt3Float3Int3: " + e.toString());
   6226         }
   6227     }
   6228 
   6229     private void verifyResultsConvertFloat3Int3(Allocation inV, Allocation out, boolean relaxed) {
   6230         float[] arrayInV = new float[INPUTSIZE * 4];
   6231         inV.copyTo(arrayInV);
   6232         int[] arrayOut = new int[INPUTSIZE * 4];
   6233         out.copyTo(arrayOut);
   6234         for (int i = 0; i < INPUTSIZE; i++) {
   6235             for (int j = 0; j < 3 ; j++) {
   6236                 // Extract the inputs.
   6237                 ArgumentsFloatInt args = new ArgumentsFloatInt();
   6238                 args.inV = arrayInV[i * 4 + j];
   6239                 // Figure out what the outputs should have been.
   6240                 CoreMathVerifier.computeConvert(args);
   6241                 // Validate the outputs.
   6242                 boolean valid = true;
   6243                 if (args.out != arrayOut[i * 4 + j]) {
   6244                     valid = false;
   6245                 }
   6246                 if (!valid) {
   6247                     StringBuilder message = new StringBuilder();
   6248                     message.append("Input inV: ");
   6249                     message.append(String.format("%14.8g {%8x} %15a",
   6250                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
   6251                     message.append("\n");
   6252                     message.append("Expected output out: ");
   6253                     message.append(String.format("%d", args.out));
   6254                     message.append("\n");
   6255                     message.append("Actual   output out: ");
   6256                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   6257                     if (args.out != arrayOut[i * 4 + j]) {
   6258                         message.append(" FAIL");
   6259                     }
   6260                     message.append("\n");
   6261                     assertTrue("Incorrect output for checkConvertFloat3Int3" +
   6262                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   6263                 }
   6264             }
   6265         }
   6266     }
   6267 
   6268     private void checkConvertFloat4Int4() {
   6269         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x8fb6403653b9fdc9l, -2.1474835210000000000e+09, 2.1474835200000000000e+09);
   6270         try {
   6271             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE);
   6272             script.forEach_testConvertInt4Float4Int4(inV, out);
   6273             verifyResultsConvertFloat4Int4(inV, out, false);
   6274         } catch (Exception e) {
   6275             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt4Float4Int4: " + e.toString());
   6276         }
   6277         try {
   6278             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE);
   6279             scriptRelaxed.forEach_testConvertInt4Float4Int4(inV, out);
   6280             verifyResultsConvertFloat4Int4(inV, out, true);
   6281         } catch (Exception e) {
   6282             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt4Float4Int4: " + e.toString());
   6283         }
   6284     }
   6285 
   6286     private void verifyResultsConvertFloat4Int4(Allocation inV, Allocation out, boolean relaxed) {
   6287         float[] arrayInV = new float[INPUTSIZE * 4];
   6288         inV.copyTo(arrayInV);
   6289         int[] arrayOut = new int[INPUTSIZE * 4];
   6290         out.copyTo(arrayOut);
   6291         for (int i = 0; i < INPUTSIZE; i++) {
   6292             for (int j = 0; j < 4 ; j++) {
   6293                 // Extract the inputs.
   6294                 ArgumentsFloatInt args = new ArgumentsFloatInt();
   6295                 args.inV = arrayInV[i * 4 + j];
   6296                 // Figure out what the outputs should have been.
   6297                 CoreMathVerifier.computeConvert(args);
   6298                 // Validate the outputs.
   6299                 boolean valid = true;
   6300                 if (args.out != arrayOut[i * 4 + j]) {
   6301                     valid = false;
   6302                 }
   6303                 if (!valid) {
   6304                     StringBuilder message = new StringBuilder();
   6305                     message.append("Input inV: ");
   6306                     message.append(String.format("%14.8g {%8x} %15a",
   6307                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
   6308                     message.append("\n");
   6309                     message.append("Expected output out: ");
   6310                     message.append(String.format("%d", args.out));
   6311                     message.append("\n");
   6312                     message.append("Actual   output out: ");
   6313                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   6314                     if (args.out != arrayOut[i * 4 + j]) {
   6315                         message.append(" FAIL");
   6316                     }
   6317                     message.append("\n");
   6318                     assertTrue("Incorrect output for checkConvertFloat4Int4" +
   6319                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   6320                 }
   6321             }
   6322         }
   6323     }
   6324 
   6325     public class ArgumentsCharInt {
   6326         public byte inV;
   6327         public int out;
   6328     }
   6329 
   6330     private void checkConvertChar2Int2() {
   6331         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_8, 2, 0x880244ac94c6831dl, true, 7);
   6332         try {
   6333             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE);
   6334             script.forEach_testConvertInt2Char2Int2(inV, out);
   6335             verifyResultsConvertChar2Int2(inV, out, false);
   6336         } catch (Exception e) {
   6337             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt2Char2Int2: " + e.toString());
   6338         }
   6339         try {
   6340             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE);
   6341             scriptRelaxed.forEach_testConvertInt2Char2Int2(inV, out);
   6342             verifyResultsConvertChar2Int2(inV, out, true);
   6343         } catch (Exception e) {
   6344             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt2Char2Int2: " + e.toString());
   6345         }
   6346     }
   6347 
   6348     private void verifyResultsConvertChar2Int2(Allocation inV, Allocation out, boolean relaxed) {
   6349         byte[] arrayInV = new byte[INPUTSIZE * 2];
   6350         inV.copyTo(arrayInV);
   6351         int[] arrayOut = new int[INPUTSIZE * 2];
   6352         out.copyTo(arrayOut);
   6353         for (int i = 0; i < INPUTSIZE; i++) {
   6354             for (int j = 0; j < 2 ; j++) {
   6355                 // Extract the inputs.
   6356                 ArgumentsCharInt args = new ArgumentsCharInt();
   6357                 args.inV = arrayInV[i * 2 + j];
   6358                 // Figure out what the outputs should have been.
   6359                 CoreMathVerifier.computeConvert(args);
   6360                 // Validate the outputs.
   6361                 boolean valid = true;
   6362                 if (args.out != arrayOut[i * 2 + j]) {
   6363                     valid = false;
   6364                 }
   6365                 if (!valid) {
   6366                     StringBuilder message = new StringBuilder();
   6367                     message.append("Input inV: ");
   6368                     message.append(String.format("%d", args.inV));
   6369                     message.append("\n");
   6370                     message.append("Expected output out: ");
   6371                     message.append(String.format("%d", args.out));
   6372                     message.append("\n");
   6373                     message.append("Actual   output out: ");
   6374                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   6375                     if (args.out != arrayOut[i * 2 + j]) {
   6376                         message.append(" FAIL");
   6377                     }
   6378                     message.append("\n");
   6379                     assertTrue("Incorrect output for checkConvertChar2Int2" +
   6380                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   6381                 }
   6382             }
   6383         }
   6384     }
   6385 
   6386     private void checkConvertChar3Int3() {
   6387         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_8, 3, 0x880244ebde6e9353l, true, 7);
   6388         try {
   6389             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE);
   6390             script.forEach_testConvertInt3Char3Int3(inV, out);
   6391             verifyResultsConvertChar3Int3(inV, out, false);
   6392         } catch (Exception e) {
   6393             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt3Char3Int3: " + e.toString());
   6394         }
   6395         try {
   6396             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE);
   6397             scriptRelaxed.forEach_testConvertInt3Char3Int3(inV, out);
   6398             verifyResultsConvertChar3Int3(inV, out, true);
   6399         } catch (Exception e) {
   6400             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt3Char3Int3: " + e.toString());
   6401         }
   6402     }
   6403 
   6404     private void verifyResultsConvertChar3Int3(Allocation inV, Allocation out, boolean relaxed) {
   6405         byte[] arrayInV = new byte[INPUTSIZE * 4];
   6406         inV.copyTo(arrayInV);
   6407         int[] arrayOut = new int[INPUTSIZE * 4];
   6408         out.copyTo(arrayOut);
   6409         for (int i = 0; i < INPUTSIZE; i++) {
   6410             for (int j = 0; j < 3 ; j++) {
   6411                 // Extract the inputs.
   6412                 ArgumentsCharInt args = new ArgumentsCharInt();
   6413                 args.inV = arrayInV[i * 4 + j];
   6414                 // Figure out what the outputs should have been.
   6415                 CoreMathVerifier.computeConvert(args);
   6416                 // Validate the outputs.
   6417                 boolean valid = true;
   6418                 if (args.out != arrayOut[i * 4 + j]) {
   6419                     valid = false;
   6420                 }
   6421                 if (!valid) {
   6422                     StringBuilder message = new StringBuilder();
   6423                     message.append("Input inV: ");
   6424                     message.append(String.format("%d", args.inV));
   6425                     message.append("\n");
   6426                     message.append("Expected output out: ");
   6427                     message.append(String.format("%d", args.out));
   6428                     message.append("\n");
   6429                     message.append("Actual   output out: ");
   6430                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   6431                     if (args.out != arrayOut[i * 4 + j]) {
   6432                         message.append(" FAIL");
   6433                     }
   6434                     message.append("\n");
   6435                     assertTrue("Incorrect output for checkConvertChar3Int3" +
   6436                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   6437                 }
   6438             }
   6439         }
   6440     }
   6441 
   6442     private void checkConvertChar4Int4() {
   6443         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_8, 4, 0x8802452b2816a389l, true, 7);
   6444         try {
   6445             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE);
   6446             script.forEach_testConvertInt4Char4Int4(inV, out);
   6447             verifyResultsConvertChar4Int4(inV, out, false);
   6448         } catch (Exception e) {
   6449             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt4Char4Int4: " + e.toString());
   6450         }
   6451         try {
   6452             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE);
   6453             scriptRelaxed.forEach_testConvertInt4Char4Int4(inV, out);
   6454             verifyResultsConvertChar4Int4(inV, out, true);
   6455         } catch (Exception e) {
   6456             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt4Char4Int4: " + e.toString());
   6457         }
   6458     }
   6459 
   6460     private void verifyResultsConvertChar4Int4(Allocation inV, Allocation out, boolean relaxed) {
   6461         byte[] arrayInV = new byte[INPUTSIZE * 4];
   6462         inV.copyTo(arrayInV);
   6463         int[] arrayOut = new int[INPUTSIZE * 4];
   6464         out.copyTo(arrayOut);
   6465         for (int i = 0; i < INPUTSIZE; i++) {
   6466             for (int j = 0; j < 4 ; j++) {
   6467                 // Extract the inputs.
   6468                 ArgumentsCharInt args = new ArgumentsCharInt();
   6469                 args.inV = arrayInV[i * 4 + j];
   6470                 // Figure out what the outputs should have been.
   6471                 CoreMathVerifier.computeConvert(args);
   6472                 // Validate the outputs.
   6473                 boolean valid = true;
   6474                 if (args.out != arrayOut[i * 4 + j]) {
   6475                     valid = false;
   6476                 }
   6477                 if (!valid) {
   6478                     StringBuilder message = new StringBuilder();
   6479                     message.append("Input inV: ");
   6480                     message.append(String.format("%d", args.inV));
   6481                     message.append("\n");
   6482                     message.append("Expected output out: ");
   6483                     message.append(String.format("%d", args.out));
   6484                     message.append("\n");
   6485                     message.append("Actual   output out: ");
   6486                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   6487                     if (args.out != arrayOut[i * 4 + j]) {
   6488                         message.append(" FAIL");
   6489                     }
   6490                     message.append("\n");
   6491                     assertTrue("Incorrect output for checkConvertChar4Int4" +
   6492                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   6493                 }
   6494             }
   6495         }
   6496     }
   6497 
   6498     public class ArgumentsUcharInt {
   6499         public byte inV;
   6500         public int out;
   6501     }
   6502 
   6503     private void checkConvertUchar2Int2() {
   6504         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_8, 2, 0x97cffb96923aa720l, false, 8);
   6505         try {
   6506             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE);
   6507             script.forEach_testConvertInt2Uchar2Int2(inV, out);
   6508             verifyResultsConvertUchar2Int2(inV, out, false);
   6509         } catch (Exception e) {
   6510             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt2Uchar2Int2: " + e.toString());
   6511         }
   6512         try {
   6513             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE);
   6514             scriptRelaxed.forEach_testConvertInt2Uchar2Int2(inV, out);
   6515             verifyResultsConvertUchar2Int2(inV, out, true);
   6516         } catch (Exception e) {
   6517             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt2Uchar2Int2: " + e.toString());
   6518         }
   6519     }
   6520 
   6521     private void verifyResultsConvertUchar2Int2(Allocation inV, Allocation out, boolean relaxed) {
   6522         byte[] arrayInV = new byte[INPUTSIZE * 2];
   6523         inV.copyTo(arrayInV);
   6524         int[] arrayOut = new int[INPUTSIZE * 2];
   6525         out.copyTo(arrayOut);
   6526         for (int i = 0; i < INPUTSIZE; i++) {
   6527             for (int j = 0; j < 2 ; j++) {
   6528                 // Extract the inputs.
   6529                 ArgumentsUcharInt args = new ArgumentsUcharInt();
   6530                 args.inV = arrayInV[i * 2 + j];
   6531                 // Figure out what the outputs should have been.
   6532                 CoreMathVerifier.computeConvert(args);
   6533                 // Validate the outputs.
   6534                 boolean valid = true;
   6535                 if (args.out != arrayOut[i * 2 + j]) {
   6536                     valid = false;
   6537                 }
   6538                 if (!valid) {
   6539                     StringBuilder message = new StringBuilder();
   6540                     message.append("Input inV: ");
   6541                     message.append(String.format("0x%x", args.inV));
   6542                     message.append("\n");
   6543                     message.append("Expected output out: ");
   6544                     message.append(String.format("%d", args.out));
   6545                     message.append("\n");
   6546                     message.append("Actual   output out: ");
   6547                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   6548                     if (args.out != arrayOut[i * 2 + j]) {
   6549                         message.append(" FAIL");
   6550                     }
   6551                     message.append("\n");
   6552                     assertTrue("Incorrect output for checkConvertUchar2Int2" +
   6553                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   6554                 }
   6555             }
   6556         }
   6557     }
   6558 
   6559     private void checkConvertUchar3Int3() {
   6560         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_8, 3, 0x97cffbd5dbe2b756l, false, 8);
   6561         try {
   6562             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE);
   6563             script.forEach_testConvertInt3Uchar3Int3(inV, out);
   6564             verifyResultsConvertUchar3Int3(inV, out, false);
   6565         } catch (Exception e) {
   6566             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt3Uchar3Int3: " + e.toString());
   6567         }
   6568         try {
   6569             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE);
   6570             scriptRelaxed.forEach_testConvertInt3Uchar3Int3(inV, out);
   6571             verifyResultsConvertUchar3Int3(inV, out, true);
   6572         } catch (Exception e) {
   6573             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt3Uchar3Int3: " + e.toString());
   6574         }
   6575     }
   6576 
   6577     private void verifyResultsConvertUchar3Int3(Allocation inV, Allocation out, boolean relaxed) {
   6578         byte[] arrayInV = new byte[INPUTSIZE * 4];
   6579         inV.copyTo(arrayInV);
   6580         int[] arrayOut = new int[INPUTSIZE * 4];
   6581         out.copyTo(arrayOut);
   6582         for (int i = 0; i < INPUTSIZE; i++) {
   6583             for (int j = 0; j < 3 ; j++) {
   6584                 // Extract the inputs.
   6585                 ArgumentsUcharInt args = new ArgumentsUcharInt();
   6586                 args.inV = arrayInV[i * 4 + j];
   6587                 // Figure out what the outputs should have been.
   6588                 CoreMathVerifier.computeConvert(args);
   6589                 // Validate the outputs.
   6590                 boolean valid = true;
   6591                 if (args.out != arrayOut[i * 4 + j]) {
   6592                     valid = false;
   6593                 }
   6594                 if (!valid) {
   6595                     StringBuilder message = new StringBuilder();
   6596                     message.append("Input inV: ");
   6597                     message.append(String.format("0x%x", args.inV));
   6598                     message.append("\n");
   6599                     message.append("Expected output out: ");
   6600                     message.append(String.format("%d", args.out));
   6601                     message.append("\n");
   6602                     message.append("Actual   output out: ");
   6603                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   6604                     if (args.out != arrayOut[i * 4 + j]) {
   6605                         message.append(" FAIL");
   6606                     }
   6607                     message.append("\n");
   6608                     assertTrue("Incorrect output for checkConvertUchar3Int3" +
   6609                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   6610                 }
   6611             }
   6612         }
   6613     }
   6614 
   6615     private void checkConvertUchar4Int4() {
   6616         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_8, 4, 0x97cffc15258ac78cl, false, 8);
   6617         try {
   6618             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE);
   6619             script.forEach_testConvertInt4Uchar4Int4(inV, out);
   6620             verifyResultsConvertUchar4Int4(inV, out, false);
   6621         } catch (Exception e) {
   6622             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt4Uchar4Int4: " + e.toString());
   6623         }
   6624         try {
   6625             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE);
   6626             scriptRelaxed.forEach_testConvertInt4Uchar4Int4(inV, out);
   6627             verifyResultsConvertUchar4Int4(inV, out, true);
   6628         } catch (Exception e) {
   6629             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt4Uchar4Int4: " + e.toString());
   6630         }
   6631     }
   6632 
   6633     private void verifyResultsConvertUchar4Int4(Allocation inV, Allocation out, boolean relaxed) {
   6634         byte[] arrayInV = new byte[INPUTSIZE * 4];
   6635         inV.copyTo(arrayInV);
   6636         int[] arrayOut = new int[INPUTSIZE * 4];
   6637         out.copyTo(arrayOut);
   6638         for (int i = 0; i < INPUTSIZE; i++) {
   6639             for (int j = 0; j < 4 ; j++) {
   6640                 // Extract the inputs.
   6641                 ArgumentsUcharInt args = new ArgumentsUcharInt();
   6642                 args.inV = arrayInV[i * 4 + j];
   6643                 // Figure out what the outputs should have been.
   6644                 CoreMathVerifier.computeConvert(args);
   6645                 // Validate the outputs.
   6646                 boolean valid = true;
   6647                 if (args.out != arrayOut[i * 4 + j]) {
   6648                     valid = false;
   6649                 }
   6650                 if (!valid) {
   6651                     StringBuilder message = new StringBuilder();
   6652                     message.append("Input inV: ");
   6653                     message.append(String.format("0x%x", args.inV));
   6654                     message.append("\n");
   6655                     message.append("Expected output out: ");
   6656                     message.append(String.format("%d", args.out));
   6657                     message.append("\n");
   6658                     message.append("Actual   output out: ");
   6659                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   6660                     if (args.out != arrayOut[i * 4 + j]) {
   6661                         message.append(" FAIL");
   6662                     }
   6663                     message.append("\n");
   6664                     assertTrue("Incorrect output for checkConvertUchar4Int4" +
   6665                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   6666                 }
   6667             }
   6668         }
   6669     }
   6670 
   6671     public class ArgumentsShortInt {
   6672         public short inV;
   6673         public int out;
   6674     }
   6675 
   6676     private void checkConvertShort2Int2() {
   6677         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_16, 2, 0x85693203252a2d69l, true, 15);
   6678         try {
   6679             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE);
   6680             script.forEach_testConvertInt2Short2Int2(inV, out);
   6681             verifyResultsConvertShort2Int2(inV, out, false);
   6682         } catch (Exception e) {
   6683             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt2Short2Int2: " + e.toString());
   6684         }
   6685         try {
   6686             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE);
   6687             scriptRelaxed.forEach_testConvertInt2Short2Int2(inV, out);
   6688             verifyResultsConvertShort2Int2(inV, out, true);
   6689         } catch (Exception e) {
   6690             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt2Short2Int2: " + e.toString());
   6691         }
   6692     }
   6693 
   6694     private void verifyResultsConvertShort2Int2(Allocation inV, Allocation out, boolean relaxed) {
   6695         short[] arrayInV = new short[INPUTSIZE * 2];
   6696         inV.copyTo(arrayInV);
   6697         int[] arrayOut = new int[INPUTSIZE * 2];
   6698         out.copyTo(arrayOut);
   6699         for (int i = 0; i < INPUTSIZE; i++) {
   6700             for (int j = 0; j < 2 ; j++) {
   6701                 // Extract the inputs.
   6702                 ArgumentsShortInt args = new ArgumentsShortInt();
   6703                 args.inV = arrayInV[i * 2 + j];
   6704                 // Figure out what the outputs should have been.
   6705                 CoreMathVerifier.computeConvert(args);
   6706                 // Validate the outputs.
   6707                 boolean valid = true;
   6708                 if (args.out != arrayOut[i * 2 + j]) {
   6709                     valid = false;
   6710                 }
   6711                 if (!valid) {
   6712                     StringBuilder message = new StringBuilder();
   6713                     message.append("Input inV: ");
   6714                     message.append(String.format("%d", args.inV));
   6715                     message.append("\n");
   6716                     message.append("Expected output out: ");
   6717                     message.append(String.format("%d", args.out));
   6718                     message.append("\n");
   6719                     message.append("Actual   output out: ");
   6720                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   6721                     if (args.out != arrayOut[i * 2 + j]) {
   6722                         message.append(" FAIL");
   6723                     }
   6724                     message.append("\n");
   6725                     assertTrue("Incorrect output for checkConvertShort2Int2" +
   6726                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   6727                 }
   6728             }
   6729         }
   6730     }
   6731 
   6732     private void checkConvertShort3Int3() {
   6733         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_16, 3, 0x856932426ed23d9fl, true, 15);
   6734         try {
   6735             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE);
   6736             script.forEach_testConvertInt3Short3Int3(inV, out);
   6737             verifyResultsConvertShort3Int3(inV, out, false);
   6738         } catch (Exception e) {
   6739             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt3Short3Int3: " + e.toString());
   6740         }
   6741         try {
   6742             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE);
   6743             scriptRelaxed.forEach_testConvertInt3Short3Int3(inV, out);
   6744             verifyResultsConvertShort3Int3(inV, out, true);
   6745         } catch (Exception e) {
   6746             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt3Short3Int3: " + e.toString());
   6747         }
   6748     }
   6749 
   6750     private void verifyResultsConvertShort3Int3(Allocation inV, Allocation out, boolean relaxed) {
   6751         short[] arrayInV = new short[INPUTSIZE * 4];
   6752         inV.copyTo(arrayInV);
   6753         int[] arrayOut = new int[INPUTSIZE * 4];
   6754         out.copyTo(arrayOut);
   6755         for (int i = 0; i < INPUTSIZE; i++) {
   6756             for (int j = 0; j < 3 ; j++) {
   6757                 // Extract the inputs.
   6758                 ArgumentsShortInt args = new ArgumentsShortInt();
   6759                 args.inV = arrayInV[i * 4 + j];
   6760                 // Figure out what the outputs should have been.
   6761                 CoreMathVerifier.computeConvert(args);
   6762                 // Validate the outputs.
   6763                 boolean valid = true;
   6764                 if (args.out != arrayOut[i * 4 + j]) {
   6765                     valid = false;
   6766                 }
   6767                 if (!valid) {
   6768                     StringBuilder message = new StringBuilder();
   6769                     message.append("Input inV: ");
   6770                     message.append(String.format("%d", args.inV));
   6771                     message.append("\n");
   6772                     message.append("Expected output out: ");
   6773                     message.append(String.format("%d", args.out));
   6774                     message.append("\n");
   6775                     message.append("Actual   output out: ");
   6776                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   6777                     if (args.out != arrayOut[i * 4 + j]) {
   6778                         message.append(" FAIL");
   6779                     }
   6780                     message.append("\n");
   6781                     assertTrue("Incorrect output for checkConvertShort3Int3" +
   6782                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   6783                 }
   6784             }
   6785         }
   6786     }
   6787 
   6788     private void checkConvertShort4Int4() {
   6789         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_16, 4, 0x85693281b87a4dd5l, true, 15);
   6790         try {
   6791             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE);
   6792             script.forEach_testConvertInt4Short4Int4(inV, out);
   6793             verifyResultsConvertShort4Int4(inV, out, false);
   6794         } catch (Exception e) {
   6795             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt4Short4Int4: " + e.toString());
   6796         }
   6797         try {
   6798             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE);
   6799             scriptRelaxed.forEach_testConvertInt4Short4Int4(inV, out);
   6800             verifyResultsConvertShort4Int4(inV, out, true);
   6801         } catch (Exception e) {
   6802             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt4Short4Int4: " + e.toString());
   6803         }
   6804     }
   6805 
   6806     private void verifyResultsConvertShort4Int4(Allocation inV, Allocation out, boolean relaxed) {
   6807         short[] arrayInV = new short[INPUTSIZE * 4];
   6808         inV.copyTo(arrayInV);
   6809         int[] arrayOut = new int[INPUTSIZE * 4];
   6810         out.copyTo(arrayOut);
   6811         for (int i = 0; i < INPUTSIZE; i++) {
   6812             for (int j = 0; j < 4 ; j++) {
   6813                 // Extract the inputs.
   6814                 ArgumentsShortInt args = new ArgumentsShortInt();
   6815                 args.inV = arrayInV[i * 4 + j];
   6816                 // Figure out what the outputs should have been.
   6817                 CoreMathVerifier.computeConvert(args);
   6818                 // Validate the outputs.
   6819                 boolean valid = true;
   6820                 if (args.out != arrayOut[i * 4 + j]) {
   6821                     valid = false;
   6822                 }
   6823                 if (!valid) {
   6824                     StringBuilder message = new StringBuilder();
   6825                     message.append("Input inV: ");
   6826                     message.append(String.format("%d", args.inV));
   6827                     message.append("\n");
   6828                     message.append("Expected output out: ");
   6829                     message.append(String.format("%d", args.out));
   6830                     message.append("\n");
   6831                     message.append("Actual   output out: ");
   6832                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   6833                     if (args.out != arrayOut[i * 4 + j]) {
   6834                         message.append(" FAIL");
   6835                     }
   6836                     message.append("\n");
   6837                     assertTrue("Incorrect output for checkConvertShort4Int4" +
   6838                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   6839                 }
   6840             }
   6841         }
   6842     }
   6843 
   6844     public class ArgumentsUshortInt {
   6845         public short inV;
   6846         public int out;
   6847     }
   6848 
   6849     private void checkConvertUshort2Int2() {
   6850         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_16, 2, 0x2cf6eb50b7ac39eal, false, 16);
   6851         try {
   6852             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE);
   6853             script.forEach_testConvertInt2Ushort2Int2(inV, out);
   6854             verifyResultsConvertUshort2Int2(inV, out, false);
   6855         } catch (Exception e) {
   6856             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt2Ushort2Int2: " + e.toString());
   6857         }
   6858         try {
   6859             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE);
   6860             scriptRelaxed.forEach_testConvertInt2Ushort2Int2(inV, out);
   6861             verifyResultsConvertUshort2Int2(inV, out, true);
   6862         } catch (Exception e) {
   6863             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt2Ushort2Int2: " + e.toString());
   6864         }
   6865     }
   6866 
   6867     private void verifyResultsConvertUshort2Int2(Allocation inV, Allocation out, boolean relaxed) {
   6868         short[] arrayInV = new short[INPUTSIZE * 2];
   6869         inV.copyTo(arrayInV);
   6870         int[] arrayOut = new int[INPUTSIZE * 2];
   6871         out.copyTo(arrayOut);
   6872         for (int i = 0; i < INPUTSIZE; i++) {
   6873             for (int j = 0; j < 2 ; j++) {
   6874                 // Extract the inputs.
   6875                 ArgumentsUshortInt args = new ArgumentsUshortInt();
   6876                 args.inV = arrayInV[i * 2 + j];
   6877                 // Figure out what the outputs should have been.
   6878                 CoreMathVerifier.computeConvert(args);
   6879                 // Validate the outputs.
   6880                 boolean valid = true;
   6881                 if (args.out != arrayOut[i * 2 + j]) {
   6882                     valid = false;
   6883                 }
   6884                 if (!valid) {
   6885                     StringBuilder message = new StringBuilder();
   6886                     message.append("Input inV: ");
   6887                     message.append(String.format("0x%x", args.inV));
   6888                     message.append("\n");
   6889                     message.append("Expected output out: ");
   6890                     message.append(String.format("%d", args.out));
   6891                     message.append("\n");
   6892                     message.append("Actual   output out: ");
   6893                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   6894                     if (args.out != arrayOut[i * 2 + j]) {
   6895                         message.append(" FAIL");
   6896                     }
   6897                     message.append("\n");
   6898                     assertTrue("Incorrect output for checkConvertUshort2Int2" +
   6899                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   6900                 }
   6901             }
   6902         }
   6903     }
   6904 
   6905     private void checkConvertUshort3Int3() {
   6906         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_16, 3, 0x2cf6eb9001544a20l, false, 16);
   6907         try {
   6908             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE);
   6909             script.forEach_testConvertInt3Ushort3Int3(inV, out);
   6910             verifyResultsConvertUshort3Int3(inV, out, false);
   6911         } catch (Exception e) {
   6912             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt3Ushort3Int3: " + e.toString());
   6913         }
   6914         try {
   6915             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE);
   6916             scriptRelaxed.forEach_testConvertInt3Ushort3Int3(inV, out);
   6917             verifyResultsConvertUshort3Int3(inV, out, true);
   6918         } catch (Exception e) {
   6919             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt3Ushort3Int3: " + e.toString());
   6920         }
   6921     }
   6922 
   6923     private void verifyResultsConvertUshort3Int3(Allocation inV, Allocation out, boolean relaxed) {
   6924         short[] arrayInV = new short[INPUTSIZE * 4];
   6925         inV.copyTo(arrayInV);
   6926         int[] arrayOut = new int[INPUTSIZE * 4];
   6927         out.copyTo(arrayOut);
   6928         for (int i = 0; i < INPUTSIZE; i++) {
   6929             for (int j = 0; j < 3 ; j++) {
   6930                 // Extract the inputs.
   6931                 ArgumentsUshortInt args = new ArgumentsUshortInt();
   6932                 args.inV = arrayInV[i * 4 + j];
   6933                 // Figure out what the outputs should have been.
   6934                 CoreMathVerifier.computeConvert(args);
   6935                 // Validate the outputs.
   6936                 boolean valid = true;
   6937                 if (args.out != arrayOut[i * 4 + j]) {
   6938                     valid = false;
   6939                 }
   6940                 if (!valid) {
   6941                     StringBuilder message = new StringBuilder();
   6942                     message.append("Input inV: ");
   6943                     message.append(String.format("0x%x", args.inV));
   6944                     message.append("\n");
   6945                     message.append("Expected output out: ");
   6946                     message.append(String.format("%d", args.out));
   6947                     message.append("\n");
   6948                     message.append("Actual   output out: ");
   6949                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   6950                     if (args.out != arrayOut[i * 4 + j]) {
   6951                         message.append(" FAIL");
   6952                     }
   6953                     message.append("\n");
   6954                     assertTrue("Incorrect output for checkConvertUshort3Int3" +
   6955                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   6956                 }
   6957             }
   6958         }
   6959     }
   6960 
   6961     private void checkConvertUshort4Int4() {
   6962         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_16, 4, 0x2cf6ebcf4afc5a56l, false, 16);
   6963         try {
   6964             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE);
   6965             script.forEach_testConvertInt4Ushort4Int4(inV, out);
   6966             verifyResultsConvertUshort4Int4(inV, out, false);
   6967         } catch (Exception e) {
   6968             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt4Ushort4Int4: " + e.toString());
   6969         }
   6970         try {
   6971             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE);
   6972             scriptRelaxed.forEach_testConvertInt4Ushort4Int4(inV, out);
   6973             verifyResultsConvertUshort4Int4(inV, out, true);
   6974         } catch (Exception e) {
   6975             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt4Ushort4Int4: " + e.toString());
   6976         }
   6977     }
   6978 
   6979     private void verifyResultsConvertUshort4Int4(Allocation inV, Allocation out, boolean relaxed) {
   6980         short[] arrayInV = new short[INPUTSIZE * 4];
   6981         inV.copyTo(arrayInV);
   6982         int[] arrayOut = new int[INPUTSIZE * 4];
   6983         out.copyTo(arrayOut);
   6984         for (int i = 0; i < INPUTSIZE; i++) {
   6985             for (int j = 0; j < 4 ; j++) {
   6986                 // Extract the inputs.
   6987                 ArgumentsUshortInt args = new ArgumentsUshortInt();
   6988                 args.inV = arrayInV[i * 4 + j];
   6989                 // Figure out what the outputs should have been.
   6990                 CoreMathVerifier.computeConvert(args);
   6991                 // Validate the outputs.
   6992                 boolean valid = true;
   6993                 if (args.out != arrayOut[i * 4 + j]) {
   6994                     valid = false;
   6995                 }
   6996                 if (!valid) {
   6997                     StringBuilder message = new StringBuilder();
   6998                     message.append("Input inV: ");
   6999                     message.append(String.format("0x%x", args.inV));
   7000                     message.append("\n");
   7001                     message.append("Expected output out: ");
   7002                     message.append(String.format("%d", args.out));
   7003                     message.append("\n");
   7004                     message.append("Actual   output out: ");
   7005                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   7006                     if (args.out != arrayOut[i * 4 + j]) {
   7007                         message.append(" FAIL");
   7008                     }
   7009                     message.append("\n");
   7010                     assertTrue("Incorrect output for checkConvertUshort4Int4" +
   7011                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   7012                 }
   7013             }
   7014         }
   7015     }
   7016 
   7017     public class ArgumentsIntInt {
   7018         public int inV;
   7019         public int out;
   7020     }
   7021 
   7022     private void checkConvertInt2Int2() {
   7023         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_32, 2, 0x501d84049a42354l, true, 31);
   7024         try {
   7025             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE);
   7026             script.forEach_testConvertInt2Int2Int2(inV, out);
   7027             verifyResultsConvertInt2Int2(inV, out, false);
   7028         } catch (Exception e) {
   7029             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt2Int2Int2: " + e.toString());
   7030         }
   7031         try {
   7032             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE);
   7033             scriptRelaxed.forEach_testConvertInt2Int2Int2(inV, out);
   7034             verifyResultsConvertInt2Int2(inV, out, true);
   7035         } catch (Exception e) {
   7036             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt2Int2Int2: " + e.toString());
   7037         }
   7038     }
   7039 
   7040     private void verifyResultsConvertInt2Int2(Allocation inV, Allocation out, boolean relaxed) {
   7041         int[] arrayInV = new int[INPUTSIZE * 2];
   7042         inV.copyTo(arrayInV);
   7043         int[] arrayOut = new int[INPUTSIZE * 2];
   7044         out.copyTo(arrayOut);
   7045         for (int i = 0; i < INPUTSIZE; i++) {
   7046             for (int j = 0; j < 2 ; j++) {
   7047                 // Extract the inputs.
   7048                 ArgumentsIntInt args = new ArgumentsIntInt();
   7049                 args.inV = arrayInV[i * 2 + j];
   7050                 // Figure out what the outputs should have been.
   7051                 CoreMathVerifier.computeConvert(args);
   7052                 // Validate the outputs.
   7053                 boolean valid = true;
   7054                 if (args.out != arrayOut[i * 2 + j]) {
   7055                     valid = false;
   7056                 }
   7057                 if (!valid) {
   7058                     StringBuilder message = new StringBuilder();
   7059                     message.append("Input inV: ");
   7060                     message.append(String.format("%d", args.inV));
   7061                     message.append("\n");
   7062                     message.append("Expected output out: ");
   7063                     message.append(String.format("%d", args.out));
   7064                     message.append("\n");
   7065                     message.append("Actual   output out: ");
   7066                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   7067                     if (args.out != arrayOut[i * 2 + j]) {
   7068                         message.append(" FAIL");
   7069                     }
   7070                     message.append("\n");
   7071                     assertTrue("Incorrect output for checkConvertInt2Int2" +
   7072                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   7073                 }
   7074             }
   7075         }
   7076     }
   7077 
   7078     private void checkConvertInt3Int3() {
   7079         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_32, 3, 0x501d87f934c338al, true, 31);
   7080         try {
   7081             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE);
   7082             script.forEach_testConvertInt3Int3Int3(inV, out);
   7083             verifyResultsConvertInt3Int3(inV, out, false);
   7084         } catch (Exception e) {
   7085             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt3Int3Int3: " + e.toString());
   7086         }
   7087         try {
   7088             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE);
   7089             scriptRelaxed.forEach_testConvertInt3Int3Int3(inV, out);
   7090             verifyResultsConvertInt3Int3(inV, out, true);
   7091         } catch (Exception e) {
   7092             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt3Int3Int3: " + e.toString());
   7093         }
   7094     }
   7095 
   7096     private void verifyResultsConvertInt3Int3(Allocation inV, Allocation out, boolean relaxed) {
   7097         int[] arrayInV = new int[INPUTSIZE * 4];
   7098         inV.copyTo(arrayInV);
   7099         int[] arrayOut = new int[INPUTSIZE * 4];
   7100         out.copyTo(arrayOut);
   7101         for (int i = 0; i < INPUTSIZE; i++) {
   7102             for (int j = 0; j < 3 ; j++) {
   7103                 // Extract the inputs.
   7104                 ArgumentsIntInt args = new ArgumentsIntInt();
   7105                 args.inV = arrayInV[i * 4 + j];
   7106                 // Figure out what the outputs should have been.
   7107                 CoreMathVerifier.computeConvert(args);
   7108                 // Validate the outputs.
   7109                 boolean valid = true;
   7110                 if (args.out != arrayOut[i * 4 + j]) {
   7111                     valid = false;
   7112                 }
   7113                 if (!valid) {
   7114                     StringBuilder message = new StringBuilder();
   7115                     message.append("Input inV: ");
   7116                     message.append(String.format("%d", args.inV));
   7117                     message.append("\n");
   7118                     message.append("Expected output out: ");
   7119                     message.append(String.format("%d", args.out));
   7120                     message.append("\n");
   7121                     message.append("Actual   output out: ");
   7122                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   7123                     if (args.out != arrayOut[i * 4 + j]) {
   7124                         message.append(" FAIL");
   7125                     }
   7126                     message.append("\n");
   7127                     assertTrue("Incorrect output for checkConvertInt3Int3" +
   7128                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   7129                 }
   7130             }
   7131         }
   7132     }
   7133 
   7134     private void checkConvertInt4Int4() {
   7135         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_32, 4, 0x501d8bedcf443c0l, true, 31);
   7136         try {
   7137             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE);
   7138             script.forEach_testConvertInt4Int4Int4(inV, out);
   7139             verifyResultsConvertInt4Int4(inV, out, false);
   7140         } catch (Exception e) {
   7141             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt4Int4Int4: " + e.toString());
   7142         }
   7143         try {
   7144             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE);
   7145             scriptRelaxed.forEach_testConvertInt4Int4Int4(inV, out);
   7146             verifyResultsConvertInt4Int4(inV, out, true);
   7147         } catch (Exception e) {
   7148             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt4Int4Int4: " + e.toString());
   7149         }
   7150     }
   7151 
   7152     private void verifyResultsConvertInt4Int4(Allocation inV, Allocation out, boolean relaxed) {
   7153         int[] arrayInV = new int[INPUTSIZE * 4];
   7154         inV.copyTo(arrayInV);
   7155         int[] arrayOut = new int[INPUTSIZE * 4];
   7156         out.copyTo(arrayOut);
   7157         for (int i = 0; i < INPUTSIZE; i++) {
   7158             for (int j = 0; j < 4 ; j++) {
   7159                 // Extract the inputs.
   7160                 ArgumentsIntInt args = new ArgumentsIntInt();
   7161                 args.inV = arrayInV[i * 4 + j];
   7162                 // Figure out what the outputs should have been.
   7163                 CoreMathVerifier.computeConvert(args);
   7164                 // Validate the outputs.
   7165                 boolean valid = true;
   7166                 if (args.out != arrayOut[i * 4 + j]) {
   7167                     valid = false;
   7168                 }
   7169                 if (!valid) {
   7170                     StringBuilder message = new StringBuilder();
   7171                     message.append("Input inV: ");
   7172                     message.append(String.format("%d", args.inV));
   7173                     message.append("\n");
   7174                     message.append("Expected output out: ");
   7175                     message.append(String.format("%d", args.out));
   7176                     message.append("\n");
   7177                     message.append("Actual   output out: ");
   7178                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   7179                     if (args.out != arrayOut[i * 4 + j]) {
   7180                         message.append(" FAIL");
   7181                     }
   7182                     message.append("\n");
   7183                     assertTrue("Incorrect output for checkConvertInt4Int4" +
   7184                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   7185                 }
   7186             }
   7187         }
   7188     }
   7189 
   7190     public class ArgumentsUintInt {
   7191         public int inV;
   7192         public int out;
   7193     }
   7194 
   7195     private void checkConvertUint2Int2() {
   7196         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_32, 2, 0x70899b043daccaddl, false, 31);
   7197         try {
   7198             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE);
   7199             script.forEach_testConvertInt2Uint2Int2(inV, out);
   7200             verifyResultsConvertUint2Int2(inV, out, false);
   7201         } catch (Exception e) {
   7202             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt2Uint2Int2: " + e.toString());
   7203         }
   7204         try {
   7205             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE);
   7206             scriptRelaxed.forEach_testConvertInt2Uint2Int2(inV, out);
   7207             verifyResultsConvertUint2Int2(inV, out, true);
   7208         } catch (Exception e) {
   7209             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt2Uint2Int2: " + e.toString());
   7210         }
   7211     }
   7212 
   7213     private void verifyResultsConvertUint2Int2(Allocation inV, Allocation out, boolean relaxed) {
   7214         int[] arrayInV = new int[INPUTSIZE * 2];
   7215         inV.copyTo(arrayInV);
   7216         int[] arrayOut = new int[INPUTSIZE * 2];
   7217         out.copyTo(arrayOut);
   7218         for (int i = 0; i < INPUTSIZE; i++) {
   7219             for (int j = 0; j < 2 ; j++) {
   7220                 // Extract the inputs.
   7221                 ArgumentsUintInt args = new ArgumentsUintInt();
   7222                 args.inV = arrayInV[i * 2 + j];
   7223                 // Figure out what the outputs should have been.
   7224                 CoreMathVerifier.computeConvert(args);
   7225                 // Validate the outputs.
   7226                 boolean valid = true;
   7227                 if (args.out != arrayOut[i * 2 + j]) {
   7228                     valid = false;
   7229                 }
   7230                 if (!valid) {
   7231                     StringBuilder message = new StringBuilder();
   7232                     message.append("Input inV: ");
   7233                     message.append(String.format("0x%x", args.inV));
   7234                     message.append("\n");
   7235                     message.append("Expected output out: ");
   7236                     message.append(String.format("%d", args.out));
   7237                     message.append("\n");
   7238                     message.append("Actual   output out: ");
   7239                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   7240                     if (args.out != arrayOut[i * 2 + j]) {
   7241                         message.append(" FAIL");
   7242                     }
   7243                     message.append("\n");
   7244                     assertTrue("Incorrect output for checkConvertUint2Int2" +
   7245                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   7246                 }
   7247             }
   7248         }
   7249     }
   7250 
   7251     private void checkConvertUint3Int3() {
   7252         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_32, 3, 0x70899b438754db13l, false, 31);
   7253         try {
   7254             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE);
   7255             script.forEach_testConvertInt3Uint3Int3(inV, out);
   7256             verifyResultsConvertUint3Int3(inV, out, false);
   7257         } catch (Exception e) {
   7258             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt3Uint3Int3: " + e.toString());
   7259         }
   7260         try {
   7261             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE);
   7262             scriptRelaxed.forEach_testConvertInt3Uint3Int3(inV, out);
   7263             verifyResultsConvertUint3Int3(inV, out, true);
   7264         } catch (Exception e) {
   7265             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt3Uint3Int3: " + e.toString());
   7266         }
   7267     }
   7268 
   7269     private void verifyResultsConvertUint3Int3(Allocation inV, Allocation out, boolean relaxed) {
   7270         int[] arrayInV = new int[INPUTSIZE * 4];
   7271         inV.copyTo(arrayInV);
   7272         int[] arrayOut = new int[INPUTSIZE * 4];
   7273         out.copyTo(arrayOut);
   7274         for (int i = 0; i < INPUTSIZE; i++) {
   7275             for (int j = 0; j < 3 ; j++) {
   7276                 // Extract the inputs.
   7277                 ArgumentsUintInt args = new ArgumentsUintInt();
   7278                 args.inV = arrayInV[i * 4 + j];
   7279                 // Figure out what the outputs should have been.
   7280                 CoreMathVerifier.computeConvert(args);
   7281                 // Validate the outputs.
   7282                 boolean valid = true;
   7283                 if (args.out != arrayOut[i * 4 + j]) {
   7284                     valid = false;
   7285                 }
   7286                 if (!valid) {
   7287                     StringBuilder message = new StringBuilder();
   7288                     message.append("Input inV: ");
   7289                     message.append(String.format("0x%x", args.inV));
   7290                     message.append("\n");
   7291                     message.append("Expected output out: ");
   7292                     message.append(String.format("%d", args.out));
   7293                     message.append("\n");
   7294                     message.append("Actual   output out: ");
   7295                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   7296                     if (args.out != arrayOut[i * 4 + j]) {
   7297                         message.append(" FAIL");
   7298                     }
   7299                     message.append("\n");
   7300                     assertTrue("Incorrect output for checkConvertUint3Int3" +
   7301                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   7302                 }
   7303             }
   7304         }
   7305     }
   7306 
   7307     private void checkConvertUint4Int4() {
   7308         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_32, 4, 0x70899b82d0fceb49l, false, 31);
   7309         try {
   7310             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE);
   7311             script.forEach_testConvertInt4Uint4Int4(inV, out);
   7312             verifyResultsConvertUint4Int4(inV, out, false);
   7313         } catch (Exception e) {
   7314             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt4Uint4Int4: " + e.toString());
   7315         }
   7316         try {
   7317             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE);
   7318             scriptRelaxed.forEach_testConvertInt4Uint4Int4(inV, out);
   7319             verifyResultsConvertUint4Int4(inV, out, true);
   7320         } catch (Exception e) {
   7321             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt4Uint4Int4: " + e.toString());
   7322         }
   7323     }
   7324 
   7325     private void verifyResultsConvertUint4Int4(Allocation inV, Allocation out, boolean relaxed) {
   7326         int[] arrayInV = new int[INPUTSIZE * 4];
   7327         inV.copyTo(arrayInV);
   7328         int[] arrayOut = new int[INPUTSIZE * 4];
   7329         out.copyTo(arrayOut);
   7330         for (int i = 0; i < INPUTSIZE; i++) {
   7331             for (int j = 0; j < 4 ; j++) {
   7332                 // Extract the inputs.
   7333                 ArgumentsUintInt args = new ArgumentsUintInt();
   7334                 args.inV = arrayInV[i * 4 + j];
   7335                 // Figure out what the outputs should have been.
   7336                 CoreMathVerifier.computeConvert(args);
   7337                 // Validate the outputs.
   7338                 boolean valid = true;
   7339                 if (args.out != arrayOut[i * 4 + j]) {
   7340                     valid = false;
   7341                 }
   7342                 if (!valid) {
   7343                     StringBuilder message = new StringBuilder();
   7344                     message.append("Input inV: ");
   7345                     message.append(String.format("0x%x", args.inV));
   7346                     message.append("\n");
   7347                     message.append("Expected output out: ");
   7348                     message.append(String.format("%d", args.out));
   7349                     message.append("\n");
   7350                     message.append("Actual   output out: ");
   7351                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   7352                     if (args.out != arrayOut[i * 4 + j]) {
   7353                         message.append(" FAIL");
   7354                     }
   7355                     message.append("\n");
   7356                     assertTrue("Incorrect output for checkConvertUint4Int4" +
   7357                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   7358                 }
   7359             }
   7360         }
   7361     }
   7362 
   7363     public class ArgumentsFloatUint {
   7364         public float inV;
   7365         public int out;
   7366     }
   7367 
   7368     private void checkConvertFloat2Uint2() {
   7369         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x239cb6cd424dca22l, 0.0000000000000000000e+00, 4.2949670400000000000e+09);
   7370         try {
   7371             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE);
   7372             script.forEach_testConvertUint2Float2Uint2(inV, out);
   7373             verifyResultsConvertFloat2Uint2(inV, out, false);
   7374         } catch (Exception e) {
   7375             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint2Float2Uint2: " + e.toString());
   7376         }
   7377         try {
   7378             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE);
   7379             scriptRelaxed.forEach_testConvertUint2Float2Uint2(inV, out);
   7380             verifyResultsConvertFloat2Uint2(inV, out, true);
   7381         } catch (Exception e) {
   7382             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint2Float2Uint2: " + e.toString());
   7383         }
   7384     }
   7385 
   7386     private void verifyResultsConvertFloat2Uint2(Allocation inV, Allocation out, boolean relaxed) {
   7387         float[] arrayInV = new float[INPUTSIZE * 2];
   7388         inV.copyTo(arrayInV);
   7389         int[] arrayOut = new int[INPUTSIZE * 2];
   7390         out.copyTo(arrayOut);
   7391         for (int i = 0; i < INPUTSIZE; i++) {
   7392             for (int j = 0; j < 2 ; j++) {
   7393                 // Extract the inputs.
   7394                 ArgumentsFloatUint args = new ArgumentsFloatUint();
   7395                 args.inV = arrayInV[i * 2 + j];
   7396                 // Figure out what the outputs should have been.
   7397                 CoreMathVerifier.computeConvert(args);
   7398                 // Validate the outputs.
   7399                 boolean valid = true;
   7400                 if (args.out != arrayOut[i * 2 + j]) {
   7401                     valid = false;
   7402                 }
   7403                 if (!valid) {
   7404                     StringBuilder message = new StringBuilder();
   7405                     message.append("Input inV: ");
   7406                     message.append(String.format("%14.8g {%8x} %15a",
   7407                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
   7408                     message.append("\n");
   7409                     message.append("Expected output out: ");
   7410                     message.append(String.format("0x%x", args.out));
   7411                     message.append("\n");
   7412                     message.append("Actual   output out: ");
   7413                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   7414                     if (args.out != arrayOut[i * 2 + j]) {
   7415                         message.append(" FAIL");
   7416                     }
   7417                     message.append("\n");
   7418                     assertTrue("Incorrect output for checkConvertFloat2Uint2" +
   7419                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   7420                 }
   7421             }
   7422         }
   7423     }
   7424 
   7425     private void checkConvertFloat3Uint3() {
   7426         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x239cc16ea1558f16l, 0.0000000000000000000e+00, 4.2949670400000000000e+09);
   7427         try {
   7428             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE);
   7429             script.forEach_testConvertUint3Float3Uint3(inV, out);
   7430             verifyResultsConvertFloat3Uint3(inV, out, false);
   7431         } catch (Exception e) {
   7432             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint3Float3Uint3: " + e.toString());
   7433         }
   7434         try {
   7435             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE);
   7436             scriptRelaxed.forEach_testConvertUint3Float3Uint3(inV, out);
   7437             verifyResultsConvertFloat3Uint3(inV, out, true);
   7438         } catch (Exception e) {
   7439             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint3Float3Uint3: " + e.toString());
   7440         }
   7441     }
   7442 
   7443     private void verifyResultsConvertFloat3Uint3(Allocation inV, Allocation out, boolean relaxed) {
   7444         float[] arrayInV = new float[INPUTSIZE * 4];
   7445         inV.copyTo(arrayInV);
   7446         int[] arrayOut = new int[INPUTSIZE * 4];
   7447         out.copyTo(arrayOut);
   7448         for (int i = 0; i < INPUTSIZE; i++) {
   7449             for (int j = 0; j < 3 ; j++) {
   7450                 // Extract the inputs.
   7451                 ArgumentsFloatUint args = new ArgumentsFloatUint();
   7452                 args.inV = arrayInV[i * 4 + j];
   7453                 // Figure out what the outputs should have been.
   7454                 CoreMathVerifier.computeConvert(args);
   7455                 // Validate the outputs.
   7456                 boolean valid = true;
   7457                 if (args.out != arrayOut[i * 4 + j]) {
   7458                     valid = false;
   7459                 }
   7460                 if (!valid) {
   7461                     StringBuilder message = new StringBuilder();
   7462                     message.append("Input inV: ");
   7463                     message.append(String.format("%14.8g {%8x} %15a",
   7464                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
   7465                     message.append("\n");
   7466                     message.append("Expected output out: ");
   7467                     message.append(String.format("0x%x", args.out));
   7468                     message.append("\n");
   7469                     message.append("Actual   output out: ");
   7470                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   7471                     if (args.out != arrayOut[i * 4 + j]) {
   7472                         message.append(" FAIL");
   7473                     }
   7474                     message.append("\n");
   7475                     assertTrue("Incorrect output for checkConvertFloat3Uint3" +
   7476                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   7477                 }
   7478             }
   7479         }
   7480     }
   7481 
   7482     private void checkConvertFloat4Uint4() {
   7483         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x239ccc10005d540al, 0.0000000000000000000e+00, 4.2949670400000000000e+09);
   7484         try {
   7485             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE);
   7486             script.forEach_testConvertUint4Float4Uint4(inV, out);
   7487             verifyResultsConvertFloat4Uint4(inV, out, false);
   7488         } catch (Exception e) {
   7489             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint4Float4Uint4: " + e.toString());
   7490         }
   7491         try {
   7492             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE);
   7493             scriptRelaxed.forEach_testConvertUint4Float4Uint4(inV, out);
   7494             verifyResultsConvertFloat4Uint4(inV, out, true);
   7495         } catch (Exception e) {
   7496             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint4Float4Uint4: " + e.toString());
   7497         }
   7498     }
   7499 
   7500     private void verifyResultsConvertFloat4Uint4(Allocation inV, Allocation out, boolean relaxed) {
   7501         float[] arrayInV = new float[INPUTSIZE * 4];
   7502         inV.copyTo(arrayInV);
   7503         int[] arrayOut = new int[INPUTSIZE * 4];
   7504         out.copyTo(arrayOut);
   7505         for (int i = 0; i < INPUTSIZE; i++) {
   7506             for (int j = 0; j < 4 ; j++) {
   7507                 // Extract the inputs.
   7508                 ArgumentsFloatUint args = new ArgumentsFloatUint();
   7509                 args.inV = arrayInV[i * 4 + j];
   7510                 // Figure out what the outputs should have been.
   7511                 CoreMathVerifier.computeConvert(args);
   7512                 // Validate the outputs.
   7513                 boolean valid = true;
   7514                 if (args.out != arrayOut[i * 4 + j]) {
   7515                     valid = false;
   7516                 }
   7517                 if (!valid) {
   7518                     StringBuilder message = new StringBuilder();
   7519                     message.append("Input inV: ");
   7520                     message.append(String.format("%14.8g {%8x} %15a",
   7521                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
   7522                     message.append("\n");
   7523                     message.append("Expected output out: ");
   7524                     message.append(String.format("0x%x", args.out));
   7525                     message.append("\n");
   7526                     message.append("Actual   output out: ");
   7527                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   7528                     if (args.out != arrayOut[i * 4 + j]) {
   7529                         message.append(" FAIL");
   7530                     }
   7531                     message.append("\n");
   7532                     assertTrue("Incorrect output for checkConvertFloat4Uint4" +
   7533                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   7534                 }
   7535             }
   7536         }
   7537     }
   7538 
   7539     public class ArgumentsCharUint {
   7540         public byte inV;
   7541         public int out;
   7542     }
   7543 
   7544     private void checkConvertChar2Uint2() {
   7545         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_8, 2, 0xd8618beceddda162l, false, 7);
   7546         try {
   7547             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE);
   7548             script.forEach_testConvertUint2Char2Uint2(inV, out);
   7549             verifyResultsConvertChar2Uint2(inV, out, false);
   7550         } catch (Exception e) {
   7551             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint2Char2Uint2: " + e.toString());
   7552         }
   7553         try {
   7554             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE);
   7555             scriptRelaxed.forEach_testConvertUint2Char2Uint2(inV, out);
   7556             verifyResultsConvertChar2Uint2(inV, out, true);
   7557         } catch (Exception e) {
   7558             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint2Char2Uint2: " + e.toString());
   7559         }
   7560     }
   7561 
   7562     private void verifyResultsConvertChar2Uint2(Allocation inV, Allocation out, boolean relaxed) {
   7563         byte[] arrayInV = new byte[INPUTSIZE * 2];
   7564         inV.copyTo(arrayInV);
   7565         int[] arrayOut = new int[INPUTSIZE * 2];
   7566         out.copyTo(arrayOut);
   7567         for (int i = 0; i < INPUTSIZE; i++) {
   7568             for (int j = 0; j < 2 ; j++) {
   7569                 // Extract the inputs.
   7570                 ArgumentsCharUint args = new ArgumentsCharUint();
   7571                 args.inV = arrayInV[i * 2 + j];
   7572                 // Figure out what the outputs should have been.
   7573                 CoreMathVerifier.computeConvert(args);
   7574                 // Validate the outputs.
   7575                 boolean valid = true;
   7576                 if (args.out != arrayOut[i * 2 + j]) {
   7577                     valid = false;
   7578                 }
   7579                 if (!valid) {
   7580                     StringBuilder message = new StringBuilder();
   7581                     message.append("Input inV: ");
   7582                     message.append(String.format("%d", args.inV));
   7583                     message.append("\n");
   7584                     message.append("Expected output out: ");
   7585                     message.append(String.format("0x%x", args.out));
   7586                     message.append("\n");
   7587                     message.append("Actual   output out: ");
   7588                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   7589                     if (args.out != arrayOut[i * 2 + j]) {
   7590                         message.append(" FAIL");
   7591                     }
   7592                     message.append("\n");
   7593                     assertTrue("Incorrect output for checkConvertChar2Uint2" +
   7594                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   7595                 }
   7596             }
   7597         }
   7598     }
   7599 
   7600     private void checkConvertChar3Uint3() {
   7601         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_8, 3, 0xd861968e4ce56656l, false, 7);
   7602         try {
   7603             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE);
   7604             script.forEach_testConvertUint3Char3Uint3(inV, out);
   7605             verifyResultsConvertChar3Uint3(inV, out, false);
   7606         } catch (Exception e) {
   7607             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint3Char3Uint3: " + e.toString());
   7608         }
   7609         try {
   7610             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE);
   7611             scriptRelaxed.forEach_testConvertUint3Char3Uint3(inV, out);
   7612             verifyResultsConvertChar3Uint3(inV, out, true);
   7613         } catch (Exception e) {
   7614             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint3Char3Uint3: " + e.toString());
   7615         }
   7616     }
   7617 
   7618     private void verifyResultsConvertChar3Uint3(Allocation inV, Allocation out, boolean relaxed) {
   7619         byte[] arrayInV = new byte[INPUTSIZE * 4];
   7620         inV.copyTo(arrayInV);
   7621         int[] arrayOut = new int[INPUTSIZE * 4];
   7622         out.copyTo(arrayOut);
   7623         for (int i = 0; i < INPUTSIZE; i++) {
   7624             for (int j = 0; j < 3 ; j++) {
   7625                 // Extract the inputs.
   7626                 ArgumentsCharUint args = new ArgumentsCharUint();
   7627                 args.inV = arrayInV[i * 4 + j];
   7628                 // Figure out what the outputs should have been.
   7629                 CoreMathVerifier.computeConvert(args);
   7630                 // Validate the outputs.
   7631                 boolean valid = true;
   7632                 if (args.out != arrayOut[i * 4 + j]) {
   7633                     valid = false;
   7634                 }
   7635                 if (!valid) {
   7636                     StringBuilder message = new StringBuilder();
   7637                     message.append("Input inV: ");
   7638                     message.append(String.format("%d", args.inV));
   7639                     message.append("\n");
   7640                     message.append("Expected output out: ");
   7641                     message.append(String.format("0x%x", args.out));
   7642                     message.append("\n");
   7643                     message.append("Actual   output out: ");
   7644                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   7645                     if (args.out != arrayOut[i * 4 + j]) {
   7646                         message.append(" FAIL");
   7647                     }
   7648                     message.append("\n");
   7649                     assertTrue("Incorrect output for checkConvertChar3Uint3" +
   7650                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   7651                 }
   7652             }
   7653         }
   7654     }
   7655 
   7656     private void checkConvertChar4Uint4() {
   7657         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_8, 4, 0xd861a12fabed2b4al, false, 7);
   7658         try {
   7659             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE);
   7660             script.forEach_testConvertUint4Char4Uint4(inV, out);
   7661             verifyResultsConvertChar4Uint4(inV, out, false);
   7662         } catch (Exception e) {
   7663             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint4Char4Uint4: " + e.toString());
   7664         }
   7665         try {
   7666             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE);
   7667             scriptRelaxed.forEach_testConvertUint4Char4Uint4(inV, out);
   7668             verifyResultsConvertChar4Uint4(inV, out, true);
   7669         } catch (Exception e) {
   7670             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint4Char4Uint4: " + e.toString());
   7671         }
   7672     }
   7673 
   7674     private void verifyResultsConvertChar4Uint4(Allocation inV, Allocation out, boolean relaxed) {
   7675         byte[] arrayInV = new byte[INPUTSIZE * 4];
   7676         inV.copyTo(arrayInV);
   7677         int[] arrayOut = new int[INPUTSIZE * 4];
   7678         out.copyTo(arrayOut);
   7679         for (int i = 0; i < INPUTSIZE; i++) {
   7680             for (int j = 0; j < 4 ; j++) {
   7681                 // Extract the inputs.
   7682                 ArgumentsCharUint args = new ArgumentsCharUint();
   7683                 args.inV = arrayInV[i * 4 + j];
   7684                 // Figure out what the outputs should have been.
   7685                 CoreMathVerifier.computeConvert(args);
   7686                 // Validate the outputs.
   7687                 boolean valid = true;
   7688                 if (args.out != arrayOut[i * 4 + j]) {
   7689                     valid = false;
   7690                 }
   7691                 if (!valid) {
   7692                     StringBuilder message = new StringBuilder();
   7693                     message.append("Input inV: ");
   7694                     message.append(String.format("%d", args.inV));
   7695                     message.append("\n");
   7696                     message.append("Expected output out: ");
   7697                     message.append(String.format("0x%x", args.out));
   7698                     message.append("\n");
   7699                     message.append("Actual   output out: ");
   7700                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   7701                     if (args.out != arrayOut[i * 4 + j]) {
   7702                         message.append(" FAIL");
   7703                     }
   7704                     message.append("\n");
   7705                     assertTrue("Incorrect output for checkConvertChar4Uint4" +
   7706                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   7707                 }
   7708             }
   7709         }
   7710     }
   7711 
   7712     public class ArgumentsUcharUint {
   7713         public byte inV;
   7714         public int out;
   7715     }
   7716 
   7717     private void checkConvertUchar2Uint2() {
   7718         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_8, 2, 0x7fef453a805fade3l, false, 8);
   7719         try {
   7720             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE);
   7721             script.forEach_testConvertUint2Uchar2Uint2(inV, out);
   7722             verifyResultsConvertUchar2Uint2(inV, out, false);
   7723         } catch (Exception e) {
   7724             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint2Uchar2Uint2: " + e.toString());
   7725         }
   7726         try {
   7727             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE);
   7728             scriptRelaxed.forEach_testConvertUint2Uchar2Uint2(inV, out);
   7729             verifyResultsConvertUchar2Uint2(inV, out, true);
   7730         } catch (Exception e) {
   7731             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint2Uchar2Uint2: " + e.toString());
   7732         }
   7733     }
   7734 
   7735     private void verifyResultsConvertUchar2Uint2(Allocation inV, Allocation out, boolean relaxed) {
   7736         byte[] arrayInV = new byte[INPUTSIZE * 2];
   7737         inV.copyTo(arrayInV);
   7738         int[] arrayOut = new int[INPUTSIZE * 2];
   7739         out.copyTo(arrayOut);
   7740         for (int i = 0; i < INPUTSIZE; i++) {
   7741             for (int j = 0; j < 2 ; j++) {
   7742                 // Extract the inputs.
   7743                 ArgumentsUcharUint args = new ArgumentsUcharUint();
   7744                 args.inV = arrayInV[i * 2 + j];
   7745                 // Figure out what the outputs should have been.
   7746                 CoreMathVerifier.computeConvert(args);
   7747                 // Validate the outputs.
   7748                 boolean valid = true;
   7749                 if (args.out != arrayOut[i * 2 + j]) {
   7750                     valid = false;
   7751                 }
   7752                 if (!valid) {
   7753                     StringBuilder message = new StringBuilder();
   7754                     message.append("Input inV: ");
   7755                     message.append(String.format("0x%x", args.inV));
   7756                     message.append("\n");
   7757                     message.append("Expected output out: ");
   7758                     message.append(String.format("0x%x", args.out));
   7759                     message.append("\n");
   7760                     message.append("Actual   output out: ");
   7761                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   7762                     if (args.out != arrayOut[i * 2 + j]) {
   7763                         message.append(" FAIL");
   7764                     }
   7765                     message.append("\n");
   7766                     assertTrue("Incorrect output for checkConvertUchar2Uint2" +
   7767                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   7768                 }
   7769             }
   7770         }
   7771     }
   7772 
   7773     private void checkConvertUchar3Uint3() {
   7774         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_8, 3, 0x7fef4fdbdf6772d7l, false, 8);
   7775         try {
   7776             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE);
   7777             script.forEach_testConvertUint3Uchar3Uint3(inV, out);
   7778             verifyResultsConvertUchar3Uint3(inV, out, false);
   7779         } catch (Exception e) {
   7780             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint3Uchar3Uint3: " + e.toString());
   7781         }
   7782         try {
   7783             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE);
   7784             scriptRelaxed.forEach_testConvertUint3Uchar3Uint3(inV, out);
   7785             verifyResultsConvertUchar3Uint3(inV, out, true);
   7786         } catch (Exception e) {
   7787             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint3Uchar3Uint3: " + e.toString());
   7788         }
   7789     }
   7790 
   7791     private void verifyResultsConvertUchar3Uint3(Allocation inV, Allocation out, boolean relaxed) {
   7792         byte[] arrayInV = new byte[INPUTSIZE * 4];
   7793         inV.copyTo(arrayInV);
   7794         int[] arrayOut = new int[INPUTSIZE * 4];
   7795         out.copyTo(arrayOut);
   7796         for (int i = 0; i < INPUTSIZE; i++) {
   7797             for (int j = 0; j < 3 ; j++) {
   7798                 // Extract the inputs.
   7799                 ArgumentsUcharUint args = new ArgumentsUcharUint();
   7800                 args.inV = arrayInV[i * 4 + j];
   7801                 // Figure out what the outputs should have been.
   7802                 CoreMathVerifier.computeConvert(args);
   7803                 // Validate the outputs.
   7804                 boolean valid = true;
   7805                 if (args.out != arrayOut[i * 4 + j]) {
   7806                     valid = false;
   7807                 }
   7808                 if (!valid) {
   7809                     StringBuilder message = new StringBuilder();
   7810                     message.append("Input inV: ");
   7811                     message.append(String.format("0x%x", args.inV));
   7812                     message.append("\n");
   7813                     message.append("Expected output out: ");
   7814                     message.append(String.format("0x%x", args.out));
   7815                     message.append("\n");
   7816                     message.append("Actual   output out: ");
   7817                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   7818                     if (args.out != arrayOut[i * 4 + j]) {
   7819                         message.append(" FAIL");
   7820                     }
   7821                     message.append("\n");
   7822                     assertTrue("Incorrect output for checkConvertUchar3Uint3" +
   7823                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   7824                 }
   7825             }
   7826         }
   7827     }
   7828 
   7829     private void checkConvertUchar4Uint4() {
   7830         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_8, 4, 0x7fef5a7d3e6f37cbl, false, 8);
   7831         try {
   7832             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE);
   7833             script.forEach_testConvertUint4Uchar4Uint4(inV, out);
   7834             verifyResultsConvertUchar4Uint4(inV, out, false);
   7835         } catch (Exception e) {
   7836             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint4Uchar4Uint4: " + e.toString());
   7837         }
   7838         try {
   7839             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE);
   7840             scriptRelaxed.forEach_testConvertUint4Uchar4Uint4(inV, out);
   7841             verifyResultsConvertUchar4Uint4(inV, out, true);
   7842         } catch (Exception e) {
   7843             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint4Uchar4Uint4: " + e.toString());
   7844         }
   7845     }
   7846 
   7847     private void verifyResultsConvertUchar4Uint4(Allocation inV, Allocation out, boolean relaxed) {
   7848         byte[] arrayInV = new byte[INPUTSIZE * 4];
   7849         inV.copyTo(arrayInV);
   7850         int[] arrayOut = new int[INPUTSIZE * 4];
   7851         out.copyTo(arrayOut);
   7852         for (int i = 0; i < INPUTSIZE; i++) {
   7853             for (int j = 0; j < 4 ; j++) {
   7854                 // Extract the inputs.
   7855                 ArgumentsUcharUint args = new ArgumentsUcharUint();
   7856                 args.inV = arrayInV[i * 4 + j];
   7857                 // Figure out what the outputs should have been.
   7858                 CoreMathVerifier.computeConvert(args);
   7859                 // Validate the outputs.
   7860                 boolean valid = true;
   7861                 if (args.out != arrayOut[i * 4 + j]) {
   7862                     valid = false;
   7863                 }
   7864                 if (!valid) {
   7865                     StringBuilder message = new StringBuilder();
   7866                     message.append("Input inV: ");
   7867                     message.append(String.format("0x%x", args.inV));
   7868                     message.append("\n");
   7869                     message.append("Expected output out: ");
   7870                     message.append(String.format("0x%x", args.out));
   7871                     message.append("\n");
   7872                     message.append("Actual   output out: ");
   7873                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   7874                     if (args.out != arrayOut[i * 4 + j]) {
   7875                         message.append(" FAIL");
   7876                     }
   7877                     message.append("\n");
   7878                     assertTrue("Incorrect output for checkConvertUchar4Uint4" +
   7879                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   7880                 }
   7881             }
   7882         }
   7883     }
   7884 
   7885     public class ArgumentsShortUint {
   7886         public short inV;
   7887         public int out;
   7888     }
   7889 
   7890     private void checkConvertShort2Uint2() {
   7891         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_16, 2, 0x68ab69772e9b3c26l, false, 15);
   7892         try {
   7893             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE);
   7894             script.forEach_testConvertUint2Short2Uint2(inV, out);
   7895             verifyResultsConvertShort2Uint2(inV, out, false);
   7896         } catch (Exception e) {
   7897             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint2Short2Uint2: " + e.toString());
   7898         }
   7899         try {
   7900             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE);
   7901             scriptRelaxed.forEach_testConvertUint2Short2Uint2(inV, out);
   7902             verifyResultsConvertShort2Uint2(inV, out, true);
   7903         } catch (Exception e) {
   7904             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint2Short2Uint2: " + e.toString());
   7905         }
   7906     }
   7907 
   7908     private void verifyResultsConvertShort2Uint2(Allocation inV, Allocation out, boolean relaxed) {
   7909         short[] arrayInV = new short[INPUTSIZE * 2];
   7910         inV.copyTo(arrayInV);
   7911         int[] arrayOut = new int[INPUTSIZE * 2];
   7912         out.copyTo(arrayOut);
   7913         for (int i = 0; i < INPUTSIZE; i++) {
   7914             for (int j = 0; j < 2 ; j++) {
   7915                 // Extract the inputs.
   7916                 ArgumentsShortUint args = new ArgumentsShortUint();
   7917                 args.inV = arrayInV[i * 2 + j];
   7918                 // Figure out what the outputs should have been.
   7919                 CoreMathVerifier.computeConvert(args);
   7920                 // Validate the outputs.
   7921                 boolean valid = true;
   7922                 if (args.out != arrayOut[i * 2 + j]) {
   7923                     valid = false;
   7924                 }
   7925                 if (!valid) {
   7926                     StringBuilder message = new StringBuilder();
   7927                     message.append("Input inV: ");
   7928                     message.append(String.format("%d", args.inV));
   7929                     message.append("\n");
   7930                     message.append("Expected output out: ");
   7931                     message.append(String.format("0x%x", args.out));
   7932                     message.append("\n");
   7933                     message.append("Actual   output out: ");
   7934                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   7935                     if (args.out != arrayOut[i * 2 + j]) {
   7936                         message.append(" FAIL");
   7937                     }
   7938                     message.append("\n");
   7939                     assertTrue("Incorrect output for checkConvertShort2Uint2" +
   7940                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   7941                 }
   7942             }
   7943         }
   7944     }
   7945 
   7946     private void checkConvertShort3Uint3() {
   7947         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_16, 3, 0x68ab74188da3011al, false, 15);
   7948         try {
   7949             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE);
   7950             script.forEach_testConvertUint3Short3Uint3(inV, out);
   7951             verifyResultsConvertShort3Uint3(inV, out, false);
   7952         } catch (Exception e) {
   7953             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint3Short3Uint3: " + e.toString());
   7954         }
   7955         try {
   7956             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE);
   7957             scriptRelaxed.forEach_testConvertUint3Short3Uint3(inV, out);
   7958             verifyResultsConvertShort3Uint3(inV, out, true);
   7959         } catch (Exception e) {
   7960             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint3Short3Uint3: " + e.toString());
   7961         }
   7962     }
   7963 
   7964     private void verifyResultsConvertShort3Uint3(Allocation inV, Allocation out, boolean relaxed) {
   7965         short[] arrayInV = new short[INPUTSIZE * 4];
   7966         inV.copyTo(arrayInV);
   7967         int[] arrayOut = new int[INPUTSIZE * 4];
   7968         out.copyTo(arrayOut);
   7969         for (int i = 0; i < INPUTSIZE; i++) {
   7970             for (int j = 0; j < 3 ; j++) {
   7971                 // Extract the inputs.
   7972                 ArgumentsShortUint args = new ArgumentsShortUint();
   7973                 args.inV = arrayInV[i * 4 + j];
   7974                 // Figure out what the outputs should have been.
   7975                 CoreMathVerifier.computeConvert(args);
   7976                 // Validate the outputs.
   7977                 boolean valid = true;
   7978                 if (args.out != arrayOut[i * 4 + j]) {
   7979                     valid = false;
   7980                 }
   7981                 if (!valid) {
   7982                     StringBuilder message = new StringBuilder();
   7983                     message.append("Input inV: ");
   7984                     message.append(String.format("%d", args.inV));
   7985                     message.append("\n");
   7986                     message.append("Expected output out: ");
   7987                     message.append(String.format("0x%x", args.out));
   7988                     message.append("\n");
   7989                     message.append("Actual   output out: ");
   7990                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   7991                     if (args.out != arrayOut[i * 4 + j]) {
   7992                         message.append(" FAIL");
   7993                     }
   7994                     message.append("\n");
   7995                     assertTrue("Incorrect output for checkConvertShort3Uint3" +
   7996                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   7997                 }
   7998             }
   7999         }
   8000     }
   8001 
   8002     private void checkConvertShort4Uint4() {
   8003         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_16, 4, 0x68ab7eb9ecaac60el, false, 15);
   8004         try {
   8005             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE);
   8006             script.forEach_testConvertUint4Short4Uint4(inV, out);
   8007             verifyResultsConvertShort4Uint4(inV, out, false);
   8008         } catch (Exception e) {
   8009             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint4Short4Uint4: " + e.toString());
   8010         }
   8011         try {
   8012             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE);
   8013             scriptRelaxed.forEach_testConvertUint4Short4Uint4(inV, out);
   8014             verifyResultsConvertShort4Uint4(inV, out, true);
   8015         } catch (Exception e) {
   8016             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint4Short4Uint4: " + e.toString());
   8017         }
   8018     }
   8019 
   8020     private void verifyResultsConvertShort4Uint4(Allocation inV, Allocation out, boolean relaxed) {
   8021         short[] arrayInV = new short[INPUTSIZE * 4];
   8022         inV.copyTo(arrayInV);
   8023         int[] arrayOut = new int[INPUTSIZE * 4];
   8024         out.copyTo(arrayOut);
   8025         for (int i = 0; i < INPUTSIZE; i++) {
   8026             for (int j = 0; j < 4 ; j++) {
   8027                 // Extract the inputs.
   8028                 ArgumentsShortUint args = new ArgumentsShortUint();
   8029                 args.inV = arrayInV[i * 4 + j];
   8030                 // Figure out what the outputs should have been.
   8031                 CoreMathVerifier.computeConvert(args);
   8032                 // Validate the outputs.
   8033                 boolean valid = true;
   8034                 if (args.out != arrayOut[i * 4 + j]) {
   8035                     valid = false;
   8036                 }
   8037                 if (!valid) {
   8038                     StringBuilder message = new StringBuilder();
   8039                     message.append("Input inV: ");
   8040                     message.append(String.format("%d", args.inV));
   8041                     message.append("\n");
   8042                     message.append("Expected output out: ");
   8043                     message.append(String.format("0x%x", args.out));
   8044                     message.append("\n");
   8045                     message.append("Actual   output out: ");
   8046                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   8047                     if (args.out != arrayOut[i * 4 + j]) {
   8048                         message.append(" FAIL");
   8049                     }
   8050                     message.append("\n");
   8051                     assertTrue("Incorrect output for checkConvertShort4Uint4" +
   8052                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   8053                 }
   8054             }
   8055         }
   8056     }
   8057 
   8058     public class ArgumentsUshortUint {
   8059         public short inV;
   8060         public int out;
   8061     }
   8062 
   8063     private void checkConvertUshort2Uint2() {
   8064         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_16, 2, 0x8d79897eca7355d1l, false, 16);
   8065         try {
   8066             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE);
   8067             script.forEach_testConvertUint2Ushort2Uint2(inV, out);
   8068             verifyResultsConvertUshort2Uint2(inV, out, false);
   8069         } catch (Exception e) {
   8070             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint2Ushort2Uint2: " + e.toString());
   8071         }
   8072         try {
   8073             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE);
   8074             scriptRelaxed.forEach_testConvertUint2Ushort2Uint2(inV, out);
   8075             verifyResultsConvertUshort2Uint2(inV, out, true);
   8076         } catch (Exception e) {
   8077             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint2Ushort2Uint2: " + e.toString());
   8078         }
   8079     }
   8080 
   8081     private void verifyResultsConvertUshort2Uint2(Allocation inV, Allocation out, boolean relaxed) {
   8082         short[] arrayInV = new short[INPUTSIZE * 2];
   8083         inV.copyTo(arrayInV);
   8084         int[] arrayOut = new int[INPUTSIZE * 2];
   8085         out.copyTo(arrayOut);
   8086         for (int i = 0; i < INPUTSIZE; i++) {
   8087             for (int j = 0; j < 2 ; j++) {
   8088                 // Extract the inputs.
   8089                 ArgumentsUshortUint args = new ArgumentsUshortUint();
   8090                 args.inV = arrayInV[i * 2 + j];
   8091                 // Figure out what the outputs should have been.
   8092                 CoreMathVerifier.computeConvert(args);
   8093                 // Validate the outputs.
   8094                 boolean valid = true;
   8095                 if (args.out != arrayOut[i * 2 + j]) {
   8096                     valid = false;
   8097                 }
   8098                 if (!valid) {
   8099                     StringBuilder message = new StringBuilder();
   8100                     message.append("Input inV: ");
   8101                     message.append(String.format("0x%x", args.inV));
   8102                     message.append("\n");
   8103                     message.append("Expected output out: ");
   8104                     message.append(String.format("0x%x", args.out));
   8105                     message.append("\n");
   8106                     message.append("Actual   output out: ");
   8107                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   8108                     if (args.out != arrayOut[i * 2 + j]) {
   8109                         message.append(" FAIL");
   8110                     }
   8111                     message.append("\n");
   8112                     assertTrue("Incorrect output for checkConvertUshort2Uint2" +
   8113                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   8114                 }
   8115             }
   8116         }
   8117     }
   8118 
   8119     private void checkConvertUshort3Uint3() {
   8120         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_16, 3, 0x8d799420297b1ac5l, false, 16);
   8121         try {
   8122             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE);
   8123             script.forEach_testConvertUint3Ushort3Uint3(inV, out);
   8124             verifyResultsConvertUshort3Uint3(inV, out, false);
   8125         } catch (Exception e) {
   8126             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint3Ushort3Uint3: " + e.toString());
   8127         }
   8128         try {
   8129             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE);
   8130             scriptRelaxed.forEach_testConvertUint3Ushort3Uint3(inV, out);
   8131             verifyResultsConvertUshort3Uint3(inV, out, true);
   8132         } catch (Exception e) {
   8133             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint3Ushort3Uint3: " + e.toString());
   8134         }
   8135     }
   8136 
   8137     private void verifyResultsConvertUshort3Uint3(Allocation inV, Allocation out, boolean relaxed) {
   8138         short[] arrayInV = new short[INPUTSIZE * 4];
   8139         inV.copyTo(arrayInV);
   8140         int[] arrayOut = new int[INPUTSIZE * 4];
   8141         out.copyTo(arrayOut);
   8142         for (int i = 0; i < INPUTSIZE; i++) {
   8143             for (int j = 0; j < 3 ; j++) {
   8144                 // Extract the inputs.
   8145                 ArgumentsUshortUint args = new ArgumentsUshortUint();
   8146                 args.inV = arrayInV[i * 4 + j];
   8147                 // Figure out what the outputs should have been.
   8148                 CoreMathVerifier.computeConvert(args);
   8149                 // Validate the outputs.
   8150                 boolean valid = true;
   8151                 if (args.out != arrayOut[i * 4 + j]) {
   8152                     valid = false;
   8153                 }
   8154                 if (!valid) {
   8155                     StringBuilder message = new StringBuilder();
   8156                     message.append("Input inV: ");
   8157                     message.append(String.format("0x%x", args.inV));
   8158                     message.append("\n");
   8159                     message.append("Expected output out: ");
   8160                     message.append(String.format("0x%x", args.out));
   8161                     message.append("\n");
   8162                     message.append("Actual   output out: ");
   8163                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   8164                     if (args.out != arrayOut[i * 4 + j]) {
   8165                         message.append(" FAIL");
   8166                     }
   8167                     message.append("\n");
   8168                     assertTrue("Incorrect output for checkConvertUshort3Uint3" +
   8169                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   8170                 }
   8171             }
   8172         }
   8173     }
   8174 
   8175     private void checkConvertUshort4Uint4() {
   8176         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_16, 4, 0x8d799ec18882dfb9l, false, 16);
   8177         try {
   8178             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE);
   8179             script.forEach_testConvertUint4Ushort4Uint4(inV, out);
   8180             verifyResultsConvertUshort4Uint4(inV, out, false);
   8181         } catch (Exception e) {
   8182             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint4Ushort4Uint4: " + e.toString());
   8183         }
   8184         try {
   8185             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE);
   8186             scriptRelaxed.forEach_testConvertUint4Ushort4Uint4(inV, out);
   8187             verifyResultsConvertUshort4Uint4(inV, out, true);
   8188         } catch (Exception e) {
   8189             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint4Ushort4Uint4: " + e.toString());
   8190         }
   8191     }
   8192 
   8193     private void verifyResultsConvertUshort4Uint4(Allocation inV, Allocation out, boolean relaxed) {
   8194         short[] arrayInV = new short[INPUTSIZE * 4];
   8195         inV.copyTo(arrayInV);
   8196         int[] arrayOut = new int[INPUTSIZE * 4];
   8197         out.copyTo(arrayOut);
   8198         for (int i = 0; i < INPUTSIZE; i++) {
   8199             for (int j = 0; j < 4 ; j++) {
   8200                 // Extract the inputs.
   8201                 ArgumentsUshortUint args = new ArgumentsUshortUint();
   8202                 args.inV = arrayInV[i * 4 + j];
   8203                 // Figure out what the outputs should have been.
   8204                 CoreMathVerifier.computeConvert(args);
   8205                 // Validate the outputs.
   8206                 boolean valid = true;
   8207                 if (args.out != arrayOut[i * 4 + j]) {
   8208                     valid = false;
   8209                 }
   8210                 if (!valid) {
   8211                     StringBuilder message = new StringBuilder();
   8212                     message.append("Input inV: ");
   8213                     message.append(String.format("0x%x", args.inV));
   8214                     message.append("\n");
   8215                     message.append("Expected output out: ");
   8216                     message.append(String.format("0x%x", args.out));
   8217                     message.append("\n");
   8218                     message.append("Actual   output out: ");
   8219                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   8220                     if (args.out != arrayOut[i * 4 + j]) {
   8221                         message.append(" FAIL");
   8222                     }
   8223                     message.append("\n");
   8224                     assertTrue("Incorrect output for checkConvertUshort4Uint4" +
   8225                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   8226                 }
   8227             }
   8228         }
   8229     }
   8230 
   8231     public class ArgumentsIntUint {
   8232         public int inV;
   8233         public int out;
   8234     }
   8235 
   8236     private void checkConvertInt2Uint2() {
   8237         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_32, 2, 0xd74f55bc4f178a9fl, false, 31);
   8238         try {
   8239             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE);
   8240             script.forEach_testConvertUint2Int2Uint2(inV, out);
   8241             verifyResultsConvertInt2Uint2(inV, out, false);
   8242         } catch (Exception e) {
   8243             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint2Int2Uint2: " + e.toString());
   8244         }
   8245         try {
   8246             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE);
   8247             scriptRelaxed.forEach_testConvertUint2Int2Uint2(inV, out);
   8248             verifyResultsConvertInt2Uint2(inV, out, true);
   8249         } catch (Exception e) {
   8250             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint2Int2Uint2: " + e.toString());
   8251         }
   8252     }
   8253 
   8254     private void verifyResultsConvertInt2Uint2(Allocation inV, Allocation out, boolean relaxed) {
   8255         int[] arrayInV = new int[INPUTSIZE * 2];
   8256         inV.copyTo(arrayInV);
   8257         int[] arrayOut = new int[INPUTSIZE * 2];
   8258         out.copyTo(arrayOut);
   8259         for (int i = 0; i < INPUTSIZE; i++) {
   8260             for (int j = 0; j < 2 ; j++) {
   8261                 // Extract the inputs.
   8262                 ArgumentsIntUint args = new ArgumentsIntUint();
   8263                 args.inV = arrayInV[i * 2 + j];
   8264                 // Figure out what the outputs should have been.
   8265                 CoreMathVerifier.computeConvert(args);
   8266                 // Validate the outputs.
   8267                 boolean valid = true;
   8268                 if (args.out != arrayOut[i * 2 + j]) {
   8269                     valid = false;
   8270                 }
   8271                 if (!valid) {
   8272                     StringBuilder message = new StringBuilder();
   8273                     message.append("Input inV: ");
   8274                     message.append(String.format("%d", args.inV));
   8275                     message.append("\n");
   8276                     message.append("Expected output out: ");
   8277                     message.append(String.format("0x%x", args.out));
   8278                     message.append("\n");
   8279                     message.append("Actual   output out: ");
   8280                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   8281                     if (args.out != arrayOut[i * 2 + j]) {
   8282                         message.append(" FAIL");
   8283                     }
   8284                     message.append("\n");
   8285                     assertTrue("Incorrect output for checkConvertInt2Uint2" +
   8286                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   8287                 }
   8288             }
   8289         }
   8290     }
   8291 
   8292     private void checkConvertInt3Uint3() {
   8293         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_32, 3, 0xd74f605dae1f4f93l, false, 31);
   8294         try {
   8295             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE);
   8296             script.forEach_testConvertUint3Int3Uint3(inV, out);
   8297             verifyResultsConvertInt3Uint3(inV, out, false);
   8298         } catch (Exception e) {
   8299             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint3Int3Uint3: " + e.toString());
   8300         }
   8301         try {
   8302             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE);
   8303             scriptRelaxed.forEach_testConvertUint3Int3Uint3(inV, out);
   8304             verifyResultsConvertInt3Uint3(inV, out, true);
   8305         } catch (Exception e) {
   8306             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint3Int3Uint3: " + e.toString());
   8307         }
   8308     }
   8309 
   8310     private void verifyResultsConvertInt3Uint3(Allocation inV, Allocation out, boolean relaxed) {
   8311         int[] arrayInV = new int[INPUTSIZE * 4];
   8312         inV.copyTo(arrayInV);
   8313         int[] arrayOut = new int[INPUTSIZE * 4];
   8314         out.copyTo(arrayOut);
   8315         for (int i = 0; i < INPUTSIZE; i++) {
   8316             for (int j = 0; j < 3 ; j++) {
   8317                 // Extract the inputs.
   8318                 ArgumentsIntUint args = new ArgumentsIntUint();
   8319                 args.inV = arrayInV[i * 4 + j];
   8320                 // Figure out what the outputs should have been.
   8321                 CoreMathVerifier.computeConvert(args);
   8322                 // Validate the outputs.
   8323                 boolean valid = true;
   8324                 if (args.out != arrayOut[i * 4 + j]) {
   8325                     valid = false;
   8326                 }
   8327                 if (!valid) {
   8328                     StringBuilder message = new StringBuilder();
   8329                     message.append("Input inV: ");
   8330                     message.append(String.format("%d", args.inV));
   8331                     message.append("\n");
   8332                     message.append("Expected output out: ");
   8333                     message.append(String.format("0x%x", args.out));
   8334                     message.append("\n");
   8335                     message.append("Actual   output out: ");
   8336                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   8337                     if (args.out != arrayOut[i * 4 + j]) {
   8338                         message.append(" FAIL");
   8339                     }
   8340                     message.append("\n");
   8341                     assertTrue("Incorrect output for checkConvertInt3Uint3" +
   8342                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   8343                 }
   8344             }
   8345         }
   8346     }
   8347 
   8348     private void checkConvertInt4Uint4() {
   8349         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_32, 4, 0xd74f6aff0d271487l, false, 31);
   8350         try {
   8351             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE);
   8352             script.forEach_testConvertUint4Int4Uint4(inV, out);
   8353             verifyResultsConvertInt4Uint4(inV, out, false);
   8354         } catch (Exception e) {
   8355             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint4Int4Uint4: " + e.toString());
   8356         }
   8357         try {
   8358             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE);
   8359             scriptRelaxed.forEach_testConvertUint4Int4Uint4(inV, out);
   8360             verifyResultsConvertInt4Uint4(inV, out, true);
   8361         } catch (Exception e) {
   8362             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint4Int4Uint4: " + e.toString());
   8363         }
   8364     }
   8365 
   8366     private void verifyResultsConvertInt4Uint4(Allocation inV, Allocation out, boolean relaxed) {
   8367         int[] arrayInV = new int[INPUTSIZE * 4];
   8368         inV.copyTo(arrayInV);
   8369         int[] arrayOut = new int[INPUTSIZE * 4];
   8370         out.copyTo(arrayOut);
   8371         for (int i = 0; i < INPUTSIZE; i++) {
   8372             for (int j = 0; j < 4 ; j++) {
   8373                 // Extract the inputs.
   8374                 ArgumentsIntUint args = new ArgumentsIntUint();
   8375                 args.inV = arrayInV[i * 4 + j];
   8376                 // Figure out what the outputs should have been.
   8377                 CoreMathVerifier.computeConvert(args);
   8378                 // Validate the outputs.
   8379                 boolean valid = true;
   8380                 if (args.out != arrayOut[i * 4 + j]) {
   8381                     valid = false;
   8382                 }
   8383                 if (!valid) {
   8384                     StringBuilder message = new StringBuilder();
   8385                     message.append("Input inV: ");
   8386                     message.append(String.format("%d", args.inV));
   8387                     message.append("\n");
   8388                     message.append("Expected output out: ");
   8389                     message.append(String.format("0x%x", args.out));
   8390                     message.append("\n");
   8391                     message.append("Actual   output out: ");
   8392                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   8393                     if (args.out != arrayOut[i * 4 + j]) {
   8394                         message.append(" FAIL");
   8395                     }
   8396                     message.append("\n");
   8397                     assertTrue("Incorrect output for checkConvertInt4Uint4" +
   8398                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   8399                 }
   8400             }
   8401         }
   8402     }
   8403 
   8404     public class ArgumentsUintUint {
   8405         public int inV;
   8406         public int out;
   8407     }
   8408 
   8409     private void checkConvertUint2Uint2() {
   8410         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_32, 2, 0xe71d0ca64c8baea2l, false, 32);
   8411         try {
   8412             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE);
   8413             script.forEach_testConvertUint2Uint2Uint2(inV, out);
   8414             verifyResultsConvertUint2Uint2(inV, out, false);
   8415         } catch (Exception e) {
   8416             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint2Uint2Uint2: " + e.toString());
   8417         }
   8418         try {
   8419             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE);
   8420             scriptRelaxed.forEach_testConvertUint2Uint2Uint2(inV, out);
   8421             verifyResultsConvertUint2Uint2(inV, out, true);
   8422         } catch (Exception e) {
   8423             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint2Uint2Uint2: " + e.toString());
   8424         }
   8425     }
   8426 
   8427     private void verifyResultsConvertUint2Uint2(Allocation inV, Allocation out, boolean relaxed) {
   8428         int[] arrayInV = new int[INPUTSIZE * 2];
   8429         inV.copyTo(arrayInV);
   8430         int[] arrayOut = new int[INPUTSIZE * 2];
   8431         out.copyTo(arrayOut);
   8432         for (int i = 0; i < INPUTSIZE; i++) {
   8433             for (int j = 0; j < 2 ; j++) {
   8434                 // Extract the inputs.
   8435                 ArgumentsUintUint args = new ArgumentsUintUint();
   8436                 args.inV = arrayInV[i * 2 + j];
   8437                 // Figure out what the outputs should have been.
   8438                 CoreMathVerifier.computeConvert(args);
   8439                 // Validate the outputs.
   8440                 boolean valid = true;
   8441                 if (args.out != arrayOut[i * 2 + j]) {
   8442                     valid = false;
   8443                 }
   8444                 if (!valid) {
   8445                     StringBuilder message = new StringBuilder();
   8446                     message.append("Input inV: ");
   8447                     message.append(String.format("0x%x", args.inV));
   8448                     message.append("\n");
   8449                     message.append("Expected output out: ");
   8450                     message.append(String.format("0x%x", args.out));
   8451                     message.append("\n");
   8452                     message.append("Actual   output out: ");
   8453                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   8454                     if (args.out != arrayOut[i * 2 + j]) {
   8455                         message.append(" FAIL");
   8456                     }
   8457                     message.append("\n");
   8458                     assertTrue("Incorrect output for checkConvertUint2Uint2" +
   8459                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   8460                 }
   8461             }
   8462         }
   8463     }
   8464 
   8465     private void checkConvertUint3Uint3() {
   8466         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_32, 3, 0xe71d1747ab937396l, false, 32);
   8467         try {
   8468             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE);
   8469             script.forEach_testConvertUint3Uint3Uint3(inV, out);
   8470             verifyResultsConvertUint3Uint3(inV, out, false);
   8471         } catch (Exception e) {
   8472             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint3Uint3Uint3: " + e.toString());
   8473         }
   8474         try {
   8475             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE);
   8476             scriptRelaxed.forEach_testConvertUint3Uint3Uint3(inV, out);
   8477             verifyResultsConvertUint3Uint3(inV, out, true);
   8478         } catch (Exception e) {
   8479             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint3Uint3Uint3: " + e.toString());
   8480         }
   8481     }
   8482 
   8483     private void verifyResultsConvertUint3Uint3(Allocation inV, Allocation out, boolean relaxed) {
   8484         int[] arrayInV = new int[INPUTSIZE * 4];
   8485         inV.copyTo(arrayInV);
   8486         int[] arrayOut = new int[INPUTSIZE * 4];
   8487         out.copyTo(arrayOut);
   8488         for (int i = 0; i < INPUTSIZE; i++) {
   8489             for (int j = 0; j < 3 ; j++) {
   8490                 // Extract the inputs.
   8491                 ArgumentsUintUint args = new ArgumentsUintUint();
   8492                 args.inV = arrayInV[i * 4 + j];
   8493                 // Figure out what the outputs should have been.
   8494                 CoreMathVerifier.computeConvert(args);
   8495                 // Validate the outputs.
   8496                 boolean valid = true;
   8497                 if (args.out != arrayOut[i * 4 + j]) {
   8498                     valid = false;
   8499                 }
   8500                 if (!valid) {
   8501                     StringBuilder message = new StringBuilder();
   8502                     message.append("Input inV: ");
   8503                     message.append(String.format("0x%x", args.inV));
   8504                     message.append("\n");
   8505                     message.append("Expected output out: ");
   8506                     message.append(String.format("0x%x", args.out));
   8507                     message.append("\n");
   8508                     message.append("Actual   output out: ");
   8509                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   8510                     if (args.out != arrayOut[i * 4 + j]) {
   8511                         message.append(" FAIL");
   8512                     }
   8513                     message.append("\n");
   8514                     assertTrue("Incorrect output for checkConvertUint3Uint3" +
   8515                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   8516                 }
   8517             }
   8518         }
   8519     }
   8520 
   8521     private void checkConvertUint4Uint4() {
   8522         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_32, 4, 0xe71d21e90a9b388al, false, 32);
   8523         try {
   8524             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE);
   8525             script.forEach_testConvertUint4Uint4Uint4(inV, out);
   8526             verifyResultsConvertUint4Uint4(inV, out, false);
   8527         } catch (Exception e) {
   8528             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint4Uint4Uint4: " + e.toString());
   8529         }
   8530         try {
   8531             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE);
   8532             scriptRelaxed.forEach_testConvertUint4Uint4Uint4(inV, out);
   8533             verifyResultsConvertUint4Uint4(inV, out, true);
   8534         } catch (Exception e) {
   8535             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint4Uint4Uint4: " + e.toString());
   8536         }
   8537     }
   8538 
   8539     private void verifyResultsConvertUint4Uint4(Allocation inV, Allocation out, boolean relaxed) {
   8540         int[] arrayInV = new int[INPUTSIZE * 4];
   8541         inV.copyTo(arrayInV);
   8542         int[] arrayOut = new int[INPUTSIZE * 4];
   8543         out.copyTo(arrayOut);
   8544         for (int i = 0; i < INPUTSIZE; i++) {
   8545             for (int j = 0; j < 4 ; j++) {
   8546                 // Extract the inputs.
   8547                 ArgumentsUintUint args = new ArgumentsUintUint();
   8548                 args.inV = arrayInV[i * 4 + j];
   8549                 // Figure out what the outputs should have been.
   8550                 CoreMathVerifier.computeConvert(args);
   8551                 // Validate the outputs.
   8552                 boolean valid = true;
   8553                 if (args.out != arrayOut[i * 4 + j]) {
   8554                     valid = false;
   8555                 }
   8556                 if (!valid) {
   8557                     StringBuilder message = new StringBuilder();
   8558                     message.append("Input inV: ");
   8559                     message.append(String.format("0x%x", args.inV));
   8560                     message.append("\n");
   8561                     message.append("Expected output out: ");
   8562                     message.append(String.format("0x%x", args.out));
   8563                     message.append("\n");
   8564                     message.append("Actual   output out: ");
   8565                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   8566                     if (args.out != arrayOut[i * 4 + j]) {
   8567                         message.append(" FAIL");
   8568                     }
   8569                     message.append("\n");
   8570                     assertTrue("Incorrect output for checkConvertUint4Uint4" +
   8571                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   8572                 }
   8573             }
   8574         }
   8575     }
   8576 
   8577     public class ArgumentsDoubleDouble {
   8578         public double inV;
   8579         public Target.Floaty out;
   8580     }
   8581 
   8582     private void checkConvertDouble2Double2() {
   8583         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_64, 2, 0x345b4a823902786el, -8.5390423905960001625e+307, 8.5390423905960001625e+307);
   8584         try {
   8585             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 2), INPUTSIZE);
   8586             script.forEach_testConvertDouble2Double2Double2(inV, out);
   8587             verifyResultsConvertDouble2Double2(inV, out, false);
   8588         } catch (Exception e) {
   8589             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble2Double2Double2: " + e.toString());
   8590         }
   8591         try {
   8592             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 2), INPUTSIZE);
   8593             scriptRelaxed.forEach_testConvertDouble2Double2Double2(inV, out);
   8594             verifyResultsConvertDouble2Double2(inV, out, true);
   8595         } catch (Exception e) {
   8596             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble2Double2Double2: " + e.toString());
   8597         }
   8598     }
   8599 
   8600     private void verifyResultsConvertDouble2Double2(Allocation inV, Allocation out, boolean relaxed) {
   8601         double[] arrayInV = new double[INPUTSIZE * 2];
   8602         inV.copyTo(arrayInV);
   8603         double[] arrayOut = new double[INPUTSIZE * 2];
   8604         out.copyTo(arrayOut);
   8605         for (int i = 0; i < INPUTSIZE; i++) {
   8606             for (int j = 0; j < 2 ; j++) {
   8607                 // Extract the inputs.
   8608                 ArgumentsDoubleDouble args = new ArgumentsDoubleDouble();
   8609                 args.inV = arrayInV[i * 2 + j];
   8610                 // Figure out what the outputs should have been.
   8611                 Target target = new Target(relaxed);
   8612                 CoreMathVerifier.computeConvert(args, target);
   8613                 // Validate the outputs.
   8614                 boolean valid = true;
   8615                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
   8616                     valid = false;
   8617                 }
   8618                 if (!valid) {
   8619                     StringBuilder message = new StringBuilder();
   8620                     message.append("Input inV: ");
   8621                     message.append(String.format("%24.8g {%16x} %31a",
   8622                             args.inV, Double.doubleToRawLongBits(args.inV), args.inV));
   8623                     message.append("\n");
   8624                     message.append("Expected output out: ");
   8625                     message.append(args.out.toString());
   8626                     message.append("\n");
   8627                     message.append("Actual   output out: ");
   8628                     message.append(String.format("%24.8g {%16x} %31a",
   8629                             arrayOut[i * 2 + j], Double.doubleToRawLongBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j]));
   8630                     if (!args.out.couldBe(arrayOut[i * 2 + j])) {
   8631                         message.append(" FAIL");
   8632                     }
   8633                     message.append("\n");
   8634                     assertTrue("Incorrect output for checkConvertDouble2Double2" +
   8635                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   8636                 }
   8637             }
   8638         }
   8639     }
   8640 
   8641     private void checkConvertDouble3Double3() {
   8642         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_64, 3, 0x34a812098f5e099al, -8.5390423905960001625e+307, 8.5390423905960001625e+307);
   8643         try {
   8644             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 3), INPUTSIZE);
   8645             script.forEach_testConvertDouble3Double3Double3(inV, out);
   8646             verifyResultsConvertDouble3Double3(inV, out, false);
   8647         } catch (Exception e) {
   8648             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble3Double3Double3: " + e.toString());
   8649         }
   8650         try {
   8651             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 3), INPUTSIZE);
   8652             scriptRelaxed.forEach_testConvertDouble3Double3Double3(inV, out);
   8653             verifyResultsConvertDouble3Double3(inV, out, true);
   8654         } catch (Exception e) {
   8655             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble3Double3Double3: " + e.toString());
   8656         }
   8657     }
   8658 
   8659     private void verifyResultsConvertDouble3Double3(Allocation inV, Allocation out, boolean relaxed) {
   8660         double[] arrayInV = new double[INPUTSIZE * 4];
   8661         inV.copyTo(arrayInV);
   8662         double[] arrayOut = new double[INPUTSIZE * 4];
   8663         out.copyTo(arrayOut);
   8664         for (int i = 0; i < INPUTSIZE; i++) {
   8665             for (int j = 0; j < 3 ; j++) {
   8666                 // Extract the inputs.
   8667                 ArgumentsDoubleDouble args = new ArgumentsDoubleDouble();
   8668                 args.inV = arrayInV[i * 4 + j];
   8669                 // Figure out what the outputs should have been.
   8670                 Target target = new Target(relaxed);
   8671                 CoreMathVerifier.computeConvert(args, target);
   8672                 // Validate the outputs.
   8673                 boolean valid = true;
   8674                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   8675                     valid = false;
   8676                 }
   8677                 if (!valid) {
   8678                     StringBuilder message = new StringBuilder();
   8679                     message.append("Input inV: ");
   8680                     message.append(String.format("%24.8g {%16x} %31a",
   8681                             args.inV, Double.doubleToRawLongBits(args.inV), args.inV));
   8682                     message.append("\n");
   8683                     message.append("Expected output out: ");
   8684                     message.append(args.out.toString());
   8685                     message.append("\n");
   8686                     message.append("Actual   output out: ");
   8687                     message.append(String.format("%24.8g {%16x} %31a",
   8688                             arrayOut[i * 4 + j], Double.doubleToRawLongBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
   8689                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   8690                         message.append(" FAIL");
   8691                     }
   8692                     message.append("\n");
   8693                     assertTrue("Incorrect output for checkConvertDouble3Double3" +
   8694                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   8695                 }
   8696             }
   8697         }
   8698     }
   8699 
   8700     private void checkConvertDouble4Double4() {
   8701         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_64, 4, 0x34f4d990e5b99ac6l, -8.5390423905960001625e+307, 8.5390423905960001625e+307);
   8702         try {
   8703             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 4), INPUTSIZE);
   8704             script.forEach_testConvertDouble4Double4Double4(inV, out);
   8705             verifyResultsConvertDouble4Double4(inV, out, false);
   8706         } catch (Exception e) {
   8707             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble4Double4Double4: " + e.toString());
   8708         }
   8709         try {
   8710             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 4), INPUTSIZE);
   8711             scriptRelaxed.forEach_testConvertDouble4Double4Double4(inV, out);
   8712             verifyResultsConvertDouble4Double4(inV, out, true);
   8713         } catch (Exception e) {
   8714             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble4Double4Double4: " + e.toString());
   8715         }
   8716     }
   8717 
   8718     private void verifyResultsConvertDouble4Double4(Allocation inV, Allocation out, boolean relaxed) {
   8719         double[] arrayInV = new double[INPUTSIZE * 4];
   8720         inV.copyTo(arrayInV);
   8721         double[] arrayOut = new double[INPUTSIZE * 4];
   8722         out.copyTo(arrayOut);
   8723         for (int i = 0; i < INPUTSIZE; i++) {
   8724             for (int j = 0; j < 4 ; j++) {
   8725                 // Extract the inputs.
   8726                 ArgumentsDoubleDouble args = new ArgumentsDoubleDouble();
   8727                 args.inV = arrayInV[i * 4 + j];
   8728                 // Figure out what the outputs should have been.
   8729                 Target target = new Target(relaxed);
   8730                 CoreMathVerifier.computeConvert(args, target);
   8731                 // Validate the outputs.
   8732                 boolean valid = true;
   8733                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   8734                     valid = false;
   8735                 }
   8736                 if (!valid) {
   8737                     StringBuilder message = new StringBuilder();
   8738                     message.append("Input inV: ");
   8739                     message.append(String.format("%24.8g {%16x} %31a",
   8740                             args.inV, Double.doubleToRawLongBits(args.inV), args.inV));
   8741                     message.append("\n");
   8742                     message.append("Expected output out: ");
   8743                     message.append(args.out.toString());
   8744                     message.append("\n");
   8745                     message.append("Actual   output out: ");
   8746                     message.append(String.format("%24.8g {%16x} %31a",
   8747                             arrayOut[i * 4 + j], Double.doubleToRawLongBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
   8748                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   8749                         message.append(" FAIL");
   8750                     }
   8751                     message.append("\n");
   8752                     assertTrue("Incorrect output for checkConvertDouble4Double4" +
   8753                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   8754                 }
   8755             }
   8756         }
   8757     }
   8758 
   8759     public class ArgumentsLongDouble {
   8760         public long inV;
   8761         public Target.Floaty out;
   8762     }
   8763 
   8764     private void checkConvertLong2Double2() {
   8765         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_64, 2, 0x7b7807124c70299bl, true, 63);
   8766         try {
   8767             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 2), INPUTSIZE);
   8768             script.forEach_testConvertDouble2Long2Double2(inV, out);
   8769             verifyResultsConvertLong2Double2(inV, out, false);
   8770         } catch (Exception e) {
   8771             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble2Long2Double2: " + e.toString());
   8772         }
   8773         try {
   8774             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 2), INPUTSIZE);
   8775             scriptRelaxed.forEach_testConvertDouble2Long2Double2(inV, out);
   8776             verifyResultsConvertLong2Double2(inV, out, true);
   8777         } catch (Exception e) {
   8778             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble2Long2Double2: " + e.toString());
   8779         }
   8780     }
   8781 
   8782     private void verifyResultsConvertLong2Double2(Allocation inV, Allocation out, boolean relaxed) {
   8783         long[] arrayInV = new long[INPUTSIZE * 2];
   8784         inV.copyTo(arrayInV);
   8785         double[] arrayOut = new double[INPUTSIZE * 2];
   8786         out.copyTo(arrayOut);
   8787         for (int i = 0; i < INPUTSIZE; i++) {
   8788             for (int j = 0; j < 2 ; j++) {
   8789                 // Extract the inputs.
   8790                 ArgumentsLongDouble args = new ArgumentsLongDouble();
   8791                 args.inV = arrayInV[i * 2 + j];
   8792                 // Figure out what the outputs should have been.
   8793                 Target target = new Target(relaxed);
   8794                 CoreMathVerifier.computeConvert(args, target);
   8795                 // Validate the outputs.
   8796                 boolean valid = true;
   8797                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
   8798                     valid = false;
   8799                 }
   8800                 if (!valid) {
   8801                     StringBuilder message = new StringBuilder();
   8802                     message.append("Input inV: ");
   8803                     message.append(String.format("%d", args.inV));
   8804                     message.append("\n");
   8805                     message.append("Expected output out: ");
   8806                     message.append(args.out.toString());
   8807                     message.append("\n");
   8808                     message.append("Actual   output out: ");
   8809                     message.append(String.format("%24.8g {%16x} %31a",
   8810                             arrayOut[i * 2 + j], Double.doubleToRawLongBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j]));
   8811                     if (!args.out.couldBe(arrayOut[i * 2 + j])) {
   8812                         message.append(" FAIL");
   8813                     }
   8814                     message.append("\n");
   8815                     assertTrue("Incorrect output for checkConvertLong2Double2" +
   8816                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   8817                 }
   8818             }
   8819         }
   8820     }
   8821 
   8822     private void checkConvertLong3Double3() {
   8823         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_64, 3, 0x7bc4ce99a2cbbac7l, true, 63);
   8824         try {
   8825             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 3), INPUTSIZE);
   8826             script.forEach_testConvertDouble3Long3Double3(inV, out);
   8827             verifyResultsConvertLong3Double3(inV, out, false);
   8828         } catch (Exception e) {
   8829             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble3Long3Double3: " + e.toString());
   8830         }
   8831         try {
   8832             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 3), INPUTSIZE);
   8833             scriptRelaxed.forEach_testConvertDouble3Long3Double3(inV, out);
   8834             verifyResultsConvertLong3Double3(inV, out, true);
   8835         } catch (Exception e) {
   8836             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble3Long3Double3: " + e.toString());
   8837         }
   8838     }
   8839 
   8840     private void verifyResultsConvertLong3Double3(Allocation inV, Allocation out, boolean relaxed) {
   8841         long[] arrayInV = new long[INPUTSIZE * 4];
   8842         inV.copyTo(arrayInV);
   8843         double[] arrayOut = new double[INPUTSIZE * 4];
   8844         out.copyTo(arrayOut);
   8845         for (int i = 0; i < INPUTSIZE; i++) {
   8846             for (int j = 0; j < 3 ; j++) {
   8847                 // Extract the inputs.
   8848                 ArgumentsLongDouble args = new ArgumentsLongDouble();
   8849                 args.inV = arrayInV[i * 4 + j];
   8850                 // Figure out what the outputs should have been.
   8851                 Target target = new Target(relaxed);
   8852                 CoreMathVerifier.computeConvert(args, target);
   8853                 // Validate the outputs.
   8854                 boolean valid = true;
   8855                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   8856                     valid = false;
   8857                 }
   8858                 if (!valid) {
   8859                     StringBuilder message = new StringBuilder();
   8860                     message.append("Input inV: ");
   8861                     message.append(String.format("%d", args.inV));
   8862                     message.append("\n");
   8863                     message.append("Expected output out: ");
   8864                     message.append(args.out.toString());
   8865                     message.append("\n");
   8866                     message.append("Actual   output out: ");
   8867                     message.append(String.format("%24.8g {%16x} %31a",
   8868                             arrayOut[i * 4 + j], Double.doubleToRawLongBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
   8869                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   8870                         message.append(" FAIL");
   8871                     }
   8872                     message.append("\n");
   8873                     assertTrue("Incorrect output for checkConvertLong3Double3" +
   8874                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   8875                 }
   8876             }
   8877         }
   8878     }
   8879 
   8880     private void checkConvertLong4Double4() {
   8881         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_64, 4, 0x7c119620f9274bf3l, true, 63);
   8882         try {
   8883             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 4), INPUTSIZE);
   8884             script.forEach_testConvertDouble4Long4Double4(inV, out);
   8885             verifyResultsConvertLong4Double4(inV, out, false);
   8886         } catch (Exception e) {
   8887             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble4Long4Double4: " + e.toString());
   8888         }
   8889         try {
   8890             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 4), INPUTSIZE);
   8891             scriptRelaxed.forEach_testConvertDouble4Long4Double4(inV, out);
   8892             verifyResultsConvertLong4Double4(inV, out, true);
   8893         } catch (Exception e) {
   8894             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble4Long4Double4: " + e.toString());
   8895         }
   8896     }
   8897 
   8898     private void verifyResultsConvertLong4Double4(Allocation inV, Allocation out, boolean relaxed) {
   8899         long[] arrayInV = new long[INPUTSIZE * 4];
   8900         inV.copyTo(arrayInV);
   8901         double[] arrayOut = new double[INPUTSIZE * 4];
   8902         out.copyTo(arrayOut);
   8903         for (int i = 0; i < INPUTSIZE; i++) {
   8904             for (int j = 0; j < 4 ; j++) {
   8905                 // Extract the inputs.
   8906                 ArgumentsLongDouble args = new ArgumentsLongDouble();
   8907                 args.inV = arrayInV[i * 4 + j];
   8908                 // Figure out what the outputs should have been.
   8909                 Target target = new Target(relaxed);
   8910                 CoreMathVerifier.computeConvert(args, target);
   8911                 // Validate the outputs.
   8912                 boolean valid = true;
   8913                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   8914                     valid = false;
   8915                 }
   8916                 if (!valid) {
   8917                     StringBuilder message = new StringBuilder();
   8918                     message.append("Input inV: ");
   8919                     message.append(String.format("%d", args.inV));
   8920                     message.append("\n");
   8921                     message.append("Expected output out: ");
   8922                     message.append(args.out.toString());
   8923                     message.append("\n");
   8924                     message.append("Actual   output out: ");
   8925                     message.append(String.format("%24.8g {%16x} %31a",
   8926                             arrayOut[i * 4 + j], Double.doubleToRawLongBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
   8927                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   8928                         message.append(" FAIL");
   8929                     }
   8930                     message.append("\n");
   8931                     assertTrue("Incorrect output for checkConvertLong4Double4" +
   8932                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   8933                 }
   8934             }
   8935         }
   8936     }
   8937 
   8938     public class ArgumentsUlongDouble {
   8939         public long inV;
   8940         public Target.Floaty out;
   8941     }
   8942 
   8943     private void checkConvertUlong2Double2() {
   8944         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_64, 2, 0xaa17685979bc7954l, false, 64);
   8945         try {
   8946             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 2), INPUTSIZE);
   8947             script.forEach_testConvertDouble2Ulong2Double2(inV, out);
   8948             verifyResultsConvertUlong2Double2(inV, out, false);
   8949         } catch (Exception e) {
   8950             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble2Ulong2Double2: " + e.toString());
   8951         }
   8952         try {
   8953             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 2), INPUTSIZE);
   8954             scriptRelaxed.forEach_testConvertDouble2Ulong2Double2(inV, out);
   8955             verifyResultsConvertUlong2Double2(inV, out, true);
   8956         } catch (Exception e) {
   8957             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble2Ulong2Double2: " + e.toString());
   8958         }
   8959     }
   8960 
   8961     private void verifyResultsConvertUlong2Double2(Allocation inV, Allocation out, boolean relaxed) {
   8962         long[] arrayInV = new long[INPUTSIZE * 2];
   8963         inV.copyTo(arrayInV);
   8964         double[] arrayOut = new double[INPUTSIZE * 2];
   8965         out.copyTo(arrayOut);
   8966         for (int i = 0; i < INPUTSIZE; i++) {
   8967             for (int j = 0; j < 2 ; j++) {
   8968                 // Extract the inputs.
   8969                 ArgumentsUlongDouble args = new ArgumentsUlongDouble();
   8970                 args.inV = arrayInV[i * 2 + j];
   8971                 // Figure out what the outputs should have been.
   8972                 Target target = new Target(relaxed);
   8973                 CoreMathVerifier.computeConvert(args, target);
   8974                 // Validate the outputs.
   8975                 boolean valid = true;
   8976                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
   8977                     valid = false;
   8978                 }
   8979                 if (!valid) {
   8980                     StringBuilder message = new StringBuilder();
   8981                     message.append("Input inV: ");
   8982                     message.append(String.format("0x%x", args.inV));
   8983                     message.append("\n");
   8984                     message.append("Expected output out: ");
   8985                     message.append(args.out.toString());
   8986                     message.append("\n");
   8987                     message.append("Actual   output out: ");
   8988                     message.append(String.format("%24.8g {%16x} %31a",
   8989                             arrayOut[i * 2 + j], Double.doubleToRawLongBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j]));
   8990                     if (!args.out.couldBe(arrayOut[i * 2 + j])) {
   8991                         message.append(" FAIL");
   8992                     }
   8993                     message.append("\n");
   8994                     assertTrue("Incorrect output for checkConvertUlong2Double2" +
   8995                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   8996                 }
   8997             }
   8998         }
   8999     }
   9000 
   9001     private void checkConvertUlong3Double3() {
   9002         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_64, 3, 0xaa642fe0d0180a80l, false, 64);
   9003         try {
   9004             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 3), INPUTSIZE);
   9005             script.forEach_testConvertDouble3Ulong3Double3(inV, out);
   9006             verifyResultsConvertUlong3Double3(inV, out, false);
   9007         } catch (Exception e) {
   9008             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble3Ulong3Double3: " + e.toString());
   9009         }
   9010         try {
   9011             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 3), INPUTSIZE);
   9012             scriptRelaxed.forEach_testConvertDouble3Ulong3Double3(inV, out);
   9013             verifyResultsConvertUlong3Double3(inV, out, true);
   9014         } catch (Exception e) {
   9015             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble3Ulong3Double3: " + e.toString());
   9016         }
   9017     }
   9018 
   9019     private void verifyResultsConvertUlong3Double3(Allocation inV, Allocation out, boolean relaxed) {
   9020         long[] arrayInV = new long[INPUTSIZE * 4];
   9021         inV.copyTo(arrayInV);
   9022         double[] arrayOut = new double[INPUTSIZE * 4];
   9023         out.copyTo(arrayOut);
   9024         for (int i = 0; i < INPUTSIZE; i++) {
   9025             for (int j = 0; j < 3 ; j++) {
   9026                 // Extract the inputs.
   9027                 ArgumentsUlongDouble args = new ArgumentsUlongDouble();
   9028                 args.inV = arrayInV[i * 4 + j];
   9029                 // Figure out what the outputs should have been.
   9030                 Target target = new Target(relaxed);
   9031                 CoreMathVerifier.computeConvert(args, target);
   9032                 // Validate the outputs.
   9033                 boolean valid = true;
   9034                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   9035                     valid = false;
   9036                 }
   9037                 if (!valid) {
   9038                     StringBuilder message = new StringBuilder();
   9039                     message.append("Input inV: ");
   9040                     message.append(String.format("0x%x", args.inV));
   9041                     message.append("\n");
   9042                     message.append("Expected output out: ");
   9043                     message.append(args.out.toString());
   9044                     message.append("\n");
   9045                     message.append("Actual   output out: ");
   9046                     message.append(String.format("%24.8g {%16x} %31a",
   9047                             arrayOut[i * 4 + j], Double.doubleToRawLongBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
   9048                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   9049                         message.append(" FAIL");
   9050                     }
   9051                     message.append("\n");
   9052                     assertTrue("Incorrect output for checkConvertUlong3Double3" +
   9053                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   9054                 }
   9055             }
   9056         }
   9057     }
   9058 
   9059     private void checkConvertUlong4Double4() {
   9060         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_64, 4, 0xaab0f76826739bacl, false, 64);
   9061         try {
   9062             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 4), INPUTSIZE);
   9063             script.forEach_testConvertDouble4Ulong4Double4(inV, out);
   9064             verifyResultsConvertUlong4Double4(inV, out, false);
   9065         } catch (Exception e) {
   9066             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble4Ulong4Double4: " + e.toString());
   9067         }
   9068         try {
   9069             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 4), INPUTSIZE);
   9070             scriptRelaxed.forEach_testConvertDouble4Ulong4Double4(inV, out);
   9071             verifyResultsConvertUlong4Double4(inV, out, true);
   9072         } catch (Exception e) {
   9073             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble4Ulong4Double4: " + e.toString());
   9074         }
   9075     }
   9076 
   9077     private void verifyResultsConvertUlong4Double4(Allocation inV, Allocation out, boolean relaxed) {
   9078         long[] arrayInV = new long[INPUTSIZE * 4];
   9079         inV.copyTo(arrayInV);
   9080         double[] arrayOut = new double[INPUTSIZE * 4];
   9081         out.copyTo(arrayOut);
   9082         for (int i = 0; i < INPUTSIZE; i++) {
   9083             for (int j = 0; j < 4 ; j++) {
   9084                 // Extract the inputs.
   9085                 ArgumentsUlongDouble args = new ArgumentsUlongDouble();
   9086                 args.inV = arrayInV[i * 4 + j];
   9087                 // Figure out what the outputs should have been.
   9088                 Target target = new Target(relaxed);
   9089                 CoreMathVerifier.computeConvert(args, target);
   9090                 // Validate the outputs.
   9091                 boolean valid = true;
   9092                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   9093                     valid = false;
   9094                 }
   9095                 if (!valid) {
   9096                     StringBuilder message = new StringBuilder();
   9097                     message.append("Input inV: ");
   9098                     message.append(String.format("0x%x", args.inV));
   9099                     message.append("\n");
   9100                     message.append("Expected output out: ");
   9101                     message.append(args.out.toString());
   9102                     message.append("\n");
   9103                     message.append("Actual   output out: ");
   9104                     message.append(String.format("%24.8g {%16x} %31a",
   9105                             arrayOut[i * 4 + j], Double.doubleToRawLongBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
   9106                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   9107                         message.append(" FAIL");
   9108                     }
   9109                     message.append("\n");
   9110                     assertTrue("Incorrect output for checkConvertUlong4Double4" +
   9111                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   9112                 }
   9113             }
   9114         }
   9115     }
   9116 
   9117     public class ArgumentsDoubleLong {
   9118         public double inV;
   9119         public long out;
   9120     }
   9121 
   9122     private void checkConvertDouble2Long2() {
   9123         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_64, 2, 0xcbf84dc0430cbe95l, -9.2233720368547747840e+18, 9.2233720368547747840e+18);
   9124         try {
   9125             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 2), INPUTSIZE);
   9126             script.forEach_testConvertLong2Double2Long2(inV, out);
   9127             verifyResultsConvertDouble2Long2(inV, out, false);
   9128         } catch (Exception e) {
   9129             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong2Double2Long2: " + e.toString());
   9130         }
   9131         try {
   9132             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 2), INPUTSIZE);
   9133             scriptRelaxed.forEach_testConvertLong2Double2Long2(inV, out);
   9134             verifyResultsConvertDouble2Long2(inV, out, true);
   9135         } catch (Exception e) {
   9136             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong2Double2Long2: " + e.toString());
   9137         }
   9138     }
   9139 
   9140     private void verifyResultsConvertDouble2Long2(Allocation inV, Allocation out, boolean relaxed) {
   9141         double[] arrayInV = new double[INPUTSIZE * 2];
   9142         inV.copyTo(arrayInV);
   9143         long[] arrayOut = new long[INPUTSIZE * 2];
   9144         out.copyTo(arrayOut);
   9145         for (int i = 0; i < INPUTSIZE; i++) {
   9146             for (int j = 0; j < 2 ; j++) {
   9147                 // Extract the inputs.
   9148                 ArgumentsDoubleLong args = new ArgumentsDoubleLong();
   9149                 args.inV = arrayInV[i * 2 + j];
   9150                 // Figure out what the outputs should have been.
   9151                 CoreMathVerifier.computeConvert(args);
   9152                 // Validate the outputs.
   9153                 boolean valid = true;
   9154                 if (args.out != arrayOut[i * 2 + j]) {
   9155                     valid = false;
   9156                 }
   9157                 if (!valid) {
   9158                     StringBuilder message = new StringBuilder();
   9159                     message.append("Input inV: ");
   9160                     message.append(String.format("%24.8g {%16x} %31a",
   9161                             args.inV, Double.doubleToRawLongBits(args.inV), args.inV));
   9162                     message.append("\n");
   9163                     message.append("Expected output out: ");
   9164                     message.append(String.format("%d", args.out));
   9165                     message.append("\n");
   9166                     message.append("Actual   output out: ");
   9167                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   9168                     if (args.out != arrayOut[i * 2 + j]) {
   9169                         message.append(" FAIL");
   9170                     }
   9171                     message.append("\n");
   9172                     assertTrue("Incorrect output for checkConvertDouble2Long2" +
   9173                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   9174                 }
   9175             }
   9176         }
   9177     }
   9178 
   9179     private void checkConvertDouble3Long3() {
   9180         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_64, 3, 0xcbf85861a2148389l, -9.2233720368547747840e+18, 9.2233720368547747840e+18);
   9181         try {
   9182             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 3), INPUTSIZE);
   9183             script.forEach_testConvertLong3Double3Long3(inV, out);
   9184             verifyResultsConvertDouble3Long3(inV, out, false);
   9185         } catch (Exception e) {
   9186             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong3Double3Long3: " + e.toString());
   9187         }
   9188         try {
   9189             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 3), INPUTSIZE);
   9190             scriptRelaxed.forEach_testConvertLong3Double3Long3(inV, out);
   9191             verifyResultsConvertDouble3Long3(inV, out, true);
   9192         } catch (Exception e) {
   9193             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong3Double3Long3: " + e.toString());
   9194         }
   9195     }
   9196 
   9197     private void verifyResultsConvertDouble3Long3(Allocation inV, Allocation out, boolean relaxed) {
   9198         double[] arrayInV = new double[INPUTSIZE * 4];
   9199         inV.copyTo(arrayInV);
   9200         long[] arrayOut = new long[INPUTSIZE * 4];
   9201         out.copyTo(arrayOut);
   9202         for (int i = 0; i < INPUTSIZE; i++) {
   9203             for (int j = 0; j < 3 ; j++) {
   9204                 // Extract the inputs.
   9205                 ArgumentsDoubleLong args = new ArgumentsDoubleLong();
   9206                 args.inV = arrayInV[i * 4 + j];
   9207                 // Figure out what the outputs should have been.
   9208                 CoreMathVerifier.computeConvert(args);
   9209                 // Validate the outputs.
   9210                 boolean valid = true;
   9211                 if (args.out != arrayOut[i * 4 + j]) {
   9212                     valid = false;
   9213                 }
   9214                 if (!valid) {
   9215                     StringBuilder message = new StringBuilder();
   9216                     message.append("Input inV: ");
   9217                     message.append(String.format("%24.8g {%16x} %31a",
   9218                             args.inV, Double.doubleToRawLongBits(args.inV), args.inV));
   9219                     message.append("\n");
   9220                     message.append("Expected output out: ");
   9221                     message.append(String.format("%d", args.out));
   9222                     message.append("\n");
   9223                     message.append("Actual   output out: ");
   9224                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   9225                     if (args.out != arrayOut[i * 4 + j]) {
   9226                         message.append(" FAIL");
   9227                     }
   9228                     message.append("\n");
   9229                     assertTrue("Incorrect output for checkConvertDouble3Long3" +
   9230                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   9231                 }
   9232             }
   9233         }
   9234     }
   9235 
   9236     private void checkConvertDouble4Long4() {
   9237         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_64, 4, 0xcbf86303011c487dl, -9.2233720368547747840e+18, 9.2233720368547747840e+18);
   9238         try {
   9239             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 4), INPUTSIZE);
   9240             script.forEach_testConvertLong4Double4Long4(inV, out);
   9241             verifyResultsConvertDouble4Long4(inV, out, false);
   9242         } catch (Exception e) {
   9243             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong4Double4Long4: " + e.toString());
   9244         }
   9245         try {
   9246             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 4), INPUTSIZE);
   9247             scriptRelaxed.forEach_testConvertLong4Double4Long4(inV, out);
   9248             verifyResultsConvertDouble4Long4(inV, out, true);
   9249         } catch (Exception e) {
   9250             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong4Double4Long4: " + e.toString());
   9251         }
   9252     }
   9253 
   9254     private void verifyResultsConvertDouble4Long4(Allocation inV, Allocation out, boolean relaxed) {
   9255         double[] arrayInV = new double[INPUTSIZE * 4];
   9256         inV.copyTo(arrayInV);
   9257         long[] arrayOut = new long[INPUTSIZE * 4];
   9258         out.copyTo(arrayOut);
   9259         for (int i = 0; i < INPUTSIZE; i++) {
   9260             for (int j = 0; j < 4 ; j++) {
   9261                 // Extract the inputs.
   9262                 ArgumentsDoubleLong args = new ArgumentsDoubleLong();
   9263                 args.inV = arrayInV[i * 4 + j];
   9264                 // Figure out what the outputs should have been.
   9265                 CoreMathVerifier.computeConvert(args);
   9266                 // Validate the outputs.
   9267                 boolean valid = true;
   9268                 if (args.out != arrayOut[i * 4 + j]) {
   9269                     valid = false;
   9270                 }
   9271                 if (!valid) {
   9272                     StringBuilder message = new StringBuilder();
   9273                     message.append("Input inV: ");
   9274                     message.append(String.format("%24.8g {%16x} %31a",
   9275                             args.inV, Double.doubleToRawLongBits(args.inV), args.inV));
   9276                     message.append("\n");
   9277                     message.append("Expected output out: ");
   9278                     message.append(String.format("%d", args.out));
   9279                     message.append("\n");
   9280                     message.append("Actual   output out: ");
   9281                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   9282                     if (args.out != arrayOut[i * 4 + j]) {
   9283                         message.append(" FAIL");
   9284                     }
   9285                     message.append("\n");
   9286                     assertTrue("Incorrect output for checkConvertDouble4Long4" +
   9287                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   9288                 }
   9289             }
   9290         }
   9291     }
   9292 
   9293     public class ArgumentsLongLong {
   9294         public long inV;
   9295         public long out;
   9296     }
   9297 
   9298     private void checkConvertLong2Long2() {
   9299         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_64, 2, 0xb570c607c81d242al, true, 63);
   9300         try {
   9301             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 2), INPUTSIZE);
   9302             script.forEach_testConvertLong2Long2Long2(inV, out);
   9303             verifyResultsConvertLong2Long2(inV, out, false);
   9304         } catch (Exception e) {
   9305             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong2Long2Long2: " + e.toString());
   9306         }
   9307         try {
   9308             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 2), INPUTSIZE);
   9309             scriptRelaxed.forEach_testConvertLong2Long2Long2(inV, out);
   9310             verifyResultsConvertLong2Long2(inV, out, true);
   9311         } catch (Exception e) {
   9312             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong2Long2Long2: " + e.toString());
   9313         }
   9314     }
   9315 
   9316     private void verifyResultsConvertLong2Long2(Allocation inV, Allocation out, boolean relaxed) {
   9317         long[] arrayInV = new long[INPUTSIZE * 2];
   9318         inV.copyTo(arrayInV);
   9319         long[] arrayOut = new long[INPUTSIZE * 2];
   9320         out.copyTo(arrayOut);
   9321         for (int i = 0; i < INPUTSIZE; i++) {
   9322             for (int j = 0; j < 2 ; j++) {
   9323                 // Extract the inputs.
   9324                 ArgumentsLongLong args = new ArgumentsLongLong();
   9325                 args.inV = arrayInV[i * 2 + j];
   9326                 // Figure out what the outputs should have been.
   9327                 CoreMathVerifier.computeConvert(args);
   9328                 // Validate the outputs.
   9329                 boolean valid = true;
   9330                 if (args.out != arrayOut[i * 2 + j]) {
   9331                     valid = false;
   9332                 }
   9333                 if (!valid) {
   9334                     StringBuilder message = new StringBuilder();
   9335                     message.append("Input inV: ");
   9336                     message.append(String.format("%d", args.inV));
   9337                     message.append("\n");
   9338                     message.append("Expected output out: ");
   9339                     message.append(String.format("%d", args.out));
   9340                     message.append("\n");
   9341                     message.append("Actual   output out: ");
   9342                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   9343                     if (args.out != arrayOut[i * 2 + j]) {
   9344                         message.append(" FAIL");
   9345                     }
   9346                     message.append("\n");
   9347                     assertTrue("Incorrect output for checkConvertLong2Long2" +
   9348                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   9349                 }
   9350             }
   9351         }
   9352     }
   9353 
   9354     private void checkConvertLong3Long3() {
   9355         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_64, 3, 0xb570d0a92724e91el, true, 63);
   9356         try {
   9357             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 3), INPUTSIZE);
   9358             script.forEach_testConvertLong3Long3Long3(inV, out);
   9359             verifyResultsConvertLong3Long3(inV, out, false);
   9360         } catch (Exception e) {
   9361             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong3Long3Long3: " + e.toString());
   9362         }
   9363         try {
   9364             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 3), INPUTSIZE);
   9365             scriptRelaxed.forEach_testConvertLong3Long3Long3(inV, out);
   9366             verifyResultsConvertLong3Long3(inV, out, true);
   9367         } catch (Exception e) {
   9368             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong3Long3Long3: " + e.toString());
   9369         }
   9370     }
   9371 
   9372     private void verifyResultsConvertLong3Long3(Allocation inV, Allocation out, boolean relaxed) {
   9373         long[] arrayInV = new long[INPUTSIZE * 4];
   9374         inV.copyTo(arrayInV);
   9375         long[] arrayOut = new long[INPUTSIZE * 4];
   9376         out.copyTo(arrayOut);
   9377         for (int i = 0; i < INPUTSIZE; i++) {
   9378             for (int j = 0; j < 3 ; j++) {
   9379                 // Extract the inputs.
   9380                 ArgumentsLongLong args = new ArgumentsLongLong();
   9381                 args.inV = arrayInV[i * 4 + j];
   9382                 // Figure out what the outputs should have been.
   9383                 CoreMathVerifier.computeConvert(args);
   9384                 // Validate the outputs.
   9385                 boolean valid = true;
   9386                 if (args.out != arrayOut[i * 4 + j]) {
   9387                     valid = false;
   9388                 }
   9389                 if (!valid) {
   9390                     StringBuilder message = new StringBuilder();
   9391                     message.append("Input inV: ");
   9392                     message.append(String.format("%d", args.inV));
   9393                     message.append("\n");
   9394                     message.append("Expected output out: ");
   9395                     message.append(String.format("%d", args.out));
   9396                     message.append("\n");
   9397                     message.append("Actual   output out: ");
   9398                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   9399                     if (args.out != arrayOut[i * 4 + j]) {
   9400                         message.append(" FAIL");
   9401                     }
   9402                     message.append("\n");
   9403                     assertTrue("Incorrect output for checkConvertLong3Long3" +
   9404                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   9405                 }
   9406             }
   9407         }
   9408     }
   9409 
   9410     private void checkConvertLong4Long4() {
   9411         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_64, 4, 0xb570db4a862cae12l, true, 63);
   9412         try {
   9413             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 4), INPUTSIZE);
   9414             script.forEach_testConvertLong4Long4Long4(inV, out);
   9415             verifyResultsConvertLong4Long4(inV, out, false);
   9416         } catch (Exception e) {
   9417             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong4Long4Long4: " + e.toString());
   9418         }
   9419         try {
   9420             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 4), INPUTSIZE);
   9421             scriptRelaxed.forEach_testConvertLong4Long4Long4(inV, out);
   9422             verifyResultsConvertLong4Long4(inV, out, true);
   9423         } catch (Exception e) {
   9424             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong4Long4Long4: " + e.toString());
   9425         }
   9426     }
   9427 
   9428     private void verifyResultsConvertLong4Long4(Allocation inV, Allocation out, boolean relaxed) {
   9429         long[] arrayInV = new long[INPUTSIZE * 4];
   9430         inV.copyTo(arrayInV);
   9431         long[] arrayOut = new long[INPUTSIZE * 4];
   9432         out.copyTo(arrayOut);
   9433         for (int i = 0; i < INPUTSIZE; i++) {
   9434             for (int j = 0; j < 4 ; j++) {
   9435                 // Extract the inputs.
   9436                 ArgumentsLongLong args = new ArgumentsLongLong();
   9437                 args.inV = arrayInV[i * 4 + j];
   9438                 // Figure out what the outputs should have been.
   9439                 CoreMathVerifier.computeConvert(args);
   9440                 // Validate the outputs.
   9441                 boolean valid = true;
   9442                 if (args.out != arrayOut[i * 4 + j]) {
   9443                     valid = false;
   9444                 }
   9445                 if (!valid) {
   9446                     StringBuilder message = new StringBuilder();
   9447                     message.append("Input inV: ");
   9448                     message.append(String.format("%d", args.inV));
   9449                     message.append("\n");
   9450                     message.append("Expected output out: ");
   9451                     message.append(String.format("%d", args.out));
   9452                     message.append("\n");
   9453                     message.append("Actual   output out: ");
   9454                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   9455                     if (args.out != arrayOut[i * 4 + j]) {
   9456                         message.append(" FAIL");
   9457                     }
   9458                     message.append("\n");
   9459                     assertTrue("Incorrect output for checkConvertLong4Long4" +
   9460                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   9461                 }
   9462             }
   9463         }
   9464     }
   9465 
   9466     public class ArgumentsUlongLong {
   9467         public long inV;
   9468         public long out;
   9469     }
   9470 
   9471     private void checkConvertUlong2Long2() {
   9472         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_64, 2, 0x5cfe7f555a9f30abl, false, 63);
   9473         try {
   9474             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 2), INPUTSIZE);
   9475             script.forEach_testConvertLong2Ulong2Long2(inV, out);
   9476             verifyResultsConvertUlong2Long2(inV, out, false);
   9477         } catch (Exception e) {
   9478             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong2Ulong2Long2: " + e.toString());
   9479         }
   9480         try {
   9481             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 2), INPUTSIZE);
   9482             scriptRelaxed.forEach_testConvertLong2Ulong2Long2(inV, out);
   9483             verifyResultsConvertUlong2Long2(inV, out, true);
   9484         } catch (Exception e) {
   9485             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong2Ulong2Long2: " + e.toString());
   9486         }
   9487     }
   9488 
   9489     private void verifyResultsConvertUlong2Long2(Allocation inV, Allocation out, boolean relaxed) {
   9490         long[] arrayInV = new long[INPUTSIZE * 2];
   9491         inV.copyTo(arrayInV);
   9492         long[] arrayOut = new long[INPUTSIZE * 2];
   9493         out.copyTo(arrayOut);
   9494         for (int i = 0; i < INPUTSIZE; i++) {
   9495             for (int j = 0; j < 2 ; j++) {
   9496                 // Extract the inputs.
   9497                 ArgumentsUlongLong args = new ArgumentsUlongLong();
   9498                 args.inV = arrayInV[i * 2 + j];
   9499                 // Figure out what the outputs should have been.
   9500                 CoreMathVerifier.computeConvert(args);
   9501                 // Validate the outputs.
   9502                 boolean valid = true;
   9503                 if (args.out != arrayOut[i * 2 + j]) {
   9504                     valid = false;
   9505                 }
   9506                 if (!valid) {
   9507                     StringBuilder message = new StringBuilder();
   9508                     message.append("Input inV: ");
   9509                     message.append(String.format("0x%x", args.inV));
   9510                     message.append("\n");
   9511                     message.append("Expected output out: ");
   9512                     message.append(String.format("%d", args.out));
   9513                     message.append("\n");
   9514                     message.append("Actual   output out: ");
   9515                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   9516                     if (args.out != arrayOut[i * 2 + j]) {
   9517                         message.append(" FAIL");
   9518                     }
   9519                     message.append("\n");
   9520                     assertTrue("Incorrect output for checkConvertUlong2Long2" +
   9521                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   9522                 }
   9523             }
   9524         }
   9525     }
   9526 
   9527     private void checkConvertUlong3Long3() {
   9528         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_64, 3, 0x5cfe89f6b9a6f59fl, false, 63);
   9529         try {
   9530             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 3), INPUTSIZE);
   9531             script.forEach_testConvertLong3Ulong3Long3(inV, out);
   9532             verifyResultsConvertUlong3Long3(inV, out, false);
   9533         } catch (Exception e) {
   9534             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong3Ulong3Long3: " + e.toString());
   9535         }
   9536         try {
   9537             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 3), INPUTSIZE);
   9538             scriptRelaxed.forEach_testConvertLong3Ulong3Long3(inV, out);
   9539             verifyResultsConvertUlong3Long3(inV, out, true);
   9540         } catch (Exception e) {
   9541             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong3Ulong3Long3: " + e.toString());
   9542         }
   9543     }
   9544 
   9545     private void verifyResultsConvertUlong3Long3(Allocation inV, Allocation out, boolean relaxed) {
   9546         long[] arrayInV = new long[INPUTSIZE * 4];
   9547         inV.copyTo(arrayInV);
   9548         long[] arrayOut = new long[INPUTSIZE * 4];
   9549         out.copyTo(arrayOut);
   9550         for (int i = 0; i < INPUTSIZE; i++) {
   9551             for (int j = 0; j < 3 ; j++) {
   9552                 // Extract the inputs.
   9553                 ArgumentsUlongLong args = new ArgumentsUlongLong();
   9554                 args.inV = arrayInV[i * 4 + j];
   9555                 // Figure out what the outputs should have been.
   9556                 CoreMathVerifier.computeConvert(args);
   9557                 // Validate the outputs.
   9558                 boolean valid = true;
   9559                 if (args.out != arrayOut[i * 4 + j]) {
   9560                     valid = false;
   9561                 }
   9562                 if (!valid) {
   9563                     StringBuilder message = new StringBuilder();
   9564                     message.append("Input inV: ");
   9565                     message.append(String.format("0x%x", args.inV));
   9566                     message.append("\n");
   9567                     message.append("Expected output out: ");
   9568                     message.append(String.format("%d", args.out));
   9569                     message.append("\n");
   9570                     message.append("Actual   output out: ");
   9571                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   9572                     if (args.out != arrayOut[i * 4 + j]) {
   9573                         message.append(" FAIL");
   9574                     }
   9575                     message.append("\n");
   9576                     assertTrue("Incorrect output for checkConvertUlong3Long3" +
   9577                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   9578                 }
   9579             }
   9580         }
   9581     }
   9582 
   9583     private void checkConvertUlong4Long4() {
   9584         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_64, 4, 0x5cfe949818aeba93l, false, 63);
   9585         try {
   9586             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 4), INPUTSIZE);
   9587             script.forEach_testConvertLong4Ulong4Long4(inV, out);
   9588             verifyResultsConvertUlong4Long4(inV, out, false);
   9589         } catch (Exception e) {
   9590             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong4Ulong4Long4: " + e.toString());
   9591         }
   9592         try {
   9593             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 4), INPUTSIZE);
   9594             scriptRelaxed.forEach_testConvertLong4Ulong4Long4(inV, out);
   9595             verifyResultsConvertUlong4Long4(inV, out, true);
   9596         } catch (Exception e) {
   9597             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong4Ulong4Long4: " + e.toString());
   9598         }
   9599     }
   9600 
   9601     private void verifyResultsConvertUlong4Long4(Allocation inV, Allocation out, boolean relaxed) {
   9602         long[] arrayInV = new long[INPUTSIZE * 4];
   9603         inV.copyTo(arrayInV);
   9604         long[] arrayOut = new long[INPUTSIZE * 4];
   9605         out.copyTo(arrayOut);
   9606         for (int i = 0; i < INPUTSIZE; i++) {
   9607             for (int j = 0; j < 4 ; j++) {
   9608                 // Extract the inputs.
   9609                 ArgumentsUlongLong args = new ArgumentsUlongLong();
   9610                 args.inV = arrayInV[i * 4 + j];
   9611                 // Figure out what the outputs should have been.
   9612                 CoreMathVerifier.computeConvert(args);
   9613                 // Validate the outputs.
   9614                 boolean valid = true;
   9615                 if (args.out != arrayOut[i * 4 + j]) {
   9616                     valid = false;
   9617                 }
   9618                 if (!valid) {
   9619                     StringBuilder message = new StringBuilder();
   9620                     message.append("Input inV: ");
   9621                     message.append(String.format("0x%x", args.inV));
   9622                     message.append("\n");
   9623                     message.append("Expected output out: ");
   9624                     message.append(String.format("%d", args.out));
   9625                     message.append("\n");
   9626                     message.append("Actual   output out: ");
   9627                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   9628                     if (args.out != arrayOut[i * 4 + j]) {
   9629                         message.append(" FAIL");
   9630                     }
   9631                     message.append("\n");
   9632                     assertTrue("Incorrect output for checkConvertUlong4Long4" +
   9633                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   9634                 }
   9635             }
   9636         }
   9637     }
   9638 
   9639     public class ArgumentsDoubleUlong {
   9640         public double inV;
   9641         public long out;
   9642     }
   9643 
   9644     private void checkConvertDouble2Ulong2() {
   9645         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_64, 2, 0x42b56e3b7e12ff5el, 0.0000000000000000000e+00, 1.8446744073709549568e+19);
   9646         try {
   9647             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 2), INPUTSIZE);
   9648             script.forEach_testConvertUlong2Double2Ulong2(inV, out);
   9649             verifyResultsConvertDouble2Ulong2(inV, out, false);
   9650         } catch (Exception e) {
   9651             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong2Double2Ulong2: " + e.toString());
   9652         }
   9653         try {
   9654             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 2), INPUTSIZE);
   9655             scriptRelaxed.forEach_testConvertUlong2Double2Ulong2(inV, out);
   9656             verifyResultsConvertDouble2Ulong2(inV, out, true);
   9657         } catch (Exception e) {
   9658             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong2Double2Ulong2: " + e.toString());
   9659         }
   9660     }
   9661 
   9662     private void verifyResultsConvertDouble2Ulong2(Allocation inV, Allocation out, boolean relaxed) {
   9663         double[] arrayInV = new double[INPUTSIZE * 2];
   9664         inV.copyTo(arrayInV);
   9665         long[] arrayOut = new long[INPUTSIZE * 2];
   9666         out.copyTo(arrayOut);
   9667         for (int i = 0; i < INPUTSIZE; i++) {
   9668             for (int j = 0; j < 2 ; j++) {
   9669                 // Extract the inputs.
   9670                 ArgumentsDoubleUlong args = new ArgumentsDoubleUlong();
   9671                 args.inV = arrayInV[i * 2 + j];
   9672                 // Figure out what the outputs should have been.
   9673                 CoreMathVerifier.computeConvert(args);
   9674                 // Validate the outputs.
   9675                 boolean valid = true;
   9676                 if (args.out != arrayOut[i * 2 + j]) {
   9677                     valid = false;
   9678                 }
   9679                 if (!valid) {
   9680                     StringBuilder message = new StringBuilder();
   9681                     message.append("Input inV: ");
   9682                     message.append(String.format("%24.8g {%16x} %31a",
   9683                             args.inV, Double.doubleToRawLongBits(args.inV), args.inV));
   9684                     message.append("\n");
   9685                     message.append("Expected output out: ");
   9686                     message.append(String.format("0x%x", args.out));
   9687                     message.append("\n");
   9688                     message.append("Actual   output out: ");
   9689                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   9690                     if (args.out != arrayOut[i * 2 + j]) {
   9691                         message.append(" FAIL");
   9692                     }
   9693                     message.append("\n");
   9694                     assertTrue("Incorrect output for checkConvertDouble2Ulong2" +
   9695                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   9696                 }
   9697             }
   9698         }
   9699     }
   9700 
   9701     private void checkConvertDouble3Ulong3() {
   9702         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_64, 3, 0x42b73756742e203cl, 0.0000000000000000000e+00, 1.8446744073709549568e+19);
   9703         try {
   9704             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 3), INPUTSIZE);
   9705             script.forEach_testConvertUlong3Double3Ulong3(inV, out);
   9706             verifyResultsConvertDouble3Ulong3(inV, out, false);
   9707         } catch (Exception e) {
   9708             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong3Double3Ulong3: " + e.toString());
   9709         }
   9710         try {
   9711             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 3), INPUTSIZE);
   9712             scriptRelaxed.forEach_testConvertUlong3Double3Ulong3(inV, out);
   9713             verifyResultsConvertDouble3Ulong3(inV, out, true);
   9714         } catch (Exception e) {
   9715             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong3Double3Ulong3: " + e.toString());
   9716         }
   9717     }
   9718 
   9719     private void verifyResultsConvertDouble3Ulong3(Allocation inV, Allocation out, boolean relaxed) {
   9720         double[] arrayInV = new double[INPUTSIZE * 4];
   9721         inV.copyTo(arrayInV);
   9722         long[] arrayOut = new long[INPUTSIZE * 4];
   9723         out.copyTo(arrayOut);
   9724         for (int i = 0; i < INPUTSIZE; i++) {
   9725             for (int j = 0; j < 3 ; j++) {
   9726                 // Extract the inputs.
   9727                 ArgumentsDoubleUlong args = new ArgumentsDoubleUlong();
   9728                 args.inV = arrayInV[i * 4 + j];
   9729                 // Figure out what the outputs should have been.
   9730                 CoreMathVerifier.computeConvert(args);
   9731                 // Validate the outputs.
   9732                 boolean valid = true;
   9733                 if (args.out != arrayOut[i * 4 + j]) {
   9734                     valid = false;
   9735                 }
   9736                 if (!valid) {
   9737                     StringBuilder message = new StringBuilder();
   9738                     message.append("Input inV: ");
   9739                     message.append(String.format("%24.8g {%16x} %31a",
   9740                             args.inV, Double.doubleToRawLongBits(args.inV), args.inV));
   9741                     message.append("\n");
   9742                     message.append("Expected output out: ");
   9743                     message.append(String.format("0x%x", args.out));
   9744                     message.append("\n");
   9745                     message.append("Actual   output out: ");
   9746                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   9747                     if (args.out != arrayOut[i * 4 + j]) {
   9748                         message.append(" FAIL");
   9749                     }
   9750                     message.append("\n");
   9751                     assertTrue("Incorrect output for checkConvertDouble3Ulong3" +
   9752                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   9753                 }
   9754             }
   9755         }
   9756     }
   9757 
   9758     private void checkConvertDouble4Ulong4() {
   9759         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_64, 4, 0x42b900716a49411al, 0.0000000000000000000e+00, 1.8446744073709549568e+19);
   9760         try {
   9761             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 4), INPUTSIZE);
   9762             script.forEach_testConvertUlong4Double4Ulong4(inV, out);
   9763             verifyResultsConvertDouble4Ulong4(inV, out, false);
   9764         } catch (Exception e) {
   9765             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong4Double4Ulong4: " + e.toString());
   9766         }
   9767         try {
   9768             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 4), INPUTSIZE);
   9769             scriptRelaxed.forEach_testConvertUlong4Double4Ulong4(inV, out);
   9770             verifyResultsConvertDouble4Ulong4(inV, out, true);
   9771         } catch (Exception e) {
   9772             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong4Double4Ulong4: " + e.toString());
   9773         }
   9774     }
   9775 
   9776     private void verifyResultsConvertDouble4Ulong4(Allocation inV, Allocation out, boolean relaxed) {
   9777         double[] arrayInV = new double[INPUTSIZE * 4];
   9778         inV.copyTo(arrayInV);
   9779         long[] arrayOut = new long[INPUTSIZE * 4];
   9780         out.copyTo(arrayOut);
   9781         for (int i = 0; i < INPUTSIZE; i++) {
   9782             for (int j = 0; j < 4 ; j++) {
   9783                 // Extract the inputs.
   9784                 ArgumentsDoubleUlong args = new ArgumentsDoubleUlong();
   9785                 args.inV = arrayInV[i * 4 + j];
   9786                 // Figure out what the outputs should have been.
   9787                 CoreMathVerifier.computeConvert(args);
   9788                 // Validate the outputs.
   9789                 boolean valid = true;
   9790                 if (args.out != arrayOut[i * 4 + j]) {
   9791                     valid = false;
   9792                 }
   9793                 if (!valid) {
   9794                     StringBuilder message = new StringBuilder();
   9795                     message.append("Input inV: ");
   9796                     message.append(String.format("%24.8g {%16x} %31a",
   9797                             args.inV, Double.doubleToRawLongBits(args.inV), args.inV));
   9798                     message.append("\n");
   9799                     message.append("Expected output out: ");
   9800                     message.append(String.format("0x%x", args.out));
   9801                     message.append("\n");
   9802                     message.append("Actual   output out: ");
   9803                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   9804                     if (args.out != arrayOut[i * 4 + j]) {
   9805                         message.append(" FAIL");
   9806                     }
   9807                     message.append("\n");
   9808                     assertTrue("Incorrect output for checkConvertDouble4Ulong4" +
   9809                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   9810                 }
   9811             }
   9812         }
   9813     }
   9814 
   9815     public class ArgumentsLongUlong {
   9816         public long inV;
   9817         public long out;
   9818     }
   9819 
   9820     private void checkConvertLong2Ulong2() {
   9821         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_64, 2, 0x79f1a23ed7d40f65l, false, 63);
   9822         try {
   9823             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 2), INPUTSIZE);
   9824             script.forEach_testConvertUlong2Long2Ulong2(inV, out);
   9825             verifyResultsConvertLong2Ulong2(inV, out, false);
   9826         } catch (Exception e) {
   9827             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong2Long2Ulong2: " + e.toString());
   9828         }
   9829         try {
   9830             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 2), INPUTSIZE);
   9831             scriptRelaxed.forEach_testConvertUlong2Long2Ulong2(inV, out);
   9832             verifyResultsConvertLong2Ulong2(inV, out, true);
   9833         } catch (Exception e) {
   9834             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong2Long2Ulong2: " + e.toString());
   9835         }
   9836     }
   9837 
   9838     private void verifyResultsConvertLong2Ulong2(Allocation inV, Allocation out, boolean relaxed) {
   9839         long[] arrayInV = new long[INPUTSIZE * 2];
   9840         inV.copyTo(arrayInV);
   9841         long[] arrayOut = new long[INPUTSIZE * 2];
   9842         out.copyTo(arrayOut);
   9843         for (int i = 0; i < INPUTSIZE; i++) {
   9844             for (int j = 0; j < 2 ; j++) {
   9845                 // Extract the inputs.
   9846                 ArgumentsLongUlong args = new ArgumentsLongUlong();
   9847                 args.inV = arrayInV[i * 2 + j];
   9848                 // Figure out what the outputs should have been.
   9849                 CoreMathVerifier.computeConvert(args);
   9850                 // Validate the outputs.
   9851                 boolean valid = true;
   9852                 if (args.out != arrayOut[i * 2 + j]) {
   9853                     valid = false;
   9854                 }
   9855                 if (!valid) {
   9856                     StringBuilder message = new StringBuilder();
   9857                     message.append("Input inV: ");
   9858                     message.append(String.format("%d", args.inV));
   9859                     message.append("\n");
   9860                     message.append("Expected output out: ");
   9861                     message.append(String.format("0x%x", args.out));
   9862                     message.append("\n");
   9863                     message.append("Actual   output out: ");
   9864                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   9865                     if (args.out != arrayOut[i * 2 + j]) {
   9866                         message.append(" FAIL");
   9867                     }
   9868                     message.append("\n");
   9869                     assertTrue("Incorrect output for checkConvertLong2Ulong2" +
   9870                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   9871                 }
   9872             }
   9873         }
   9874     }
   9875 
   9876     private void checkConvertLong3Ulong3() {
   9877         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_64, 3, 0x79f36b59cdef3043l, false, 63);
   9878         try {
   9879             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 3), INPUTSIZE);
   9880             script.forEach_testConvertUlong3Long3Ulong3(inV, out);
   9881             verifyResultsConvertLong3Ulong3(inV, out, false);
   9882         } catch (Exception e) {
   9883             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong3Long3Ulong3: " + e.toString());
   9884         }
   9885         try {
   9886             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 3), INPUTSIZE);
   9887             scriptRelaxed.forEach_testConvertUlong3Long3Ulong3(inV, out);
   9888             verifyResultsConvertLong3Ulong3(inV, out, true);
   9889         } catch (Exception e) {
   9890             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong3Long3Ulong3: " + e.toString());
   9891         }
   9892     }
   9893 
   9894     private void verifyResultsConvertLong3Ulong3(Allocation inV, Allocation out, boolean relaxed) {
   9895         long[] arrayInV = new long[INPUTSIZE * 4];
   9896         inV.copyTo(arrayInV);
   9897         long[] arrayOut = new long[INPUTSIZE * 4];
   9898         out.copyTo(arrayOut);
   9899         for (int i = 0; i < INPUTSIZE; i++) {
   9900             for (int j = 0; j < 3 ; j++) {
   9901                 // Extract the inputs.
   9902                 ArgumentsLongUlong args = new ArgumentsLongUlong();
   9903                 args.inV = arrayInV[i * 4 + j];
   9904                 // Figure out what the outputs should have been.
   9905                 CoreMathVerifier.computeConvert(args);
   9906                 // Validate the outputs.
   9907                 boolean valid = true;
   9908                 if (args.out != arrayOut[i * 4 + j]) {
   9909                     valid = false;
   9910                 }
   9911                 if (!valid) {
   9912                     StringBuilder message = new StringBuilder();
   9913                     message.append("Input inV: ");
   9914                     message.append(String.format("%d", args.inV));
   9915                     message.append("\n");
   9916                     message.append("Expected output out: ");
   9917                     message.append(String.format("0x%x", args.out));
   9918                     message.append("\n");
   9919                     message.append("Actual   output out: ");
   9920                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   9921                     if (args.out != arrayOut[i * 4 + j]) {
   9922                         message.append(" FAIL");
   9923                     }
   9924                     message.append("\n");
   9925                     assertTrue("Incorrect output for checkConvertLong3Ulong3" +
   9926                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   9927                 }
   9928             }
   9929         }
   9930     }
   9931 
   9932     private void checkConvertLong4Ulong4() {
   9933         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_64, 4, 0x79f53474c40a5121l, false, 63);
   9934         try {
   9935             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 4), INPUTSIZE);
   9936             script.forEach_testConvertUlong4Long4Ulong4(inV, out);
   9937             verifyResultsConvertLong4Ulong4(inV, out, false);
   9938         } catch (Exception e) {
   9939             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong4Long4Ulong4: " + e.toString());
   9940         }
   9941         try {
   9942             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 4), INPUTSIZE);
   9943             scriptRelaxed.forEach_testConvertUlong4Long4Ulong4(inV, out);
   9944             verifyResultsConvertLong4Ulong4(inV, out, true);
   9945         } catch (Exception e) {
   9946             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong4Long4Ulong4: " + e.toString());
   9947         }
   9948     }
   9949 
   9950     private void verifyResultsConvertLong4Ulong4(Allocation inV, Allocation out, boolean relaxed) {
   9951         long[] arrayInV = new long[INPUTSIZE * 4];
   9952         inV.copyTo(arrayInV);
   9953         long[] arrayOut = new long[INPUTSIZE * 4];
   9954         out.copyTo(arrayOut);
   9955         for (int i = 0; i < INPUTSIZE; i++) {
   9956             for (int j = 0; j < 4 ; j++) {
   9957                 // Extract the inputs.
   9958                 ArgumentsLongUlong args = new ArgumentsLongUlong();
   9959                 args.inV = arrayInV[i * 4 + j];
   9960                 // Figure out what the outputs should have been.
   9961                 CoreMathVerifier.computeConvert(args);
   9962                 // Validate the outputs.
   9963                 boolean valid = true;
   9964                 if (args.out != arrayOut[i * 4 + j]) {
   9965                     valid = false;
   9966                 }
   9967                 if (!valid) {
   9968                     StringBuilder message = new StringBuilder();
   9969                     message.append("Input inV: ");
   9970                     message.append(String.format("%d", args.inV));
   9971                     message.append("\n");
   9972                     message.append("Expected output out: ");
   9973                     message.append(String.format("0x%x", args.out));
   9974                     message.append("\n");
   9975                     message.append("Actual   output out: ");
   9976                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   9977                     if (args.out != arrayOut[i * 4 + j]) {
   9978                         message.append(" FAIL");
   9979                     }
   9980                     message.append("\n");
   9981                     assertTrue("Incorrect output for checkConvertLong4Ulong4" +
   9982                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   9983                 }
   9984             }
   9985         }
   9986     }
   9987 
   9988     public class ArgumentsUlongUlong {
   9989         public long inV;
   9990         public long out;
   9991     }
   9992 
   9993     private void checkConvertUlong2Ulong2() {
   9994         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_64, 2, 0x9ebfc24673ac2910l, false, 64);
   9995         try {
   9996             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 2), INPUTSIZE);
   9997             script.forEach_testConvertUlong2Ulong2Ulong2(inV, out);
   9998             verifyResultsConvertUlong2Ulong2(inV, out, false);
   9999         } catch (Exception e) {
   10000             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong2Ulong2Ulong2: " + e.toString());
   10001         }
   10002         try {
   10003             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 2), INPUTSIZE);
   10004             scriptRelaxed.forEach_testConvertUlong2Ulong2Ulong2(inV, out);
   10005             verifyResultsConvertUlong2Ulong2(inV, out, true);
   10006         } catch (Exception e) {
   10007             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong2Ulong2Ulong2: " + e.toString());
   10008         }
   10009     }
   10010 
   10011     private void verifyResultsConvertUlong2Ulong2(Allocation inV, Allocation out, boolean relaxed) {
   10012         long[] arrayInV = new long[INPUTSIZE * 2];
   10013         inV.copyTo(arrayInV);
   10014         long[] arrayOut = new long[INPUTSIZE * 2];
   10015         out.copyTo(arrayOut);
   10016         for (int i = 0; i < INPUTSIZE; i++) {
   10017             for (int j = 0; j < 2 ; j++) {
   10018                 // Extract the inputs.
   10019                 ArgumentsUlongUlong args = new ArgumentsUlongUlong();
   10020                 args.inV = arrayInV[i * 2 + j];
   10021                 // Figure out what the outputs should have been.
   10022                 CoreMathVerifier.computeConvert(args);
   10023                 // Validate the outputs.
   10024                 boolean valid = true;
   10025                 if (args.out != arrayOut[i * 2 + j]) {
   10026                     valid = false;
   10027                 }
   10028                 if (!valid) {
   10029                     StringBuilder message = new StringBuilder();
   10030                     message.append("Input inV: ");
   10031                     message.append(String.format("0x%x", args.inV));
   10032                     message.append("\n");
   10033                     message.append("Expected output out: ");
   10034                     message.append(String.format("0x%x", args.out));
   10035                     message.append("\n");
   10036                     message.append("Actual   output out: ");
   10037                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   10038                     if (args.out != arrayOut[i * 2 + j]) {
   10039                         message.append(" FAIL");
   10040                     }
   10041                     message.append("\n");
   10042                     assertTrue("Incorrect output for checkConvertUlong2Ulong2" +
   10043                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   10044                 }
   10045             }
   10046         }
   10047     }
   10048 
   10049     private void checkConvertUlong3Ulong3() {
   10050         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_64, 3, 0x9ec18b6169c749eel, false, 64);
   10051         try {
   10052             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 3), INPUTSIZE);
   10053             script.forEach_testConvertUlong3Ulong3Ulong3(inV, out);
   10054             verifyResultsConvertUlong3Ulong3(inV, out, false);
   10055         } catch (Exception e) {
   10056             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong3Ulong3Ulong3: " + e.toString());
   10057         }
   10058         try {
   10059             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 3), INPUTSIZE);
   10060             scriptRelaxed.forEach_testConvertUlong3Ulong3Ulong3(inV, out);
   10061             verifyResultsConvertUlong3Ulong3(inV, out, true);
   10062         } catch (Exception e) {
   10063             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong3Ulong3Ulong3: " + e.toString());
   10064         }
   10065     }
   10066 
   10067     private void verifyResultsConvertUlong3Ulong3(Allocation inV, Allocation out, boolean relaxed) {
   10068         long[] arrayInV = new long[INPUTSIZE * 4];
   10069         inV.copyTo(arrayInV);
   10070         long[] arrayOut = new long[INPUTSIZE * 4];
   10071         out.copyTo(arrayOut);
   10072         for (int i = 0; i < INPUTSIZE; i++) {
   10073             for (int j = 0; j < 3 ; j++) {
   10074                 // Extract the inputs.
   10075                 ArgumentsUlongUlong args = new ArgumentsUlongUlong();
   10076                 args.inV = arrayInV[i * 4 + j];
   10077                 // Figure out what the outputs should have been.
   10078                 CoreMathVerifier.computeConvert(args);
   10079                 // Validate the outputs.
   10080                 boolean valid = true;
   10081                 if (args.out != arrayOut[i * 4 + j]) {
   10082                     valid = false;
   10083                 }
   10084                 if (!valid) {
   10085                     StringBuilder message = new StringBuilder();
   10086                     message.append("Input inV: ");
   10087                     message.append(String.format("0x%x", args.inV));
   10088                     message.append("\n");
   10089                     message.append("Expected output out: ");
   10090                     message.append(String.format("0x%x", args.out));
   10091                     message.append("\n");
   10092                     message.append("Actual   output out: ");
   10093                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   10094                     if (args.out != arrayOut[i * 4 + j]) {
   10095                         message.append(" FAIL");
   10096                     }
   10097                     message.append("\n");
   10098                     assertTrue("Incorrect output for checkConvertUlong3Ulong3" +
   10099                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   10100                 }
   10101             }
   10102         }
   10103     }
   10104 
   10105     private void checkConvertUlong4Ulong4() {
   10106         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_64, 4, 0x9ec3547c5fe26accl, false, 64);
   10107         try {
   10108             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 4), INPUTSIZE);
   10109             script.forEach_testConvertUlong4Ulong4Ulong4(inV, out);
   10110             verifyResultsConvertUlong4Ulong4(inV, out, false);
   10111         } catch (Exception e) {
   10112             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong4Ulong4Ulong4: " + e.toString());
   10113         }
   10114         try {
   10115             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 4), INPUTSIZE);
   10116             scriptRelaxed.forEach_testConvertUlong4Ulong4Ulong4(inV, out);
   10117             verifyResultsConvertUlong4Ulong4(inV, out, true);
   10118         } catch (Exception e) {
   10119             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong4Ulong4Ulong4: " + e.toString());
   10120         }
   10121     }
   10122 
   10123     private void verifyResultsConvertUlong4Ulong4(Allocation inV, Allocation out, boolean relaxed) {
   10124         long[] arrayInV = new long[INPUTSIZE * 4];
   10125         inV.copyTo(arrayInV);
   10126         long[] arrayOut = new long[INPUTSIZE * 4];
   10127         out.copyTo(arrayOut);
   10128         for (int i = 0; i < INPUTSIZE; i++) {
   10129             for (int j = 0; j < 4 ; j++) {
   10130                 // Extract the inputs.
   10131                 ArgumentsUlongUlong args = new ArgumentsUlongUlong();
   10132                 args.inV = arrayInV[i * 4 + j];
   10133                 // Figure out what the outputs should have been.
   10134                 CoreMathVerifier.computeConvert(args);
   10135                 // Validate the outputs.
   10136                 boolean valid = true;
   10137                 if (args.out != arrayOut[i * 4 + j]) {
   10138                     valid = false;
   10139                 }
   10140                 if (!valid) {
   10141                     StringBuilder message = new StringBuilder();
   10142                     message.append("Input inV: ");
   10143                     message.append(String.format("0x%x", args.inV));
   10144                     message.append("\n");
   10145                     message.append("Expected output out: ");
   10146                     message.append(String.format("0x%x", args.out));
   10147                     message.append("\n");
   10148                     message.append("Actual   output out: ");
   10149                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   10150                     if (args.out != arrayOut[i * 4 + j]) {
   10151                         message.append(" FAIL");
   10152                     }
   10153                     message.append("\n");
   10154                     assertTrue("Incorrect output for checkConvertUlong4Ulong4" +
   10155                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   10156                 }
   10157             }
   10158         }
   10159     }
   10160 
   10161     public class ArgumentsDoubleFloat {
   10162         public double inV;
   10163         public Target.Floaty out;
   10164     }
   10165 
   10166     private void checkConvertDouble2Float2() {
   10167         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_64, 2, 0x42b4cec67d6d9a2dl, -1.6163412428744576259e+38, 1.6163412428744576259e+38);
   10168         try {
   10169             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
   10170             script.forEach_testConvertFloat2Double2Float2(inV, out);
   10171             verifyResultsConvertDouble2Float2(inV, out, false);
   10172         } catch (Exception e) {
   10173             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat2Double2Float2: " + e.toString());
   10174         }
   10175         try {
   10176             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
   10177             scriptRelaxed.forEach_testConvertFloat2Double2Float2(inV, out);
   10178             verifyResultsConvertDouble2Float2(inV, out, true);
   10179         } catch (Exception e) {
   10180             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat2Double2Float2: " + e.toString());
   10181         }
   10182     }
   10183 
   10184     private void verifyResultsConvertDouble2Float2(Allocation inV, Allocation out, boolean relaxed) {
   10185         double[] arrayInV = new double[INPUTSIZE * 2];
   10186         inV.copyTo(arrayInV);
   10187         float[] arrayOut = new float[INPUTSIZE * 2];
   10188         out.copyTo(arrayOut);
   10189         for (int i = 0; i < INPUTSIZE; i++) {
   10190             for (int j = 0; j < 2 ; j++) {
   10191                 // Extract the inputs.
   10192                 ArgumentsDoubleFloat args = new ArgumentsDoubleFloat();
   10193                 args.inV = arrayInV[i * 2 + j];
   10194                 // Figure out what the outputs should have been.
   10195                 Target target = new Target(relaxed);
   10196                 CoreMathVerifier.computeConvert(args, target);
   10197                 // Validate the outputs.
   10198                 boolean valid = true;
   10199                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
   10200                     valid = false;
   10201                 }
   10202                 if (!valid) {
   10203                     StringBuilder message = new StringBuilder();
   10204                     message.append("Input inV: ");
   10205                     message.append(String.format("%24.8g {%16x} %31a",
   10206                             args.inV, Double.doubleToRawLongBits(args.inV), args.inV));
   10207                     message.append("\n");
   10208                     message.append("Expected output out: ");
   10209                     message.append(args.out.toString());
   10210                     message.append("\n");
   10211                     message.append("Actual   output out: ");
   10212                     message.append(String.format("%14.8g {%8x} %15a",
   10213                             arrayOut[i * 2 + j], Float.floatToRawIntBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j]));
   10214                     if (!args.out.couldBe(arrayOut[i * 2 + j])) {
   10215                         message.append(" FAIL");
   10216                     }
   10217                     message.append("\n");
   10218                     assertTrue("Incorrect output for checkConvertDouble2Float2" +
   10219                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   10220                 }
   10221             }
   10222         }
   10223     }
   10224 
   10225     private void checkConvertDouble3Float3() {
   10226         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_64, 3, 0x42b697e17388bb0bl, -1.6163412428744576259e+38, 1.6163412428744576259e+38);
   10227         try {
   10228             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
   10229             script.forEach_testConvertFloat3Double3Float3(inV, out);
   10230             verifyResultsConvertDouble3Float3(inV, out, false);
   10231         } catch (Exception e) {
   10232             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat3Double3Float3: " + e.toString());
   10233         }
   10234         try {
   10235             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
   10236             scriptRelaxed.forEach_testConvertFloat3Double3Float3(inV, out);
   10237             verifyResultsConvertDouble3Float3(inV, out, true);
   10238         } catch (Exception e) {
   10239             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat3Double3Float3: " + e.toString());
   10240         }
   10241     }
   10242 
   10243     private void verifyResultsConvertDouble3Float3(Allocation inV, Allocation out, boolean relaxed) {
   10244         double[] arrayInV = new double[INPUTSIZE * 4];
   10245         inV.copyTo(arrayInV);
   10246         float[] arrayOut = new float[INPUTSIZE * 4];
   10247         out.copyTo(arrayOut);
   10248         for (int i = 0; i < INPUTSIZE; i++) {
   10249             for (int j = 0; j < 3 ; j++) {
   10250                 // Extract the inputs.
   10251                 ArgumentsDoubleFloat args = new ArgumentsDoubleFloat();
   10252                 args.inV = arrayInV[i * 4 + j];
   10253                 // Figure out what the outputs should have been.
   10254                 Target target = new Target(relaxed);
   10255                 CoreMathVerifier.computeConvert(args, target);
   10256                 // Validate the outputs.
   10257                 boolean valid = true;
   10258                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   10259                     valid = false;
   10260                 }
   10261                 if (!valid) {
   10262                     StringBuilder message = new StringBuilder();
   10263                     message.append("Input inV: ");
   10264                     message.append(String.format("%24.8g {%16x} %31a",
   10265                             args.inV, Double.doubleToRawLongBits(args.inV), args.inV));
   10266                     message.append("\n");
   10267                     message.append("Expected output out: ");
   10268                     message.append(args.out.toString());
   10269                     message.append("\n");
   10270                     message.append("Actual   output out: ");
   10271                     message.append(String.format("%14.8g {%8x} %15a",
   10272                             arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
   10273                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   10274                         message.append(" FAIL");
   10275                     }
   10276                     message.append("\n");
   10277                     assertTrue("Incorrect output for checkConvertDouble3Float3" +
   10278                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   10279                 }
   10280             }
   10281         }
   10282     }
   10283 
   10284     private void checkConvertDouble4Float4() {
   10285         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_64, 4, 0x42b860fc69a3dbe9l, -1.6163412428744576259e+38, 1.6163412428744576259e+38);
   10286         try {
   10287             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
   10288             script.forEach_testConvertFloat4Double4Float4(inV, out);
   10289             verifyResultsConvertDouble4Float4(inV, out, false);
   10290         } catch (Exception e) {
   10291             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat4Double4Float4: " + e.toString());
   10292         }
   10293         try {
   10294             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
   10295             scriptRelaxed.forEach_testConvertFloat4Double4Float4(inV, out);
   10296             verifyResultsConvertDouble4Float4(inV, out, true);
   10297         } catch (Exception e) {
   10298             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat4Double4Float4: " + e.toString());
   10299         }
   10300     }
   10301 
   10302     private void verifyResultsConvertDouble4Float4(Allocation inV, Allocation out, boolean relaxed) {
   10303         double[] arrayInV = new double[INPUTSIZE * 4];
   10304         inV.copyTo(arrayInV);
   10305         float[] arrayOut = new float[INPUTSIZE * 4];
   10306         out.copyTo(arrayOut);
   10307         for (int i = 0; i < INPUTSIZE; i++) {
   10308             for (int j = 0; j < 4 ; j++) {
   10309                 // Extract the inputs.
   10310                 ArgumentsDoubleFloat args = new ArgumentsDoubleFloat();
   10311                 args.inV = arrayInV[i * 4 + j];
   10312                 // Figure out what the outputs should have been.
   10313                 Target target = new Target(relaxed);
   10314                 CoreMathVerifier.computeConvert(args, target);
   10315                 // Validate the outputs.
   10316                 boolean valid = true;
   10317                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   10318                     valid = false;
   10319                 }
   10320                 if (!valid) {
   10321                     StringBuilder message = new StringBuilder();
   10322                     message.append("Input inV: ");
   10323                     message.append(String.format("%24.8g {%16x} %31a",
   10324                             args.inV, Double.doubleToRawLongBits(args.inV), args.inV));
   10325                     message.append("\n");
   10326                     message.append("Expected output out: ");
   10327                     message.append(args.out.toString());
   10328                     message.append("\n");
   10329                     message.append("Actual   output out: ");
   10330                     message.append(String.format("%14.8g {%8x} %15a",
   10331                             arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
   10332                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   10333                         message.append(" FAIL");
   10334                     }
   10335                     message.append("\n");
   10336                     assertTrue("Incorrect output for checkConvertDouble4Float4" +
   10337                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   10338                 }
   10339             }
   10340         }
   10341     }
   10342 
   10343     public class ArgumentsLongFloat {
   10344         public long inV;
   10345         public Target.Floaty out;
   10346     }
   10347 
   10348     private void checkConvertLong2Float2() {
   10349         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_64, 2, 0x79f102c9d72eaa34l, true, 63);
   10350         try {
   10351             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
   10352             script.forEach_testConvertFloat2Long2Float2(inV, out);
   10353             verifyResultsConvertLong2Float2(inV, out, false);
   10354         } catch (Exception e) {
   10355             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat2Long2Float2: " + e.toString());
   10356         }
   10357         try {
   10358             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
   10359             scriptRelaxed.forEach_testConvertFloat2Long2Float2(inV, out);
   10360             verifyResultsConvertLong2Float2(inV, out, true);
   10361         } catch (Exception e) {
   10362             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat2Long2Float2: " + e.toString());
   10363         }
   10364     }
   10365 
   10366     private void verifyResultsConvertLong2Float2(Allocation inV, Allocation out, boolean relaxed) {
   10367         long[] arrayInV = new long[INPUTSIZE * 2];
   10368         inV.copyTo(arrayInV);
   10369         float[] arrayOut = new float[INPUTSIZE * 2];
   10370         out.copyTo(arrayOut);
   10371         for (int i = 0; i < INPUTSIZE; i++) {
   10372             for (int j = 0; j < 2 ; j++) {
   10373                 // Extract the inputs.
   10374                 ArgumentsLongFloat args = new ArgumentsLongFloat();
   10375                 args.inV = arrayInV[i * 2 + j];
   10376                 // Figure out what the outputs should have been.
   10377                 Target target = new Target(relaxed);
   10378                 CoreMathVerifier.computeConvert(args, target);
   10379                 // Validate the outputs.
   10380                 boolean valid = true;
   10381                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
   10382                     valid = false;
   10383                 }
   10384                 if (!valid) {
   10385                     StringBuilder message = new StringBuilder();
   10386                     message.append("Input inV: ");
   10387                     message.append(String.format("%d", args.inV));
   10388                     message.append("\n");
   10389                     message.append("Expected output out: ");
   10390                     message.append(args.out.toString());
   10391                     message.append("\n");
   10392                     message.append("Actual   output out: ");
   10393                     message.append(String.format("%14.8g {%8x} %15a",
   10394                             arrayOut[i * 2 + j], Float.floatToRawIntBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j]));
   10395                     if (!args.out.couldBe(arrayOut[i * 2 + j])) {
   10396                         message.append(" FAIL");
   10397                     }
   10398                     message.append("\n");
   10399                     assertTrue("Incorrect output for checkConvertLong2Float2" +
   10400                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   10401                 }
   10402             }
   10403         }
   10404     }
   10405 
   10406     private void checkConvertLong3Float3() {
   10407         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_64, 3, 0x79f2cbe4cd49cb12l, true, 63);
   10408         try {
   10409             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
   10410             script.forEach_testConvertFloat3Long3Float3(inV, out);
   10411             verifyResultsConvertLong3Float3(inV, out, false);
   10412         } catch (Exception e) {
   10413             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat3Long3Float3: " + e.toString());
   10414         }
   10415         try {
   10416             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
   10417             scriptRelaxed.forEach_testConvertFloat3Long3Float3(inV, out);
   10418             verifyResultsConvertLong3Float3(inV, out, true);
   10419         } catch (Exception e) {
   10420             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat3Long3Float3: " + e.toString());
   10421         }
   10422     }
   10423 
   10424     private void verifyResultsConvertLong3Float3(Allocation inV, Allocation out, boolean relaxed) {
   10425         long[] arrayInV = new long[INPUTSIZE * 4];
   10426         inV.copyTo(arrayInV);
   10427         float[] arrayOut = new float[INPUTSIZE * 4];
   10428         out.copyTo(arrayOut);
   10429         for (int i = 0; i < INPUTSIZE; i++) {
   10430             for (int j = 0; j < 3 ; j++) {
   10431                 // Extract the inputs.
   10432                 ArgumentsLongFloat args = new ArgumentsLongFloat();
   10433                 args.inV = arrayInV[i * 4 + j];
   10434                 // Figure out what the outputs should have been.
   10435                 Target target = new Target(relaxed);
   10436                 CoreMathVerifier.computeConvert(args, target);
   10437                 // Validate the outputs.
   10438                 boolean valid = true;
   10439                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   10440                     valid = false;
   10441                 }
   10442                 if (!valid) {
   10443                     StringBuilder message = new StringBuilder();
   10444                     message.append("Input inV: ");
   10445                     message.append(String.format("%d", args.inV));
   10446                     message.append("\n");
   10447                     message.append("Expected output out: ");
   10448                     message.append(args.out.toString());
   10449                     message.append("\n");
   10450                     message.append("Actual   output out: ");
   10451                     message.append(String.format("%14.8g {%8x} %15a",
   10452                             arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
   10453                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   10454                         message.append(" FAIL");
   10455                     }
   10456                     message.append("\n");
   10457                     assertTrue("Incorrect output for checkConvertLong3Float3" +
   10458                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   10459                 }
   10460             }
   10461         }
   10462     }
   10463 
   10464     private void checkConvertLong4Float4() {
   10465         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_64, 4, 0x79f494ffc364ebf0l, true, 63);
   10466         try {
   10467             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
   10468             script.forEach_testConvertFloat4Long4Float4(inV, out);
   10469             verifyResultsConvertLong4Float4(inV, out, false);
   10470         } catch (Exception e) {
   10471             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat4Long4Float4: " + e.toString());
   10472         }
   10473         try {
   10474             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
   10475             scriptRelaxed.forEach_testConvertFloat4Long4Float4(inV, out);
   10476             verifyResultsConvertLong4Float4(inV, out, true);
   10477         } catch (Exception e) {
   10478             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat4Long4Float4: " + e.toString());
   10479         }
   10480     }
   10481 
   10482     private void verifyResultsConvertLong4Float4(Allocation inV, Allocation out, boolean relaxed) {
   10483         long[] arrayInV = new long[INPUTSIZE * 4];
   10484         inV.copyTo(arrayInV);
   10485         float[] arrayOut = new float[INPUTSIZE * 4];
   10486         out.copyTo(arrayOut);
   10487         for (int i = 0; i < INPUTSIZE; i++) {
   10488             for (int j = 0; j < 4 ; j++) {
   10489                 // Extract the inputs.
   10490                 ArgumentsLongFloat args = new ArgumentsLongFloat();
   10491                 args.inV = arrayInV[i * 4 + j];
   10492                 // Figure out what the outputs should have been.
   10493                 Target target = new Target(relaxed);
   10494                 CoreMathVerifier.computeConvert(args, target);
   10495                 // Validate the outputs.
   10496                 boolean valid = true;
   10497                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   10498                     valid = false;
   10499                 }
   10500                 if (!valid) {
   10501                     StringBuilder message = new StringBuilder();
   10502                     message.append("Input inV: ");
   10503                     message.append(String.format("%d", args.inV));
   10504                     message.append("\n");
   10505                     message.append("Expected output out: ");
   10506                     message.append(args.out.toString());
   10507                     message.append("\n");
   10508                     message.append("Actual   output out: ");
   10509                     message.append(String.format("%14.8g {%8x} %15a",
   10510                             arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
   10511                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   10512                         message.append(" FAIL");
   10513                     }
   10514                     message.append("\n");
   10515                     assertTrue("Incorrect output for checkConvertLong4Float4" +
   10516                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   10517                 }
   10518             }
   10519         }
   10520     }
   10521 
   10522     public class ArgumentsUlongFloat {
   10523         public long inV;
   10524         public Target.Floaty out;
   10525     }
   10526 
   10527     private void checkConvertUlong2Float2() {
   10528         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_64, 2, 0x9ebf22d17306c3dfl, false, 64);
   10529         try {
   10530             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
   10531             script.forEach_testConvertFloat2Ulong2Float2(inV, out);
   10532             verifyResultsConvertUlong2Float2(inV, out, false);
   10533         } catch (Exception e) {
   10534             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat2Ulong2Float2: " + e.toString());
   10535         }
   10536         try {
   10537             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 2), INPUTSIZE);
   10538             scriptRelaxed.forEach_testConvertFloat2Ulong2Float2(inV, out);
   10539             verifyResultsConvertUlong2Float2(inV, out, true);
   10540         } catch (Exception e) {
   10541             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat2Ulong2Float2: " + e.toString());
   10542         }
   10543     }
   10544 
   10545     private void verifyResultsConvertUlong2Float2(Allocation inV, Allocation out, boolean relaxed) {
   10546         long[] arrayInV = new long[INPUTSIZE * 2];
   10547         inV.copyTo(arrayInV);
   10548         float[] arrayOut = new float[INPUTSIZE * 2];
   10549         out.copyTo(arrayOut);
   10550         for (int i = 0; i < INPUTSIZE; i++) {
   10551             for (int j = 0; j < 2 ; j++) {
   10552                 // Extract the inputs.
   10553                 ArgumentsUlongFloat args = new ArgumentsUlongFloat();
   10554                 args.inV = arrayInV[i * 2 + j];
   10555                 // Figure out what the outputs should have been.
   10556                 Target target = new Target(relaxed);
   10557                 CoreMathVerifier.computeConvert(args, target);
   10558                 // Validate the outputs.
   10559                 boolean valid = true;
   10560                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
   10561                     valid = false;
   10562                 }
   10563                 if (!valid) {
   10564                     StringBuilder message = new StringBuilder();
   10565                     message.append("Input inV: ");
   10566                     message.append(String.format("0x%x", args.inV));
   10567                     message.append("\n");
   10568                     message.append("Expected output out: ");
   10569                     message.append(args.out.toString());
   10570                     message.append("\n");
   10571                     message.append("Actual   output out: ");
   10572                     message.append(String.format("%14.8g {%8x} %15a",
   10573                             arrayOut[i * 2 + j], Float.floatToRawIntBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j]));
   10574                     if (!args.out.couldBe(arrayOut[i * 2 + j])) {
   10575                         message.append(" FAIL");
   10576                     }
   10577                     message.append("\n");
   10578                     assertTrue("Incorrect output for checkConvertUlong2Float2" +
   10579                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   10580                 }
   10581             }
   10582         }
   10583     }
   10584 
   10585     private void checkConvertUlong3Float3() {
   10586         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_64, 3, 0x9ec0ebec6921e4bdl, false, 64);
   10587         try {
   10588             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
   10589             script.forEach_testConvertFloat3Ulong3Float3(inV, out);
   10590             verifyResultsConvertUlong3Float3(inV, out, false);
   10591         } catch (Exception e) {
   10592             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat3Ulong3Float3: " + e.toString());
   10593         }
   10594         try {
   10595             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 3), INPUTSIZE);
   10596             scriptRelaxed.forEach_testConvertFloat3Ulong3Float3(inV, out);
   10597             verifyResultsConvertUlong3Float3(inV, out, true);
   10598         } catch (Exception e) {
   10599             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat3Ulong3Float3: " + e.toString());
   10600         }
   10601     }
   10602 
   10603     private void verifyResultsConvertUlong3Float3(Allocation inV, Allocation out, boolean relaxed) {
   10604         long[] arrayInV = new long[INPUTSIZE * 4];
   10605         inV.copyTo(arrayInV);
   10606         float[] arrayOut = new float[INPUTSIZE * 4];
   10607         out.copyTo(arrayOut);
   10608         for (int i = 0; i < INPUTSIZE; i++) {
   10609             for (int j = 0; j < 3 ; j++) {
   10610                 // Extract the inputs.
   10611                 ArgumentsUlongFloat args = new ArgumentsUlongFloat();
   10612                 args.inV = arrayInV[i * 4 + j];
   10613                 // Figure out what the outputs should have been.
   10614                 Target target = new Target(relaxed);
   10615                 CoreMathVerifier.computeConvert(args, target);
   10616                 // Validate the outputs.
   10617                 boolean valid = true;
   10618                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   10619                     valid = false;
   10620                 }
   10621                 if (!valid) {
   10622                     StringBuilder message = new StringBuilder();
   10623                     message.append("Input inV: ");
   10624                     message.append(String.format("0x%x", args.inV));
   10625                     message.append("\n");
   10626                     message.append("Expected output out: ");
   10627                     message.append(args.out.toString());
   10628                     message.append("\n");
   10629                     message.append("Actual   output out: ");
   10630                     message.append(String.format("%14.8g {%8x} %15a",
   10631                             arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
   10632                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   10633                         message.append(" FAIL");
   10634                     }
   10635                     message.append("\n");
   10636                     assertTrue("Incorrect output for checkConvertUlong3Float3" +
   10637                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   10638                 }
   10639             }
   10640         }
   10641     }
   10642 
   10643     private void checkConvertUlong4Float4() {
   10644         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_64, 4, 0x9ec2b5075f3d059bl, false, 64);
   10645         try {
   10646             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
   10647             script.forEach_testConvertFloat4Ulong4Float4(inV, out);
   10648             verifyResultsConvertUlong4Float4(inV, out, false);
   10649         } catch (Exception e) {
   10650             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat4Ulong4Float4: " + e.toString());
   10651         }
   10652         try {
   10653             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_32, 4), INPUTSIZE);
   10654             scriptRelaxed.forEach_testConvertFloat4Ulong4Float4(inV, out);
   10655             verifyResultsConvertUlong4Float4(inV, out, true);
   10656         } catch (Exception e) {
   10657             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertFloat4Ulong4Float4: " + e.toString());
   10658         }
   10659     }
   10660 
   10661     private void verifyResultsConvertUlong4Float4(Allocation inV, Allocation out, boolean relaxed) {
   10662         long[] arrayInV = new long[INPUTSIZE * 4];
   10663         inV.copyTo(arrayInV);
   10664         float[] arrayOut = new float[INPUTSIZE * 4];
   10665         out.copyTo(arrayOut);
   10666         for (int i = 0; i < INPUTSIZE; i++) {
   10667             for (int j = 0; j < 4 ; j++) {
   10668                 // Extract the inputs.
   10669                 ArgumentsUlongFloat args = new ArgumentsUlongFloat();
   10670                 args.inV = arrayInV[i * 4 + j];
   10671                 // Figure out what the outputs should have been.
   10672                 Target target = new Target(relaxed);
   10673                 CoreMathVerifier.computeConvert(args, target);
   10674                 // Validate the outputs.
   10675                 boolean valid = true;
   10676                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   10677                     valid = false;
   10678                 }
   10679                 if (!valid) {
   10680                     StringBuilder message = new StringBuilder();
   10681                     message.append("Input inV: ");
   10682                     message.append(String.format("0x%x", args.inV));
   10683                     message.append("\n");
   10684                     message.append("Expected output out: ");
   10685                     message.append(args.out.toString());
   10686                     message.append("\n");
   10687                     message.append("Actual   output out: ");
   10688                     message.append(String.format("%14.8g {%8x} %15a",
   10689                             arrayOut[i * 4 + j], Float.floatToRawIntBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
   10690                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   10691                         message.append(" FAIL");
   10692                     }
   10693                     message.append("\n");
   10694                     assertTrue("Incorrect output for checkConvertUlong4Float4" +
   10695                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   10696                 }
   10697             }
   10698         }
   10699     }
   10700 
   10701     public class ArgumentsDoubleChar {
   10702         public double inV;
   10703         public byte out;
   10704     }
   10705 
   10706     private void checkConvertDouble2Char2() {
   10707         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_64, 2, 0xcbf84b7bef094a17l, -1.2800000000000000000e+02, 1.2700000000000000000e+02);
   10708         try {
   10709             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 2), INPUTSIZE);
   10710             script.forEach_testConvertChar2Double2Char2(inV, out);
   10711             verifyResultsConvertDouble2Char2(inV, out, false);
   10712         } catch (Exception e) {
   10713             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar2Double2Char2: " + e.toString());
   10714         }
   10715         try {
   10716             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 2), INPUTSIZE);
   10717             scriptRelaxed.forEach_testConvertChar2Double2Char2(inV, out);
   10718             verifyResultsConvertDouble2Char2(inV, out, true);
   10719         } catch (Exception e) {
   10720             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar2Double2Char2: " + e.toString());
   10721         }
   10722     }
   10723 
   10724     private void verifyResultsConvertDouble2Char2(Allocation inV, Allocation out, boolean relaxed) {
   10725         double[] arrayInV = new double[INPUTSIZE * 2];
   10726         inV.copyTo(arrayInV);
   10727         byte[] arrayOut = new byte[INPUTSIZE * 2];
   10728         out.copyTo(arrayOut);
   10729         for (int i = 0; i < INPUTSIZE; i++) {
   10730             for (int j = 0; j < 2 ; j++) {
   10731                 // Extract the inputs.
   10732                 ArgumentsDoubleChar args = new ArgumentsDoubleChar();
   10733                 args.inV = arrayInV[i * 2 + j];
   10734                 // Figure out what the outputs should have been.
   10735                 CoreMathVerifier.computeConvert(args);
   10736                 // Validate the outputs.
   10737                 boolean valid = true;
   10738                 if (args.out != arrayOut[i * 2 + j]) {
   10739                     valid = false;
   10740                 }
   10741                 if (!valid) {
   10742                     StringBuilder message = new StringBuilder();
   10743                     message.append("Input inV: ");
   10744                     message.append(String.format("%24.8g {%16x} %31a",
   10745                             args.inV, Double.doubleToRawLongBits(args.inV), args.inV));
   10746                     message.append("\n");
   10747                     message.append("Expected output out: ");
   10748                     message.append(String.format("%d", args.out));
   10749                     message.append("\n");
   10750                     message.append("Actual   output out: ");
   10751                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   10752                     if (args.out != arrayOut[i * 2 + j]) {
   10753                         message.append(" FAIL");
   10754                     }
   10755                     message.append("\n");
   10756                     assertTrue("Incorrect output for checkConvertDouble2Char2" +
   10757                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   10758                 }
   10759             }
   10760         }
   10761     }
   10762 
   10763     private void checkConvertDouble3Char3() {
   10764         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_64, 3, 0xcbf8561d4e110f0bl, -1.2800000000000000000e+02, 1.2700000000000000000e+02);
   10765         try {
   10766             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 3), INPUTSIZE);
   10767             script.forEach_testConvertChar3Double3Char3(inV, out);
   10768             verifyResultsConvertDouble3Char3(inV, out, false);
   10769         } catch (Exception e) {
   10770             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar3Double3Char3: " + e.toString());
   10771         }
   10772         try {
   10773             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 3), INPUTSIZE);
   10774             scriptRelaxed.forEach_testConvertChar3Double3Char3(inV, out);
   10775             verifyResultsConvertDouble3Char3(inV, out, true);
   10776         } catch (Exception e) {
   10777             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar3Double3Char3: " + e.toString());
   10778         }
   10779     }
   10780 
   10781     private void verifyResultsConvertDouble3Char3(Allocation inV, Allocation out, boolean relaxed) {
   10782         double[] arrayInV = new double[INPUTSIZE * 4];
   10783         inV.copyTo(arrayInV);
   10784         byte[] arrayOut = new byte[INPUTSIZE * 4];
   10785         out.copyTo(arrayOut);
   10786         for (int i = 0; i < INPUTSIZE; i++) {
   10787             for (int j = 0; j < 3 ; j++) {
   10788                 // Extract the inputs.
   10789                 ArgumentsDoubleChar args = new ArgumentsDoubleChar();
   10790                 args.inV = arrayInV[i * 4 + j];
   10791                 // Figure out what the outputs should have been.
   10792                 CoreMathVerifier.computeConvert(args);
   10793                 // Validate the outputs.
   10794                 boolean valid = true;
   10795                 if (args.out != arrayOut[i * 4 + j]) {
   10796                     valid = false;
   10797                 }
   10798                 if (!valid) {
   10799                     StringBuilder message = new StringBuilder();
   10800                     message.append("Input inV: ");
   10801                     message.append(String.format("%24.8g {%16x} %31a",
   10802                             args.inV, Double.doubleToRawLongBits(args.inV), args.inV));
   10803                     message.append("\n");
   10804                     message.append("Expected output out: ");
   10805                     message.append(String.format("%d", args.out));
   10806                     message.append("\n");
   10807                     message.append("Actual   output out: ");
   10808                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   10809                     if (args.out != arrayOut[i * 4 + j]) {
   10810                         message.append(" FAIL");
   10811                     }
   10812                     message.append("\n");
   10813                     assertTrue("Incorrect output for checkConvertDouble3Char3" +
   10814                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   10815                 }
   10816             }
   10817         }
   10818     }
   10819 
   10820     private void checkConvertDouble4Char4() {
   10821         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_64, 4, 0xcbf860bead18d3ffl, -1.2800000000000000000e+02, 1.2700000000000000000e+02);
   10822         try {
   10823             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 4), INPUTSIZE);
   10824             script.forEach_testConvertChar4Double4Char4(inV, out);
   10825             verifyResultsConvertDouble4Char4(inV, out, false);
   10826         } catch (Exception e) {
   10827             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar4Double4Char4: " + e.toString());
   10828         }
   10829         try {
   10830             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 4), INPUTSIZE);
   10831             scriptRelaxed.forEach_testConvertChar4Double4Char4(inV, out);
   10832             verifyResultsConvertDouble4Char4(inV, out, true);
   10833         } catch (Exception e) {
   10834             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar4Double4Char4: " + e.toString());
   10835         }
   10836     }
   10837 
   10838     private void verifyResultsConvertDouble4Char4(Allocation inV, Allocation out, boolean relaxed) {
   10839         double[] arrayInV = new double[INPUTSIZE * 4];
   10840         inV.copyTo(arrayInV);
   10841         byte[] arrayOut = new byte[INPUTSIZE * 4];
   10842         out.copyTo(arrayOut);
   10843         for (int i = 0; i < INPUTSIZE; i++) {
   10844             for (int j = 0; j < 4 ; j++) {
   10845                 // Extract the inputs.
   10846                 ArgumentsDoubleChar args = new ArgumentsDoubleChar();
   10847                 args.inV = arrayInV[i * 4 + j];
   10848                 // Figure out what the outputs should have been.
   10849                 CoreMathVerifier.computeConvert(args);
   10850                 // Validate the outputs.
   10851                 boolean valid = true;
   10852                 if (args.out != arrayOut[i * 4 + j]) {
   10853                     valid = false;
   10854                 }
   10855                 if (!valid) {
   10856                     StringBuilder message = new StringBuilder();
   10857                     message.append("Input inV: ");
   10858                     message.append(String.format("%24.8g {%16x} %31a",
   10859                             args.inV, Double.doubleToRawLongBits(args.inV), args.inV));
   10860                     message.append("\n");
   10861                     message.append("Expected output out: ");
   10862                     message.append(String.format("%d", args.out));
   10863                     message.append("\n");
   10864                     message.append("Actual   output out: ");
   10865                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   10866                     if (args.out != arrayOut[i * 4 + j]) {
   10867                         message.append(" FAIL");
   10868                     }
   10869                     message.append("\n");
   10870                     assertTrue("Incorrect output for checkConvertDouble4Char4" +
   10871                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   10872                 }
   10873             }
   10874         }
   10875     }
   10876 
   10877     public class ArgumentsLongChar {
   10878         public long inV;
   10879         public byte out;
   10880     }
   10881 
   10882     private void checkConvertLong2Char2() {
   10883         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_64, 2, 0xb570c3c37419afacl, true, 7);
   10884         try {
   10885             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 2), INPUTSIZE);
   10886             script.forEach_testConvertChar2Long2Char2(inV, out);
   10887             verifyResultsConvertLong2Char2(inV, out, false);
   10888         } catch (Exception e) {
   10889             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar2Long2Char2: " + e.toString());
   10890         }
   10891         try {
   10892             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 2), INPUTSIZE);
   10893             scriptRelaxed.forEach_testConvertChar2Long2Char2(inV, out);
   10894             verifyResultsConvertLong2Char2(inV, out, true);
   10895         } catch (Exception e) {
   10896             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar2Long2Char2: " + e.toString());
   10897         }
   10898     }
   10899 
   10900     private void verifyResultsConvertLong2Char2(Allocation inV, Allocation out, boolean relaxed) {
   10901         long[] arrayInV = new long[INPUTSIZE * 2];
   10902         inV.copyTo(arrayInV);
   10903         byte[] arrayOut = new byte[INPUTSIZE * 2];
   10904         out.copyTo(arrayOut);
   10905         for (int i = 0; i < INPUTSIZE; i++) {
   10906             for (int j = 0; j < 2 ; j++) {
   10907                 // Extract the inputs.
   10908                 ArgumentsLongChar args = new ArgumentsLongChar();
   10909                 args.inV = arrayInV[i * 2 + j];
   10910                 // Figure out what the outputs should have been.
   10911                 CoreMathVerifier.computeConvert(args);
   10912                 // Validate the outputs.
   10913                 boolean valid = true;
   10914                 if (args.out != arrayOut[i * 2 + j]) {
   10915                     valid = false;
   10916                 }
   10917                 if (!valid) {
   10918                     StringBuilder message = new StringBuilder();
   10919                     message.append("Input inV: ");
   10920                     message.append(String.format("%d", args.inV));
   10921                     message.append("\n");
   10922                     message.append("Expected output out: ");
   10923                     message.append(String.format("%d", args.out));
   10924                     message.append("\n");
   10925                     message.append("Actual   output out: ");
   10926                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   10927                     if (args.out != arrayOut[i * 2 + j]) {
   10928                         message.append(" FAIL");
   10929                     }
   10930                     message.append("\n");
   10931                     assertTrue("Incorrect output for checkConvertLong2Char2" +
   10932                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   10933                 }
   10934             }
   10935         }
   10936     }
   10937 
   10938     private void checkConvertLong3Char3() {
   10939         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_64, 3, 0xb570ce64d32174a0l, true, 7);
   10940         try {
   10941             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 3), INPUTSIZE);
   10942             script.forEach_testConvertChar3Long3Char3(inV, out);
   10943             verifyResultsConvertLong3Char3(inV, out, false);
   10944         } catch (Exception e) {
   10945             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar3Long3Char3: " + e.toString());
   10946         }
   10947         try {
   10948             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 3), INPUTSIZE);
   10949             scriptRelaxed.forEach_testConvertChar3Long3Char3(inV, out);
   10950             verifyResultsConvertLong3Char3(inV, out, true);
   10951         } catch (Exception e) {
   10952             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar3Long3Char3: " + e.toString());
   10953         }
   10954     }
   10955 
   10956     private void verifyResultsConvertLong3Char3(Allocation inV, Allocation out, boolean relaxed) {
   10957         long[] arrayInV = new long[INPUTSIZE * 4];
   10958         inV.copyTo(arrayInV);
   10959         byte[] arrayOut = new byte[INPUTSIZE * 4];
   10960         out.copyTo(arrayOut);
   10961         for (int i = 0; i < INPUTSIZE; i++) {
   10962             for (int j = 0; j < 3 ; j++) {
   10963                 // Extract the inputs.
   10964                 ArgumentsLongChar args = new ArgumentsLongChar();
   10965                 args.inV = arrayInV[i * 4 + j];
   10966                 // Figure out what the outputs should have been.
   10967                 CoreMathVerifier.computeConvert(args);
   10968                 // Validate the outputs.
   10969                 boolean valid = true;
   10970                 if (args.out != arrayOut[i * 4 + j]) {
   10971                     valid = false;
   10972                 }
   10973                 if (!valid) {
   10974                     StringBuilder message = new StringBuilder();
   10975                     message.append("Input inV: ");
   10976                     message.append(String.format("%d", args.inV));
   10977                     message.append("\n");
   10978                     message.append("Expected output out: ");
   10979                     message.append(String.format("%d", args.out));
   10980                     message.append("\n");
   10981                     message.append("Actual   output out: ");
   10982                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   10983                     if (args.out != arrayOut[i * 4 + j]) {
   10984                         message.append(" FAIL");
   10985                     }
   10986                     message.append("\n");
   10987                     assertTrue("Incorrect output for checkConvertLong3Char3" +
   10988                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   10989                 }
   10990             }
   10991         }
   10992     }
   10993 
   10994     private void checkConvertLong4Char4() {
   10995         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_64, 4, 0xb570d90632293994l, true, 7);
   10996         try {
   10997             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 4), INPUTSIZE);
   10998             script.forEach_testConvertChar4Long4Char4(inV, out);
   10999             verifyResultsConvertLong4Char4(inV, out, false);
   11000         } catch (Exception e) {
   11001             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar4Long4Char4: " + e.toString());
   11002         }
   11003         try {
   11004             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 4), INPUTSIZE);
   11005             scriptRelaxed.forEach_testConvertChar4Long4Char4(inV, out);
   11006             verifyResultsConvertLong4Char4(inV, out, true);
   11007         } catch (Exception e) {
   11008             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar4Long4Char4: " + e.toString());
   11009         }
   11010     }
   11011 
   11012     private void verifyResultsConvertLong4Char4(Allocation inV, Allocation out, boolean relaxed) {
   11013         long[] arrayInV = new long[INPUTSIZE * 4];
   11014         inV.copyTo(arrayInV);
   11015         byte[] arrayOut = new byte[INPUTSIZE * 4];
   11016         out.copyTo(arrayOut);
   11017         for (int i = 0; i < INPUTSIZE; i++) {
   11018             for (int j = 0; j < 4 ; j++) {
   11019                 // Extract the inputs.
   11020                 ArgumentsLongChar args = new ArgumentsLongChar();
   11021                 args.inV = arrayInV[i * 4 + j];
   11022                 // Figure out what the outputs should have been.
   11023                 CoreMathVerifier.computeConvert(args);
   11024                 // Validate the outputs.
   11025                 boolean valid = true;
   11026                 if (args.out != arrayOut[i * 4 + j]) {
   11027                     valid = false;
   11028                 }
   11029                 if (!valid) {
   11030                     StringBuilder message = new StringBuilder();
   11031                     message.append("Input inV: ");
   11032                     message.append(String.format("%d", args.inV));
   11033                     message.append("\n");
   11034                     message.append("Expected output out: ");
   11035                     message.append(String.format("%d", args.out));
   11036                     message.append("\n");
   11037                     message.append("Actual   output out: ");
   11038                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   11039                     if (args.out != arrayOut[i * 4 + j]) {
   11040                         message.append(" FAIL");
   11041                     }
   11042                     message.append("\n");
   11043                     assertTrue("Incorrect output for checkConvertLong4Char4" +
   11044                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   11045                 }
   11046             }
   11047         }
   11048     }
   11049 
   11050     public class ArgumentsUlongChar {
   11051         public long inV;
   11052         public byte out;
   11053     }
   11054 
   11055     private void checkConvertUlong2Char2() {
   11056         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_64, 2, 0x5cfe7d11069bbc2dl, false, 7);
   11057         try {
   11058             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 2), INPUTSIZE);
   11059             script.forEach_testConvertChar2Ulong2Char2(inV, out);
   11060             verifyResultsConvertUlong2Char2(inV, out, false);
   11061         } catch (Exception e) {
   11062             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar2Ulong2Char2: " + e.toString());
   11063         }
   11064         try {
   11065             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 2), INPUTSIZE);
   11066             scriptRelaxed.forEach_testConvertChar2Ulong2Char2(inV, out);
   11067             verifyResultsConvertUlong2Char2(inV, out, true);
   11068         } catch (Exception e) {
   11069             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar2Ulong2Char2: " + e.toString());
   11070         }
   11071     }
   11072 
   11073     private void verifyResultsConvertUlong2Char2(Allocation inV, Allocation out, boolean relaxed) {
   11074         long[] arrayInV = new long[INPUTSIZE * 2];
   11075         inV.copyTo(arrayInV);
   11076         byte[] arrayOut = new byte[INPUTSIZE * 2];
   11077         out.copyTo(arrayOut);
   11078         for (int i = 0; i < INPUTSIZE; i++) {
   11079             for (int j = 0; j < 2 ; j++) {
   11080                 // Extract the inputs.
   11081                 ArgumentsUlongChar args = new ArgumentsUlongChar();
   11082                 args.inV = arrayInV[i * 2 + j];
   11083                 // Figure out what the outputs should have been.
   11084                 CoreMathVerifier.computeConvert(args);
   11085                 // Validate the outputs.
   11086                 boolean valid = true;
   11087                 if (args.out != arrayOut[i * 2 + j]) {
   11088                     valid = false;
   11089                 }
   11090                 if (!valid) {
   11091                     StringBuilder message = new StringBuilder();
   11092                     message.append("Input inV: ");
   11093                     message.append(String.format("0x%x", args.inV));
   11094                     message.append("\n");
   11095                     message.append("Expected output out: ");
   11096                     message.append(String.format("%d", args.out));
   11097                     message.append("\n");
   11098                     message.append("Actual   output out: ");
   11099                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   11100                     if (args.out != arrayOut[i * 2 + j]) {
   11101                         message.append(" FAIL");
   11102                     }
   11103                     message.append("\n");
   11104                     assertTrue("Incorrect output for checkConvertUlong2Char2" +
   11105                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   11106                 }
   11107             }
   11108         }
   11109     }
   11110 
   11111     private void checkConvertUlong3Char3() {
   11112         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_64, 3, 0x5cfe87b265a38121l, false, 7);
   11113         try {
   11114             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 3), INPUTSIZE);
   11115             script.forEach_testConvertChar3Ulong3Char3(inV, out);
   11116             verifyResultsConvertUlong3Char3(inV, out, false);
   11117         } catch (Exception e) {
   11118             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar3Ulong3Char3: " + e.toString());
   11119         }
   11120         try {
   11121             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 3), INPUTSIZE);
   11122             scriptRelaxed.forEach_testConvertChar3Ulong3Char3(inV, out);
   11123             verifyResultsConvertUlong3Char3(inV, out, true);
   11124         } catch (Exception e) {
   11125             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar3Ulong3Char3: " + e.toString());
   11126         }
   11127     }
   11128 
   11129     private void verifyResultsConvertUlong3Char3(Allocation inV, Allocation out, boolean relaxed) {
   11130         long[] arrayInV = new long[INPUTSIZE * 4];
   11131         inV.copyTo(arrayInV);
   11132         byte[] arrayOut = new byte[INPUTSIZE * 4];
   11133         out.copyTo(arrayOut);
   11134         for (int i = 0; i < INPUTSIZE; i++) {
   11135             for (int j = 0; j < 3 ; j++) {
   11136                 // Extract the inputs.
   11137                 ArgumentsUlongChar args = new ArgumentsUlongChar();
   11138                 args.inV = arrayInV[i * 4 + j];
   11139                 // Figure out what the outputs should have been.
   11140                 CoreMathVerifier.computeConvert(args);
   11141                 // Validate the outputs.
   11142                 boolean valid = true;
   11143                 if (args.out != arrayOut[i * 4 + j]) {
   11144                     valid = false;
   11145                 }
   11146                 if (!valid) {
   11147                     StringBuilder message = new StringBuilder();
   11148                     message.append("Input inV: ");
   11149                     message.append(String.format("0x%x", args.inV));
   11150                     message.append("\n");
   11151                     message.append("Expected output out: ");
   11152                     message.append(String.format("%d", args.out));
   11153                     message.append("\n");
   11154                     message.append("Actual   output out: ");
   11155                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   11156                     if (args.out != arrayOut[i * 4 + j]) {
   11157                         message.append(" FAIL");
   11158                     }
   11159                     message.append("\n");
   11160                     assertTrue("Incorrect output for checkConvertUlong3Char3" +
   11161                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   11162                 }
   11163             }
   11164         }
   11165     }
   11166 
   11167     private void checkConvertUlong4Char4() {
   11168         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_64, 4, 0x5cfe9253c4ab4615l, false, 7);
   11169         try {
   11170             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 4), INPUTSIZE);
   11171             script.forEach_testConvertChar4Ulong4Char4(inV, out);
   11172             verifyResultsConvertUlong4Char4(inV, out, false);
   11173         } catch (Exception e) {
   11174             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar4Ulong4Char4: " + e.toString());
   11175         }
   11176         try {
   11177             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_8, 4), INPUTSIZE);
   11178             scriptRelaxed.forEach_testConvertChar4Ulong4Char4(inV, out);
   11179             verifyResultsConvertUlong4Char4(inV, out, true);
   11180         } catch (Exception e) {
   11181             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertChar4Ulong4Char4: " + e.toString());
   11182         }
   11183     }
   11184 
   11185     private void verifyResultsConvertUlong4Char4(Allocation inV, Allocation out, boolean relaxed) {
   11186         long[] arrayInV = new long[INPUTSIZE * 4];
   11187         inV.copyTo(arrayInV);
   11188         byte[] arrayOut = new byte[INPUTSIZE * 4];
   11189         out.copyTo(arrayOut);
   11190         for (int i = 0; i < INPUTSIZE; i++) {
   11191             for (int j = 0; j < 4 ; j++) {
   11192                 // Extract the inputs.
   11193                 ArgumentsUlongChar args = new ArgumentsUlongChar();
   11194                 args.inV = arrayInV[i * 4 + j];
   11195                 // Figure out what the outputs should have been.
   11196                 CoreMathVerifier.computeConvert(args);
   11197                 // Validate the outputs.
   11198                 boolean valid = true;
   11199                 if (args.out != arrayOut[i * 4 + j]) {
   11200                     valid = false;
   11201                 }
   11202                 if (!valid) {
   11203                     StringBuilder message = new StringBuilder();
   11204                     message.append("Input inV: ");
   11205                     message.append(String.format("0x%x", args.inV));
   11206                     message.append("\n");
   11207                     message.append("Expected output out: ");
   11208                     message.append(String.format("%d", args.out));
   11209                     message.append("\n");
   11210                     message.append("Actual   output out: ");
   11211                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   11212                     if (args.out != arrayOut[i * 4 + j]) {
   11213                         message.append(" FAIL");
   11214                     }
   11215                     message.append("\n");
   11216                     assertTrue("Incorrect output for checkConvertUlong4Char4" +
   11217                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   11218                 }
   11219             }
   11220         }
   11221     }
   11222 
   11223     public class ArgumentsDoubleUchar {
   11224         public double inV;
   11225         public byte out;
   11226     }
   11227 
   11228     private void checkConvertDouble2Uchar2() {
   11229         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_64, 2, 0x42b56bf72a0f8ae0l, 0.0000000000000000000e+00, 2.5500000000000000000e+02);
   11230         try {
   11231             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE);
   11232             script.forEach_testConvertUchar2Double2Uchar2(inV, out);
   11233             verifyResultsConvertDouble2Uchar2(inV, out, false);
   11234         } catch (Exception e) {
   11235             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar2Double2Uchar2: " + e.toString());
   11236         }
   11237         try {
   11238             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE);
   11239             scriptRelaxed.forEach_testConvertUchar2Double2Uchar2(inV, out);
   11240             verifyResultsConvertDouble2Uchar2(inV, out, true);
   11241         } catch (Exception e) {
   11242             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar2Double2Uchar2: " + e.toString());
   11243         }
   11244     }
   11245 
   11246     private void verifyResultsConvertDouble2Uchar2(Allocation inV, Allocation out, boolean relaxed) {
   11247         double[] arrayInV = new double[INPUTSIZE * 2];
   11248         inV.copyTo(arrayInV);
   11249         byte[] arrayOut = new byte[INPUTSIZE * 2];
   11250         out.copyTo(arrayOut);
   11251         for (int i = 0; i < INPUTSIZE; i++) {
   11252             for (int j = 0; j < 2 ; j++) {
   11253                 // Extract the inputs.
   11254                 ArgumentsDoubleUchar args = new ArgumentsDoubleUchar();
   11255                 args.inV = arrayInV[i * 2 + j];
   11256                 // Figure out what the outputs should have been.
   11257                 CoreMathVerifier.computeConvert(args);
   11258                 // Validate the outputs.
   11259                 boolean valid = true;
   11260                 if (args.out != arrayOut[i * 2 + j]) {
   11261                     valid = false;
   11262                 }
   11263                 if (!valid) {
   11264                     StringBuilder message = new StringBuilder();
   11265                     message.append("Input inV: ");
   11266                     message.append(String.format("%24.8g {%16x} %31a",
   11267                             args.inV, Double.doubleToRawLongBits(args.inV), args.inV));
   11268                     message.append("\n");
   11269                     message.append("Expected output out: ");
   11270                     message.append(String.format("0x%x", args.out));
   11271                     message.append("\n");
   11272                     message.append("Actual   output out: ");
   11273                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   11274                     if (args.out != arrayOut[i * 2 + j]) {
   11275                         message.append(" FAIL");
   11276                     }
   11277                     message.append("\n");
   11278                     assertTrue("Incorrect output for checkConvertDouble2Uchar2" +
   11279                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   11280                 }
   11281             }
   11282         }
   11283     }
   11284 
   11285     private void checkConvertDouble3Uchar3() {
   11286         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_64, 3, 0x42b73512202aabbel, 0.0000000000000000000e+00, 2.5500000000000000000e+02);
   11287         try {
   11288             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE);
   11289             script.forEach_testConvertUchar3Double3Uchar3(inV, out);
   11290             verifyResultsConvertDouble3Uchar3(inV, out, false);
   11291         } catch (Exception e) {
   11292             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar3Double3Uchar3: " + e.toString());
   11293         }
   11294         try {
   11295             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE);
   11296             scriptRelaxed.forEach_testConvertUchar3Double3Uchar3(inV, out);
   11297             verifyResultsConvertDouble3Uchar3(inV, out, true);
   11298         } catch (Exception e) {
   11299             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar3Double3Uchar3: " + e.toString());
   11300         }
   11301     }
   11302 
   11303     private void verifyResultsConvertDouble3Uchar3(Allocation inV, Allocation out, boolean relaxed) {
   11304         double[] arrayInV = new double[INPUTSIZE * 4];
   11305         inV.copyTo(arrayInV);
   11306         byte[] arrayOut = new byte[INPUTSIZE * 4];
   11307         out.copyTo(arrayOut);
   11308         for (int i = 0; i < INPUTSIZE; i++) {
   11309             for (int j = 0; j < 3 ; j++) {
   11310                 // Extract the inputs.
   11311                 ArgumentsDoubleUchar args = new ArgumentsDoubleUchar();
   11312                 args.inV = arrayInV[i * 4 + j];
   11313                 // Figure out what the outputs should have been.
   11314                 CoreMathVerifier.computeConvert(args);
   11315                 // Validate the outputs.
   11316                 boolean valid = true;
   11317                 if (args.out != arrayOut[i * 4 + j]) {
   11318                     valid = false;
   11319                 }
   11320                 if (!valid) {
   11321                     StringBuilder message = new StringBuilder();
   11322                     message.append("Input inV: ");
   11323                     message.append(String.format("%24.8g {%16x} %31a",
   11324                             args.inV, Double.doubleToRawLongBits(args.inV), args.inV));
   11325                     message.append("\n");
   11326                     message.append("Expected output out: ");
   11327                     message.append(String.format("0x%x", args.out));
   11328                     message.append("\n");
   11329                     message.append("Actual   output out: ");
   11330                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   11331                     if (args.out != arrayOut[i * 4 + j]) {
   11332                         message.append(" FAIL");
   11333                     }
   11334                     message.append("\n");
   11335                     assertTrue("Incorrect output for checkConvertDouble3Uchar3" +
   11336                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   11337                 }
   11338             }
   11339         }
   11340     }
   11341 
   11342     private void checkConvertDouble4Uchar4() {
   11343         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_64, 4, 0x42b8fe2d1645cc9cl, 0.0000000000000000000e+00, 2.5500000000000000000e+02);
   11344         try {
   11345             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE);
   11346             script.forEach_testConvertUchar4Double4Uchar4(inV, out);
   11347             verifyResultsConvertDouble4Uchar4(inV, out, false);
   11348         } catch (Exception e) {
   11349             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar4Double4Uchar4: " + e.toString());
   11350         }
   11351         try {
   11352             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE);
   11353             scriptRelaxed.forEach_testConvertUchar4Double4Uchar4(inV, out);
   11354             verifyResultsConvertDouble4Uchar4(inV, out, true);
   11355         } catch (Exception e) {
   11356             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar4Double4Uchar4: " + e.toString());
   11357         }
   11358     }
   11359 
   11360     private void verifyResultsConvertDouble4Uchar4(Allocation inV, Allocation out, boolean relaxed) {
   11361         double[] arrayInV = new double[INPUTSIZE * 4];
   11362         inV.copyTo(arrayInV);
   11363         byte[] arrayOut = new byte[INPUTSIZE * 4];
   11364         out.copyTo(arrayOut);
   11365         for (int i = 0; i < INPUTSIZE; i++) {
   11366             for (int j = 0; j < 4 ; j++) {
   11367                 // Extract the inputs.
   11368                 ArgumentsDoubleUchar args = new ArgumentsDoubleUchar();
   11369                 args.inV = arrayInV[i * 4 + j];
   11370                 // Figure out what the outputs should have been.
   11371                 CoreMathVerifier.computeConvert(args);
   11372                 // Validate the outputs.
   11373                 boolean valid = true;
   11374                 if (args.out != arrayOut[i * 4 + j]) {
   11375                     valid = false;
   11376                 }
   11377                 if (!valid) {
   11378                     StringBuilder message = new StringBuilder();
   11379                     message.append("Input inV: ");
   11380                     message.append(String.format("%24.8g {%16x} %31a",
   11381                             args.inV, Double.doubleToRawLongBits(args.inV), args.inV));
   11382                     message.append("\n");
   11383                     message.append("Expected output out: ");
   11384                     message.append(String.format("0x%x", args.out));
   11385                     message.append("\n");
   11386                     message.append("Actual   output out: ");
   11387                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   11388                     if (args.out != arrayOut[i * 4 + j]) {
   11389                         message.append(" FAIL");
   11390                     }
   11391                     message.append("\n");
   11392                     assertTrue("Incorrect output for checkConvertDouble4Uchar4" +
   11393                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   11394                 }
   11395             }
   11396         }
   11397     }
   11398 
   11399     public class ArgumentsLongUchar {
   11400         public long inV;
   11401         public byte out;
   11402     }
   11403 
   11404     private void checkConvertLong2Uchar2() {
   11405         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_64, 2, 0x79f19ffa83d09ae7l, false, 8);
   11406         try {
   11407             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE);
   11408             script.forEach_testConvertUchar2Long2Uchar2(inV, out);
   11409             verifyResultsConvertLong2Uchar2(inV, out, false);
   11410         } catch (Exception e) {
   11411             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar2Long2Uchar2: " + e.toString());
   11412         }
   11413         try {
   11414             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE);
   11415             scriptRelaxed.forEach_testConvertUchar2Long2Uchar2(inV, out);
   11416             verifyResultsConvertLong2Uchar2(inV, out, true);
   11417         } catch (Exception e) {
   11418             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar2Long2Uchar2: " + e.toString());
   11419         }
   11420     }
   11421 
   11422     private void verifyResultsConvertLong2Uchar2(Allocation inV, Allocation out, boolean relaxed) {
   11423         long[] arrayInV = new long[INPUTSIZE * 2];
   11424         inV.copyTo(arrayInV);
   11425         byte[] arrayOut = new byte[INPUTSIZE * 2];
   11426         out.copyTo(arrayOut);
   11427         for (int i = 0; i < INPUTSIZE; i++) {
   11428             for (int j = 0; j < 2 ; j++) {
   11429                 // Extract the inputs.
   11430                 ArgumentsLongUchar args = new ArgumentsLongUchar();
   11431                 args.inV = arrayInV[i * 2 + j];
   11432                 // Figure out what the outputs should have been.
   11433                 CoreMathVerifier.computeConvert(args);
   11434                 // Validate the outputs.
   11435                 boolean valid = true;
   11436                 if (args.out != arrayOut[i * 2 + j]) {
   11437                     valid = false;
   11438                 }
   11439                 if (!valid) {
   11440                     StringBuilder message = new StringBuilder();
   11441                     message.append("Input inV: ");
   11442                     message.append(String.format("%d", args.inV));
   11443                     message.append("\n");
   11444                     message.append("Expected output out: ");
   11445                     message.append(String.format("0x%x", args.out));
   11446                     message.append("\n");
   11447                     message.append("Actual   output out: ");
   11448                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   11449                     if (args.out != arrayOut[i * 2 + j]) {
   11450                         message.append(" FAIL");
   11451                     }
   11452                     message.append("\n");
   11453                     assertTrue("Incorrect output for checkConvertLong2Uchar2" +
   11454                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   11455                 }
   11456             }
   11457         }
   11458     }
   11459 
   11460     private void checkConvertLong3Uchar3() {
   11461         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_64, 3, 0x79f3691579ebbbc5l, false, 8);
   11462         try {
   11463             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE);
   11464             script.forEach_testConvertUchar3Long3Uchar3(inV, out);
   11465             verifyResultsConvertLong3Uchar3(inV, out, false);
   11466         } catch (Exception e) {
   11467             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar3Long3Uchar3: " + e.toString());
   11468         }
   11469         try {
   11470             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE);
   11471             scriptRelaxed.forEach_testConvertUchar3Long3Uchar3(inV, out);
   11472             verifyResultsConvertLong3Uchar3(inV, out, true);
   11473         } catch (Exception e) {
   11474             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar3Long3Uchar3: " + e.toString());
   11475         }
   11476     }
   11477 
   11478     private void verifyResultsConvertLong3Uchar3(Allocation inV, Allocation out, boolean relaxed) {
   11479         long[] arrayInV = new long[INPUTSIZE * 4];
   11480         inV.copyTo(arrayInV);
   11481         byte[] arrayOut = new byte[INPUTSIZE * 4];
   11482         out.copyTo(arrayOut);
   11483         for (int i = 0; i < INPUTSIZE; i++) {
   11484             for (int j = 0; j < 3 ; j++) {
   11485                 // Extract the inputs.
   11486                 ArgumentsLongUchar args = new ArgumentsLongUchar();
   11487                 args.inV = arrayInV[i * 4 + j];
   11488                 // Figure out what the outputs should have been.
   11489                 CoreMathVerifier.computeConvert(args);
   11490                 // Validate the outputs.
   11491                 boolean valid = true;
   11492                 if (args.out != arrayOut[i * 4 + j]) {
   11493                     valid = false;
   11494                 }
   11495                 if (!valid) {
   11496                     StringBuilder message = new StringBuilder();
   11497                     message.append("Input inV: ");
   11498                     message.append(String.format("%d", args.inV));
   11499                     message.append("\n");
   11500                     message.append("Expected output out: ");
   11501                     message.append(String.format("0x%x", args.out));
   11502                     message.append("\n");
   11503                     message.append("Actual   output out: ");
   11504                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   11505                     if (args.out != arrayOut[i * 4 + j]) {
   11506                         message.append(" FAIL");
   11507                     }
   11508                     message.append("\n");
   11509                     assertTrue("Incorrect output for checkConvertLong3Uchar3" +
   11510                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   11511                 }
   11512             }
   11513         }
   11514     }
   11515 
   11516     private void checkConvertLong4Uchar4() {
   11517         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_64, 4, 0x79f532307006dca3l, false, 8);
   11518         try {
   11519             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE);
   11520             script.forEach_testConvertUchar4Long4Uchar4(inV, out);
   11521             verifyResultsConvertLong4Uchar4(inV, out, false);
   11522         } catch (Exception e) {
   11523             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar4Long4Uchar4: " + e.toString());
   11524         }
   11525         try {
   11526             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE);
   11527             scriptRelaxed.forEach_testConvertUchar4Long4Uchar4(inV, out);
   11528             verifyResultsConvertLong4Uchar4(inV, out, true);
   11529         } catch (Exception e) {
   11530             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar4Long4Uchar4: " + e.toString());
   11531         }
   11532     }
   11533 
   11534     private void verifyResultsConvertLong4Uchar4(Allocation inV, Allocation out, boolean relaxed) {
   11535         long[] arrayInV = new long[INPUTSIZE * 4];
   11536         inV.copyTo(arrayInV);
   11537         byte[] arrayOut = new byte[INPUTSIZE * 4];
   11538         out.copyTo(arrayOut);
   11539         for (int i = 0; i < INPUTSIZE; i++) {
   11540             for (int j = 0; j < 4 ; j++) {
   11541                 // Extract the inputs.
   11542                 ArgumentsLongUchar args = new ArgumentsLongUchar();
   11543                 args.inV = arrayInV[i * 4 + j];
   11544                 // Figure out what the outputs should have been.
   11545                 CoreMathVerifier.computeConvert(args);
   11546                 // Validate the outputs.
   11547                 boolean valid = true;
   11548                 if (args.out != arrayOut[i * 4 + j]) {
   11549                     valid = false;
   11550                 }
   11551                 if (!valid) {
   11552                     StringBuilder message = new StringBuilder();
   11553                     message.append("Input inV: ");
   11554                     message.append(String.format("%d", args.inV));
   11555                     message.append("\n");
   11556                     message.append("Expected output out: ");
   11557                     message.append(String.format("0x%x", args.out));
   11558                     message.append("\n");
   11559                     message.append("Actual   output out: ");
   11560                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   11561                     if (args.out != arrayOut[i * 4 + j]) {
   11562                         message.append(" FAIL");
   11563                     }
   11564                     message.append("\n");
   11565                     assertTrue("Incorrect output for checkConvertLong4Uchar4" +
   11566                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   11567                 }
   11568             }
   11569         }
   11570     }
   11571 
   11572     public class ArgumentsUlongUchar {
   11573         public long inV;
   11574         public byte out;
   11575     }
   11576 
   11577     private void checkConvertUlong2Uchar2() {
   11578         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_64, 2, 0x9ebfc0021fa8b492l, false, 8);
   11579         try {
   11580             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE);
   11581             script.forEach_testConvertUchar2Ulong2Uchar2(inV, out);
   11582             verifyResultsConvertUlong2Uchar2(inV, out, false);
   11583         } catch (Exception e) {
   11584             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar2Ulong2Uchar2: " + e.toString());
   11585         }
   11586         try {
   11587             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 2), INPUTSIZE);
   11588             scriptRelaxed.forEach_testConvertUchar2Ulong2Uchar2(inV, out);
   11589             verifyResultsConvertUlong2Uchar2(inV, out, true);
   11590         } catch (Exception e) {
   11591             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar2Ulong2Uchar2: " + e.toString());
   11592         }
   11593     }
   11594 
   11595     private void verifyResultsConvertUlong2Uchar2(Allocation inV, Allocation out, boolean relaxed) {
   11596         long[] arrayInV = new long[INPUTSIZE * 2];
   11597         inV.copyTo(arrayInV);
   11598         byte[] arrayOut = new byte[INPUTSIZE * 2];
   11599         out.copyTo(arrayOut);
   11600         for (int i = 0; i < INPUTSIZE; i++) {
   11601             for (int j = 0; j < 2 ; j++) {
   11602                 // Extract the inputs.
   11603                 ArgumentsUlongUchar args = new ArgumentsUlongUchar();
   11604                 args.inV = arrayInV[i * 2 + j];
   11605                 // Figure out what the outputs should have been.
   11606                 CoreMathVerifier.computeConvert(args);
   11607                 // Validate the outputs.
   11608                 boolean valid = true;
   11609                 if (args.out != arrayOut[i * 2 + j]) {
   11610                     valid = false;
   11611                 }
   11612                 if (!valid) {
   11613                     StringBuilder message = new StringBuilder();
   11614                     message.append("Input inV: ");
   11615                     message.append(String.format("0x%x", args.inV));
   11616                     message.append("\n");
   11617                     message.append("Expected output out: ");
   11618                     message.append(String.format("0x%x", args.out));
   11619                     message.append("\n");
   11620                     message.append("Actual   output out: ");
   11621                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   11622                     if (args.out != arrayOut[i * 2 + j]) {
   11623                         message.append(" FAIL");
   11624                     }
   11625                     message.append("\n");
   11626                     assertTrue("Incorrect output for checkConvertUlong2Uchar2" +
   11627                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   11628                 }
   11629             }
   11630         }
   11631     }
   11632 
   11633     private void checkConvertUlong3Uchar3() {
   11634         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_64, 3, 0x9ec1891d15c3d570l, false, 8);
   11635         try {
   11636             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE);
   11637             script.forEach_testConvertUchar3Ulong3Uchar3(inV, out);
   11638             verifyResultsConvertUlong3Uchar3(inV, out, false);
   11639         } catch (Exception e) {
   11640             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar3Ulong3Uchar3: " + e.toString());
   11641         }
   11642         try {
   11643             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 3), INPUTSIZE);
   11644             scriptRelaxed.forEach_testConvertUchar3Ulong3Uchar3(inV, out);
   11645             verifyResultsConvertUlong3Uchar3(inV, out, true);
   11646         } catch (Exception e) {
   11647             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar3Ulong3Uchar3: " + e.toString());
   11648         }
   11649     }
   11650 
   11651     private void verifyResultsConvertUlong3Uchar3(Allocation inV, Allocation out, boolean relaxed) {
   11652         long[] arrayInV = new long[INPUTSIZE * 4];
   11653         inV.copyTo(arrayInV);
   11654         byte[] arrayOut = new byte[INPUTSIZE * 4];
   11655         out.copyTo(arrayOut);
   11656         for (int i = 0; i < INPUTSIZE; i++) {
   11657             for (int j = 0; j < 3 ; j++) {
   11658                 // Extract the inputs.
   11659                 ArgumentsUlongUchar args = new ArgumentsUlongUchar();
   11660                 args.inV = arrayInV[i * 4 + j];
   11661                 // Figure out what the outputs should have been.
   11662                 CoreMathVerifier.computeConvert(args);
   11663                 // Validate the outputs.
   11664                 boolean valid = true;
   11665                 if (args.out != arrayOut[i * 4 + j]) {
   11666                     valid = false;
   11667                 }
   11668                 if (!valid) {
   11669                     StringBuilder message = new StringBuilder();
   11670                     message.append("Input inV: ");
   11671                     message.append(String.format("0x%x", args.inV));
   11672                     message.append("\n");
   11673                     message.append("Expected output out: ");
   11674                     message.append(String.format("0x%x", args.out));
   11675                     message.append("\n");
   11676                     message.append("Actual   output out: ");
   11677                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   11678                     if (args.out != arrayOut[i * 4 + j]) {
   11679                         message.append(" FAIL");
   11680                     }
   11681                     message.append("\n");
   11682                     assertTrue("Incorrect output for checkConvertUlong3Uchar3" +
   11683                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   11684                 }
   11685             }
   11686         }
   11687     }
   11688 
   11689     private void checkConvertUlong4Uchar4() {
   11690         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_64, 4, 0x9ec352380bdef64el, false, 8);
   11691         try {
   11692             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE);
   11693             script.forEach_testConvertUchar4Ulong4Uchar4(inV, out);
   11694             verifyResultsConvertUlong4Uchar4(inV, out, false);
   11695         } catch (Exception e) {
   11696             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar4Ulong4Uchar4: " + e.toString());
   11697         }
   11698         try {
   11699             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_8, 4), INPUTSIZE);
   11700             scriptRelaxed.forEach_testConvertUchar4Ulong4Uchar4(inV, out);
   11701             verifyResultsConvertUlong4Uchar4(inV, out, true);
   11702         } catch (Exception e) {
   11703             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUchar4Ulong4Uchar4: " + e.toString());
   11704         }
   11705     }
   11706 
   11707     private void verifyResultsConvertUlong4Uchar4(Allocation inV, Allocation out, boolean relaxed) {
   11708         long[] arrayInV = new long[INPUTSIZE * 4];
   11709         inV.copyTo(arrayInV);
   11710         byte[] arrayOut = new byte[INPUTSIZE * 4];
   11711         out.copyTo(arrayOut);
   11712         for (int i = 0; i < INPUTSIZE; i++) {
   11713             for (int j = 0; j < 4 ; j++) {
   11714                 // Extract the inputs.
   11715                 ArgumentsUlongUchar args = new ArgumentsUlongUchar();
   11716                 args.inV = arrayInV[i * 4 + j];
   11717                 // Figure out what the outputs should have been.
   11718                 CoreMathVerifier.computeConvert(args);
   11719                 // Validate the outputs.
   11720                 boolean valid = true;
   11721                 if (args.out != arrayOut[i * 4 + j]) {
   11722                     valid = false;
   11723                 }
   11724                 if (!valid) {
   11725                     StringBuilder message = new StringBuilder();
   11726                     message.append("Input inV: ");
   11727                     message.append(String.format("0x%x", args.inV));
   11728                     message.append("\n");
   11729                     message.append("Expected output out: ");
   11730                     message.append(String.format("0x%x", args.out));
   11731                     message.append("\n");
   11732                     message.append("Actual   output out: ");
   11733                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   11734                     if (args.out != arrayOut[i * 4 + j]) {
   11735                         message.append(" FAIL");
   11736                     }
   11737                     message.append("\n");
   11738                     assertTrue("Incorrect output for checkConvertUlong4Uchar4" +
   11739                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   11740                 }
   11741             }
   11742         }
   11743     }
   11744 
   11745     public class ArgumentsDoubleShort {
   11746         public double inV;
   11747         public short out;
   11748     }
   11749 
   11750     private void checkConvertDouble2Short2() {
   11751         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_64, 2, 0x42b557fbbf1d55f9l, -3.2768000000000000000e+04, 3.2767000000000000000e+04);
   11752         try {
   11753             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 2), INPUTSIZE);
   11754             script.forEach_testConvertShort2Double2Short2(inV, out);
   11755             verifyResultsConvertDouble2Short2(inV, out, false);
   11756         } catch (Exception e) {
   11757             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort2Double2Short2: " + e.toString());
   11758         }
   11759         try {
   11760             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 2), INPUTSIZE);
   11761             scriptRelaxed.forEach_testConvertShort2Double2Short2(inV, out);
   11762             verifyResultsConvertDouble2Short2(inV, out, true);
   11763         } catch (Exception e) {
   11764             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort2Double2Short2: " + e.toString());
   11765         }
   11766     }
   11767 
   11768     private void verifyResultsConvertDouble2Short2(Allocation inV, Allocation out, boolean relaxed) {
   11769         double[] arrayInV = new double[INPUTSIZE * 2];
   11770         inV.copyTo(arrayInV);
   11771         short[] arrayOut = new short[INPUTSIZE * 2];
   11772         out.copyTo(arrayOut);
   11773         for (int i = 0; i < INPUTSIZE; i++) {
   11774             for (int j = 0; j < 2 ; j++) {
   11775                 // Extract the inputs.
   11776                 ArgumentsDoubleShort args = new ArgumentsDoubleShort();
   11777                 args.inV = arrayInV[i * 2 + j];
   11778                 // Figure out what the outputs should have been.
   11779                 CoreMathVerifier.computeConvert(args);
   11780                 // Validate the outputs.
   11781                 boolean valid = true;
   11782                 if (args.out != arrayOut[i * 2 + j]) {
   11783                     valid = false;
   11784                 }
   11785                 if (!valid) {
   11786                     StringBuilder message = new StringBuilder();
   11787                     message.append("Input inV: ");
   11788                     message.append(String.format("%24.8g {%16x} %31a",
   11789                             args.inV, Double.doubleToRawLongBits(args.inV), args.inV));
   11790                     message.append("\n");
   11791                     message.append("Expected output out: ");
   11792                     message.append(String.format("%d", args.out));
   11793                     message.append("\n");
   11794                     message.append("Actual   output out: ");
   11795                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   11796                     if (args.out != arrayOut[i * 2 + j]) {
   11797                         message.append(" FAIL");
   11798                     }
   11799                     message.append("\n");
   11800                     assertTrue("Incorrect output for checkConvertDouble2Short2" +
   11801                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   11802                 }
   11803             }
   11804         }
   11805     }
   11806 
   11807     private void checkConvertDouble3Short3() {
   11808         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_64, 3, 0x42b72116b53876d7l, -3.2768000000000000000e+04, 3.2767000000000000000e+04);
   11809         try {
   11810             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 3), INPUTSIZE);
   11811             script.forEach_testConvertShort3Double3Short3(inV, out);
   11812             verifyResultsConvertDouble3Short3(inV, out, false);
   11813         } catch (Exception e) {
   11814             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort3Double3Short3: " + e.toString());
   11815         }
   11816         try {
   11817             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 3), INPUTSIZE);
   11818             scriptRelaxed.forEach_testConvertShort3Double3Short3(inV, out);
   11819             verifyResultsConvertDouble3Short3(inV, out, true);
   11820         } catch (Exception e) {
   11821             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort3Double3Short3: " + e.toString());
   11822         }
   11823     }
   11824 
   11825     private void verifyResultsConvertDouble3Short3(Allocation inV, Allocation out, boolean relaxed) {
   11826         double[] arrayInV = new double[INPUTSIZE * 4];
   11827         inV.copyTo(arrayInV);
   11828         short[] arrayOut = new short[INPUTSIZE * 4];
   11829         out.copyTo(arrayOut);
   11830         for (int i = 0; i < INPUTSIZE; i++) {
   11831             for (int j = 0; j < 3 ; j++) {
   11832                 // Extract the inputs.
   11833                 ArgumentsDoubleShort args = new ArgumentsDoubleShort();
   11834                 args.inV = arrayInV[i * 4 + j];
   11835                 // Figure out what the outputs should have been.
   11836                 CoreMathVerifier.computeConvert(args);
   11837                 // Validate the outputs.
   11838                 boolean valid = true;
   11839                 if (args.out != arrayOut[i * 4 + j]) {
   11840                     valid = false;
   11841                 }
   11842                 if (!valid) {
   11843                     StringBuilder message = new StringBuilder();
   11844                     message.append("Input inV: ");
   11845                     message.append(String.format("%24.8g {%16x} %31a",
   11846                             args.inV, Double.doubleToRawLongBits(args.inV), args.inV));
   11847                     message.append("\n");
   11848                     message.append("Expected output out: ");
   11849                     message.append(String.format("%d", args.out));
   11850                     message.append("\n");
   11851                     message.append("Actual   output out: ");
   11852                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   11853                     if (args.out != arrayOut[i * 4 + j]) {
   11854                         message.append(" FAIL");
   11855                     }
   11856                     message.append("\n");
   11857                     assertTrue("Incorrect output for checkConvertDouble3Short3" +
   11858                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   11859                 }
   11860             }
   11861         }
   11862     }
   11863 
   11864     private void checkConvertDouble4Short4() {
   11865         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_64, 4, 0x42b8ea31ab5397b5l, -3.2768000000000000000e+04, 3.2767000000000000000e+04);
   11866         try {
   11867             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 4), INPUTSIZE);
   11868             script.forEach_testConvertShort4Double4Short4(inV, out);
   11869             verifyResultsConvertDouble4Short4(inV, out, false);
   11870         } catch (Exception e) {
   11871             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort4Double4Short4: " + e.toString());
   11872         }
   11873         try {
   11874             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 4), INPUTSIZE);
   11875             scriptRelaxed.forEach_testConvertShort4Double4Short4(inV, out);
   11876             verifyResultsConvertDouble4Short4(inV, out, true);
   11877         } catch (Exception e) {
   11878             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort4Double4Short4: " + e.toString());
   11879         }
   11880     }
   11881 
   11882     private void verifyResultsConvertDouble4Short4(Allocation inV, Allocation out, boolean relaxed) {
   11883         double[] arrayInV = new double[INPUTSIZE * 4];
   11884         inV.copyTo(arrayInV);
   11885         short[] arrayOut = new short[INPUTSIZE * 4];
   11886         out.copyTo(arrayOut);
   11887         for (int i = 0; i < INPUTSIZE; i++) {
   11888             for (int j = 0; j < 4 ; j++) {
   11889                 // Extract the inputs.
   11890                 ArgumentsDoubleShort args = new ArgumentsDoubleShort();
   11891                 args.inV = arrayInV[i * 4 + j];
   11892                 // Figure out what the outputs should have been.
   11893                 CoreMathVerifier.computeConvert(args);
   11894                 // Validate the outputs.
   11895                 boolean valid = true;
   11896                 if (args.out != arrayOut[i * 4 + j]) {
   11897                     valid = false;
   11898                 }
   11899                 if (!valid) {
   11900                     StringBuilder message = new StringBuilder();
   11901                     message.append("Input inV: ");
   11902                     message.append(String.format("%24.8g {%16x} %31a",
   11903                             args.inV, Double.doubleToRawLongBits(args.inV), args.inV));
   11904                     message.append("\n");
   11905                     message.append("Expected output out: ");
   11906                     message.append(String.format("%d", args.out));
   11907                     message.append("\n");
   11908                     message.append("Actual   output out: ");
   11909                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   11910                     if (args.out != arrayOut[i * 4 + j]) {
   11911                         message.append(" FAIL");
   11912                     }
   11913                     message.append("\n");
   11914                     assertTrue("Incorrect output for checkConvertDouble4Short4" +
   11915                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   11916                 }
   11917             }
   11918         }
   11919     }
   11920 
   11921     public class ArgumentsLongShort {
   11922         public long inV;
   11923         public short out;
   11924     }
   11925 
   11926     private void checkConvertLong2Short2() {
   11927         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_64, 2, 0x79f18bff18de6600l, true, 15);
   11928         try {
   11929             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 2), INPUTSIZE);
   11930             script.forEach_testConvertShort2Long2Short2(inV, out);
   11931             verifyResultsConvertLong2Short2(inV, out, false);
   11932         } catch (Exception e) {
   11933             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort2Long2Short2: " + e.toString());
   11934         }
   11935         try {
   11936             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 2), INPUTSIZE);
   11937             scriptRelaxed.forEach_testConvertShort2Long2Short2(inV, out);
   11938             verifyResultsConvertLong2Short2(inV, out, true);
   11939         } catch (Exception e) {
   11940             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort2Long2Short2: " + e.toString());
   11941         }
   11942     }
   11943 
   11944     private void verifyResultsConvertLong2Short2(Allocation inV, Allocation out, boolean relaxed) {
   11945         long[] arrayInV = new long[INPUTSIZE * 2];
   11946         inV.copyTo(arrayInV);
   11947         short[] arrayOut = new short[INPUTSIZE * 2];
   11948         out.copyTo(arrayOut);
   11949         for (int i = 0; i < INPUTSIZE; i++) {
   11950             for (int j = 0; j < 2 ; j++) {
   11951                 // Extract the inputs.
   11952                 ArgumentsLongShort args = new ArgumentsLongShort();
   11953                 args.inV = arrayInV[i * 2 + j];
   11954                 // Figure out what the outputs should have been.
   11955                 CoreMathVerifier.computeConvert(args);
   11956                 // Validate the outputs.
   11957                 boolean valid = true;
   11958                 if (args.out != arrayOut[i * 2 + j]) {
   11959                     valid = false;
   11960                 }
   11961                 if (!valid) {
   11962                     StringBuilder message = new StringBuilder();
   11963                     message.append("Input inV: ");
   11964                     message.append(String.format("%d", args.inV));
   11965                     message.append("\n");
   11966                     message.append("Expected output out: ");
   11967                     message.append(String.format("%d", args.out));
   11968                     message.append("\n");
   11969                     message.append("Actual   output out: ");
   11970                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   11971                     if (args.out != arrayOut[i * 2 + j]) {
   11972                         message.append(" FAIL");
   11973                     }
   11974                     message.append("\n");
   11975                     assertTrue("Incorrect output for checkConvertLong2Short2" +
   11976                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   11977                 }
   11978             }
   11979         }
   11980     }
   11981 
   11982     private void checkConvertLong3Short3() {
   11983         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_64, 3, 0x79f3551a0ef986del, true, 15);
   11984         try {
   11985             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 3), INPUTSIZE);
   11986             script.forEach_testConvertShort3Long3Short3(inV, out);
   11987             verifyResultsConvertLong3Short3(inV, out, false);
   11988         } catch (Exception e) {
   11989             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort3Long3Short3: " + e.toString());
   11990         }
   11991         try {
   11992             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 3), INPUTSIZE);
   11993             scriptRelaxed.forEach_testConvertShort3Long3Short3(inV, out);
   11994             verifyResultsConvertLong3Short3(inV, out, true);
   11995         } catch (Exception e) {
   11996             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort3Long3Short3: " + e.toString());
   11997         }
   11998     }
   11999 
   12000     private void verifyResultsConvertLong3Short3(Allocation inV, Allocation out, boolean relaxed) {
   12001         long[] arrayInV = new long[INPUTSIZE * 4];
   12002         inV.copyTo(arrayInV);
   12003         short[] arrayOut = new short[INPUTSIZE * 4];
   12004         out.copyTo(arrayOut);
   12005         for (int i = 0; i < INPUTSIZE; i++) {
   12006             for (int j = 0; j < 3 ; j++) {
   12007                 // Extract the inputs.
   12008                 ArgumentsLongShort args = new ArgumentsLongShort();
   12009                 args.inV = arrayInV[i * 4 + j];
   12010                 // Figure out what the outputs should have been.
   12011                 CoreMathVerifier.computeConvert(args);
   12012                 // Validate the outputs.
   12013                 boolean valid = true;
   12014                 if (args.out != arrayOut[i * 4 + j]) {
   12015                     valid = false;
   12016                 }
   12017                 if (!valid) {
   12018                     StringBuilder message = new StringBuilder();
   12019                     message.append("Input inV: ");
   12020                     message.append(String.format("%d", args.inV));
   12021                     message.append("\n");
   12022                     message.append("Expected output out: ");
   12023                     message.append(String.format("%d", args.out));
   12024                     message.append("\n");
   12025                     message.append("Actual   output out: ");
   12026                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   12027                     if (args.out != arrayOut[i * 4 + j]) {
   12028                         message.append(" FAIL");
   12029                     }
   12030                     message.append("\n");
   12031                     assertTrue("Incorrect output for checkConvertLong3Short3" +
   12032                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   12033                 }
   12034             }
   12035         }
   12036     }
   12037 
   12038     private void checkConvertLong4Short4() {
   12039         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_64, 4, 0x79f51e350514a7bcl, true, 15);
   12040         try {
   12041             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 4), INPUTSIZE);
   12042             script.forEach_testConvertShort4Long4Short4(inV, out);
   12043             verifyResultsConvertLong4Short4(inV, out, false);
   12044         } catch (Exception e) {
   12045             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort4Long4Short4: " + e.toString());
   12046         }
   12047         try {
   12048             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 4), INPUTSIZE);
   12049             scriptRelaxed.forEach_testConvertShort4Long4Short4(inV, out);
   12050             verifyResultsConvertLong4Short4(inV, out, true);
   12051         } catch (Exception e) {
   12052             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort4Long4Short4: " + e.toString());
   12053         }
   12054     }
   12055 
   12056     private void verifyResultsConvertLong4Short4(Allocation inV, Allocation out, boolean relaxed) {
   12057         long[] arrayInV = new long[INPUTSIZE * 4];
   12058         inV.copyTo(arrayInV);
   12059         short[] arrayOut = new short[INPUTSIZE * 4];
   12060         out.copyTo(arrayOut);
   12061         for (int i = 0; i < INPUTSIZE; i++) {
   12062             for (int j = 0; j < 4 ; j++) {
   12063                 // Extract the inputs.
   12064                 ArgumentsLongShort args = new ArgumentsLongShort();
   12065                 args.inV = arrayInV[i * 4 + j];
   12066                 // Figure out what the outputs should have been.
   12067                 CoreMathVerifier.computeConvert(args);
   12068                 // Validate the outputs.
   12069                 boolean valid = true;
   12070                 if (args.out != arrayOut[i * 4 + j]) {
   12071                     valid = false;
   12072                 }
   12073                 if (!valid) {
   12074                     StringBuilder message = new StringBuilder();
   12075                     message.append("Input inV: ");
   12076                     message.append(String.format("%d", args.inV));
   12077                     message.append("\n");
   12078                     message.append("Expected output out: ");
   12079                     message.append(String.format("%d", args.out));
   12080                     message.append("\n");
   12081                     message.append("Actual   output out: ");
   12082                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   12083                     if (args.out != arrayOut[i * 4 + j]) {
   12084                         message.append(" FAIL");
   12085                     }
   12086                     message.append("\n");
   12087                     assertTrue("Incorrect output for checkConvertLong4Short4" +
   12088                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   12089                 }
   12090             }
   12091         }
   12092     }
   12093 
   12094     public class ArgumentsUlongShort {
   12095         public long inV;
   12096         public short out;
   12097     }
   12098 
   12099     private void checkConvertUlong2Short2() {
   12100         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_64, 2, 0x9ebfac06b4b67fabl, false, 15);
   12101         try {
   12102             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 2), INPUTSIZE);
   12103             script.forEach_testConvertShort2Ulong2Short2(inV, out);
   12104             verifyResultsConvertUlong2Short2(inV, out, false);
   12105         } catch (Exception e) {
   12106             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort2Ulong2Short2: " + e.toString());
   12107         }
   12108         try {
   12109             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 2), INPUTSIZE);
   12110             scriptRelaxed.forEach_testConvertShort2Ulong2Short2(inV, out);
   12111             verifyResultsConvertUlong2Short2(inV, out, true);
   12112         } catch (Exception e) {
   12113             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort2Ulong2Short2: " + e.toString());
   12114         }
   12115     }
   12116 
   12117     private void verifyResultsConvertUlong2Short2(Allocation inV, Allocation out, boolean relaxed) {
   12118         long[] arrayInV = new long[INPUTSIZE * 2];
   12119         inV.copyTo(arrayInV);
   12120         short[] arrayOut = new short[INPUTSIZE * 2];
   12121         out.copyTo(arrayOut);
   12122         for (int i = 0; i < INPUTSIZE; i++) {
   12123             for (int j = 0; j < 2 ; j++) {
   12124                 // Extract the inputs.
   12125                 ArgumentsUlongShort args = new ArgumentsUlongShort();
   12126                 args.inV = arrayInV[i * 2 + j];
   12127                 // Figure out what the outputs should have been.
   12128                 CoreMathVerifier.computeConvert(args);
   12129                 // Validate the outputs.
   12130                 boolean valid = true;
   12131                 if (args.out != arrayOut[i * 2 + j]) {
   12132                     valid = false;
   12133                 }
   12134                 if (!valid) {
   12135                     StringBuilder message = new StringBuilder();
   12136                     message.append("Input inV: ");
   12137                     message.append(String.format("0x%x", args.inV));
   12138                     message.append("\n");
   12139                     message.append("Expected output out: ");
   12140                     message.append(String.format("%d", args.out));
   12141                     message.append("\n");
   12142                     message.append("Actual   output out: ");
   12143                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   12144                     if (args.out != arrayOut[i * 2 + j]) {
   12145                         message.append(" FAIL");
   12146                     }
   12147                     message.append("\n");
   12148                     assertTrue("Incorrect output for checkConvertUlong2Short2" +
   12149                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   12150                 }
   12151             }
   12152         }
   12153     }
   12154 
   12155     private void checkConvertUlong3Short3() {
   12156         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_64, 3, 0x9ec17521aad1a089l, false, 15);
   12157         try {
   12158             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 3), INPUTSIZE);
   12159             script.forEach_testConvertShort3Ulong3Short3(inV, out);
   12160             verifyResultsConvertUlong3Short3(inV, out, false);
   12161         } catch (Exception e) {
   12162             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort3Ulong3Short3: " + e.toString());
   12163         }
   12164         try {
   12165             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 3), INPUTSIZE);
   12166             scriptRelaxed.forEach_testConvertShort3Ulong3Short3(inV, out);
   12167             verifyResultsConvertUlong3Short3(inV, out, true);
   12168         } catch (Exception e) {
   12169             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort3Ulong3Short3: " + e.toString());
   12170         }
   12171     }
   12172 
   12173     private void verifyResultsConvertUlong3Short3(Allocation inV, Allocation out, boolean relaxed) {
   12174         long[] arrayInV = new long[INPUTSIZE * 4];
   12175         inV.copyTo(arrayInV);
   12176         short[] arrayOut = new short[INPUTSIZE * 4];
   12177         out.copyTo(arrayOut);
   12178         for (int i = 0; i < INPUTSIZE; i++) {
   12179             for (int j = 0; j < 3 ; j++) {
   12180                 // Extract the inputs.
   12181                 ArgumentsUlongShort args = new ArgumentsUlongShort();
   12182                 args.inV = arrayInV[i * 4 + j];
   12183                 // Figure out what the outputs should have been.
   12184                 CoreMathVerifier.computeConvert(args);
   12185                 // Validate the outputs.
   12186                 boolean valid = true;
   12187                 if (args.out != arrayOut[i * 4 + j]) {
   12188                     valid = false;
   12189                 }
   12190                 if (!valid) {
   12191                     StringBuilder message = new StringBuilder();
   12192                     message.append("Input inV: ");
   12193                     message.append(String.format("0x%x", args.inV));
   12194                     message.append("\n");
   12195                     message.append("Expected output out: ");
   12196                     message.append(String.format("%d", args.out));
   12197                     message.append("\n");
   12198                     message.append("Actual   output out: ");
   12199                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   12200                     if (args.out != arrayOut[i * 4 + j]) {
   12201                         message.append(" FAIL");
   12202                     }
   12203                     message.append("\n");
   12204                     assertTrue("Incorrect output for checkConvertUlong3Short3" +
   12205                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   12206                 }
   12207             }
   12208         }
   12209     }
   12210 
   12211     private void checkConvertUlong4Short4() {
   12212         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_64, 4, 0x9ec33e3ca0ecc167l, false, 15);
   12213         try {
   12214             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 4), INPUTSIZE);
   12215             script.forEach_testConvertShort4Ulong4Short4(inV, out);
   12216             verifyResultsConvertUlong4Short4(inV, out, false);
   12217         } catch (Exception e) {
   12218             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort4Ulong4Short4: " + e.toString());
   12219         }
   12220         try {
   12221             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_16, 4), INPUTSIZE);
   12222             scriptRelaxed.forEach_testConvertShort4Ulong4Short4(inV, out);
   12223             verifyResultsConvertUlong4Short4(inV, out, true);
   12224         } catch (Exception e) {
   12225             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertShort4Ulong4Short4: " + e.toString());
   12226         }
   12227     }
   12228 
   12229     private void verifyResultsConvertUlong4Short4(Allocation inV, Allocation out, boolean relaxed) {
   12230         long[] arrayInV = new long[INPUTSIZE * 4];
   12231         inV.copyTo(arrayInV);
   12232         short[] arrayOut = new short[INPUTSIZE * 4];
   12233         out.copyTo(arrayOut);
   12234         for (int i = 0; i < INPUTSIZE; i++) {
   12235             for (int j = 0; j < 4 ; j++) {
   12236                 // Extract the inputs.
   12237                 ArgumentsUlongShort args = new ArgumentsUlongShort();
   12238                 args.inV = arrayInV[i * 4 + j];
   12239                 // Figure out what the outputs should have been.
   12240                 CoreMathVerifier.computeConvert(args);
   12241                 // Validate the outputs.
   12242                 boolean valid = true;
   12243                 if (args.out != arrayOut[i * 4 + j]) {
   12244                     valid = false;
   12245                 }
   12246                 if (!valid) {
   12247                     StringBuilder message = new StringBuilder();
   12248                     message.append("Input inV: ");
   12249                     message.append(String.format("0x%x", args.inV));
   12250                     message.append("\n");
   12251                     message.append("Expected output out: ");
   12252                     message.append(String.format("%d", args.out));
   12253                     message.append("\n");
   12254                     message.append("Actual   output out: ");
   12255                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   12256                     if (args.out != arrayOut[i * 4 + j]) {
   12257                         message.append(" FAIL");
   12258                     }
   12259                     message.append("\n");
   12260                     assertTrue("Incorrect output for checkConvertUlong4Short4" +
   12261                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   12262                 }
   12263             }
   12264         }
   12265     }
   12266 
   12267     public class ArgumentsDoubleUshort {
   12268         public double inV;
   12269         public short out;
   12270     }
   12271 
   12272     private void checkConvertDouble2Ushort2() {
   12273         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_64, 2, 0x3479ccaea92a37bcl, 0.0000000000000000000e+00, 6.5535000000000000000e+04);
   12274         try {
   12275             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE);
   12276             script.forEach_testConvertUshort2Double2Ushort2(inV, out);
   12277             verifyResultsConvertDouble2Ushort2(inV, out, false);
   12278         } catch (Exception e) {
   12279             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort2Double2Ushort2: " + e.toString());
   12280         }
   12281         try {
   12282             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE);
   12283             scriptRelaxed.forEach_testConvertUshort2Double2Ushort2(inV, out);
   12284             verifyResultsConvertDouble2Ushort2(inV, out, true);
   12285         } catch (Exception e) {
   12286             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort2Double2Ushort2: " + e.toString());
   12287         }
   12288     }
   12289 
   12290     private void verifyResultsConvertDouble2Ushort2(Allocation inV, Allocation out, boolean relaxed) {
   12291         double[] arrayInV = new double[INPUTSIZE * 2];
   12292         inV.copyTo(arrayInV);
   12293         short[] arrayOut = new short[INPUTSIZE * 2];
   12294         out.copyTo(arrayOut);
   12295         for (int i = 0; i < INPUTSIZE; i++) {
   12296             for (int j = 0; j < 2 ; j++) {
   12297                 // Extract the inputs.
   12298                 ArgumentsDoubleUshort args = new ArgumentsDoubleUshort();
   12299                 args.inV = arrayInV[i * 2 + j];
   12300                 // Figure out what the outputs should have been.
   12301                 CoreMathVerifier.computeConvert(args);
   12302                 // Validate the outputs.
   12303                 boolean valid = true;
   12304                 if (args.out != arrayOut[i * 2 + j]) {
   12305                     valid = false;
   12306                 }
   12307                 if (!valid) {
   12308                     StringBuilder message = new StringBuilder();
   12309                     message.append("Input inV: ");
   12310                     message.append(String.format("%24.8g {%16x} %31a",
   12311                             args.inV, Double.doubleToRawLongBits(args.inV), args.inV));
   12312                     message.append("\n");
   12313                     message.append("Expected output out: ");
   12314                     message.append(String.format("0x%x", args.out));
   12315                     message.append("\n");
   12316                     message.append("Actual   output out: ");
   12317                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   12318                     if (args.out != arrayOut[i * 2 + j]) {
   12319                         message.append(" FAIL");
   12320                     }
   12321                     message.append("\n");
   12322                     assertTrue("Incorrect output for checkConvertDouble2Ushort2" +
   12323                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   12324                 }
   12325             }
   12326         }
   12327     }
   12328 
   12329     private void checkConvertDouble3Ushort3() {
   12330         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_64, 3, 0x34c69435ff85c8e8l, 0.0000000000000000000e+00, 6.5535000000000000000e+04);
   12331         try {
   12332             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE);
   12333             script.forEach_testConvertUshort3Double3Ushort3(inV, out);
   12334             verifyResultsConvertDouble3Ushort3(inV, out, false);
   12335         } catch (Exception e) {
   12336             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort3Double3Ushort3: " + e.toString());
   12337         }
   12338         try {
   12339             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE);
   12340             scriptRelaxed.forEach_testConvertUshort3Double3Ushort3(inV, out);
   12341             verifyResultsConvertDouble3Ushort3(inV, out, true);
   12342         } catch (Exception e) {
   12343             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort3Double3Ushort3: " + e.toString());
   12344         }
   12345     }
   12346 
   12347     private void verifyResultsConvertDouble3Ushort3(Allocation inV, Allocation out, boolean relaxed) {
   12348         double[] arrayInV = new double[INPUTSIZE * 4];
   12349         inV.copyTo(arrayInV);
   12350         short[] arrayOut = new short[INPUTSIZE * 4];
   12351         out.copyTo(arrayOut);
   12352         for (int i = 0; i < INPUTSIZE; i++) {
   12353             for (int j = 0; j < 3 ; j++) {
   12354                 // Extract the inputs.
   12355                 ArgumentsDoubleUshort args = new ArgumentsDoubleUshort();
   12356                 args.inV = arrayInV[i * 4 + j];
   12357                 // Figure out what the outputs should have been.
   12358                 CoreMathVerifier.computeConvert(args);
   12359                 // Validate the outputs.
   12360                 boolean valid = true;
   12361                 if (args.out != arrayOut[i * 4 + j]) {
   12362                     valid = false;
   12363                 }
   12364                 if (!valid) {
   12365                     StringBuilder message = new StringBuilder();
   12366                     message.append("Input inV: ");
   12367                     message.append(String.format("%24.8g {%16x} %31a",
   12368                             args.inV, Double.doubleToRawLongBits(args.inV), args.inV));
   12369                     message.append("\n");
   12370                     message.append("Expected output out: ");
   12371                     message.append(String.format("0x%x", args.out));
   12372                     message.append("\n");
   12373                     message.append("Actual   output out: ");
   12374                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   12375                     if (args.out != arrayOut[i * 4 + j]) {
   12376                         message.append(" FAIL");
   12377                     }
   12378                     message.append("\n");
   12379                     assertTrue("Incorrect output for checkConvertDouble3Ushort3" +
   12380                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   12381                 }
   12382             }
   12383         }
   12384     }
   12385 
   12386     private void checkConvertDouble4Ushort4() {
   12387         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_64, 4, 0x35135bbd55e15a14l, 0.0000000000000000000e+00, 6.5535000000000000000e+04);
   12388         try {
   12389             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE);
   12390             script.forEach_testConvertUshort4Double4Ushort4(inV, out);
   12391             verifyResultsConvertDouble4Ushort4(inV, out, false);
   12392         } catch (Exception e) {
   12393             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort4Double4Ushort4: " + e.toString());
   12394         }
   12395         try {
   12396             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE);
   12397             scriptRelaxed.forEach_testConvertUshort4Double4Ushort4(inV, out);
   12398             verifyResultsConvertDouble4Ushort4(inV, out, true);
   12399         } catch (Exception e) {
   12400             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort4Double4Ushort4: " + e.toString());
   12401         }
   12402     }
   12403 
   12404     private void verifyResultsConvertDouble4Ushort4(Allocation inV, Allocation out, boolean relaxed) {
   12405         double[] arrayInV = new double[INPUTSIZE * 4];
   12406         inV.copyTo(arrayInV);
   12407         short[] arrayOut = new short[INPUTSIZE * 4];
   12408         out.copyTo(arrayOut);
   12409         for (int i = 0; i < INPUTSIZE; i++) {
   12410             for (int j = 0; j < 4 ; j++) {
   12411                 // Extract the inputs.
   12412                 ArgumentsDoubleUshort args = new ArgumentsDoubleUshort();
   12413                 args.inV = arrayInV[i * 4 + j];
   12414                 // Figure out what the outputs should have been.
   12415                 CoreMathVerifier.computeConvert(args);
   12416                 // Validate the outputs.
   12417                 boolean valid = true;
   12418                 if (args.out != arrayOut[i * 4 + j]) {
   12419                     valid = false;
   12420                 }
   12421                 if (!valid) {
   12422                     StringBuilder message = new StringBuilder();
   12423                     message.append("Input inV: ");
   12424                     message.append(String.format("%24.8g {%16x} %31a",
   12425                             args.inV, Double.doubleToRawLongBits(args.inV), args.inV));
   12426                     message.append("\n");
   12427                     message.append("Expected output out: ");
   12428                     message.append(String.format("0x%x", args.out));
   12429                     message.append("\n");
   12430                     message.append("Actual   output out: ");
   12431                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   12432                     if (args.out != arrayOut[i * 4 + j]) {
   12433                         message.append(" FAIL");
   12434                     }
   12435                     message.append("\n");
   12436                     assertTrue("Incorrect output for checkConvertDouble4Ushort4" +
   12437                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   12438                 }
   12439             }
   12440         }
   12441     }
   12442 
   12443     public class ArgumentsLongUshort {
   12444         public long inV;
   12445         public short out;
   12446     }
   12447 
   12448     private void checkConvertLong2Ushort2() {
   12449         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_64, 2, 0x7b96893ebc97e8e9l, false, 16);
   12450         try {
   12451             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE);
   12452             script.forEach_testConvertUshort2Long2Ushort2(inV, out);
   12453             verifyResultsConvertLong2Ushort2(inV, out, false);
   12454         } catch (Exception e) {
   12455             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort2Long2Ushort2: " + e.toString());
   12456         }
   12457         try {
   12458             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE);
   12459             scriptRelaxed.forEach_testConvertUshort2Long2Ushort2(inV, out);
   12460             verifyResultsConvertLong2Ushort2(inV, out, true);
   12461         } catch (Exception e) {
   12462             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort2Long2Ushort2: " + e.toString());
   12463         }
   12464     }
   12465 
   12466     private void verifyResultsConvertLong2Ushort2(Allocation inV, Allocation out, boolean relaxed) {
   12467         long[] arrayInV = new long[INPUTSIZE * 2];
   12468         inV.copyTo(arrayInV);
   12469         short[] arrayOut = new short[INPUTSIZE * 2];
   12470         out.copyTo(arrayOut);
   12471         for (int i = 0; i < INPUTSIZE; i++) {
   12472             for (int j = 0; j < 2 ; j++) {
   12473                 // Extract the inputs.
   12474                 ArgumentsLongUshort args = new ArgumentsLongUshort();
   12475                 args.inV = arrayInV[i * 2 + j];
   12476                 // Figure out what the outputs should have been.
   12477                 CoreMathVerifier.computeConvert(args);
   12478                 // Validate the outputs.
   12479                 boolean valid = true;
   12480                 if (args.out != arrayOut[i * 2 + j]) {
   12481                     valid = false;
   12482                 }
   12483                 if (!valid) {
   12484                     StringBuilder message = new StringBuilder();
   12485                     message.append("Input inV: ");
   12486                     message.append(String.format("%d", args.inV));
   12487                     message.append("\n");
   12488                     message.append("Expected output out: ");
   12489                     message.append(String.format("0x%x", args.out));
   12490                     message.append("\n");
   12491                     message.append("Actual   output out: ");
   12492                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   12493                     if (args.out != arrayOut[i * 2 + j]) {
   12494                         message.append(" FAIL");
   12495                     }
   12496                     message.append("\n");
   12497                     assertTrue("Incorrect output for checkConvertLong2Ushort2" +
   12498                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   12499                 }
   12500             }
   12501         }
   12502     }
   12503 
   12504     private void checkConvertLong3Ushort3() {
   12505         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_64, 3, 0x7be350c612f37a15l, false, 16);
   12506         try {
   12507             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE);
   12508             script.forEach_testConvertUshort3Long3Ushort3(inV, out);
   12509             verifyResultsConvertLong3Ushort3(inV, out, false);
   12510         } catch (Exception e) {
   12511             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort3Long3Ushort3: " + e.toString());
   12512         }
   12513         try {
   12514             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE);
   12515             scriptRelaxed.forEach_testConvertUshort3Long3Ushort3(inV, out);
   12516             verifyResultsConvertLong3Ushort3(inV, out, true);
   12517         } catch (Exception e) {
   12518             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort3Long3Ushort3: " + e.toString());
   12519         }
   12520     }
   12521 
   12522     private void verifyResultsConvertLong3Ushort3(Allocation inV, Allocation out, boolean relaxed) {
   12523         long[] arrayInV = new long[INPUTSIZE * 4];
   12524         inV.copyTo(arrayInV);
   12525         short[] arrayOut = new short[INPUTSIZE * 4];
   12526         out.copyTo(arrayOut);
   12527         for (int i = 0; i < INPUTSIZE; i++) {
   12528             for (int j = 0; j < 3 ; j++) {
   12529                 // Extract the inputs.
   12530                 ArgumentsLongUshort args = new ArgumentsLongUshort();
   12531                 args.inV = arrayInV[i * 4 + j];
   12532                 // Figure out what the outputs should have been.
   12533                 CoreMathVerifier.computeConvert(args);
   12534                 // Validate the outputs.
   12535                 boolean valid = true;
   12536                 if (args.out != arrayOut[i * 4 + j]) {
   12537                     valid = false;
   12538                 }
   12539                 if (!valid) {
   12540                     StringBuilder message = new StringBuilder();
   12541                     message.append("Input inV: ");
   12542                     message.append(String.format("%d", args.inV));
   12543                     message.append("\n");
   12544                     message.append("Expected output out: ");
   12545                     message.append(String.format("0x%x", args.out));
   12546                     message.append("\n");
   12547                     message.append("Actual   output out: ");
   12548                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   12549                     if (args.out != arrayOut[i * 4 + j]) {
   12550                         message.append(" FAIL");
   12551                     }
   12552                     message.append("\n");
   12553                     assertTrue("Incorrect output for checkConvertLong3Ushort3" +
   12554                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   12555                 }
   12556             }
   12557         }
   12558     }
   12559 
   12560     private void checkConvertLong4Ushort4() {
   12561         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_64, 4, 0x7c30184d694f0b41l, false, 16);
   12562         try {
   12563             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE);
   12564             script.forEach_testConvertUshort4Long4Ushort4(inV, out);
   12565             verifyResultsConvertLong4Ushort4(inV, out, false);
   12566         } catch (Exception e) {
   12567             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort4Long4Ushort4: " + e.toString());
   12568         }
   12569         try {
   12570             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE);
   12571             scriptRelaxed.forEach_testConvertUshort4Long4Ushort4(inV, out);
   12572             verifyResultsConvertLong4Ushort4(inV, out, true);
   12573         } catch (Exception e) {
   12574             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort4Long4Ushort4: " + e.toString());
   12575         }
   12576     }
   12577 
   12578     private void verifyResultsConvertLong4Ushort4(Allocation inV, Allocation out, boolean relaxed) {
   12579         long[] arrayInV = new long[INPUTSIZE * 4];
   12580         inV.copyTo(arrayInV);
   12581         short[] arrayOut = new short[INPUTSIZE * 4];
   12582         out.copyTo(arrayOut);
   12583         for (int i = 0; i < INPUTSIZE; i++) {
   12584             for (int j = 0; j < 4 ; j++) {
   12585                 // Extract the inputs.
   12586                 ArgumentsLongUshort args = new ArgumentsLongUshort();
   12587                 args.inV = arrayInV[i * 4 + j];
   12588                 // Figure out what the outputs should have been.
   12589                 CoreMathVerifier.computeConvert(args);
   12590                 // Validate the outputs.
   12591                 boolean valid = true;
   12592                 if (args.out != arrayOut[i * 4 + j]) {
   12593                     valid = false;
   12594                 }
   12595                 if (!valid) {
   12596                     StringBuilder message = new StringBuilder();
   12597                     message.append("Input inV: ");
   12598                     message.append(String.format("%d", args.inV));
   12599                     message.append("\n");
   12600                     message.append("Expected output out: ");
   12601                     message.append(String.format("0x%x", args.out));
   12602                     message.append("\n");
   12603                     message.append("Actual   output out: ");
   12604                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   12605                     if (args.out != arrayOut[i * 4 + j]) {
   12606                         message.append(" FAIL");
   12607                     }
   12608                     message.append("\n");
   12609                     assertTrue("Incorrect output for checkConvertLong4Ushort4" +
   12610                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   12611                 }
   12612             }
   12613         }
   12614     }
   12615 
   12616     public class ArgumentsUlongUshort {
   12617         public long inV;
   12618         public short out;
   12619     }
   12620 
   12621     private void checkConvertUlong2Ushort2() {
   12622         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_64, 2, 0xaa35ea85e9e438a2l, false, 16);
   12623         try {
   12624             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE);
   12625             script.forEach_testConvertUshort2Ulong2Ushort2(inV, out);
   12626             verifyResultsConvertUlong2Ushort2(inV, out, false);
   12627         } catch (Exception e) {
   12628             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort2Ulong2Ushort2: " + e.toString());
   12629         }
   12630         try {
   12631             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 2), INPUTSIZE);
   12632             scriptRelaxed.forEach_testConvertUshort2Ulong2Ushort2(inV, out);
   12633             verifyResultsConvertUlong2Ushort2(inV, out, true);
   12634         } catch (Exception e) {
   12635             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort2Ulong2Ushort2: " + e.toString());
   12636         }
   12637     }
   12638 
   12639     private void verifyResultsConvertUlong2Ushort2(Allocation inV, Allocation out, boolean relaxed) {
   12640         long[] arrayInV = new long[INPUTSIZE * 2];
   12641         inV.copyTo(arrayInV);
   12642         short[] arrayOut = new short[INPUTSIZE * 2];
   12643         out.copyTo(arrayOut);
   12644         for (int i = 0; i < INPUTSIZE; i++) {
   12645             for (int j = 0; j < 2 ; j++) {
   12646                 // Extract the inputs.
   12647                 ArgumentsUlongUshort args = new ArgumentsUlongUshort();
   12648                 args.inV = arrayInV[i * 2 + j];
   12649                 // Figure out what the outputs should have been.
   12650                 CoreMathVerifier.computeConvert(args);
   12651                 // Validate the outputs.
   12652                 boolean valid = true;
   12653                 if (args.out != arrayOut[i * 2 + j]) {
   12654                     valid = false;
   12655                 }
   12656                 if (!valid) {
   12657                     StringBuilder message = new StringBuilder();
   12658                     message.append("Input inV: ");
   12659                     message.append(String.format("0x%x", args.inV));
   12660                     message.append("\n");
   12661                     message.append("Expected output out: ");
   12662                     message.append(String.format("0x%x", args.out));
   12663                     message.append("\n");
   12664                     message.append("Actual   output out: ");
   12665                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   12666                     if (args.out != arrayOut[i * 2 + j]) {
   12667                         message.append(" FAIL");
   12668                     }
   12669                     message.append("\n");
   12670                     assertTrue("Incorrect output for checkConvertUlong2Ushort2" +
   12671                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   12672                 }
   12673             }
   12674         }
   12675     }
   12676 
   12677     private void checkConvertUlong3Ushort3() {
   12678         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_64, 3, 0xaa82b20d403fc9cel, false, 16);
   12679         try {
   12680             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE);
   12681             script.forEach_testConvertUshort3Ulong3Ushort3(inV, out);
   12682             verifyResultsConvertUlong3Ushort3(inV, out, false);
   12683         } catch (Exception e) {
   12684             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort3Ulong3Ushort3: " + e.toString());
   12685         }
   12686         try {
   12687             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 3), INPUTSIZE);
   12688             scriptRelaxed.forEach_testConvertUshort3Ulong3Ushort3(inV, out);
   12689             verifyResultsConvertUlong3Ushort3(inV, out, true);
   12690         } catch (Exception e) {
   12691             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort3Ulong3Ushort3: " + e.toString());
   12692         }
   12693     }
   12694 
   12695     private void verifyResultsConvertUlong3Ushort3(Allocation inV, Allocation out, boolean relaxed) {
   12696         long[] arrayInV = new long[INPUTSIZE * 4];
   12697         inV.copyTo(arrayInV);
   12698         short[] arrayOut = new short[INPUTSIZE * 4];
   12699         out.copyTo(arrayOut);
   12700         for (int i = 0; i < INPUTSIZE; i++) {
   12701             for (int j = 0; j < 3 ; j++) {
   12702                 // Extract the inputs.
   12703                 ArgumentsUlongUshort args = new ArgumentsUlongUshort();
   12704                 args.inV = arrayInV[i * 4 + j];
   12705                 // Figure out what the outputs should have been.
   12706                 CoreMathVerifier.computeConvert(args);
   12707                 // Validate the outputs.
   12708                 boolean valid = true;
   12709                 if (args.out != arrayOut[i * 4 + j]) {
   12710                     valid = false;
   12711                 }
   12712                 if (!valid) {
   12713                     StringBuilder message = new StringBuilder();
   12714                     message.append("Input inV: ");
   12715                     message.append(String.format("0x%x", args.inV));
   12716                     message.append("\n");
   12717                     message.append("Expected output out: ");
   12718                     message.append(String.format("0x%x", args.out));
   12719                     message.append("\n");
   12720                     message.append("Actual   output out: ");
   12721                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   12722                     if (args.out != arrayOut[i * 4 + j]) {
   12723                         message.append(" FAIL");
   12724                     }
   12725                     message.append("\n");
   12726                     assertTrue("Incorrect output for checkConvertUlong3Ushort3" +
   12727                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   12728                 }
   12729             }
   12730         }
   12731     }
   12732 
   12733     private void checkConvertUlong4Ushort4() {
   12734         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_64, 4, 0xaacf7994969b5afal, false, 16);
   12735         try {
   12736             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE);
   12737             script.forEach_testConvertUshort4Ulong4Ushort4(inV, out);
   12738             verifyResultsConvertUlong4Ushort4(inV, out, false);
   12739         } catch (Exception e) {
   12740             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort4Ulong4Ushort4: " + e.toString());
   12741         }
   12742         try {
   12743             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_16, 4), INPUTSIZE);
   12744             scriptRelaxed.forEach_testConvertUshort4Ulong4Ushort4(inV, out);
   12745             verifyResultsConvertUlong4Ushort4(inV, out, true);
   12746         } catch (Exception e) {
   12747             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUshort4Ulong4Ushort4: " + e.toString());
   12748         }
   12749     }
   12750 
   12751     private void verifyResultsConvertUlong4Ushort4(Allocation inV, Allocation out, boolean relaxed) {
   12752         long[] arrayInV = new long[INPUTSIZE * 4];
   12753         inV.copyTo(arrayInV);
   12754         short[] arrayOut = new short[INPUTSIZE * 4];
   12755         out.copyTo(arrayOut);
   12756         for (int i = 0; i < INPUTSIZE; i++) {
   12757             for (int j = 0; j < 4 ; j++) {
   12758                 // Extract the inputs.
   12759                 ArgumentsUlongUshort args = new ArgumentsUlongUshort();
   12760                 args.inV = arrayInV[i * 4 + j];
   12761                 // Figure out what the outputs should have been.
   12762                 CoreMathVerifier.computeConvert(args);
   12763                 // Validate the outputs.
   12764                 boolean valid = true;
   12765                 if (args.out != arrayOut[i * 4 + j]) {
   12766                     valid = false;
   12767                 }
   12768                 if (!valid) {
   12769                     StringBuilder message = new StringBuilder();
   12770                     message.append("Input inV: ");
   12771                     message.append(String.format("0x%x", args.inV));
   12772                     message.append("\n");
   12773                     message.append("Expected output out: ");
   12774                     message.append(String.format("0x%x", args.out));
   12775                     message.append("\n");
   12776                     message.append("Actual   output out: ");
   12777                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   12778                     if (args.out != arrayOut[i * 4 + j]) {
   12779                         message.append(" FAIL");
   12780                     }
   12781                     message.append("\n");
   12782                     assertTrue("Incorrect output for checkConvertUlong4Ushort4" +
   12783                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   12784                 }
   12785             }
   12786         }
   12787     }
   12788 
   12789     public class ArgumentsDoubleInt {
   12790         public double inV;
   12791         public int out;
   12792     }
   12793 
   12794     private void checkConvertDouble2Int2() {
   12795         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_64, 2, 0xa57cd81dcaf628fcl, -2.1474836480000000000e+09, 2.1474836470000000000e+09);
   12796         try {
   12797             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE);
   12798             script.forEach_testConvertInt2Double2Int2(inV, out);
   12799             verifyResultsConvertDouble2Int2(inV, out, false);
   12800         } catch (Exception e) {
   12801             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt2Double2Int2: " + e.toString());
   12802         }
   12803         try {
   12804             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE);
   12805             scriptRelaxed.forEach_testConvertInt2Double2Int2(inV, out);
   12806             verifyResultsConvertDouble2Int2(inV, out, true);
   12807         } catch (Exception e) {
   12808             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt2Double2Int2: " + e.toString());
   12809         }
   12810     }
   12811 
   12812     private void verifyResultsConvertDouble2Int2(Allocation inV, Allocation out, boolean relaxed) {
   12813         double[] arrayInV = new double[INPUTSIZE * 2];
   12814         inV.copyTo(arrayInV);
   12815         int[] arrayOut = new int[INPUTSIZE * 2];
   12816         out.copyTo(arrayOut);
   12817         for (int i = 0; i < INPUTSIZE; i++) {
   12818             for (int j = 0; j < 2 ; j++) {
   12819                 // Extract the inputs.
   12820                 ArgumentsDoubleInt args = new ArgumentsDoubleInt();
   12821                 args.inV = arrayInV[i * 2 + j];
   12822                 // Figure out what the outputs should have been.
   12823                 CoreMathVerifier.computeConvert(args);
   12824                 // Validate the outputs.
   12825                 boolean valid = true;
   12826                 if (args.out != arrayOut[i * 2 + j]) {
   12827                     valid = false;
   12828                 }
   12829                 if (!valid) {
   12830                     StringBuilder message = new StringBuilder();
   12831                     message.append("Input inV: ");
   12832                     message.append(String.format("%24.8g {%16x} %31a",
   12833                             args.inV, Double.doubleToRawLongBits(args.inV), args.inV));
   12834                     message.append("\n");
   12835                     message.append("Expected output out: ");
   12836                     message.append(String.format("%d", args.out));
   12837                     message.append("\n");
   12838                     message.append("Actual   output out: ");
   12839                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   12840                     if (args.out != arrayOut[i * 2 + j]) {
   12841                         message.append(" FAIL");
   12842                     }
   12843                     message.append("\n");
   12844                     assertTrue("Incorrect output for checkConvertDouble2Int2" +
   12845                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   12846                 }
   12847             }
   12848         }
   12849     }
   12850 
   12851     private void checkConvertDouble3Int3() {
   12852         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_64, 3, 0xa57cd85d149e3932l, -2.1474836480000000000e+09, 2.1474836470000000000e+09);
   12853         try {
   12854             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE);
   12855             script.forEach_testConvertInt3Double3Int3(inV, out);
   12856             verifyResultsConvertDouble3Int3(inV, out, false);
   12857         } catch (Exception e) {
   12858             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt3Double3Int3: " + e.toString());
   12859         }
   12860         try {
   12861             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE);
   12862             scriptRelaxed.forEach_testConvertInt3Double3Int3(inV, out);
   12863             verifyResultsConvertDouble3Int3(inV, out, true);
   12864         } catch (Exception e) {
   12865             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt3Double3Int3: " + e.toString());
   12866         }
   12867     }
   12868 
   12869     private void verifyResultsConvertDouble3Int3(Allocation inV, Allocation out, boolean relaxed) {
   12870         double[] arrayInV = new double[INPUTSIZE * 4];
   12871         inV.copyTo(arrayInV);
   12872         int[] arrayOut = new int[INPUTSIZE * 4];
   12873         out.copyTo(arrayOut);
   12874         for (int i = 0; i < INPUTSIZE; i++) {
   12875             for (int j = 0; j < 3 ; j++) {
   12876                 // Extract the inputs.
   12877                 ArgumentsDoubleInt args = new ArgumentsDoubleInt();
   12878                 args.inV = arrayInV[i * 4 + j];
   12879                 // Figure out what the outputs should have been.
   12880                 CoreMathVerifier.computeConvert(args);
   12881                 // Validate the outputs.
   12882                 boolean valid = true;
   12883                 if (args.out != arrayOut[i * 4 + j]) {
   12884                     valid = false;
   12885                 }
   12886                 if (!valid) {
   12887                     StringBuilder message = new StringBuilder();
   12888                     message.append("Input inV: ");
   12889                     message.append(String.format("%24.8g {%16x} %31a",
   12890                             args.inV, Double.doubleToRawLongBits(args.inV), args.inV));
   12891                     message.append("\n");
   12892                     message.append("Expected output out: ");
   12893                     message.append(String.format("%d", args.out));
   12894                     message.append("\n");
   12895                     message.append("Actual   output out: ");
   12896                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   12897                     if (args.out != arrayOut[i * 4 + j]) {
   12898                         message.append(" FAIL");
   12899                     }
   12900                     message.append("\n");
   12901                     assertTrue("Incorrect output for checkConvertDouble3Int3" +
   12902                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   12903                 }
   12904             }
   12905         }
   12906     }
   12907 
   12908     private void checkConvertDouble4Int4() {
   12909         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_64, 4, 0xa57cd89c5e464968l, -2.1474836480000000000e+09, 2.1474836470000000000e+09);
   12910         try {
   12911             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE);
   12912             script.forEach_testConvertInt4Double4Int4(inV, out);
   12913             verifyResultsConvertDouble4Int4(inV, out, false);
   12914         } catch (Exception e) {
   12915             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt4Double4Int4: " + e.toString());
   12916         }
   12917         try {
   12918             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE);
   12919             scriptRelaxed.forEach_testConvertInt4Double4Int4(inV, out);
   12920             verifyResultsConvertDouble4Int4(inV, out, true);
   12921         } catch (Exception e) {
   12922             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt4Double4Int4: " + e.toString());
   12923         }
   12924     }
   12925 
   12926     private void verifyResultsConvertDouble4Int4(Allocation inV, Allocation out, boolean relaxed) {
   12927         double[] arrayInV = new double[INPUTSIZE * 4];
   12928         inV.copyTo(arrayInV);
   12929         int[] arrayOut = new int[INPUTSIZE * 4];
   12930         out.copyTo(arrayOut);
   12931         for (int i = 0; i < INPUTSIZE; i++) {
   12932             for (int j = 0; j < 4 ; j++) {
   12933                 // Extract the inputs.
   12934                 ArgumentsDoubleInt args = new ArgumentsDoubleInt();
   12935                 args.inV = arrayInV[i * 4 + j];
   12936                 // Figure out what the outputs should have been.
   12937                 CoreMathVerifier.computeConvert(args);
   12938                 // Validate the outputs.
   12939                 boolean valid = true;
   12940                 if (args.out != arrayOut[i * 4 + j]) {
   12941                     valid = false;
   12942                 }
   12943                 if (!valid) {
   12944                     StringBuilder message = new StringBuilder();
   12945                     message.append("Input inV: ");
   12946                     message.append(String.format("%24.8g {%16x} %31a",
   12947                             args.inV, Double.doubleToRawLongBits(args.inV), args.inV));
   12948                     message.append("\n");
   12949                     message.append("Expected output out: ");
   12950                     message.append(String.format("%d", args.out));
   12951                     message.append("\n");
   12952                     message.append("Actual   output out: ");
   12953                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   12954                     if (args.out != arrayOut[i * 4 + j]) {
   12955                         message.append(" FAIL");
   12956                     }
   12957                     message.append("\n");
   12958                     assertTrue("Incorrect output for checkConvertDouble4Int4" +
   12959                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   12960                 }
   12961             }
   12962         }
   12963     }
   12964 
   12965     public class ArgumentsLongInt {
   12966         public long inV;
   12967         public int out;
   12968     }
   12969 
   12970     private void checkConvertLong2Int2() {
   12971         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_64, 2, 0xfe441c66e5deba3bl, true, 31);
   12972         try {
   12973             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE);
   12974             script.forEach_testConvertInt2Long2Int2(inV, out);
   12975             verifyResultsConvertLong2Int2(inV, out, false);
   12976         } catch (Exception e) {
   12977             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt2Long2Int2: " + e.toString());
   12978         }
   12979         try {
   12980             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE);
   12981             scriptRelaxed.forEach_testConvertInt2Long2Int2(inV, out);
   12982             verifyResultsConvertLong2Int2(inV, out, true);
   12983         } catch (Exception e) {
   12984             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt2Long2Int2: " + e.toString());
   12985         }
   12986     }
   12987 
   12988     private void verifyResultsConvertLong2Int2(Allocation inV, Allocation out, boolean relaxed) {
   12989         long[] arrayInV = new long[INPUTSIZE * 2];
   12990         inV.copyTo(arrayInV);
   12991         int[] arrayOut = new int[INPUTSIZE * 2];
   12992         out.copyTo(arrayOut);
   12993         for (int i = 0; i < INPUTSIZE; i++) {
   12994             for (int j = 0; j < 2 ; j++) {
   12995                 // Extract the inputs.
   12996                 ArgumentsLongInt args = new ArgumentsLongInt();
   12997                 args.inV = arrayInV[i * 2 + j];
   12998                 // Figure out what the outputs should have been.
   12999                 CoreMathVerifier.computeConvert(args);
   13000                 // Validate the outputs.
   13001                 boolean valid = true;
   13002                 if (args.out != arrayOut[i * 2 + j]) {
   13003                     valid = false;
   13004                 }
   13005                 if (!valid) {
   13006                     StringBuilder message = new StringBuilder();
   13007                     message.append("Input inV: ");
   13008                     message.append(String.format("%d", args.inV));
   13009                     message.append("\n");
   13010                     message.append("Expected output out: ");
   13011                     message.append(String.format("%d", args.out));
   13012                     message.append("\n");
   13013                     message.append("Actual   output out: ");
   13014                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   13015                     if (args.out != arrayOut[i * 2 + j]) {
   13016                         message.append(" FAIL");
   13017                     }
   13018                     message.append("\n");
   13019                     assertTrue("Incorrect output for checkConvertLong2Int2" +
   13020                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   13021                 }
   13022             }
   13023         }
   13024     }
   13025 
   13026     private void checkConvertLong3Int3() {
   13027         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_64, 3, 0xfe441ca62f86ca71l, true, 31);
   13028         try {
   13029             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE);
   13030             script.forEach_testConvertInt3Long3Int3(inV, out);
   13031             verifyResultsConvertLong3Int3(inV, out, false);
   13032         } catch (Exception e) {
   13033             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt3Long3Int3: " + e.toString());
   13034         }
   13035         try {
   13036             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE);
   13037             scriptRelaxed.forEach_testConvertInt3Long3Int3(inV, out);
   13038             verifyResultsConvertLong3Int3(inV, out, true);
   13039         } catch (Exception e) {
   13040             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt3Long3Int3: " + e.toString());
   13041         }
   13042     }
   13043 
   13044     private void verifyResultsConvertLong3Int3(Allocation inV, Allocation out, boolean relaxed) {
   13045         long[] arrayInV = new long[INPUTSIZE * 4];
   13046         inV.copyTo(arrayInV);
   13047         int[] arrayOut = new int[INPUTSIZE * 4];
   13048         out.copyTo(arrayOut);
   13049         for (int i = 0; i < INPUTSIZE; i++) {
   13050             for (int j = 0; j < 3 ; j++) {
   13051                 // Extract the inputs.
   13052                 ArgumentsLongInt args = new ArgumentsLongInt();
   13053                 args.inV = arrayInV[i * 4 + j];
   13054                 // Figure out what the outputs should have been.
   13055                 CoreMathVerifier.computeConvert(args);
   13056                 // Validate the outputs.
   13057                 boolean valid = true;
   13058                 if (args.out != arrayOut[i * 4 + j]) {
   13059                     valid = false;
   13060                 }
   13061                 if (!valid) {
   13062                     StringBuilder message = new StringBuilder();
   13063                     message.append("Input inV: ");
   13064                     message.append(String.format("%d", args.inV));
   13065                     message.append("\n");
   13066                     message.append("Expected output out: ");
   13067                     message.append(String.format("%d", args.out));
   13068                     message.append("\n");
   13069                     message.append("Actual   output out: ");
   13070                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   13071                     if (args.out != arrayOut[i * 4 + j]) {
   13072                         message.append(" FAIL");
   13073                     }
   13074                     message.append("\n");
   13075                     assertTrue("Incorrect output for checkConvertLong3Int3" +
   13076                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   13077                 }
   13078             }
   13079         }
   13080     }
   13081 
   13082     private void checkConvertLong4Int4() {
   13083         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_64, 4, 0xfe441ce5792edaa7l, true, 31);
   13084         try {
   13085             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE);
   13086             script.forEach_testConvertInt4Long4Int4(inV, out);
   13087             verifyResultsConvertLong4Int4(inV, out, false);
   13088         } catch (Exception e) {
   13089             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt4Long4Int4: " + e.toString());
   13090         }
   13091         try {
   13092             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE);
   13093             scriptRelaxed.forEach_testConvertInt4Long4Int4(inV, out);
   13094             verifyResultsConvertLong4Int4(inV, out, true);
   13095         } catch (Exception e) {
   13096             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt4Long4Int4: " + e.toString());
   13097         }
   13098     }
   13099 
   13100     private void verifyResultsConvertLong4Int4(Allocation inV, Allocation out, boolean relaxed) {
   13101         long[] arrayInV = new long[INPUTSIZE * 4];
   13102         inV.copyTo(arrayInV);
   13103         int[] arrayOut = new int[INPUTSIZE * 4];
   13104         out.copyTo(arrayOut);
   13105         for (int i = 0; i < INPUTSIZE; i++) {
   13106             for (int j = 0; j < 4 ; j++) {
   13107                 // Extract the inputs.
   13108                 ArgumentsLongInt args = new ArgumentsLongInt();
   13109                 args.inV = arrayInV[i * 4 + j];
   13110                 // Figure out what the outputs should have been.
   13111                 CoreMathVerifier.computeConvert(args);
   13112                 // Validate the outputs.
   13113                 boolean valid = true;
   13114                 if (args.out != arrayOut[i * 4 + j]) {
   13115                     valid = false;
   13116                 }
   13117                 if (!valid) {
   13118                     StringBuilder message = new StringBuilder();
   13119                     message.append("Input inV: ");
   13120                     message.append(String.format("%d", args.inV));
   13121                     message.append("\n");
   13122                     message.append("Expected output out: ");
   13123                     message.append(String.format("%d", args.out));
   13124                     message.append("\n");
   13125                     message.append("Actual   output out: ");
   13126                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   13127                     if (args.out != arrayOut[i * 4 + j]) {
   13128                         message.append(" FAIL");
   13129                     }
   13130                     message.append("\n");
   13131                     assertTrue("Incorrect output for checkConvertLong4Int4" +
   13132                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   13133                 }
   13134             }
   13135         }
   13136     }
   13137 
   13138     public class ArgumentsUlongInt {
   13139         public long inV;
   13140         public int out;
   13141     }
   13142 
   13143     private void checkConvertUlong2Int2() {
   13144         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_64, 2, 0xe11d350e352de3el, false, 31);
   13145         try {
   13146             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE);
   13147             script.forEach_testConvertInt2Ulong2Int2(inV, out);
   13148             verifyResultsConvertUlong2Int2(inV, out, false);
   13149         } catch (Exception e) {
   13150             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt2Ulong2Int2: " + e.toString());
   13151         }
   13152         try {
   13153             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 2), INPUTSIZE);
   13154             scriptRelaxed.forEach_testConvertInt2Ulong2Int2(inV, out);
   13155             verifyResultsConvertUlong2Int2(inV, out, true);
   13156         } catch (Exception e) {
   13157             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt2Ulong2Int2: " + e.toString());
   13158         }
   13159     }
   13160 
   13161     private void verifyResultsConvertUlong2Int2(Allocation inV, Allocation out, boolean relaxed) {
   13162         long[] arrayInV = new long[INPUTSIZE * 2];
   13163         inV.copyTo(arrayInV);
   13164         int[] arrayOut = new int[INPUTSIZE * 2];
   13165         out.copyTo(arrayOut);
   13166         for (int i = 0; i < INPUTSIZE; i++) {
   13167             for (int j = 0; j < 2 ; j++) {
   13168                 // Extract the inputs.
   13169                 ArgumentsUlongInt args = new ArgumentsUlongInt();
   13170                 args.inV = arrayInV[i * 2 + j];
   13171                 // Figure out what the outputs should have been.
   13172                 CoreMathVerifier.computeConvert(args);
   13173                 // Validate the outputs.
   13174                 boolean valid = true;
   13175                 if (args.out != arrayOut[i * 2 + j]) {
   13176                     valid = false;
   13177                 }
   13178                 if (!valid) {
   13179                     StringBuilder message = new StringBuilder();
   13180                     message.append("Input inV: ");
   13181                     message.append(String.format("0x%x", args.inV));
   13182                     message.append("\n");
   13183                     message.append("Expected output out: ");
   13184                     message.append(String.format("%d", args.out));
   13185                     message.append("\n");
   13186                     message.append("Actual   output out: ");
   13187                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   13188                     if (args.out != arrayOut[i * 2 + j]) {
   13189                         message.append(" FAIL");
   13190                     }
   13191                     message.append("\n");
   13192                     assertTrue("Incorrect output for checkConvertUlong2Int2" +
   13193                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   13194                 }
   13195             }
   13196         }
   13197     }
   13198 
   13199     private void checkConvertUlong3Int3() {
   13200         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_64, 3, 0xe11d3902cfaee74l, false, 31);
   13201         try {
   13202             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE);
   13203             script.forEach_testConvertInt3Ulong3Int3(inV, out);
   13204             verifyResultsConvertUlong3Int3(inV, out, false);
   13205         } catch (Exception e) {
   13206             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt3Ulong3Int3: " + e.toString());
   13207         }
   13208         try {
   13209             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 3), INPUTSIZE);
   13210             scriptRelaxed.forEach_testConvertInt3Ulong3Int3(inV, out);
   13211             verifyResultsConvertUlong3Int3(inV, out, true);
   13212         } catch (Exception e) {
   13213             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt3Ulong3Int3: " + e.toString());
   13214         }
   13215     }
   13216 
   13217     private void verifyResultsConvertUlong3Int3(Allocation inV, Allocation out, boolean relaxed) {
   13218         long[] arrayInV = new long[INPUTSIZE * 4];
   13219         inV.copyTo(arrayInV);
   13220         int[] arrayOut = new int[INPUTSIZE * 4];
   13221         out.copyTo(arrayOut);
   13222         for (int i = 0; i < INPUTSIZE; i++) {
   13223             for (int j = 0; j < 3 ; j++) {
   13224                 // Extract the inputs.
   13225                 ArgumentsUlongInt args = new ArgumentsUlongInt();
   13226                 args.inV = arrayInV[i * 4 + j];
   13227                 // Figure out what the outputs should have been.
   13228                 CoreMathVerifier.computeConvert(args);
   13229                 // Validate the outputs.
   13230                 boolean valid = true;
   13231                 if (args.out != arrayOut[i * 4 + j]) {
   13232                     valid = false;
   13233                 }
   13234                 if (!valid) {
   13235                     StringBuilder message = new StringBuilder();
   13236                     message.append("Input inV: ");
   13237                     message.append(String.format("0x%x", args.inV));
   13238                     message.append("\n");
   13239                     message.append("Expected output out: ");
   13240                     message.append(String.format("%d", args.out));
   13241                     message.append("\n");
   13242                     message.append("Actual   output out: ");
   13243                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   13244                     if (args.out != arrayOut[i * 4 + j]) {
   13245                         message.append(" FAIL");
   13246                     }
   13247                     message.append("\n");
   13248                     assertTrue("Incorrect output for checkConvertUlong3Int3" +
   13249                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   13250                 }
   13251             }
   13252         }
   13253     }
   13254 
   13255     private void checkConvertUlong4Int4() {
   13256         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_64, 4, 0xe11d3cf76a2feaal, false, 31);
   13257         try {
   13258             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE);
   13259             script.forEach_testConvertInt4Ulong4Int4(inV, out);
   13260             verifyResultsConvertUlong4Int4(inV, out, false);
   13261         } catch (Exception e) {
   13262             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt4Ulong4Int4: " + e.toString());
   13263         }
   13264         try {
   13265             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_32, 4), INPUTSIZE);
   13266             scriptRelaxed.forEach_testConvertInt4Ulong4Int4(inV, out);
   13267             verifyResultsConvertUlong4Int4(inV, out, true);
   13268         } catch (Exception e) {
   13269             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertInt4Ulong4Int4: " + e.toString());
   13270         }
   13271     }
   13272 
   13273     private void verifyResultsConvertUlong4Int4(Allocation inV, Allocation out, boolean relaxed) {
   13274         long[] arrayInV = new long[INPUTSIZE * 4];
   13275         inV.copyTo(arrayInV);
   13276         int[] arrayOut = new int[INPUTSIZE * 4];
   13277         out.copyTo(arrayOut);
   13278         for (int i = 0; i < INPUTSIZE; i++) {
   13279             for (int j = 0; j < 4 ; j++) {
   13280                 // Extract the inputs.
   13281                 ArgumentsUlongInt args = new ArgumentsUlongInt();
   13282                 args.inV = arrayInV[i * 4 + j];
   13283                 // Figure out what the outputs should have been.
   13284                 CoreMathVerifier.computeConvert(args);
   13285                 // Validate the outputs.
   13286                 boolean valid = true;
   13287                 if (args.out != arrayOut[i * 4 + j]) {
   13288                     valid = false;
   13289                 }
   13290                 if (!valid) {
   13291                     StringBuilder message = new StringBuilder();
   13292                     message.append("Input inV: ");
   13293                     message.append(String.format("0x%x", args.inV));
   13294                     message.append("\n");
   13295                     message.append("Expected output out: ");
   13296                     message.append(String.format("%d", args.out));
   13297                     message.append("\n");
   13298                     message.append("Actual   output out: ");
   13299                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   13300                     if (args.out != arrayOut[i * 4 + j]) {
   13301                         message.append(" FAIL");
   13302                     }
   13303                     message.append("\n");
   13304                     assertTrue("Incorrect output for checkConvertUlong4Int4" +
   13305                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   13306                 }
   13307             }
   13308         }
   13309     }
   13310 
   13311     public class ArgumentsDoubleUint {
   13312         public double inV;
   13313         public int out;
   13314     }
   13315 
   13316     private void checkConvertDouble2Uint2() {
   13317         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_64, 2, 0xcbf84ff107de7dd7l, 0.0000000000000000000e+00, 4.2949672950000000000e+09);
   13318         try {
   13319             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE);
   13320             script.forEach_testConvertUint2Double2Uint2(inV, out);
   13321             verifyResultsConvertDouble2Uint2(inV, out, false);
   13322         } catch (Exception e) {
   13323             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint2Double2Uint2: " + e.toString());
   13324         }
   13325         try {
   13326             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE);
   13327             scriptRelaxed.forEach_testConvertUint2Double2Uint2(inV, out);
   13328             verifyResultsConvertDouble2Uint2(inV, out, true);
   13329         } catch (Exception e) {
   13330             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint2Double2Uint2: " + e.toString());
   13331         }
   13332     }
   13333 
   13334     private void verifyResultsConvertDouble2Uint2(Allocation inV, Allocation out, boolean relaxed) {
   13335         double[] arrayInV = new double[INPUTSIZE * 2];
   13336         inV.copyTo(arrayInV);
   13337         int[] arrayOut = new int[INPUTSIZE * 2];
   13338         out.copyTo(arrayOut);
   13339         for (int i = 0; i < INPUTSIZE; i++) {
   13340             for (int j = 0; j < 2 ; j++) {
   13341                 // Extract the inputs.
   13342                 ArgumentsDoubleUint args = new ArgumentsDoubleUint();
   13343                 args.inV = arrayInV[i * 2 + j];
   13344                 // Figure out what the outputs should have been.
   13345                 CoreMathVerifier.computeConvert(args);
   13346                 // Validate the outputs.
   13347                 boolean valid = true;
   13348                 if (args.out != arrayOut[i * 2 + j]) {
   13349                     valid = false;
   13350                 }
   13351                 if (!valid) {
   13352                     StringBuilder message = new StringBuilder();
   13353                     message.append("Input inV: ");
   13354                     message.append(String.format("%24.8g {%16x} %31a",
   13355                             args.inV, Double.doubleToRawLongBits(args.inV), args.inV));
   13356                     message.append("\n");
   13357                     message.append("Expected output out: ");
   13358                     message.append(String.format("0x%x", args.out));
   13359                     message.append("\n");
   13360                     message.append("Actual   output out: ");
   13361                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   13362                     if (args.out != arrayOut[i * 2 + j]) {
   13363                         message.append(" FAIL");
   13364                     }
   13365                     message.append("\n");
   13366                     assertTrue("Incorrect output for checkConvertDouble2Uint2" +
   13367                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   13368                 }
   13369             }
   13370         }
   13371     }
   13372 
   13373     private void checkConvertDouble3Uint3() {
   13374         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_64, 3, 0xcbf85a9266e642cbl, 0.0000000000000000000e+00, 4.2949672950000000000e+09);
   13375         try {
   13376             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE);
   13377             script.forEach_testConvertUint3Double3Uint3(inV, out);
   13378             verifyResultsConvertDouble3Uint3(inV, out, false);
   13379         } catch (Exception e) {
   13380             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint3Double3Uint3: " + e.toString());
   13381         }
   13382         try {
   13383             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE);
   13384             scriptRelaxed.forEach_testConvertUint3Double3Uint3(inV, out);
   13385             verifyResultsConvertDouble3Uint3(inV, out, true);
   13386         } catch (Exception e) {
   13387             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint3Double3Uint3: " + e.toString());
   13388         }
   13389     }
   13390 
   13391     private void verifyResultsConvertDouble3Uint3(Allocation inV, Allocation out, boolean relaxed) {
   13392         double[] arrayInV = new double[INPUTSIZE * 4];
   13393         inV.copyTo(arrayInV);
   13394         int[] arrayOut = new int[INPUTSIZE * 4];
   13395         out.copyTo(arrayOut);
   13396         for (int i = 0; i < INPUTSIZE; i++) {
   13397             for (int j = 0; j < 3 ; j++) {
   13398                 // Extract the inputs.
   13399                 ArgumentsDoubleUint args = new ArgumentsDoubleUint();
   13400                 args.inV = arrayInV[i * 4 + j];
   13401                 // Figure out what the outputs should have been.
   13402                 CoreMathVerifier.computeConvert(args);
   13403                 // Validate the outputs.
   13404                 boolean valid = true;
   13405                 if (args.out != arrayOut[i * 4 + j]) {
   13406                     valid = false;
   13407                 }
   13408                 if (!valid) {
   13409                     StringBuilder message = new StringBuilder();
   13410                     message.append("Input inV: ");
   13411                     message.append(String.format("%24.8g {%16x} %31a",
   13412                             args.inV, Double.doubleToRawLongBits(args.inV), args.inV));
   13413                     message.append("\n");
   13414                     message.append("Expected output out: ");
   13415                     message.append(String.format("0x%x", args.out));
   13416                     message.append("\n");
   13417                     message.append("Actual   output out: ");
   13418                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   13419                     if (args.out != arrayOut[i * 4 + j]) {
   13420                         message.append(" FAIL");
   13421                     }
   13422                     message.append("\n");
   13423                     assertTrue("Incorrect output for checkConvertDouble3Uint3" +
   13424                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   13425                 }
   13426             }
   13427         }
   13428     }
   13429 
   13430     private void checkConvertDouble4Uint4() {
   13431         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_64, 4, 0xcbf86533c5ee07bfl, 0.0000000000000000000e+00, 4.2949672950000000000e+09);
   13432         try {
   13433             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE);
   13434             script.forEach_testConvertUint4Double4Uint4(inV, out);
   13435             verifyResultsConvertDouble4Uint4(inV, out, false);
   13436         } catch (Exception e) {
   13437             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint4Double4Uint4: " + e.toString());
   13438         }
   13439         try {
   13440             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE);
   13441             scriptRelaxed.forEach_testConvertUint4Double4Uint4(inV, out);
   13442             verifyResultsConvertDouble4Uint4(inV, out, true);
   13443         } catch (Exception e) {
   13444             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint4Double4Uint4: " + e.toString());
   13445         }
   13446     }
   13447 
   13448     private void verifyResultsConvertDouble4Uint4(Allocation inV, Allocation out, boolean relaxed) {
   13449         double[] arrayInV = new double[INPUTSIZE * 4];
   13450         inV.copyTo(arrayInV);
   13451         int[] arrayOut = new int[INPUTSIZE * 4];
   13452         out.copyTo(arrayOut);
   13453         for (int i = 0; i < INPUTSIZE; i++) {
   13454             for (int j = 0; j < 4 ; j++) {
   13455                 // Extract the inputs.
   13456                 ArgumentsDoubleUint args = new ArgumentsDoubleUint();
   13457                 args.inV = arrayInV[i * 4 + j];
   13458                 // Figure out what the outputs should have been.
   13459                 CoreMathVerifier.computeConvert(args);
   13460                 // Validate the outputs.
   13461                 boolean valid = true;
   13462                 if (args.out != arrayOut[i * 4 + j]) {
   13463                     valid = false;
   13464                 }
   13465                 if (!valid) {
   13466                     StringBuilder message = new StringBuilder();
   13467                     message.append("Input inV: ");
   13468                     message.append(String.format("%24.8g {%16x} %31a",
   13469                             args.inV, Double.doubleToRawLongBits(args.inV), args.inV));
   13470                     message.append("\n");
   13471                     message.append("Expected output out: ");
   13472                     message.append(String.format("0x%x", args.out));
   13473                     message.append("\n");
   13474                     message.append("Actual   output out: ");
   13475                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   13476                     if (args.out != arrayOut[i * 4 + j]) {
   13477                         message.append(" FAIL");
   13478                     }
   13479                     message.append("\n");
   13480                     assertTrue("Incorrect output for checkConvertDouble4Uint4" +
   13481                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   13482                 }
   13483             }
   13484         }
   13485     }
   13486 
   13487     public class ArgumentsLongUint {
   13488         public long inV;
   13489         public int out;
   13490     }
   13491 
   13492     private void checkConvertLong2Uint2() {
   13493         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_64, 2, 0xb570c8388ceee36cl, false, 32);
   13494         try {
   13495             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE);
   13496             script.forEach_testConvertUint2Long2Uint2(inV, out);
   13497             verifyResultsConvertLong2Uint2(inV, out, false);
   13498         } catch (Exception e) {
   13499             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint2Long2Uint2: " + e.toString());
   13500         }
   13501         try {
   13502             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE);
   13503             scriptRelaxed.forEach_testConvertUint2Long2Uint2(inV, out);
   13504             verifyResultsConvertLong2Uint2(inV, out, true);
   13505         } catch (Exception e) {
   13506             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint2Long2Uint2: " + e.toString());
   13507         }
   13508     }
   13509 
   13510     private void verifyResultsConvertLong2Uint2(Allocation inV, Allocation out, boolean relaxed) {
   13511         long[] arrayInV = new long[INPUTSIZE * 2];
   13512         inV.copyTo(arrayInV);
   13513         int[] arrayOut = new int[INPUTSIZE * 2];
   13514         out.copyTo(arrayOut);
   13515         for (int i = 0; i < INPUTSIZE; i++) {
   13516             for (int j = 0; j < 2 ; j++) {
   13517                 // Extract the inputs.
   13518                 ArgumentsLongUint args = new ArgumentsLongUint();
   13519                 args.inV = arrayInV[i * 2 + j];
   13520                 // Figure out what the outputs should have been.
   13521                 CoreMathVerifier.computeConvert(args);
   13522                 // Validate the outputs.
   13523                 boolean valid = true;
   13524                 if (args.out != arrayOut[i * 2 + j]) {
   13525                     valid = false;
   13526                 }
   13527                 if (!valid) {
   13528                     StringBuilder message = new StringBuilder();
   13529                     message.append("Input inV: ");
   13530                     message.append(String.format("%d", args.inV));
   13531                     message.append("\n");
   13532                     message.append("Expected output out: ");
   13533                     message.append(String.format("0x%x", args.out));
   13534                     message.append("\n");
   13535                     message.append("Actual   output out: ");
   13536                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   13537                     if (args.out != arrayOut[i * 2 + j]) {
   13538                         message.append(" FAIL");
   13539                     }
   13540                     message.append("\n");
   13541                     assertTrue("Incorrect output for checkConvertLong2Uint2" +
   13542                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   13543                 }
   13544             }
   13545         }
   13546     }
   13547 
   13548     private void checkConvertLong3Uint3() {
   13549         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_64, 3, 0xb570d2d9ebf6a860l, false, 32);
   13550         try {
   13551             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE);
   13552             script.forEach_testConvertUint3Long3Uint3(inV, out);
   13553             verifyResultsConvertLong3Uint3(inV, out, false);
   13554         } catch (Exception e) {
   13555             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint3Long3Uint3: " + e.toString());
   13556         }
   13557         try {
   13558             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE);
   13559             scriptRelaxed.forEach_testConvertUint3Long3Uint3(inV, out);
   13560             verifyResultsConvertLong3Uint3(inV, out, true);
   13561         } catch (Exception e) {
   13562             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint3Long3Uint3: " + e.toString());
   13563         }
   13564     }
   13565 
   13566     private void verifyResultsConvertLong3Uint3(Allocation inV, Allocation out, boolean relaxed) {
   13567         long[] arrayInV = new long[INPUTSIZE * 4];
   13568         inV.copyTo(arrayInV);
   13569         int[] arrayOut = new int[INPUTSIZE * 4];
   13570         out.copyTo(arrayOut);
   13571         for (int i = 0; i < INPUTSIZE; i++) {
   13572             for (int j = 0; j < 3 ; j++) {
   13573                 // Extract the inputs.
   13574                 ArgumentsLongUint args = new ArgumentsLongUint();
   13575                 args.inV = arrayInV[i * 4 + j];
   13576                 // Figure out what the outputs should have been.
   13577                 CoreMathVerifier.computeConvert(args);
   13578                 // Validate the outputs.
   13579                 boolean valid = true;
   13580                 if (args.out != arrayOut[i * 4 + j]) {
   13581                     valid = false;
   13582                 }
   13583                 if (!valid) {
   13584                     StringBuilder message = new StringBuilder();
   13585                     message.append("Input inV: ");
   13586                     message.append(String.format("%d", args.inV));
   13587                     message.append("\n");
   13588                     message.append("Expected output out: ");
   13589                     message.append(String.format("0x%x", args.out));
   13590                     message.append("\n");
   13591                     message.append("Actual   output out: ");
   13592                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   13593                     if (args.out != arrayOut[i * 4 + j]) {
   13594                         message.append(" FAIL");
   13595                     }
   13596                     message.append("\n");
   13597                     assertTrue("Incorrect output for checkConvertLong3Uint3" +
   13598                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   13599                 }
   13600             }
   13601         }
   13602     }
   13603 
   13604     private void checkConvertLong4Uint4() {
   13605         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_64, 4, 0xb570dd7b4afe6d54l, false, 32);
   13606         try {
   13607             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE);
   13608             script.forEach_testConvertUint4Long4Uint4(inV, out);
   13609             verifyResultsConvertLong4Uint4(inV, out, false);
   13610         } catch (Exception e) {
   13611             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint4Long4Uint4: " + e.toString());
   13612         }
   13613         try {
   13614             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE);
   13615             scriptRelaxed.forEach_testConvertUint4Long4Uint4(inV, out);
   13616             verifyResultsConvertLong4Uint4(inV, out, true);
   13617         } catch (Exception e) {
   13618             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint4Long4Uint4: " + e.toString());
   13619         }
   13620     }
   13621 
   13622     private void verifyResultsConvertLong4Uint4(Allocation inV, Allocation out, boolean relaxed) {
   13623         long[] arrayInV = new long[INPUTSIZE * 4];
   13624         inV.copyTo(arrayInV);
   13625         int[] arrayOut = new int[INPUTSIZE * 4];
   13626         out.copyTo(arrayOut);
   13627         for (int i = 0; i < INPUTSIZE; i++) {
   13628             for (int j = 0; j < 4 ; j++) {
   13629                 // Extract the inputs.
   13630                 ArgumentsLongUint args = new ArgumentsLongUint();
   13631                 args.inV = arrayInV[i * 4 + j];
   13632                 // Figure out what the outputs should have been.
   13633                 CoreMathVerifier.computeConvert(args);
   13634                 // Validate the outputs.
   13635                 boolean valid = true;
   13636                 if (args.out != arrayOut[i * 4 + j]) {
   13637                     valid = false;
   13638                 }
   13639                 if (!valid) {
   13640                     StringBuilder message = new StringBuilder();
   13641                     message.append("Input inV: ");
   13642                     message.append(String.format("%d", args.inV));
   13643                     message.append("\n");
   13644                     message.append("Expected output out: ");
   13645                     message.append(String.format("0x%x", args.out));
   13646                     message.append("\n");
   13647                     message.append("Actual   output out: ");
   13648                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   13649                     if (args.out != arrayOut[i * 4 + j]) {
   13650                         message.append(" FAIL");
   13651                     }
   13652                     message.append("\n");
   13653                     assertTrue("Incorrect output for checkConvertLong4Uint4" +
   13654                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   13655                 }
   13656             }
   13657         }
   13658     }
   13659 
   13660     public class ArgumentsUlongUint {
   13661         public long inV;
   13662         public int out;
   13663     }
   13664 
   13665     private void checkConvertUlong2Uint2() {
   13666         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_64, 2, 0x5cfe81861f70efedl, false, 32);
   13667         try {
   13668             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE);
   13669             script.forEach_testConvertUint2Ulong2Uint2(inV, out);
   13670             verifyResultsConvertUlong2Uint2(inV, out, false);
   13671         } catch (Exception e) {
   13672             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint2Ulong2Uint2: " + e.toString());
   13673         }
   13674         try {
   13675             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 2), INPUTSIZE);
   13676             scriptRelaxed.forEach_testConvertUint2Ulong2Uint2(inV, out);
   13677             verifyResultsConvertUlong2Uint2(inV, out, true);
   13678         } catch (Exception e) {
   13679             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint2Ulong2Uint2: " + e.toString());
   13680         }
   13681     }
   13682 
   13683     private void verifyResultsConvertUlong2Uint2(Allocation inV, Allocation out, boolean relaxed) {
   13684         long[] arrayInV = new long[INPUTSIZE * 2];
   13685         inV.copyTo(arrayInV);
   13686         int[] arrayOut = new int[INPUTSIZE * 2];
   13687         out.copyTo(arrayOut);
   13688         for (int i = 0; i < INPUTSIZE; i++) {
   13689             for (int j = 0; j < 2 ; j++) {
   13690                 // Extract the inputs.
   13691                 ArgumentsUlongUint args = new ArgumentsUlongUint();
   13692                 args.inV = arrayInV[i * 2 + j];
   13693                 // Figure out what the outputs should have been.
   13694                 CoreMathVerifier.computeConvert(args);
   13695                 // Validate the outputs.
   13696                 boolean valid = true;
   13697                 if (args.out != arrayOut[i * 2 + j]) {
   13698                     valid = false;
   13699                 }
   13700                 if (!valid) {
   13701                     StringBuilder message = new StringBuilder();
   13702                     message.append("Input inV: ");
   13703                     message.append(String.format("0x%x", args.inV));
   13704                     message.append("\n");
   13705                     message.append("Expected output out: ");
   13706                     message.append(String.format("0x%x", args.out));
   13707                     message.append("\n");
   13708                     message.append("Actual   output out: ");
   13709                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   13710                     if (args.out != arrayOut[i * 2 + j]) {
   13711                         message.append(" FAIL");
   13712                     }
   13713                     message.append("\n");
   13714                     assertTrue("Incorrect output for checkConvertUlong2Uint2" +
   13715                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   13716                 }
   13717             }
   13718         }
   13719     }
   13720 
   13721     private void checkConvertUlong3Uint3() {
   13722         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_64, 3, 0x5cfe8c277e78b4e1l, false, 32);
   13723         try {
   13724             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE);
   13725             script.forEach_testConvertUint3Ulong3Uint3(inV, out);
   13726             verifyResultsConvertUlong3Uint3(inV, out, false);
   13727         } catch (Exception e) {
   13728             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint3Ulong3Uint3: " + e.toString());
   13729         }
   13730         try {
   13731             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 3), INPUTSIZE);
   13732             scriptRelaxed.forEach_testConvertUint3Ulong3Uint3(inV, out);
   13733             verifyResultsConvertUlong3Uint3(inV, out, true);
   13734         } catch (Exception e) {
   13735             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint3Ulong3Uint3: " + e.toString());
   13736         }
   13737     }
   13738 
   13739     private void verifyResultsConvertUlong3Uint3(Allocation inV, Allocation out, boolean relaxed) {
   13740         long[] arrayInV = new long[INPUTSIZE * 4];
   13741         inV.copyTo(arrayInV);
   13742         int[] arrayOut = new int[INPUTSIZE * 4];
   13743         out.copyTo(arrayOut);
   13744         for (int i = 0; i < INPUTSIZE; i++) {
   13745             for (int j = 0; j < 3 ; j++) {
   13746                 // Extract the inputs.
   13747                 ArgumentsUlongUint args = new ArgumentsUlongUint();
   13748                 args.inV = arrayInV[i * 4 + j];
   13749                 // Figure out what the outputs should have been.
   13750                 CoreMathVerifier.computeConvert(args);
   13751                 // Validate the outputs.
   13752                 boolean valid = true;
   13753                 if (args.out != arrayOut[i * 4 + j]) {
   13754                     valid = false;
   13755                 }
   13756                 if (!valid) {
   13757                     StringBuilder message = new StringBuilder();
   13758                     message.append("Input inV: ");
   13759                     message.append(String.format("0x%x", args.inV));
   13760                     message.append("\n");
   13761                     message.append("Expected output out: ");
   13762                     message.append(String.format("0x%x", args.out));
   13763                     message.append("\n");
   13764                     message.append("Actual   output out: ");
   13765                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   13766                     if (args.out != arrayOut[i * 4 + j]) {
   13767                         message.append(" FAIL");
   13768                     }
   13769                     message.append("\n");
   13770                     assertTrue("Incorrect output for checkConvertUlong3Uint3" +
   13771                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   13772                 }
   13773             }
   13774         }
   13775     }
   13776 
   13777     private void checkConvertUlong4Uint4() {
   13778         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_64, 4, 0x5cfe96c8dd8079d5l, false, 32);
   13779         try {
   13780             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE);
   13781             script.forEach_testConvertUint4Ulong4Uint4(inV, out);
   13782             verifyResultsConvertUlong4Uint4(inV, out, false);
   13783         } catch (Exception e) {
   13784             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint4Ulong4Uint4: " + e.toString());
   13785         }
   13786         try {
   13787             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_32, 4), INPUTSIZE);
   13788             scriptRelaxed.forEach_testConvertUint4Ulong4Uint4(inV, out);
   13789             verifyResultsConvertUlong4Uint4(inV, out, true);
   13790         } catch (Exception e) {
   13791             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUint4Ulong4Uint4: " + e.toString());
   13792         }
   13793     }
   13794 
   13795     private void verifyResultsConvertUlong4Uint4(Allocation inV, Allocation out, boolean relaxed) {
   13796         long[] arrayInV = new long[INPUTSIZE * 4];
   13797         inV.copyTo(arrayInV);
   13798         int[] arrayOut = new int[INPUTSIZE * 4];
   13799         out.copyTo(arrayOut);
   13800         for (int i = 0; i < INPUTSIZE; i++) {
   13801             for (int j = 0; j < 4 ; j++) {
   13802                 // Extract the inputs.
   13803                 ArgumentsUlongUint args = new ArgumentsUlongUint();
   13804                 args.inV = arrayInV[i * 4 + j];
   13805                 // Figure out what the outputs should have been.
   13806                 CoreMathVerifier.computeConvert(args);
   13807                 // Validate the outputs.
   13808                 boolean valid = true;
   13809                 if (args.out != arrayOut[i * 4 + j]) {
   13810                     valid = false;
   13811                 }
   13812                 if (!valid) {
   13813                     StringBuilder message = new StringBuilder();
   13814                     message.append("Input inV: ");
   13815                     message.append(String.format("0x%x", args.inV));
   13816                     message.append("\n");
   13817                     message.append("Expected output out: ");
   13818                     message.append(String.format("0x%x", args.out));
   13819                     message.append("\n");
   13820                     message.append("Actual   output out: ");
   13821                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   13822                     if (args.out != arrayOut[i * 4 + j]) {
   13823                         message.append(" FAIL");
   13824                     }
   13825                     message.append("\n");
   13826                     assertTrue("Incorrect output for checkConvertUlong4Uint4" +
   13827                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   13828                 }
   13829             }
   13830         }
   13831     }
   13832 
   13833     public class ArgumentsFloatDouble {
   13834         public float inV;
   13835         public Target.Floaty out;
   13836     }
   13837 
   13838     private void checkConvertFloat2Double2() {
   13839         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x36c6372446e08221l, -1.6163412428744576259e+38, 1.6163412428744576259e+38);
   13840         try {
   13841             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 2), INPUTSIZE);
   13842             script.forEach_testConvertDouble2Float2Double2(inV, out);
   13843             verifyResultsConvertFloat2Double2(inV, out, false);
   13844         } catch (Exception e) {
   13845             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble2Float2Double2: " + e.toString());
   13846         }
   13847         try {
   13848             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 2), INPUTSIZE);
   13849             scriptRelaxed.forEach_testConvertDouble2Float2Double2(inV, out);
   13850             verifyResultsConvertFloat2Double2(inV, out, true);
   13851         } catch (Exception e) {
   13852             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble2Float2Double2: " + e.toString());
   13853         }
   13854     }
   13855 
   13856     private void verifyResultsConvertFloat2Double2(Allocation inV, Allocation out, boolean relaxed) {
   13857         float[] arrayInV = new float[INPUTSIZE * 2];
   13858         inV.copyTo(arrayInV);
   13859         double[] arrayOut = new double[INPUTSIZE * 2];
   13860         out.copyTo(arrayOut);
   13861         for (int i = 0; i < INPUTSIZE; i++) {
   13862             for (int j = 0; j < 2 ; j++) {
   13863                 // Extract the inputs.
   13864                 ArgumentsFloatDouble args = new ArgumentsFloatDouble();
   13865                 args.inV = arrayInV[i * 2 + j];
   13866                 // Figure out what the outputs should have been.
   13867                 Target target = new Target(relaxed);
   13868                 CoreMathVerifier.computeConvert(args, target);
   13869                 // Validate the outputs.
   13870                 boolean valid = true;
   13871                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
   13872                     valid = false;
   13873                 }
   13874                 if (!valid) {
   13875                     StringBuilder message = new StringBuilder();
   13876                     message.append("Input inV: ");
   13877                     message.append(String.format("%14.8g {%8x} %15a",
   13878                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
   13879                     message.append("\n");
   13880                     message.append("Expected output out: ");
   13881                     message.append(args.out.toString());
   13882                     message.append("\n");
   13883                     message.append("Actual   output out: ");
   13884                     message.append(String.format("%24.8g {%16x} %31a",
   13885                             arrayOut[i * 2 + j], Double.doubleToRawLongBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j]));
   13886                     if (!args.out.couldBe(arrayOut[i * 2 + j])) {
   13887                         message.append(" FAIL");
   13888                     }
   13889                     message.append("\n");
   13890                     assertTrue("Incorrect output for checkConvertFloat2Double2" +
   13891                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   13892                 }
   13893             }
   13894         }
   13895     }
   13896 
   13897     private void checkConvertFloat3Double3() {
   13898         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x3712feab9d3c134dl, -1.6163412428744576259e+38, 1.6163412428744576259e+38);
   13899         try {
   13900             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 3), INPUTSIZE);
   13901             script.forEach_testConvertDouble3Float3Double3(inV, out);
   13902             verifyResultsConvertFloat3Double3(inV, out, false);
   13903         } catch (Exception e) {
   13904             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble3Float3Double3: " + e.toString());
   13905         }
   13906         try {
   13907             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 3), INPUTSIZE);
   13908             scriptRelaxed.forEach_testConvertDouble3Float3Double3(inV, out);
   13909             verifyResultsConvertFloat3Double3(inV, out, true);
   13910         } catch (Exception e) {
   13911             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble3Float3Double3: " + e.toString());
   13912         }
   13913     }
   13914 
   13915     private void verifyResultsConvertFloat3Double3(Allocation inV, Allocation out, boolean relaxed) {
   13916         float[] arrayInV = new float[INPUTSIZE * 4];
   13917         inV.copyTo(arrayInV);
   13918         double[] arrayOut = new double[INPUTSIZE * 4];
   13919         out.copyTo(arrayOut);
   13920         for (int i = 0; i < INPUTSIZE; i++) {
   13921             for (int j = 0; j < 3 ; j++) {
   13922                 // Extract the inputs.
   13923                 ArgumentsFloatDouble args = new ArgumentsFloatDouble();
   13924                 args.inV = arrayInV[i * 4 + j];
   13925                 // Figure out what the outputs should have been.
   13926                 Target target = new Target(relaxed);
   13927                 CoreMathVerifier.computeConvert(args, target);
   13928                 // Validate the outputs.
   13929                 boolean valid = true;
   13930                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   13931                     valid = false;
   13932                 }
   13933                 if (!valid) {
   13934                     StringBuilder message = new StringBuilder();
   13935                     message.append("Input inV: ");
   13936                     message.append(String.format("%14.8g {%8x} %15a",
   13937                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
   13938                     message.append("\n");
   13939                     message.append("Expected output out: ");
   13940                     message.append(args.out.toString());
   13941                     message.append("\n");
   13942                     message.append("Actual   output out: ");
   13943                     message.append(String.format("%24.8g {%16x} %31a",
   13944                             arrayOut[i * 4 + j], Double.doubleToRawLongBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
   13945                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   13946                         message.append(" FAIL");
   13947                     }
   13948                     message.append("\n");
   13949                     assertTrue("Incorrect output for checkConvertFloat3Double3" +
   13950                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   13951                 }
   13952             }
   13953         }
   13954     }
   13955 
   13956     private void checkConvertFloat4Double4() {
   13957         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x375fc632f397a479l, -1.6163412428744576259e+38, 1.6163412428744576259e+38);
   13958         try {
   13959             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 4), INPUTSIZE);
   13960             script.forEach_testConvertDouble4Float4Double4(inV, out);
   13961             verifyResultsConvertFloat4Double4(inV, out, false);
   13962         } catch (Exception e) {
   13963             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble4Float4Double4: " + e.toString());
   13964         }
   13965         try {
   13966             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 4), INPUTSIZE);
   13967             scriptRelaxed.forEach_testConvertDouble4Float4Double4(inV, out);
   13968             verifyResultsConvertFloat4Double4(inV, out, true);
   13969         } catch (Exception e) {
   13970             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble4Float4Double4: " + e.toString());
   13971         }
   13972     }
   13973 
   13974     private void verifyResultsConvertFloat4Double4(Allocation inV, Allocation out, boolean relaxed) {
   13975         float[] arrayInV = new float[INPUTSIZE * 4];
   13976         inV.copyTo(arrayInV);
   13977         double[] arrayOut = new double[INPUTSIZE * 4];
   13978         out.copyTo(arrayOut);
   13979         for (int i = 0; i < INPUTSIZE; i++) {
   13980             for (int j = 0; j < 4 ; j++) {
   13981                 // Extract the inputs.
   13982                 ArgumentsFloatDouble args = new ArgumentsFloatDouble();
   13983                 args.inV = arrayInV[i * 4 + j];
   13984                 // Figure out what the outputs should have been.
   13985                 Target target = new Target(relaxed);
   13986                 CoreMathVerifier.computeConvert(args, target);
   13987                 // Validate the outputs.
   13988                 boolean valid = true;
   13989                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   13990                     valid = false;
   13991                 }
   13992                 if (!valid) {
   13993                     StringBuilder message = new StringBuilder();
   13994                     message.append("Input inV: ");
   13995                     message.append(String.format("%14.8g {%8x} %15a",
   13996                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
   13997                     message.append("\n");
   13998                     message.append("Expected output out: ");
   13999                     message.append(args.out.toString());
   14000                     message.append("\n");
   14001                     message.append("Actual   output out: ");
   14002                     message.append(String.format("%24.8g {%16x} %31a",
   14003                             arrayOut[i * 4 + j], Double.doubleToRawLongBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
   14004                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   14005                         message.append(" FAIL");
   14006                     }
   14007                     message.append("\n");
   14008                     assertTrue("Incorrect output for checkConvertFloat4Double4" +
   14009                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   14010                 }
   14011             }
   14012         }
   14013     }
   14014 
   14015     public class ArgumentsCharDouble {
   14016         public byte inV;
   14017         public Target.Floaty out;
   14018     }
   14019 
   14020     private void checkConvertChar2Double2() {
   14021         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_8, 2, 0xd86d88e268ca2f61l, true, 7);
   14022         try {
   14023             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 2), INPUTSIZE);
   14024             script.forEach_testConvertDouble2Char2Double2(inV, out);
   14025             verifyResultsConvertChar2Double2(inV, out, false);
   14026         } catch (Exception e) {
   14027             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble2Char2Double2: " + e.toString());
   14028         }
   14029         try {
   14030             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 2), INPUTSIZE);
   14031             scriptRelaxed.forEach_testConvertDouble2Char2Double2(inV, out);
   14032             verifyResultsConvertChar2Double2(inV, out, true);
   14033         } catch (Exception e) {
   14034             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble2Char2Double2: " + e.toString());
   14035         }
   14036     }
   14037 
   14038     private void verifyResultsConvertChar2Double2(Allocation inV, Allocation out, boolean relaxed) {
   14039         byte[] arrayInV = new byte[INPUTSIZE * 2];
   14040         inV.copyTo(arrayInV);
   14041         double[] arrayOut = new double[INPUTSIZE * 2];
   14042         out.copyTo(arrayOut);
   14043         for (int i = 0; i < INPUTSIZE; i++) {
   14044             for (int j = 0; j < 2 ; j++) {
   14045                 // Extract the inputs.
   14046                 ArgumentsCharDouble args = new ArgumentsCharDouble();
   14047                 args.inV = arrayInV[i * 2 + j];
   14048                 // Figure out what the outputs should have been.
   14049                 Target target = new Target(relaxed);
   14050                 CoreMathVerifier.computeConvert(args, target);
   14051                 // Validate the outputs.
   14052                 boolean valid = true;
   14053                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
   14054                     valid = false;
   14055                 }
   14056                 if (!valid) {
   14057                     StringBuilder message = new StringBuilder();
   14058                     message.append("Input inV: ");
   14059                     message.append(String.format("%d", args.inV));
   14060                     message.append("\n");
   14061                     message.append("Expected output out: ");
   14062                     message.append(args.out.toString());
   14063                     message.append("\n");
   14064                     message.append("Actual   output out: ");
   14065                     message.append(String.format("%24.8g {%16x} %31a",
   14066                             arrayOut[i * 2 + j], Double.doubleToRawLongBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j]));
   14067                     if (!args.out.couldBe(arrayOut[i * 2 + j])) {
   14068                         message.append(" FAIL");
   14069                     }
   14070                     message.append("\n");
   14071                     assertTrue("Incorrect output for checkConvertChar2Double2" +
   14072                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   14073                 }
   14074             }
   14075         }
   14076     }
   14077 
   14078     private void checkConvertChar3Double3() {
   14079         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_8, 3, 0xd8ba5069bf25c08dl, true, 7);
   14080         try {
   14081             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 3), INPUTSIZE);
   14082             script.forEach_testConvertDouble3Char3Double3(inV, out);
   14083             verifyResultsConvertChar3Double3(inV, out, false);
   14084         } catch (Exception e) {
   14085             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble3Char3Double3: " + e.toString());
   14086         }
   14087         try {
   14088             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 3), INPUTSIZE);
   14089             scriptRelaxed.forEach_testConvertDouble3Char3Double3(inV, out);
   14090             verifyResultsConvertChar3Double3(inV, out, true);
   14091         } catch (Exception e) {
   14092             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble3Char3Double3: " + e.toString());
   14093         }
   14094     }
   14095 
   14096     private void verifyResultsConvertChar3Double3(Allocation inV, Allocation out, boolean relaxed) {
   14097         byte[] arrayInV = new byte[INPUTSIZE * 4];
   14098         inV.copyTo(arrayInV);
   14099         double[] arrayOut = new double[INPUTSIZE * 4];
   14100         out.copyTo(arrayOut);
   14101         for (int i = 0; i < INPUTSIZE; i++) {
   14102             for (int j = 0; j < 3 ; j++) {
   14103                 // Extract the inputs.
   14104                 ArgumentsCharDouble args = new ArgumentsCharDouble();
   14105                 args.inV = arrayInV[i * 4 + j];
   14106                 // Figure out what the outputs should have been.
   14107                 Target target = new Target(relaxed);
   14108                 CoreMathVerifier.computeConvert(args, target);
   14109                 // Validate the outputs.
   14110                 boolean valid = true;
   14111                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   14112                     valid = false;
   14113                 }
   14114                 if (!valid) {
   14115                     StringBuilder message = new StringBuilder();
   14116                     message.append("Input inV: ");
   14117                     message.append(String.format("%d", args.inV));
   14118                     message.append("\n");
   14119                     message.append("Expected output out: ");
   14120                     message.append(args.out.toString());
   14121                     message.append("\n");
   14122                     message.append("Actual   output out: ");
   14123                     message.append(String.format("%24.8g {%16x} %31a",
   14124                             arrayOut[i * 4 + j], Double.doubleToRawLongBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
   14125                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   14126                         message.append(" FAIL");
   14127                     }
   14128                     message.append("\n");
   14129                     assertTrue("Incorrect output for checkConvertChar3Double3" +
   14130                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   14131                 }
   14132             }
   14133         }
   14134     }
   14135 
   14136     private void checkConvertChar4Double4() {
   14137         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_8, 4, 0xd90717f1158151b9l, true, 7);
   14138         try {
   14139             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 4), INPUTSIZE);
   14140             script.forEach_testConvertDouble4Char4Double4(inV, out);
   14141             verifyResultsConvertChar4Double4(inV, out, false);
   14142         } catch (Exception e) {
   14143             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble4Char4Double4: " + e.toString());
   14144         }
   14145         try {
   14146             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 4), INPUTSIZE);
   14147             scriptRelaxed.forEach_testConvertDouble4Char4Double4(inV, out);
   14148             verifyResultsConvertChar4Double4(inV, out, true);
   14149         } catch (Exception e) {
   14150             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble4Char4Double4: " + e.toString());
   14151         }
   14152     }
   14153 
   14154     private void verifyResultsConvertChar4Double4(Allocation inV, Allocation out, boolean relaxed) {
   14155         byte[] arrayInV = new byte[INPUTSIZE * 4];
   14156         inV.copyTo(arrayInV);
   14157         double[] arrayOut = new double[INPUTSIZE * 4];
   14158         out.copyTo(arrayOut);
   14159         for (int i = 0; i < INPUTSIZE; i++) {
   14160             for (int j = 0; j < 4 ; j++) {
   14161                 // Extract the inputs.
   14162                 ArgumentsCharDouble args = new ArgumentsCharDouble();
   14163                 args.inV = arrayInV[i * 4 + j];
   14164                 // Figure out what the outputs should have been.
   14165                 Target target = new Target(relaxed);
   14166                 CoreMathVerifier.computeConvert(args, target);
   14167                 // Validate the outputs.
   14168                 boolean valid = true;
   14169                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   14170                     valid = false;
   14171                 }
   14172                 if (!valid) {
   14173                     StringBuilder message = new StringBuilder();
   14174                     message.append("Input inV: ");
   14175                     message.append(String.format("%d", args.inV));
   14176                     message.append("\n");
   14177                     message.append("Expected output out: ");
   14178                     message.append(args.out.toString());
   14179                     message.append("\n");
   14180                     message.append("Actual   output out: ");
   14181                     message.append(String.format("%24.8g {%16x} %31a",
   14182                             arrayOut[i * 4 + j], Double.doubleToRawLongBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
   14183                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   14184                         message.append(" FAIL");
   14185                     }
   14186                     message.append("\n");
   14187                     assertTrue("Incorrect output for checkConvertChar4Double4" +
   14188                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   14189                 }
   14190             }
   14191         }
   14192     }
   14193 
   14194     public class ArgumentsUcharDouble {
   14195         public byte inV;
   14196         public Target.Floaty out;
   14197     }
   14198 
   14199     private void checkConvertUchar2Double2() {
   14200         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_8, 2, 0x70cea2996167f1al, false, 8);
   14201         try {
   14202             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 2), INPUTSIZE);
   14203             script.forEach_testConvertDouble2Uchar2Double2(inV, out);
   14204             verifyResultsConvertUchar2Double2(inV, out, false);
   14205         } catch (Exception e) {
   14206             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble2Uchar2Double2: " + e.toString());
   14207         }
   14208         try {
   14209             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 2), INPUTSIZE);
   14210             scriptRelaxed.forEach_testConvertDouble2Uchar2Double2(inV, out);
   14211             verifyResultsConvertUchar2Double2(inV, out, true);
   14212         } catch (Exception e) {
   14213             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble2Uchar2Double2: " + e.toString());
   14214         }
   14215     }
   14216 
   14217     private void verifyResultsConvertUchar2Double2(Allocation inV, Allocation out, boolean relaxed) {
   14218         byte[] arrayInV = new byte[INPUTSIZE * 2];
   14219         inV.copyTo(arrayInV);
   14220         double[] arrayOut = new double[INPUTSIZE * 2];
   14221         out.copyTo(arrayOut);
   14222         for (int i = 0; i < INPUTSIZE; i++) {
   14223             for (int j = 0; j < 2 ; j++) {
   14224                 // Extract the inputs.
   14225                 ArgumentsUcharDouble args = new ArgumentsUcharDouble();
   14226                 args.inV = arrayInV[i * 2 + j];
   14227                 // Figure out what the outputs should have been.
   14228                 Target target = new Target(relaxed);
   14229                 CoreMathVerifier.computeConvert(args, target);
   14230                 // Validate the outputs.
   14231                 boolean valid = true;
   14232                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
   14233                     valid = false;
   14234                 }
   14235                 if (!valid) {
   14236                     StringBuilder message = new StringBuilder();
   14237                     message.append("Input inV: ");
   14238                     message.append(String.format("0x%x", args.inV));
   14239                     message.append("\n");
   14240                     message.append("Expected output out: ");
   14241                     message.append(args.out.toString());
   14242                     message.append("\n");
   14243                     message.append("Actual   output out: ");
   14244                     message.append(String.format("%24.8g {%16x} %31a",
   14245                             arrayOut[i * 2 + j], Double.doubleToRawLongBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j]));
   14246                     if (!args.out.couldBe(arrayOut[i * 2 + j])) {
   14247                         message.append(" FAIL");
   14248                     }
   14249                     message.append("\n");
   14250                     assertTrue("Incorrect output for checkConvertUchar2Double2" +
   14251                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   14252                 }
   14253             }
   14254         }
   14255     }
   14256 
   14257     private void checkConvertUchar3Double3() {
   14258         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_8, 3, 0x759b1b0ec721046l, false, 8);
   14259         try {
   14260             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 3), INPUTSIZE);
   14261             script.forEach_testConvertDouble3Uchar3Double3(inV, out);
   14262             verifyResultsConvertUchar3Double3(inV, out, false);
   14263         } catch (Exception e) {
   14264             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble3Uchar3Double3: " + e.toString());
   14265         }
   14266         try {
   14267             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 3), INPUTSIZE);
   14268             scriptRelaxed.forEach_testConvertDouble3Uchar3Double3(inV, out);
   14269             verifyResultsConvertUchar3Double3(inV, out, true);
   14270         } catch (Exception e) {
   14271             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble3Uchar3Double3: " + e.toString());
   14272         }
   14273     }
   14274 
   14275     private void verifyResultsConvertUchar3Double3(Allocation inV, Allocation out, boolean relaxed) {
   14276         byte[] arrayInV = new byte[INPUTSIZE * 4];
   14277         inV.copyTo(arrayInV);
   14278         double[] arrayOut = new double[INPUTSIZE * 4];
   14279         out.copyTo(arrayOut);
   14280         for (int i = 0; i < INPUTSIZE; i++) {
   14281             for (int j = 0; j < 3 ; j++) {
   14282                 // Extract the inputs.
   14283                 ArgumentsUcharDouble args = new ArgumentsUcharDouble();
   14284                 args.inV = arrayInV[i * 4 + j];
   14285                 // Figure out what the outputs should have been.
   14286                 Target target = new Target(relaxed);
   14287                 CoreMathVerifier.computeConvert(args, target);
   14288                 // Validate the outputs.
   14289                 boolean valid = true;
   14290                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   14291                     valid = false;
   14292                 }
   14293                 if (!valid) {
   14294                     StringBuilder message = new StringBuilder();
   14295                     message.append("Input inV: ");
   14296                     message.append(String.format("0x%x", args.inV));
   14297                     message.append("\n");
   14298                     message.append("Expected output out: ");
   14299                     message.append(args.out.toString());
   14300                     message.append("\n");
   14301                     message.append("Actual   output out: ");
   14302                     message.append(String.format("%24.8g {%16x} %31a",
   14303                             arrayOut[i * 4 + j], Double.doubleToRawLongBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
   14304                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   14305                         message.append(" FAIL");
   14306                     }
   14307                     message.append("\n");
   14308                     assertTrue("Incorrect output for checkConvertUchar3Double3" +
   14309                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   14310                 }
   14311             }
   14312         }
   14313     }
   14314 
   14315     private void checkConvertUchar4Double4() {
   14316         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_8, 4, 0x7a6793842cda172l, false, 8);
   14317         try {
   14318             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 4), INPUTSIZE);
   14319             script.forEach_testConvertDouble4Uchar4Double4(inV, out);
   14320             verifyResultsConvertUchar4Double4(inV, out, false);
   14321         } catch (Exception e) {
   14322             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble4Uchar4Double4: " + e.toString());
   14323         }
   14324         try {
   14325             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 4), INPUTSIZE);
   14326             scriptRelaxed.forEach_testConvertDouble4Uchar4Double4(inV, out);
   14327             verifyResultsConvertUchar4Double4(inV, out, true);
   14328         } catch (Exception e) {
   14329             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble4Uchar4Double4: " + e.toString());
   14330         }
   14331     }
   14332 
   14333     private void verifyResultsConvertUchar4Double4(Allocation inV, Allocation out, boolean relaxed) {
   14334         byte[] arrayInV = new byte[INPUTSIZE * 4];
   14335         inV.copyTo(arrayInV);
   14336         double[] arrayOut = new double[INPUTSIZE * 4];
   14337         out.copyTo(arrayOut);
   14338         for (int i = 0; i < INPUTSIZE; i++) {
   14339             for (int j = 0; j < 4 ; j++) {
   14340                 // Extract the inputs.
   14341                 ArgumentsUcharDouble args = new ArgumentsUcharDouble();
   14342                 args.inV = arrayInV[i * 4 + j];
   14343                 // Figure out what the outputs should have been.
   14344                 Target target = new Target(relaxed);
   14345                 CoreMathVerifier.computeConvert(args, target);
   14346                 // Validate the outputs.
   14347                 boolean valid = true;
   14348                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   14349                     valid = false;
   14350                 }
   14351                 if (!valid) {
   14352                     StringBuilder message = new StringBuilder();
   14353                     message.append("Input inV: ");
   14354                     message.append(String.format("0x%x", args.inV));
   14355                     message.append("\n");
   14356                     message.append("Expected output out: ");
   14357                     message.append(args.out.toString());
   14358                     message.append("\n");
   14359                     message.append("Actual   output out: ");
   14360                     message.append(String.format("%24.8g {%16x} %31a",
   14361                             arrayOut[i * 4 + j], Double.doubleToRawLongBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
   14362                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   14363                         message.append(" FAIL");
   14364                     }
   14365                     message.append("\n");
   14366                     assertTrue("Incorrect output for checkConvertUchar4Double4" +
   14367                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   14368                 }
   14369             }
   14370         }
   14371     }
   14372 
   14373     public class ArgumentsShortDouble {
   14374         public short inV;
   14375         public Target.Floaty out;
   14376     }
   14377 
   14378     private void checkConvertShort2Double2() {
   14379         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_16, 2, 0xfdeea470023d0105l, true, 15);
   14380         try {
   14381             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 2), INPUTSIZE);
   14382             script.forEach_testConvertDouble2Short2Double2(inV, out);
   14383             verifyResultsConvertShort2Double2(inV, out, false);
   14384         } catch (Exception e) {
   14385             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble2Short2Double2: " + e.toString());
   14386         }
   14387         try {
   14388             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 2), INPUTSIZE);
   14389             scriptRelaxed.forEach_testConvertDouble2Short2Double2(inV, out);
   14390             verifyResultsConvertShort2Double2(inV, out, true);
   14391         } catch (Exception e) {
   14392             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble2Short2Double2: " + e.toString());
   14393         }
   14394     }
   14395 
   14396     private void verifyResultsConvertShort2Double2(Allocation inV, Allocation out, boolean relaxed) {
   14397         short[] arrayInV = new short[INPUTSIZE * 2];
   14398         inV.copyTo(arrayInV);
   14399         double[] arrayOut = new double[INPUTSIZE * 2];
   14400         out.copyTo(arrayOut);
   14401         for (int i = 0; i < INPUTSIZE; i++) {
   14402             for (int j = 0; j < 2 ; j++) {
   14403                 // Extract the inputs.
   14404                 ArgumentsShortDouble args = new ArgumentsShortDouble();
   14405                 args.inV = arrayInV[i * 2 + j];
   14406                 // Figure out what the outputs should have been.
   14407                 Target target = new Target(relaxed);
   14408                 CoreMathVerifier.computeConvert(args, target);
   14409                 // Validate the outputs.
   14410                 boolean valid = true;
   14411                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
   14412                     valid = false;
   14413                 }
   14414                 if (!valid) {
   14415                     StringBuilder message = new StringBuilder();
   14416                     message.append("Input inV: ");
   14417                     message.append(String.format("%d", args.inV));
   14418                     message.append("\n");
   14419                     message.append("Expected output out: ");
   14420                     message.append(args.out.toString());
   14421                     message.append("\n");
   14422                     message.append("Actual   output out: ");
   14423                     message.append(String.format("%24.8g {%16x} %31a",
   14424                             arrayOut[i * 2 + j], Double.doubleToRawLongBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j]));
   14425                     if (!args.out.couldBe(arrayOut[i * 2 + j])) {
   14426                         message.append(" FAIL");
   14427                     }
   14428                     message.append("\n");
   14429                     assertTrue("Incorrect output for checkConvertShort2Double2" +
   14430                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   14431                 }
   14432             }
   14433         }
   14434     }
   14435 
   14436     private void checkConvertShort3Double3() {
   14437         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_16, 3, 0xfe3b6bf758989231l, true, 15);
   14438         try {
   14439             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 3), INPUTSIZE);
   14440             script.forEach_testConvertDouble3Short3Double3(inV, out);
   14441             verifyResultsConvertShort3Double3(inV, out, false);
   14442         } catch (Exception e) {
   14443             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble3Short3Double3: " + e.toString());
   14444         }
   14445         try {
   14446             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 3), INPUTSIZE);
   14447             scriptRelaxed.forEach_testConvertDouble3Short3Double3(inV, out);
   14448             verifyResultsConvertShort3Double3(inV, out, true);
   14449         } catch (Exception e) {
   14450             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble3Short3Double3: " + e.toString());
   14451         }
   14452     }
   14453 
   14454     private void verifyResultsConvertShort3Double3(Allocation inV, Allocation out, boolean relaxed) {
   14455         short[] arrayInV = new short[INPUTSIZE * 4];
   14456         inV.copyTo(arrayInV);
   14457         double[] arrayOut = new double[INPUTSIZE * 4];
   14458         out.copyTo(arrayOut);
   14459         for (int i = 0; i < INPUTSIZE; i++) {
   14460             for (int j = 0; j < 3 ; j++) {
   14461                 // Extract the inputs.
   14462                 ArgumentsShortDouble args = new ArgumentsShortDouble();
   14463                 args.inV = arrayInV[i * 4 + j];
   14464                 // Figure out what the outputs should have been.
   14465                 Target target = new Target(relaxed);
   14466                 CoreMathVerifier.computeConvert(args, target);
   14467                 // Validate the outputs.
   14468                 boolean valid = true;
   14469                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   14470                     valid = false;
   14471                 }
   14472                 if (!valid) {
   14473                     StringBuilder message = new StringBuilder();
   14474                     message.append("Input inV: ");
   14475                     message.append(String.format("%d", args.inV));
   14476                     message.append("\n");
   14477                     message.append("Expected output out: ");
   14478                     message.append(args.out.toString());
   14479                     message.append("\n");
   14480                     message.append("Actual   output out: ");
   14481                     message.append(String.format("%24.8g {%16x} %31a",
   14482                             arrayOut[i * 4 + j], Double.doubleToRawLongBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
   14483                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   14484                         message.append(" FAIL");
   14485                     }
   14486                     message.append("\n");
   14487                     assertTrue("Incorrect output for checkConvertShort3Double3" +
   14488                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   14489                 }
   14490             }
   14491         }
   14492     }
   14493 
   14494     private void checkConvertShort4Double4() {
   14495         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_16, 4, 0xfe88337eaef4235dl, true, 15);
   14496         try {
   14497             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 4), INPUTSIZE);
   14498             script.forEach_testConvertDouble4Short4Double4(inV, out);
   14499             verifyResultsConvertShort4Double4(inV, out, false);
   14500         } catch (Exception e) {
   14501             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble4Short4Double4: " + e.toString());
   14502         }
   14503         try {
   14504             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 4), INPUTSIZE);
   14505             scriptRelaxed.forEach_testConvertDouble4Short4Double4(inV, out);
   14506             verifyResultsConvertShort4Double4(inV, out, true);
   14507         } catch (Exception e) {
   14508             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble4Short4Double4: " + e.toString());
   14509         }
   14510     }
   14511 
   14512     private void verifyResultsConvertShort4Double4(Allocation inV, Allocation out, boolean relaxed) {
   14513         short[] arrayInV = new short[INPUTSIZE * 4];
   14514         inV.copyTo(arrayInV);
   14515         double[] arrayOut = new double[INPUTSIZE * 4];
   14516         out.copyTo(arrayOut);
   14517         for (int i = 0; i < INPUTSIZE; i++) {
   14518             for (int j = 0; j < 4 ; j++) {
   14519                 // Extract the inputs.
   14520                 ArgumentsShortDouble args = new ArgumentsShortDouble();
   14521                 args.inV = arrayInV[i * 4 + j];
   14522                 // Figure out what the outputs should have been.
   14523                 Target target = new Target(relaxed);
   14524                 CoreMathVerifier.computeConvert(args, target);
   14525                 // Validate the outputs.
   14526                 boolean valid = true;
   14527                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   14528                     valid = false;
   14529                 }
   14530                 if (!valid) {
   14531                     StringBuilder message = new StringBuilder();
   14532                     message.append("Input inV: ");
   14533                     message.append(String.format("%d", args.inV));
   14534                     message.append("\n");
   14535                     message.append("Expected output out: ");
   14536                     message.append(args.out.toString());
   14537                     message.append("\n");
   14538                     message.append("Actual   output out: ");
   14539                     message.append(String.format("%24.8g {%16x} %31a",
   14540                             arrayOut[i * 4 + j], Double.doubleToRawLongBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
   14541                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   14542                         message.append(" FAIL");
   14543                     }
   14544                     message.append("\n");
   14545                     assertTrue("Incorrect output for checkConvertShort4Double4" +
   14546                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   14547                 }
   14548             }
   14549         }
   14550     }
   14551 
   14552     public class ArgumentsUshortDouble {
   14553         public short inV;
   14554         public Target.Floaty out;
   14555     }
   14556 
   14557     private void checkConvertUshort2Double2() {
   14558         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_16, 2, 0xd2b3fb649e0e6518l, false, 16);
   14559         try {
   14560             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 2), INPUTSIZE);
   14561             script.forEach_testConvertDouble2Ushort2Double2(inV, out);
   14562             verifyResultsConvertUshort2Double2(inV, out, false);
   14563         } catch (Exception e) {
   14564             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble2Ushort2Double2: " + e.toString());
   14565         }
   14566         try {
   14567             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 2), INPUTSIZE);
   14568             scriptRelaxed.forEach_testConvertDouble2Ushort2Double2(inV, out);
   14569             verifyResultsConvertUshort2Double2(inV, out, true);
   14570         } catch (Exception e) {
   14571             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble2Ushort2Double2: " + e.toString());
   14572         }
   14573     }
   14574 
   14575     private void verifyResultsConvertUshort2Double2(Allocation inV, Allocation out, boolean relaxed) {
   14576         short[] arrayInV = new short[INPUTSIZE * 2];
   14577         inV.copyTo(arrayInV);
   14578         double[] arrayOut = new double[INPUTSIZE * 2];
   14579         out.copyTo(arrayOut);
   14580         for (int i = 0; i < INPUTSIZE; i++) {
   14581             for (int j = 0; j < 2 ; j++) {
   14582                 // Extract the inputs.
   14583                 ArgumentsUshortDouble args = new ArgumentsUshortDouble();
   14584                 args.inV = arrayInV[i * 2 + j];
   14585                 // Figure out what the outputs should have been.
   14586                 Target target = new Target(relaxed);
   14587                 CoreMathVerifier.computeConvert(args, target);
   14588                 // Validate the outputs.
   14589                 boolean valid = true;
   14590                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
   14591                     valid = false;
   14592                 }
   14593                 if (!valid) {
   14594                     StringBuilder message = new StringBuilder();
   14595                     message.append("Input inV: ");
   14596                     message.append(String.format("0x%x", args.inV));
   14597                     message.append("\n");
   14598                     message.append("Expected output out: ");
   14599                     message.append(args.out.toString());
   14600                     message.append("\n");
   14601                     message.append("Actual   output out: ");
   14602                     message.append(String.format("%24.8g {%16x} %31a",
   14603                             arrayOut[i * 2 + j], Double.doubleToRawLongBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j]));
   14604                     if (!args.out.couldBe(arrayOut[i * 2 + j])) {
   14605                         message.append(" FAIL");
   14606                     }
   14607                     message.append("\n");
   14608                     assertTrue("Incorrect output for checkConvertUshort2Double2" +
   14609                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   14610                 }
   14611             }
   14612         }
   14613     }
   14614 
   14615     private void checkConvertUshort3Double3() {
   14616         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_16, 3, 0xd300c2ebf469f644l, false, 16);
   14617         try {
   14618             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 3), INPUTSIZE);
   14619             script.forEach_testConvertDouble3Ushort3Double3(inV, out);
   14620             verifyResultsConvertUshort3Double3(inV, out, false);
   14621         } catch (Exception e) {
   14622             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble3Ushort3Double3: " + e.toString());
   14623         }
   14624         try {
   14625             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 3), INPUTSIZE);
   14626             scriptRelaxed.forEach_testConvertDouble3Ushort3Double3(inV, out);
   14627             verifyResultsConvertUshort3Double3(inV, out, true);
   14628         } catch (Exception e) {
   14629             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble3Ushort3Double3: " + e.toString());
   14630         }
   14631     }
   14632 
   14633     private void verifyResultsConvertUshort3Double3(Allocation inV, Allocation out, boolean relaxed) {
   14634         short[] arrayInV = new short[INPUTSIZE * 4];
   14635         inV.copyTo(arrayInV);
   14636         double[] arrayOut = new double[INPUTSIZE * 4];
   14637         out.copyTo(arrayOut);
   14638         for (int i = 0; i < INPUTSIZE; i++) {
   14639             for (int j = 0; j < 3 ; j++) {
   14640                 // Extract the inputs.
   14641                 ArgumentsUshortDouble args = new ArgumentsUshortDouble();
   14642                 args.inV = arrayInV[i * 4 + j];
   14643                 // Figure out what the outputs should have been.
   14644                 Target target = new Target(relaxed);
   14645                 CoreMathVerifier.computeConvert(args, target);
   14646                 // Validate the outputs.
   14647                 boolean valid = true;
   14648                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   14649                     valid = false;
   14650                 }
   14651                 if (!valid) {
   14652                     StringBuilder message = new StringBuilder();
   14653                     message.append("Input inV: ");
   14654                     message.append(String.format("0x%x", args.inV));
   14655                     message.append("\n");
   14656                     message.append("Expected output out: ");
   14657                     message.append(args.out.toString());
   14658                     message.append("\n");
   14659                     message.append("Actual   output out: ");
   14660                     message.append(String.format("%24.8g {%16x} %31a",
   14661                             arrayOut[i * 4 + j], Double.doubleToRawLongBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
   14662                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   14663                         message.append(" FAIL");
   14664                     }
   14665                     message.append("\n");
   14666                     assertTrue("Incorrect output for checkConvertUshort3Double3" +
   14667                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   14668                 }
   14669             }
   14670         }
   14671     }
   14672 
   14673     private void checkConvertUshort4Double4() {
   14674         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_16, 4, 0xd34d8a734ac58770l, false, 16);
   14675         try {
   14676             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 4), INPUTSIZE);
   14677             script.forEach_testConvertDouble4Ushort4Double4(inV, out);
   14678             verifyResultsConvertUshort4Double4(inV, out, false);
   14679         } catch (Exception e) {
   14680             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble4Ushort4Double4: " + e.toString());
   14681         }
   14682         try {
   14683             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 4), INPUTSIZE);
   14684             scriptRelaxed.forEach_testConvertDouble4Ushort4Double4(inV, out);
   14685             verifyResultsConvertUshort4Double4(inV, out, true);
   14686         } catch (Exception e) {
   14687             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble4Ushort4Double4: " + e.toString());
   14688         }
   14689     }
   14690 
   14691     private void verifyResultsConvertUshort4Double4(Allocation inV, Allocation out, boolean relaxed) {
   14692         short[] arrayInV = new short[INPUTSIZE * 4];
   14693         inV.copyTo(arrayInV);
   14694         double[] arrayOut = new double[INPUTSIZE * 4];
   14695         out.copyTo(arrayOut);
   14696         for (int i = 0; i < INPUTSIZE; i++) {
   14697             for (int j = 0; j < 4 ; j++) {
   14698                 // Extract the inputs.
   14699                 ArgumentsUshortDouble args = new ArgumentsUshortDouble();
   14700                 args.inV = arrayInV[i * 4 + j];
   14701                 // Figure out what the outputs should have been.
   14702                 Target target = new Target(relaxed);
   14703                 CoreMathVerifier.computeConvert(args, target);
   14704                 // Validate the outputs.
   14705                 boolean valid = true;
   14706                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   14707                     valid = false;
   14708                 }
   14709                 if (!valid) {
   14710                     StringBuilder message = new StringBuilder();
   14711                     message.append("Input inV: ");
   14712                     message.append(String.format("0x%x", args.inV));
   14713                     message.append("\n");
   14714                     message.append("Expected output out: ");
   14715                     message.append(args.out.toString());
   14716                     message.append("\n");
   14717                     message.append("Actual   output out: ");
   14718                     message.append(String.format("%24.8g {%16x} %31a",
   14719                             arrayOut[i * 4 + j], Double.doubleToRawLongBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
   14720                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   14721                         message.append(" FAIL");
   14722                     }
   14723                     message.append("\n");
   14724                     assertTrue("Incorrect output for checkConvertUshort4Double4" +
   14725                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   14726                 }
   14727             }
   14728         }
   14729     }
   14730 
   14731     public class ArgumentsIntDouble {
   14732         public int inV;
   14733         public Target.Floaty out;
   14734     }
   14735 
   14736     private void checkConvertInt2Double2() {
   14737         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_32, 2, 0x1be423b7a40fc8f6l, true, 31);
   14738         try {
   14739             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 2), INPUTSIZE);
   14740             script.forEach_testConvertDouble2Int2Double2(inV, out);
   14741             verifyResultsConvertInt2Double2(inV, out, false);
   14742         } catch (Exception e) {
   14743             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble2Int2Double2: " + e.toString());
   14744         }
   14745         try {
   14746             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 2), INPUTSIZE);
   14747             scriptRelaxed.forEach_testConvertDouble2Int2Double2(inV, out);
   14748             verifyResultsConvertInt2Double2(inV, out, true);
   14749         } catch (Exception e) {
   14750             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble2Int2Double2: " + e.toString());
   14751         }
   14752     }
   14753 
   14754     private void verifyResultsConvertInt2Double2(Allocation inV, Allocation out, boolean relaxed) {
   14755         int[] arrayInV = new int[INPUTSIZE * 2];
   14756         inV.copyTo(arrayInV);
   14757         double[] arrayOut = new double[INPUTSIZE * 2];
   14758         out.copyTo(arrayOut);
   14759         for (int i = 0; i < INPUTSIZE; i++) {
   14760             for (int j = 0; j < 2 ; j++) {
   14761                 // Extract the inputs.
   14762                 ArgumentsIntDouble args = new ArgumentsIntDouble();
   14763                 args.inV = arrayInV[i * 2 + j];
   14764                 // Figure out what the outputs should have been.
   14765                 Target target = new Target(relaxed);
   14766                 CoreMathVerifier.computeConvert(args, target);
   14767                 // Validate the outputs.
   14768                 boolean valid = true;
   14769                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
   14770                     valid = false;
   14771                 }
   14772                 if (!valid) {
   14773                     StringBuilder message = new StringBuilder();
   14774                     message.append("Input inV: ");
   14775                     message.append(String.format("%d", args.inV));
   14776                     message.append("\n");
   14777                     message.append("Expected output out: ");
   14778                     message.append(args.out.toString());
   14779                     message.append("\n");
   14780                     message.append("Actual   output out: ");
   14781                     message.append(String.format("%24.8g {%16x} %31a",
   14782                             arrayOut[i * 2 + j], Double.doubleToRawLongBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j]));
   14783                     if (!args.out.couldBe(arrayOut[i * 2 + j])) {
   14784                         message.append(" FAIL");
   14785                     }
   14786                     message.append("\n");
   14787                     assertTrue("Incorrect output for checkConvertInt2Double2" +
   14788                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   14789                 }
   14790             }
   14791         }
   14792     }
   14793 
   14794     private void checkConvertInt3Double3() {
   14795         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_32, 3, 0x1c30eb3efa6b5a22l, true, 31);
   14796         try {
   14797             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 3), INPUTSIZE);
   14798             script.forEach_testConvertDouble3Int3Double3(inV, out);
   14799             verifyResultsConvertInt3Double3(inV, out, false);
   14800         } catch (Exception e) {
   14801             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble3Int3Double3: " + e.toString());
   14802         }
   14803         try {
   14804             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 3), INPUTSIZE);
   14805             scriptRelaxed.forEach_testConvertDouble3Int3Double3(inV, out);
   14806             verifyResultsConvertInt3Double3(inV, out, true);
   14807         } catch (Exception e) {
   14808             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble3Int3Double3: " + e.toString());
   14809         }
   14810     }
   14811 
   14812     private void verifyResultsConvertInt3Double3(Allocation inV, Allocation out, boolean relaxed) {
   14813         int[] arrayInV = new int[INPUTSIZE * 4];
   14814         inV.copyTo(arrayInV);
   14815         double[] arrayOut = new double[INPUTSIZE * 4];
   14816         out.copyTo(arrayOut);
   14817         for (int i = 0; i < INPUTSIZE; i++) {
   14818             for (int j = 0; j < 3 ; j++) {
   14819                 // Extract the inputs.
   14820                 ArgumentsIntDouble args = new ArgumentsIntDouble();
   14821                 args.inV = arrayInV[i * 4 + j];
   14822                 // Figure out what the outputs should have been.
   14823                 Target target = new Target(relaxed);
   14824                 CoreMathVerifier.computeConvert(args, target);
   14825                 // Validate the outputs.
   14826                 boolean valid = true;
   14827                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   14828                     valid = false;
   14829                 }
   14830                 if (!valid) {
   14831                     StringBuilder message = new StringBuilder();
   14832                     message.append("Input inV: ");
   14833                     message.append(String.format("%d", args.inV));
   14834                     message.append("\n");
   14835                     message.append("Expected output out: ");
   14836                     message.append(args.out.toString());
   14837                     message.append("\n");
   14838                     message.append("Actual   output out: ");
   14839                     message.append(String.format("%24.8g {%16x} %31a",
   14840                             arrayOut[i * 4 + j], Double.doubleToRawLongBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
   14841                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   14842                         message.append(" FAIL");
   14843                     }
   14844                     message.append("\n");
   14845                     assertTrue("Incorrect output for checkConvertInt3Double3" +
   14846                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   14847                 }
   14848             }
   14849         }
   14850     }
   14851 
   14852     private void checkConvertInt4Double4() {
   14853         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_32, 4, 0x1c7db2c650c6eb4el, true, 31);
   14854         try {
   14855             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 4), INPUTSIZE);
   14856             script.forEach_testConvertDouble4Int4Double4(inV, out);
   14857             verifyResultsConvertInt4Double4(inV, out, false);
   14858         } catch (Exception e) {
   14859             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble4Int4Double4: " + e.toString());
   14860         }
   14861         try {
   14862             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 4), INPUTSIZE);
   14863             scriptRelaxed.forEach_testConvertDouble4Int4Double4(inV, out);
   14864             verifyResultsConvertInt4Double4(inV, out, true);
   14865         } catch (Exception e) {
   14866             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble4Int4Double4: " + e.toString());
   14867         }
   14868     }
   14869 
   14870     private void verifyResultsConvertInt4Double4(Allocation inV, Allocation out, boolean relaxed) {
   14871         int[] arrayInV = new int[INPUTSIZE * 4];
   14872         inV.copyTo(arrayInV);
   14873         double[] arrayOut = new double[INPUTSIZE * 4];
   14874         out.copyTo(arrayOut);
   14875         for (int i = 0; i < INPUTSIZE; i++) {
   14876             for (int j = 0; j < 4 ; j++) {
   14877                 // Extract the inputs.
   14878                 ArgumentsIntDouble args = new ArgumentsIntDouble();
   14879                 args.inV = arrayInV[i * 4 + j];
   14880                 // Figure out what the outputs should have been.
   14881                 Target target = new Target(relaxed);
   14882                 CoreMathVerifier.computeConvert(args, target);
   14883                 // Validate the outputs.
   14884                 boolean valid = true;
   14885                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   14886                     valid = false;
   14887                 }
   14888                 if (!valid) {
   14889                     StringBuilder message = new StringBuilder();
   14890                     message.append("Input inV: ");
   14891                     message.append(String.format("%d", args.inV));
   14892                     message.append("\n");
   14893                     message.append("Expected output out: ");
   14894                     message.append(args.out.toString());
   14895                     message.append("\n");
   14896                     message.append("Actual   output out: ");
   14897                     message.append(String.format("%24.8g {%16x} %31a",
   14898                             arrayOut[i * 4 + j], Double.doubleToRawLongBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
   14899                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   14900                         message.append(" FAIL");
   14901                     }
   14902                     message.append("\n");
   14903                     assertTrue("Incorrect output for checkConvertInt4Double4" +
   14904                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   14905                 }
   14906             }
   14907         }
   14908     }
   14909 
   14910     public class ArgumentsUintDouble {
   14911         public int inV;
   14912         public Target.Floaty out;
   14913     }
   14914 
   14915     private void checkConvertUint2Double2() {
   14916         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_32, 2, 0x40b243bf3fe7e2a1l, false, 32);
   14917         try {
   14918             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 2), INPUTSIZE);
   14919             script.forEach_testConvertDouble2Uint2Double2(inV, out);
   14920             verifyResultsConvertUint2Double2(inV, out, false);
   14921         } catch (Exception e) {
   14922             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble2Uint2Double2: " + e.toString());
   14923         }
   14924         try {
   14925             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 2), INPUTSIZE);
   14926             scriptRelaxed.forEach_testConvertDouble2Uint2Double2(inV, out);
   14927             verifyResultsConvertUint2Double2(inV, out, true);
   14928         } catch (Exception e) {
   14929             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble2Uint2Double2: " + e.toString());
   14930         }
   14931     }
   14932 
   14933     private void verifyResultsConvertUint2Double2(Allocation inV, Allocation out, boolean relaxed) {
   14934         int[] arrayInV = new int[INPUTSIZE * 2];
   14935         inV.copyTo(arrayInV);
   14936         double[] arrayOut = new double[INPUTSIZE * 2];
   14937         out.copyTo(arrayOut);
   14938         for (int i = 0; i < INPUTSIZE; i++) {
   14939             for (int j = 0; j < 2 ; j++) {
   14940                 // Extract the inputs.
   14941                 ArgumentsUintDouble args = new ArgumentsUintDouble();
   14942                 args.inV = arrayInV[i * 2 + j];
   14943                 // Figure out what the outputs should have been.
   14944                 Target target = new Target(relaxed);
   14945                 CoreMathVerifier.computeConvert(args, target);
   14946                 // Validate the outputs.
   14947                 boolean valid = true;
   14948                 if (!args.out.couldBe(arrayOut[i * 2 + j])) {
   14949                     valid = false;
   14950                 }
   14951                 if (!valid) {
   14952                     StringBuilder message = new StringBuilder();
   14953                     message.append("Input inV: ");
   14954                     message.append(String.format("0x%x", args.inV));
   14955                     message.append("\n");
   14956                     message.append("Expected output out: ");
   14957                     message.append(args.out.toString());
   14958                     message.append("\n");
   14959                     message.append("Actual   output out: ");
   14960                     message.append(String.format("%24.8g {%16x} %31a",
   14961                             arrayOut[i * 2 + j], Double.doubleToRawLongBits(arrayOut[i * 2 + j]), arrayOut[i * 2 + j]));
   14962                     if (!args.out.couldBe(arrayOut[i * 2 + j])) {
   14963                         message.append(" FAIL");
   14964                     }
   14965                     message.append("\n");
   14966                     assertTrue("Incorrect output for checkConvertUint2Double2" +
   14967                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   14968                 }
   14969             }
   14970         }
   14971     }
   14972 
   14973     private void checkConvertUint3Double3() {
   14974         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_32, 3, 0x40ff0b46964373cdl, false, 32);
   14975         try {
   14976             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 3), INPUTSIZE);
   14977             script.forEach_testConvertDouble3Uint3Double3(inV, out);
   14978             verifyResultsConvertUint3Double3(inV, out, false);
   14979         } catch (Exception e) {
   14980             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble3Uint3Double3: " + e.toString());
   14981         }
   14982         try {
   14983             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 3), INPUTSIZE);
   14984             scriptRelaxed.forEach_testConvertDouble3Uint3Double3(inV, out);
   14985             verifyResultsConvertUint3Double3(inV, out, true);
   14986         } catch (Exception e) {
   14987             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble3Uint3Double3: " + e.toString());
   14988         }
   14989     }
   14990 
   14991     private void verifyResultsConvertUint3Double3(Allocation inV, Allocation out, boolean relaxed) {
   14992         int[] arrayInV = new int[INPUTSIZE * 4];
   14993         inV.copyTo(arrayInV);
   14994         double[] arrayOut = new double[INPUTSIZE * 4];
   14995         out.copyTo(arrayOut);
   14996         for (int i = 0; i < INPUTSIZE; i++) {
   14997             for (int j = 0; j < 3 ; j++) {
   14998                 // Extract the inputs.
   14999                 ArgumentsUintDouble args = new ArgumentsUintDouble();
   15000                 args.inV = arrayInV[i * 4 + j];
   15001                 // Figure out what the outputs should have been.
   15002                 Target target = new Target(relaxed);
   15003                 CoreMathVerifier.computeConvert(args, target);
   15004                 // Validate the outputs.
   15005                 boolean valid = true;
   15006                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   15007                     valid = false;
   15008                 }
   15009                 if (!valid) {
   15010                     StringBuilder message = new StringBuilder();
   15011                     message.append("Input inV: ");
   15012                     message.append(String.format("0x%x", args.inV));
   15013                     message.append("\n");
   15014                     message.append("Expected output out: ");
   15015                     message.append(args.out.toString());
   15016                     message.append("\n");
   15017                     message.append("Actual   output out: ");
   15018                     message.append(String.format("%24.8g {%16x} %31a",
   15019                             arrayOut[i * 4 + j], Double.doubleToRawLongBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
   15020                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   15021                         message.append(" FAIL");
   15022                     }
   15023                     message.append("\n");
   15024                     assertTrue("Incorrect output for checkConvertUint3Double3" +
   15025                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   15026                 }
   15027             }
   15028         }
   15029     }
   15030 
   15031     private void checkConvertUint4Double4() {
   15032         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_32, 4, 0x414bd2cdec9f04f9l, false, 32);
   15033         try {
   15034             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 4), INPUTSIZE);
   15035             script.forEach_testConvertDouble4Uint4Double4(inV, out);
   15036             verifyResultsConvertUint4Double4(inV, out, false);
   15037         } catch (Exception e) {
   15038             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble4Uint4Double4: " + e.toString());
   15039         }
   15040         try {
   15041             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.FLOAT_64, 4), INPUTSIZE);
   15042             scriptRelaxed.forEach_testConvertDouble4Uint4Double4(inV, out);
   15043             verifyResultsConvertUint4Double4(inV, out, true);
   15044         } catch (Exception e) {
   15045             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertDouble4Uint4Double4: " + e.toString());
   15046         }
   15047     }
   15048 
   15049     private void verifyResultsConvertUint4Double4(Allocation inV, Allocation out, boolean relaxed) {
   15050         int[] arrayInV = new int[INPUTSIZE * 4];
   15051         inV.copyTo(arrayInV);
   15052         double[] arrayOut = new double[INPUTSIZE * 4];
   15053         out.copyTo(arrayOut);
   15054         for (int i = 0; i < INPUTSIZE; i++) {
   15055             for (int j = 0; j < 4 ; j++) {
   15056                 // Extract the inputs.
   15057                 ArgumentsUintDouble args = new ArgumentsUintDouble();
   15058                 args.inV = arrayInV[i * 4 + j];
   15059                 // Figure out what the outputs should have been.
   15060                 Target target = new Target(relaxed);
   15061                 CoreMathVerifier.computeConvert(args, target);
   15062                 // Validate the outputs.
   15063                 boolean valid = true;
   15064                 if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   15065                     valid = false;
   15066                 }
   15067                 if (!valid) {
   15068                     StringBuilder message = new StringBuilder();
   15069                     message.append("Input inV: ");
   15070                     message.append(String.format("0x%x", args.inV));
   15071                     message.append("\n");
   15072                     message.append("Expected output out: ");
   15073                     message.append(args.out.toString());
   15074                     message.append("\n");
   15075                     message.append("Actual   output out: ");
   15076                     message.append(String.format("%24.8g {%16x} %31a",
   15077                             arrayOut[i * 4 + j], Double.doubleToRawLongBits(arrayOut[i * 4 + j]), arrayOut[i * 4 + j]));
   15078                     if (!args.out.couldBe(arrayOut[i * 4 + j])) {
   15079                         message.append(" FAIL");
   15080                     }
   15081                     message.append("\n");
   15082                     assertTrue("Incorrect output for checkConvertUint4Double4" +
   15083                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   15084                 }
   15085             }
   15086         }
   15087     }
   15088 
   15089     public class ArgumentsFloatLong {
   15090         public float inV;
   15091         public long out;
   15092     }
   15093 
   15094     private void checkConvertFloat2Long2() {
   15095         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 2, 0x239cb49c7d7c0ae0l, -9.2233714870989619200e+18, 9.2233714870989619200e+18);
   15096         try {
   15097             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 2), INPUTSIZE);
   15098             script.forEach_testConvertLong2Float2Long2(inV, out);
   15099             verifyResultsConvertFloat2Long2(inV, out, false);
   15100         } catch (Exception e) {
   15101             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong2Float2Long2: " + e.toString());
   15102         }
   15103         try {
   15104             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 2), INPUTSIZE);
   15105             scriptRelaxed.forEach_testConvertLong2Float2Long2(inV, out);
   15106             verifyResultsConvertFloat2Long2(inV, out, true);
   15107         } catch (Exception e) {
   15108             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong2Float2Long2: " + e.toString());
   15109         }
   15110     }
   15111 
   15112     private void verifyResultsConvertFloat2Long2(Allocation inV, Allocation out, boolean relaxed) {
   15113         float[] arrayInV = new float[INPUTSIZE * 2];
   15114         inV.copyTo(arrayInV);
   15115         long[] arrayOut = new long[INPUTSIZE * 2];
   15116         out.copyTo(arrayOut);
   15117         for (int i = 0; i < INPUTSIZE; i++) {
   15118             for (int j = 0; j < 2 ; j++) {
   15119                 // Extract the inputs.
   15120                 ArgumentsFloatLong args = new ArgumentsFloatLong();
   15121                 args.inV = arrayInV[i * 2 + j];
   15122                 // Figure out what the outputs should have been.
   15123                 CoreMathVerifier.computeConvert(args);
   15124                 // Validate the outputs.
   15125                 boolean valid = true;
   15126                 if (args.out != arrayOut[i * 2 + j]) {
   15127                     valid = false;
   15128                 }
   15129                 if (!valid) {
   15130                     StringBuilder message = new StringBuilder();
   15131                     message.append("Input inV: ");
   15132                     message.append(String.format("%14.8g {%8x} %15a",
   15133                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
   15134                     message.append("\n");
   15135                     message.append("Expected output out: ");
   15136                     message.append(String.format("%d", args.out));
   15137                     message.append("\n");
   15138                     message.append("Actual   output out: ");
   15139                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   15140                     if (args.out != arrayOut[i * 2 + j]) {
   15141                         message.append(" FAIL");
   15142                     }
   15143                     message.append("\n");
   15144                     assertTrue("Incorrect output for checkConvertFloat2Long2" +
   15145                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   15146                 }
   15147             }
   15148         }
   15149     }
   15150 
   15151     private void checkConvertFloat3Long3() {
   15152         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 3, 0x239cbf3ddc83cfd4l, -9.2233714870989619200e+18, 9.2233714870989619200e+18);
   15153         try {
   15154             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 3), INPUTSIZE);
   15155             script.forEach_testConvertLong3Float3Long3(inV, out);
   15156             verifyResultsConvertFloat3Long3(inV, out, false);
   15157         } catch (Exception e) {
   15158             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong3Float3Long3: " + e.toString());
   15159         }
   15160         try {
   15161             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 3), INPUTSIZE);
   15162             scriptRelaxed.forEach_testConvertLong3Float3Long3(inV, out);
   15163             verifyResultsConvertFloat3Long3(inV, out, true);
   15164         } catch (Exception e) {
   15165             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong3Float3Long3: " + e.toString());
   15166         }
   15167     }
   15168 
   15169     private void verifyResultsConvertFloat3Long3(Allocation inV, Allocation out, boolean relaxed) {
   15170         float[] arrayInV = new float[INPUTSIZE * 4];
   15171         inV.copyTo(arrayInV);
   15172         long[] arrayOut = new long[INPUTSIZE * 4];
   15173         out.copyTo(arrayOut);
   15174         for (int i = 0; i < INPUTSIZE; i++) {
   15175             for (int j = 0; j < 3 ; j++) {
   15176                 // Extract the inputs.
   15177                 ArgumentsFloatLong args = new ArgumentsFloatLong();
   15178                 args.inV = arrayInV[i * 4 + j];
   15179                 // Figure out what the outputs should have been.
   15180                 CoreMathVerifier.computeConvert(args);
   15181                 // Validate the outputs.
   15182                 boolean valid = true;
   15183                 if (args.out != arrayOut[i * 4 + j]) {
   15184                     valid = false;
   15185                 }
   15186                 if (!valid) {
   15187                     StringBuilder message = new StringBuilder();
   15188                     message.append("Input inV: ");
   15189                     message.append(String.format("%14.8g {%8x} %15a",
   15190                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
   15191                     message.append("\n");
   15192                     message.append("Expected output out: ");
   15193                     message.append(String.format("%d", args.out));
   15194                     message.append("\n");
   15195                     message.append("Actual   output out: ");
   15196                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   15197                     if (args.out != arrayOut[i * 4 + j]) {
   15198                         message.append(" FAIL");
   15199                     }
   15200                     message.append("\n");
   15201                     assertTrue("Incorrect output for checkConvertFloat3Long3" +
   15202                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   15203                 }
   15204             }
   15205         }
   15206     }
   15207 
   15208     private void checkConvertFloat4Long4() {
   15209         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 4, 0x239cc9df3b8b94c8l, -9.2233714870989619200e+18, 9.2233714870989619200e+18);
   15210         try {
   15211             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 4), INPUTSIZE);
   15212             script.forEach_testConvertLong4Float4Long4(inV, out);
   15213             verifyResultsConvertFloat4Long4(inV, out, false);
   15214         } catch (Exception e) {
   15215             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong4Float4Long4: " + e.toString());
   15216         }
   15217         try {
   15218             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 4), INPUTSIZE);
   15219             scriptRelaxed.forEach_testConvertLong4Float4Long4(inV, out);
   15220             verifyResultsConvertFloat4Long4(inV, out, true);
   15221         } catch (Exception e) {
   15222             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong4Float4Long4: " + e.toString());
   15223         }
   15224     }
   15225 
   15226     private void verifyResultsConvertFloat4Long4(Allocation inV, Allocation out, boolean relaxed) {
   15227         float[] arrayInV = new float[INPUTSIZE * 4];
   15228         inV.copyTo(arrayInV);
   15229         long[] arrayOut = new long[INPUTSIZE * 4];
   15230         out.copyTo(arrayOut);
   15231         for (int i = 0; i < INPUTSIZE; i++) {
   15232             for (int j = 0; j < 4 ; j++) {
   15233                 // Extract the inputs.
   15234                 ArgumentsFloatLong args = new ArgumentsFloatLong();
   15235                 args.inV = arrayInV[i * 4 + j];
   15236                 // Figure out what the outputs should have been.
   15237                 CoreMathVerifier.computeConvert(args);
   15238                 // Validate the outputs.
   15239                 boolean valid = true;
   15240                 if (args.out != arrayOut[i * 4 + j]) {
   15241                     valid = false;
   15242                 }
   15243                 if (!valid) {
   15244                     StringBuilder message = new StringBuilder();
   15245                     message.append("Input inV: ");
   15246                     message.append(String.format("%14.8g {%8x} %15a",
   15247                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
   15248                     message.append("\n");
   15249                     message.append("Expected output out: ");
   15250                     message.append(String.format("%d", args.out));
   15251                     message.append("\n");
   15252                     message.append("Actual   output out: ");
   15253                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   15254                     if (args.out != arrayOut[i * 4 + j]) {
   15255                         message.append(" FAIL");
   15256                     }
   15257                     message.append("\n");
   15258                     assertTrue("Incorrect output for checkConvertFloat4Long4" +
   15259                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   15260                 }
   15261             }
   15262         }
   15263     }
   15264 
   15265     public class ArgumentsCharLong {
   15266         public byte inV;
   15267         public long out;
   15268     }
   15269 
   15270     private void checkConvertChar2Long2() {
   15271         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_8, 2, 0xd86189bc290be220l, true, 7);
   15272         try {
   15273             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 2), INPUTSIZE);
   15274             script.forEach_testConvertLong2Char2Long2(inV, out);
   15275             verifyResultsConvertChar2Long2(inV, out, false);
   15276         } catch (Exception e) {
   15277             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong2Char2Long2: " + e.toString());
   15278         }
   15279         try {
   15280             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 2), INPUTSIZE);
   15281             scriptRelaxed.forEach_testConvertLong2Char2Long2(inV, out);
   15282             verifyResultsConvertChar2Long2(inV, out, true);
   15283         } catch (Exception e) {
   15284             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong2Char2Long2: " + e.toString());
   15285         }
   15286     }
   15287 
   15288     private void verifyResultsConvertChar2Long2(Allocation inV, Allocation out, boolean relaxed) {
   15289         byte[] arrayInV = new byte[INPUTSIZE * 2];
   15290         inV.copyTo(arrayInV);
   15291         long[] arrayOut = new long[INPUTSIZE * 2];
   15292         out.copyTo(arrayOut);
   15293         for (int i = 0; i < INPUTSIZE; i++) {
   15294             for (int j = 0; j < 2 ; j++) {
   15295                 // Extract the inputs.
   15296                 ArgumentsCharLong args = new ArgumentsCharLong();
   15297                 args.inV = arrayInV[i * 2 + j];
   15298                 // Figure out what the outputs should have been.
   15299                 CoreMathVerifier.computeConvert(args);
   15300                 // Validate the outputs.
   15301                 boolean valid = true;
   15302                 if (args.out != arrayOut[i * 2 + j]) {
   15303                     valid = false;
   15304                 }
   15305                 if (!valid) {
   15306                     StringBuilder message = new StringBuilder();
   15307                     message.append("Input inV: ");
   15308                     message.append(String.format("%d", args.inV));
   15309                     message.append("\n");
   15310                     message.append("Expected output out: ");
   15311                     message.append(String.format("%d", args.out));
   15312                     message.append("\n");
   15313                     message.append("Actual   output out: ");
   15314                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   15315                     if (args.out != arrayOut[i * 2 + j]) {
   15316                         message.append(" FAIL");
   15317                     }
   15318                     message.append("\n");
   15319                     assertTrue("Incorrect output for checkConvertChar2Long2" +
   15320                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   15321                 }
   15322             }
   15323         }
   15324     }
   15325 
   15326     private void checkConvertChar3Long3() {
   15327         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_8, 3, 0xd861945d8813a714l, true, 7);
   15328         try {
   15329             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 3), INPUTSIZE);
   15330             script.forEach_testConvertLong3Char3Long3(inV, out);
   15331             verifyResultsConvertChar3Long3(inV, out, false);
   15332         } catch (Exception e) {
   15333             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong3Char3Long3: " + e.toString());
   15334         }
   15335         try {
   15336             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 3), INPUTSIZE);
   15337             scriptRelaxed.forEach_testConvertLong3Char3Long3(inV, out);
   15338             verifyResultsConvertChar3Long3(inV, out, true);
   15339         } catch (Exception e) {
   15340             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong3Char3Long3: " + e.toString());
   15341         }
   15342     }
   15343 
   15344     private void verifyResultsConvertChar3Long3(Allocation inV, Allocation out, boolean relaxed) {
   15345         byte[] arrayInV = new byte[INPUTSIZE * 4];
   15346         inV.copyTo(arrayInV);
   15347         long[] arrayOut = new long[INPUTSIZE * 4];
   15348         out.copyTo(arrayOut);
   15349         for (int i = 0; i < INPUTSIZE; i++) {
   15350             for (int j = 0; j < 3 ; j++) {
   15351                 // Extract the inputs.
   15352                 ArgumentsCharLong args = new ArgumentsCharLong();
   15353                 args.inV = arrayInV[i * 4 + j];
   15354                 // Figure out what the outputs should have been.
   15355                 CoreMathVerifier.computeConvert(args);
   15356                 // Validate the outputs.
   15357                 boolean valid = true;
   15358                 if (args.out != arrayOut[i * 4 + j]) {
   15359                     valid = false;
   15360                 }
   15361                 if (!valid) {
   15362                     StringBuilder message = new StringBuilder();
   15363                     message.append("Input inV: ");
   15364                     message.append(String.format("%d", args.inV));
   15365                     message.append("\n");
   15366                     message.append("Expected output out: ");
   15367                     message.append(String.format("%d", args.out));
   15368                     message.append("\n");
   15369                     message.append("Actual   output out: ");
   15370                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   15371                     if (args.out != arrayOut[i * 4 + j]) {
   15372                         message.append(" FAIL");
   15373                     }
   15374                     message.append("\n");
   15375                     assertTrue("Incorrect output for checkConvertChar3Long3" +
   15376                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   15377                 }
   15378             }
   15379         }
   15380     }
   15381 
   15382     private void checkConvertChar4Long4() {
   15383         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_8, 4, 0xd8619efee71b6c08l, true, 7);
   15384         try {
   15385             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 4), INPUTSIZE);
   15386             script.forEach_testConvertLong4Char4Long4(inV, out);
   15387             verifyResultsConvertChar4Long4(inV, out, false);
   15388         } catch (Exception e) {
   15389             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong4Char4Long4: " + e.toString());
   15390         }
   15391         try {
   15392             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 4), INPUTSIZE);
   15393             scriptRelaxed.forEach_testConvertLong4Char4Long4(inV, out);
   15394             verifyResultsConvertChar4Long4(inV, out, true);
   15395         } catch (Exception e) {
   15396             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong4Char4Long4: " + e.toString());
   15397         }
   15398     }
   15399 
   15400     private void verifyResultsConvertChar4Long4(Allocation inV, Allocation out, boolean relaxed) {
   15401         byte[] arrayInV = new byte[INPUTSIZE * 4];
   15402         inV.copyTo(arrayInV);
   15403         long[] arrayOut = new long[INPUTSIZE * 4];
   15404         out.copyTo(arrayOut);
   15405         for (int i = 0; i < INPUTSIZE; i++) {
   15406             for (int j = 0; j < 4 ; j++) {
   15407                 // Extract the inputs.
   15408                 ArgumentsCharLong args = new ArgumentsCharLong();
   15409                 args.inV = arrayInV[i * 4 + j];
   15410                 // Figure out what the outputs should have been.
   15411                 CoreMathVerifier.computeConvert(args);
   15412                 // Validate the outputs.
   15413                 boolean valid = true;
   15414                 if (args.out != arrayOut[i * 4 + j]) {
   15415                     valid = false;
   15416                 }
   15417                 if (!valid) {
   15418                     StringBuilder message = new StringBuilder();
   15419                     message.append("Input inV: ");
   15420                     message.append(String.format("%d", args.inV));
   15421                     message.append("\n");
   15422                     message.append("Expected output out: ");
   15423                     message.append(String.format("%d", args.out));
   15424                     message.append("\n");
   15425                     message.append("Actual   output out: ");
   15426                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   15427                     if (args.out != arrayOut[i * 4 + j]) {
   15428                         message.append(" FAIL");
   15429                     }
   15430                     message.append("\n");
   15431                     assertTrue("Incorrect output for checkConvertChar4Long4" +
   15432                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   15433                 }
   15434             }
   15435         }
   15436     }
   15437 
   15438     public class ArgumentsUcharLong {
   15439         public byte inV;
   15440         public long out;
   15441     }
   15442 
   15443     private void checkConvertUchar2Long2() {
   15444         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_8, 2, 0x7fef4309bb8deea1l, false, 8);
   15445         try {
   15446             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 2), INPUTSIZE);
   15447             script.forEach_testConvertLong2Uchar2Long2(inV, out);
   15448             verifyResultsConvertUchar2Long2(inV, out, false);
   15449         } catch (Exception e) {
   15450             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong2Uchar2Long2: " + e.toString());
   15451         }
   15452         try {
   15453             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 2), INPUTSIZE);
   15454             scriptRelaxed.forEach_testConvertLong2Uchar2Long2(inV, out);
   15455             verifyResultsConvertUchar2Long2(inV, out, true);
   15456         } catch (Exception e) {
   15457             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong2Uchar2Long2: " + e.toString());
   15458         }
   15459     }
   15460 
   15461     private void verifyResultsConvertUchar2Long2(Allocation inV, Allocation out, boolean relaxed) {
   15462         byte[] arrayInV = new byte[INPUTSIZE * 2];
   15463         inV.copyTo(arrayInV);
   15464         long[] arrayOut = new long[INPUTSIZE * 2];
   15465         out.copyTo(arrayOut);
   15466         for (int i = 0; i < INPUTSIZE; i++) {
   15467             for (int j = 0; j < 2 ; j++) {
   15468                 // Extract the inputs.
   15469                 ArgumentsUcharLong args = new ArgumentsUcharLong();
   15470                 args.inV = arrayInV[i * 2 + j];
   15471                 // Figure out what the outputs should have been.
   15472                 CoreMathVerifier.computeConvert(args);
   15473                 // Validate the outputs.
   15474                 boolean valid = true;
   15475                 if (args.out != arrayOut[i * 2 + j]) {
   15476                     valid = false;
   15477                 }
   15478                 if (!valid) {
   15479                     StringBuilder message = new StringBuilder();
   15480                     message.append("Input inV: ");
   15481                     message.append(String.format("0x%x", args.inV));
   15482                     message.append("\n");
   15483                     message.append("Expected output out: ");
   15484                     message.append(String.format("%d", args.out));
   15485                     message.append("\n");
   15486                     message.append("Actual   output out: ");
   15487                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   15488                     if (args.out != arrayOut[i * 2 + j]) {
   15489                         message.append(" FAIL");
   15490                     }
   15491                     message.append("\n");
   15492                     assertTrue("Incorrect output for checkConvertUchar2Long2" +
   15493                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   15494                 }
   15495             }
   15496         }
   15497     }
   15498 
   15499     private void checkConvertUchar3Long3() {
   15500         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_8, 3, 0x7fef4dab1a95b395l, false, 8);
   15501         try {
   15502             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 3), INPUTSIZE);
   15503             script.forEach_testConvertLong3Uchar3Long3(inV, out);
   15504             verifyResultsConvertUchar3Long3(inV, out, false);
   15505         } catch (Exception e) {
   15506             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong3Uchar3Long3: " + e.toString());
   15507         }
   15508         try {
   15509             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 3), INPUTSIZE);
   15510             scriptRelaxed.forEach_testConvertLong3Uchar3Long3(inV, out);
   15511             verifyResultsConvertUchar3Long3(inV, out, true);
   15512         } catch (Exception e) {
   15513             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong3Uchar3Long3: " + e.toString());
   15514         }
   15515     }
   15516 
   15517     private void verifyResultsConvertUchar3Long3(Allocation inV, Allocation out, boolean relaxed) {
   15518         byte[] arrayInV = new byte[INPUTSIZE * 4];
   15519         inV.copyTo(arrayInV);
   15520         long[] arrayOut = new long[INPUTSIZE * 4];
   15521         out.copyTo(arrayOut);
   15522         for (int i = 0; i < INPUTSIZE; i++) {
   15523             for (int j = 0; j < 3 ; j++) {
   15524                 // Extract the inputs.
   15525                 ArgumentsUcharLong args = new ArgumentsUcharLong();
   15526                 args.inV = arrayInV[i * 4 + j];
   15527                 // Figure out what the outputs should have been.
   15528                 CoreMathVerifier.computeConvert(args);
   15529                 // Validate the outputs.
   15530                 boolean valid = true;
   15531                 if (args.out != arrayOut[i * 4 + j]) {
   15532                     valid = false;
   15533                 }
   15534                 if (!valid) {
   15535                     StringBuilder message = new StringBuilder();
   15536                     message.append("Input inV: ");
   15537                     message.append(String.format("0x%x", args.inV));
   15538                     message.append("\n");
   15539                     message.append("Expected output out: ");
   15540                     message.append(String.format("%d", args.out));
   15541                     message.append("\n");
   15542                     message.append("Actual   output out: ");
   15543                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   15544                     if (args.out != arrayOut[i * 4 + j]) {
   15545                         message.append(" FAIL");
   15546                     }
   15547                     message.append("\n");
   15548                     assertTrue("Incorrect output for checkConvertUchar3Long3" +
   15549                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   15550                 }
   15551             }
   15552         }
   15553     }
   15554 
   15555     private void checkConvertUchar4Long4() {
   15556         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_8, 4, 0x7fef584c799d7889l, false, 8);
   15557         try {
   15558             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 4), INPUTSIZE);
   15559             script.forEach_testConvertLong4Uchar4Long4(inV, out);
   15560             verifyResultsConvertUchar4Long4(inV, out, false);
   15561         } catch (Exception e) {
   15562             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong4Uchar4Long4: " + e.toString());
   15563         }
   15564         try {
   15565             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 4), INPUTSIZE);
   15566             scriptRelaxed.forEach_testConvertLong4Uchar4Long4(inV, out);
   15567             verifyResultsConvertUchar4Long4(inV, out, true);
   15568         } catch (Exception e) {
   15569             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong4Uchar4Long4: " + e.toString());
   15570         }
   15571     }
   15572 
   15573     private void verifyResultsConvertUchar4Long4(Allocation inV, Allocation out, boolean relaxed) {
   15574         byte[] arrayInV = new byte[INPUTSIZE * 4];
   15575         inV.copyTo(arrayInV);
   15576         long[] arrayOut = new long[INPUTSIZE * 4];
   15577         out.copyTo(arrayOut);
   15578         for (int i = 0; i < INPUTSIZE; i++) {
   15579             for (int j = 0; j < 4 ; j++) {
   15580                 // Extract the inputs.
   15581                 ArgumentsUcharLong args = new ArgumentsUcharLong();
   15582                 args.inV = arrayInV[i * 4 + j];
   15583                 // Figure out what the outputs should have been.
   15584                 CoreMathVerifier.computeConvert(args);
   15585                 // Validate the outputs.
   15586                 boolean valid = true;
   15587                 if (args.out != arrayOut[i * 4 + j]) {
   15588                     valid = false;
   15589                 }
   15590                 if (!valid) {
   15591                     StringBuilder message = new StringBuilder();
   15592                     message.append("Input inV: ");
   15593                     message.append(String.format("0x%x", args.inV));
   15594                     message.append("\n");
   15595                     message.append("Expected output out: ");
   15596                     message.append(String.format("%d", args.out));
   15597                     message.append("\n");
   15598                     message.append("Actual   output out: ");
   15599                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   15600                     if (args.out != arrayOut[i * 4 + j]) {
   15601                         message.append(" FAIL");
   15602                     }
   15603                     message.append("\n");
   15604                     assertTrue("Incorrect output for checkConvertUchar4Long4" +
   15605                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   15606                 }
   15607             }
   15608         }
   15609     }
   15610 
   15611     public class ArgumentsShortLong {
   15612         public short inV;
   15613         public long out;
   15614     }
   15615 
   15616     private void checkConvertShort2Long2() {
   15617         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_16, 2, 0x68ab674669c97ce4l, true, 15);
   15618         try {
   15619             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 2), INPUTSIZE);
   15620             script.forEach_testConvertLong2Short2Long2(inV, out);
   15621             verifyResultsConvertShort2Long2(inV, out, false);
   15622         } catch (Exception e) {
   15623             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong2Short2Long2: " + e.toString());
   15624         }
   15625         try {
   15626             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 2), INPUTSIZE);
   15627             scriptRelaxed.forEach_testConvertLong2Short2Long2(inV, out);
   15628             verifyResultsConvertShort2Long2(inV, out, true);
   15629         } catch (Exception e) {
   15630             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong2Short2Long2: " + e.toString());
   15631         }
   15632     }
   15633 
   15634     private void verifyResultsConvertShort2Long2(Allocation inV, Allocation out, boolean relaxed) {
   15635         short[] arrayInV = new short[INPUTSIZE * 2];
   15636         inV.copyTo(arrayInV);
   15637         long[] arrayOut = new long[INPUTSIZE * 2];
   15638         out.copyTo(arrayOut);
   15639         for (int i = 0; i < INPUTSIZE; i++) {
   15640             for (int j = 0; j < 2 ; j++) {
   15641                 // Extract the inputs.
   15642                 ArgumentsShortLong args = new ArgumentsShortLong();
   15643                 args.inV = arrayInV[i * 2 + j];
   15644                 // Figure out what the outputs should have been.
   15645                 CoreMathVerifier.computeConvert(args);
   15646                 // Validate the outputs.
   15647                 boolean valid = true;
   15648                 if (args.out != arrayOut[i * 2 + j]) {
   15649                     valid = false;
   15650                 }
   15651                 if (!valid) {
   15652                     StringBuilder message = new StringBuilder();
   15653                     message.append("Input inV: ");
   15654                     message.append(String.format("%d", args.inV));
   15655                     message.append("\n");
   15656                     message.append("Expected output out: ");
   15657                     message.append(String.format("%d", args.out));
   15658                     message.append("\n");
   15659                     message.append("Actual   output out: ");
   15660                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   15661                     if (args.out != arrayOut[i * 2 + j]) {
   15662                         message.append(" FAIL");
   15663                     }
   15664                     message.append("\n");
   15665                     assertTrue("Incorrect output for checkConvertShort2Long2" +
   15666                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   15667                 }
   15668             }
   15669         }
   15670     }
   15671 
   15672     private void checkConvertShort3Long3() {
   15673         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_16, 3, 0x68ab71e7c8d141d8l, true, 15);
   15674         try {
   15675             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 3), INPUTSIZE);
   15676             script.forEach_testConvertLong3Short3Long3(inV, out);
   15677             verifyResultsConvertShort3Long3(inV, out, false);
   15678         } catch (Exception e) {
   15679             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong3Short3Long3: " + e.toString());
   15680         }
   15681         try {
   15682             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 3), INPUTSIZE);
   15683             scriptRelaxed.forEach_testConvertLong3Short3Long3(inV, out);
   15684             verifyResultsConvertShort3Long3(inV, out, true);
   15685         } catch (Exception e) {
   15686             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong3Short3Long3: " + e.toString());
   15687         }
   15688     }
   15689 
   15690     private void verifyResultsConvertShort3Long3(Allocation inV, Allocation out, boolean relaxed) {
   15691         short[] arrayInV = new short[INPUTSIZE * 4];
   15692         inV.copyTo(arrayInV);
   15693         long[] arrayOut = new long[INPUTSIZE * 4];
   15694         out.copyTo(arrayOut);
   15695         for (int i = 0; i < INPUTSIZE; i++) {
   15696             for (int j = 0; j < 3 ; j++) {
   15697                 // Extract the inputs.
   15698                 ArgumentsShortLong args = new ArgumentsShortLong();
   15699                 args.inV = arrayInV[i * 4 + j];
   15700                 // Figure out what the outputs should have been.
   15701                 CoreMathVerifier.computeConvert(args);
   15702                 // Validate the outputs.
   15703                 boolean valid = true;
   15704                 if (args.out != arrayOut[i * 4 + j]) {
   15705                     valid = false;
   15706                 }
   15707                 if (!valid) {
   15708                     StringBuilder message = new StringBuilder();
   15709                     message.append("Input inV: ");
   15710                     message.append(String.format("%d", args.inV));
   15711                     message.append("\n");
   15712                     message.append("Expected output out: ");
   15713                     message.append(String.format("%d", args.out));
   15714                     message.append("\n");
   15715                     message.append("Actual   output out: ");
   15716                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   15717                     if (args.out != arrayOut[i * 4 + j]) {
   15718                         message.append(" FAIL");
   15719                     }
   15720                     message.append("\n");
   15721                     assertTrue("Incorrect output for checkConvertShort3Long3" +
   15722                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   15723                 }
   15724             }
   15725         }
   15726     }
   15727 
   15728     private void checkConvertShort4Long4() {
   15729         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_16, 4, 0x68ab7c8927d906ccl, true, 15);
   15730         try {
   15731             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 4), INPUTSIZE);
   15732             script.forEach_testConvertLong4Short4Long4(inV, out);
   15733             verifyResultsConvertShort4Long4(inV, out, false);
   15734         } catch (Exception e) {
   15735             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong4Short4Long4: " + e.toString());
   15736         }
   15737         try {
   15738             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 4), INPUTSIZE);
   15739             scriptRelaxed.forEach_testConvertLong4Short4Long4(inV, out);
   15740             verifyResultsConvertShort4Long4(inV, out, true);
   15741         } catch (Exception e) {
   15742             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong4Short4Long4: " + e.toString());
   15743         }
   15744     }
   15745 
   15746     private void verifyResultsConvertShort4Long4(Allocation inV, Allocation out, boolean relaxed) {
   15747         short[] arrayInV = new short[INPUTSIZE * 4];
   15748         inV.copyTo(arrayInV);
   15749         long[] arrayOut = new long[INPUTSIZE * 4];
   15750         out.copyTo(arrayOut);
   15751         for (int i = 0; i < INPUTSIZE; i++) {
   15752             for (int j = 0; j < 4 ; j++) {
   15753                 // Extract the inputs.
   15754                 ArgumentsShortLong args = new ArgumentsShortLong();
   15755                 args.inV = arrayInV[i * 4 + j];
   15756                 // Figure out what the outputs should have been.
   15757                 CoreMathVerifier.computeConvert(args);
   15758                 // Validate the outputs.
   15759                 boolean valid = true;
   15760                 if (args.out != arrayOut[i * 4 + j]) {
   15761                     valid = false;
   15762                 }
   15763                 if (!valid) {
   15764                     StringBuilder message = new StringBuilder();
   15765                     message.append("Input inV: ");
   15766                     message.append(String.format("%d", args.inV));
   15767                     message.append("\n");
   15768                     message.append("Expected output out: ");
   15769                     message.append(String.format("%d", args.out));
   15770                     message.append("\n");
   15771                     message.append("Actual   output out: ");
   15772                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   15773                     if (args.out != arrayOut[i * 4 + j]) {
   15774                         message.append(" FAIL");
   15775                     }
   15776                     message.append("\n");
   15777                     assertTrue("Incorrect output for checkConvertShort4Long4" +
   15778                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   15779                 }
   15780             }
   15781         }
   15782     }
   15783 
   15784     public class ArgumentsUshortLong {
   15785         public short inV;
   15786         public long out;
   15787     }
   15788 
   15789     private void checkConvertUshort2Long2() {
   15790         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_16, 2, 0x8d79874e05a1968fl, false, 16);
   15791         try {
   15792             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 2), INPUTSIZE);
   15793             script.forEach_testConvertLong2Ushort2Long2(inV, out);
   15794             verifyResultsConvertUshort2Long2(inV, out, false);
   15795         } catch (Exception e) {
   15796             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong2Ushort2Long2: " + e.toString());
   15797         }
   15798         try {
   15799             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 2), INPUTSIZE);
   15800             scriptRelaxed.forEach_testConvertLong2Ushort2Long2(inV, out);
   15801             verifyResultsConvertUshort2Long2(inV, out, true);
   15802         } catch (Exception e) {
   15803             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong2Ushort2Long2: " + e.toString());
   15804         }
   15805     }
   15806 
   15807     private void verifyResultsConvertUshort2Long2(Allocation inV, Allocation out, boolean relaxed) {
   15808         short[] arrayInV = new short[INPUTSIZE * 2];
   15809         inV.copyTo(arrayInV);
   15810         long[] arrayOut = new long[INPUTSIZE * 2];
   15811         out.copyTo(arrayOut);
   15812         for (int i = 0; i < INPUTSIZE; i++) {
   15813             for (int j = 0; j < 2 ; j++) {
   15814                 // Extract the inputs.
   15815                 ArgumentsUshortLong args = new ArgumentsUshortLong();
   15816                 args.inV = arrayInV[i * 2 + j];
   15817                 // Figure out what the outputs should have been.
   15818                 CoreMathVerifier.computeConvert(args);
   15819                 // Validate the outputs.
   15820                 boolean valid = true;
   15821                 if (args.out != arrayOut[i * 2 + j]) {
   15822                     valid = false;
   15823                 }
   15824                 if (!valid) {
   15825                     StringBuilder message = new StringBuilder();
   15826                     message.append("Input inV: ");
   15827                     message.append(String.format("0x%x", args.inV));
   15828                     message.append("\n");
   15829                     message.append("Expected output out: ");
   15830                     message.append(String.format("%d", args.out));
   15831                     message.append("\n");
   15832                     message.append("Actual   output out: ");
   15833                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   15834                     if (args.out != arrayOut[i * 2 + j]) {
   15835                         message.append(" FAIL");
   15836                     }
   15837                     message.append("\n");
   15838                     assertTrue("Incorrect output for checkConvertUshort2Long2" +
   15839                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   15840                 }
   15841             }
   15842         }
   15843     }
   15844 
   15845     private void checkConvertUshort3Long3() {
   15846         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_16, 3, 0x8d7991ef64a95b83l, false, 16);
   15847         try {
   15848             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 3), INPUTSIZE);
   15849             script.forEach_testConvertLong3Ushort3Long3(inV, out);
   15850             verifyResultsConvertUshort3Long3(inV, out, false);
   15851         } catch (Exception e) {
   15852             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong3Ushort3Long3: " + e.toString());
   15853         }
   15854         try {
   15855             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 3), INPUTSIZE);
   15856             scriptRelaxed.forEach_testConvertLong3Ushort3Long3(inV, out);
   15857             verifyResultsConvertUshort3Long3(inV, out, true);
   15858         } catch (Exception e) {
   15859             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong3Ushort3Long3: " + e.toString());
   15860         }
   15861     }
   15862 
   15863     private void verifyResultsConvertUshort3Long3(Allocation inV, Allocation out, boolean relaxed) {
   15864         short[] arrayInV = new short[INPUTSIZE * 4];
   15865         inV.copyTo(arrayInV);
   15866         long[] arrayOut = new long[INPUTSIZE * 4];
   15867         out.copyTo(arrayOut);
   15868         for (int i = 0; i < INPUTSIZE; i++) {
   15869             for (int j = 0; j < 3 ; j++) {
   15870                 // Extract the inputs.
   15871                 ArgumentsUshortLong args = new ArgumentsUshortLong();
   15872                 args.inV = arrayInV[i * 4 + j];
   15873                 // Figure out what the outputs should have been.
   15874                 CoreMathVerifier.computeConvert(args);
   15875                 // Validate the outputs.
   15876                 boolean valid = true;
   15877                 if (args.out != arrayOut[i * 4 + j]) {
   15878                     valid = false;
   15879                 }
   15880                 if (!valid) {
   15881                     StringBuilder message = new StringBuilder();
   15882                     message.append("Input inV: ");
   15883                     message.append(String.format("0x%x", args.inV));
   15884                     message.append("\n");
   15885                     message.append("Expected output out: ");
   15886                     message.append(String.format("%d", args.out));
   15887                     message.append("\n");
   15888                     message.append("Actual   output out: ");
   15889                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   15890                     if (args.out != arrayOut[i * 4 + j]) {
   15891                         message.append(" FAIL");
   15892                     }
   15893                     message.append("\n");
   15894                     assertTrue("Incorrect output for checkConvertUshort3Long3" +
   15895                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   15896                 }
   15897             }
   15898         }
   15899     }
   15900 
   15901     private void checkConvertUshort4Long4() {
   15902         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_16, 4, 0x8d799c90c3b12077l, false, 16);
   15903         try {
   15904             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 4), INPUTSIZE);
   15905             script.forEach_testConvertLong4Ushort4Long4(inV, out);
   15906             verifyResultsConvertUshort4Long4(inV, out, false);
   15907         } catch (Exception e) {
   15908             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong4Ushort4Long4: " + e.toString());
   15909         }
   15910         try {
   15911             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 4), INPUTSIZE);
   15912             scriptRelaxed.forEach_testConvertLong4Ushort4Long4(inV, out);
   15913             verifyResultsConvertUshort4Long4(inV, out, true);
   15914         } catch (Exception e) {
   15915             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong4Ushort4Long4: " + e.toString());
   15916         }
   15917     }
   15918 
   15919     private void verifyResultsConvertUshort4Long4(Allocation inV, Allocation out, boolean relaxed) {
   15920         short[] arrayInV = new short[INPUTSIZE * 4];
   15921         inV.copyTo(arrayInV);
   15922         long[] arrayOut = new long[INPUTSIZE * 4];
   15923         out.copyTo(arrayOut);
   15924         for (int i = 0; i < INPUTSIZE; i++) {
   15925             for (int j = 0; j < 4 ; j++) {
   15926                 // Extract the inputs.
   15927                 ArgumentsUshortLong args = new ArgumentsUshortLong();
   15928                 args.inV = arrayInV[i * 4 + j];
   15929                 // Figure out what the outputs should have been.
   15930                 CoreMathVerifier.computeConvert(args);
   15931                 // Validate the outputs.
   15932                 boolean valid = true;
   15933                 if (args.out != arrayOut[i * 4 + j]) {
   15934                     valid = false;
   15935                 }
   15936                 if (!valid) {
   15937                     StringBuilder message = new StringBuilder();
   15938                     message.append("Input inV: ");
   15939                     message.append(String.format("0x%x", args.inV));
   15940                     message.append("\n");
   15941                     message.append("Expected output out: ");
   15942                     message.append(String.format("%d", args.out));
   15943                     message.append("\n");
   15944                     message.append("Actual   output out: ");
   15945                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   15946                     if (args.out != arrayOut[i * 4 + j]) {
   15947                         message.append(" FAIL");
   15948                     }
   15949                     message.append("\n");
   15950                     assertTrue("Incorrect output for checkConvertUshort4Long4" +
   15951                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   15952                 }
   15953             }
   15954         }
   15955     }
   15956 
   15957     public class ArgumentsIntLong {
   15958         public int inV;
   15959         public long out;
   15960     }
   15961 
   15962     private void checkConvertInt2Long2() {
   15963         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_32, 2, 0xd74f538b8a45cb5dl, true, 31);
   15964         try {
   15965             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 2), INPUTSIZE);
   15966             script.forEach_testConvertLong2Int2Long2(inV, out);
   15967             verifyResultsConvertInt2Long2(inV, out, false);
   15968         } catch (Exception e) {
   15969             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong2Int2Long2: " + e.toString());
   15970         }
   15971         try {
   15972             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 2), INPUTSIZE);
   15973             scriptRelaxed.forEach_testConvertLong2Int2Long2(inV, out);
   15974             verifyResultsConvertInt2Long2(inV, out, true);
   15975         } catch (Exception e) {
   15976             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong2Int2Long2: " + e.toString());
   15977         }
   15978     }
   15979 
   15980     private void verifyResultsConvertInt2Long2(Allocation inV, Allocation out, boolean relaxed) {
   15981         int[] arrayInV = new int[INPUTSIZE * 2];
   15982         inV.copyTo(arrayInV);
   15983         long[] arrayOut = new long[INPUTSIZE * 2];
   15984         out.copyTo(arrayOut);
   15985         for (int i = 0; i < INPUTSIZE; i++) {
   15986             for (int j = 0; j < 2 ; j++) {
   15987                 // Extract the inputs.
   15988                 ArgumentsIntLong args = new ArgumentsIntLong();
   15989                 args.inV = arrayInV[i * 2 + j];
   15990                 // Figure out what the outputs should have been.
   15991                 CoreMathVerifier.computeConvert(args);
   15992                 // Validate the outputs.
   15993                 boolean valid = true;
   15994                 if (args.out != arrayOut[i * 2 + j]) {
   15995                     valid = false;
   15996                 }
   15997                 if (!valid) {
   15998                     StringBuilder message = new StringBuilder();
   15999                     message.append("Input inV: ");
   16000                     message.append(String.format("%d", args.inV));
   16001                     message.append("\n");
   16002                     message.append("Expected output out: ");
   16003                     message.append(String.format("%d", args.out));
   16004                     message.append("\n");
   16005                     message.append("Actual   output out: ");
   16006                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   16007                     if (args.out != arrayOut[i * 2 + j]) {
   16008                         message.append(" FAIL");
   16009                     }
   16010                     message.append("\n");
   16011                     assertTrue("Incorrect output for checkConvertInt2Long2" +
   16012                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   16013                 }
   16014             }
   16015         }
   16016     }
   16017 
   16018     private void checkConvertInt3Long3() {
   16019         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_32, 3, 0xd74f5e2ce94d9051l, true, 31);
   16020         try {
   16021             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 3), INPUTSIZE);
   16022             script.forEach_testConvertLong3Int3Long3(inV, out);
   16023             verifyResultsConvertInt3Long3(inV, out, false);
   16024         } catch (Exception e) {
   16025             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong3Int3Long3: " + e.toString());
   16026         }
   16027         try {
   16028             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 3), INPUTSIZE);
   16029             scriptRelaxed.forEach_testConvertLong3Int3Long3(inV, out);
   16030             verifyResultsConvertInt3Long3(inV, out, true);
   16031         } catch (Exception e) {
   16032             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong3Int3Long3: " + e.toString());
   16033         }
   16034     }
   16035 
   16036     private void verifyResultsConvertInt3Long3(Allocation inV, Allocation out, boolean relaxed) {
   16037         int[] arrayInV = new int[INPUTSIZE * 4];
   16038         inV.copyTo(arrayInV);
   16039         long[] arrayOut = new long[INPUTSIZE * 4];
   16040         out.copyTo(arrayOut);
   16041         for (int i = 0; i < INPUTSIZE; i++) {
   16042             for (int j = 0; j < 3 ; j++) {
   16043                 // Extract the inputs.
   16044                 ArgumentsIntLong args = new ArgumentsIntLong();
   16045                 args.inV = arrayInV[i * 4 + j];
   16046                 // Figure out what the outputs should have been.
   16047                 CoreMathVerifier.computeConvert(args);
   16048                 // Validate the outputs.
   16049                 boolean valid = true;
   16050                 if (args.out != arrayOut[i * 4 + j]) {
   16051                     valid = false;
   16052                 }
   16053                 if (!valid) {
   16054                     StringBuilder message = new StringBuilder();
   16055                     message.append("Input inV: ");
   16056                     message.append(String.format("%d", args.inV));
   16057                     message.append("\n");
   16058                     message.append("Expected output out: ");
   16059                     message.append(String.format("%d", args.out));
   16060                     message.append("\n");
   16061                     message.append("Actual   output out: ");
   16062                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   16063                     if (args.out != arrayOut[i * 4 + j]) {
   16064                         message.append(" FAIL");
   16065                     }
   16066                     message.append("\n");
   16067                     assertTrue("Incorrect output for checkConvertInt3Long3" +
   16068                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   16069                 }
   16070             }
   16071         }
   16072     }
   16073 
   16074     private void checkConvertInt4Long4() {
   16075         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_32, 4, 0xd74f68ce48555545l, true, 31);
   16076         try {
   16077             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 4), INPUTSIZE);
   16078             script.forEach_testConvertLong4Int4Long4(inV, out);
   16079             verifyResultsConvertInt4Long4(inV, out, false);
   16080         } catch (Exception e) {
   16081             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong4Int4Long4: " + e.toString());
   16082         }
   16083         try {
   16084             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 4), INPUTSIZE);
   16085             scriptRelaxed.forEach_testConvertLong4Int4Long4(inV, out);
   16086             verifyResultsConvertInt4Long4(inV, out, true);
   16087         } catch (Exception e) {
   16088             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong4Int4Long4: " + e.toString());
   16089         }
   16090     }
   16091 
   16092     private void verifyResultsConvertInt4Long4(Allocation inV, Allocation out, boolean relaxed) {
   16093         int[] arrayInV = new int[INPUTSIZE * 4];
   16094         inV.copyTo(arrayInV);
   16095         long[] arrayOut = new long[INPUTSIZE * 4];
   16096         out.copyTo(arrayOut);
   16097         for (int i = 0; i < INPUTSIZE; i++) {
   16098             for (int j = 0; j < 4 ; j++) {
   16099                 // Extract the inputs.
   16100                 ArgumentsIntLong args = new ArgumentsIntLong();
   16101                 args.inV = arrayInV[i * 4 + j];
   16102                 // Figure out what the outputs should have been.
   16103                 CoreMathVerifier.computeConvert(args);
   16104                 // Validate the outputs.
   16105                 boolean valid = true;
   16106                 if (args.out != arrayOut[i * 4 + j]) {
   16107                     valid = false;
   16108                 }
   16109                 if (!valid) {
   16110                     StringBuilder message = new StringBuilder();
   16111                     message.append("Input inV: ");
   16112                     message.append(String.format("%d", args.inV));
   16113                     message.append("\n");
   16114                     message.append("Expected output out: ");
   16115                     message.append(String.format("%d", args.out));
   16116                     message.append("\n");
   16117                     message.append("Actual   output out: ");
   16118                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   16119                     if (args.out != arrayOut[i * 4 + j]) {
   16120                         message.append(" FAIL");
   16121                     }
   16122                     message.append("\n");
   16123                     assertTrue("Incorrect output for checkConvertInt4Long4" +
   16124                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   16125                 }
   16126             }
   16127         }
   16128     }
   16129 
   16130     public class ArgumentsUintLong {
   16131         public int inV;
   16132         public long out;
   16133     }
   16134 
   16135     private void checkConvertUint2Long2() {
   16136         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_32, 2, 0xe71d0a7587b9ef60l, false, 32);
   16137         try {
   16138             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 2), INPUTSIZE);
   16139             script.forEach_testConvertLong2Uint2Long2(inV, out);
   16140             verifyResultsConvertUint2Long2(inV, out, false);
   16141         } catch (Exception e) {
   16142             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong2Uint2Long2: " + e.toString());
   16143         }
   16144         try {
   16145             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 2), INPUTSIZE);
   16146             scriptRelaxed.forEach_testConvertLong2Uint2Long2(inV, out);
   16147             verifyResultsConvertUint2Long2(inV, out, true);
   16148         } catch (Exception e) {
   16149             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong2Uint2Long2: " + e.toString());
   16150         }
   16151     }
   16152 
   16153     private void verifyResultsConvertUint2Long2(Allocation inV, Allocation out, boolean relaxed) {
   16154         int[] arrayInV = new int[INPUTSIZE * 2];
   16155         inV.copyTo(arrayInV);
   16156         long[] arrayOut = new long[INPUTSIZE * 2];
   16157         out.copyTo(arrayOut);
   16158         for (int i = 0; i < INPUTSIZE; i++) {
   16159             for (int j = 0; j < 2 ; j++) {
   16160                 // Extract the inputs.
   16161                 ArgumentsUintLong args = new ArgumentsUintLong();
   16162                 args.inV = arrayInV[i * 2 + j];
   16163                 // Figure out what the outputs should have been.
   16164                 CoreMathVerifier.computeConvert(args);
   16165                 // Validate the outputs.
   16166                 boolean valid = true;
   16167                 if (args.out != arrayOut[i * 2 + j]) {
   16168                     valid = false;
   16169                 }
   16170                 if (!valid) {
   16171                     StringBuilder message = new StringBuilder();
   16172                     message.append("Input inV: ");
   16173                     message.append(String.format("0x%x", args.inV));
   16174                     message.append("\n");
   16175                     message.append("Expected output out: ");
   16176                     message.append(String.format("%d", args.out));
   16177                     message.append("\n");
   16178                     message.append("Actual   output out: ");
   16179                     message.append(String.format("%d", arrayOut[i * 2 + j]));
   16180                     if (args.out != arrayOut[i * 2 + j]) {
   16181                         message.append(" FAIL");
   16182                     }
   16183                     message.append("\n");
   16184                     assertTrue("Incorrect output for checkConvertUint2Long2" +
   16185                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   16186                 }
   16187             }
   16188         }
   16189     }
   16190 
   16191     private void checkConvertUint3Long3() {
   16192         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_32, 3, 0xe71d1516e6c1b454l, false, 32);
   16193         try {
   16194             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 3), INPUTSIZE);
   16195             script.forEach_testConvertLong3Uint3Long3(inV, out);
   16196             verifyResultsConvertUint3Long3(inV, out, false);
   16197         } catch (Exception e) {
   16198             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong3Uint3Long3: " + e.toString());
   16199         }
   16200         try {
   16201             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 3), INPUTSIZE);
   16202             scriptRelaxed.forEach_testConvertLong3Uint3Long3(inV, out);
   16203             verifyResultsConvertUint3Long3(inV, out, true);
   16204         } catch (Exception e) {
   16205             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong3Uint3Long3: " + e.toString());
   16206         }
   16207     }
   16208 
   16209     private void verifyResultsConvertUint3Long3(Allocation inV, Allocation out, boolean relaxed) {
   16210         int[] arrayInV = new int[INPUTSIZE * 4];
   16211         inV.copyTo(arrayInV);
   16212         long[] arrayOut = new long[INPUTSIZE * 4];
   16213         out.copyTo(arrayOut);
   16214         for (int i = 0; i < INPUTSIZE; i++) {
   16215             for (int j = 0; j < 3 ; j++) {
   16216                 // Extract the inputs.
   16217                 ArgumentsUintLong args = new ArgumentsUintLong();
   16218                 args.inV = arrayInV[i * 4 + j];
   16219                 // Figure out what the outputs should have been.
   16220                 CoreMathVerifier.computeConvert(args);
   16221                 // Validate the outputs.
   16222                 boolean valid = true;
   16223                 if (args.out != arrayOut[i * 4 + j]) {
   16224                     valid = false;
   16225                 }
   16226                 if (!valid) {
   16227                     StringBuilder message = new StringBuilder();
   16228                     message.append("Input inV: ");
   16229                     message.append(String.format("0x%x", args.inV));
   16230                     message.append("\n");
   16231                     message.append("Expected output out: ");
   16232                     message.append(String.format("%d", args.out));
   16233                     message.append("\n");
   16234                     message.append("Actual   output out: ");
   16235                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   16236                     if (args.out != arrayOut[i * 4 + j]) {
   16237                         message.append(" FAIL");
   16238                     }
   16239                     message.append("\n");
   16240                     assertTrue("Incorrect output for checkConvertUint3Long3" +
   16241                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   16242                 }
   16243             }
   16244         }
   16245     }
   16246 
   16247     private void checkConvertUint4Long4() {
   16248         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_32, 4, 0xe71d1fb845c97948l, false, 32);
   16249         try {
   16250             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 4), INPUTSIZE);
   16251             script.forEach_testConvertLong4Uint4Long4(inV, out);
   16252             verifyResultsConvertUint4Long4(inV, out, false);
   16253         } catch (Exception e) {
   16254             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong4Uint4Long4: " + e.toString());
   16255         }
   16256         try {
   16257             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.SIGNED_64, 4), INPUTSIZE);
   16258             scriptRelaxed.forEach_testConvertLong4Uint4Long4(inV, out);
   16259             verifyResultsConvertUint4Long4(inV, out, true);
   16260         } catch (Exception e) {
   16261             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertLong4Uint4Long4: " + e.toString());
   16262         }
   16263     }
   16264 
   16265     private void verifyResultsConvertUint4Long4(Allocation inV, Allocation out, boolean relaxed) {
   16266         int[] arrayInV = new int[INPUTSIZE * 4];
   16267         inV.copyTo(arrayInV);
   16268         long[] arrayOut = new long[INPUTSIZE * 4];
   16269         out.copyTo(arrayOut);
   16270         for (int i = 0; i < INPUTSIZE; i++) {
   16271             for (int j = 0; j < 4 ; j++) {
   16272                 // Extract the inputs.
   16273                 ArgumentsUintLong args = new ArgumentsUintLong();
   16274                 args.inV = arrayInV[i * 4 + j];
   16275                 // Figure out what the outputs should have been.
   16276                 CoreMathVerifier.computeConvert(args);
   16277                 // Validate the outputs.
   16278                 boolean valid = true;
   16279                 if (args.out != arrayOut[i * 4 + j]) {
   16280                     valid = false;
   16281                 }
   16282                 if (!valid) {
   16283                     StringBuilder message = new StringBuilder();
   16284                     message.append("Input inV: ");
   16285                     message.append(String.format("0x%x", args.inV));
   16286                     message.append("\n");
   16287                     message.append("Expected output out: ");
   16288                     message.append(String.format("%d", args.out));
   16289                     message.append("\n");
   16290                     message.append("Actual   output out: ");
   16291                     message.append(String.format("%d", arrayOut[i * 4 + j]));
   16292                     if (args.out != arrayOut[i * 4 + j]) {
   16293                         message.append(" FAIL");
   16294                     }
   16295                     message.append("\n");
   16296                     assertTrue("Incorrect output for checkConvertUint4Long4" +
   16297                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   16298                 }
   16299             }
   16300         }
   16301     }
   16302 
   16303     public class ArgumentsFloatUlong {
   16304         public float inV;
   16305         public long out;
   16306     }
   16307 
   16308     private void checkConvertFloat2Ulong2() {
   16309         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 2, 0xfb52b5394ec4cff7l, 0.0000000000000000000e+00, 1.8446742974197923840e+19);
   16310         try {
   16311             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 2), INPUTSIZE);
   16312             script.forEach_testConvertUlong2Float2Ulong2(inV, out);
   16313             verifyResultsConvertFloat2Ulong2(inV, out, false);
   16314         } catch (Exception e) {
   16315             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong2Float2Ulong2: " + e.toString());
   16316         }
   16317         try {
   16318             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 2), INPUTSIZE);
   16319             scriptRelaxed.forEach_testConvertUlong2Float2Ulong2(inV, out);
   16320             verifyResultsConvertFloat2Ulong2(inV, out, true);
   16321         } catch (Exception e) {
   16322             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong2Float2Ulong2: " + e.toString());
   16323         }
   16324     }
   16325 
   16326     private void verifyResultsConvertFloat2Ulong2(Allocation inV, Allocation out, boolean relaxed) {
   16327         float[] arrayInV = new float[INPUTSIZE * 2];
   16328         inV.copyTo(arrayInV);
   16329         long[] arrayOut = new long[INPUTSIZE * 2];
   16330         out.copyTo(arrayOut);
   16331         for (int i = 0; i < INPUTSIZE; i++) {
   16332             for (int j = 0; j < 2 ; j++) {
   16333                 // Extract the inputs.
   16334                 ArgumentsFloatUlong args = new ArgumentsFloatUlong();
   16335                 args.inV = arrayInV[i * 2 + j];
   16336                 // Figure out what the outputs should have been.
   16337                 CoreMathVerifier.computeConvert(args);
   16338                 // Validate the outputs.
   16339                 boolean valid = true;
   16340                 if (args.out != arrayOut[i * 2 + j]) {
   16341                     valid = false;
   16342                 }
   16343                 if (!valid) {
   16344                     StringBuilder message = new StringBuilder();
   16345                     message.append("Input inV: ");
   16346                     message.append(String.format("%14.8g {%8x} %15a",
   16347                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
   16348                     message.append("\n");
   16349                     message.append("Expected output out: ");
   16350                     message.append(String.format("0x%x", args.out));
   16351                     message.append("\n");
   16352                     message.append("Actual   output out: ");
   16353                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   16354                     if (args.out != arrayOut[i * 2 + j]) {
   16355                         message.append(" FAIL");
   16356                     }
   16357                     message.append("\n");
   16358                     assertTrue("Incorrect output for checkConvertFloat2Ulong2" +
   16359                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   16360                 }
   16361             }
   16362         }
   16363     }
   16364 
   16365     private void checkConvertFloat3Ulong3() {
   16366         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 3, 0xfb547e5444dff0d5l, 0.0000000000000000000e+00, 1.8446742974197923840e+19);
   16367         try {
   16368             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 3), INPUTSIZE);
   16369             script.forEach_testConvertUlong3Float3Ulong3(inV, out);
   16370             verifyResultsConvertFloat3Ulong3(inV, out, false);
   16371         } catch (Exception e) {
   16372             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong3Float3Ulong3: " + e.toString());
   16373         }
   16374         try {
   16375             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 3), INPUTSIZE);
   16376             scriptRelaxed.forEach_testConvertUlong3Float3Ulong3(inV, out);
   16377             verifyResultsConvertFloat3Ulong3(inV, out, true);
   16378         } catch (Exception e) {
   16379             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong3Float3Ulong3: " + e.toString());
   16380         }
   16381     }
   16382 
   16383     private void verifyResultsConvertFloat3Ulong3(Allocation inV, Allocation out, boolean relaxed) {
   16384         float[] arrayInV = new float[INPUTSIZE * 4];
   16385         inV.copyTo(arrayInV);
   16386         long[] arrayOut = new long[INPUTSIZE * 4];
   16387         out.copyTo(arrayOut);
   16388         for (int i = 0; i < INPUTSIZE; i++) {
   16389             for (int j = 0; j < 3 ; j++) {
   16390                 // Extract the inputs.
   16391                 ArgumentsFloatUlong args = new ArgumentsFloatUlong();
   16392                 args.inV = arrayInV[i * 4 + j];
   16393                 // Figure out what the outputs should have been.
   16394                 CoreMathVerifier.computeConvert(args);
   16395                 // Validate the outputs.
   16396                 boolean valid = true;
   16397                 if (args.out != arrayOut[i * 4 + j]) {
   16398                     valid = false;
   16399                 }
   16400                 if (!valid) {
   16401                     StringBuilder message = new StringBuilder();
   16402                     message.append("Input inV: ");
   16403                     message.append(String.format("%14.8g {%8x} %15a",
   16404                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
   16405                     message.append("\n");
   16406                     message.append("Expected output out: ");
   16407                     message.append(String.format("0x%x", args.out));
   16408                     message.append("\n");
   16409                     message.append("Actual   output out: ");
   16410                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   16411                     if (args.out != arrayOut[i * 4 + j]) {
   16412                         message.append(" FAIL");
   16413                     }
   16414                     message.append("\n");
   16415                     assertTrue("Incorrect output for checkConvertFloat3Ulong3" +
   16416                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   16417                 }
   16418             }
   16419         }
   16420     }
   16421 
   16422     private void checkConvertFloat4Ulong4() {
   16423         Allocation inV = createRandomFloatAllocation(mRS, Element.DataType.FLOAT_32, 4, 0xfb56476f3afb11b3l, 0.0000000000000000000e+00, 1.8446742974197923840e+19);
   16424         try {
   16425             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 4), INPUTSIZE);
   16426             script.forEach_testConvertUlong4Float4Ulong4(inV, out);
   16427             verifyResultsConvertFloat4Ulong4(inV, out, false);
   16428         } catch (Exception e) {
   16429             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong4Float4Ulong4: " + e.toString());
   16430         }
   16431         try {
   16432             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 4), INPUTSIZE);
   16433             scriptRelaxed.forEach_testConvertUlong4Float4Ulong4(inV, out);
   16434             verifyResultsConvertFloat4Ulong4(inV, out, true);
   16435         } catch (Exception e) {
   16436             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong4Float4Ulong4: " + e.toString());
   16437         }
   16438     }
   16439 
   16440     private void verifyResultsConvertFloat4Ulong4(Allocation inV, Allocation out, boolean relaxed) {
   16441         float[] arrayInV = new float[INPUTSIZE * 4];
   16442         inV.copyTo(arrayInV);
   16443         long[] arrayOut = new long[INPUTSIZE * 4];
   16444         out.copyTo(arrayOut);
   16445         for (int i = 0; i < INPUTSIZE; i++) {
   16446             for (int j = 0; j < 4 ; j++) {
   16447                 // Extract the inputs.
   16448                 ArgumentsFloatUlong args = new ArgumentsFloatUlong();
   16449                 args.inV = arrayInV[i * 4 + j];
   16450                 // Figure out what the outputs should have been.
   16451                 CoreMathVerifier.computeConvert(args);
   16452                 // Validate the outputs.
   16453                 boolean valid = true;
   16454                 if (args.out != arrayOut[i * 4 + j]) {
   16455                     valid = false;
   16456                 }
   16457                 if (!valid) {
   16458                     StringBuilder message = new StringBuilder();
   16459                     message.append("Input inV: ");
   16460                     message.append(String.format("%14.8g {%8x} %15a",
   16461                             args.inV, Float.floatToRawIntBits(args.inV), args.inV));
   16462                     message.append("\n");
   16463                     message.append("Expected output out: ");
   16464                     message.append(String.format("0x%x", args.out));
   16465                     message.append("\n");
   16466                     message.append("Actual   output out: ");
   16467                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   16468                     if (args.out != arrayOut[i * 4 + j]) {
   16469                         message.append(" FAIL");
   16470                     }
   16471                     message.append("\n");
   16472                     assertTrue("Incorrect output for checkConvertFloat4Ulong4" +
   16473                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   16474                 }
   16475             }
   16476         }
   16477     }
   16478 
   16479     public class ArgumentsCharUlong {
   16480         public byte inV;
   16481         public long out;
   16482     }
   16483 
   16484     private void checkConvertChar2Ulong2() {
   16485         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_8, 2, 0x5862818b1fedf7b7l, false, 7);
   16486         try {
   16487             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 2), INPUTSIZE);
   16488             script.forEach_testConvertUlong2Char2Ulong2(inV, out);
   16489             verifyResultsConvertChar2Ulong2(inV, out, false);
   16490         } catch (Exception e) {
   16491             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong2Char2Ulong2: " + e.toString());
   16492         }
   16493         try {
   16494             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 2), INPUTSIZE);
   16495             scriptRelaxed.forEach_testConvertUlong2Char2Ulong2(inV, out);
   16496             verifyResultsConvertChar2Ulong2(inV, out, true);
   16497         } catch (Exception e) {
   16498             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong2Char2Ulong2: " + e.toString());
   16499         }
   16500     }
   16501 
   16502     private void verifyResultsConvertChar2Ulong2(Allocation inV, Allocation out, boolean relaxed) {
   16503         byte[] arrayInV = new byte[INPUTSIZE * 2];
   16504         inV.copyTo(arrayInV);
   16505         long[] arrayOut = new long[INPUTSIZE * 2];
   16506         out.copyTo(arrayOut);
   16507         for (int i = 0; i < INPUTSIZE; i++) {
   16508             for (int j = 0; j < 2 ; j++) {
   16509                 // Extract the inputs.
   16510                 ArgumentsCharUlong args = new ArgumentsCharUlong();
   16511                 args.inV = arrayInV[i * 2 + j];
   16512                 // Figure out what the outputs should have been.
   16513                 CoreMathVerifier.computeConvert(args);
   16514                 // Validate the outputs.
   16515                 boolean valid = true;
   16516                 if (args.out != arrayOut[i * 2 + j]) {
   16517                     valid = false;
   16518                 }
   16519                 if (!valid) {
   16520                     StringBuilder message = new StringBuilder();
   16521                     message.append("Input inV: ");
   16522                     message.append(String.format("%d", args.inV));
   16523                     message.append("\n");
   16524                     message.append("Expected output out: ");
   16525                     message.append(String.format("0x%x", args.out));
   16526                     message.append("\n");
   16527                     message.append("Actual   output out: ");
   16528                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   16529                     if (args.out != arrayOut[i * 2 + j]) {
   16530                         message.append(" FAIL");
   16531                     }
   16532                     message.append("\n");
   16533                     assertTrue("Incorrect output for checkConvertChar2Ulong2" +
   16534                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   16535                 }
   16536             }
   16537         }
   16538     }
   16539 
   16540     private void checkConvertChar3Ulong3() {
   16541         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_8, 3, 0x58644aa616091895l, false, 7);
   16542         try {
   16543             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 3), INPUTSIZE);
   16544             script.forEach_testConvertUlong3Char3Ulong3(inV, out);
   16545             verifyResultsConvertChar3Ulong3(inV, out, false);
   16546         } catch (Exception e) {
   16547             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong3Char3Ulong3: " + e.toString());
   16548         }
   16549         try {
   16550             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 3), INPUTSIZE);
   16551             scriptRelaxed.forEach_testConvertUlong3Char3Ulong3(inV, out);
   16552             verifyResultsConvertChar3Ulong3(inV, out, true);
   16553         } catch (Exception e) {
   16554             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong3Char3Ulong3: " + e.toString());
   16555         }
   16556     }
   16557 
   16558     private void verifyResultsConvertChar3Ulong3(Allocation inV, Allocation out, boolean relaxed) {
   16559         byte[] arrayInV = new byte[INPUTSIZE * 4];
   16560         inV.copyTo(arrayInV);
   16561         long[] arrayOut = new long[INPUTSIZE * 4];
   16562         out.copyTo(arrayOut);
   16563         for (int i = 0; i < INPUTSIZE; i++) {
   16564             for (int j = 0; j < 3 ; j++) {
   16565                 // Extract the inputs.
   16566                 ArgumentsCharUlong args = new ArgumentsCharUlong();
   16567                 args.inV = arrayInV[i * 4 + j];
   16568                 // Figure out what the outputs should have been.
   16569                 CoreMathVerifier.computeConvert(args);
   16570                 // Validate the outputs.
   16571                 boolean valid = true;
   16572                 if (args.out != arrayOut[i * 4 + j]) {
   16573                     valid = false;
   16574                 }
   16575                 if (!valid) {
   16576                     StringBuilder message = new StringBuilder();
   16577                     message.append("Input inV: ");
   16578                     message.append(String.format("%d", args.inV));
   16579                     message.append("\n");
   16580                     message.append("Expected output out: ");
   16581                     message.append(String.format("0x%x", args.out));
   16582                     message.append("\n");
   16583                     message.append("Actual   output out: ");
   16584                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   16585                     if (args.out != arrayOut[i * 4 + j]) {
   16586                         message.append(" FAIL");
   16587                     }
   16588                     message.append("\n");
   16589                     assertTrue("Incorrect output for checkConvertChar3Ulong3" +
   16590                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   16591                 }
   16592             }
   16593         }
   16594     }
   16595 
   16596     private void checkConvertChar4Ulong4() {
   16597         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_8, 4, 0x586613c10c243973l, false, 7);
   16598         try {
   16599             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 4), INPUTSIZE);
   16600             script.forEach_testConvertUlong4Char4Ulong4(inV, out);
   16601             verifyResultsConvertChar4Ulong4(inV, out, false);
   16602         } catch (Exception e) {
   16603             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong4Char4Ulong4: " + e.toString());
   16604         }
   16605         try {
   16606             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 4), INPUTSIZE);
   16607             scriptRelaxed.forEach_testConvertUlong4Char4Ulong4(inV, out);
   16608             verifyResultsConvertChar4Ulong4(inV, out, true);
   16609         } catch (Exception e) {
   16610             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong4Char4Ulong4: " + e.toString());
   16611         }
   16612     }
   16613 
   16614     private void verifyResultsConvertChar4Ulong4(Allocation inV, Allocation out, boolean relaxed) {
   16615         byte[] arrayInV = new byte[INPUTSIZE * 4];
   16616         inV.copyTo(arrayInV);
   16617         long[] arrayOut = new long[INPUTSIZE * 4];
   16618         out.copyTo(arrayOut);
   16619         for (int i = 0; i < INPUTSIZE; i++) {
   16620             for (int j = 0; j < 4 ; j++) {
   16621                 // Extract the inputs.
   16622                 ArgumentsCharUlong args = new ArgumentsCharUlong();
   16623                 args.inV = arrayInV[i * 4 + j];
   16624                 // Figure out what the outputs should have been.
   16625                 CoreMathVerifier.computeConvert(args);
   16626                 // Validate the outputs.
   16627                 boolean valid = true;
   16628                 if (args.out != arrayOut[i * 4 + j]) {
   16629                     valid = false;
   16630                 }
   16631                 if (!valid) {
   16632                     StringBuilder message = new StringBuilder();
   16633                     message.append("Input inV: ");
   16634                     message.append(String.format("%d", args.inV));
   16635                     message.append("\n");
   16636                     message.append("Expected output out: ");
   16637                     message.append(String.format("0x%x", args.out));
   16638                     message.append("\n");
   16639                     message.append("Actual   output out: ");
   16640                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   16641                     if (args.out != arrayOut[i * 4 + j]) {
   16642                         message.append(" FAIL");
   16643                     }
   16644                     message.append("\n");
   16645                     assertTrue("Incorrect output for checkConvertChar4Ulong4" +
   16646                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   16647                 }
   16648             }
   16649         }
   16650     }
   16651 
   16652     public class ArgumentsUcharUlong {
   16653         public byte inV;
   16654         public long out;
   16655     }
   16656 
   16657     private void checkConvertUchar2Ulong2() {
   16658         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_8, 2, 0x7d30a192bbc61162l, false, 8);
   16659         try {
   16660             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 2), INPUTSIZE);
   16661             script.forEach_testConvertUlong2Uchar2Ulong2(inV, out);
   16662             verifyResultsConvertUchar2Ulong2(inV, out, false);
   16663         } catch (Exception e) {
   16664             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong2Uchar2Ulong2: " + e.toString());
   16665         }
   16666         try {
   16667             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 2), INPUTSIZE);
   16668             scriptRelaxed.forEach_testConvertUlong2Uchar2Ulong2(inV, out);
   16669             verifyResultsConvertUchar2Ulong2(inV, out, true);
   16670         } catch (Exception e) {
   16671             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong2Uchar2Ulong2: " + e.toString());
   16672         }
   16673     }
   16674 
   16675     private void verifyResultsConvertUchar2Ulong2(Allocation inV, Allocation out, boolean relaxed) {
   16676         byte[] arrayInV = new byte[INPUTSIZE * 2];
   16677         inV.copyTo(arrayInV);
   16678         long[] arrayOut = new long[INPUTSIZE * 2];
   16679         out.copyTo(arrayOut);
   16680         for (int i = 0; i < INPUTSIZE; i++) {
   16681             for (int j = 0; j < 2 ; j++) {
   16682                 // Extract the inputs.
   16683                 ArgumentsUcharUlong args = new ArgumentsUcharUlong();
   16684                 args.inV = arrayInV[i * 2 + j];
   16685                 // Figure out what the outputs should have been.
   16686                 CoreMathVerifier.computeConvert(args);
   16687                 // Validate the outputs.
   16688                 boolean valid = true;
   16689                 if (args.out != arrayOut[i * 2 + j]) {
   16690                     valid = false;
   16691                 }
   16692                 if (!valid) {
   16693                     StringBuilder message = new StringBuilder();
   16694                     message.append("Input inV: ");
   16695                     message.append(String.format("0x%x", args.inV));
   16696                     message.append("\n");
   16697                     message.append("Expected output out: ");
   16698                     message.append(String.format("0x%x", args.out));
   16699                     message.append("\n");
   16700                     message.append("Actual   output out: ");
   16701                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   16702                     if (args.out != arrayOut[i * 2 + j]) {
   16703                         message.append(" FAIL");
   16704                     }
   16705                     message.append("\n");
   16706                     assertTrue("Incorrect output for checkConvertUchar2Ulong2" +
   16707                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   16708                 }
   16709             }
   16710         }
   16711     }
   16712 
   16713     private void checkConvertUchar3Ulong3() {
   16714         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_8, 3, 0x7d326aadb1e13240l, false, 8);
   16715         try {
   16716             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 3), INPUTSIZE);
   16717             script.forEach_testConvertUlong3Uchar3Ulong3(inV, out);
   16718             verifyResultsConvertUchar3Ulong3(inV, out, false);
   16719         } catch (Exception e) {
   16720             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong3Uchar3Ulong3: " + e.toString());
   16721         }
   16722         try {
   16723             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 3), INPUTSIZE);
   16724             scriptRelaxed.forEach_testConvertUlong3Uchar3Ulong3(inV, out);
   16725             verifyResultsConvertUchar3Ulong3(inV, out, true);
   16726         } catch (Exception e) {
   16727             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong3Uchar3Ulong3: " + e.toString());
   16728         }
   16729     }
   16730 
   16731     private void verifyResultsConvertUchar3Ulong3(Allocation inV, Allocation out, boolean relaxed) {
   16732         byte[] arrayInV = new byte[INPUTSIZE * 4];
   16733         inV.copyTo(arrayInV);
   16734         long[] arrayOut = new long[INPUTSIZE * 4];
   16735         out.copyTo(arrayOut);
   16736         for (int i = 0; i < INPUTSIZE; i++) {
   16737             for (int j = 0; j < 3 ; j++) {
   16738                 // Extract the inputs.
   16739                 ArgumentsUcharUlong args = new ArgumentsUcharUlong();
   16740                 args.inV = arrayInV[i * 4 + j];
   16741                 // Figure out what the outputs should have been.
   16742                 CoreMathVerifier.computeConvert(args);
   16743                 // Validate the outputs.
   16744                 boolean valid = true;
   16745                 if (args.out != arrayOut[i * 4 + j]) {
   16746                     valid = false;
   16747                 }
   16748                 if (!valid) {
   16749                     StringBuilder message = new StringBuilder();
   16750                     message.append("Input inV: ");
   16751                     message.append(String.format("0x%x", args.inV));
   16752                     message.append("\n");
   16753                     message.append("Expected output out: ");
   16754                     message.append(String.format("0x%x", args.out));
   16755                     message.append("\n");
   16756                     message.append("Actual   output out: ");
   16757                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   16758                     if (args.out != arrayOut[i * 4 + j]) {
   16759                         message.append(" FAIL");
   16760                     }
   16761                     message.append("\n");
   16762                     assertTrue("Incorrect output for checkConvertUchar3Ulong3" +
   16763                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   16764                 }
   16765             }
   16766         }
   16767     }
   16768 
   16769     private void checkConvertUchar4Ulong4() {
   16770         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_8, 4, 0x7d3433c8a7fc531el, false, 8);
   16771         try {
   16772             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 4), INPUTSIZE);
   16773             script.forEach_testConvertUlong4Uchar4Ulong4(inV, out);
   16774             verifyResultsConvertUchar4Ulong4(inV, out, false);
   16775         } catch (Exception e) {
   16776             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong4Uchar4Ulong4: " + e.toString());
   16777         }
   16778         try {
   16779             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 4), INPUTSIZE);
   16780             scriptRelaxed.forEach_testConvertUlong4Uchar4Ulong4(inV, out);
   16781             verifyResultsConvertUchar4Ulong4(inV, out, true);
   16782         } catch (Exception e) {
   16783             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong4Uchar4Ulong4: " + e.toString());
   16784         }
   16785     }
   16786 
   16787     private void verifyResultsConvertUchar4Ulong4(Allocation inV, Allocation out, boolean relaxed) {
   16788         byte[] arrayInV = new byte[INPUTSIZE * 4];
   16789         inV.copyTo(arrayInV);
   16790         long[] arrayOut = new long[INPUTSIZE * 4];
   16791         out.copyTo(arrayOut);
   16792         for (int i = 0; i < INPUTSIZE; i++) {
   16793             for (int j = 0; j < 4 ; j++) {
   16794                 // Extract the inputs.
   16795                 ArgumentsUcharUlong args = new ArgumentsUcharUlong();
   16796                 args.inV = arrayInV[i * 4 + j];
   16797                 // Figure out what the outputs should have been.
   16798                 CoreMathVerifier.computeConvert(args);
   16799                 // Validate the outputs.
   16800                 boolean valid = true;
   16801                 if (args.out != arrayOut[i * 4 + j]) {
   16802                     valid = false;
   16803                 }
   16804                 if (!valid) {
   16805                     StringBuilder message = new StringBuilder();
   16806                     message.append("Input inV: ");
   16807                     message.append(String.format("0x%x", args.inV));
   16808                     message.append("\n");
   16809                     message.append("Expected output out: ");
   16810                     message.append(String.format("0x%x", args.out));
   16811                     message.append("\n");
   16812                     message.append("Actual   output out: ");
   16813                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   16814                     if (args.out != arrayOut[i * 4 + j]) {
   16815                         message.append(" FAIL");
   16816                     }
   16817                     message.append("\n");
   16818                     assertTrue("Incorrect output for checkConvertUchar4Ulong4" +
   16819                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   16820                 }
   16821             }
   16822         }
   16823     }
   16824 
   16825     public class ArgumentsShortUlong {
   16826         public short inV;
   16827         public long out;
   16828     }
   16829 
   16830     private void checkConvertShort2Ulong2() {
   16831         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_16, 2, 0x94cab7c3ffc6f6a3l, false, 15);
   16832         try {
   16833             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 2), INPUTSIZE);
   16834             script.forEach_testConvertUlong2Short2Ulong2(inV, out);
   16835             verifyResultsConvertShort2Ulong2(inV, out, false);
   16836         } catch (Exception e) {
   16837             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong2Short2Ulong2: " + e.toString());
   16838         }
   16839         try {
   16840             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 2), INPUTSIZE);
   16841             scriptRelaxed.forEach_testConvertUlong2Short2Ulong2(inV, out);
   16842             verifyResultsConvertShort2Ulong2(inV, out, true);
   16843         } catch (Exception e) {
   16844             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong2Short2Ulong2: " + e.toString());
   16845         }
   16846     }
   16847 
   16848     private void verifyResultsConvertShort2Ulong2(Allocation inV, Allocation out, boolean relaxed) {
   16849         short[] arrayInV = new short[INPUTSIZE * 2];
   16850         inV.copyTo(arrayInV);
   16851         long[] arrayOut = new long[INPUTSIZE * 2];
   16852         out.copyTo(arrayOut);
   16853         for (int i = 0; i < INPUTSIZE; i++) {
   16854             for (int j = 0; j < 2 ; j++) {
   16855                 // Extract the inputs.
   16856                 ArgumentsShortUlong args = new ArgumentsShortUlong();
   16857                 args.inV = arrayInV[i * 2 + j];
   16858                 // Figure out what the outputs should have been.
   16859                 CoreMathVerifier.computeConvert(args);
   16860                 // Validate the outputs.
   16861                 boolean valid = true;
   16862                 if (args.out != arrayOut[i * 2 + j]) {
   16863                     valid = false;
   16864                 }
   16865                 if (!valid) {
   16866                     StringBuilder message = new StringBuilder();
   16867                     message.append("Input inV: ");
   16868                     message.append(String.format("%d", args.inV));
   16869                     message.append("\n");
   16870                     message.append("Expected output out: ");
   16871                     message.append(String.format("0x%x", args.out));
   16872                     message.append("\n");
   16873                     message.append("Actual   output out: ");
   16874                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   16875                     if (args.out != arrayOut[i * 2 + j]) {
   16876                         message.append(" FAIL");
   16877                     }
   16878                     message.append("\n");
   16879                     assertTrue("Incorrect output for checkConvertShort2Ulong2" +
   16880                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   16881                 }
   16882             }
   16883         }
   16884     }
   16885 
   16886     private void checkConvertShort3Ulong3() {
   16887         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_16, 3, 0x94cc80def5e21781l, false, 15);
   16888         try {
   16889             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 3), INPUTSIZE);
   16890             script.forEach_testConvertUlong3Short3Ulong3(inV, out);
   16891             verifyResultsConvertShort3Ulong3(inV, out, false);
   16892         } catch (Exception e) {
   16893             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong3Short3Ulong3: " + e.toString());
   16894         }
   16895         try {
   16896             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 3), INPUTSIZE);
   16897             scriptRelaxed.forEach_testConvertUlong3Short3Ulong3(inV, out);
   16898             verifyResultsConvertShort3Ulong3(inV, out, true);
   16899         } catch (Exception e) {
   16900             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong3Short3Ulong3: " + e.toString());
   16901         }
   16902     }
   16903 
   16904     private void verifyResultsConvertShort3Ulong3(Allocation inV, Allocation out, boolean relaxed) {
   16905         short[] arrayInV = new short[INPUTSIZE * 4];
   16906         inV.copyTo(arrayInV);
   16907         long[] arrayOut = new long[INPUTSIZE * 4];
   16908         out.copyTo(arrayOut);
   16909         for (int i = 0; i < INPUTSIZE; i++) {
   16910             for (int j = 0; j < 3 ; j++) {
   16911                 // Extract the inputs.
   16912                 ArgumentsShortUlong args = new ArgumentsShortUlong();
   16913                 args.inV = arrayInV[i * 4 + j];
   16914                 // Figure out what the outputs should have been.
   16915                 CoreMathVerifier.computeConvert(args);
   16916                 // Validate the outputs.
   16917                 boolean valid = true;
   16918                 if (args.out != arrayOut[i * 4 + j]) {
   16919                     valid = false;
   16920                 }
   16921                 if (!valid) {
   16922                     StringBuilder message = new StringBuilder();
   16923                     message.append("Input inV: ");
   16924                     message.append(String.format("%d", args.inV));
   16925                     message.append("\n");
   16926                     message.append("Expected output out: ");
   16927                     message.append(String.format("0x%x", args.out));
   16928                     message.append("\n");
   16929                     message.append("Actual   output out: ");
   16930                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   16931                     if (args.out != arrayOut[i * 4 + j]) {
   16932                         message.append(" FAIL");
   16933                     }
   16934                     message.append("\n");
   16935                     assertTrue("Incorrect output for checkConvertShort3Ulong3" +
   16936                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   16937                 }
   16938             }
   16939         }
   16940     }
   16941 
   16942     private void checkConvertShort4Ulong4() {
   16943         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_16, 4, 0x94ce49f9ebfd385fl, false, 15);
   16944         try {
   16945             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 4), INPUTSIZE);
   16946             script.forEach_testConvertUlong4Short4Ulong4(inV, out);
   16947             verifyResultsConvertShort4Ulong4(inV, out, false);
   16948         } catch (Exception e) {
   16949             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong4Short4Ulong4: " + e.toString());
   16950         }
   16951         try {
   16952             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 4), INPUTSIZE);
   16953             scriptRelaxed.forEach_testConvertUlong4Short4Ulong4(inV, out);
   16954             verifyResultsConvertShort4Ulong4(inV, out, true);
   16955         } catch (Exception e) {
   16956             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong4Short4Ulong4: " + e.toString());
   16957         }
   16958     }
   16959 
   16960     private void verifyResultsConvertShort4Ulong4(Allocation inV, Allocation out, boolean relaxed) {
   16961         short[] arrayInV = new short[INPUTSIZE * 4];
   16962         inV.copyTo(arrayInV);
   16963         long[] arrayOut = new long[INPUTSIZE * 4];
   16964         out.copyTo(arrayOut);
   16965         for (int i = 0; i < INPUTSIZE; i++) {
   16966             for (int j = 0; j < 4 ; j++) {
   16967                 // Extract the inputs.
   16968                 ArgumentsShortUlong args = new ArgumentsShortUlong();
   16969                 args.inV = arrayInV[i * 4 + j];
   16970                 // Figure out what the outputs should have been.
   16971                 CoreMathVerifier.computeConvert(args);
   16972                 // Validate the outputs.
   16973                 boolean valid = true;
   16974                 if (args.out != arrayOut[i * 4 + j]) {
   16975                     valid = false;
   16976                 }
   16977                 if (!valid) {
   16978                     StringBuilder message = new StringBuilder();
   16979                     message.append("Input inV: ");
   16980                     message.append(String.format("%d", args.inV));
   16981                     message.append("\n");
   16982                     message.append("Expected output out: ");
   16983                     message.append(String.format("0x%x", args.out));
   16984                     message.append("\n");
   16985                     message.append("Actual   output out: ");
   16986                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   16987                     if (args.out != arrayOut[i * 4 + j]) {
   16988                         message.append(" FAIL");
   16989                     }
   16990                     message.append("\n");
   16991                     assertTrue("Incorrect output for checkConvertShort4Ulong4" +
   16992                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   16993                 }
   16994             }
   16995         }
   16996     }
   16997 
   16998     public class ArgumentsUshortUlong {
   16999         public short inV;
   17000         public long out;
   17001     }
   17002 
   17003     private void checkConvertUshort2Ulong2() {
   17004         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_16, 2, 0xc36a190b2d13465cl, false, 16);
   17005         try {
   17006             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 2), INPUTSIZE);
   17007             script.forEach_testConvertUlong2Ushort2Ulong2(inV, out);
   17008             verifyResultsConvertUshort2Ulong2(inV, out, false);
   17009         } catch (Exception e) {
   17010             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong2Ushort2Ulong2: " + e.toString());
   17011         }
   17012         try {
   17013             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 2), INPUTSIZE);
   17014             scriptRelaxed.forEach_testConvertUlong2Ushort2Ulong2(inV, out);
   17015             verifyResultsConvertUshort2Ulong2(inV, out, true);
   17016         } catch (Exception e) {
   17017             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong2Ushort2Ulong2: " + e.toString());
   17018         }
   17019     }
   17020 
   17021     private void verifyResultsConvertUshort2Ulong2(Allocation inV, Allocation out, boolean relaxed) {
   17022         short[] arrayInV = new short[INPUTSIZE * 2];
   17023         inV.copyTo(arrayInV);
   17024         long[] arrayOut = new long[INPUTSIZE * 2];
   17025         out.copyTo(arrayOut);
   17026         for (int i = 0; i < INPUTSIZE; i++) {
   17027             for (int j = 0; j < 2 ; j++) {
   17028                 // Extract the inputs.
   17029                 ArgumentsUshortUlong args = new ArgumentsUshortUlong();
   17030                 args.inV = arrayInV[i * 2 + j];
   17031                 // Figure out what the outputs should have been.
   17032                 CoreMathVerifier.computeConvert(args);
   17033                 // Validate the outputs.
   17034                 boolean valid = true;
   17035                 if (args.out != arrayOut[i * 2 + j]) {
   17036                     valid = false;
   17037                 }
   17038                 if (!valid) {
   17039                     StringBuilder message = new StringBuilder();
   17040                     message.append("Input inV: ");
   17041                     message.append(String.format("0x%x", args.inV));
   17042                     message.append("\n");
   17043                     message.append("Expected output out: ");
   17044                     message.append(String.format("0x%x", args.out));
   17045                     message.append("\n");
   17046                     message.append("Actual   output out: ");
   17047                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   17048                     if (args.out != arrayOut[i * 2 + j]) {
   17049                         message.append(" FAIL");
   17050                     }
   17051                     message.append("\n");
   17052                     assertTrue("Incorrect output for checkConvertUshort2Ulong2" +
   17053                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   17054                 }
   17055             }
   17056         }
   17057     }
   17058 
   17059     private void checkConvertUshort3Ulong3() {
   17060         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_16, 3, 0xc36be226232e673al, false, 16);
   17061         try {
   17062             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 3), INPUTSIZE);
   17063             script.forEach_testConvertUlong3Ushort3Ulong3(inV, out);
   17064             verifyResultsConvertUshort3Ulong3(inV, out, false);
   17065         } catch (Exception e) {
   17066             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong3Ushort3Ulong3: " + e.toString());
   17067         }
   17068         try {
   17069             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 3), INPUTSIZE);
   17070             scriptRelaxed.forEach_testConvertUlong3Ushort3Ulong3(inV, out);
   17071             verifyResultsConvertUshort3Ulong3(inV, out, true);
   17072         } catch (Exception e) {
   17073             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong3Ushort3Ulong3: " + e.toString());
   17074         }
   17075     }
   17076 
   17077     private void verifyResultsConvertUshort3Ulong3(Allocation inV, Allocation out, boolean relaxed) {
   17078         short[] arrayInV = new short[INPUTSIZE * 4];
   17079         inV.copyTo(arrayInV);
   17080         long[] arrayOut = new long[INPUTSIZE * 4];
   17081         out.copyTo(arrayOut);
   17082         for (int i = 0; i < INPUTSIZE; i++) {
   17083             for (int j = 0; j < 3 ; j++) {
   17084                 // Extract the inputs.
   17085                 ArgumentsUshortUlong args = new ArgumentsUshortUlong();
   17086                 args.inV = arrayInV[i * 4 + j];
   17087                 // Figure out what the outputs should have been.
   17088                 CoreMathVerifier.computeConvert(args);
   17089                 // Validate the outputs.
   17090                 boolean valid = true;
   17091                 if (args.out != arrayOut[i * 4 + j]) {
   17092                     valid = false;
   17093                 }
   17094                 if (!valid) {
   17095                     StringBuilder message = new StringBuilder();
   17096                     message.append("Input inV: ");
   17097                     message.append(String.format("0x%x", args.inV));
   17098                     message.append("\n");
   17099                     message.append("Expected output out: ");
   17100                     message.append(String.format("0x%x", args.out));
   17101                     message.append("\n");
   17102                     message.append("Actual   output out: ");
   17103                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   17104                     if (args.out != arrayOut[i * 4 + j]) {
   17105                         message.append(" FAIL");
   17106                     }
   17107                     message.append("\n");
   17108                     assertTrue("Incorrect output for checkConvertUshort3Ulong3" +
   17109                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   17110                 }
   17111             }
   17112         }
   17113     }
   17114 
   17115     private void checkConvertUshort4Ulong4() {
   17116         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_16, 4, 0xc36dab4119498818l, false, 16);
   17117         try {
   17118             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 4), INPUTSIZE);
   17119             script.forEach_testConvertUlong4Ushort4Ulong4(inV, out);
   17120             verifyResultsConvertUshort4Ulong4(inV, out, false);
   17121         } catch (Exception e) {
   17122             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong4Ushort4Ulong4: " + e.toString());
   17123         }
   17124         try {
   17125             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 4), INPUTSIZE);
   17126             scriptRelaxed.forEach_testConvertUlong4Ushort4Ulong4(inV, out);
   17127             verifyResultsConvertUshort4Ulong4(inV, out, true);
   17128         } catch (Exception e) {
   17129             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong4Ushort4Ulong4: " + e.toString());
   17130         }
   17131     }
   17132 
   17133     private void verifyResultsConvertUshort4Ulong4(Allocation inV, Allocation out, boolean relaxed) {
   17134         short[] arrayInV = new short[INPUTSIZE * 4];
   17135         inV.copyTo(arrayInV);
   17136         long[] arrayOut = new long[INPUTSIZE * 4];
   17137         out.copyTo(arrayOut);
   17138         for (int i = 0; i < INPUTSIZE; i++) {
   17139             for (int j = 0; j < 4 ; j++) {
   17140                 // Extract the inputs.
   17141                 ArgumentsUshortUlong args = new ArgumentsUshortUlong();
   17142                 args.inV = arrayInV[i * 4 + j];
   17143                 // Figure out what the outputs should have been.
   17144                 CoreMathVerifier.computeConvert(args);
   17145                 // Validate the outputs.
   17146                 boolean valid = true;
   17147                 if (args.out != arrayOut[i * 4 + j]) {
   17148                     valid = false;
   17149                 }
   17150                 if (!valid) {
   17151                     StringBuilder message = new StringBuilder();
   17152                     message.append("Input inV: ");
   17153                     message.append(String.format("0x%x", args.inV));
   17154                     message.append("\n");
   17155                     message.append("Expected output out: ");
   17156                     message.append(String.format("0x%x", args.out));
   17157                     message.append("\n");
   17158                     message.append("Actual   output out: ");
   17159                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   17160                     if (args.out != arrayOut[i * 4 + j]) {
   17161                         message.append(" FAIL");
   17162                     }
   17163                     message.append("\n");
   17164                     assertTrue("Incorrect output for checkConvertUshort4Ulong4" +
   17165                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   17166                 }
   17167             }
   17168         }
   17169     }
   17170 
   17171     public class ArgumentsIntUlong {
   17172         public int inV;
   17173         public long out;
   17174     }
   17175 
   17176     private void checkConvertInt2Ulong2() {
   17177         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_32, 2, 0x2a53676074a824f6l, false, 31);
   17178         try {
   17179             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 2), INPUTSIZE);
   17180             script.forEach_testConvertUlong2Int2Ulong2(inV, out);
   17181             verifyResultsConvertInt2Ulong2(inV, out, false);
   17182         } catch (Exception e) {
   17183             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong2Int2Ulong2: " + e.toString());
   17184         }
   17185         try {
   17186             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 2), INPUTSIZE);
   17187             scriptRelaxed.forEach_testConvertUlong2Int2Ulong2(inV, out);
   17188             verifyResultsConvertInt2Ulong2(inV, out, true);
   17189         } catch (Exception e) {
   17190             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong2Int2Ulong2: " + e.toString());
   17191         }
   17192     }
   17193 
   17194     private void verifyResultsConvertInt2Ulong2(Allocation inV, Allocation out, boolean relaxed) {
   17195         int[] arrayInV = new int[INPUTSIZE * 2];
   17196         inV.copyTo(arrayInV);
   17197         long[] arrayOut = new long[INPUTSIZE * 2];
   17198         out.copyTo(arrayOut);
   17199         for (int i = 0; i < INPUTSIZE; i++) {
   17200             for (int j = 0; j < 2 ; j++) {
   17201                 // Extract the inputs.
   17202                 ArgumentsIntUlong args = new ArgumentsIntUlong();
   17203                 args.inV = arrayInV[i * 2 + j];
   17204                 // Figure out what the outputs should have been.
   17205                 CoreMathVerifier.computeConvert(args);
   17206                 // Validate the outputs.
   17207                 boolean valid = true;
   17208                 if (args.out != arrayOut[i * 2 + j]) {
   17209                     valid = false;
   17210                 }
   17211                 if (!valid) {
   17212                     StringBuilder message = new StringBuilder();
   17213                     message.append("Input inV: ");
   17214                     message.append(String.format("%d", args.inV));
   17215                     message.append("\n");
   17216                     message.append("Expected output out: ");
   17217                     message.append(String.format("0x%x", args.out));
   17218                     message.append("\n");
   17219                     message.append("Actual   output out: ");
   17220                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   17221                     if (args.out != arrayOut[i * 2 + j]) {
   17222                         message.append(" FAIL");
   17223                     }
   17224                     message.append("\n");
   17225                     assertTrue("Incorrect output for checkConvertInt2Ulong2" +
   17226                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   17227                 }
   17228             }
   17229         }
   17230     }
   17231 
   17232     private void checkConvertInt3Ulong3() {
   17233         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_32, 3, 0x2a55307b6ac345d4l, false, 31);
   17234         try {
   17235             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 3), INPUTSIZE);
   17236             script.forEach_testConvertUlong3Int3Ulong3(inV, out);
   17237             verifyResultsConvertInt3Ulong3(inV, out, false);
   17238         } catch (Exception e) {
   17239             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong3Int3Ulong3: " + e.toString());
   17240         }
   17241         try {
   17242             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 3), INPUTSIZE);
   17243             scriptRelaxed.forEach_testConvertUlong3Int3Ulong3(inV, out);
   17244             verifyResultsConvertInt3Ulong3(inV, out, true);
   17245         } catch (Exception e) {
   17246             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong3Int3Ulong3: " + e.toString());
   17247         }
   17248     }
   17249 
   17250     private void verifyResultsConvertInt3Ulong3(Allocation inV, Allocation out, boolean relaxed) {
   17251         int[] arrayInV = new int[INPUTSIZE * 4];
   17252         inV.copyTo(arrayInV);
   17253         long[] arrayOut = new long[INPUTSIZE * 4];
   17254         out.copyTo(arrayOut);
   17255         for (int i = 0; i < INPUTSIZE; i++) {
   17256             for (int j = 0; j < 3 ; j++) {
   17257                 // Extract the inputs.
   17258                 ArgumentsIntUlong args = new ArgumentsIntUlong();
   17259                 args.inV = arrayInV[i * 4 + j];
   17260                 // Figure out what the outputs should have been.
   17261                 CoreMathVerifier.computeConvert(args);
   17262                 // Validate the outputs.
   17263                 boolean valid = true;
   17264                 if (args.out != arrayOut[i * 4 + j]) {
   17265                     valid = false;
   17266                 }
   17267                 if (!valid) {
   17268                     StringBuilder message = new StringBuilder();
   17269                     message.append("Input inV: ");
   17270                     message.append(String.format("%d", args.inV));
   17271                     message.append("\n");
   17272                     message.append("Expected output out: ");
   17273                     message.append(String.format("0x%x", args.out));
   17274                     message.append("\n");
   17275                     message.append("Actual   output out: ");
   17276                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   17277                     if (args.out != arrayOut[i * 4 + j]) {
   17278                         message.append(" FAIL");
   17279                     }
   17280                     message.append("\n");
   17281                     assertTrue("Incorrect output for checkConvertInt3Ulong3" +
   17282                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   17283                 }
   17284             }
   17285         }
   17286     }
   17287 
   17288     private void checkConvertInt4Ulong4() {
   17289         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.SIGNED_32, 4, 0x2a56f99660de66b2l, false, 31);
   17290         try {
   17291             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 4), INPUTSIZE);
   17292             script.forEach_testConvertUlong4Int4Ulong4(inV, out);
   17293             verifyResultsConvertInt4Ulong4(inV, out, false);
   17294         } catch (Exception e) {
   17295             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong4Int4Ulong4: " + e.toString());
   17296         }
   17297         try {
   17298             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 4), INPUTSIZE);
   17299             scriptRelaxed.forEach_testConvertUlong4Int4Ulong4(inV, out);
   17300             verifyResultsConvertInt4Ulong4(inV, out, true);
   17301         } catch (Exception e) {
   17302             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong4Int4Ulong4: " + e.toString());
   17303         }
   17304     }
   17305 
   17306     private void verifyResultsConvertInt4Ulong4(Allocation inV, Allocation out, boolean relaxed) {
   17307         int[] arrayInV = new int[INPUTSIZE * 4];
   17308         inV.copyTo(arrayInV);
   17309         long[] arrayOut = new long[INPUTSIZE * 4];
   17310         out.copyTo(arrayOut);
   17311         for (int i = 0; i < INPUTSIZE; i++) {
   17312             for (int j = 0; j < 4 ; j++) {
   17313                 // Extract the inputs.
   17314                 ArgumentsIntUlong args = new ArgumentsIntUlong();
   17315                 args.inV = arrayInV[i * 4 + j];
   17316                 // Figure out what the outputs should have been.
   17317                 CoreMathVerifier.computeConvert(args);
   17318                 // Validate the outputs.
   17319                 boolean valid = true;
   17320                 if (args.out != arrayOut[i * 4 + j]) {
   17321                     valid = false;
   17322                 }
   17323                 if (!valid) {
   17324                     StringBuilder message = new StringBuilder();
   17325                     message.append("Input inV: ");
   17326                     message.append(String.format("%d", args.inV));
   17327                     message.append("\n");
   17328                     message.append("Expected output out: ");
   17329                     message.append(String.format("0x%x", args.out));
   17330                     message.append("\n");
   17331                     message.append("Actual   output out: ");
   17332                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   17333                     if (args.out != arrayOut[i * 4 + j]) {
   17334                         message.append(" FAIL");
   17335                     }
   17336                     message.append("\n");
   17337                     assertTrue("Incorrect output for checkConvertInt4Ulong4" +
   17338                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   17339                 }
   17340             }
   17341         }
   17342     }
   17343 
   17344     public class ArgumentsUintUlong {
   17345         public int inV;
   17346         public long out;
   17347     }
   17348 
   17349     private void checkConvertUint2Ulong2() {
   17350         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_32, 2, 0xd1e120ae072a3177l, false, 32);
   17351         try {
   17352             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 2), INPUTSIZE);
   17353             script.forEach_testConvertUlong2Uint2Ulong2(inV, out);
   17354             verifyResultsConvertUint2Ulong2(inV, out, false);
   17355         } catch (Exception e) {
   17356             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong2Uint2Ulong2: " + e.toString());
   17357         }
   17358         try {
   17359             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 2), INPUTSIZE);
   17360             scriptRelaxed.forEach_testConvertUlong2Uint2Ulong2(inV, out);
   17361             verifyResultsConvertUint2Ulong2(inV, out, true);
   17362         } catch (Exception e) {
   17363             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong2Uint2Ulong2: " + e.toString());
   17364         }
   17365     }
   17366 
   17367     private void verifyResultsConvertUint2Ulong2(Allocation inV, Allocation out, boolean relaxed) {
   17368         int[] arrayInV = new int[INPUTSIZE * 2];
   17369         inV.copyTo(arrayInV);
   17370         long[] arrayOut = new long[INPUTSIZE * 2];
   17371         out.copyTo(arrayOut);
   17372         for (int i = 0; i < INPUTSIZE; i++) {
   17373             for (int j = 0; j < 2 ; j++) {
   17374                 // Extract the inputs.
   17375                 ArgumentsUintUlong args = new ArgumentsUintUlong();
   17376                 args.inV = arrayInV[i * 2 + j];
   17377                 // Figure out what the outputs should have been.
   17378                 CoreMathVerifier.computeConvert(args);
   17379                 // Validate the outputs.
   17380                 boolean valid = true;
   17381                 if (args.out != arrayOut[i * 2 + j]) {
   17382                     valid = false;
   17383                 }
   17384                 if (!valid) {
   17385                     StringBuilder message = new StringBuilder();
   17386                     message.append("Input inV: ");
   17387                     message.append(String.format("0x%x", args.inV));
   17388                     message.append("\n");
   17389                     message.append("Expected output out: ");
   17390                     message.append(String.format("0x%x", args.out));
   17391                     message.append("\n");
   17392                     message.append("Actual   output out: ");
   17393                     message.append(String.format("0x%x", arrayOut[i * 2 + j]));
   17394                     if (args.out != arrayOut[i * 2 + j]) {
   17395                         message.append(" FAIL");
   17396                     }
   17397                     message.append("\n");
   17398                     assertTrue("Incorrect output for checkConvertUint2Ulong2" +
   17399                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   17400                 }
   17401             }
   17402         }
   17403     }
   17404 
   17405     private void checkConvertUint3Ulong3() {
   17406         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_32, 3, 0xd1e2e9c8fd455255l, false, 32);
   17407         try {
   17408             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 3), INPUTSIZE);
   17409             script.forEach_testConvertUlong3Uint3Ulong3(inV, out);
   17410             verifyResultsConvertUint3Ulong3(inV, out, false);
   17411         } catch (Exception e) {
   17412             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong3Uint3Ulong3: " + e.toString());
   17413         }
   17414         try {
   17415             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 3), INPUTSIZE);
   17416             scriptRelaxed.forEach_testConvertUlong3Uint3Ulong3(inV, out);
   17417             verifyResultsConvertUint3Ulong3(inV, out, true);
   17418         } catch (Exception e) {
   17419             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong3Uint3Ulong3: " + e.toString());
   17420         }
   17421     }
   17422 
   17423     private void verifyResultsConvertUint3Ulong3(Allocation inV, Allocation out, boolean relaxed) {
   17424         int[] arrayInV = new int[INPUTSIZE * 4];
   17425         inV.copyTo(arrayInV);
   17426         long[] arrayOut = new long[INPUTSIZE * 4];
   17427         out.copyTo(arrayOut);
   17428         for (int i = 0; i < INPUTSIZE; i++) {
   17429             for (int j = 0; j < 3 ; j++) {
   17430                 // Extract the inputs.
   17431                 ArgumentsUintUlong args = new ArgumentsUintUlong();
   17432                 args.inV = arrayInV[i * 4 + j];
   17433                 // Figure out what the outputs should have been.
   17434                 CoreMathVerifier.computeConvert(args);
   17435                 // Validate the outputs.
   17436                 boolean valid = true;
   17437                 if (args.out != arrayOut[i * 4 + j]) {
   17438                     valid = false;
   17439                 }
   17440                 if (!valid) {
   17441                     StringBuilder message = new StringBuilder();
   17442                     message.append("Input inV: ");
   17443                     message.append(String.format("0x%x", args.inV));
   17444                     message.append("\n");
   17445                     message.append("Expected output out: ");
   17446                     message.append(String.format("0x%x", args.out));
   17447                     message.append("\n");
   17448                     message.append("Actual   output out: ");
   17449                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   17450                     if (args.out != arrayOut[i * 4 + j]) {
   17451                         message.append(" FAIL");
   17452                     }
   17453                     message.append("\n");
   17454                     assertTrue("Incorrect output for checkConvertUint3Ulong3" +
   17455                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   17456                 }
   17457             }
   17458         }
   17459     }
   17460 
   17461     private void checkConvertUint4Ulong4() {
   17462         Allocation inV = createRandomIntegerAllocation(mRS, Element.DataType.UNSIGNED_32, 4, 0xd1e4b2e3f3607333l, false, 32);
   17463         try {
   17464             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 4), INPUTSIZE);
   17465             script.forEach_testConvertUlong4Uint4Ulong4(inV, out);
   17466             verifyResultsConvertUint4Ulong4(inV, out, false);
   17467         } catch (Exception e) {
   17468             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong4Uint4Ulong4: " + e.toString());
   17469         }
   17470         try {
   17471             Allocation out = Allocation.createSized(mRS, getElement(mRS, Element.DataType.UNSIGNED_64, 4), INPUTSIZE);
   17472             scriptRelaxed.forEach_testConvertUlong4Uint4Ulong4(inV, out);
   17473             verifyResultsConvertUint4Ulong4(inV, out, true);
   17474         } catch (Exception e) {
   17475             throw new RSRuntimeException("RenderScript. Can't invoke forEach_testConvertUlong4Uint4Ulong4: " + e.toString());
   17476         }
   17477     }
   17478 
   17479     private void verifyResultsConvertUint4Ulong4(Allocation inV, Allocation out, boolean relaxed) {
   17480         int[] arrayInV = new int[INPUTSIZE * 4];
   17481         inV.copyTo(arrayInV);
   17482         long[] arrayOut = new long[INPUTSIZE * 4];
   17483         out.copyTo(arrayOut);
   17484         for (int i = 0; i < INPUTSIZE; i++) {
   17485             for (int j = 0; j < 4 ; j++) {
   17486                 // Extract the inputs.
   17487                 ArgumentsUintUlong args = new ArgumentsUintUlong();
   17488                 args.inV = arrayInV[i * 4 + j];
   17489                 // Figure out what the outputs should have been.
   17490                 CoreMathVerifier.computeConvert(args);
   17491                 // Validate the outputs.
   17492                 boolean valid = true;
   17493                 if (args.out != arrayOut[i * 4 + j]) {
   17494                     valid = false;
   17495                 }
   17496                 if (!valid) {
   17497                     StringBuilder message = new StringBuilder();
   17498                     message.append("Input inV: ");
   17499                     message.append(String.format("0x%x", args.inV));
   17500                     message.append("\n");
   17501                     message.append("Expected output out: ");
   17502                     message.append(String.format("0x%x", args.out));
   17503                     message.append("\n");
   17504                     message.append("Actual   output out: ");
   17505                     message.append(String.format("0x%x", arrayOut[i * 4 + j]));
   17506                     if (args.out != arrayOut[i * 4 + j]) {
   17507                         message.append(" FAIL");
   17508                     }
   17509                     message.append("\n");
   17510                     assertTrue("Incorrect output for checkConvertUint4Ulong4" +
   17511                             (relaxed ? "_relaxed" : "") + ":\n" + message.toString(), valid);
   17512                 }
   17513             }
   17514         }
   17515     }
   17516 
   17517     public void testConvert() {
   17518         checkConvertFloat2Float2();
   17519         checkConvertFloat3Float3();
   17520         checkConvertFloat4Float4();
   17521         checkConvertChar2Float2();
   17522         checkConvertChar3Float3();
   17523         checkConvertChar4Float4();
   17524         checkConvertUchar2Float2();
   17525         checkConvertUchar3Float3();
   17526         checkConvertUchar4Float4();
   17527         checkConvertShort2Float2();
   17528         checkConvertShort3Float3();
   17529         checkConvertShort4Float4();
   17530         checkConvertUshort2Float2();
   17531         checkConvertUshort3Float3();
   17532         checkConvertUshort4Float4();
   17533         checkConvertInt2Float2();
   17534         checkConvertInt3Float3();
   17535         checkConvertInt4Float4();
   17536         checkConvertUint2Float2();
   17537         checkConvertUint3Float3();
   17538         checkConvertUint4Float4();
   17539         checkConvertFloat2Char2();
   17540         checkConvertFloat3Char3();
   17541         checkConvertFloat4Char4();
   17542         checkConvertChar2Char2();
   17543         checkConvertChar3Char3();
   17544         checkConvertChar4Char4();
   17545         checkConvertUchar2Char2();
   17546         checkConvertUchar3Char3();
   17547         checkConvertUchar4Char4();
   17548         checkConvertShort2Char2();
   17549         checkConvertShort3Char3();
   17550         checkConvertShort4Char4();
   17551         checkConvertUshort2Char2();
   17552         checkConvertUshort3Char3();
   17553         checkConvertUshort4Char4();
   17554         checkConvertInt2Char2();
   17555         checkConvertInt3Char3();
   17556         checkConvertInt4Char4();
   17557         checkConvertUint2Char2();
   17558         checkConvertUint3Char3();
   17559         checkConvertUint4Char4();
   17560         checkConvertFloat2Uchar2();
   17561         checkConvertFloat3Uchar3();
   17562         checkConvertFloat4Uchar4();
   17563         checkConvertChar2Uchar2();
   17564         checkConvertChar3Uchar3();
   17565         checkConvertChar4Uchar4();
   17566         checkConvertUchar2Uchar2();
   17567         checkConvertUchar3Uchar3();
   17568         checkConvertUchar4Uchar4();
   17569         checkConvertShort2Uchar2();
   17570         checkConvertShort3Uchar3();
   17571         checkConvertShort4Uchar4();
   17572         checkConvertUshort2Uchar2();
   17573         checkConvertUshort3Uchar3();
   17574         checkConvertUshort4Uchar4();
   17575         checkConvertInt2Uchar2();
   17576         checkConvertInt3Uchar3();
   17577         checkConvertInt4Uchar4();
   17578         checkConvertUint2Uchar2();
   17579         checkConvertUint3Uchar3();
   17580         checkConvertUint4Uchar4();
   17581         checkConvertFloat2Short2();
   17582         checkConvertFloat3Short3();
   17583         checkConvertFloat4Short4();
   17584         checkConvertChar2Short2();
   17585         checkConvertChar3Short3();
   17586         checkConvertChar4Short4();
   17587         checkConvertUchar2Short2();
   17588         checkConvertUchar3Short3();
   17589         checkConvertUchar4Short4();
   17590         checkConvertShort2Short2();
   17591         checkConvertShort3Short3();
   17592         checkConvertShort4Short4();
   17593         checkConvertUshort2Short2();
   17594         checkConvertUshort3Short3();
   17595         checkConvertUshort4Short4();
   17596         checkConvertInt2Short2();
   17597         checkConvertInt3Short3();
   17598         checkConvertInt4Short4();
   17599         checkConvertUint2Short2();
   17600         checkConvertUint3Short3();
   17601         checkConvertUint4Short4();
   17602         checkConvertFloat2Ushort2();
   17603         checkConvertFloat3Ushort3();
   17604         checkConvertFloat4Ushort4();
   17605         checkConvertChar2Ushort2();
   17606         checkConvertChar3Ushort3();
   17607         checkConvertChar4Ushort4();
   17608         checkConvertUchar2Ushort2();
   17609         checkConvertUchar3Ushort3();
   17610         checkConvertUchar4Ushort4();
   17611         checkConvertShort2Ushort2();
   17612         checkConvertShort3Ushort3();
   17613         checkConvertShort4Ushort4();
   17614         checkConvertUshort2Ushort2();
   17615         checkConvertUshort3Ushort3();
   17616         checkConvertUshort4Ushort4();
   17617         checkConvertInt2Ushort2();
   17618         checkConvertInt3Ushort3();
   17619         checkConvertInt4Ushort4();
   17620         checkConvertUint2Ushort2();
   17621         checkConvertUint3Ushort3();
   17622         checkConvertUint4Ushort4();
   17623         checkConvertFloat2Int2();
   17624         checkConvertFloat3Int3();
   17625         checkConvertFloat4Int4();
   17626         checkConvertChar2Int2();
   17627         checkConvertChar3Int3();
   17628         checkConvertChar4Int4();
   17629         checkConvertUchar2Int2();
   17630         checkConvertUchar3Int3();
   17631         checkConvertUchar4Int4();
   17632         checkConvertShort2Int2();
   17633         checkConvertShort3Int3();
   17634         checkConvertShort4Int4();
   17635         checkConvertUshort2Int2();
   17636         checkConvertUshort3Int3();
   17637         checkConvertUshort4Int4();
   17638         checkConvertInt2Int2();
   17639         checkConvertInt3Int3();
   17640         checkConvertInt4Int4();
   17641         checkConvertUint2Int2();
   17642         checkConvertUint3Int3();
   17643         checkConvertUint4Int4();
   17644         checkConvertFloat2Uint2();
   17645         checkConvertFloat3Uint3();
   17646         checkConvertFloat4Uint4();
   17647         checkConvertChar2Uint2();
   17648         checkConvertChar3Uint3();
   17649         checkConvertChar4Uint4();
   17650         checkConvertUchar2Uint2();
   17651         checkConvertUchar3Uint3();
   17652         checkConvertUchar4Uint4();
   17653         checkConvertShort2Uint2();
   17654         checkConvertShort3Uint3();
   17655         checkConvertShort4Uint4();
   17656         checkConvertUshort2Uint2();
   17657         checkConvertUshort3Uint3();
   17658         checkConvertUshort4Uint4();
   17659         checkConvertInt2Uint2();
   17660         checkConvertInt3Uint3();
   17661         checkConvertInt4Uint4();
   17662         checkConvertUint2Uint2();
   17663         checkConvertUint3Uint3();
   17664         checkConvertUint4Uint4();
   17665         checkConvertDouble2Double2();
   17666         checkConvertDouble3Double3();
   17667         checkConvertDouble4Double4();
   17668         checkConvertLong2Double2();
   17669         checkConvertLong3Double3();
   17670         checkConvertLong4Double4();
   17671         checkConvertUlong2Double2();
   17672         checkConvertUlong3Double3();
   17673         checkConvertUlong4Double4();
   17674         checkConvertDouble2Long2();
   17675         checkConvertDouble3Long3();
   17676         checkConvertDouble4Long4();
   17677         checkConvertLong2Long2();
   17678         checkConvertLong3Long3();
   17679         checkConvertLong4Long4();
   17680         checkConvertUlong2Long2();
   17681         checkConvertUlong3Long3();
   17682         checkConvertUlong4Long4();
   17683         checkConvertDouble2Ulong2();
   17684         checkConvertDouble3Ulong3();
   17685         checkConvertDouble4Ulong4();
   17686         checkConvertLong2Ulong2();
   17687         checkConvertLong3Ulong3();
   17688         checkConvertLong4Ulong4();
   17689         checkConvertUlong2Ulong2();
   17690         checkConvertUlong3Ulong3();
   17691         checkConvertUlong4Ulong4();
   17692         checkConvertDouble2Float2();
   17693         checkConvertDouble3Float3();
   17694         checkConvertDouble4Float4();
   17695         checkConvertLong2Float2();
   17696         checkConvertLong3Float3();
   17697         checkConvertLong4Float4();
   17698         checkConvertUlong2Float2();
   17699         checkConvertUlong3Float3();
   17700         checkConvertUlong4Float4();
   17701         checkConvertDouble2Char2();
   17702         checkConvertDouble3Char3();
   17703         checkConvertDouble4Char4();
   17704         checkConvertLong2Char2();
   17705         checkConvertLong3Char3();
   17706         checkConvertLong4Char4();
   17707         checkConvertUlong2Char2();
   17708         checkConvertUlong3Char3();
   17709         checkConvertUlong4Char4();
   17710         checkConvertDouble2Uchar2();
   17711         checkConvertDouble3Uchar3();
   17712         checkConvertDouble4Uchar4();
   17713         checkConvertLong2Uchar2();
   17714         checkConvertLong3Uchar3();
   17715         checkConvertLong4Uchar4();
   17716         checkConvertUlong2Uchar2();
   17717         checkConvertUlong3Uchar3();
   17718         checkConvertUlong4Uchar4();
   17719         checkConvertDouble2Short2();
   17720         checkConvertDouble3Short3();
   17721         checkConvertDouble4Short4();
   17722         checkConvertLong2Short2();
   17723         checkConvertLong3Short3();
   17724         checkConvertLong4Short4();
   17725         checkConvertUlong2Short2();
   17726         checkConvertUlong3Short3();
   17727         checkConvertUlong4Short4();
   17728         checkConvertDouble2Ushort2();
   17729         checkConvertDouble3Ushort3();
   17730         checkConvertDouble4Ushort4();
   17731         checkConvertLong2Ushort2();
   17732         checkConvertLong3Ushort3();
   17733         checkConvertLong4Ushort4();
   17734         checkConvertUlong2Ushort2();
   17735         checkConvertUlong3Ushort3();
   17736         checkConvertUlong4Ushort4();
   17737         checkConvertDouble2Int2();
   17738         checkConvertDouble3Int3();
   17739         checkConvertDouble4Int4();
   17740         checkConvertLong2Int2();
   17741         checkConvertLong3Int3();
   17742         checkConvertLong4Int4();
   17743         checkConvertUlong2Int2();
   17744         checkConvertUlong3Int3();
   17745         checkConvertUlong4Int4();
   17746         checkConvertDouble2Uint2();
   17747         checkConvertDouble3Uint3();
   17748         checkConvertDouble4Uint4();
   17749         checkConvertLong2Uint2();
   17750         checkConvertLong3Uint3();
   17751         checkConvertLong4Uint4();
   17752         checkConvertUlong2Uint2();
   17753         checkConvertUlong3Uint3();
   17754         checkConvertUlong4Uint4();
   17755         checkConvertFloat2Double2();
   17756         checkConvertFloat3Double3();
   17757         checkConvertFloat4Double4();
   17758         checkConvertChar2Double2();
   17759         checkConvertChar3Double3();
   17760         checkConvertChar4Double4();
   17761         checkConvertUchar2Double2();
   17762         checkConvertUchar3Double3();
   17763         checkConvertUchar4Double4();
   17764         checkConvertShort2Double2();
   17765         checkConvertShort3Double3();
   17766         checkConvertShort4Double4();
   17767         checkConvertUshort2Double2();
   17768         checkConvertUshort3Double3();
   17769         checkConvertUshort4Double4();
   17770         checkConvertInt2Double2();
   17771         checkConvertInt3Double3();
   17772         checkConvertInt4Double4();
   17773         checkConvertUint2Double2();
   17774         checkConvertUint3Double3();
   17775         checkConvertUint4Double4();
   17776         checkConvertFloat2Long2();
   17777         checkConvertFloat3Long3();
   17778         checkConvertFloat4Long4();
   17779         checkConvertChar2Long2();
   17780         checkConvertChar3Long3();
   17781         checkConvertChar4Long4();
   17782         checkConvertUchar2Long2();
   17783         checkConvertUchar3Long3();
   17784         checkConvertUchar4Long4();
   17785         checkConvertShort2Long2();
   17786         checkConvertShort3Long3();
   17787         checkConvertShort4Long4();
   17788         checkConvertUshort2Long2();
   17789         checkConvertUshort3Long3();
   17790         checkConvertUshort4Long4();
   17791         checkConvertInt2Long2();
   17792         checkConvertInt3Long3();
   17793         checkConvertInt4Long4();
   17794         checkConvertUint2Long2();
   17795         checkConvertUint3Long3();
   17796         checkConvertUint4Long4();
   17797         checkConvertFloat2Ulong2();
   17798         checkConvertFloat3Ulong3();
   17799         checkConvertFloat4Ulong4();
   17800         checkConvertChar2Ulong2();
   17801         checkConvertChar3Ulong3();
   17802         checkConvertChar4Ulong4();
   17803         checkConvertUchar2Ulong2();
   17804         checkConvertUchar3Ulong3();
   17805         checkConvertUchar4Ulong4();
   17806         checkConvertShort2Ulong2();
   17807         checkConvertShort3Ulong3();
   17808         checkConvertShort4Ulong4();
   17809         checkConvertUshort2Ulong2();
   17810         checkConvertUshort3Ulong3();
   17811         checkConvertUshort4Ulong4();
   17812         checkConvertInt2Ulong2();
   17813         checkConvertInt3Ulong3();
   17814         checkConvertInt4Ulong4();
   17815         checkConvertUint2Ulong2();
   17816         checkConvertUint3Ulong3();
   17817         checkConvertUint4Ulong4();
   17818     }
   17819 }
   17820