Mercurial > hg > truffle
annotate graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntLookupSwitchTest.java @ 14906:f3a5036cc13c
javadoc fixes
javadoc has become stricter in jdk8
author | Bernhard Urban <bernhard.urban@jku.at> |
---|---|
date | Mon, 31 Mar 2014 20:51:09 +0200 |
parents | f705fc04faa5 |
children | 64dcb92ee75a |
rev | line source |
---|---|
13095
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1 /* |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
4 * |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
8 * |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
14 * |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
18 * |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
21 * questions. |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
22 */ |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
23 |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
24 package com.oracle.graal.compiler.hsail.test; |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
25 |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
26 import org.junit.Test; |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
27 import com.oracle.graal.compiler.hsail.test.infra.*; |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
28 |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
29 /** |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
30 * Tests a switch statement with integer keys. This test exercises the LOOKUPSWITCH Java bytecode |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
31 * instruction. |
14906 | 32 * |
13095
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
33 * The HSAIL code generated for this example is a series of cascading compare and branch |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
34 * instructions for each case of the switch. |
14906 | 35 * |
13095
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
36 * These HSAIL instructions have the following form: |
14906 | 37 * |
38 * | |
13095
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
39 * //Check whether the key matches the key constant of the case. Store the result of the compare (0 |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
40 * or 1) in the control register c0. |
14906 | 41 * |
42 * cmp_eq $c0 <source register>, <key constant for case statement> | |
43 * | |
13095
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
44 * //Branch to the corresponding label of that case if there's a match. |
14906 | 45 * |
46 * cbr $c0 <branch target for that case> | |
13095
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
47 */ |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
48 public class IntLookupSwitchTest extends GraalKernelTester { |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
49 |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
50 static final int num = 20; |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
51 // Output array storing the results of the operations. |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
52 @Result protected int[] outArray = new int[num]; |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
53 |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
54 /** |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
55 * The static "kernel" method we will be testing. This method writes to an output array based on |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
56 * switching on an element of an input array. By convention the gid is the last parameter. |
14906 | 57 * |
13095
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
58 * Note: Because the key constants used in the cases of the switch are sparsely distributed, the |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
59 * Java source compiler compiles this example into the LOOKUPSWITCH bytecode instruction. So |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
60 * this is really a test to see whether the HSAIL backend is appropriately handling the |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
61 * LOOKUPSWITCH bytecode. |
14906 | 62 * |
13095
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
63 * @param out the output array |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
64 * @param ina the input array |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
65 * @param gid the parameter used to index into the input and output arrays |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
66 */ |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
67 public static void run(int[] out, int[] ina, int gid) { |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
68 switch (ina[gid]) { |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
69 case 0: |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
70 out[gid] = ina[gid]; |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
71 break; |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
72 case 1: |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
73 case 2: |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
74 break; |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
75 case 5: |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
76 out[gid] = ina[gid] * ina[gid]; |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
77 break; |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
78 case 10: |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
79 out[gid] = -ina[gid]; |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
80 break; |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
81 case 15: |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
82 out[gid] = ina[gid] - ina[gid]; |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
83 break; |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
84 case 19: |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
85 out[gid] = ina[gid] + ina[gid]; |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
86 break; |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
87 default: |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
88 out[gid] = 9; |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
89 break; |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
90 } |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
91 out[gid] += ina[gid]; |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
92 } |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
93 |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
94 /** |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
95 * Tests the HSAIL code generated for this unit test by comparing the result of executing this |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
96 * code with the result of executing a sequential Java version of this unit test. |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
97 */ |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
98 @Test |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
99 public void test() { |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
100 super.testGeneratedHsail(); |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
101 } |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
102 |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
103 /** |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
104 * Initializes the input and output arrays passed to the run routine. |
14906 | 105 * |
13095
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
106 * @param in the input array |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
107 */ |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
108 void setupArrays(int[] in) { |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
109 for (int i = 0; i < num; i++) { |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
110 in[i] = i < num / 2 ? i : -i; |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
111 outArray[i] = 0; |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
112 } |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
113 } |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
114 |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
115 /** |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
116 * Dispatches the HSAIL kernel for this test case. |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
117 */ |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
118 @Override |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
119 public void runTest() { |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
120 int[] inArray = new int[num]; |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
121 setupArrays(inArray); |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
122 dispatchMethodKernel(num, outArray, inArray); |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
123 } |
f705fc04faa5
HSAIL: adds support for handling Java switch constructs .
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
124 } |