org.vmmagic.unboxed
Class Word

java.lang.Object
  extended by org.vmmagic.unboxed.Word

public final class Word
extends Object

A generic pointer-sized integer. Can be converted to/from other pointer-sized types, and provides shifting and masking operations.


Constructor Summary
Word()
           
 
Method Summary
 Word and(Word w2)
          Bit-wise and of two words.
 boolean EQ(Word w2)
          Equality comparison
static Word fromIntSignExtend(int val)
          Convert an int to a word.
static Word fromIntZeroExtend(int val)
          Convert an int to a word.
static Word fromLong(long val)
          Convert a long to a word.
 boolean GE(Word w2)
          Greater-than or equal comparison
 boolean GT(Word w2)
          Greater-than comparison
 boolean isMax()
          Test for zero.
 boolean isZero()
          Test for zero.
 boolean LE(Word w2)
          Less-than or equal comparison
 Word lsh(int amt)
          Left-shift a word.
 boolean LT(Word addr2)
          Less-than comparison
static Word max()
          The maximum representable Word value.
 Word minus(Extent w2)
          Subtract an extent from a word.
 Word minus(Offset w2)
          Subtract an offset from a word
 Word minus(Word w2)
          Subtract two words
 boolean NE(Word w2)
          Not-equal comparison
 Word not()
          Bit-wise complement of a word.
static Word one()
          The Word constant 1.
 Word or(Word w2)
          Bit-wise or of two words.
 Word plus(Extent w2)
          Add an extent to a word
 Word plus(Offset w2)
          Add an offset to a word
 Word plus(Word w2)
          Add two words
 Word rsha(int amt)
          Arithmetic right-shift a word.
 Word rshl(int amt)
          Logical right-shift a word.
 Address toAddress()
          Type-cast to an address.
 Extent toExtent()
          Type-cast to an extent
 int toInt()
          Type-cast to an int, truncating on 64-bit platforms.
 long toLong()
          Type-cast to a long, zero-extending on a 32-bit platform.
 Offset toOffset()
          Type-cast to an offset
 Word xor(Word w2)
          Bit-wise exclusive or of two words.
static Word zero()
          The Word constant 0.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Word

public Word()
Method Detail

fromIntSignExtend

public static Word fromIntSignExtend(int val)
Convert an int to a word. On 64-bit machines, sign-extend the high order bit.

Parameters:
val -
Returns:
A word instance whose value is val, sign-extended on 64 bit machines

fromIntZeroExtend

public static Word fromIntZeroExtend(int val)
Convert an int to a word. On 64-bit machines, zero-extend the high order bit.

Parameters:
val -
Returns:
A word instance whose value is val, zero-extended on 64 bit machines

fromLong

public static Word fromLong(long val)
Convert a long to a word. On 64-bit this is a no-op, on 32-bit the long is truncated.

Parameters:
val -
Returns:
A word instance whose value is val on 32 bit machine this truncates the upper 32 bits.

zero

public static Word zero()
The Word constant 0. Equivalent to Word.fromIntSignExtend(0), but more readable.

Returns:
the Word constant 0.

one

public static Word one()
The Word constant 1. Equivalent to Word.fromIntSignExtend(1), but more readable.

Returns:
the Word constant 1.

max

public static Word max()
The maximum representable Word value. Words are unsigned, so this is a word full of 1s, 32/64-bit safe.

Returns:
the maximum representable Word value

toInt

public int toInt()
Type-cast to an int, truncating on 64-bit platforms.

Returns:
an int, with the same value as the word on 32 bit platforms; truncates on 64 bit platforms.

toLong

public long toLong()
Type-cast to a long, zero-extending on a 32-bit platform.

Returns:
a long, with the same value as the word (zero extends on 32 bit platforms).

toAddress

public Address toAddress()
Type-cast to an address.


toOffset

public Offset toOffset()
Type-cast to an offset


toExtent

public Extent toExtent()
Type-cast to an extent


plus

public Word plus(Word w2)
Add two words

Parameters:
w2 -
Returns:
The word whose value is this+w2

plus

public Word plus(Offset w2)
Add an offset to a word

Parameters:
w2 -
Returns:
The word whose value is this+w2

plus

public Word plus(Extent w2)
Add an extent to a word

Parameters:
w2 -
Returns:
The word whose value is this+w2

minus

public Word minus(Word w2)
Subtract two words

Parameters:
w2 -
Returns:
The word whose value is this-w2

minus

public Word minus(Offset w2)
Subtract an offset from a word

Parameters:
w2 -
Returns:
The word whose value is this-w2

minus

public Word minus(Extent w2)
Subtract an extent from a word.

Parameters:
w2 -
Returns:
The word whose value is this-w2

isZero

public boolean isZero()
Test for zero. Equivalent to .EQ(Word.zero())

Returns:
return true if this is equal to Word.zero(), false otherwise

isMax

public boolean isMax()
Test for zero. Equivalent to .EQ(Word.max())

Returns:
true if this is equal to Word.max(), false otherwise

LT

public boolean LT(Word addr2)
Less-than comparison

Parameters:
addr2 -
Returns:
true if this Word instance is less than addr2

LE

public boolean LE(Word w2)
Less-than or equal comparison

Parameters:
w2 -
Returns:
true if this Word instance is less than or equal to w2

GT

public boolean GT(Word w2)
Greater-than comparison

Parameters:
w2 -
Returns:
true if this Word instance is greater than w2

GE

public boolean GE(Word w2)
Greater-than or equal comparison

Parameters:
w2 -
Returns:
true if this Word instance is greater than or equal to w2

EQ

public boolean EQ(Word w2)
Equality comparison

Parameters:
w2 -
Returns:
true if this Word instance is equal to w2

NE

public boolean NE(Word w2)
Not-equal comparison

Parameters:
w2 -
Returns:
true if this Word instance is not equal to w2

and

public Word and(Word w2)
Bit-wise and of two words.

Parameters:
w2 -
Returns:
The word whose value is the bitwise and of this and w2

or

public Word or(Word w2)
Bit-wise or of two words.

Parameters:
w2 -
Returns:
The word whose value is the bitwise not of this and w2

not

public Word not()
Bit-wise complement of a word.

Returns:
the bitwise complement of this

xor

public Word xor(Word w2)
Bit-wise exclusive or of two words.

Parameters:
w2 -
Returns:
The word whose value is the bitwise xor of this and w2

lsh

public Word lsh(int amt)
Left-shift a word. Shifts of a size greater than the Word are undefined and have an architecture and compiler specific behaviour. On Intel the shift amount ignores the most significant bits, for example for a 32bit Word 1 << 32 == 1, the result will be 0 on PowerPC. Shifts may or may not be combined by the compiler, this yields differing behaviour, for example for a 32bit Word 1 <<32 may or may not equal 1 << 16 << 16.

Parameters:
amt - the amount to shift by
Returns:
new Word shifted by the given amount

rshl

public Word rshl(int amt)
Logical right-shift a word. Shifts of a size greater than the Word are undefined and have an architecture and compiler specific behaviour see also lsh(int).

Parameters:
amt - the amount to shift by
Returns:
new Word shifted by the given amount

rsha

public Word rsha(int amt)
Arithmetic right-shift a word. Shifts of a size greater than the Word are undefined and have an architecture and compiler specific behaviour see also lsh(int). Arithmetic right-shift a word. Equivalent to the integer >> operator

Parameters:
amt - the amount to shift by
Returns:
new Word shifted by the given amount