Unsigned

Immutable VHDL-2008 unsigned value. The leftmost bit is the most significant.

Conversion and resizing

classmethod from_int(value: int, *, width: int) → Self
Parameters:
  • value: int

    Python integer, including False as zero and True as one. Unsigned requires a non-negative value.

  • width: int

    Non-negative bit count; booleans raise TypeError. At positive widths, the integer must fit the type. At zero width, return a null vector regardless of the integer’s magnitude.

Returns:

A value with range width - 1 downto 0, or 0 downto 1 at zero width.

Raises:
  • OverflowError – The integer does not fit a positive width.

  • TypeError – value is not an integer, or width is omitted, non-integer, or boolean.

  • ValueError – width is negative, or an Unsigned input value is negative.

classmethod from_int(value: int, *, w: int) → Self
Parameters:
  • value: int

    Python integer, with the same constraints as the width form.

  • w: int

    Alias for width, with the same constraints.

Returns:

The same value as the width form.

Raises:

TypeError – Both width and w are supplied.

to_int() → int
Returns:

The arbitrary-precision Python integer interpretation. Weak L and H become 0 and 1. A null vector warns and returns zero.

Raises:

ValueError – A bit is unresolved, independently of COCOTB_RESOLVE_X.

to_logic_array() → LogicArray
Returns:

An independent cocotb array with the same bits and index range.

as_signed() → Signed
Returns:

A Signed interpretation of the same bits and range, equivalent to Signed(self).

as_unsigned() → Unsigned
Returns:

An Unsigned interpretation of the same bits and range, equivalent to Unsigned(self).

resize(width: int) → Self
Parameters:
  • width: int

    Non-negative result bit count, given positionally or by keyword.

Returns:

A resized value with descending range. Zero width gives 0 downto 1; resizing a null input to positive width gives zeros. Unsigned widening adds zeros and narrowing keeps the low bits. Signed widening copies the raw sign bit; narrowing keeps the original sign and the lowest width - 1 bits.

Raises:
  • TypeError – width is omitted, non-integer, or boolean.

  • ValueError – width is negative.

resize(*, w: int) → Self
Parameters:
  • w: int

    Alias for width, with the same constraints.

Returns:

The same value as the width form.

Raises:

TypeError – w is supplied with a positional width or width keyword.

Remainder and modulus

mod(other: Self | int) → Self
Parameters:
  • other: Self | int

    Divisor of the same numeric type, or a VHDL scalar integer operand.

Returns:

VHDL mod, equivalent to %. Vector/vector width follows the divisor; an integer overload returns this value’s width.

Raises:

ZeroDivisionError – The resolved divisor is zero.

rem(other: Self | int) → Self
Parameters:
  • other: Self | int

    Divisor of the same numeric type, or a VHDL scalar integer operand.

Returns:

VHDL rem, whose nonzero result follows the dividend’s sign. Vector/vector width follows the divisor; an integer overload returns this value’s width.

Raises:

ZeroDivisionError – The resolved divisor is zero.

rrem(other: int) → Self
Parameters:
  • other: int

    Integer dividend for other rem self.

Returns:

The scalar/vector VHDL remainder, with this value’s width.

Raises:
  • ZeroDivisionError – This value is a resolved zero divisor.

  • ValueError – The unsigned overload encounters a null vector, or the integer dividend needs more bits than a non-null vector. The package’s array assignment then has unequal lengths. Resolved zero division is checked before the non-null length error.

Matching comparisons

Matching equality treats - as a wildcard. A U scalar comparison produces U, and an X scalar comparison produces X, even if another bit differs. Matching ordering rejects -, returns X for other unresolved values, and interprets weak L and H numerically. Null operands warn and return X. Integer operands undergo checked conversion at this value’s width.

match_eq(other: Self | int) → Logic
Parameters:
  • other: Self | int

    Right operand for VHDL ?=.

Returns:

The VHDL matching-equality logic value.

match_ne(other: Self | int) → Logic
Parameters:
  • other: Self | int

    Right operand for VHDL ?/=.

Returns:

The VHDL matching-inequality logic value.

match_lt(other: Self | int) → Logic
Parameters:
  • other: Self | int

    Right operand for VHDL ?<.

Returns:

The VHDL matching less-than logic value.

Raises:

ValueError – Either operand contains -.

match_le(other: Self | int) → Logic
Parameters:
  • other: Self | int

    Right operand for VHDL ?<=.

Returns:

The VHDL matching less-than-or-equal logic value.

Raises:

ValueError – Either operand contains -.

match_gt(other: Self | int) → Logic
Parameters:
  • other: Self | int

    Right operand for VHDL ?>.

Returns:

The VHDL matching greater-than logic value.

Raises:

ValueError – Either operand contains -.

match_ge(other: Self | int) → Logic
Parameters:
  • other: Self | int

    Right operand for VHDL ?>=.

Returns:

The VHDL matching greater-than-or-equal logic value.

Raises:

ValueError – Either operand contains -.

Logic

Logical vector operands require the same numeric type and equal lengths. A scalar Logic operand broadcasts across all bits. All nine IEEE logic states participate in the logic tables.

