use of org.graalvm.compiler.nodes.calc.IntegerMulHighNode in project graal by oracle.
the class AArch64GraphBuilderPlugins method registerMathPlugins.
private static void registerMathPlugins(InvocationPlugins plugins, boolean registerForeignCallMath) {
Registration r = new Registration(plugins, Math.class);
if (registerForeignCallMath) {
registerUnaryMath(r, "sin", SIN);
registerUnaryMath(r, "cos", COS);
registerUnaryMath(r, "tan", TAN);
registerUnaryMath(r, "exp", EXP);
registerUnaryMath(r, "log", LOG);
registerUnaryMath(r, "log10", LOG10);
r.register(new InlineOnlyInvocationPlugin("pow", double.class, double.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) {
b.push(JavaKind.Double, b.append(BinaryMathIntrinsicNode.create(x, y, BinaryMathIntrinsicNode.BinaryOperation.POW)));
return true;
}
});
}
registerFMA(r);
registerIntegerAbs(r);
r.register(new InvocationPlugin("multiplyHigh", long.class, long.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) {
b.push(JavaKind.Long, b.append(new IntegerMulHighNode(x, y)));
return true;
}
});
registerMinMax(r);
r.register(new InvocationPlugin("copySign", float.class, float.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode magnitude, ValueNode sign) {
b.addPush(JavaKind.Float, new CopySignNode(magnitude, sign));
return true;
}
});
r.register(new InvocationPlugin("copySign", double.class, double.class) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode magnitude, ValueNode sign) {
b.addPush(JavaKind.Double, new CopySignNode(magnitude, sign));
return true;
}
});
}
use of org.graalvm.compiler.nodes.calc.IntegerMulHighNode in project graal by oracle.
the class TruffleGraphBuilderPlugins method registerExactMathPlugins.
public static void registerExactMathPlugins(InvocationPlugins plugins, Replacements replacements, LoweringProvider lowerer, MetaAccessProvider metaAccess) {
final ResolvedJavaType exactMathType = getRuntime().resolveType(metaAccess, "com.oracle.truffle.api.ExactMath");
Registration r = new Registration(plugins, new ResolvedJavaSymbol(exactMathType), replacements);
for (JavaKind kind : new JavaKind[] { JavaKind.Int, JavaKind.Long }) {
Class<?> type = kind.toJavaClass();
r.register(new InvocationPlugin("multiplyHigh", type, type) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) {
b.addPush(kind, new IntegerMulHighNode(x, y));
return true;
}
});
r.register(new InvocationPlugin("multiplyHighUnsigned", type, type) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) {
b.addPush(kind, new UnsignedMulHighNode(x, y));
return true;
}
});
}
for (JavaKind kind : new JavaKind[] { JavaKind.Float, JavaKind.Double }) {
r.registerConditional(lowerer.supportsRounding(), new InvocationPlugin("truncate", kind.toJavaClass()) {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x) {
b.addPush(kind, new RoundNode(x, RoundingMode.TRUNCATE));
return true;
}
});
}
}
use of org.graalvm.compiler.nodes.calc.IntegerMulHighNode in project graal by oracle.
the class OptimizeDivPhase method optimizeSignedDiv.
protected static void optimizeSignedDiv(SignedDivNode div) {
ValueNode forX = div.getX();
long c = div.getY().asJavaConstant().asLong();
assert c != 1 && c != -1 && c != 0;
IntegerStamp dividendStamp = (IntegerStamp) forX.stamp(NodeView.DEFAULT);
int bitSize = dividendStamp.getBits();
Pair<Long, Integer> nums = magicDivideConstants(c, bitSize);
long magicNum = nums.getLeft().longValue();
int shiftNum = nums.getRight().intValue();
assert shiftNum >= 0;
ConstantNode m = ConstantNode.forLong(magicNum);
ValueNode value;
if (bitSize == 32) {
value = new MulNode(new SignExtendNode(forX, 64), m);
if ((c > 0 && magicNum < 0) || (c < 0 && magicNum > 0)) {
// Get upper 32-bits of the result
value = NarrowNode.create(new RightShiftNode(value, ConstantNode.forInt(32)), 32, NodeView.DEFAULT);
if (c > 0) {
value = BinaryArithmeticNode.add(value, forX, NodeView.DEFAULT);
} else {
value = BinaryArithmeticNode.sub(value, forX, NodeView.DEFAULT);
}
if (shiftNum > 0) {
value = new RightShiftNode(value, ConstantNode.forInt(shiftNum));
}
} else {
value = new RightShiftNode(value, ConstantNode.forInt(32 + shiftNum));
value = new NarrowNode(value, Integer.SIZE);
}
} else {
assert bitSize == 64;
value = new IntegerMulHighNode(forX, m);
if (c > 0 && magicNum < 0) {
value = BinaryArithmeticNode.add(value, forX, NodeView.DEFAULT);
} else if (c < 0 && magicNum > 0) {
value = BinaryArithmeticNode.sub(value, forX, NodeView.DEFAULT);
}
if (shiftNum > 0) {
value = new RightShiftNode(value, ConstantNode.forInt(shiftNum));
}
}
if (c < 0) {
ConstantNode s = ConstantNode.forInt(bitSize - 1);
ValueNode sign = UnsignedRightShiftNode.create(value, s, NodeView.DEFAULT);
value = BinaryArithmeticNode.add(value, sign, NodeView.DEFAULT);
} else if (dividendStamp.canBeNegative()) {
ConstantNode s = ConstantNode.forInt(bitSize - 1);
ValueNode sign = UnsignedRightShiftNode.create(forX, s, NodeView.DEFAULT);
value = BinaryArithmeticNode.add(value, sign, NodeView.DEFAULT);
}
StructuredGraph graph = div.graph();
graph.replaceFixed(div, graph.addOrUniqueWithInputs(value));
}
Aggregations