Integer¶
Implements fixed width integer types: Uint
- unsigned, Int
- signed and Integer
- sign agnostic type. These types correspond to
HDL logic vector types.
Objects of these classes can also be instantiated and they provide some integer arithmetic capabilities.
-
class
IntegerType
¶ Bases:
pygears.typing.uint.IntegralType
Defines lib methods for all Integer based classes.
-
__mul__
(other)¶ Returns the same type, whose width is equal to the sum of operand widths if both operands are unsigned. Returns the signed Int type if other operand is signed.
>>> Uint[8] + Uint[8] Uint[16] >>> Uint[8] + Int[8] Int[16]
-
property
args
¶ Returns a list of values supplied for each generic parameter.
>>> Tuple[Uint[1], Uint[2]].args [Uint[1], Uint[2]]
-
property
base
¶ Returns base generic class of the type.
>>> assert Uint[16].base == Uint
-
property
fields
¶ Returns the names of the generic parameters.
>>> Tuple[Uint[1], Uint[2]].fields ('f0', 'f1')
>>> Tuple[{'u1': Uint[1], 'u2': Uint[2]}].fields ('u0', 'u1')
-
is_generic
()¶ Return True if no values have been supplied for the generic parameters.
>>> Uint.is_generic() True
>>> Uint['template'].is_generic() False
-
items
()¶ Generator that yields (key, element) pairs.
-
keys
()¶ Returns a list of keys that can be used for indexing the type.
>>> Int[8].keys() [0, 1, 2, 3, 4, 5, 6, 7]
-
property
specified
¶ Return True if all generic parameters were supplied concrete values.
>>> Uint['template'].specified False
>>> Uint[16].specified True
-
property
templates
¶ Returns a list of templated generic variables within the type. The type is searched recursively. Each template is reported only once.
>>> Tuple[Tuple['T1', 'T2'], 'T1'].templates ['T1', 'T2']
-
property
width
¶ Calculates the bit width of the type.
>>> int(Tuple[Uint[1], Uint[2]]) 3
-
-
class
Integer
¶ Bases:
pygears.typing.uint.Integral
Base type for both
Int
andUint
generic types. Corresponds to HDL logic vector types. For an example Integer[9] translates tologic [8:0]
.-
__len__
()¶ Returns the number of bits used for the representation
>>> len(Integer[8](0)) 8
-
classmethod
decode
(val)¶ Creates Integer object from any int-convertible object val.
>>> Integer[8].decode(0xffff) Integer[8](255)
-
width
¶ Returns the number of bits used for the representation
>>> Integer[8](0).width 8
-