hades.models
Class StdLogicVector

java.lang.Object
  extended byhades.models.StdLogicVector
All Implemented Interfaces:
java.io.Serializable

public class StdLogicVector
extends java.lang.Object
implements java.io.Serializable

StdLogicVector: represents multi-bit StdLogic1164 values.

StdLogicVector is modeled in close analogy to the IEEE StdLogicVector and StdLogic1164 data types used in VHDL, with some changes to use OO-style and Java. Please note that the VHDL "UNSIGNED" type is not supported yet, because all integer datatypes in Java are signed. Also note a limitation to at most 63 bits for a single StdLogicVector.

Each bus (StdLogicVector) is modeled as an array of StdLogic1164 values, where the array size is specified by giving its upper and lower indices. Therefore, a StdLogicVector is mainly a means for easier editing, but not a means to improve simulation speed above the use of individual StdLogic1164 signals. If necessary, use other signal data types like hades.models.ruge.IntegerSignal to speed up simulation with buses.

As a convenience, this class supplies a double set of methods for most arithmetic and logic functions - member functions which take one argument, and static functions.

A resolution function, if any, is applied for each bit of the array in turn. WARNING: Note that the current implementation of StdLogicVector and the current resolution function will fail if different bits of one StdLogicVector are short-circuited by external circuits.

See Also:
Serialized Form

Field Summary
static boolean debug
           
static long INVALID_XXX
           
static long MAX_BITS
           
static long TRISTATE_ZZZ
           
static long UNDEFINED_UUU
           
 
Constructor Summary
StdLogicVector(int n_bits)
          construct a new StdLogicVector with n_bits bits, all initialized to the undefined value (hades.models.StdLogic1164._U).
StdLogicVector(int n_bits, long value)
          construct a new StdLogicVector with n_bits bits, pre-initialized by 'value'.
StdLogicVector(int n_bits, StdLogic1164 defaultValue)
           
StdLogicVector(int n_bits, java.lang.String bitString)
          construct a new StdLogicVector with n_bits (< MAX_BITS) and initialize it from the String 'bitString', which is expected to contain a suitable binary StdLogic1164 compatible representation, e.g.
 
Method Summary
 StdLogicVector add(StdLogicVector R)
           
static StdLogicVector add(StdLogicVector L, StdLogicVector R)
           
 java.lang.String addLeadingZeroes(java.lang.String s, int width)
           
 StdLogicVector and_bitwise(StdLogicVector B)
           
 StdLogic1164 and_onebit()
          return the logical AND of all bits in this StdLogicVector
 StdLogicVector append(StdLogic1164 tail)
           
 StdLogicVector append(StdLogicVector tail)
           
