Skip to content

olo_base_pkg_logic

Back to Entity List

Status Information

VHDL Source: olo_base_pkg_logic

Description

This package contains different logic functions not defined in IEEE packages but used by Open Logic internally or on its interfaces to the user (e.g. for port-widths depending on generics). The package is written mainly for these purposes and does not aim for completeness - nevertheless as a user you are free to use it for your code of course.

Definitions

Polynomial_Prbs\<N>_c

Common LFSR polynomials. X^N positions are marked by a one:

x⁹ + x⁵ + 1 = "100010000"

Functions

zerosVector() / onesVector()

Returns a std_logic_vector of a given length containing all zeros or all ones.

function zerosVector(size : in natural) return std_logic_vector;
function onesVector(size : in natural) return std_logic_vector;

shiftLeft() / shiftRight()

Shift a std_logic_vector an arbitrary number of bits to the right or left and shift in either '0' or '1' (configurable).

function shiftLeft(     arg  : in std_logic_vector;
                        bits : in integer;
                        fill : in std_logic := '0') return std_logic_vector;
function shiftRight(    arg  : in std_logic_vector;
                        bits : in integer;
                        fill : in std_logic := '0') return std_logic_vector;

bits is the number of bits to shift, fill is the bit-value shifted in.

binaryToGray() / grayToBinary()

Conversion between binary numbers and gray coded numbers.

binaryToGray(binary : in std_logic_vector) return std_logic_vector;
function grayToBinary(gray : in std_logic_vector) return std_logic_vector;

ppcOr()

Computation of the OR parallel prefix, which is useful for implementing arbiters.

ppcOr(inp : in std_logic_vector) return std_logic_vector;

to01X()

Convert a std_logic resp all bits in a std_logic_vector to '0', '1' or 'X'.

to01X(inp : in std_logic) return std_logic;
function to01X(inp : in std_logic_vector) return std_logic_vector;

'H' and 'L' are interpreted as '1' and '0', so this function can be used to convert weak signals from testbenches into binary signals.

  • '0', 'L' --> '0'
  • '1', 'H' --> '1'
  • all others --> 'X'

to01()

Convert a std_logic resp all bits in a std_logic_vector to '0' or '1'.

to01(inp : in std_logic) return std_logic;
function to01(inp : in std_logic_vector) return std_logic_vector;

'H' and 'L' are interpreted as '1' and '0', so this function can be used to convert weak signals from testbenches into binary signals.

  • '0', 'L' --> '0'
  • '1', 'H' --> '1'
  • all others --> '0'

invertBitOrder()

Invert bit-order in a std_logic_vector.

invertBitOrder(inp : in std_logic_vector) return std_logic_vector;

invertByteOrder()

Invert the byte-order in a std_logic_vector.

This function is only allowed for number of bits being a multiple of 8, otherwise it asserts an error.

invertByteOrder(inp : in std_logic_vector) return std_logic_vector;

getSetBitIndex()

Return the index of the first set bit ('1') in a std_logic_vector.

The search direction is controlled by the fromMsb flag:

  • If fromMsb = true, the search begins from the most significant bit (MSB, bit with highest index).
  • If fromMsb = false, the search begins from the least significant bit (LS, bit with lowest index).

If no bits are set:

  • Returns vec'low when searching from MSB (fromMsb = true)
  • Returns vec'high when searching from LSB (fromMsb = false)

This function behaves the same whether the input vector is defined with a downto or to range.

function getSetBitIndex(vec : in std_logic_vector; fromMsb : in boolean) return integer;

getLeadingSetBitIndex()

Return the index of the first set bit ('1') in a std_logic_vector, starting the search from the most significant bit (MSB).

If no bits are set, returns vec'low.

This function behaves the same whether the input vector is defined with a downto or to range.

function getLeadingSetBitIndex(vec : in std_logic_vector) return integer;

getTrailingSetBitIndex()

Return the index of the first set bit ('1') in a std_logic_vector, starting the search from the least significant bit (LSB).

If no bits are set, returns vec'high.

This function behaves the same whether the input vector is defined with a downto or to range.

function getTrailingSetBitIndex(vec : in std_logic_vector) return integer;

setBits()

Build a std_logic_vector of the given width with '1' at the listed bit indexes and '0' elsewhere. Useful for constructing bit-flip patterns and masks.

function setBits(indexes : in IntegerArray_t; width : in positive) return std_logic_vector;
function setBits(idx     : in natural;        width : in positive) return std_logic_vector;

Examples:

setBits(5, 10)         -- "0000100000"   (bit 5 set in a 10-bit vector)
setBits((3, 5), 10)    -- "0000101000"   (bits 3 and 5 set)
setBits(IntegerArray_t'(0, 2, 5), 8)  -- "00100101"

Note: VHDL aggregates need at least two elements, so the single-bit case must use the (idx, width) overload. The array overload covers two or more indexes via positional aggregate.