1 /*
   2  * Copyright (c) 2011, 2018, 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 
  24 
  25 package org.graalvm.compiler.core.common.calc;
  26 
  27 //JaCoCo Exclude
  28 
  29 /**
  30  * Utilities for unsigned comparisons. All methods have correct, but slow, standard Java
  31  * implementations so that they can be used with compilers not supporting the intrinsics.
  32  */
  33 public class UnsignedMath {
  34 
  35     /**
  36      * Unsigned comparison aboveThan for two numbers.
  37      */
  38     public static boolean aboveThan(int a, int b) {
  39         return Integer.compareUnsigned(a, b) > 0;
  40     }
  41 
  42     /**
  43      * Unsigned comparison aboveOrEqual for two numbers.
  44      */
  45     public static boolean aboveOrEqual(int a, int b) {
  46         return Integer.compareUnsigned(a, b) >= 0;
  47     }
  48 
  49     /**
  50      * Unsigned comparison belowThan for two numbers.
  51      */
  52     public static boolean belowThan(int a, int b) {
  53         return Integer.compareUnsigned(a, b) < 0;
  54     }
  55 
  56     /**
  57      * Unsigned comparison belowOrEqual for two numbers.
  58      */
  59     public static boolean belowOrEqual(int a, int b) {
  60         return Integer.compareUnsigned(a, b) <= 0;
  61     }
  62 
  63     /**
  64      * Unsigned comparison aboveThan for two numbers.
  65      */
  66     public static boolean aboveThan(long a, long b) {
  67         return Long.compareUnsigned(a, b) > 0;
  68     }
  69 
  70     /**
  71      * Unsigned comparison aboveOrEqual for two numbers.
  72      */
  73     public static boolean aboveOrEqual(long a, long b) {
  74         return Long.compareUnsigned(a, b) >= 0;
  75     }
  76 
  77     /**
  78      * Unsigned comparison belowThan for two numbers.
  79      */
  80     public static boolean belowThan(long a, long b) {
  81         return Long.compareUnsigned(a, b) < 0;
  82     }
  83 
  84     /**
  85      * Unsigned comparison belowOrEqual for two numbers.
  86      */
  87     public static boolean belowOrEqual(long a, long b) {
  88         return Long.compareUnsigned(a, b) <= 0;
  89     }
  90 }