hwt.hdl.types package

This package contains HDL types (e.g. Bits), value classes and conversion functions for them.

Submodules

hwt.hdl.types.array module

class hwt.hdl.types.array.HArray(element_t, size, const=False)[source]

Bases: hwt.hdl.types.hdlType.HdlType

HDL array type

Variables:
  • element_t – type of elements
  • size – number of items
__init__(element_t, size, const=False)[source]

Initialize self. See help(type(self)) for accurate signature.

bit_length()[source]
Returns:bit width for this type
classmethod getValueCls()[source]
Attention:Overrode in implementation of concrete HdlType.
Returns:class for value derived from this type
classmethod get_reinterpret_cast_fn()[source]

Get method for converting type

hwt.hdl.types.arrayCast module

hwt.hdl.types.arrayCast.getBits_from_array(array, wordWidth, start, end, reinterpretElmToType=None)[source]

Gets value of bits between selected range from memory

Parameters:
  • start – bit address of start of bit of bits
  • end – bit address of first bit behind bits
Returns:

instance of BitsVal (derived from SimBits type) which contains copy of selected bits

hwt.hdl.types.arrayCast.reinterpret_cast_harray(typeFrom, sigOrVal, toType)[source]
hwt.hdl.types.arrayCast.reinterpret_harray_to_harray(typeFrom, sigOrVal, arrayT)[source]
hwt.hdl.types.arrayCast.reinterpret_harray_to_hstruct(typeFrom, sigOrVal, structT)[source]
hwt.hdl.types.arrayCast.reinterptet_harray_to_bits(typeFrom, sigOrVal, bitsT)[source]

Cast HArray signal or value to signal or value of type Bits

hwt.hdl.types.arrayVal module

class hwt.hdl.types.arrayVal.HArrayVal(dtype: HdlType, val, vld_mask)[source]

Bases: hwt.hdl.value.HValue

Class for values of array HDL type

_eq(other)[source]
_eq__val(other)[source]
_getitem__val(key)[source]
Atention:this will clone item from array, iterate over .val if you need to modify items
_is_full_valid()[source]
_setitem__val(index, value)[source]
classmethod from_py(typeObj, val, vld_mask=None)[source]
Parameters:
  • val – None or dictionary {index:HValue} or iterrable of values
  • vld_mask – if is None validity is resolved from val if is 0 value is invalidated if is 1 value has to be valid
to_py()[source]

hwt.hdl.types.bitValFunctions module

hwt.hdl.types.bitValFunctions.bitsArithOp(self, other, op)[source]
hwt.hdl.types.bitValFunctions.bitsBitOp(self: Union[hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase, hwt.hdl.value.HValue], other, op: hwt.hdl.operatorDefs.OpDefinition, getVldFn: Callable[[hwt.hdl.value.HValue, hwt.hdl.value.HValue], int], reduceValCheckFn: Callable[[hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase, hwt.hdl.value.HValue], bool], reduceSigCheckFn: Callable[[hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase, bool, bool], Union[hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase, hwt.hdl.value.HValue]])[source]

Apply a generic bitwise binary operator

Attention:

If other is Bool signal, convert this to bool (not ideal, due VHDL event operator)

Variables:
  • self – operand 0
  • other – operand 1
  • op – operator used
  • getVldFn – function to resolve invalid (X) states
  • reduceValCheckFn – function to reduce useless operators (partially evaluate the expression if possible)
  • reduceSigCheckFn – function to reduce useless operators for signals and its negation flags (e.g. a&a = a, a&~a=0, b^b=0) function parameters are in format (op0Original:RtlSignalBase, op0Negated: bool, op1Negated:bool) -> Union[RtlSignalBase, HValue]: returns result signal if reduction is possible else None
hwt.hdl.types.bitValFunctions.bitsCmp(self, other, op, selfReduceVal, evalFn=None)[source]

Apply a generic comparison binary operator

Attention:

If other is Bool signal convert this to bool (not ideal, due VHDL event operator)

