1 /*
   2  * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 /**
  26  * @test
  27  * @bug 7192963
  28  * @summary assert(_in[req-1] == this) failed: Must pass arg count to 'new'
  29  *
  30  * @run main/othervm/timeout=400 -Xbatch -Xmx64m TestByteVect
  31  */
  32 
  33 public class TestByteVect {
  34   private static final int ARRLEN = 997;
  35   private static final int ITERS  = 11000;
  36   public static void main(String args[]) {
  37     System.out.println("Testing Byte vectors");
  38     int errn = test();
  39     if (errn > 0) {
  40       System.err.println("FAILED: " + errn + " errors");
  41       System.exit(97);
  42     }
  43     System.out.println("PASSED");
  44   }
  45 
  46   static int test() {
  47     byte[] a0 = new byte[ARRLEN];
  48     byte[] a1 = new byte[ARRLEN];
  49     // Initialize
  50     for (int i=0; i<ARRLEN; i++) {
  51       a1[i] = (byte)i;
  52     }
  53     System.out.println("Warmup");
  54     for (int i=0; i<ITERS; i++) {
  55       test_init(a0);
  56       test_addi(a0, a1);
  57       test_lsai(a0, a1);
  58       test_unrl_init(a0);
  59       test_unrl_addi(a0, a1);
  60       test_unrl_lsai(a0, a1);
  61     }
  62     // Test and verify results
  63     System.out.println("Verification");
  64     int errn = 0;
  65     {
  66       test_init(a0);
  67       for (int i=0; i<ARRLEN; i++) {
  68         errn += verify("test_init: ", i, a0[i], (byte)(i&3));
  69       }
  70       test_addi(a0, a1);
  71       for (int i=0; i<ARRLEN; i++) {
  72         errn += verify("test_addi: ", i, a0[i], (byte)(i+(i&3)));
  73       }
  74       test_lsai(a0, a1);
  75       for (int i=0; i<ARRLEN; i++) {
  76         errn += verify("test_lsai: ", i, a0[i], (byte)(i<<(i&3)));
  77       }
  78       test_unrl_init(a0);
  79       for (int i=0; i<ARRLEN; i++) {
  80         errn += verify("test_unrl_init: ", i, a0[i], (byte)(i&3));
  81       }
  82       test_unrl_addi(a0, a1);
  83       for (int i=0; i<ARRLEN; i++) {
  84         errn += verify("test_unrl_addi: ", i, a0[i], (byte)(i+(i&3)));
  85       }
  86       test_unrl_lsai(a0, a1);
  87       for (int i=0; i<ARRLEN; i++) {
  88         errn += verify("test_unrl_lsai: ", i, a0[i], (byte)(i<<(i&3)));
  89       }
  90     }
  91 
  92     if (errn > 0)
  93       return errn;
  94 
  95     System.out.println("Time");
  96     long start, end;
  97 
  98     start = System.currentTimeMillis();
  99     for (int i=0; i<ITERS; i++) {
 100       test_init(a0);
 101     }
 102     end = System.currentTimeMillis();
 103     System.out.println("test_init: " + (end - start));
 104 
 105     start = System.currentTimeMillis();
 106     for (int i=0; i<ITERS; i++) {
 107       test_addi(a0, a1);
 108     }
 109     end = System.currentTimeMillis();
 110     System.out.println("test_addi: " + (end - start));
 111 
 112     start = System.currentTimeMillis();
 113     for (int i=0; i<ITERS; i++) {
 114       test_lsai(a0, a1);
 115     }
 116     end = System.currentTimeMillis();
 117     System.out.println("test_lsai: " + (end - start));
 118 
 119     start = System.currentTimeMillis();
 120     for (int i=0; i<ITERS; i++) {
 121       test_unrl_init(a0);
 122     }
 123     end = System.currentTimeMillis();
 124     System.out.println("test_unrl_init: " + (end - start));
 125 
 126     start = System.currentTimeMillis();
 127     for (int i=0; i<ITERS; i++) {
 128       test_unrl_addi(a0, a1);
 129     }
 130     end = System.currentTimeMillis();
 131     System.out.println("test_unrl_addi: " + (end - start));
 132 
 133     start = System.currentTimeMillis();
 134     for (int i=0; i<ITERS; i++) {
 135       test_unrl_lsai(a0, a1);
 136     }
 137     end = System.currentTimeMillis();
 138     System.out.println("test_unrl_lsai: " + (end - start));
 139 
 140     return errn;
 141   }
 142 
 143   static void test_init(byte[] a0) {
 144     for (int i = 0; i < a0.length; i+=1) {
 145       a0[i] = (byte)(i&3);
 146     }
 147   }
 148   static void test_addi(byte[] a0, byte[] a1) {
 149     for (int i = 0; i < a0.length; i+=1) {
 150       a0[i] = (byte)(a1[i]+(i&3));
 151     }
 152   }
 153   static void test_lsai(byte[] a0, byte[] a1) {
 154     for (int i = 0; i < a0.length; i+=1) {
 155       a0[i] = (byte)(a1[i]<<(i&3));
 156     }
 157   }
 158   static void test_unrl_init(byte[] a0) {
 159     int i = 0;
 160     for (; i < a0.length-4; i+=4) {
 161       a0[i+0] = 0;
 162       a0[i+1] = 1;
 163       a0[i+2] = 2;
 164       a0[i+3] = 3;
 165     }
 166     for (; i < a0.length; i++) {
 167       a0[i] = (byte)(i&3);
 168     }
 169   }
 170   static void test_unrl_addi(byte[] a0, byte[] a1) {
 171     int i = 0;
 172     for (; i < a0.length-4; i+=4) {
 173       a0[i+0] = (byte)(a1[i+0]+0);
 174       a0[i+1] = (byte)(a1[i+1]+1);
 175       a0[i+2] = (byte)(a1[i+2]+2);
 176       a0[i+3] = (byte)(a1[i+3]+3);
 177     }
 178     for (; i < a0.length; i++) {
 179       a0[i] = (byte)(a1[i]+(i&3));
 180     }
 181   }
 182   static void test_unrl_lsai(byte[] a0, byte[] a1) {
 183     int i = 0;
 184     for (; i < a0.length-4; i+=4) {
 185       a0[i+0] = (byte)(a1[i+0]<<0);
 186       a0[i+1] = (byte)(a1[i+1]<<1);
 187       a0[i+2] = (byte)(a1[i+2]<<2);
 188       a0[i+3] = (byte)(a1[i+3]<<3);
 189     }
 190     for (; i < a0.length; i++) {
 191       a0[i] = (byte)(a1[i]<<(i&3));
 192     }
 193   }
 194 
 195   static int verify(String text, int i, byte elem, byte val) {
 196     if (elem != val) {
 197       System.err.println(text + "[" + i + "] = " + elem + " != " + val);
 198       return 1;
 199     }
 200     return 0;
 201   }
 202 }
 203