annotate graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongBitwiseShiftRightTest.java @ 13880:4c2f5b7deb6c

Added tag graal-0.1 for changeset b124e22eb772
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Wed, 05 Feb 2014 14:59:55 +0100
parents c73b857b1be9
children 64dcb92ee75a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
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
26 import org.junit.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
27 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
28
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 * Tests bitwise right shift of long values. Generates an shr_s64 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
31 */
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 public class LongBitwiseShiftRightTest 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
33
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 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
35 // 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
36 @Result protected long[] outArray = new long[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
37
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 * The static "kernel" method we will be testing. This method performs a bitwise shift righj
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 * operation on an element of an input array and writes the result to the corresponding index of
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 * 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
42 *
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 * @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
44 * @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
45 * @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
46 * @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
47 */
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 public static void run(long[] out, long[] 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
49 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
50 }
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 * 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
54 * 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
55 */
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 @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
57 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
58 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
59 }
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 * 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
63 *
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 * 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
65 * 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
66 * 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
67 *
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 * @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
69 */
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 void setupArrays(long[] 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
71 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
72 /**
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 * Fill lower half of in[] with positive numbers and upper half with negative numbers.
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 */
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 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
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 * Fill shiftAmount[] so that even elements are positive and odd elements are negative.
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 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
80 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
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 }
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
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 /**
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 * 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
86 */
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 @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
88 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
89 long[] inArray = new long[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
90 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
91 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
92 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
93 }
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
94 }