1 /*
   2  * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * The Universal Permissive License (UPL), Version 1.0
   6  *
   7  * Subject to the condition set forth below, permission is hereby granted to any
   8  * person obtaining a copy of this software, associated documentation and/or
   9  * data (collectively the "Software"), free of charge and under any and all
  10  * copyright rights in the Software, and any and all patent rights owned or
  11  * freely licensable by each licensor hereunder covering either (i) the
  12  * unmodified Software as contributed to or provided by such licensor, or (ii)
  13  * the Larger Works (as defined below), to deal in both
  14  *
  15  * (a) the Software, and
  16  *
  17  * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
  18  * one is included with the Software each a "Larger Work" to which the Software
  19  * is contributed by such licensors),
  20  *
  21  * without restriction, including without limitation the rights to copy, create
  22  * derivative works of, display, perform, and distribute the Software and make,
  23  * use, sell, offer for sale, import, export, have made, and have sold the
  24  * Software and the Larger Work(s), and to sublicense the foregoing rights on
  25  * either these or other terms.
  26  *
  27  * This license is subject to the following condition:
  28  *
  29  * The above copyright notice and either this complete permission notice or at a
  30  * minimum a reference to the UPL must be included in all copies or substantial
  31  * portions of the Software.
  32  *
  33  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  34  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  35  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  36  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  37  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  38  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  39  * SOFTWARE.
  40  */
  41 package jdk.internal.vm.compiler.word;
  42 
  43 /**
  44  * Represents an unsigned word-sized value.
  45  *
  46  * @since 1.0
  47  */
  48 public interface UnsignedWord extends ComparableWord {
  49 
  50     /**
  51      * Returns a Unsigned whose value is {@code (this + val)}.
  52      *
  53      * @param val value to be added to this Unsigned.
  54      * @return {@code this + val}
  55      *
  56      * @since 1.0
  57      */
  58     UnsignedWord add(UnsignedWord val);
  59 
  60     /**
  61      * Returns a Unsigned whose value is {@code (this - val)}.
  62      *
  63      * @param val value to be subtracted from this Unsigned.
  64      * @return {@code this - val}
  65      *
  66      * @since 1.0
  67      */
  68     UnsignedWord subtract(UnsignedWord val);
  69 
  70     /**
  71      * Returns a Unsigned whose value is {@code (this * val)}.
  72      *
  73      * @param val value to be multiplied by this Unsigned.
  74      * @return {@code this * val}
  75      *
  76      * @since 1.0
  77      */
  78     UnsignedWord multiply(UnsignedWord val);
  79 
  80     /**
  81      * Returns a Unsigned whose value is {@code (this / val)}.
  82      *
  83      * @param val value by which this Unsigned is to be divided.
  84      * @return {@code this / val}
  85      *
  86      * @since 1.0
  87      */
  88     UnsignedWord unsignedDivide(UnsignedWord val);
  89 
  90     /**
  91      * Returns a Unsigned whose value is {@code (this % val)}.
  92      *
  93      * @param val value by which this Unsigned is to be divided, and the remainder computed.
  94      * @return {@code this % val}
  95      *
  96      * @since 1.0
  97      */
  98     UnsignedWord unsignedRemainder(UnsignedWord val);
  99 
 100     /**
 101      * Returns a Unsigned whose value is {@code (this << n)}.
 102      *
 103      * @param n shift distance, in bits.
 104      * @return {@code this << n}
 105      *
 106      * @since 1.0
 107      */
 108     UnsignedWord shiftLeft(UnsignedWord n);
 109 
 110     /**
 111      * Returns a Unsigned whose value is {@code (this >>> n)}. No sign extension is performed.
 112      *
 113      * @param n shift distance, in bits.
 114      * @return {@code this >> n}
 115      *
 116      * @since 1.0
 117      */
 118     UnsignedWord unsignedShiftRight(UnsignedWord n);
 119 
 120     /**
 121      * Returns a Unsigned whose value is {@code (this & val)}.
 122      *
 123      * @param val value to be AND'ed with this Unsigned.
 124      * @return {@code this & val}
 125      *
 126      * @since 1.0
 127      */
 128     UnsignedWord and(UnsignedWord val);
 129 
 130     /**
 131      * Returns a Unsigned whose value is {@code (this | val)}.
 132      *
 133      * @param val value to be OR'ed with this Unsigned.
 134      * @return {@code this | val}
 135      *
 136      * @since 1.0
 137      */
 138     UnsignedWord or(UnsignedWord val);
 139 
 140     /**
 141      * Returns a Unsigned whose value is {@code (this ^ val)}.
 142      *
 143      * @param val value to be XOR'ed with this Unsigned.
 144      * @return {@code this ^ val}
 145      *
 146      * @since 1.0
 147      */
 148     UnsignedWord xor(UnsignedWord val);
 149 
 150     /**
 151      * Returns a Unsigned whose value is {@code (~this)}.
 152      *
 153      * @return {@code ~this}
 154      *
 155      * @since 1.0
 156      */
 157     UnsignedWord not();
 158 
 159     /**
 160      * Compares this Unsigned with the specified value.
 161      *
 162      * @param val value to which this Unsigned is to be compared.
 163      * @return {@code this == val}
 164      *
 165      * @since 1.0
 166      */
 167     boolean equal(UnsignedWord val);
 168 
 169     /**
 170      * Compares this Unsigned with the specified value.
 171      *
 172      * @param val value to which this Unsigned is to be compared.
 173      * @return {@code this != val}
 174      *
 175      * @since 1.0
 176      */
 177     boolean notEqual(UnsignedWord val);
 178 
 179     /**
 180      * Compares this Unsigned with the specified value.
 181      *
 182      * @param val value to which this Unsigned is to be compared.
 183      * @return {@code this < val}
 184      *
 185      * @since 1.0
 186      */
 187     boolean belowThan(UnsignedWord val);
 188 
 189     /**
 190      * Compares this Unsigned with the specified value.
 191      *
 192      * @param val value to which this Unsigned is to be compared.
 193      * @return {@code this <= val}
 194      *
 195      * @since 1.0
 196      */
 197     boolean belowOrEqual(UnsignedWord val);
 198 
 199     /**
 200      * Compares this Unsigned with the specified value.
 201      *
 202      * @param val value to which this Unsigned is to be compared.
 203      * @return {@code this > val}
 204      *
 205      * @since 1.0
 206      */
 207     boolean aboveThan(UnsignedWord val);
 208 
 209     /**
 210      * Compares this Unsigned with the specified value.
 211      *
 212      * @param val value to which this Unsigned is to be compared.
 213      * @return {@code this >= val}
 214      *
 215      * @since 1.0
 216      */
 217     boolean aboveOrEqual(UnsignedWord val);
 218 
 219     /**
 220      * Returns a Unsigned whose value is {@code (this + val)}.
 221      * <p>
 222      * Note that the right operand is a signed value, while the operation is performed unsigned.
 223      * Therefore, the result is only well-defined for positive right operands.
 224      *
 225      * @param val value to be added to this Unsigned.
 226      * @return {@code this + val}
 227      *
 228      * @since 1.0
 229      */
 230     UnsignedWord add(int val);
 231 
 232     /**
 233      * Returns a Unsigned whose value is {@code (this - val)}.
 234      * <p>
 235      * Note that the right operand is a signed value, while the operation is performed unsigned.
 236      * Therefore, the result is only well-defined for positive right operands.
 237      *
 238      * @param val value to be subtracted from this Unsigned.
 239      * @return {@code this - val}
 240      *
 241      * @since 1.0
 242      */
 243     UnsignedWord subtract(int val);
 244 
 245     /**
 246      * Returns a Unsigned whose value is {@code (this * val)}.
 247      * <p>
 248      * Note that the right operand is a signed value, while the operation is performed unsigned.
 249      * Therefore, the result is only well-defined for positive right operands.
 250      *
 251      * @param val value to be multiplied by this Unsigned.
 252      * @return {@code this * val}
 253      *
 254      * @since 1.0
 255      */
 256     UnsignedWord multiply(int val);
 257 
 258     /**
 259      * Returns a Unsigned whose value is {@code (this / val)}.
 260      * <p>
 261      * Note that the right operand is a signed value, while the operation is performed unsigned.
 262      * Therefore, the result is only well-defined for positive right operands.
 263      *
 264      * @param val value by which this Unsigned is to be divided.
 265      * @return {@code this / val}
 266      *
 267      * @since 1.0
 268      */
 269     UnsignedWord unsignedDivide(int val);
 270 
 271     /**
 272      * Returns a Unsigned whose value is {@code (this % val)}.
 273      * <p>
 274      * Note that the right operand is a signed value, while the operation is performed unsigned.
 275      * Therefore, the result is only well-defined for positive right operands.
 276      *
 277      * @param val value by which this Unsigned is to be divided, and the remainder computed.
 278      * @return {@code this % val}
 279      *
 280      * @since 1.0
 281      */
 282     UnsignedWord unsignedRemainder(int val);
 283 
 284     /**
 285      * Returns a Unsigned whose value is {@code (this << n)}.
 286      * <p>
 287      * Note that the right operand is a signed value, while the operation is performed unsigned.
 288      * Therefore, the result is only well-defined for positive right operands.
 289      *
 290      * @param n shift distance, in bits.
 291      * @return {@code this << n}
 292      *
 293      * @since 1.0
 294      */
 295     UnsignedWord shiftLeft(int n);
 296 
 297     /**
 298      * Returns a Unsigned whose value is {@code (this >>> n)}. No sign extension is performed.
 299      * <p>
 300      * Note that the right operand is a signed value, while the operation is performed unsigned.
 301      * Therefore, the result is only well-defined for positive right operands.
 302      *
 303      * @param n shift distance, in bits.
 304      * @return {@code this >> n}
 305      *
 306      * @since 1.0
 307      */
 308     UnsignedWord unsignedShiftRight(int n);
 309 
 310     /**
 311      * Returns a Unsigned whose value is {@code (this & val)}.
 312      * <p>
 313      * Note that the right operand is a signed value, while the operation is performed unsigned.
 314      * Therefore, the result is only well-defined for positive right operands.
 315      *
 316      * @param val value to be AND'ed with this Unsigned.
 317      * @return {@code this & val}
 318      *
 319      * @since 1.0
 320      */
 321     UnsignedWord and(int val);
 322 
 323     /**
 324      * Returns a Unsigned whose value is {@code (this | val)}.
 325      * <p>
 326      * Note that the right operand is a signed value, while the operation is performed unsigned.
 327      * Therefore, the result is only well-defined for positive right operands.
 328      *
 329      * @param val value to be OR'ed with this Unsigned.
 330      * @return {@code this | val}
 331      *
 332      * @since 1.0
 333      */
 334     UnsignedWord or(int val);
 335 
 336     /**
 337      * Returns a Unsigned whose value is {@code (this ^ val)}.
 338      * <p>
 339      * Note that the right operand is a signed value, while the operation is performed unsigned.
 340      * Therefore, the result is only well-defined for positive right operands.
 341      *
 342      * @param val value to be XOR'ed with this Unsigned.
 343      * @return {@code this ^ val}
 344      *
 345      * @since 1.0
 346      */
 347     UnsignedWord xor(int val);
 348 
 349     /**
 350      * Compares this Unsigned with the specified value.
 351      * <p>
 352      * Note that the right operand is a signed value, while the operation is performed unsigned.
 353      * Therefore, the result is only well-defined for positive right operands.
 354      *
 355      * @param val value to which this Unsigned is to be compared.
 356      * @return {@code this == val}
 357      *
 358      * @since 1.0
 359      */
 360     boolean equal(int val);
 361 
 362     /**
 363      * Compares this Unsigned with the specified value.
 364      * <p>
 365      * Note that the right operand is a signed value, while the operation is performed unsigned.
 366      * Therefore, the result is only well-defined for positive right operands.
 367      *
 368      * @param val value to which this Unsigned is to be compared.
 369      * @return {@code this != val}
 370      *
 371      * @since 1.0
 372      */
 373     boolean notEqual(int val);
 374 
 375     /**
 376      * Compares this Unsigned with the specified value.
 377      * <p>
 378      * Note that the right operand is a signed value, while the operation is performed unsigned.
 379      * Therefore, the result is only well-defined for positive right operands.
 380      *
 381      * @param val value to which this Unsigned is to be compared.
 382      * @return {@code this < val}
 383      *
 384      * @since 1.0
 385      */
 386     boolean belowThan(int val);
 387 
 388     /**
 389      * Compares this Unsigned with the specified value.
 390      * <p>
 391      * Note that the right operand is a signed value, while the operation is performed unsigned.
 392      * Therefore, the result is only well-defined for positive right operands.
 393      *
 394      * @param val value to which this Unsigned is to be compared.
 395      * @return {@code this <= val}
 396      *
 397      * @since 1.0
 398      */
 399     boolean belowOrEqual(int val);
 400 
 401     /**
 402      * Compares this Unsigned with the specified value.
 403      * <p>
 404      * Note that the right operand is a signed value, while the operation is performed unsigned.
 405      * Therefore, the result is only well-defined for positive right operands.
 406      *
 407      * @param val value to which this Unsigned is to be compared.
 408      * @return {@code this > val}
 409      *
 410      * @since 1.0
 411      */
 412     boolean aboveThan(int val);
 413 
 414     /**
 415      * Compares this Unsigned with the specified value.
 416      * <p>
 417      * Note that the right operand is a signed value, while the operation is performed unsigned.
 418      * Therefore, the result is only well-defined for positive right operands.
 419      *
 420      * @param val value to which this Unsigned is to be compared.
 421      * @return {@code this >= val}
 422      *
 423      * @since 1.0
 424      */
 425     boolean aboveOrEqual(int val);
 426 }