Mercurial > hg > graal-jvmci-8
annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/AbsNode.java @ 19529:8fc336a04d77
Create TYPE fields for LIRInstruction and CompositeValue. Renaming NodeClass#get to NodeClass#create.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Fri, 20 Feb 2015 22:22:55 +0100 |
parents | 61d3cb8e1280 |
children | 14e703edb2ab |
rev | line source |
---|---|
18298
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
1 /* |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved. |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
4 * |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
8 * |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
14 * |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
18 * |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
21 * questions. |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
22 */ |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.graal.nodes.calc; |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
24 |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
25 import com.oracle.graal.compiler.common.type.*; |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
26 import com.oracle.graal.compiler.common.type.ArithmeticOpTable.UnaryOp.Abs; |
19403
7e2c87dae93e
Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18998
diff
changeset
|
27 import com.oracle.graal.graph.*; |
18298
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
28 import com.oracle.graal.graph.spi.*; |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
29 import com.oracle.graal.lir.gen.*; |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
30 import com.oracle.graal.nodeinfo.*; |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
31 import com.oracle.graal.nodes.*; |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
32 import com.oracle.graal.nodes.spi.*; |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
33 |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
34 /** |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
35 * Absolute value. |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
36 */ |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
37 @NodeInfo |
18998
ec0733b5a90a
Allow final modifier on node subclasses and start adding the modifier to leaf classes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18845
diff
changeset
|
38 public final class AbsNode extends UnaryArithmeticNode<Abs> implements ArithmeticLIRLowerable, NarrowableArithmeticNode { |
19529
8fc336a04d77
Create TYPE fields for LIRInstruction and CompositeValue. Renaming NodeClass#get to NodeClass#create.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19410
diff
changeset
|
39 public static final NodeClass<AbsNode> TYPE = NodeClass.create(AbsNode.class); |
18298
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
40 |
18845
f57d86eb036f
removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents:
18646
diff
changeset
|
41 public AbsNode(ValueNode x) { |
19403
7e2c87dae93e
Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
18998
diff
changeset
|
42 super(TYPE, ArithmeticOpTable::getAbs, x); |
18298
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
43 } |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
44 |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
45 @Override |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
46 public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) { |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
47 ValueNode ret = super.canonical(tool, forValue); |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
48 if (ret != this) { |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
49 return ret; |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
50 } |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
51 if (forValue instanceof AbsNode) { |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
52 return forValue; |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
53 } |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
54 return this; |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
55 } |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
56 |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
57 @Override |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
58 public void generate(NodeMappableLIRBuilder builder, ArithmeticLIRGenerator gen) { |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
59 builder.setResult(this, gen.emitMathAbs(builder.operand(getValue()))); |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
60 } |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
61 |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
62 @NodeIntrinsic |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
63 public static float abs(float n) { |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
64 return Math.abs(n); |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
65 } |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
66 |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
67 @NodeIntrinsic |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
68 public static double abs(double n) { |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
69 return Math.abs(n); |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
70 } |
ba5c9055c53a
Make abs and sqrt subclasses of UnaryArithmeticNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
71 } |