UnsignedWord.java revision 13304:5e9c41536bd2
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.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25package org.graalvm.word;
26
27public interface UnsignedWord extends ComparableWord {
28
29    /**
30     * Returns a Unsigned whose value is {@code (this + val)}.
31     *
32     * @param val value to be added to this Unsigned.
33     * @return {@code this + val}
34     */
35    UnsignedWord add(UnsignedWord val);
36
37    /**
38     * Returns a Unsigned whose value is {@code (this - val)}.
39     *
40     * @param val value to be subtracted from this Unsigned.
41     * @return {@code this - val}
42     */
43    UnsignedWord subtract(UnsignedWord val);
44
45    /**
46     * Returns a Unsigned whose value is {@code (this * val)}.
47     *
48     * @param val value to be multiplied by this Unsigned.
49     * @return {@code this * val}
50     */
51    UnsignedWord multiply(UnsignedWord val);
52
53    /**
54     * Returns a Unsigned whose value is {@code (this / val)}.
55     *
56     * @param val value by which this Unsigned is to be divided.
57     * @return {@code this / val}
58     */
59    UnsignedWord unsignedDivide(UnsignedWord val);
60
61    /**
62     * Returns a Unsigned whose value is {@code (this % val)}.
63     *
64     * @param val value by which this Unsigned is to be divided, and the remainder computed.
65     * @return {@code this % val}
66     */
67    UnsignedWord unsignedRemainder(UnsignedWord val);
68
69    /**
70     * Returns a Unsigned whose value is {@code (this << n)}.
71     *
72     * @param n shift distance, in bits.
73     * @return {@code this << n}
74     */
75    UnsignedWord shiftLeft(UnsignedWord n);
76
77    /**
78     * Returns a Unsigned whose value is {@code (this >>> n)}. No sign extension is performed.
79     *
80     * @param n shift distance, in bits.
81     * @return {@code this >> n}
82     */
83    UnsignedWord unsignedShiftRight(UnsignedWord n);
84
85    /**
86     * Returns a Unsigned whose value is {@code (this & val)}.
87     *
88     * @param val value to be AND'ed with this Unsigned.
89     * @return {@code this & val}
90     */
91    UnsignedWord and(UnsignedWord val);
92
93    /**
94     * Returns a Unsigned whose value is {@code (this | val)}.
95     *
96     * @param val value to be OR'ed with this Unsigned.
97     * @return {@code this | val}
98     */
99    UnsignedWord or(UnsignedWord val);
100
101    /**
102     * Returns a Unsigned whose value is {@code (this ^ val)}.
103     *
104     * @param val value to be XOR'ed with this Unsigned.
105     * @return {@code this ^ val}
106     */
107    UnsignedWord xor(UnsignedWord val);
108
109    /**
110     * Returns a Unsigned whose value is {@code (~this)}.
111     *
112     * @return {@code ~this}
113     */
114    UnsignedWord not();
115
116    /**
117     * Compares this Unsigned with the specified value.
118     *
119     * @param val value to which this Unsigned is to be compared.
120     * @return {@code this == val}
121     */
122    boolean equal(UnsignedWord val);
123
124    /**
125     * Compares this Unsigned with the specified value.
126     *
127     * @param val value to which this Unsigned is to be compared.
128     * @return {@code this != val}
129     */
130    boolean notEqual(UnsignedWord val);
131
132    /**
133     * Compares this Unsigned with the specified value.
134     *
135     * @param val value to which this Unsigned is to be compared.
136     * @return {@code this < val}
137     */
138    boolean belowThan(UnsignedWord val);
139
140    /**
141     * Compares this Unsigned with the specified value.
142     *
143     * @param val value to which this Unsigned is to be compared.
144     * @return {@code this <= val}
145     */
146    boolean belowOrEqual(UnsignedWord val);
147
148    /**
149     * Compares this Unsigned with the specified value.
150     *
151     * @param val value to which this Unsigned is to be compared.
152     * @return {@code this > val}
153     */
154    boolean aboveThan(UnsignedWord val);
155
156    /**
157     * Compares this Unsigned with the specified value.
158     *
159     * @param val value to which this Unsigned is to be compared.
160     * @return {@code this >= val}
161     */
162    boolean aboveOrEqual(UnsignedWord val);
163
164    /**
165     * Returns a Unsigned whose value is {@code (this + val)}.
166     * <p>
167     * Note that the right operand is a signed value, while the operation is performed unsigned.
168     * Therefore, the result is only well-defined for positive right operands.
169     *
170     * @param val value to be added to this Unsigned.
171     * @return {@code this + val}
172     */
173    UnsignedWord add(int val);
174
175    /**
176     * Returns a Unsigned whose value is {@code (this - val)}.
177     * <p>
178     * Note that the right operand is a signed value, while the operation is performed unsigned.
179     * Therefore, the result is only well-defined for positive right operands.
180     *
181     * @param val value to be subtracted from this Unsigned.
182     * @return {@code this - val}
183     */
184    UnsignedWord subtract(int val);
185
186    /**
187     * Returns a Unsigned whose value is {@code (this * val)}.
188     * <p>
189     * Note that the right operand is a signed value, while the operation is performed unsigned.
190     * Therefore, the result is only well-defined for positive right operands.
191     *
192     * @param val value to be multiplied by this Unsigned.
193     * @return {@code this * val}
194     */
195    UnsignedWord multiply(int val);
196
197    /**
198     * Returns a Unsigned whose value is {@code (this / val)}.
199     * <p>
200     * Note that the right operand is a signed value, while the operation is performed unsigned.
201     * Therefore, the result is only well-defined for positive right operands.
202     *
203     * @param val value by which this Unsigned is to be divided.
204     * @return {@code this / val}
205     */
206    UnsignedWord unsignedDivide(int val);
207
208    /**
209     * Returns a Unsigned whose value is {@code (this % val)}.
210     * <p>
211     * Note that the right operand is a signed value, while the operation is performed unsigned.
212     * Therefore, the result is only well-defined for positive right operands.
213     *
214     * @param val value by which this Unsigned is to be divided, and the remainder computed.
215     * @return {@code this % val}
216     */
217    UnsignedWord unsignedRemainder(int val);
218
219    /**
220     * Returns a Unsigned whose value is {@code (this << n)}.
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 n shift distance, in bits.
226     * @return {@code this << n}
227     */
228    UnsignedWord shiftLeft(int n);
229
230    /**
231     * Returns a Unsigned whose value is {@code (this >>> n)}. No sign extension is performed.
232     * <p>
233     * Note that the right operand is a signed value, while the operation is performed unsigned.
234     * Therefore, the result is only well-defined for positive right operands.
235     *
236     * @param n shift distance, in bits.
237     * @return {@code this >> n}
238     */
239    UnsignedWord unsignedShiftRight(int n);
240
241    /**
242     * Returns a Unsigned whose value is {@code (this & val)}.
243     * <p>
244     * Note that the right operand is a signed value, while the operation is performed unsigned.
245     * Therefore, the result is only well-defined for positive right operands.
246     *
247     * @param val value to be AND'ed with this Unsigned.
248     * @return {@code this & val}
249     */
250    UnsignedWord and(int val);
251
252    /**
253     * Returns a Unsigned whose value is {@code (this | val)}.
254     * <p>
255     * Note that the right operand is a signed value, while the operation is performed unsigned.
256     * Therefore, the result is only well-defined for positive right operands.
257     *
258     * @param val value to be OR'ed with this Unsigned.
259     * @return {@code this | val}
260     */
261    UnsignedWord or(int val);
262
263    /**
264     * Returns a Unsigned whose value is {@code (this ^ val)}.
265     * <p>
266     * Note that the right operand is a signed value, while the operation is performed unsigned.
267     * Therefore, the result is only well-defined for positive right operands.
268     *
269     * @param val value to be XOR'ed with this Unsigned.
270     * @return {@code this ^ val}
271     */
272    UnsignedWord xor(int val);
273
274    /**
275     * Compares this Unsigned with the specified value.
276     * <p>
277     * Note that the right operand is a signed value, while the operation is performed unsigned.
278     * Therefore, the result is only well-defined for positive right operands.
279     *
280     * @param val value to which this Unsigned is to be compared.
281     * @return {@code this == val}
282     */
283    boolean equal(int val);
284
285    /**
286     * Compares this Unsigned with the specified value.
287     * <p>
288     * Note that the right operand is a signed value, while the operation is performed unsigned.
289     * Therefore, the result is only well-defined for positive right operands.
290     *
291     * @param val value to which this Unsigned is to be compared.
292     * @return {@code this != val}
293     */
294    boolean notEqual(int val);
295
296    /**
297     * Compares this Unsigned with the specified value.
298     * <p>
299     * Note that the right operand is a signed value, while the operation is performed unsigned.
300     * Therefore, the result is only well-defined for positive right operands.
301     *
302     * @param val value to which this Unsigned is to be compared.
303     * @return {@code this < val}
304     */
305    boolean belowThan(int val);
306
307    /**
308     * Compares this Unsigned with the specified value.
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 which this Unsigned is to be compared.
314     * @return {@code this <= val}
315     */
316    boolean belowOrEqual(int val);
317
318    /**
319     * Compares this Unsigned with the specified value.
320     * <p>
321     * Note that the right operand is a signed value, while the operation is performed unsigned.
322     * Therefore, the result is only well-defined for positive right operands.
323     *
324     * @param val value to which this Unsigned is to be compared.
325     * @return {@code this > val}
326     */
327    boolean aboveThan(int val);
328
329    /**
330     * Compares this Unsigned with the specified value.
331     * <p>
332     * Note that the right operand is a signed value, while the operation is performed unsigned.
333     * Therefore, the result is only well-defined for positive right operands.
334     *
335     * @param val value to which this Unsigned is to be compared.
336     * @return {@code this >= val}
337     */
338    boolean aboveOrEqual(int val);
339}
340