1 /*
   2  * Copyright (c) 2012, 2012, 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.word;
  24 
  25 public interface Unsigned extends ComparableWord {
  26 
  27     /**
  28      * Returns a Unsigned whose value is {@code (this + val)}.
  29      *
  30      * @param val value to be added to this Unsigned.
  31      * @return {@code this + val}
  32      */
  33     Unsigned add(Unsigned val);
  34 
  35     /**
  36      * Returns a Unsigned whose value is {@code (this - val)}.
  37      *
  38      * @param val value to be subtracted from this Unsigned.
  39      * @return {@code this - val}
  40      */
  41     Unsigned subtract(Unsigned val);
  42 
  43     /**
  44      * Returns a Unsigned whose value is {@code (this * val)}.
  45      *
  46      * @param val value to be multiplied by this Unsigned.
  47      * @return {@code this * val}
  48      */
  49     Unsigned multiply(Unsigned val);
  50 
  51     /**
  52      * Returns a Unsigned whose value is {@code (this / val)}.
  53      *
  54      * @param val value by which this Unsigned is to be divided.
  55      * @return {@code this / val}
  56      */
  57     Unsigned unsignedDivide(Unsigned val);
  58 
  59     /**
  60      * Returns a Unsigned whose value is {@code (this % val)}.
  61      *
  62      * @param val value by which this Unsigned is to be divided, and the remainder computed.
  63      * @return {@code this % val}
  64      */
  65     Unsigned unsignedRemainder(Unsigned val);
  66 
  67     /**
  68      * Returns a Unsigned whose value is {@code (this << n)}.
  69      *
  70      * @param n shift distance, in bits.
  71      * @return {@code this << n}
  72      */
  73     Unsigned shiftLeft(Unsigned n);
  74 
  75     /**
  76      * Returns a Unsigned whose value is {@code (this >>> n)}. No sign extension is performed.
  77      *
  78      * @param n shift distance, in bits.
  79      * @return {@code this >> n}
  80      */
  81     Unsigned unsignedShiftRight(Unsigned n);
  82 
  83     /**
  84      * Returns a Unsigned whose value is {@code (this & val)}.
  85      *
  86      * @param val value to be AND'ed with this Unsigned.
  87      * @return {@code this & val}
  88      */
  89     Unsigned and(Unsigned val);
  90 
  91     /**
  92      * Returns a Unsigned whose value is {@code (this | val)}.
  93      *
  94      * @param val value to be OR'ed with this Unsigned.
  95      * @return {@code this | val}
  96      */
  97     Unsigned or(Unsigned val);
  98 
  99     /**
 100      * Returns a Unsigned whose value is {@code (this ^ val)}.
 101      *
 102      * @param val value to be XOR'ed with this Unsigned.
 103      * @return {@code this ^ val}
 104      */
 105     Unsigned xor(Unsigned val);
 106 
 107     /**
 108      * Returns a Unsigned whose value is {@code (~this)}.
 109      *
 110      * @return {@code ~this}
 111      */
 112     Unsigned not();
 113 
 114     /**
 115      * Compares this Unsigned with the specified value.
 116      *
 117      * @param val value to which this Unsigned is to be compared.
 118      * @return {@code this == val}
 119      */
 120     boolean equal(Unsigned val);
 121 
 122     /**
 123      * Compares this Unsigned with the specified value.
 124      *
 125      * @param val value to which this Unsigned is to be compared.
 126      * @return {@code this != val}
 127      */
 128     boolean notEqual(Unsigned val);
 129 
 130     /**
 131      * Compares this Unsigned with the specified value.
 132      *
 133      * @param val value to which this Unsigned is to be compared.
 134      * @return {@code this < val}
 135      */
 136     boolean belowThan(Unsigned val);
 137 
 138     /**
 139      * Compares this Unsigned with the specified value.
 140      *
 141      * @param val value to which this Unsigned is to be compared.
 142      * @return {@code this <= val}
 143      */
 144     boolean belowOrEqual(Unsigned val);
 145 
 146     /**
 147      * Compares this Unsigned with the specified value.
 148      *
 149      * @param val value to which this Unsigned is to be compared.
 150      * @return {@code this > val}
 151      */
 152     boolean aboveThan(Unsigned val);
 153 
 154     /**
 155      * Compares this Unsigned with the specified value.
 156      *
 157      * @param val value to which this Unsigned is to be compared.
 158      * @return {@code this >= val}
 159      */
 160     boolean aboveOrEqual(Unsigned val);
 161 
 162     /**
 163      * Returns a Unsigned whose value is {@code (this + val)}.
 164      * <p>
 165      * Note that the right operand is a signed value, while the operation is performed unsigned.
 166      * Therefore, the result is only well-defined for positive right operands.
 167      *
 168      * @param val value to be added to this Unsigned.
 169      * @return {@code this + val}
 170      */
 171     Unsigned add(int val);
 172 
 173     /**
 174      * Returns a Unsigned whose value is {@code (this - val)}.
 175      * <p>
 176      * Note that the right operand is a signed value, while the operation is performed unsigned.
 177      * Therefore, the result is only well-defined for positive right operands.
 178      *
 179      * @param val value to be subtracted from this Unsigned.
 180      * @return {@code this - val}
 181      */
 182     Unsigned subtract(int val);
 183 
 184     /**
 185      * Returns a Unsigned whose value is {@code (this * val)}.
 186      * <p>
 187      * Note that the right operand is a signed value, while the operation is performed unsigned.
 188      * Therefore, the result is only well-defined for positive right operands.
 189      *
 190      * @param val value to be multiplied by this Unsigned.
 191      * @return {@code this * val}
 192      */
 193     Unsigned multiply(int val);
 194 
 195     /**
 196      * Returns a Unsigned whose value is {@code (this / val)}.
 197      * <p>
 198      * Note that the right operand is a signed value, while the operation is performed unsigned.
 199      * Therefore, the result is only well-defined for positive right operands.
 200      *
 201      * @param val value by which this Unsigned is to be divided.
 202      * @return {@code this / val}
 203      */
 204     Unsigned unsignedDivide(int val);
 205 
 206     /**
 207      * Returns a Unsigned whose value is {@code (this % val)}.
 208      * <p>
 209      * Note that the right operand is a signed value, while the operation is performed unsigned.
 210      * Therefore, the result is only well-defined for positive right operands.
 211      *
 212      * @param val value by which this Unsigned is to be divided, and the remainder computed.
 213      * @return {@code this % val}
 214      */
 215     Unsigned unsignedRemainder(int val);
 216 
 217     /**
 218      * Returns a Unsigned whose value is {@code (this << n)}.
 219      * <p>
 220      * Note that the right operand is a signed value, while the operation is performed unsigned.
 221      * Therefore, the result is only well-defined for positive right operands.
 222      *
 223      * @param n shift distance, in bits.
 224      * @return {@code this << n}
 225      */
 226     Unsigned shiftLeft(int n);
 227 
 228     /**
 229      * Returns a Unsigned whose value is {@code (this >>> n)}. No sign extension is performed.
 230      * <p>
 231      * Note that the right operand is a signed value, while the operation is performed unsigned.
 232      * Therefore, the result is only well-defined for positive right operands.
 233      *
 234      * @param n shift distance, in bits.
 235      * @return {@code this >> n}
 236      */
 237     Unsigned unsignedShiftRight(int n);
 238 
 239     /**
 240      * Returns a Unsigned whose value is {@code (this & val)}.
 241      * <p>
 242      * Note that the right operand is a signed value, while the operation is performed unsigned.
 243      * Therefore, the result is only well-defined for positive right operands.
 244      *
 245      * @param val value to be AND'ed with this Unsigned.
 246      * @return {@code this & val}
 247      */
 248     Unsigned and(int val);
 249 
 250     /**
 251      * Returns a Unsigned whose value is {@code (this | val)}.
 252      * <p>
 253      * Note that the right operand is a signed value, while the operation is performed unsigned.
 254      * Therefore, the result is only well-defined for positive right operands.
 255      *
 256      * @param val value to be OR'ed with this Unsigned.
 257      * @return {@code this | val}
 258      */
 259     Unsigned or(int val);
 260 
 261     /**
 262      * Returns a Unsigned whose value is {@code (this ^ val)}.
 263      * <p>
 264      * Note that the right operand is a signed value, while the operation is performed unsigned.
 265      * Therefore, the result is only well-defined for positive right operands.
 266      *
 267      * @param val value to be XOR'ed with this Unsigned.
 268      * @return {@code this ^ val}
 269      */
 270     Unsigned xor(int val);
 271 
 272     /**
 273      * Compares this Unsigned with the specified value.
 274      * <p>
 275      * Note that the right operand is a signed value, while the operation is performed unsigned.
 276      * Therefore, the result is only well-defined for positive right operands.
 277      *
 278      * @param val value to which this Unsigned is to be compared.
 279      * @return {@code this == val}
 280      */
 281     boolean equal(int val);
 282 
 283     /**
 284      * Compares this Unsigned with the specified value.
 285      * <p>
 286      * Note that the right operand is a signed value, while the operation is performed unsigned.
 287      * Therefore, the result is only well-defined for positive right operands.
 288      *
 289      * @param val value to which this Unsigned is to be compared.
 290      * @return {@code this != val}
 291      */
 292     boolean notEqual(int val);
 293 
 294     /**
 295      * Compares this Unsigned with the specified value.
 296      * <p>
 297      * Note that the right operand is a signed value, while the operation is performed unsigned.
 298      * Therefore, the result is only well-defined for positive right operands.
 299      *
 300      * @param val value to which this Unsigned is to be compared.
 301      * @return {@code this < val}
 302      */
 303     boolean belowThan(int val);
 304 
 305     /**
 306      * Compares this Unsigned with the specified value.
 307      * <p>
 308      * Note that the right operand is a signed value, while the operation is performed unsigned.
 309      * Therefore, the result is only well-defined for positive right operands.
 310      *
 311      * @param val value to which this Unsigned is to be compared.
 312      * @return {@code this <= val}
 313      */
 314     boolean belowOrEqual(int val);
 315 
 316     /**
 317      * Compares this Unsigned with the specified value.
 318      * <p>
 319      * Note that the right operand is a signed value, while the operation is performed unsigned.
 320      * Therefore, the result is only well-defined for positive right operands.
 321      *
 322      * @param val value to which this Unsigned is to be compared.
 323      * @return {@code this > val}
 324      */
 325     boolean aboveThan(int val);
 326 
 327     /**
 328      * Compares this Unsigned with the specified value.
 329      * <p>
 330      * Note that the right operand is a signed value, while the operation is performed unsigned.
 331      * Therefore, the result is only well-defined for positive right operands.
 332      *
 333      * @param val value to which this Unsigned is to be compared.
 334      * @return {@code this >= val}
 335      */
 336     boolean aboveOrEqual(int val);
 337 }