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