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.
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.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
-
_getitem__val
(key)[source]¶ Atention: this will clone item from array, iterate over .val if you need to modify items
-
hwt.hdl.types.bitValFunctions module¶
-
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.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.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
-
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.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>¶
-
_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
-
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
hwt.hdl.types.enumVal module¶
-
class
hwt.hdl.types.enumVal.
HEnumVal
(dtype: HdlType, val, vld_mask)[source]¶ Bases:
hwt.hdl.value.HValue
hwt.hdl.types.eventCapableVal module¶
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.
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
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)
-
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
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
hwt.hdl.types.sliceUtils module¶
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
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 )
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
-
_getitem__val
(key)[source]¶ Atention: this will clone item from array, iterate over .val if you need to modify items
-
hwt.hdl.types.string module¶
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
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
- template – list of tuples (type, name) or
- fields – tuple of
-
class
hwt.hdl.types.struct.
HStructField
(typ: hwt.hdl.types.hdlType.HdlType, name: str, meta=None)[source]¶ Bases:
object
hwt.hdl.types.structCast module¶
-
hwt.hdl.types.structCast.
hstruct_reinterpret
(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.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
-
hwt.hdl.types.typeCast module¶
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
-
class
hwt.hdl.types.union.
HUnionMemberHandler
(field)[source]¶ Bases:
object
Object which manages the acces to HUnion field
-
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
¶