Mercurial > hg > graal-compiler
changeset 22670:90c5039a70f1
Move UnsignedMath class to graal, and remove methods that duplicate existing methods in JDK.
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/calc/Condition.java Tue Sep 22 15:43:15 2015 +0200 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/calc/Condition.java Tue Sep 22 15:41:43 2015 +0200 @@ -22,7 +22,6 @@ */ package com.oracle.graal.compiler.common.calc; -import jdk.internal.jvmci.code.UnsignedMath; import jdk.internal.jvmci.common.JVMCIError; import jdk.internal.jvmci.meta.Constant; import jdk.internal.jvmci.meta.ConstantReflectionProvider;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/calc/UnsignedMath.java Tue Sep 22 15:41:43 2015 +0200 @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.compiler.common.calc; + +//JaCoCo Exclude + +/** + * Utilities for unsigned comparisons. All methods have correct, but slow, standard Java + * implementations so that they can be used with compilers not supporting the intrinsics. + */ +public class UnsignedMath { + + /** + * Unsigned comparison aboveThan for two numbers. + */ + public static boolean aboveThan(int a, int b) { + return Integer.compareUnsigned(a, b) > 0; + } + + /** + * Unsigned comparison aboveOrEqual for two numbers. + */ + public static boolean aboveOrEqual(int a, int b) { + return Integer.compareUnsigned(a, b) >= 0; + } + + /** + * Unsigned comparison belowThan for two numbers. + */ + public static boolean belowThan(int a, int b) { + return Integer.compareUnsigned(a, b) < 0; + } + + /** + * Unsigned comparison belowOrEqual for two numbers. + */ + public static boolean belowOrEqual(int a, int b) { + return Integer.compareUnsigned(a, b) <= 0; + } + + /** + * Unsigned comparison aboveThan for two numbers. + */ + public static boolean aboveThan(long a, long b) { + return Long.compareUnsigned(a, b) > 0; + } + + /** + * Unsigned comparison aboveOrEqual for two numbers. + */ + public static boolean aboveOrEqual(long a, long b) { + return Long.compareUnsigned(a, b) >= 0; + } + + /** + * Unsigned comparison belowThan for two numbers. + */ + public static boolean belowThan(long a, long b) { + return Long.compareUnsigned(a, b) < 0; + } + + /** + * Unsigned comparison belowOrEqual for two numbers. + */ + public static boolean belowOrEqual(long a, long b) { + return Long.compareUnsigned(a, b) <= 0; + } +}
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/NewObjectSnippets.java Tue Sep 22 15:43:15 2015 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/NewObjectSnippets.java Tue Sep 22 15:41:43 2015 +0200 @@ -23,6 +23,7 @@ package com.oracle.graal.hotspot.replacements; import static com.oracle.graal.compiler.common.GraalOptions.SnippetCounters; +import static com.oracle.graal.compiler.common.calc.UnsignedMath.belowThan; import static com.oracle.graal.hotspot.nodes.CStringNode.cstring; import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.CLASS_ARRAY_KLASS_LOCATION; import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.HUB_WRITE_LOCATION; @@ -62,7 +63,6 @@ import static com.oracle.graal.replacements.ReplacementsUtil.staticAssert; import static com.oracle.graal.replacements.SnippetTemplate.DEFAULT_REPLACER; import static com.oracle.graal.replacements.nodes.ExplodeLoopNode.explodeLoop; -import static jdk.internal.jvmci.code.UnsignedMath.belowThan; import static jdk.internal.jvmci.hotspot.HotSpotJVMCIRuntimeProvider.getArrayBaseOffset; import static jdk.internal.jvmci.hotspot.HotSpotMetaAccessProvider.computeArrayAllocationSize; import jdk.internal.jvmci.code.CodeUtil;
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/UnsignedDivNode.java Tue Sep 22 15:43:15 2015 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/UnsignedDivNode.java Tue Sep 22 15:41:43 2015 +0200 @@ -23,7 +23,6 @@ package com.oracle.graal.nodes.calc; import jdk.internal.jvmci.code.CodeUtil; -import jdk.internal.jvmci.code.UnsignedMath; import com.oracle.graal.compiler.common.type.IntegerStamp; import com.oracle.graal.graph.NodeClass; @@ -57,7 +56,7 @@ if (yConst == 0) { return this; // this will trap, cannot canonicalize } - return ConstantNode.forIntegerStamp(stamp(), UnsignedMath.divide(CodeUtil.zeroExtend(forX.asJavaConstant().asLong(), bits), yConst)); + return ConstantNode.forIntegerStamp(stamp(), Long.divideUnsigned(CodeUtil.zeroExtend(forX.asJavaConstant().asLong(), bits), yConst)); } else if (forY.isConstant()) { long c = CodeUtil.zeroExtend(forY.asJavaConstant().asLong(), bits); if (c == 1) {
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/UnsignedRemNode.java Tue Sep 22 15:43:15 2015 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/UnsignedRemNode.java Tue Sep 22 15:41:43 2015 +0200 @@ -23,7 +23,6 @@ package com.oracle.graal.nodes.calc; import jdk.internal.jvmci.code.CodeUtil; -import jdk.internal.jvmci.code.UnsignedMath; import com.oracle.graal.compiler.common.type.IntegerStamp; import com.oracle.graal.graph.NodeClass; @@ -57,7 +56,7 @@ if (yConst == 0) { return this; // this will trap, cannot canonicalize } - return ConstantNode.forIntegerStamp(stamp(), UnsignedMath.remainder(CodeUtil.zeroExtend(forX.asJavaConstant().asLong(), bits), yConst)); + return ConstantNode.forIntegerStamp(stamp(), Long.remainderUnsigned(CodeUtil.zeroExtend(forX.asJavaConstant().asLong(), bits), yConst)); } else if (forY.isConstant()) { long c = CodeUtil.zeroExtend(forY.asJavaConstant().asLong(), bits); if (c == 1) {
--- a/graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/UnsignedMathTest.java Tue Sep 22 15:43:15 2015 +0200 +++ b/graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/UnsignedMathTest.java Tue Sep 22 15:41:43 2015 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -22,10 +22,9 @@ */ package com.oracle.graal.replacements.test; -import jdk.internal.jvmci.code.UnsignedMath; - import org.junit.Test; +import com.oracle.graal.compiler.common.calc.UnsignedMath; import com.oracle.graal.compiler.test.GraalCompilerTest; /** @@ -50,11 +49,11 @@ } public static int divideInt(int a, int b) { - return UnsignedMath.divide(a, b); + return Integer.divideUnsigned(a, b); } public static int remainderInt(int a, int b) { - return UnsignedMath.remainder(a, b); + return Integer.remainderUnsigned(a, b); } public static boolean aboveThanLong(long a, long b) { @@ -74,11 +73,11 @@ } public static long divideLong(long a, long b) { - return UnsignedMath.divide(a, b); + return Long.divideUnsigned(a, b); } public static long remainderLong(long a, long b) { - return UnsignedMath.remainder(a, b); + return Long.remainderUnsigned(a, b); } private void testInt(int a, int b) {
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/StandardGraphBuilderPlugins.java Tue Sep 22 15:43:15 2015 +0200 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/StandardGraphBuilderPlugins.java Tue Sep 22 15:41:43 2015 +0200 @@ -30,7 +30,6 @@ import java.lang.reflect.Field; import java.util.Arrays; -import jdk.internal.jvmci.code.UnsignedMath; import jdk.internal.jvmci.common.JVMCIError; import jdk.internal.jvmci.meta.DeoptimizationAction; import jdk.internal.jvmci.meta.DeoptimizationReason; @@ -46,6 +45,7 @@ import com.oracle.graal.api.directives.GraalDirectives; import com.oracle.graal.compiler.common.calc.Condition; +import com.oracle.graal.compiler.common.calc.UnsignedMath; import com.oracle.graal.compiler.common.type.ObjectStamp; import com.oracle.graal.compiler.common.type.Stamp; import com.oracle.graal.compiler.common.type.StampFactory; @@ -415,30 +415,6 @@ r.register2("aboveOrEqual", long.class, long.class, new UnsignedMathPlugin(Condition.AE)); r.register2("belowOrEqual", int.class, int.class, new UnsignedMathPlugin(Condition.BE)); r.register2("belowOrEqual", long.class, long.class, new UnsignedMathPlugin(Condition.BE)); - r.register2("divide", int.class, int.class, new InvocationPlugin() { - public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) { - b.push(JavaKind.Int, b.recursiveAppend(new UnsignedDivNode(x, y).canonical(null, x, y))); - return true; - } - }); - r.register2("divide", long.class, long.class, new InvocationPlugin() { - public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) { - b.push(JavaKind.Long, b.recursiveAppend(new UnsignedDivNode(x, y).canonical(null, x, y))); - return true; - } - }); - r.register2("remainder", int.class, int.class, new InvocationPlugin() { - public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) { - b.push(JavaKind.Int, b.recursiveAppend(new UnsignedRemNode(x, y).canonical(null, x, y))); - return true; - } - }); - r.register2("remainder", long.class, long.class, new InvocationPlugin() { - public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) { - b.push(JavaKind.Long, b.recursiveAppend(new UnsignedRemNode(x, y).canonical(null, x, y))); - return true; - } - }); } protected static void registerBoxingPlugins(InvocationPlugins plugins) {
--- a/graal/com.oracle.graal.word/src/com/oracle/graal/word/Word.java Tue Sep 22 15:43:15 2015 +0200 +++ b/graal/com.oracle.graal.word/src/com/oracle/graal/word/Word.java Tue Sep 22 15:41:43 2015 +0200 @@ -29,11 +29,11 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import jdk.internal.jvmci.code.UnsignedMath; import jdk.internal.jvmci.common.JVMCIError; import jdk.internal.jvmci.meta.LocationIdentity; import com.oracle.graal.compiler.common.calc.Condition; +import com.oracle.graal.compiler.common.calc.UnsignedMath; import com.oracle.graal.nodes.ValueNode; import com.oracle.graal.nodes.calc.AddNode; import com.oracle.graal.nodes.calc.AndNode; @@ -319,7 +319,7 @@ @Operation(node = UnsignedDivNode.class) public Word unsignedDivide(Word val) { - return box(UnsignedMath.divide(unbox(), val.unbox())); + return box(Long.divideUnsigned(unbox(), val.unbox())); } @Override @@ -353,7 +353,7 @@ @Operation(node = UnsignedRemNode.class) public Word unsignedRemainder(Word val) { - return box(UnsignedMath.remainder(unbox(), val.unbox())); + return box(Long.remainderUnsigned(unbox(), val.unbox())); } @Override