TestLongVect.java revision 12158:0fe2815ffa74
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 * @test
26 * @bug 7192963
27 * @summary assert(_in[req-1] == this) failed: Must pass arg count to 'new'
28 *
29 * @run main/othervm/timeout=400 -Xbatch -Xmx64m compiler.c2.cr7192963.TestLongVect
30 */
31
32package compiler.c2.cr7192963;
33
34public class TestLongVect {
35  private static final int ARRLEN = 997;
36  private static final int ITERS  = 11000;
37  public static void main(String args[]) {
38    System.out.println("Testing Long vectors");
39    int errn = test();
40    if (errn > 0) {
41      System.err.println("FAILED: " + errn + " errors");
42      System.exit(97);
43    }
44    System.out.println("PASSED");
45  }
46
47  static int test() {
48    long[] a0 = new long[ARRLEN];
49    long[] a1 = new long[ARRLEN];
50    // Initialize
51    for (int i=0; i<ARRLEN; i++) {
52      a1[i] = (long)i;
53    }
54    System.out.println("Warmup");
55    for (int i=0; i<ITERS; i++) {
56      test_init(a0);
57      test_addi(a0, a1);
58      test_lsai(a0, a1);
59      test_unrl_init(a0);
60      test_unrl_addi(a0, a1);
61      test_unrl_lsai(a0, a1);
62    }
63    // Test and verify results
64    System.out.println("Verification");
65    int errn = 0;
66    {
67      test_init(a0);
68      for (int i=0; i<ARRLEN; i++) {
69        errn += verify("test_init: ", i, a0[i], (long)(i&3));
70      }
71      test_addi(a0, a1);
72      for (int i=0; i<ARRLEN; i++) {
73        errn += verify("test_addi: ", i, a0[i], (long)(i+(i&3)));
74      }
75      test_lsai(a0, a1);
76      for (int i=0; i<ARRLEN; i++) {
77        errn += verify("test_lsai: ", i, a0[i], (long)(i<<(i&3)));
78      }
79      test_unrl_init(a0);
80      for (int i=0; i<ARRLEN; i++) {
81        errn += verify("test_unrl_init: ", i, a0[i], (long)(i&3));
82      }
83      test_unrl_addi(a0, a1);
84      for (int i=0; i<ARRLEN; i++) {
85        errn += verify("test_unrl_addi: ", i, a0[i], (long)(i+(i&3)));
86      }
87      test_unrl_lsai(a0, a1);
88      for (int i=0; i<ARRLEN; i++) {
89        errn += verify("test_unrl_lsai: ", i, a0[i], (long)(i<<(i&3)));
90      }
91    }
92
93    if (errn > 0)
94      return errn;
95
96    System.out.println("Time");
97    long start, end;
98
99    start = System.currentTimeMillis();
100    for (int i=0; i<ITERS; i++) {
101      test_init(a0);
102    }
103    end = System.currentTimeMillis();
104    System.out.println("test_init: " + (end - start));
105
106    start = System.currentTimeMillis();
107    for (int i=0; i<ITERS; i++) {
108      test_addi(a0, a1);
109    }
110    end = System.currentTimeMillis();
111    System.out.println("test_addi: " + (end - start));
112
113    start = System.currentTimeMillis();
114    for (int i=0; i<ITERS; i++) {
115      test_lsai(a0, a1);
116    }
117    end = System.currentTimeMillis();
118    System.out.println("test_lsai: " + (end - start));
119
120    start = System.currentTimeMillis();
121    for (int i=0; i<ITERS; i++) {
122      test_unrl_init(a0);
123    }
124    end = System.currentTimeMillis();
125    System.out.println("test_unrl_init: " + (end - start));
126
127    start = System.currentTimeMillis();
128    for (int i=0; i<ITERS; i++) {
129      test_unrl_addi(a0, a1);
130    }
131    end = System.currentTimeMillis();
132    System.out.println("test_unrl_addi: " + (end - start));
133
134    start = System.currentTimeMillis();
135    for (int i=0; i<ITERS; i++) {
136      test_unrl_lsai(a0, a1);
137    }
138    end = System.currentTimeMillis();
139    System.out.println("test_unrl_lsai: " + (end - start));
140
141    return errn;
142  }
143
144  static void test_init(long[] a0) {
145    for (int i = 0; i < a0.length; i+=1) {
146      a0[i] = (long)(i&3);
147    }
148  }
149  static void test_addi(long[] a0, long[] a1) {
150    for (int i = 0; i < a0.length; i+=1) {
151      a0[i] = (long)(a1[i]+(i&3));
152    }
153  }
154  static void test_lsai(long[] a0, long[] a1) {
155    for (int i = 0; i < a0.length; i+=1) {
156      a0[i] = (long)(a1[i]<<(i&3));
157    }
158  }
159  static void test_unrl_init(long[] a0) {
160    int i = 0;
161    for (; i < a0.length-4; i+=4) {
162      a0[i+0] = 0;
163      a0[i+1] = 1;
164      a0[i+2] = 2;
165      a0[i+3] = 3;
166    }
167    for (; i < a0.length; i++) {
168      a0[i] = (long)(i&3);
169    }
170  }
171  static void test_unrl_addi(long[] a0, long[] a1) {
172    int i = 0;
173    for (; i < a0.length-4; i+=4) {
174      a0[i+0] = (long)(a1[i+0]+0);
175      a0[i+1] = (long)(a1[i+1]+1);
176      a0[i+2] = (long)(a1[i+2]+2);
177      a0[i+3] = (long)(a1[i+3]+3);
178    }
179    for (; i < a0.length; i++) {
180      a0[i] = (long)(a1[i]+(i&3));
181    }
182  }
183  static void test_unrl_lsai(long[] a0, long[] a1) {
184    int i = 0;
185    for (; i < a0.length-4; i+=4) {
186      a0[i+0] = (long)(a1[i+0]<<0);
187      a0[i+1] = (long)(a1[i+1]<<1);
188      a0[i+2] = (long)(a1[i+2]<<2);
189      a0[i+3] = (long)(a1[i+3]<<3);
190    }
191    for (; i < a0.length; i++) {
192      a0[i] = (long)(a1[i]<<(i&3));
193    }
194  }
195
196  static int verify(String text, int i, long elem, long val) {
197    if (elem != val) {
198      System.err.println(text + "[" + i + "] = " + elem + " != " + val);
199      return 1;
200    }
201    return 0;
202  }
203}
204
205