pyMathBitPrecise package¶
Submodules¶
pyMathBitPrecise.array3t module¶
pyMathBitPrecise.bit_utils module¶
- exception pyMathBitPrecise.bit_utils.ValidityError¶
Bases:
ValueError
Value is not fully defined and thus can not be used
- pyMathBitPrecise.bit_utils.align(val: int, lowerBitCntToAlign: int) int ¶
Cut off lower bits to align a int value.
- pyMathBitPrecise.bit_utils.align_with_known_width(val, width: int, lowerBitCntToAlign: int)¶
Does same as
align()
just with the known width of val
- pyMathBitPrecise.bit_utils.apply_set_and_clear(val: int, set_flag: int, clear_flag: int)¶
- Parameters:
val – an input value of the flag(s)
set_flag – a mask of bits to set to 1
clear_flag – a mask of bits to set to 0
- Note:
set has higher priority
- Returns:
new value of the flag
- pyMathBitPrecise.bit_utils.bit_field(_from: int, to: int) int ¶
Generate int which has bits ‘_from’ to ‘to’ set to ‘1’
- Note:
_from 0 to 1 -> ‘1’
- pyMathBitPrecise.bit_utils.bit_list_reversed_bits_in_bytes(bitList, extend=None)¶
Byte reflection (0x0f -> 0xf0)
- pyMathBitPrecise.bit_utils.bit_list_reversed_endianity(bitList, extend=True)¶
- pyMathBitPrecise.bit_utils.bit_list_to_int(bitList)¶
In input list LSB first, in result little endian ([0, 1] -> 0b10)
- pyMathBitPrecise.bit_utils.bit_set_to(val: int, bitNo: int, bitVal: int) int ¶
Set specified bit in int to a specified value
- pyMathBitPrecise.bit_utils.byte_list_to_be_int(_bytes: List[int])¶
In input list LSB first, in result little endian ([1, 0] -> 0x0001)
- pyMathBitPrecise.bit_utils.clean_bit(val: int, bitNo: int) int ¶
Set a specified bit to ‘0’
- pyMathBitPrecise.bit_utils.extend_to_size(collection, items, pad=0)¶
- pyMathBitPrecise.bit_utils.get_bit(val: int, bitNo: int) int ¶
Get bit from int
- pyMathBitPrecise.bit_utils.get_bit_range(val: int, bitsStart: int, bitsLen: int) int ¶
Get sequence of bits from an int value
- pyMathBitPrecise.bit_utils.int_list_to_int(il: List[int], item_width: int)¶
[0x0201, 0x0403] -> 0x04030201
- pyMathBitPrecise.bit_utils.int_to_int_list(v: int, item_width: int, number_of_items: int)¶
opposite of
int_list_to_int()
- pyMathBitPrecise.bit_utils.iter_bits(val: int, length: int) Generator[int, int, None] ¶
Iterate bits in int. LSB first.
- pyMathBitPrecise.bit_utils.mask(bits: int) int ¶
Generate mask of specified size (sequence of ‘1’)
- pyMathBitPrecise.bit_utils.mask_bytes(val: int, byte_mask: int, mask_bit_length: int) int ¶
Use each bit in byte_mask as a mask for each byte in val.
- Note:
Useful for masking of value for HW interfaces where mask is represented by a vector of bits where each bit is mask for byte in data vector.
- pyMathBitPrecise.bit_utils.normalize_slice(s: slice, obj_width: int) Tuple[int, int] ¶
- pyMathBitPrecise.bit_utils.reverse_bits(val, width)¶
Reverse bits in integer value of specified width
- pyMathBitPrecise.bit_utils.set_bit(val: int, bitNo: int) int ¶
Set a specified bit to ‘1’
- pyMathBitPrecise.bit_utils.set_bit_range(val: int, bitStart: int, bitsLen: int, newBits: int) int ¶
Set specified range of bits in int to a specified value
- pyMathBitPrecise.bit_utils.to_signed(val: int, width: int) int ¶
Convert unsigned int to negative int which has same bits set (emulate sign overflow).
- Note:
bits in value are not changed, just python int object has signed flag set properly. And number is in expected range.
- pyMathBitPrecise.bit_utils.to_unsigned(val, width) int ¶
- pyMathBitPrecise.bit_utils.toggle_bit(val: int, bitNo: int) int ¶
Toggle specified bit in int
pyMathBitPrecise.bits3t module¶
- class pyMathBitPrecise.bits3t.Bits3t(bit_length: int, signed=False, name: str | None = None, force_vector=False, strict_sign=True, strict_width=True)¶
Bases:
object
Meta type for integer of specified size where each bit can be ‘1’, ‘0’ or ‘X’ for undefined value.
- Variables:
~.bit_length – number representation of value of this type
~.signed – flag which tells if this type is signed or not
~._all_mask – cached value of mask for all bits
~.name – name for anotation
~.force_vector –
use always hdl vector type (for example std_logic_vector(0 downto 0)
instead of std_logic in VHDL, wire[1] instead of wire)
~.strict_sign – same thing as strict_width just for signed/unsigned
~.strict_width – if True the arithmetic, bitwise and comparision operators can be performed only on value of this exact same width
- Note:
operation is not strict if at least one operand does not have strict flag set, the result width/sign is taken from other operand (or first if bouth are not strict)
- all_mask()¶
- Returns:
mask for bites of this type ( 0b111 for Bits(3) )
- bit_length()¶
- Returns:
number of bits required for representation of value of this type
- class pyMathBitPrecise.bits3t.Bits3val(t: Bits3t, val: int, vld_mask: int)¶
Bases:
object
Class for value of Bits3t type
- Variables:
~._dtype – reference on type of this value
~.val – always unsigned representation int value
~.vld_mask – always unsigned value of the mask, if bit in mask is ‘0’ the corresponding bit in val is invalid
- to_py() int ¶
- pyMathBitPrecise.bits3t.bitsArithOp__val(self: Bits3val, other: Bits3val | int, evalFn) Bits3val ¶
Apply arithmetic operator
pyMathBitPrecise.bits3t_vld_masks module¶
- pyMathBitPrecise.bits3t_vld_masks.vld_mask_for_and(a, b) int ¶
- pyMathBitPrecise.bits3t_vld_masks.vld_mask_for_or(a, b) int ¶
- pyMathBitPrecise.bits3t_vld_masks.vld_mask_for_xor(a, b) int ¶
pyMathBitPrecise.enum3t module¶
- class pyMathBitPrecise.enum3t.Enum3t¶
Bases:
object
- Note:
use as Python enum.Enum, the value is always ignored and name is used as a value
- class pyMathBitPrecise.enum3t.Enum3tMeta(cls, bases, classdict)¶
Bases:
type
- class pyMathBitPrecise.enum3t.Enum3val(t, val, vld_mask)¶
Bases:
object
- pyMathBitPrecise.enum3t.define_Enum3t(name: str, values: List[str])¶
Define Enum3t subclass from enum names
pyMathBitPrecise.floatt module¶
- class pyMathBitPrecise.floatt.Floatt(exponent_w, mantisa_w, name=None)¶
Bases:
object
IEEE 754 like float type with configurable sizes fo exponent and mantisa.
- all_mask()¶
- Returns:
mask for bites of this type ( 0b111 for Bits(3) )
- bit_length()¶
- Returns:
number of bits required for representation of value of this type
- class pyMathBitPrecise.floatt.FloattVal(t: Floatt, val: Tuple[int, int, int], vld_mask: int)¶
Bases:
object
Class for value of Bits3t type
- Variables:
~._dtype – reference on type of this value
~.val – always unsigned representation int value
~.vld_mask – always unsigned value of the mask, if bit in mask is ‘0’ the corresponding bit in val is invalid
- to_py() int ¶
- pyMathBitPrecise.floatt.FloattVal__arith_op(self, other, op)¶
- pyMathBitPrecise.floatt.FloattVal__cmp_op(self, other, op)¶
pyMathBitPrecise.utils module¶
- pyMathBitPrecise.utils.grouper(n, iterable, padvalue=None)¶
grouper(3, ‘abcdefg’, ‘x’) –> (‘a’,’b’,’c’), (‘d’,’e’,’f’), (‘g’,’x’,’x’)