Mercurial > hg > truffle
comparison graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntBitwiseNotTest.java @ 12651:c73b857b1be9
Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation
Contributed-by: Vasanth Venkatachalam <Vasanth.Venkatachalam@amd.com>
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 01 Nov 2013 12:06:22 +0100 |
parents | |
children | 64dcb92ee75a |
comparison
equal
deleted
inserted
replaced
12650:04c74433529a | 12651:c73b857b1be9 |
---|---|
1 /* | |
2 * Copyright (c) 2009, 2013, 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 package com.oracle.graal.compiler.hsail.test; | |
25 | |
26 import org.junit.Test; | |
27 import com.oracle.graal.compiler.hsail.test.infra.*; | |
28 | |
29 /** | |
30 * Tests bitwise not of an integer. | |
31 */ | |
32 public class IntBitwiseNotTest extends GraalKernelTester { | |
33 | |
34 static final int num = 20; | |
35 // Output array storing the results of the operations. | |
36 @Result protected int[] outArray = new int[num]; | |
37 | |
38 /** | |
39 * The static "kernel" method we will be testing. This method performs a bitwise not operation | |
40 * on an element of an input array and writes the result to the corresponding index of an output | |
41 * array. By convention the gid is the last parameter. | |
42 * | |
43 * @param out the output array | |
44 * @param ina the input array | |
45 * @param gid the parameter used to index into the input and output arrays | |
46 */ | |
47 public static void run(int[] out, int[] ina, int gid) { | |
48 out[gid] = ~(ina[gid]); | |
49 } | |
50 | |
51 /** | |
52 * Tests the HSAIL code generated for this unit test by comparing the result of executing this | |
53 * code with the result of executing a sequential Java version of this unit test. | |
54 */ | |
55 @Test | |
56 public void test() { | |
57 super.testGeneratedHsail(); | |
58 } | |
59 | |
60 /** | |
61 * Initializes the input and output arrays passed to the run routine. | |
62 * | |
63 * @param in the input array | |
64 */ | |
65 void setupArrays(int[] in) { | |
66 for (int i = 0; i < num; i++) { | |
67 in[i] = i < num / 2 ? i : -i; | |
68 outArray[i] = 0; | |
69 } | |
70 } | |
71 | |
72 /** | |
73 * Dispatches the HSAIL kernel for this test case. | |
74 */ | |
75 @Override | |
76 public void runTest() { | |
77 int[] inArray = new int[num]; | |
78 setupArrays(inArray); | |
79 dispatchMethodKernel(num, outArray, inArray); | |
80 } | |
81 } |