def _eq__val(self, other): assert self._dtype.element_t == other._dtype.element_t assert self._dtype.size == other._dtype.size eq = True vld = 1 keysA = set(self.val) keysB = set(other.val) sharedKeys = keysA.union(keysB) lsh = len(sharedKeys) if (lsh == int(self._dtype.size) and len(keysA) == lsh and len(keysB) == lsh): for k in sharedKeys: a = self.val[k] b = other.val[k] eq = eq and bool(a) == bool(b) if not eq: break vld = vld & a.vld_mask & b.vld_mask else: eq = False vld = 0 return BOOL.getValueCls()(BOOL, int(eq), vld)
def type_check_bool_param(self, name): STR_BOOL = ("TRUE", "FALSE") v = getattr(self, name) if self._store_manager.serializer_cls == VerilogSerializer: # for verilog we need to convert it to "TRUE" or "FALSE" string if not isinstance(v, STR.getValueCls()): if isinstance(v, (bool, BIT.getValueCls())): v = "TRUE" if v else "FALSE" else: assert v in STR_BOOL, (name, v) v = STR.from_py(v) object.__setattr__(self, name, v) else: assert v._dtype == STR, (name, "must be of type ", STR, " or compatible, is:", v) else: if not isinstance(v, BOOL.getValueCls()): if isinstance(v, (str, STR.getValueCls())): v = str(v) if v == "FALSE": v = False elif v == "TRUE": v = True else: raise AssertionError( name, "must be of type ", BOOL, " or string \"TRUE\" or \"FALSE\" or compatible, is:", v) v = BOOL.from_py(v) object.__setattr__(self, name, v) else: assert v._dtype == BOOL, (name, "must be of type ", BOOL, " or compatible, is:", v)
def _eq__val(self, other): assert self._dtype.elmType == other._dtype.elmType assert self._dtype.size == other._dtype.size eq = True vld = 1 updateTime = -1 keysA = set(self.val) keysB = set(other.val) sharedKeys = keysA.union(keysB) lsh = len(sharedKeys) if (lsh == int(self._dtype.size) and len(keysA) == lsh and len(keysB) == lsh): for k in sharedKeys: a = self.val[k] b = other.val[k] eq = eq and a == b if not eq: break vld = vld & a.vldMask & b.vldMask updateTime = max(updateTime, a.updateTime, b.updateTime) else: eq = False vld = 0 return BOOL.getValueCls()(eq, BOOL, vld, updateTime)
def _eq__val(self, other): assert self._dtype.element_t == other._dtype.element_t eq = True vld = 1 if (len(self.val) == len(other.val)): for a, b in zip(self.val, other.val): eq = eq and bool(a) == bool(b) if not eq: break vld = vld & a.vld_mask & b.vld_mask else: eq = False vld = 0 return BOOL.getValueCls()(BOOL, int(eq), vld)
from hwt.hdl.value import Value, areValues from hwt.hdl.types.defs import BOOL from hwt.hdl.operator import Operator from hwt.hdl.operatorDefs import AllOps from hwt.doc_markers import internal BoolVal = BOOL.getValueCls() class HEnumVal(Value): @classmethod def fromPy(cls, val, typeObj, vldMask=None): """ :param val: value of python type bool or None :param typeObj: instance of HEnum :param vldMask: if is None validity is resolved from val if is 0 value is invalidated if is 1 value has to be valid """ if val is None: assert vldMask is None or vldMask == 0 valid = False val = typeObj._allValues[0] else: if vldMask is None or vldMask == 1: assert isinstance(val, str) valid = True else: valid = False val = None
def _eq__val(self, other): eq = self.val == other.val vld = int(self.vldMask and other.vldMask) updateTime = max(self.updateTime, other.updateTime) return BOOL.getValueCls()(eq, BOOL, vld, updateTime)
def _eq__val(self, other): eq = self.val == other.val vld = int(self.vld_mask and other.vld_mask) return BOOL.getValueCls()(BOOL, int(eq), vld)