annotate graal/com.oracle.graal.nodes.test/src/com/oracle/graal/nodes/test/NegateNodeCanonicalizationTest.java @ 14630:51d774eb5e14

update changelog
author Andreas Woess <andreas.woess@jku.at>
date Thu, 20 Mar 2014 01:45:36 +0100
parents 99ca997f4eae
children 06c15e88d383
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12460
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
1 /*
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
4 *
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
7 * published by the Free Software Foundation.
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
8 *
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
13 * accompanied this code).
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
14 *
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
18 *
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
21 * questions.
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
22 */
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
23 package com.oracle.graal.nodes.test;
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
24
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
25 import static org.junit.Assert.*;
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
26
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
27 import org.junit.*;
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
28
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
29 import com.oracle.graal.api.meta.*;
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
30 import com.oracle.graal.nodes.*;
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
31 import com.oracle.graal.nodes.calc.*;
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
32
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
33 /**
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
34 * This class tests that the canonicalization for constant negate nodes cover all cases.
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
35 */
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
36 public class NegateNodeCanonicalizationTest {
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
37
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
38 private StructuredGraph graph;
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
39
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
40 @Before
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
41 public void before() {
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
42 graph = new StructuredGraph();
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
43 }
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
44
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
45 @Test
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
46 public void testByte() {
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
47 byte[] a = new byte[]{Byte.MIN_VALUE, Byte.MIN_VALUE + 1, -1, 0, 1, Byte.MAX_VALUE - 1, Byte.MAX_VALUE};
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
48 for (byte i : a) {
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
49 ConstantNode node = ConstantNode.forByte(i, graph);
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
50 Constant expected = Constant.forInt(-i);
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
51 assertEquals(expected, new NegateNode(node).evalConst(node.asConstant()));
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
52 }
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
53 }
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
54
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
55 @Test
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
56 public void testChar() {
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
57 char[] a = new char[]{Character.MIN_VALUE, Character.MIN_VALUE + 1, 0, 1, Character.MAX_VALUE - 1, Character.MAX_VALUE};
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
58 for (char i : a) {
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
59 ConstantNode node = ConstantNode.forChar(i, graph);
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
60 Constant expected = Constant.forInt(-i);
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
61 assertEquals(expected, new NegateNode(node).evalConst(node.asConstant()));
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
62 }
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
63 }
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
64
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
65 @Test
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
66 public void testShort() {
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
67 short[] a = new short[]{Short.MIN_VALUE, Short.MIN_VALUE + 1, -1, 0, 1, Short.MAX_VALUE - 1, Short.MAX_VALUE};
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
68 for (short i : a) {
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
69 ConstantNode node = ConstantNode.forShort(i, graph);
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
70 Constant expected = Constant.forInt(-i);
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
71 assertEquals(expected, new NegateNode(node).evalConst(node.asConstant()));
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
72 }
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
73 }
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
74
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
75 @Test
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
76 public void testInt() {
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
77 int[] a = new int[]{Integer.MIN_VALUE, Integer.MIN_VALUE + 1, -1, 0, 1, Integer.MAX_VALUE - 1, Integer.MAX_VALUE};
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
78 for (int i : a) {
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
79 ConstantNode node = ConstantNode.forInt(i, graph);
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
80 Constant expected = Constant.forInt(-i);
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
81 assertEquals(expected, new NegateNode(node).evalConst(node.asConstant()));
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
82 }
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
83 }
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
84
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
85 @Test
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
86 public void testLong() {
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
87 long[] a = new long[]{Long.MIN_VALUE, Long.MIN_VALUE + 1, -1, 0, 1, Long.MAX_VALUE - 1, Long.MAX_VALUE};
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
88 for (long i : a) {
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
89 ConstantNode node = ConstantNode.forLong(i, graph);
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
90 Constant expected = Constant.forLong(-i);
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
91 assertEquals(expected, new NegateNode(node).evalConst(node.asConstant()));
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
92 }
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
93 }
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
94
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
95 @Test
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
96 public void testFloat() {
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
97 float[] a = new float[]{Float.MIN_VALUE, Float.MIN_VALUE + 1, -1, 0, 1, Float.MAX_VALUE - 1, Float.MAX_VALUE};
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
98 for (float i : a) {
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
99 ConstantNode node = ConstantNode.forFloat(i, graph);
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
100 Constant expected = Constant.forFloat(-i);
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
101 assertEquals(expected, new NegateNode(node).evalConst(node.asConstant()));
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
102 }
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
103 }
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
104
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
105 @Test
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
106 public void testDouble() {
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
107 double[] a = new double[]{Double.MIN_VALUE, Double.MIN_VALUE + 1, -1, 0, 1, Double.MAX_VALUE - 1, Double.MAX_VALUE};
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
108 for (double i : a) {
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
109 ConstantNode node = ConstantNode.forDouble(i, graph);
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
110 Constant expected = Constant.forDouble(-i);
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
111 assertEquals(expected, new NegateNode(node).evalConst(node.asConstant()));
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
112 }
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
113 }
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
114
99ca997f4eae added NegateNodeCanonicalizationTest
twisti
parents:
diff changeset
115 }