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 a signed word-sized value.
  45  *
  46  * @since 1.0
  47  */
  48 public interface SignedWord extends ComparableWord {
  49 
  50     /**
  51      * Returns a Signed whose value is {@code (this + val)}.
  52      *
  53      * @param val value to be added to this Signed.
  54      * @return {@code this + val}
  55      *
  56      * @since 1.0
  57      */
  58     SignedWord add(SignedWord val);
  59 
  60     /**
  61      * Returns a Signed whose value is {@code (this - val)}.
  62      *
  63      * @param val value to be subtracted from this Signed.
  64      * @return {@code this - val}
  65      *
  66      * @since 1.0
  67      */
  68     SignedWord subtract(SignedWord val);
  69 
  70     /**
  71      * Returns a Signed whose value is {@code (this * val)}.
  72      *
  73      * @param val value to be multiplied by this Signed.
  74      * @return {@code this * val}
  75      *
  76      * @since 1.0
  77      */
  78     SignedWord multiply(SignedWord val);
  79 
  80     /**
  81      * Returns a Signed whose value is {@code (this / val)}.
  82      *
  83      * @param val value by which this Signed is to be divided.
  84      * @return {@code this / val}
  85      *
  86      * @since 1.0
  87      */
  88     SignedWord signedDivide(SignedWord val);
  89 
  90     /**
  91      * Returns a Signed whose value is {@code (this % val)}.
  92      *
  93      * @param val value by which this Signed is to be divided, and the remainder computed.
  94      * @return {@code this % val}
  95      *
  96      * @since 1.0
  97      */
  98     SignedWord signedRemainder(SignedWord val);
  99 
 100     /**
 101      * Returns a Signed 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     SignedWord shiftLeft(UnsignedWord n);
 109 
 110     /**
 111      * Returns a Signed whose value is {@code (this >> n)}. Sign extension is performed.
 112      *
 113      * @param n shift distance, in bits.
 114      * @return {@code this >> n}
 115      *
 116      * @since 1.0
 117      */
 118     SignedWord signedShiftRight(UnsignedWord n);
 119 
 120     /**
 121      * Returns a Signed whose value is {@code (this & val)}. (This method returns a negative Signed
 122      * if and only if this and val are both negative.)
 123      *
 124      * @param val value to be AND'ed with this Signed.
 125      * @return {@code this & val}
 126      *
 127      * @since 1.0
 128      */
 129     SignedWord and(SignedWord val);
 130 
 131     /**
 132      * Returns a Signed whose value is {@code (this | val)}. (This method returns a negative Signed
 133      * if and only if either this or val is negative.)
 134      *
 135      * @param val value to be OR'ed with this Signed.
 136      * @return {@code this | val}
 137      *
 138      * @since 1.0
 139      */
 140     SignedWord or(SignedWord val);
 141 
 142     /**
 143      * Returns a Signed whose value is {@code (this ^ val)}. (This method returns a negative Signed
 144      * if and only if exactly one of this and val are negative.)
 145      *
 146      * @param val value to be XOR'ed with this Signed.
 147      * @return {@code this ^ val}
 148      *
 149      * @since 1.0
 150      */
 151     SignedWord xor(SignedWord val);
 152 
 153     /**
 154      * Returns a Signed whose value is {@code (~this)}. (This method returns a negative value if and
 155      * only if this Signed is non-negative.)
 156      *
 157      * @return {@code ~this}
 158      *
 159      * @since 1.0
 160      */
 161     SignedWord not();
 162 
 163     /**
 164      * Compares this Signed with the specified value.
 165      *
 166      * @param val value to which this Signed is to be compared.
 167      * @return {@code this == val}
 168      *
 169      * @since 1.0
 170      */
 171     boolean equal(SignedWord val);
 172 
 173     /**
 174      * Compares this Signed with the specified value.
 175      *
 176      * @param val value to which this Signed is to be compared.
 177      * @return {@code this != val}
 178      *
 179      * @since 1.0
 180      */
 181     boolean notEqual(SignedWord val);
 182 
 183     /**
 184      * Compares this Signed with the specified value.
 185      *
 186      * @param val value to which this Signed is to be compared.
 187      * @return {@code this < val}
 188      *
 189      * @since 1.0
 190      */
 191     boolean lessThan(SignedWord val);
 192 
 193     /**
 194      * Compares this Signed with the specified value.
 195      *
 196      * @param val value to which this Signed is to be compared.
 197      * @return {@code this <= val}
 198      *
 199      * @since 1.0
 200      */
 201     boolean lessOrEqual(SignedWord val);
 202 
 203     /**
 204      * Compares this Signed with the specified value.
 205      *
 206      * @param val value to which this Signed is to be compared.
 207      * @return {@code this > val}
 208      *
 209      * @since 1.0
 210      */
 211     boolean greaterThan(SignedWord val);
 212 
 213     /**
 214      * Compares this Signed with the specified value.
 215      *
 216      * @param val value to which this Signed is to be compared.
 217      * @return {@code this >= val}
 218      *
 219      * @since 1.0
 220      */
 221     boolean greaterOrEqual(SignedWord val);
 222 
 223     /**
 224      * Returns a Signed whose value is {@code (this + val)}.
 225      *
 226      * @param val value to be added to this Signed.
 227      * @return {@code this + val}
 228      *
 229      * @since 1.0
 230      */
 231     SignedWord add(int val);
 232 
 233     /**
 234      * Returns a Signed whose value is {@code (this - val)}.
 235      *
 236      * @param val value to be subtracted from this Signed.
 237      * @return {@code this - val}
 238      *
 239      * @since 1.0
 240      */
 241     SignedWord subtract(int val);
 242 
 243     /**
 244      * Returns a Signed whose value is {@code (this * val)}.
 245      *
 246      * @param val value to be multiplied by this Signed.
 247      * @return {@code this * val}
 248      *
 249      * @since 1.0
 250      */
 251     SignedWord multiply(int val);
 252 
 253     /**
 254      * Returns a Signed whose value is {@code (this / val)}.
 255      *
 256      * @param val value by which this Signed is to be divided.
 257      * @return {@code this / val}
 258      *
 259      * @since 1.0
 260      */
 261     SignedWord signedDivide(int val);
 262 
 263     /**
 264      * Returns a Signed whose value is {@code (this % val)}.
 265      *
 266      * @param val value by which this Signed is to be divided, and the remainder computed.
 267      * @return {@code this % val}
 268      *
 269      * @since 1.0
 270      */
 271     SignedWord signedRemainder(int val);
 272 
 273     /**
 274      * Returns a Signed whose value is {@code (this << n)}.
 275      *
 276      * @param n shift distance, in bits.
 277      * @return {@code this << n}
 278      *
 279      * @since 1.0
 280      */
 281     SignedWord shiftLeft(int n);
 282 
 283     /**
 284      * Returns a Signed whose value is {@code (this >> n)}. Sign extension is performed.
 285      *
 286      * @param n shift distance, in bits.
 287      * @return {@code this >> n}
 288      *
 289      * @since 1.0
 290      */
 291     SignedWord signedShiftRight(int n);
 292 
 293     /**
 294      * Returns a Signed whose value is {@code (this & val)}. (This method returns a negative Signed
 295      * if and only if this and val are both negative.)
 296      *
 297      * @param val value to be AND'ed with this Signed.
 298      * @return {@code this & val}
 299      *
 300      * @since 1.0
 301      */
 302     SignedWord and(int val);
 303 
 304     /**
 305      * Returns a Signed whose value is {@code (this | val)}. (This method returns a negative Signed
 306      * if and only if either this or val is negative.)
 307      *
 308      * @param val value to be OR'ed with this Signed.
 309      * @return {@code this | val}
 310      *
 311      * @since 1.0
 312      */
 313     SignedWord or(int val);
 314 
 315     /**
 316      * Returns a Signed whose value is {@code (this ^ val)}. (This method returns a negative Signed
 317      * if and only if exactly one of this and val are negative.)
 318      *
 319      * @param val value to be XOR'ed with this Signed.
 320      * @return {@code this ^ val}
 321      *
 322      * @since 1.0
 323      */
 324     SignedWord xor(int val);
 325 
 326     /**
 327      * Compares this Signed with the specified value.
 328      *
 329      * @param val value to which this Signed is to be compared.
 330      * @return {@code this == val}
 331      *
 332      * @since 1.0
 333      */
 334     boolean equal(int val);
 335 
 336     /**
 337      * Compares this Signed with the specified value.
 338      *
 339      * @param val value to which this Signed is to be compared.
 340      * @return {@code this != val}
 341      *
 342      * @since 1.0
 343      */
 344     boolean notEqual(int val);
 345 
 346     /**
 347      * Compares this Signed with the specified value.
 348      *
 349      * @param val value to which this Signed is to be compared.
 350      * @return {@code this < val}
 351      *
 352      * @since 1.0
 353      */
 354     boolean lessThan(int val);
 355 
 356     /**
 357      * Compares this Signed with the specified value.
 358      *
 359      * @param val value to which this Signed is to be compared.
 360      * @return {@code this <= val}
 361      *
 362      * @since 1.0
 363      */
 364     boolean lessOrEqual(int val);
 365 
 366     /**
 367      * Compares this Signed with the specified value.
 368      *
 369      * @param val value to which this Signed is to be compared.
 370      * @return {@code this > val}
 371      *
 372      * @since 1.0
 373      */
 374     boolean greaterThan(int val);
 375 
 376     /**
 377      * Compares this Signed with the specified value.
 378      *
 379      * @param val value to which this Signed is to be compared.
 380      * @return {@code this >= val}
 381      *
 382      * @since 1.0
 383      */
 384     boolean greaterOrEqual(int val);
 385 }