Variables:
  • self – operand 0
  • other – operand 1
  • op – operator used
  • selfReduceVal – the value which is a result if operands are all same signal (e.g. a==a = 1, b<b=0)
  • evalFn – override of a python operator function (by default one from “op” is used)
hwt.hdl.types.bitValFunctions.bitsCmp_detect_useless_cmp(op0, op1, op)[source]
hwt.hdl.types.bitValFunctions.extractNegation(sig: hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase)[source]
Returns:tuple(the signal without negation, True if signal was negated)

hwt.hdl.types.bitVal_opReduce module

hwt.hdl.types.bitVal_opReduce.reduceSigCheckFnAnd(op0Original: hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase, op0Negated: bool, op1Negated: bool) → Union[hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase, hwt.hdl.value.HValue][source]
hwt.hdl.types.bitVal_opReduce.reduceSigCheckFnOr(op0Original: hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase, op0Negated: bool, op1Negated: bool) → Union[hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase, hwt.hdl.value.HValue][source]
hwt.hdl.types.bitVal_opReduce.reduceSigCheckFnXor(op0Original: hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase, op0Negated: bool, op1Negated: bool) → Union[hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase, hwt.hdl.value.HValue][source]
hwt.hdl.types.bitVal_opReduce.tryReduceAnd(sig: hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase, val: hwt.hdl.value.HValue)[source]

Return sig and val reduced by & operator or None if it is not possible to statically reduce expression

hwt.hdl.types.bitVal_opReduce.tryReduceOr(sig: hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase, val: hwt.hdl.value.HValue)[source]

Return sig and val reduced by | operator or None if it is not possible to statically reduce expression

hwt.hdl.types.bitVal_opReduce.tryReduceXor(sig: hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase, val: hwt.hdl.value.HValue)[source]

Return sig and val reduced by ^ operator or None if it is not possible to statically reduce expression

hwt.hdl.types.bits module

class hwt.hdl.types.bits.Bits(bit_length, signed=None, force_vector=False, negated=False, name=None, const=False, strict_sign=True, strict_width=True)[source]

Bases: hwt.hdl.types.hdlType.HdlType, pyMathBitPrecise.bits3t.Bits3t

Elemental HDL type representing bits (vector or single bit)

__init__(bit_length, signed=None, force_vector=False, negated=False, name=None, const=False, strict_sign=True, strict_width=True)[source]
Parameters:negated – if true the value is in negated form
domain_size()[source]
Returns:how many values can have specified type
classmethod getValueCls()[source]
Attention:Overrode in implementation of concrete HdlType.
Returns:class for value derived from this type
classmethod get_auto_cast_fn()[source]

Get method for converting type

classmethod get_reinterpret_cast_fn()[source]

Get method for converting type

hwt.hdl.types.bitsCast module

hwt.hdl.types.bitsCast.convertBits(self: hwt.hdl.types.bits.Bits, sigOrVal, toType: hwt.hdl.types.hdlType.HdlType)[source]

Cast Bit subtypes, (integers, bool, …)

hwt.hdl.types.bitsCast.convertBits__val(self: hwt.hdl.types.bits.Bits, val: BitVal, toType: hwt.hdl.types.hdlType.HdlType)[source]
hwt.hdl.types.bitsCast.reinterpretBits(self: hwt.hdl.types.bits.Bits, sigOrVal: Union[hwt.synthesizer.rtlLevel.rtlSignal.RtlSignal, hwt.hdl.value.HValue], toType: hwt.hdl.types.hdlType.HdlType)[source]

Cast object of same bit size between to other type (f.e. bits to struct, union or array)

hwt.hdl.types.bitsCast.reinterpretBits__val(self: hwt.hdl.types.bits.Bits, val: hwt.hdl.value.HValue, toType: hwt.hdl.types.hdlType.HdlType)[source]
hwt.hdl.types.bitsCast.reinterpret_bits_to_harray(sigOrVal: Union[hwt.synthesizer.rtlLevel.rtlSignal.RtlSignal, hwt.hdl.value.HValue], hArrayT: hwt.hdl.types.array.HArray)[source]
hwt.hdl.types.bitsCast.reinterpret_bits_to_hstruct(val: Union[hwt.synthesizer.rtlLevel.rtlSignal.RtlSignal, hwt.hdl.value.HValue], hStructT: hwt.hdl.types.struct.HStruct)[source]

