|
36 | 36 | import jdk.graal.compiler.core.common.Stride;
|
37 | 37 | import jdk.graal.compiler.core.common.StrideUtil;
|
38 | 38 | import jdk.graal.compiler.core.common.calc.CanonicalCondition;
|
| 39 | +import jdk.graal.compiler.core.common.calc.FloatConvert; |
39 | 40 | import jdk.graal.compiler.core.common.spi.ConstantFieldProvider;
|
40 | 41 | import jdk.graal.compiler.core.common.type.Stamp;
|
41 | 42 | import jdk.graal.compiler.core.common.type.StampFactory;
|
|
53 | 54 | import jdk.graal.compiler.nodes.ValueNode;
|
54 | 55 | import jdk.graal.compiler.nodes.calc.AddNode;
|
55 | 56 | import jdk.graal.compiler.nodes.calc.CompareNode;
|
| 57 | +import jdk.graal.compiler.nodes.calc.FloatConvertNode; |
56 | 58 | import jdk.graal.compiler.nodes.calc.LeftShiftNode;
|
57 | 59 | import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderContext;
|
58 | 60 | import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin;
|
59 | 61 | import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin;
|
60 | 62 | import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin.OptionalInlineOnlyInvocationPlugin;
|
| 63 | +import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin.OptionalInvocationPlugin; |
61 | 64 | import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver;
|
62 | 65 | import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins;
|
63 | 66 | import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins.OptionalLazySymbol;
|
@@ -95,6 +98,7 @@ public static void register(Architecture architecture, InvocationPlugins plugins
|
95 | 98 | if (architecture instanceof AMD64 || architecture instanceof AArch64) {
|
96 | 99 | registerTStringPlugins(plugins, replacements, architecture);
|
97 | 100 | registerArrayUtilsPlugins(plugins, replacements);
|
| 101 | + registerExactMathPlugins(plugins, replacements); |
98 | 102 | }
|
99 | 103 | registerFramePlugins(plugins, replacements);
|
100 | 104 | registerBytecodePlugins(plugins, replacements);
|
@@ -667,4 +671,44 @@ public static boolean applyIndexOf(GraphBuilderContext b, ResolvedJavaMethod tar
|
667 | 671 | }
|
668 | 672 | return true;
|
669 | 673 | }
|
| 674 | + |
| 675 | + public static void registerExactMathPlugins(InvocationPlugins plugins, Replacements replacements) { |
| 676 | + plugins.registerIntrinsificationPredicate(t -> t.getName().equals("Lcom/oracle/truffle/api/ExactMath;")); |
| 677 | + var r = new InvocationPlugins.Registration(plugins, "com.oracle.truffle.api.ExactMath", replacements); |
| 678 | + var lowerer = replacements.getProviders().getLowerer(); |
| 679 | + |
| 680 | + for (JavaKind floatKind : new JavaKind[]{JavaKind.Float, JavaKind.Double}) { |
| 681 | + for (JavaKind integerKind : new JavaKind[]{JavaKind.Int, JavaKind.Long}) { |
| 682 | + r.registerConditional(lowerer.supportsUnsignedFloatConvert(), new OptionalInvocationPlugin( |
| 683 | + integerKind == JavaKind.Long ? "truncateToUnsignedLong" : "truncateToUnsignedInt", |
| 684 | + floatKind.toJavaClass()) { |
| 685 | + @Override |
| 686 | + public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x) { |
| 687 | + FloatConvert op = floatKind == JavaKind.Double |
| 688 | + ? (integerKind == JavaKind.Long |
| 689 | + ? FloatConvert.D2UL |
| 690 | + : FloatConvert.D2UI) |
| 691 | + : (integerKind == JavaKind.Long |
| 692 | + ? FloatConvert.F2UL |
| 693 | + : FloatConvert.F2UI); |
| 694 | + b.addPush(integerKind, FloatConvertNode.create(op, x, NodeView.DEFAULT)); |
| 695 | + return true; |
| 696 | + } |
| 697 | + }); |
| 698 | + } |
| 699 | + |
| 700 | + r.registerConditional(lowerer.supportsUnsignedFloatConvert(), new OptionalInvocationPlugin( |
| 701 | + floatKind == JavaKind.Double ? "unsignedToDouble" : "unsignedToFloat", |
| 702 | + long.class) { |
| 703 | + @Override |
| 704 | + public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x) { |
| 705 | + FloatConvert op = floatKind == JavaKind.Double |
| 706 | + ? FloatConvert.UL2D |
| 707 | + : FloatConvert.UL2F; |
| 708 | + b.addPush(floatKind, FloatConvertNode.create(op, x, NodeView.DEFAULT)); |
| 709 | + return true; |
| 710 | + } |
| 711 | + }); |
| 712 | + } |
| 713 | + } |
670 | 714 | }
|
0 commit comments