nand(other: Self | Logic) → Self
Parameters:
  • other: Self | Logic

    Vector or broadcast scalar for VHDL nand.

Returns:

Elementwise NAND, with the logical result range described below.

Raises:

ValueError – Vector lengths differ.

nor(other: Self | Logic) → Self
Parameters:
  • other: Self | Logic

    Vector or broadcast scalar for VHDL nor.

Returns:

Elementwise NOR, with the logical result range described below.

Raises:

ValueError – Vector lengths differ.

xnor(other: Self | Logic) → Self
Parameters:
  • other: Self | Logic

    Vector or broadcast scalar for VHDL xnor.

Returns:

Elementwise XNOR, with the logical result range described below.

Raises:

ValueError – Vector lengths differ.

Vector/vector logical results and ~x use width - 1 downto 0, including -1 downto 0 for null vectors. Scalar/vector logical results use 1 to width, including 1 to 0 for null vectors.

and_reduce() → Logic
Returns:

VHDL reduction AND; a null vector produces 1.

nand_reduce() → Logic
Returns:

VHDL reduction NAND; a null vector produces 0.

or_reduce() → Logic
Returns:

VHDL reduction OR; a null vector produces 0.

nor_reduce() → Logic
Returns:

VHDL reduction NOR; a null vector produces 1.

xor_reduce() → Logic
Returns:

VHDL reduction XOR; a null vector produces 0.

xnor_reduce() → Logic
Returns:

VHDL reduction XNOR; a null vector produces 1.

Shifts and rotations

Movement copies raw logic states. Results use width - 1 downto 0, with 0 downto 1 for null vectors. Signed arithmetic-right shifts keep the input range when the count is zero or the input has one bit. All movement counts require integers other than booleans; True and False raise TypeError, including for null inputs.

shift_left(count: int) → Self
Parameters:
  • count: int

    Non-negative number of bit positions.

Returns:

A same-width left shift, filling with zero; equivalent to <<.

shift_right(count: int) → Self
Parameters:
  • count: int

    Non-negative number of bit positions.

Returns:

A same-width right shift, filling with the raw sign for Signed and zero for Unsigned; equivalent to >>.

rotate_left(count: int) → Self
Parameters:
  • count: int

    Non-negative number of bit positions, reduced modulo the nonzero width.

Returns:

A same-width left rotation.

rotate_right(count: int) → Self
Parameters:
  • count: int

    Non-negative number of bit positions, reduced modulo the nonzero width.

Returns:

A same-width right rotation.

sll(count: int) → Self
Parameters:
  • count: int

    Signed bit-position count. A negative count reverses direction.

Returns:

VHDL logical left shift, filling with zero in either direction.

srl(count: int) → Self
Parameters:
  • count: int

    Signed bit-position count. A negative count reverses direction.

Returns:

VHDL logical right shift, filling with zero in either direction.

sla(count: int) → Self
Parameters:
  • count: int

    Signed bit-position count. A negative count reverses direction.

Returns:

VHDL arithmetic left shift. Left movement fills with zero; right movement copies the sign for Signed and fills with zero for Unsigned.

sra(count: int) → Self
Parameters:
  • count: int

    Signed bit-position count. A negative count reverses direction.

Returns:

VHDL arithmetic right shift. Right movement copies the sign for Signed and fills with zero for Unsigned; left movement fills with zero.

rol(count: int) → Self
Parameters:
  • count: int

    Signed bit-position count. A negative count rotates right.

Returns:

VHDL left rotation.

ror(count: int) → Self
Parameters:
  • count: int

    Signed bit-position count. A negative count rotates left.

Returns:

VHDL right rotation.

Concatenation

concat(other: Self | Logic) → Self
Parameters:
  • other: Self | Logic

    Same-type vector or scalar logic value placed after this value’s bits.

Returns:

Raw concatenation with range 0 to total_width - 1. If both vectors are null, the result has the right operand’s range.

class coaxi.Unsigned(value: Literal[0], *, width: int) → None
Parameters:
  • value: Literal[0]

    Python integer 0. Use from_int() for other integers or booleans.

  • width: int

    Non-negative bit count. The value has range width - 1 downto 0, or 0 downto 1 at zero width.

Returns:

None.

Raises:
  • TypeError – value is not integer 0, neither width name is supplied, or the bit count is non-integer or boolean.

  • ValueError – width is negative.

class Unsigned(value: Literal[0], *, w: int) → None
Parameters:
  • value: Literal[0]

    Python integer 0.

  • w: int

    Alias for width, with the same constraints.

Returns:

None.

Raises:

TypeError – Both width and w are supplied.

class Unsigned(value: LogicArray | Signed | Unsigned) → None
Parameters:
  • value: LogicArray | Signed | Unsigned

    Bits and index range to copy. Non-null ranges require non-negative indices. The bits are reinterpreted as unsigned: Unsigned(Signed.from_int(-1, width=8)) represents 255.

Returns:

None.

Raises:
  • TypeError – width or w is supplied with a vector.

  • ValueError – A non-null range has a negative index.

Self in the signatures denotes Unsigned. Properties and operator contracts are in Numeric values.