Reinterpret signal of type Bits to signal of type HStruct

hwt.hdl.types.bitsCast.reinterpret_bits_to_hstruct__val(val: hwt.hdl.value.HValue, hStructT: hwt.hdl.types.struct.HStruct)[source]

Reinterpret signal of type Bits to signal of type HStruct

hwt.hdl.types.bitsCast.transfer_signals(src: hwt.synthesizer.interfaceLevel.mainBases.InterfaceBase, dst: hwt.synthesizer.interfaceLevel.mainBases.InterfaceBase)[source]

hwt.hdl.types.bitsVal module

class hwt.hdl.types.bitsVal.BitsVal(t: pyMathBitPrecise.bits3t.Bits3t, val: int, vld_mask: int)[source]

Bases: pyMathBitPrecise.bits3t.Bits3val, hwt.hdl.types.eventCapableVal.EventCapableVal, hwt.hdl.value.HValue

Attention:operator on signals are using value operator functions as well
_BOOL = <Bits, "bool", 1bit>
_auto_cast(dtype)[source]

Cast value to a compatible type

_concat(other)[source]

Concatenate this with other to one wider value/signal

_concat__val(other)[source]
_convSign(signed)[source]

Convert signum, no bit manipulation just data are represented differently

Parameters:signed – if True value will be signed, if False value will be unsigned, if None value will be vector without any sign specification
_convSign__val(signed: Optional[bool])[source]
_eq(other)[source]

Operator self._eq(other) as self == other == is not overriden in order to prevent tricky behavior if hashing partially valid values

_isOn()[source]
_signed()[source]
_ternary(a, b)[source]

Ternary operator (a if self else b).

_unsigned()[source]
_vec()[source]
classmethod from_py(typeObj, val, vld_mask=None)[source]
hwt.hdl.types.bitsVal._get_operator_i_am_the_result_of(val_or_sig: Union[hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase, hwt.hdl.value.HValue])[source]

hwt.hdl.types.defs module

Definitions of most common types

hwt.hdl.types.enum module

class hwt.hdl.types.enum.HEnum(name, valueNames, const=False)[source]

Bases: hwt.hdl.types.hdlType.HdlType

Hdl enum type

Variables:
  • name – name of this type
  • _allValues – tuple of all values for this enum
Note:

for each value there is a property on this type object

__init__(name, valueNames, const=False)[source]
Parameters:
  • name – name for this type
  • valueNames – sequence of string which will be used as names for enum members
all_mask()[source]
bit_length()[source]
domain_size()[source]
Returns:how many values can have specified type
classmethod getValueCls()[source]
Attention:Overrode in implementation of concrete HdlType.
Returns:class for value derived from this type

hwt.hdl.types.enumVal module

class hwt.hdl.types.enumVal.HEnumVal(dtype: HdlType, val, vld_mask)[source]

Bases: hwt.hdl.value.HValue

_eq(other)[source]
_eq__val(other)[source]
_ne__val(other)[source]
classmethod from_py(typeObj, val, vld_mask=None)[source]
Parameters:
  • val – value of python type bool or None
  • typeObj – instance of HEnum
  • vld_mask – if is None validity is resolved from val if is 0 value is invalidated if is 1 value has to be valid

hwt.hdl.types.eventCapableVal module

class hwt.hdl.types.eventCapableVal.EventCapableVal[source]

Bases: object

Base class for event capable values

_onFallingEdge()[source]
_onRisingEdge()[source]

hwt.hdl.types.float module

class hwt.hdl.types.float.HFloat(exponent_w, mantisa_w, name=None, const=False)[source]

Bases: hwt.hdl.types.hdlType.HdlType, pyMathBitPrecise.floatt.Floatt

Elemental HDL type representing IEEE 754 like float type.

__init__(exponent_w, mantisa_w, name=None, const=False)[source]
Parameters:negated – if true the value is in negated form
classmethod getValueCls()[source]
Attention:Overrode in implementation of concrete HdlType.
Returns:class for value derived from this type

