Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.graal.replacements.amd64/src/com/oracle/graal/replacements/amd64/AMD64CountTrailingZerosNode.java @ 18495:fe0db662e982
adds ability for substitution guards to have a constructor with an Architecture argument
added extra flags enum to AMD64 to drive code emission features (currently contains UseCountLeadingZerosInstruction and UseCountTrailingZerosInstruction)
moved lzcnt/tzcnt nodes and substitutions to com.oracle.graal.replacements.amd64
Contributed-by: Igor Veresov <igor.veresov@oracle.com>
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 24 Nov 2014 20:32:24 +0100 |
parents | graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/CountTrailingZerosNode.java@6dc4f0be9a70 |
children | f57d86eb036f |
comparison
equal
deleted
inserted
replaced
18494:9e944c7eaded | 18495:fe0db662e982 |
---|---|
1 /* | |
2 * Copyright (c) 2012, 2014, 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.replacements.amd64; | |
24 | |
25 import com.oracle.graal.api.code.*; | |
26 import com.oracle.graal.api.meta.*; | |
27 import com.oracle.graal.compiler.common.type.*; | |
28 import com.oracle.graal.graph.spi.*; | |
29 import com.oracle.graal.nodeinfo.*; | |
30 import com.oracle.graal.nodes.*; | |
31 import com.oracle.graal.nodes.calc.*; | |
32 import com.oracle.graal.nodes.spi.*; | |
33 | |
34 /** | |
35 * Count the number of trailing zeros. | |
36 */ | |
37 @NodeInfo | |
38 public class AMD64CountTrailingZerosNode extends UnaryNode implements LIRLowerable { | |
39 | |
40 public static AMD64CountTrailingZerosNode create(ValueNode value) { | |
41 return new AMD64CountTrailingZerosNode(value); | |
42 } | |
43 | |
44 protected AMD64CountTrailingZerosNode(ValueNode value) { | |
45 super(StampFactory.forInteger(Kind.Int, 0, ((PrimitiveStamp) value.stamp()).getBits()), value); | |
46 assert value.getKind() == Kind.Int || value.getKind() == Kind.Long; | |
47 } | |
48 | |
49 @Override | |
50 public boolean inferStamp() { | |
51 IntegerStamp valueStamp = (IntegerStamp) getValue().stamp(); | |
52 long mask = CodeUtil.mask(valueStamp.getBits()); | |
53 int min = Long.numberOfTrailingZeros(valueStamp.upMask() & mask); | |
54 int max = Long.numberOfTrailingZeros(valueStamp.downMask() & mask); | |
55 return updateStamp(StampFactory.forInteger(Kind.Int, min, max)); | |
56 } | |
57 | |
58 @Override | |
59 public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) { | |
60 if (forValue.isConstant()) { | |
61 JavaConstant c = forValue.asJavaConstant(); | |
62 if (forValue.getKind() == Kind.Int) { | |
63 return ConstantNode.forInt(Integer.numberOfTrailingZeros(c.asInt())); | |
64 } else { | |
65 return ConstantNode.forInt(Long.numberOfTrailingZeros(c.asLong())); | |
66 } | |
67 } | |
68 return this; | |
69 } | |
70 | |
71 /** | |
72 * Raw intrinsic for tzcntq instruction. | |
73 * | |
74 * @param v | |
75 * @return number of trailing zeros | |
76 */ | |
77 @NodeIntrinsic | |
78 public static native int count(long v); | |
79 | |
80 /** | |
81 * Raw intrinsic for tzcntl instruction. | |
82 * | |
83 * @param v | |
84 * @return number of trailing zeros | |
85 */ | |
86 @NodeIntrinsic | |
87 public static native int count(int v); | |
88 | |
89 @Override | |
90 public void generate(NodeLIRBuilderTool gen) { | |
91 Value result = gen.getLIRGeneratorTool().emitCountTrailingZeros(gen.operand(getValue())); | |
92 gen.setResult(this, result); | |
93 } | |
94 } |