use of org.graalvm.compiler.nodes.calc.NarrowNode in project graal by oracle.
the class StandardGraphBuilderPlugins method registerCharacterPlugins.
private static void registerCharacterPlugins(InvocationPlugins plugins) {
Registration r = new Registration(plugins, Character.class);
r.register1("reverseBytes", char.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
// return (char) (Integer.reverse(i) >> 16);
ReverseBytesNode reverse = b.add(new ReverseBytesNode(value));
RightShiftNode rightShift = b.add(new RightShiftNode(reverse, b.add(ConstantNode.forInt(16))));
ZeroExtendNode charCast = b.add(new ZeroExtendNode(b.add(new NarrowNode(rightShift, 16)), 32));
b.push(JavaKind.Char, b.append(charCast.canonical(null)));
return true;
}
});
}
use of org.graalvm.compiler.nodes.calc.NarrowNode in project graal by oracle.
the class CInterfaceInvocationPlugin method adaptPrimitiveType.
static ValueNode adaptPrimitiveType(StructuredGraph graph, ValueNode value, JavaKind fromKind, JavaKind toKind, boolean isUnsigned) {
if (fromKind == toKind) {
return value;
}
assert fromKind.isNumericFloat() == toKind.isNumericFloat();
int fromBits = fromKind.getBitCount();
int toBits = toKind.getBitCount();
if (fromBits == toBits) {
return value;
} else if (fromKind.isNumericFloat()) {
FloatConvert op;
if (fromKind == JavaKind.Float && toKind == JavaKind.Double) {
op = FloatConvert.F2D;
} else if (fromKind == JavaKind.Double && toKind == JavaKind.Float) {
op = FloatConvert.D2F;
} else {
throw shouldNotReachHere();
}
return graph.unique(new FloatConvertNode(op, value));
} else if (toKind == JavaKind.Boolean) {
JavaKind computeKind = fromKind == JavaKind.Long ? JavaKind.Long : JavaKind.Int;
LogicNode comparison = graph.unique(new IntegerEqualsNode(adaptPrimitiveType(graph, value, fromKind, computeKind, true), ConstantNode.forIntegerKind(computeKind, 0, graph)));
return graph.unique(new ConditionalNode(comparison, ConstantNode.forBoolean(false, graph), ConstantNode.forBoolean(true, graph)));
} else if (fromBits > toBits) {
return graph.unique(new NarrowNode(value, toBits));
} else if (isUnsigned) {
return graph.unique(new ZeroExtendNode(value, toBits));
} else {
return graph.unique(new SignExtendNode(value, toBits));
}
}
use of org.graalvm.compiler.nodes.calc.NarrowNode in project graal by oracle.
the class StandardGraphBuilderPlugins method registerShortPlugins.
private static void registerShortPlugins(InvocationPlugins plugins) {
Registration r = new Registration(plugins, Short.class);
r.register1("reverseBytes", short.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
// return (short) (Integer.reverse(i) >> 16);
ReverseBytesNode reverse = b.add(new ReverseBytesNode(value));
RightShiftNode rightShift = b.add(new RightShiftNode(reverse, b.add(ConstantNode.forInt(16))));
SignExtendNode charCast = b.add(new SignExtendNode(b.add(new NarrowNode(rightShift, 16)), 32));
b.push(JavaKind.Short, b.append(charCast.canonical(null)));
return true;
}
});
}
use of org.graalvm.compiler.nodes.calc.NarrowNode in project graal by oracle.
the class CEntryPointCallStubMethod method inlinePrologueAndEpilogue.
private static void inlinePrologueAndEpilogue(SubstrateGraphKit kit, InvokeNode prologueInvoke, InvokeNode epilogueInvoke, JavaKind returnKind) {
assert (prologueInvoke != null) == (epilogueInvoke != null);
if (prologueInvoke != null) {
kit.inline(prologueInvoke);
NodeIterable<CEntryPointPrologueBailoutNode> bailoutNodes = kit.getGraph().getNodes().filter(CEntryPointPrologueBailoutNode.class);
for (CEntryPointPrologueBailoutNode node : bailoutNodes) {
ValueNode result = node.getResult();
switch(returnKind) {
case Float:
assert result.getStackKind().isNumericFloat();
result = kit.unique(new FloatConvertNode(FloatConvert.D2F, result));
break;
case Byte:
case Char:
case Short:
case Int:
assert result.getStackKind().isNumericInteger();
result = kit.unique(new NarrowNode(result, returnKind.getBitCount()));
break;
default:
// no conversion necessary
break;
}
ReturnNode returnNode = kit.add(new ReturnNode(result));
node.replaceAndDelete(returnNode);
}
if (epilogueInvoke.isAlive()) {
kit.inline(epilogueInvoke);
}
}
}
Aggregations