1 /* 2 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.graalvm.compiler.core.common.calc; 24 25 //JaCoCo Exclude 26 27 /** 28 * Utilities for unsigned comparisons. All methods have correct, but slow, standard Java 29 * implementations so that they can be used with compilers not supporting the intrinsics. 30 */ 31 public class UnsignedMath { 32 33 /** 34 * Unsigned comparison aboveThan for two numbers. 35 */ 36 public static boolean aboveThan(int a, int b) { 37 return Integer.compareUnsigned(a, b) > 0; 38 } 39 40 /** 41 * Unsigned comparison aboveOrEqual for two numbers. 42 */ 43 public static boolean aboveOrEqual(int a, int b) { 44 return Integer.compareUnsigned(a, b) >= 0; 45 } 46 47 /** 48 * Unsigned comparison belowThan for two numbers. 49 */ 50 public static boolean belowThan(int a, int b) { 51 return Integer.compareUnsigned(a, b) < 0; 52 } 53 54 /** 55 * Unsigned comparison belowOrEqual for two numbers. 56 */ 57 public static boolean belowOrEqual(int a, int b) { 58 return Integer.compareUnsigned(a, b) <= 0; 59 } 60 61 /** 62 * Unsigned comparison aboveThan for two numbers. 63 */ 64 public static boolean aboveThan(long a, long b) { 65 return Long.compareUnsigned(a, b) > 0; 66 } 67 68 /** 69 * Unsigned comparison aboveOrEqual for two numbers. 70 */ 71 public static boolean aboveOrEqual(long a, long b) { 72 return Long.compareUnsigned(a, b) >= 0; 73 } 74 75 /** 76 * Unsigned comparison belowThan for two numbers. 77 */ 78 public static boolean belowThan(long a, long b) { 79 return Long.compareUnsigned(a, b) < 0; 80 } 81 82 /** 83 * Unsigned comparison belowOrEqual for two numbers. 84 */ 85 public static boolean belowOrEqual(long a, long b) { 86 return Long.compareUnsigned(a, b) <= 0; 87 } 88 }