Search in sources :

Example 1 with IntegerMulHighNode

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;
        }
    });
}
Also used : CopySignNode(org.graalvm.compiler.nodes.calc.CopySignNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) InlineOnlyInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin) ValueNode(org.graalvm.compiler.nodes.ValueNode) SnippetSubstitutionInvocationPlugin(org.graalvm.compiler.replacements.SnippetSubstitutionInvocationPlugin) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) InlineOnlyInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin) IntegerMulHighNode(org.graalvm.compiler.nodes.calc.IntegerMulHighNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 2 with IntegerMulHighNode

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;
            }
        });
    }
}
Also used : Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) ResolvedJavaSymbol(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.ResolvedJavaSymbol) IntegerMulHighNode(org.graalvm.compiler.nodes.calc.IntegerMulHighNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) RoundNode(org.graalvm.compiler.nodes.calc.RoundNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ValueNode(org.graalvm.compiler.nodes.ValueNode) RequiredInlineOnlyInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInlineOnlyInvocationPlugin) RequiredInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) JavaKind(jdk.vm.ci.meta.JavaKind) UnsignedMulHighNode(org.graalvm.compiler.replacements.nodes.arithmetic.UnsignedMulHighNode)

Example 3 with IntegerMulHighNode

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));
}
Also used : SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) UnsignedRightShiftNode(org.graalvm.compiler.nodes.calc.UnsignedRightShiftNode) RightShiftNode(org.graalvm.compiler.nodes.calc.RightShiftNode) NarrowNode(org.graalvm.compiler.nodes.calc.NarrowNode) IntegerMulHighNode(org.graalvm.compiler.nodes.calc.IntegerMulHighNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) ValueNode(org.graalvm.compiler.nodes.ValueNode) MulNode(org.graalvm.compiler.nodes.calc.MulNode)

Aggregations

ValueNode (org.graalvm.compiler.nodes.ValueNode)3 IntegerMulHighNode (org.graalvm.compiler.nodes.calc.IntegerMulHighNode)3 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)2 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)2 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)2 JavaKind (jdk.vm.ci.meta.JavaKind)1 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)1 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)1 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)1 CopySignNode (org.graalvm.compiler.nodes.calc.CopySignNode)1 MulNode (org.graalvm.compiler.nodes.calc.MulNode)1 NarrowNode (org.graalvm.compiler.nodes.calc.NarrowNode)1 RightShiftNode (org.graalvm.compiler.nodes.calc.RightShiftNode)1 RoundNode (org.graalvm.compiler.nodes.calc.RoundNode)1 SignExtendNode (org.graalvm.compiler.nodes.calc.SignExtendNode)1 UnsignedRightShiftNode (org.graalvm.compiler.nodes.calc.UnsignedRightShiftNode)1 InlineOnlyInvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin)1 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)1