< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.aarch64/src/org/graalvm/compiler/replacements/aarch64/AArch64IntegerArithmeticSnippets.java

Print this page
rev 56282 : [mq]: graal
   1 /*
   2  * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2018, Red Hat Inc. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.


  27 package org.graalvm.compiler.replacements.aarch64;
  28 
  29 import org.graalvm.compiler.api.replacements.Snippet;
  30 import org.graalvm.compiler.api.replacements.Snippet.ConstantParameter;
  31 import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
  32 import org.graalvm.compiler.core.common.type.IntegerStamp;
  33 import org.graalvm.compiler.debug.DebugHandlersFactory;
  34 import org.graalvm.compiler.debug.GraalError;
  35 import org.graalvm.compiler.graph.Node.NodeIntrinsic;
  36 import org.graalvm.compiler.graph.NodeClass;
  37 import org.graalvm.compiler.nodeinfo.NodeInfo;
  38 import org.graalvm.compiler.nodes.DeoptimizeNode;
  39 import org.graalvm.compiler.nodes.NodeView;
  40 import org.graalvm.compiler.nodes.StructuredGraph;
  41 import org.graalvm.compiler.nodes.ValueNode;
  42 import org.graalvm.compiler.nodes.calc.IntegerDivRemNode;
  43 import org.graalvm.compiler.nodes.calc.SignedDivNode;
  44 import org.graalvm.compiler.nodes.calc.SignedRemNode;
  45 import org.graalvm.compiler.nodes.calc.UnsignedDivNode;
  46 import org.graalvm.compiler.nodes.calc.UnsignedRemNode;

  47 import org.graalvm.compiler.nodes.spi.LoweringTool;
  48 import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
  49 import org.graalvm.compiler.options.OptionValues;
  50 import org.graalvm.compiler.phases.util.Providers;
  51 import org.graalvm.compiler.replacements.SnippetTemplate;
  52 import org.graalvm.compiler.replacements.SnippetTemplate.AbstractTemplates;
  53 import org.graalvm.compiler.replacements.SnippetTemplate.Arguments;
  54 import org.graalvm.compiler.replacements.Snippets;
  55 
  56 import jdk.vm.ci.code.TargetDescription;
  57 import jdk.vm.ci.meta.DeoptimizationAction;
  58 import jdk.vm.ci.meta.DeoptimizationReason;
  59 import jdk.vm.ci.meta.JavaKind;
  60 
  61 /**
  62  * Division in AArch64 ISA does not generate a trap when dividing by zero, but instead sets the
  63  * result to 0. These snippets throw an ArithmethicException if the denominator is 0 and otherwise
  64  * forward to the LIRGenerator.
  65  */
  66 public class AArch64IntegerArithmeticSnippets extends AbstractTemplates implements Snippets {


 166         return safeUDiv(x, y);
 167     }
 168 
 169     @Snippet
 170     public static int uiremSnippet(int x, int y, @ConstantParameter boolean needsZeroCheck) {
 171         if (needsZeroCheck) {
 172             checkForZero(y);
 173         }
 174         return safeURem(x, y);
 175     }
 176 
 177     @Snippet
 178     public static long ulremSnippet(long x, long y, @ConstantParameter boolean needsZeroCheck) {
 179         if (needsZeroCheck) {
 180             checkForZero(y);
 181         }
 182         return safeURem(x, y);
 183     }
 184 
 185     private static void checkForZero(int y) {
 186         if (y == 0) {
 187             // "/ by zero"
 188             DeoptimizeNode.deopt(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.ArithmeticException);
 189         }
 190     }
 191 
 192     private static void checkForZero(long y) {
 193         if (y == 0) {
 194             // "/ by zero"
 195             DeoptimizeNode.deopt(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.ArithmeticException);
 196         }
 197     }
 198 
 199     @NodeIntrinsic(SafeSignedDivNode.class)
 200     private static native int safeDiv(int x, int y);
 201 
 202     @NodeIntrinsic(SafeSignedDivNode.class)
 203     private static native long safeDiv(long x, long y);
 204 
 205     @NodeIntrinsic(SafeSignedRemNode.class)
 206     private static native int safeRem(int x, int y);
 207 
 208     @NodeIntrinsic(SafeSignedRemNode.class)
 209     private static native long safeRem(long x, long y);
 210 
 211     @NodeIntrinsic(SafeUnsignedDivNode.class)
 212     private static native int safeUDiv(int x, int y);
 213 


   1 /*
   2  * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2018, Red Hat Inc. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.


  27 package org.graalvm.compiler.replacements.aarch64;
  28 
  29 import org.graalvm.compiler.api.replacements.Snippet;
  30 import org.graalvm.compiler.api.replacements.Snippet.ConstantParameter;
  31 import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
  32 import org.graalvm.compiler.core.common.type.IntegerStamp;
  33 import org.graalvm.compiler.debug.DebugHandlersFactory;
  34 import org.graalvm.compiler.debug.GraalError;
  35 import org.graalvm.compiler.graph.Node.NodeIntrinsic;
  36 import org.graalvm.compiler.graph.NodeClass;
  37 import org.graalvm.compiler.nodeinfo.NodeInfo;
  38 import org.graalvm.compiler.nodes.DeoptimizeNode;
  39 import org.graalvm.compiler.nodes.NodeView;
  40 import org.graalvm.compiler.nodes.StructuredGraph;
  41 import org.graalvm.compiler.nodes.ValueNode;
  42 import org.graalvm.compiler.nodes.calc.IntegerDivRemNode;
  43 import org.graalvm.compiler.nodes.calc.SignedDivNode;
  44 import org.graalvm.compiler.nodes.calc.SignedRemNode;
  45 import org.graalvm.compiler.nodes.calc.UnsignedDivNode;
  46 import org.graalvm.compiler.nodes.calc.UnsignedRemNode;
  47 import org.graalvm.compiler.nodes.extended.BranchProbabilityNode;
  48 import org.graalvm.compiler.nodes.spi.LoweringTool;
  49 import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
  50 import org.graalvm.compiler.options.OptionValues;
  51 import org.graalvm.compiler.phases.util.Providers;
  52 import org.graalvm.compiler.replacements.SnippetTemplate;
  53 import org.graalvm.compiler.replacements.SnippetTemplate.AbstractTemplates;
  54 import org.graalvm.compiler.replacements.SnippetTemplate.Arguments;
  55 import org.graalvm.compiler.replacements.Snippets;
  56 
  57 import jdk.vm.ci.code.TargetDescription;
  58 import jdk.vm.ci.meta.DeoptimizationAction;
  59 import jdk.vm.ci.meta.DeoptimizationReason;
  60 import jdk.vm.ci.meta.JavaKind;
  61 
  62 /**
  63  * Division in AArch64 ISA does not generate a trap when dividing by zero, but instead sets the
  64  * result to 0. These snippets throw an ArithmethicException if the denominator is 0 and otherwise
  65  * forward to the LIRGenerator.
  66  */
  67 public class AArch64IntegerArithmeticSnippets extends AbstractTemplates implements Snippets {


 167         return safeUDiv(x, y);
 168     }
 169 
 170     @Snippet
 171     public static int uiremSnippet(int x, int y, @ConstantParameter boolean needsZeroCheck) {
 172         if (needsZeroCheck) {
 173             checkForZero(y);
 174         }
 175         return safeURem(x, y);
 176     }
 177 
 178     @Snippet
 179     public static long ulremSnippet(long x, long y, @ConstantParameter boolean needsZeroCheck) {
 180         if (needsZeroCheck) {
 181             checkForZero(y);
 182         }
 183         return safeURem(x, y);
 184     }
 185 
 186     private static void checkForZero(int y) {
 187         if (BranchProbabilityNode.probability(BranchProbabilityNode.DEOPT_PROBABILITY, y == 0)) {
 188             // "/ by zero"
 189             DeoptimizeNode.deopt(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.ArithmeticException);
 190         }
 191     }
 192 
 193     private static void checkForZero(long y) {
 194         if (BranchProbabilityNode.probability(BranchProbabilityNode.DEOPT_PROBABILITY, y == 0)) {
 195             // "/ by zero"
 196             DeoptimizeNode.deopt(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.ArithmeticException);
 197         }
 198     }
 199 
 200     @NodeIntrinsic(SafeSignedDivNode.class)
 201     private static native int safeDiv(int x, int y);
 202 
 203     @NodeIntrinsic(SafeSignedDivNode.class)
 204     private static native long safeDiv(long x, long y);
 205 
 206     @NodeIntrinsic(SafeSignedRemNode.class)
 207     private static native int safeRem(int x, int y);
 208 
 209     @NodeIntrinsic(SafeSignedRemNode.class)
 210     private static native long safeRem(long x, long y);
 211 
 212     @NodeIntrinsic(SafeUnsignedDivNode.class)
 213     private static native int safeUDiv(int x, int y);
 214 


< prev index next >