12460
|
1 /*
|
|
2 * Copyright (c) 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 package com.oracle.graal.nodes.test;
|
|
24
|
|
25 import static org.junit.Assert.*;
|
|
26
|
|
27 import org.junit.*;
|
|
28
|
|
29 import com.oracle.graal.api.meta.*;
|
|
30 import com.oracle.graal.nodes.*;
|
|
31 import com.oracle.graal.nodes.calc.*;
|
|
32
|
|
33 /**
|
|
34 * This class tests that the canonicalization for constant negate nodes cover all cases.
|
|
35 */
|
|
36 public class NegateNodeCanonicalizationTest {
|
|
37
|
|
38 private StructuredGraph graph;
|
|
39
|
|
40 @Before
|
|
41 public void before() {
|
|
42 graph = new StructuredGraph();
|
|
43 }
|
|
44
|
|
45 @Test
|
|
46 public void testByte() {
|
|
47 byte[] a = new byte[]{Byte.MIN_VALUE, Byte.MIN_VALUE + 1, -1, 0, 1, Byte.MAX_VALUE - 1, Byte.MAX_VALUE};
|
|
48 for (byte i : a) {
|
|
49 ConstantNode node = ConstantNode.forByte(i, graph);
|
|
50 Constant expected = Constant.forInt(-i);
|
|
51 assertEquals(expected, new NegateNode(node).evalConst(node.asConstant()));
|
|
52 }
|
|
53 }
|
|
54
|
|
55 @Test
|
|
56 public void testChar() {
|
|
57 char[] a = new char[]{Character.MIN_VALUE, Character.MIN_VALUE + 1, 0, 1, Character.MAX_VALUE - 1, Character.MAX_VALUE};
|
|
58 for (char i : a) {
|
|
59 ConstantNode node = ConstantNode.forChar(i, graph);
|
|
60 Constant expected = Constant.forInt(-i);
|
|
61 assertEquals(expected, new NegateNode(node).evalConst(node.asConstant()));
|
|
62 }
|
|
63 }
|
|
64
|
|
65 @Test
|
|
66 public void testShort() {
|
|
67 short[] a = new short[]{Short.MIN_VALUE, Short.MIN_VALUE + 1, -1, 0, 1, Short.MAX_VALUE - 1, Short.MAX_VALUE};
|
|
68 for (short i : a) {
|
|
69 ConstantNode node = ConstantNode.forShort(i, graph);
|
|
70 Constant expected = Constant.forInt(-i);
|
|
71 assertEquals(expected, new NegateNode(node).evalConst(node.asConstant()));
|
|
72 }
|
|
73 }
|
|
74
|
|
75 @Test
|
|
76 public void testInt() {
|
|
77 int[] a = new int[]{Integer.MIN_VALUE, Integer.MIN_VALUE + 1, -1, 0, 1, Integer.MAX_VALUE - 1, Integer.MAX_VALUE};
|
|
78 for (int i : a) {
|
|
79 ConstantNode node = ConstantNode.forInt(i, graph);
|
|
80 Constant expected = Constant.forInt(-i);
|
|
81 assertEquals(expected, new NegateNode(node).evalConst(node.asConstant()));
|
|
82 }
|
|
83 }
|
|
84
|
|
85 @Test
|
|
86 public void testLong() {
|
|
87 long[] a = new long[]{Long.MIN_VALUE, Long.MIN_VALUE + 1, -1, 0, 1, Long.MAX_VALUE - 1, Long.MAX_VALUE};
|
|
88 for (long i : a) {
|
|
89 ConstantNode node = ConstantNode.forLong(i, graph);
|
|
90 Constant expected = Constant.forLong(-i);
|
|
91 assertEquals(expected, new NegateNode(node).evalConst(node.asConstant()));
|
|
92 }
|
|
93 }
|
|
94
|
|
95 @Test
|
|
96 public void testFloat() {
|
|
97 float[] a = new float[]{Float.MIN_VALUE, Float.MIN_VALUE + 1, -1, 0, 1, Float.MAX_VALUE - 1, Float.MAX_VALUE};
|
|
98 for (float i : a) {
|
|
99 ConstantNode node = ConstantNode.forFloat(i, graph);
|
|
100 Constant expected = Constant.forFloat(-i);
|
|
101 assertEquals(expected, new NegateNode(node).evalConst(node.asConstant()));
|
|
102 }
|
|
103 }
|
|
104
|
|
105 @Test
|
|
106 public void testDouble() {
|
|
107 double[] a = new double[]{Double.MIN_VALUE, Double.MIN_VALUE + 1, -1, 0, 1, Double.MAX_VALUE - 1, Double.MAX_VALUE};
|
|
108 for (double i : a) {
|
|
109 ConstantNode node = ConstantNode.forDouble(i, graph);
|
|
110 Constant expected = Constant.forDouble(-i);
|
|
111 assertEquals(expected, new NegateNode(node).evalConst(node.asConstant()));
|
|
112 }
|
|
113 }
|
|
114
|
|
115 }
|