engine
Class BitVector

java.lang.Object
  |
  +--engine.Assignable
        |
        +--engine.DataHolder
              |
              +--engine.BitVector
Direct Known Subclasses:
Wire

public class BitVector
extends DataHolder

The implementation of a 4-state (0,1,X,Z) bit array.

See Also:
Serialized Form

Field Summary
protected static int[][] abgCond
          used to combine the alternatives in the ambiguity case of ?: operator
static int[] ands
           
private  byte[] b0
          each "elecrical" bit is represented as a 2 - bit value (see table) below
private  byte[] b1
          each "elecrical" bit is represented as a 2 - bit value (see table) below
(package private)  int increment
          Used in a for(..
(package private)  int lsb
          indexes of the MSB & the LSB
(package private)  int msb
          indexes of the MSB & the LSB
(package private)  int n
          the size ( |msb - lsb| + 1)
static int[] nands
           
(package private) static int[][] negedge
           
static int[] nors
           
static int[] nots
           
static int[] ors
           
(package private) static int[][] posedge
           
(package private)  boolean signed
          true if this BitVector is signed (this is NOT the sign bit !!)
(package private) static char[][] vtable16
          4-bit expansions for hexa digits:
static char[][] vtable8
           
static int X
           
static int[] xnors
           
static int[] xors
           
static int Z
           
 
Fields inherited from class engine.DataHolder
monitors
 
Fields inherited from class engine.Assignable
data, initValDefaults, lookupTables, lookupTableSupply0, lookupTableSupply1, lookupTableTri0, lookupTableTri1, lookupTableWand, lookupTableWire, lookupTableWor, typeSupply0, typeSupply1, typeTri0, typeTri1, typeTrireg, typeWand, typeWire, typeWor, X, Z
 
Constructor Summary
BitVector(java.math.BigInteger bi, boolean signed)
           
BitVector(BitVector b)
          copy constructor
BitVector(BitVector b, int start, int end)
          this <- b [start : end];
BitVector(byte bit, int n)
          Creates a new Bitvector filled with the 'bit' value
BitVector(int msb, int lsb)
          Creates a new unsigned BitVector
BitVector(int msb, int lsb, boolean signed)
           
BitVector(long l, boolean signed)
           
BitVector(java.lang.String image, int base, int size)
          creates an unsigned BitVector
BitVector(java.lang.String image, int base, int size, boolean signed, boolean sign)
          parses image, according to base & size
 
Method Summary
 Result add(Result r)
          this = this + b does NOT guarantees the integrity of b !
static int and(int a, int b)
           
 void attrib(BitVector b)
          this <- b
 void attrib(BitVector b, int start, int end)
          This[start:end] <- b
(package private)  void attrib(int from, int to, BitVector b, int start, int end)
          This[from:to] <- b[start:end];
(package private)  void attrib(long val)
          this <- valPetru val can be < 0 !
static BitVector b0()
          returns a new one - bit BitVector whose value is 0
static BitVector b1()
          returns a new one - bit BitVector whose value is 1
 void bAnd(Result r)
           
 void bAndR()
           
 long bitsToLong()
          converts this BitVector to its binary representation into a long
 void bNAnd(Result r)
           
 void bNAndR()
           
 void bNOr(Result r)
           
 void bNOrR()
           
 void bNot()
           
 void bNXor(Result r)
           
 void bNXOrR()
           
 void bOr(Result r)
           
 void bOrR()
           
static BitVector bX()
          returns a new une - bit BitVector whose value is X
 void bXor(Result r)
           
 void bXOrR()
           
static BitVector bZ()
          returns a new one - bit BitVector whose value is Z
 Result cEq(Result r)
           
protected  java.lang.Object clone()
           
 Result cNEq(Result r)
           
 void combineFAbgCond(BitVector b)
          combines this and b for the ambiguous case of ?:
(package private)  int compare(BitVector b)
          Looks for a value change between this and b (used for edge detesction).
(package private)  java.lang.Object[] compute()
          Computes the acutal value for each bit, considering the BitSelects assigned to it.
 Result div(Result r)
          todo: implementation
 Result duplicate()
           
protected  void ensureBitCapacity(int newLength)
          checks that ths BitVector can hold enough bits
protected  void ensureCapacity(int newLength)
          checks that ths BitVector can hold enough bytes
 boolean equals(BitVector b)
          Check two BitVectors to be identical.
(package private)  void expand0(int newLength)
          expands the bitvector to the new size, padding the new space with 0 the msb is adjusted accordingly
(package private)  void expandS(int newN)
          performs arithmetic (Signed) expansion if signed is set (for Luke : i.e.
 Result ge(Result r)
           
 void genericReduction(int[] table)
          Reduces the BitVector according to the given given truth table
 void genericReduction1(int[] table)
          Same as genericReduction, but the direction is reversed, because I don't want to transpose the truth tables from the Standard.
protected  int getb(int i)
          returns both b[1:0]
protected  int getb0(int i)
          Returns the i-th bit from b0.
protected  int getb1(int i)
          returns the i-th bit from b1
 int getBit(int i)
          gets the i'th bit value (i is in the range lsb..msb !)
 BitVector getBits()
           
 int getBool()
           
 BitVector getInt()
           
 long getLong()
           
 Real getReal()
          a combination of the $bitstoreal and the $itor system functions
 int getSign()
           
 int getType()
           
 Result gt(Result r)
           
 boolean isDefined()
           
 boolean isNull()
          Tests if this bivector is 0
 boolean isTrue()
           
 boolean isX()
           
 boolean isZ()
           
 Result le(Result r)
           
 int length()
           
 Result lEq(Result r)
           
 Result lNEq(Result r)
           
 void lNot()
          Reduces this BitVector to a single-bit one wich contains its logical truth value (0, 1, or X).
 Result lt(Result r)
           
 Result mod(Result r)
          The result is stored into this.
 Result mul(Result r)
          Multiplies this BitVector and r.
 void neg()
          This = -this (2's complement).
static int not(int x)
           
static int or(int a, int b)
           
 void reduce(int value)
          reduces the BitVector to a single bit vector
(package private)  byte[] reverse(byte[] original)
          Whata' ...
protected  void setb(int i, int v)
          sets both b0 and b1
protected  void setb0(int i, int v)
          sets the i-th bit from b0
protected  void setb1(int i, int v)
          sets the i-th bit from b1
 void setBit(int i, int value)
          sets the i'th bit to value (i is in the range lsb..msb !)
(package private)  void setLength(int length)
          Modifies the length of this Bitvector, expanding or shrinking it as necessary.
 void shl(int i)
          Shift this BitVector with i positions.
 void shl(Result count)
           
 void shr(Result count)
           
 Result sub(Result r)
          this = this - r does NOT guarantee the integrity of parameter r implementation is: r = -r this = this+r
 java.lang.String toString()
           
 java.lang.String toString(int base)
           
(package private)  void trunc(int newLength)
          cuts off the most significants bits, so the length remains newL...
 long value()
          computes the value represented by this BitVector
static int xor(int a, int b)
           
 
Methods inherited from class engine.DataHolder
addMonitor, getWatchMonitor, hasMonitor, notifyMonitors, removeMonitor
 
Methods inherited from class engine.Assignable
addAssignement, removeAssignement
 
Methods inherited from class java.lang.Object
, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

X

public static final int X

Z

public static final int Z

b0

private byte[] b0
each "elecrical" bit is represented as a 2 - bit value (see table) below

b1

private byte[] b1
each "elecrical" bit is represented as a 2 - bit value (see table) below

msb

int msb
indexes of the MSB & the LSB

lsb

int lsb
indexes of the MSB & the LSB

increment

int increment
Used in a for(.. ; .. ; .. += increment) to traverse this BitVector from LSB to MSB ( i guess.. yeah, I was right !)

n

int n
the size ( |msb - lsb| + 1)

signed

boolean signed
true if this BitVector is signed (this is NOT the sign bit !!)

ands

public static final int[] ands

ors

public static final int[] ors

xors

public static final int[] xors

nands

public static final int[] nands

nors

public static final int[] nors

xnors

public static final int[] xnors

nots

public static final int[] nots

vtable8

public static final char[][] vtable8

vtable16

static final char[][] vtable16
4-bit expansions for hexa digits:

posedge

static final int[][] posedge

negedge

static final int[][] negedge

abgCond

protected static final int[][] abgCond
used to combine the alternatives in the ambiguity case of ?: operator
Constructor Detail

BitVector

public BitVector(long l,
                 boolean signed)

BitVector

public BitVector(java.math.BigInteger bi,
                 boolean signed)

BitVector

public BitVector(int msb,
                 int lsb)
Creates a new unsigned BitVector

BitVector

public BitVector(int msb,
                 int lsb,
                 boolean signed)

BitVector

public BitVector(byte bit,
                 int n)
Creates a new Bitvector filled with the 'bit' value

BitVector

public BitVector(BitVector b)
copy constructor

BitVector

public BitVector(BitVector b,
                 int start,
                 int end)
          throws InterpretTimeException
this <- b [start : end];
Throws:
InterpretTimeException - if MSB & LSB are reversed

BitVector

public BitVector(java.lang.String image,
                 int base,
                 int size)
creates an unsigned BitVector

BitVector

public BitVector(java.lang.String image,
                 int base,
                 int size,
                 boolean signed,
                 boolean sign)
parses image, according to base & size
Method Detail

and

public static final int and(int a,
                            int b)

or

public static final int or(int a,
                           int b)

xor

public static final int xor(int a,
                            int b)

not

public static final int not(int x)

bX

public static final BitVector bX()
returns a new une - bit BitVector whose value is X

bZ

public static final BitVector bZ()
returns a new one - bit BitVector whose value is Z

b1

public static final BitVector b1()
returns a new one - bit BitVector whose value is 1

b0

public static final BitVector b0()
returns a new one - bit BitVector whose value is 0

clone

protected java.lang.Object clone()
Overrides:
clone in class java.lang.Object

equals

public boolean equals(BitVector b)
Check two BitVectors to be identical. They must have the same length & data.

attrib

public void attrib(BitVector b)
            throws InterpretTimeException
this <- b

attrib

public void attrib(BitVector b,
                   int start,
                   int end)
            throws InterpretTimeException
This[start:end] <- b

attrib

void attrib(int from,
            int to,
            BitVector b,
            int start,
            int end)
      throws InterpretTimeException
This[from:to] <- b[start:end];

attrib

void attrib(long val)
      throws InterpretTimeException
this <- valPetru val can be < 0 !

ensureCapacity

protected final void ensureCapacity(int newLength)
checks that ths BitVector can hold enough bytes
Parameters:
newLength - the number of bytes that this BitVector must hold

ensureBitCapacity

protected final void ensureBitCapacity(int newLength)
checks that ths BitVector can hold enough bits
Parameters:
newLength - the number of bits that this BitVector must hold

getb0

protected final int getb0(int i)
Returns the i-th bit from b0.
Parameters:
i - the index of requested bit
Throws:
java.lang.IndexOutOfBoundsException -  

setb0

protected final void setb0(int i,
                           int v)
sets the i-th bit from b0

getb1

protected final int getb1(int i)
returns the i-th bit from b1

setb1

protected final void setb1(int i,
                           int v)
sets the i-th bit from b1

setb

protected final void setb(int i,
                          int v)
sets both b0 and b1

getb

protected final int getb(int i)
returns both b[1:0]

setBit

public final void setBit(int i,
                         int value)
sets the i'th bit to value (i is in the range lsb..msb !)

getBit

public final int getBit(int i)
gets the i'th bit value (i is in the range lsb..msb !)

reduce

public final void reduce(int value)
reduces the BitVector to a single bit vector
Parameters:
value - the value assigned to the bit

bAnd

public void bAnd(Result r)
          throws InterpretTimeException

bOr

public void bOr(Result r)
         throws InterpretTimeException

bXor

public void bXor(Result r)
          throws InterpretTimeException

bNAnd

public void bNAnd(Result r)
           throws InterpretTimeException

bNOr

public void bNOr(Result r)
          throws InterpretTimeException

bNXor

public void bNXor(Result r)
           throws InterpretTimeException

bNot

public void bNot()
          throws InterpretTimeException

lNot

public void lNot()
Reduces this BitVector to a single-bit one wich contains its logical truth value (0, 1, or X).

neg

public void neg()
This = -this (2's complement).

shl

public void shl(Result count)
         throws InterpretTimeException

shl

public void shl(int i)
Shift this BitVector with i positions. If i > 0, the shift is done to the left. In this case, if the BitVector is a reg, its size remains the same. Else ( i.e it is an integer) its size will grow in order to accomodate the result of the operation. Remember that OVI says : shift is always logical (no sign expansion).

shr

public void shr(Result count)
         throws InterpretTimeException

isDefined

public boolean isDefined()

isNull

public boolean isNull()
Tests if this bivector is 0

isZ

public boolean isZ()

isX

public boolean isX()

lEq

public Result lEq(Result r)

lNEq

public Result lNEq(Result r)

cEq

public Result cEq(Result r)
           throws InterpretTimeException

cNEq

public Result cNEq(Result r)
            throws InterpretTimeException

lt

public Result lt(Result r)

ge

public Result ge(Result r)

gt

public Result gt(Result r)

le

public Result le(Result r)

bAndR

public void bAndR()
           throws InterpretTimeException

bOrR

public void bOrR()
          throws InterpretTimeException

bXOrR

public void bXOrR()
           throws InterpretTimeException

bNAndR

public void bNAndR()
            throws InterpretTimeException

bNOrR

public void bNOrR()
           throws InterpretTimeException

bNXOrR

public void bNXOrR()
            throws InterpretTimeException

genericReduction

public void genericReduction(int[] table)
                      throws InterpretTimeException
Reduces the BitVector according to the given given truth table

genericReduction1

public void genericReduction1(int[] table)
                       throws InterpretTimeException
Same as genericReduction, but the direction is reversed, because I don't want to transpose the truth tables from the Standard.

expandS

void expandS(int newN)
performs arithmetic (Signed) expansion if signed is set (for Luke : i.e. with sign extension) the trick is that it preserves the sign bit only for integers, so when assigning an integer to a register, the int always appeares to be "longer" than it, from the register's point of view and thus, the integer's size need not to be fixed, nor limited

getSign

public int getSign()

add

public Result add(Result r)
this = this + b does NOT guarantees the integrity of b !

sub

public Result sub(Result r)
this = this - r does NOT guarantee the integrity of parameter r implementation is: r = -r this = this+r

reverse

byte[] reverse(byte[] original)
Whata' ...

mul

public Result mul(Result r)
Multiplies this BitVector and r. The result is stored into this.

mod

public Result mod(Result r)
           throws InterpretTimeException
The result is stored into this.

div

public Result div(Result r)
todo: implementation

bitsToLong

public long bitsToLong()
                throws UndefinedValueException
converts this BitVector to its binary representation into a long

value

public long value()
           throws UndefinedValueException
computes the value represented by this BitVector
Returns:
the value represented by this BitVector. If some bits are X or Z, the result is undefined.
Throws:
UndefinedValueException -  

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(int base)

expand0

void expand0(int newLength)
expands the bitvector to the new size, padding the new space with 0 the msb is adjusted accordingly

trunc

void trunc(int newLength)
cuts off the most significants bits, so the length remains newL...

setLength

void setLength(int length)
Modifies the length of this Bitvector, expanding or shrinking it as necessary.

compare

int compare(BitVector b)
Looks for a value change between this and b (used for edge detesction).

compute

java.lang.Object[] compute()
                     throws InterpretTimeException
Computes the acutal value for each bit, considering the BitSelects assigned to it. It's suitable for reg continuous assign statement(i guess..).
Returns:
the value obtained from arbitration of all the values driving this BitVector.
Overrides:
compute in class Assignable

combineFAbgCond

public final void combineFAbgCond(BitVector b)
combines this and b for the ambiguous case of ?:

getReal

public Real getReal()
a combination of the $bitstoreal and the $itor system functions
See Also:
Result

getBits

public BitVector getBits()
See Also:
Result

getInt

public BitVector getInt()
See Also:
Result

getBool

public int getBool()
See Also:
Result

getLong

public long getLong()

duplicate

public Result duplicate()
See Also:
Result

isTrue

public boolean isTrue()

getType

public int getType()

length

public int length()