Signed¶
Immutable VHDL-2008 signed value. The leftmost bit is the sign bit.
Conversion and resizing¶
- classmethod from_int(value: int, *, width: int) Self¶
- Parameters:
value: intPython integer, including
Falseas zero andTrueas one.Unsignedrequires a non-negative value.width: intNon-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, or0 downto 1at zero width.- Raises:
OverflowError – The integer does not fit a positive width.
TypeError –
valueis not an integer, orwidthis omitted, non-integer, or boolean.ValueError –
widthis negative, or anUnsignedinput value is negative.
- classmethod from_int(value: int, *, w: int) Self
- Parameters:
value: intPython integer, with the same constraints as the
widthform.w: intAlias for
width, with the same constraints.
- Returns:
The same value as the
widthform.- Raises:
TypeError – Both
widthandware supplied.
- to_int() int¶
- Returns:
The arbitrary-precision Python integer interpretation. Weak
LandHbecome0and1. 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
Signedinterpretation of the same bits and range, equivalent toSigned(self).
- as_unsigned() Unsigned¶
- Returns:
An
Unsignedinterpretation of the same bits and range, equivalent toUnsigned(self).
- resize(width: int) Self¶
- Parameters:
width: intNon-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 lowestwidth - 1bits.- Raises:
TypeError –
widthis omitted, non-integer, or boolean.ValueError –
widthis negative.
- resize(*, w: int) Self
- Parameters:
w: intAlias for
width, with the same constraints.
- Returns:
The same value as the
widthform.- Raises:
TypeError –
wis supplied with a positional width orwidthkeyword.
Remainder and modulus¶
- mod(other: Self | int) Self¶
- Parameters:
other: Self | intDivisor 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 | intDivisor 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: intInteger 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 | intRight operand for VHDL
?=.
- Returns:
The VHDL matching-equality logic value.
- match_ne(other: Self | int) Logic¶
- Parameters:
other: Self | intRight operand for VHDL
?/=.
- Returns:
The VHDL matching-inequality logic value.
- match_lt(other: Self | int) Logic¶
- Parameters:
other: Self | intRight 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 | intRight 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 | intRight 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 | intRight 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 | LogicVector 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 | LogicVector 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 | LogicVector 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: intNon-negative number of bit positions.
- Returns:
A same-width left shift, filling with zero; equivalent to
<<.
- shift_right(count: int) Self¶
- Parameters:
count: intNon-negative number of bit positions.
- Returns:
A same-width right shift, filling with the raw sign for
Signedand zero forUnsigned; equivalent to>>.
- rotate_left(count: int) Self¶
- Parameters:
count: intNon-negative number of bit positions, reduced modulo the nonzero width.
- Returns:
A same-width left rotation.
- rotate_right(count: int) Self¶
- Parameters:
count: intNon-negative number of bit positions, reduced modulo the nonzero width.
- Returns:
A same-width right rotation.
- sll(count: int) Self¶
- Parameters:
count: intSigned 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: intSigned 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: intSigned bit-position count. A negative count reverses direction.
- Returns:
VHDL arithmetic left shift. Left movement fills with zero; right movement copies the sign for
Signedand fills with zero forUnsigned.
- sra(count: int) Self¶
- Parameters:
count: intSigned bit-position count. A negative count reverses direction.
- Returns:
VHDL arithmetic right shift. Right movement copies the sign for
Signedand fills with zero forUnsigned; left movement fills with zero.
- rol(count: int) Self¶
- Parameters:
count: intSigned bit-position count. A negative count rotates right.
- Returns:
VHDL left rotation.
- ror(count: int) Self¶
- Parameters:
count: intSigned bit-position count. A negative count rotates left.
- Returns:
VHDL right rotation.
Concatenation¶
- concat(other: Self | Logic) Self¶
- Parameters:
other: Self | LogicSame-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.Signed(value: Literal[0], *, width: int) None¶
- Parameters:
value: Literal[0]Python integer
0. Usefrom_int()for other integers or booleans.width: intNon-negative bit count. The value has range
width - 1 downto 0, or0 downto 1at zero width.
- Returns:
None.- Raises:
TypeError –
valueis not integer0, neither width name is supplied, or the bit count is non-integer or boolean.ValueError –
widthis negative.
- class Signed(value: Literal[0], *, w: int) None
- Parameters:
value: Literal[0]Python integer
0.w: intAlias for
width, with the same constraints.
- Returns:
None.- Raises:
TypeError – Both
widthandware supplied.
- class Signed(value: LogicArray | Signed | Unsigned) None
- Parameters:
value: LogicArray | Signed | UnsignedBits and index range to copy. Non-null ranges require non-negative indices. The bits are reinterpreted as signed:
Signed(Unsigned.from_int(255, width=8))represents-1.
- Returns:
None.- Raises:
TypeError –
widthorwis supplied with a vector.ValueError – A non-null range has a negative index.
Self in the signatures denotes Signed. Properties and operator contracts
are in Numeric values.