hwt.hdl.types.floatVal module

class hwt.hdl.types.floatVal.HFloatVal(dtype: HdlType, val, vld_mask)[source]

Bases: hwt.hdl.value.HValue, pyMathBitPrecise.floatt.FloattVal

HValue class for HFloat type

_eq(other)[source]
_eq_val(other)[source]
_is_full_valid()[source]
Returns:True if all bits in value are valid
classmethod from_py(typeObj, val, vld_mask=None)[source]
to_py()[source]

Convert to python slice object

hwt.hdl.types.hdlType module

class hwt.hdl.types.hdlType.HdlType(const=False)[source]

Bases: object

Base class for all hardware related types.

Variables:
  • _auto_cast_fn – convert function (attribute set on first convert function call)
  • _reinterpret_cast_fn – reinterpret function (attribute set on first convert function call)
__init__(const=False)[source]

Initialize self. See help(type(self)) for accurate signature.

_as_hdl(to_Hdl: ToHdlAst, declaration)[source]
_as_hdl_requires_def(to_Hdl: ToHdlAst, other_types: list)[source]
_from_py(v, vld_mask)[source]

same as from_py just without type checks

auto_cast(sigOrVal, toType)[source]

Cast value or signal of this type to another compatible type.

Parameters:
  • sigOrVal – instance of signal or value to cast
  • toType – instance of HdlType to cast into
from_py(v, vld_mask=None)[source]

Construct value of this type. Delegated on value class for this type

classmethod getValueCls()[source]
Attention:Overrode in implementation of concrete HdlType.
Returns:class for value derived from this type
classmethod get_auto_cast_fn()[source]

Get method for converting type

classmethod get_reinterpret_cast_fn()[source]

Get method for converting type

reinterpret_cast(sigOrVal, toType)[source]

Cast value or signal of this type to another type of same size.

Parameters:
  • sigOrVal – instance of signal or value to cast
  • toType – instance of HdlType to cast into
exception hwt.hdl.types.hdlType.MethodNotOverloaded[source]

Bases: NotImplementedError

hwt.hdl.types.hdlType.default_auto_cast_fn(typeFrom, sigOrVal, toType)[source]
hwt.hdl.types.hdlType.default_reinterpret_cast_fn(typeFrom, sigOrVal, toType)[source]

hwt.hdl.types.slice module

class hwt.hdl.types.slice.HSlice(const=False)[source]

Bases: hwt.hdl.types.hdlType.HdlType

Slice type, used for selecting items from arrays or vectors

classmethod getValueCls()[source]
Attention:Overrode in implementation of concrete HdlType.
Returns:class for value derived from this type

hwt.hdl.types.sliceUtils module

hwt.hdl.types.sliceUtils.slice_to_SLICE(sliceVals, width)[source]

convert python slice to value of SLICE hdl type

hwt.hdl.types.sliceVal module

class hwt.hdl.types.sliceVal.HSliceVal(dtype: HdlType, val, vld_mask)[source]

Bases: hwt.hdl.value.HValue

HValue class for HSlice type

_eq(other)[source]
_eq_val(other)[source]
_is_full_valid()[source]
_size()[source]
Returns:how many bits is this slice selecting
classmethod from_py(typeObj, val, vld_mask=None)[source]
staticEval()[source]
to_py()[source]

Convert to python slice object

hwt.hdl.types.sliceVal.slice_member_to_hval(v)[source]

hwt.hdl.types.stream module

class hwt.hdl.types.stream.HStream(element_t, frame_len=inf, start_offsets: Optional[List[int]] = None, const=False)[source]

Bases: hwt.hdl.types.hdlType.HdlType

Stream is an abstract type. It is an array with unspecified size.

Variables:
  • element_t – type of smalest chunk of data which can be send over this stream
  • len_min – minimum repetitions of element_t (inclusive interval)
  • len_max – maximum repetitions of element_t (inclusive interval)
  • start_offsets – list of numbers which represents the number of invalid bytes before valid data on stream (invalid bytes means the bytes which does not have bit validity set, e.g. Axi4Stream keep=0b10 -> offset=1 )
