001/* 002 * This file is part of the Jikes RVM project (http://jikesrvm.org). 003 * 004 * This file is licensed to You under the Eclipse Public License (EPL); 005 * You may not use this file except in compliance with the License. You 006 * may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/eclipse-1.0.php 009 * 010 * See the COPYRIGHT.txt file distributed with this work for information 011 * regarding copyright ownership. 012 */ 013package org.vmmagic.unboxed; 014 015import org.vmmagic.Unboxed; 016import org.vmmagic.pragma.RawStorage; 017 018/** 019 * A generic pointer-sized integer. Can be converted to/from other pointer-sized types, and 020 * provides shifting and masking operations. 021 */ 022@Unboxed 023@RawStorage(lengthInWords = true, length = 1) 024public final class Word { 025 026 /** 027 * Converts an int to a word. On 64-bit machines, sign-extend the high order bit. 028 * 029 * @param val the value to convert to a word 030 * @return A word instance whose value is val, sign-extended on 64 bit machines 031 */ 032 public static Word fromIntSignExtend(int val) { 033 return null; 034 } 035 036 /** 037 * Converts an int to a word. On 64-bit machines, zero-extend the high order bit. 038 * 039 * @param val the value to convert to a word 040 * @return A word instance whose value is val, zero-extended on 64 bit machines 041 */ 042 public static Word fromIntZeroExtend(int val) { 043 return null; 044 } 045 046 /** 047 * Converts a long to a word. On 64-bit this is a no-op, on 32-bit the long is truncated. 048 * 049 * @param val the value to convert to a word 050 * @return A word instance whose value is val on 32 bit machine this truncates the upper 32 bits. 051 */ 052 public static Word fromLong(long val) { 053 return null; 054 } 055 056 /** 057 * The Word constant 0. 058 * Equivalent to {@code Word.fromIntSignExtend(0)}, but more readable. 059 * 060 * @return the Word constant 0. 061 */ 062 public static Word zero() { 063 return null; 064 } 065 066 /** 067 * The Word constant 1. 068 * Equivalent to {@code Word.fromIntSignExtend(1)}, but more readable. 069 * 070 * @return the Word constant 1. 071 */ 072 public static Word one() { 073 return null; 074 } 075 076 /** 077 * The maximum representable Word value. Words are unsigned, so this is 078 * a word full of 1s, 32/64-bit safe. 079 * 080 * @return the maximum representable Word value 081 */ 082 public static Word max() { 083 return null; 084 } 085 086 /** 087 * Type-cast to an int, truncating on 64-bit platforms. 088 * 089 * @return an int, with the same value as the word on 32 bit platforms; truncates on 64 bit platforms. 090 */ 091 public int toInt() { 092 return 0; 093 } 094 095 /** 096 * Type-cast to a long, zero-extending on a 32-bit platform. 097 * @return a long, with the same value as the word (zero extends on 32 bit platforms). 098 */ 099 public long toLong() { 100 return 0L; 101 } 102 103 /** @return this word type-cast to an address. */ 104 public Address toAddress() { 105 return null; 106 } 107 108 /** @return this word type-cast to an offset */ 109 public Offset toOffset() { 110 return null; 111 } 112 113 /** @return this word type-cast to an extent */ 114 public Extent toExtent() { 115 return null; 116 } 117 118 /** 119 * Adds two words. 120 * 121 * @param w2 the word to add 122 * @return The word whose value is this+w2 123 */ 124 public Word plus(Word w2) { 125 return null; 126 } 127 128 /** 129 * Add an offset to a word 130 * @param w2 the offset to add 131 * @return The word whose value is this+w2 132 */ 133 public Word plus(Offset w2) { 134 return null; 135 } 136 137 /** 138 * Add an extent to a word 139 * @param w2 the extent to add 140 * @return The word whose value is this+w2 141 */ 142 public Word plus(Extent w2) { 143 return null; 144 } 145 146 /** 147 * Subtract two words 148 * @param w2 the word to subtract 149 * @return The word whose value is this-w2 150 */ 151 public Word minus(Word w2) { 152 return null; 153 } 154 155 /** 156 * Subtract an offset from a word 157 * @param w2 the offset to subtract 158 * @return The word whose value is this-w2 159 */ 160 public Word minus(Offset w2) { 161 return null; 162 } 163 164 /** 165 * Subtract an extent from a word. 166 * @param w2 the extent to subtract 167 * @return The word whose value is this-w2 168 */ 169 public Word minus(Extent w2) { 170 return null; 171 } 172 173 /** 174 * Test for zero. Equivalent to {@code .EQ(Word.zero())} 175 * @return {@code true} if this is equal to {@code Word.zero()}, 176 * {@code false} otherwise 177 */ 178 public boolean isZero() { 179 return false; 180 } 181 182 /** 183 * Test for zero. Equivalent to {@code .EQ(Word.max())} 184 * @return {@code true} if this is equal to {@code Word.max()}, 185 * {@code false} otherwise 186 */ 187 public boolean isMax() { 188 return false; 189 } 190 191 /** 192 * Less-than comparison 193 * @param addr2 the address to compare with 194 * @return true if this <code>Word</code> instance is <i>less than</i> <code>addr2</code> 195 */ 196 public boolean LT(Word addr2) { 197 return false; 198 } 199 200 /** 201 * Less-than or equal comparison 202 * @param w2 the word to compare with 203 * @return true if this <code>Word</code> instance is <i>less than or equal to</i> <code>w2</code> 204 */ 205 public boolean LE(Word w2) { 206 return false; 207 } 208 209 /** 210 * Greater-than comparison 211 * @param w2 the word to compare with 212 * @return true if this <code>Word</code> instance is <i>greater than</i> <code>w2</code> 213 */ 214 public boolean GT(Word w2) { 215 return false; 216 } 217 218 /** 219 * Greater-than or equal comparison 220 * @param w2 the word to compare with 221 * @return true if this <code>Word</code> instance is <i>greater than or equal to</i> <code>w2</code> 222 */ 223 public boolean GE(Word w2) { 224 return false; 225 } 226 227 /** 228 * Equality comparison 229 * @param w2 the word to compare with 230 * @return true if this <code>Word</code> instance is <i>equal to</i> <code>w2</code> 231 */ 232 public boolean EQ(Word w2) { 233 return false; 234 } 235 236 /** 237 * Not-equal comparison 238 * @param w2 the word to compare with 239 * @return true if this <code>Word</code> instance is <i>not equal to</i> <code>w2</code> 240 */ 241 public boolean NE(Word w2) { 242 return false; 243 } 244 245 /** 246 * Bit-wise and of two words. 247 * @param w2 the word to and with 248 * @return The word whose value is the bitwise and of this and w2 249 */ 250 public Word and(Word w2) { 251 return null; 252 } 253 254 /** 255 * Bit-wise or of two words. 256 * @param w2 the word to or with 257 * @return The word whose value is the bitwise not of this and w2 258 */ 259 public Word or(Word w2) { 260 return null; 261 } 262 263 /** 264 * Bit-wise complement of a word. 265 * @return the bitwise complement of this 266 */ 267 public Word not() { 268 return null; 269 } 270 271 /** 272 * Bit-wise exclusive or of two words. 273 * @param w2 the word to xor with 274 * @return The word whose value is the bitwise xor of this and w2 275 */ 276 public Word xor(Word w2) { 277 return null; 278 } 279 280 /** 281 * Left-shift a word. Shifts of a size greater than the Word are undefined and 282 * have an architecture and compiler specific behaviour. On Intel the shift 283 * amount ignores the most significant bits, for example for a 32bit Word 1 284 * << 32 == 1, the result will be 0 on PowerPC. Shifts may or may not be 285 * combined by the compiler, this yields differing behaviour, for example for a 286 * 32bit Word 1 <<32 may or may not equal 1 << 16 << 16. 287 * 288 * @param amt the amount to shift by 289 * @return new Word shifted by the given amount 290 */ 291 public Word lsh(int amt) { 292 return null; 293 } 294 295 /** 296 * Logical right-shift a word. Shifts of a size greater than the Word are undefined and 297 * have an architecture and compiler specific behaviour see also {@link #lsh(int)}. 298 * 299 * @param amt the amount to shift by 300 * @return new Word shifted by the given amount 301 */ 302 public Word rshl(int amt) { 303 return null; 304 } 305 306 /** 307 * Arithmetic right-shift a word. Shifts of a size greater than the Word are undefined and 308 * have an architecture and compiler specific behaviour see also {@link #lsh(int)}. 309 * Arithmetic right-shift a word. Equivalent to the integer <code>>></code> operator 310 * 311 * @param amt the amount to shift by 312 * @return new Word shifted by the given amount 313 */ 314 public Word rsha(int amt) { 315 return null; 316 } 317} 318