static boolean check(StdLogicVector L, StdLogicVector R)
          check whether this StdLogicVector has the arithmetic value 1, that is, the last bit (LSB) is 1, and all other bits are zero public boolean is_001() { return ( (_0_mask | _1_mask) == _length_mask) && (_1_mask == 1L)); } /** an utility method to check the validity of operands L and R to binary arithmetic or logical operations.
static void checkWidth(StdLogicVector L, StdLogicVector R)
           
static StdLogicVector concat(StdLogicVector head, StdLogicVector tail)
          convenience duplicate of append()
 StdLogicVector copy()
           
 StdLogicVector decr()
           
static void demonstrateHotspot101Bug(int n_bits)
           
 boolean equals(java.lang.Object arg)
          check whether Object arg is a StdLogicVector, and whether the this-object have the same width and the same StdLogic1164 values at each bit position.
static StdLogic1164 get2ComplementAddOverflow(StdLogicVector L, StdLogicVector R)
          check whether the 2-complement addition of vectors L and R results in an overflow.
 StdLogic1164 getBitAt(int index)
          get the StdLogic1164 value (object) at vector postion 'index'.
 int getBitIntValueAt(int index)
           
 long getBitMask()
          return a bit mask in which the lowest n bits are set, where n is the length (width) of this StdLogicVector.
 long getSignedValue()
          return the signed long integer value representation of this StdLogicVector.
 long getValue()
          return the unsigned integer (long) value representation of this StdLogicVector.
 int getWidth()
           
 java.lang.String getWidthString()
           
 boolean has_0()
           
 boolean has_1()
           
 boolean has_D()
           
 boolean has_H()
           
 boolean has_L()
           
 boolean has_U()
           
 boolean has_UXZ()
          check whether any bit in this StdLogicVector is undefined, that is, _U, _X, _Z, _W, or _D.
 boolean has_W()
           
 boolean has_X()
           
 boolean has_Z()
           
 StdLogicVector incr()
           
 StdLogicVector invert_bitwise()
          return the a bitwise inverted copy of this StdLogicVector.
 boolean is_000()
          check whether all bits of this StdLogicVector are '0'
 boolean is_111()
           
 boolean is_ZZZ()
           
static boolean isEqual(StdLogicVector L, StdLogicVector R)
           
static boolean isGreaterEqual(StdLogicVector L, StdLogicVector R)
           
static boolean isGreaterThan(StdLogicVector L, StdLogicVector R)
           
static boolean isLessEqual(StdLogicVector L, StdLogicVector R)
           
static boolean isLessThan(StdLogicVector L, StdLogicVector R)
           
static void main(java.lang.String[] argv)
           
static void msg(java.lang.String msg)
           
 StdLogic1164 nand_onebit()
           
 StdLogic1164 nor_onebit()
           
 StdLogicVector or_bitwise(StdLogicVector B)
           
 StdLogic1164 or_onebit()
          return the logical OR of all bits in this StdLogicVector
 void parse(java.lang.String s)
          parse a bin/dec/hex-formatted value from a String and set the value of this StdLogicVector correspondingly.
static StdLogicVector resolve(StdLogicVector[] inputs)
          resolve(): StdLogic1164-compatible resolution function of any number of input vectors.
 java.lang.String rightAlign(java.lang.String s, int minWidth)
           
 StdLogicVector rol(int count)
           
 StdLogicVector ror(int count)
           
static void selftest()
           
 void setBitAt(int index, int value)
           
 void setBitAt(int index, StdLogic1164 value)
           
 void setValue(long value)
          set the bits in this StdLogicVector from the numerical 'value'.
 StdLogicVector shl(int count)
          create a left-shifted (by count bits) copy of this StdLogicVector
 StdLogicVector shr_arithmetical(int count)
          create a right-shifted (by count bits) copy of this StdLogicVector.
 StdLogicVector shr_logical(int count)
          create a right-shifted (by count bits) copy of this StdLogicVector.
 StdLogicVector sub(StdLogicVector R)
           
static StdLogicVector sub(StdLogicVector L, StdLogicVector R)
           
 StdLogicVector subset(int upper, int lower)
          return the subset from 62 >= upper ...
static void testGetSignedValue()
           
static void testShiftRight()
           
 java.lang.String toBinString()
           
 java.lang.String toBinString(int minWidth)
           
 java.lang.String toDecString()
           
 java.lang.String toDecString(int minWidth)
           
 java.lang.String toDecStringPadded()
           
 java.lang.String toDecStringPadded(int minWidth)
           
 java.lang.String toHexString()
           
 java.lang.String toHexString(int minWidth)
           
static StdLogicVector toStdLogicVector(int value, int n_bits)
           
 java.lang.String toString()
           
 StdLogic1164 xnor_onebit()
          return the logical XNOR (inverted parity) of all bits in this vector
 StdLogicVector xor_bitwise(StdLogicVector B)
           
 StdLogic1164 xor_onebit()
          return the logical XOR (parity) of all bits in this StdLogicVector
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

debug

public static final boolean debug
See Also:
Constant Field Values

INVALID_XXX

public static final long INVALID_XXX
See Also:
Constant Field Values

UNDEFINED_UUU

public static final long UNDEFINED_UUU
See Also:
Constant Field Values

TRISTATE_ZZZ

public static final long TRISTATE_ZZZ
See Also:
Constant Field Values

MAX_BITS

public static final long MAX_BITS
See Also:
Constant Field Values
Constructor Detail

StdLogicVector

public StdLogicVector(int n_bits)
construct a new StdLogicVector with n_bits bits, all initialized to the undefined value (hades.models.StdLogic1164._U).

Indices run from (n_bits-1 downto 0), where n_bits is limited to MAX_BITS in the current implementation.


StdLogicVector

public StdLogicVector(int n_bits,
                      long value)
construct a new StdLogicVector with n_bits bits, pre-initialized by 'value'.

See Also:
StdLogicVector

StdLogicVector

public StdLogicVector(int n_bits,
                      java.lang.String bitString)
construct a new StdLogicVector with n_bits (< MAX_BITS) and initialize it from the String 'bitString', which is expected to contain a suitable binary StdLogic1164 compatible representation, e.g. "UX010Z11" for an 8-bit vector.

If the parser fails on the given bitString, the StdLogicVector is constructed and silently initialized with a 'U's.


StdLogicVector

public StdLogicVector(int n_bits,
                      StdLogic1164 defaultValue)
Method Detail

copy

public StdLogicVector copy()

toStdLogicVector

public static StdLogicVector toStdLogicVector(int value,
                                              int n_bits)

getWidth

public int getWidth()

getBitMask

public final long getBitMask()
return a bit mask in which the lowest n bits are set, where n is the length (width) of this StdLogicVector. For example, calling getBitMask() on a nine-bit vector would return 0x01FFL;

Note that getBitMask() also returns the largest possible integer (long) value representable with this StdLogicVector.


getBitIntValueAt

public int getBitIntValueAt(int index)

getBitAt

public StdLogic1164 getBitAt(int index)
get the StdLogic1164 value (object) at vector postion 'index'. NOTE: this method may return a null value, if either the index is out of range (e.g., less than zero), or if this vector contains an un-initialized entry.


setBitAt

public void setBitAt(int index,
                     StdLogic1164 value)

setBitAt

public void setBitAt(int index,
                     int value)

setValue

public void setValue(long value)
set the bits in this StdLogicVector from the numerical 'value'. This method will recognize the three symbolic constants UNDEFINED_UUU, INVALID_XXX, and TRISTATE_ZZZ to set all bits of the vector to 'U', 'X', and 'Z' respectively.


getValue

public long getValue()
return the unsigned integer (long) value representation of this StdLogicVector. This method will return the symbolic constant UNDEFINED_UUU if any bit in the vector is 'U', INVALID_XXX if any bit is 'X', 'D' or 'W', and TRISTATE_ZZZ if all bits are 'Z'.


getSignedValue

public long getSignedValue()
return the signed long integer value representation of this StdLogicVector. This method will return the symbolic constant UNDEFINED_UUU if any bit in the vector is 'U', INVALID_XXX if any bit is 'X', 'D' or 'W', and TRISTATE_ZZZ if all bits are 'Z'.


incr

public StdLogicVector incr()

decr

public StdLogicVector decr()

checkWidth

public static void checkWidth(StdLogicVector L,
                              StdLogicVector R)

add

public StdLogicVector add(StdLogicVector R)

add

public static StdLogicVector add(StdLogicVector L,
                                 StdLogicVector R)

get2ComplementAddOverflow

public static StdLogic1164 get2ComplementAddOverflow(StdLogicVector L,
                                                     StdLogicVector R)
check whether the 2-complement addition of vectors L and R results in an overflow. For an overflow, return StdLogic1164._1, or StdLogic1164._0 if no overflow occurs.

Note that there may be better realizations for this method.


sub

public StdLogicVector sub(StdLogicVector R)

sub

public static StdLogicVector sub(StdLogicVector L,
                                 StdLogicVector R)

shr_arithmetical

public StdLogicVector shr_arithmetical(int count)
                                throws java.lang.Exception
create a right-shifted (by count bits) copy of this StdLogicVector. This method uses arithmetic right shift with sign-extension, where the MSB (leftmost) bit of the source data is extended count times.

Don't use negative or too large shift counts.

Throws:
java.lang.Exception

shr_logical

public StdLogicVector shr_logical(int count)
                           throws java.lang.Exception
create a right-shifted (by count bits) copy of this StdLogicVector. This method uses logical right shift, which zeroes shifted in from the left (MSB).

Don't use negative or too large shift counts.

Throws:
java.lang.Exception

ror

public StdLogicVector ror(int count)
                   throws java.lang.Exception
Throws:
java.lang.Exception

shl

public StdLogicVector shl(int count)
                   throws java.lang.Exception
create a left-shifted (by count bits) copy of this StdLogicVector

Throws:
java.lang.Exception

rol

public StdLogicVector rol(int count)
                   throws java.lang.Exception
Throws:
java.lang.Exception

invert_bitwise

public StdLogicVector invert_bitwise()
return the a bitwise inverted copy of this StdLogicVector.


and_bitwise

public StdLogicVector and_bitwise(StdLogicVector B)

or_bitwise

public StdLogicVector or_bitwise(StdLogicVector B)

xor_bitwise

public StdLogicVector xor_bitwise(StdLogicVector B)

resolve

public static final StdLogicVector resolve(StdLogicVector[] inputs)
                                    throws java.lang.Exception
resolve(): StdLogic1164-compatible resolution function of any number of input vectors. This method checks that all vectors have the same length and throws an Exception if not. If at most one input vector is non_ZZZ, than that value is returned. Else, a StdLogic1164 resolution function is applied to each bit of the vectors in turn (which may be slow).

Throws:
java.lang.Exception

and_onebit

public StdLogic1164 and_onebit()
return the logical AND of all bits in this StdLogicVector


or_onebit

public StdLogic1164 or_onebit()
return the logical OR of all bits in this StdLogicVector


xor_onebit

public StdLogic1164 xor_onebit()
return the logical XOR (parity) of all bits in this StdLogicVector


nand_onebit

public StdLogic1164 nand_onebit()

nor_onebit

public StdLogic1164 nor_onebit()

xnor_onebit

public StdLogic1164 xnor_onebit()
return the logical XNOR (inverted parity) of all bits in this vector


append

public StdLogicVector append(StdLogicVector tail)

append

public StdLogicVector append(StdLogic1164 tail)

concat

public static StdLogicVector concat(StdLogicVector head,
                                    StdLogicVector tail)
convenience duplicate of append()


subset

public StdLogicVector subset(int upper,
                             int lower)
return the subset from 62 >= upper ... lower >= 0 of this StdLogicVector. Subset indices outside the valid range are silently clipped to the valid range (currently 62 ... 0).


equals

public boolean equals(java.lang.Object arg)
check whether Object arg is a StdLogicVector, and whether the this-object have the same width and the same StdLogic1164 values at each bit position.


isEqual

public static boolean isEqual(StdLogicVector L,
                              StdLogicVector R)

has_UXZ

public boolean has_UXZ()
check whether any bit in this StdLogicVector is undefined, that is, _U, _X, _Z, _W, or _D.


has_U

public boolean has_U()

has_X

public boolean has_X()

has_0

public boolean has_0()

has_1

public boolean has_1()

has_Z

public boolean has_Z()

has_L

public boolean has_L()

has_H

public boolean has_H()

has_W

public boolean has_W()

has_D

public boolean has_D()

is_000

public boolean is_000()
check whether all bits of this StdLogicVector are '0'


is_111

public boolean is_111()

is_ZZZ

public boolean is_ZZZ()

check

public static boolean check(StdLogicVector L,
                            StdLogicVector R)
                     throws java.lang.Exception
check whether this StdLogicVector has the arithmetic value 1, that is, the last bit (LSB) is 1, and all other bits are zero public boolean is_001() { return ( (_0_mask | _1_mask) == _length_mask) && (_1_mask == 1L)); } /** an utility method to check the validity of operands L and R to binary arithmetic or logical operations. This method throws an Exception if either L or R are null objects, if their widths mismatch. It will return false, if either one of the operands has an invalid arithmetic value (e.g. a _U, _X, _Z, _W or _D bit). If both operands are valid, it will return true.

Throws:
java.lang.Exception

isLessThan

public static boolean isLessThan(StdLogicVector L,
                                 StdLogicVector R)
                          throws java.lang.Exception
Throws:
java.lang.Exception

isLessEqual

public static boolean isLessEqual(StdLogicVector L,
                                  StdLogicVector R)
                           throws java.lang.Exception
Throws:
java.lang.Exception

isGreaterThan

public static boolean isGreaterThan(StdLogicVector L,
                                    StdLogicVector R)
                             throws java.lang.Exception
Throws:
java.lang.Exception

isGreaterEqual

public static boolean isGreaterEqual(StdLogicVector L,
                                     StdLogicVector R)
                              throws java.lang.Exception
Throws:
java.lang.Exception

toString

public java.lang.String toString()

parse

public void parse(java.lang.String s)
           throws java.lang.NumberFormatException
parse a bin/dec/hex-formatted value from a String and set the value of this StdLogicVector correspondingly. We expect the following formats:

Throws:
java.lang.NumberFormatException

toHexString

public java.lang.String toHexString()

toHexString

public java.lang.String toHexString(int minWidth)

toDecString

public java.lang.String toDecString()

toDecString

public java.lang.String toDecString(int minWidth)

toDecStringPadded

public java.lang.String toDecStringPadded()

toDecStringPadded

public java.lang.String toDecStringPadded(int minWidth)

toBinString

public java.lang.String toBinString()

toBinString

public java.lang.String toBinString(int minWidth)

addLeadingZeroes

public java.lang.String addLeadingZeroes(java.lang.String s,
                                         int width)

rightAlign

public java.lang.String rightAlign(java.lang.String s,
                                   int minWidth)

getWidthString

public java.lang.String getWidthString()

msg

public static void msg(java.lang.String msg)

demonstrateHotspot101Bug

public static void demonstrateHotspot101Bug(int n_bits)

selftest

public static void selftest()

testShiftRight

public static void testShiftRight()

testGetSignedValue

public static void testGetSignedValue()

main

public static void main(java.lang.String[] argv)