__init__(element_t, frame_len=inf, start_offsets: Optional[List[int]] = None, const=False)[source]

Initialize self. See help(type(self)) for accurate signature.

bit_length()[source]
classmethod getValueCls()[source]
Attention:Overrode in implementation of concrete HdlType.
Returns:class for value derived from this type

hwt.hdl.types.streamVal module

class hwt.hdl.types.streamVal.HStreamVal(dtype: HdlType, val, vld_mask)[source]

Bases: hwt.hdl.value.HValue

Class for values of HStream HDL type

_eq(other)[source]
_eq__val(other)[source]
_getitem__val(key)[source]
Atention:this will clone item from array, iterate over .val if you need to modify items
_is_full_valid()[source]
_setitem__val(index, value)[source]
classmethod from_py(typeObj, val, vld_mask=None)[source]
Parameters:
  • typeObj – HStream instance
  • val – None or iterrable of values
  • vld_mask – if is None validity is resolved from val if is 0 value is invalidated if is 1 value has to be valid
to_py()[source]

hwt.hdl.types.string module

class hwt.hdl.types.string.HString(const=False)[source]

Bases: hwt.hdl.types.hdlType.HdlType

all_mask()[source]
classmethod getValueCls()[source]
Attention:Overrode in implementation of concrete HdlType.
Returns:class for value derived from this type

hwt.hdl.types.stringVal module

class hwt.hdl.types.stringVal.HStringVal(dtype: HdlType, val, vld_mask)[source]

Bases: hwt.hdl.value.HValue

Value class for hdl HString type

_eq(other)[source]
_eq__val(other)[source]
classmethod from_py(typeObj, val, vld_mask=None)[source]
Parameters:
  • val – python string or None
  • typeObj – instance of HString HdlType
  • vld_mask – if is None validity is resolved from val if is 0 value is invalidated if is 1 value has to be valid
to_py()[source]

hwt.hdl.types.struct module

class hwt.hdl.types.struct.HStruct(*template, name=None, const=False)[source]

Bases: hwt.hdl.types.hdlType.HdlType

HDL structure type

Variables:
  • fields – tuple of HStructField instances in this struct
  • name – name of this HStruct type
  • field_by_name – dictionary which maps the name of the field to HStructField instance
  • valueCls – Class of value for this type as usual in HdlType implementations
__init__(*template, name=None, const=False)[source]
Parameters:
  • template – list of tuples (type, name) or HStructField objects name can be None (= padding)
  • name – optional name used for debugging purposes
bit_length()[source]
getValueCls()[source]
Attention:Overrode in implementation of concrete HdlType.
Returns:class for value derived from this type
classmethod get_reinterpret_cast_fn()[source]

Get method for converting type

class hwt.hdl.types.struct.HStructField(typ: hwt.hdl.types.hdlType.HdlType, name: str, meta=None)[source]

Bases: object

__init__(typ: hwt.hdl.types.hdlType.HdlType, name: str, meta=None)[source]

Initialize self. See help(type(self)) for accurate signature.

class hwt.hdl.types.struct.HStructFieldMeta(split=False)[source]

Bases: object

Meta for field in struct type

Variables:split – flag which specifies if structured data type of this field should be synchronized as a one interface or each it’s part should be synchronized separately
__init__(split=False)[source]

Initialize self. See help(type(self)) for accurate signature.

hwt.hdl.types.structCast module

hwt.hdl.types.structCast.hstruct_reinterpret(self, sigOrVal, toType: hwt.hdl.types.hdlType.HdlType)[source]
hwt.hdl.types.structCast.hstruct_reinterpret_to_bits(self, sigOrVal, toType: hwt.hdl.types.hdlType.HdlType)[source]
hwt.hdl.types.structCast.hstruct_reinterpret_using_bits(self, sigOrVal, toType: hwt.hdl.types.hdlType.HdlType)[source]

hwt.hdl.types.structUtils module

hwt.hdl.types.structUtils.HdlType_select(t: hwt.hdl.types.struct.HStruct, fieldsToUse: Dict[Union[int, str], filed_filter_t])[source]

