Mercurial > hg > truffle
annotate graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntBitwiseShiftLeftTest.java @ 18408:2c3666f44855
Truffle: initial commit of object API implementation
author | Andreas Woess <andreas.woess@jku.at> |
---|---|
date | Tue, 18 Nov 2014 23:19:43 +0100 |
parents | 64dcb92ee75a |
children |
rev | line source |
---|---|
12651
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1 /* |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
4 * |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
8 * |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
14 * |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
18 * |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
21 * questions. |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
22 */ |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
23 |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
24 package com.oracle.graal.compiler.hsail.test; |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
25 |
14991
64dcb92ee75a
Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
12651
diff
changeset
|
26 import org.junit.*; |
12651
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
27 |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
28 import com.oracle.graal.compiler.hsail.test.infra.*; |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
29 |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
30 /** |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
31 * Tests bitwise shift left of int values. Generates an shl_s32 instruction. |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
32 */ |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
33 public class IntBitwiseShiftLeftTest extends GraalKernelTester { |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
34 |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
35 static final int num = 100; |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
36 // Output array containing the results of shift operations. |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
37 @Result protected int[] outArray = new int[num]; |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
38 |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
39 /** |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
40 * The static "kernel" method we will be testing. This method performs a bitwise shift left |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
41 * operation on each element of an input array and writes each result to the corresponding index |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
42 * of an output array. By convention the gid is the last parameter. |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
43 * |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
44 * @param out the output array |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
45 * @param ina the input array |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
46 * @param shiftAmount an array of values used for the shift magnitude |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
47 * @param gid the parameter used to index into the input and output arrays |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
48 */ |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
49 public static void run(int[] out, int[] ina, int[] shiftAmount, int gid) { |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
50 out[gid] = ina[gid] << shiftAmount[gid]; |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
51 } |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
52 |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
53 /** |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
54 * Tests the HSAIL code generated for this unit test by comparing the result of executing this |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
55 * code with the result of executing a sequential Java version of this unit test. |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
56 */ |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
57 @Test |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
58 public void test() { |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
59 super.testGeneratedHsail(); |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
60 } |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
61 |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
62 /** |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
63 * Initializes the arrays passed to the run routine. |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
64 * |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
65 * We do this in such a way that the input arrays contain a mix of negative and positive values. |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
66 * As a result, the work items will exercise all the different combinations for the sign of the |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
67 * value being shifted and the sign of the shift magnitude. |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
68 * |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
69 * @param in the input array |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
70 */ |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
71 void setupArrays(int[] in, int[] shiftAmount) { |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
72 for (int i = 0; i < num; i++) { |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
73 in[i] = i < num / 2 ? i : -i; |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
74 shiftAmount[i] = (i & 1) == 0 ? i : -i; |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
75 outArray[i] = 0; |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
76 } |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
77 } |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
78 |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
79 /** |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
80 * Dispatches the HSAIL kernel for this test case. |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
81 */ |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
82 @Override |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
83 public void runTest() { |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
84 int[] inArray = new int[num]; |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
85 int[] shiftAmount = new int[num]; |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
86 setupArrays(inArray, shiftAmount); |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
87 dispatchMethodKernel(num, outArray, inArray, shiftAmount); |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
88 } |
c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
89 } |