Mercurial > hg > truffle
annotate graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/DoubleCeilTest.java @ 18205:7f63e7683ee7
Truffle: refactor TraceTruffleCompilationAST into a separate class.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 27 Oct 2014 17:34:08 +0100 |
parents | 64dcb92ee75a |
children |
rev | line source |
---|---|
13308
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1 /* |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
4 * |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
8 * |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
14 * |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
18 * |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
21 * questions. |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
22 */ |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
23 |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
24 package com.oracle.graal.compiler.hsail.test; |
d3b3c6e17d40
HSAIL: added Math intrinsifications
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:
13308
diff
changeset
|
26 import org.junit.*; |
64dcb92ee75a
Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
13308
diff
changeset
|
27 |
13308
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
28 import com.oracle.graal.compiler.hsail.test.infra.*; |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
29 |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
30 /** |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
31 * Tests intrinsic for calls to Math.ceil(). Generates a ceil_f64 instruction. |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
32 */ |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
33 public class DoubleCeilTest extends GraalKernelTester { |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
34 |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
35 static final int num = 40; |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
36 // Output array storing the results. |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
37 @Result protected double[] outArray = new double[num]; |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
38 |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
39 /** |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
40 * The static "kernel" method we will be testing. This method calls Math.ceil() on an element of |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
41 * an input array and writes the result to the corresponding index of an output array. By |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
42 * convention the gid is the last parameter. |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
43 * |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
44 * @param out the output array. |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
45 * @param ina the input array. |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
46 * @param gid the parameter used to index into the input and output arrays. |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
47 */ |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
48 public static void run(double[] out, double[] ina, int gid) { |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
49 out[gid] = Math.ceil(ina[gid]); |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
50 } |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
51 |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
52 /** |
d3b3c6e17d40
HSAIL: added Math intrinsifications
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 |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
54 * code with the result of executing a sequential Java version of this unit test. |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
55 */ |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
56 @Test |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
57 public void test() { |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
58 super.testGeneratedHsail(); |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
59 } |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
60 |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
61 /** |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
62 * Initializes the input and output arrays passed to the run routine. |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
63 * |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
64 * @param in the input array. |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
65 */ |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
66 void setupArrays(double[] in) { |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
67 // Initialize arrays with a mix of positive and negativ values and any corner cases. |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
68 for (int i = 0; i < num; i++) { |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
69 if (i == 0) { |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
70 in[i] = 0.0; |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
71 } else if (i == 1) { |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
72 in[i] = -0.0; |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
73 } else if (i == 2) { |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
74 in[i] = Double.NaN; |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
75 } else if (i == 3) { |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
76 in[i] = Double.NEGATIVE_INFINITY; |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
77 } else if (i == 4) { |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
78 in[i] = Double.POSITIVE_INFINITY; |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
79 } else { |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
80 in[i] = i < num / 2 ? i + 0.5 : -i - 0.5; |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
81 } |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
82 outArray[i] = 0; |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
83 } |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
84 } |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
85 |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
86 /** |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
87 * Dispatches the HSAIL kernel for this test case. |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
88 */ |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
89 @Override |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
90 public void runTest() { |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
91 double[] inArray = new double[num]; |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
92 setupArrays(inArray); |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
93 dispatchMethodKernel(num, outArray, inArray); |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
94 } |
d3b3c6e17d40
HSAIL: added Math intrinsifications
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
95 } |