Search in sources :

Example 1 with BitCountNode

use of org.graalvm.compiler.replacements.nodes.BitCountNode in project graal by oracle.

the class SPARCGraphBuilderPlugins method registerIntegerLongPlugins.

private static void registerIntegerLongPlugins(InvocationPlugins plugins, Class<?> substituteDeclaringClass, JavaKind kind, BytecodeProvider bytecodeProvider) {
    Class<?> declaringClass = kind.toBoxedJavaClass();
    Class<?> type = kind.toJavaClass();
    Registration r = new Registration(plugins, declaringClass, bytecodeProvider);
    r.registerMethodSubstitution(substituteDeclaringClass, "numberOfLeadingZeros", type);
    r.registerMethodSubstitution(substituteDeclaringClass, "numberOfTrailingZeros", type);
    r.register1("bitCount", type, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
            b.push(JavaKind.Int, b.append(new BitCountNode(value).canonical(null)));
            return true;
        }
    });
}
Also used : GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) BitCountNode(org.graalvm.compiler.replacements.nodes.BitCountNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 2 with BitCountNode

use of org.graalvm.compiler.replacements.nodes.BitCountNode in project graal by oracle.

the class AMD64GraphBuilderPlugins method registerIntegerLongPlugins.

private static void registerIntegerLongPlugins(InvocationPlugins plugins, Class<?> substituteDeclaringClass, JavaKind kind, AMD64 arch, BytecodeProvider bytecodeProvider) {
    Class<?> declaringClass = kind.toBoxedJavaClass();
    Class<?> type = kind.toJavaClass();
    Registration r = new Registration(plugins, declaringClass, bytecodeProvider);
    if (arch.getFeatures().contains(AMD64.CPUFeature.LZCNT) && arch.getFlags().contains(AMD64.Flag.UseCountLeadingZerosInstruction)) {
        r.register1("numberOfLeadingZeros", type, new InvocationPlugin() {

            @Override
            public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
                ValueNode folded = AMD64CountLeadingZerosNode.tryFold(value);
                if (folded != null) {
                    b.addPush(JavaKind.Int, folded);
                } else {
                    b.addPush(JavaKind.Int, new AMD64CountLeadingZerosNode(value));
                }
                return true;
            }
        });
    } else {
        r.registerMethodSubstitution(substituteDeclaringClass, "numberOfLeadingZeros", type);
    }
    if (arch.getFeatures().contains(AMD64.CPUFeature.BMI1) && arch.getFlags().contains(AMD64.Flag.UseCountTrailingZerosInstruction)) {
        r.register1("numberOfTrailingZeros", type, new InvocationPlugin() {

            @Override
            public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
                ValueNode folded = AMD64CountTrailingZerosNode.tryFold(value);
                if (folded != null) {
                    b.addPush(JavaKind.Int, folded);
                } else {
                    b.addPush(JavaKind.Int, new AMD64CountTrailingZerosNode(value));
                }
                return true;
            }
        });
    } else {
        r.registerMethodSubstitution(substituteDeclaringClass, "numberOfTrailingZeros", type);
    }
    if (arch.getFeatures().contains(AMD64.CPUFeature.POPCNT)) {
        r.register1("bitCount", type, new InvocationPlugin() {

            @Override
            public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
                b.push(JavaKind.Int, b.append(new BitCountNode(value).canonical(null)));
                return true;
            }
        });
    }
}
Also used : GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) BitCountNode(org.graalvm.compiler.replacements.nodes.BitCountNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 ValueNode (org.graalvm.compiler.nodes.ValueNode)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 BitCountNode (org.graalvm.compiler.replacements.nodes.BitCountNode)2 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)1