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 Signed extends ComparableWord {
  26 
  27     /**
  28      * Returns a Signed whose value is {@code (this + val)}.
  29      *
  30      * @param val value to be added to this Signed.
  31      * @return {@code this + val}
  32      */
  33     Signed add(Signed val);
  34 
  35     /**
  36      * Returns a Signed whose value is {@code (this - val)}.
  37      *
  38      * @param val value to be subtracted from this Signed.
  39      * @return {@code this - val}
  40      */
  41     Signed subtract(Signed val);
  42 
  43     /**
  44      * Returns a Signed whose value is {@code (this * val)}.
  45      *
  46      * @param val value to be multiplied by this Signed.
  47      * @return {@code this * val}
  48      */
  49     Signed multiply(Signed val);
  50 
  51     /**
  52      * Returns a Signed whose value is {@code (this / val)}.
  53      *
  54      * @param val value by which this Signed is to be divided.
  55      * @return {@code this / val}
  56      */
  57     Signed signedDivide(Signed val);
  58 
  59     /**
  60      * Returns a Signed whose value is {@code (this % val)}.
  61      *
  62      * @param val value by which this Signed is to be divided, and the remainder computed.
  63      * @return {@code this % val}
  64      */
  65     Signed signedRemainder(Signed val);
  66 
  67     /**
  68      * Returns a Signed whose value is {@code (this << n)}.
  69      *
  70      * @param n shift distance, in bits.
  71      * @return {@code this << n}
  72      */
  73     Signed shiftLeft(Unsigned n);
  74 
  75     /**
  76      * Returns a Signed whose value is {@code (this >> n)}. Sign extension is performed.
  77      *
  78      * @param n shift distance, in bits.
  79      * @return {@code this >> n}
  80      */
  81     Signed signedShiftRight(Unsigned n);
  82 
  83     /**
  84      * Returns a Signed whose value is {@code (this & val)}. (This method returns a negative Signed
  85      * if and only if this and val are both negative.)
  86      *
  87      * @param val value to be AND'ed with this Signed.
  88      * @return {@code this & val}
  89      */
  90     Signed and(Signed val);
  91 
  92     /**
  93      * Returns a Signed whose value is {@code (this | val)}. (This method returns a negative Signed
  94      * if and only if either this or val is negative.)
  95      *
  96      * @param val value to be OR'ed with this Signed.
  97      * @return {@code this | val}
  98      */
  99     Signed or(Signed val);
 100 
 101     /**
 102      * Returns a Signed whose value is {@code (this ^ val)}. (This method returns a negative Signed
 103      * if and only if exactly one of this and val are negative.)
 104      *
 105      * @param val value to be XOR'ed with this Signed.
 106      * @return {@code this ^ val}
 107      */
 108     Signed xor(Signed val);
 109 
 110     /**
 111      * Returns a Signed whose value is {@code (~this)}. (This method returns a negative value if and
 112      * only if this Signed is non-negative.)
 113      *
 114      * @return {@code ~this}
 115      */
 116     Signed not();
 117 
 118     /**
 119      * Compares this Signed with the specified value.
 120      *
 121      * @param val value to which this Signed is to be compared.
 122      * @return {@code this == val}
 123      */
 124     boolean equal(Signed val);
 125 
 126     /**
 127      * Compares this Signed with the specified value.
 128      *
 129      * @param val value to which this Signed is to be compared.
 130      * @return {@code this != val}
 131      */
 132     boolean notEqual(Signed val);
 133 
 134     /**
 135      * Compares this Signed with the specified value.
 136      *
 137      * @param val value to which this Signed is to be compared.
 138      * @return {@code this < val}
 139      */
 140     boolean lessThan(Signed val);
 141 
 142     /**
 143      * Compares this Signed with the specified value.
 144      *
 145      * @param val value to which this Signed is to be compared.
 146      * @return {@code this <= val}
 147      */
 148     boolean lessOrEqual(Signed val);
 149 
 150     /**
 151      * Compares this Signed with the specified value.
 152      *
 153      * @param val value to which this Signed is to be compared.
 154      * @return {@code this > val}
 155      */
 156     boolean greaterThan(Signed val);
 157 
 158     /**
 159      * Compares this Signed with the specified value.
 160      *
 161      * @param val value to which this Signed is to be compared.
 162      * @return {@code this >= val}
 163      */
 164     boolean greaterOrEqual(Signed val);
 165 
 166     /**
 167      * Returns a Signed whose value is {@code (this + val)}.
 168      *
 169      * @param val value to be added to this Signed.
 170      * @return {@code this + val}
 171      */
 172     Signed add(int val);
 173 
 174     /**
 175      * Returns a Signed whose value is {@code (this - val)}.
 176      *
 177      * @param val value to be subtracted from this Signed.
 178      * @return {@code this - val}
 179      */
 180     Signed subtract(int val);
 181 
 182     /**
 183      * Returns a Signed whose value is {@code (this * val)}.
 184      *
 185      * @param val value to be multiplied by this Signed.
 186      * @return {@code this * val}
 187      */
 188     Signed multiply(int val);
 189 
 190     /**
 191      * Returns a Signed whose value is {@code (this / val)}.
 192      *
 193      * @param val value by which this Signed is to be divided.
 194      * @return {@code this / val}
 195      */
 196     Signed signedDivide(int val);
 197 
 198     /**
 199      * Returns a Signed whose value is {@code (this % val)}.
 200      *
 201      * @param val value by which this Signed is to be divided, and the remainder computed.
 202      * @return {@code this % val}
 203      */
 204     Signed signedRemainder(int val);
 205 
 206     /**
 207      * Returns a Signed whose value is {@code (this << n)}.
 208      *
 209      * @param n shift distance, in bits.
 210      * @return {@code this << n}
 211      */
 212     Signed shiftLeft(int n);
 213 
 214     /**
 215      * Returns a Signed whose value is {@code (this >> n)}. Sign extension is performed.
 216      *
 217      * @param n shift distance, in bits.
 218      * @return {@code this >> n}
 219      */
 220     Signed signedShiftRight(int n);
 221 
 222     /**
 223      * Returns a Signed whose value is {@code (this & val)}. (This method returns a negative Signed
 224      * if and only if this and val are both negative.)
 225      *
 226      * @param val value to be AND'ed with this Signed.
 227      * @return {@code this & val}
 228      */
 229     Signed and(int val);
 230 
 231     /**
 232      * Returns a Signed whose value is {@code (this | val)}. (This method returns a negative Signed
 233      * if and only if either this or val is negative.)
 234      *
 235      * @param val value to be OR'ed with this Signed.
 236      * @return {@code this | val}
 237      */
 238     Signed or(int val);
 239 
 240     /**
 241      * Returns a Signed whose value is {@code (this ^ val)}. (This method returns a negative Signed
 242      * if and only if exactly one of this and val are negative.)
 243      *
 244      * @param val value to be XOR'ed with this Signed.
 245      * @return {@code this ^ val}
 246      */
 247     Signed xor(int val);
 248 
 249     /**
 250      * Compares this Signed with the specified value.
 251      *
 252      * @param val value to which this Signed is to be compared.
 253      * @return {@code this == val}
 254      */
 255     boolean equal(int val);
 256 
 257     /**
 258      * Compares this Signed with the specified value.
 259      *
 260      * @param val value to which this Signed is to be compared.
 261      * @return {@code this != val}
 262      */
 263     boolean notEqual(int val);
 264 
 265     /**
 266      * Compares this Signed with the specified value.
 267      *
 268      * @param val value to which this Signed is to be compared.
 269      * @return {@code this < val}
 270      */
 271     boolean lessThan(int val);
 272 
 273     /**
 274      * Compares this Signed with the specified value.
 275      *
 276      * @param val value to which this Signed is to be compared.
 277      * @return {@code this <= val}
 278      */
 279     boolean lessOrEqual(int val);
 280 
 281     /**
 282      * Compares this Signed with the specified value.
 283      *
 284      * @param val value to which this Signed is to be compared.
 285      * @return {@code this > val}
 286      */
 287     boolean greaterThan(int val);
 288 
 289     /**
 290      * Compares this Signed with the specified value.
 291      *
 292      * @param val value to which this Signed is to be compared.
 293      * @return {@code this >= val}
 294      */
 295     boolean greaterOrEqual(int val);
 296 }