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