Select fields from type structure (rest will become padding)

Parameters:
  • t – HdlType type instance
  • fieldsToUse – dict {name:{…}} or set of names to select, dictionary is used to select nested fields in HStruct/HUnion fields/array items (f.e. {“struct1”: {“field1”, “field2”}, “field3”:{}} will select field1 and 2 from struct1 and field3 from root)
hwt.hdl.types.structUtils.field_path_get_type(root: hwt.hdl.types.hdlType.HdlType, field_path: hwt.synthesizer.typePath.TypePath)[source]

Get a data type of element using field path

hwt.hdl.types.structValBase module

class hwt.hdl.types.structValBase.StructValBase(typeObj, val, skipCheck=False)[source]

Bases: hwt.hdl.value.HValue

Base class for values for structure types. Every structure type has it’s own value class derived from this.

__init__(typeObj, val, skipCheck=False)[source]
Parameters:
  • val – None or dict {field name: field value}
  • typeObj – instance of HString HdlType
  • skipCheck – flag to skip field name consistency in val
_eq(other)[source]
_is_full_valid()[source]
classmethod from_py(typeObj, val, vld_mask=None)[source]
Parameters:
  • val – None or dict {field name: field value}
  • typeObj – instance of HString HdlType
  • vld_mask – if is None validity is resolved from val if is 0 value is invalidated if is 1 value has to be valid
to_py()[source]

hwt.hdl.types.typeCast module

hwt.hdl.types.typeCast.toHVal(op: Any, suggestedType: Optional[hwt.hdl.types.hdlType.HdlType] = None)[source]

Convert python or hdl value/signal object to hdl value/signal object

hwt.hdl.types.union module

class hwt.hdl.types.union.HUnion(*template, name=None, const=False)[source]

Bases: hwt.hdl.types.hdlType.HdlType

HDL union type (same data multiple representations)

Variables:
  • fields – read only OrderedDict {key:StructField} for each member in this union
  • name – name of this type
  • __bit_length_val – precalculated bit_length of this type
__init__(*template, name=None, const=False)[source]
Parameters:
  • template – list of tuples (type, name) or HStructField objects name can be None (= padding)
  • name – optional name used for debugging purposes
bit_length()[source]
getValueCls()[source]
Attention:Overrode in implementation of concrete HdlType.
Returns:class for value derived from this type
class hwt.hdl.types.union.HUnionMemberHandler(field)[source]

Bases: object

Object which manages the acces to HUnion field

__init__(field)[source]

Initialize self. See help(type(self)) for accurate signature.

get(parent)[source]
set(parent, v)[source]
class hwt.hdl.types.union.UnionValBase(typeObj, val)[source]

Bases: hwt.hdl.value.HValue

Base class for values for union types. Every union type has it’s own value class derived from this.

Variables:
  • _dtype – union type of this value
  • __usedField – member which is actually used to represent value
  • __val – value for __usedField
__init__(typeObj, val)[source]
Parameters:
  • val – None or tuple (member name, member value)
  • typeObj – instance of HUnion HdlType for this value
_dtype
_usedField
_val
classmethod from_py(typeObj, val, vld_mask=None)[source]
Parameters:
  • val – None or tuple (member name, member value)
  • typeObj – instance of HUnion HdlType for this value
  • vld_mask – if is None validity is resolved from val if is 0 value is invalidated if is 1 value has to be valid

hwt.hdl.types.utils module

hwt.hdl.types.utils.HValue_from_words(t: hwt.hdl.types.hdlType.HdlType, data: List[Union[hwt.hdl.value.HValue, hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase, int]], getDataFn=None, dataWidth=None) → hwt.hdl.value.HValue[source]

Parse raw Bits array to a value of specified HdlType

hwt.hdl.types.utils.is_only_padding(t: hwt.hdl.types.hdlType.HdlType) → bool[source]
hwt.hdl.types.utils.walkFlattenFields(sigOrVal: Union[hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase, hwt.hdl.value.HValue], skipPadding=True)[source]

Walk all simple values in HStruct or HArray