def bitsCmp_detect_useless_cmp(op0, op1, op): v = int(op1) width = op1._dtype.bit_length() if op0._dtype.signed: min_val = -1 if width == 1 else mask(width - 1) - 1 max_val = 0 if width == 1 else mask(width - 1) else: min_val = 0 max_val = mask(width) if v == min_val: # value can not be lower than min_val if op == AllOps.GE: # -> always True return BOOL.from_py(1, 1) elif op == AllOps.LT: # -> always False return BOOL.from_py(0, 1) elif op == AllOps.LE: # convert <= to == to highlight the real function return AllOps.EQ elif v == max_val: # value can not be greater than max_val if op == AllOps.GT: # always False return BOOL.from_py(0, 1) elif op == AllOps.LE: # always True return BOOL.from_py(1, 1) elif op == AllOps.GE: # because value can not be greater than max return AllOps.EQ
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 hBool(pyVal): """ create hdl bool value (for example bool value in vhdl)""" return BOOL.from_py(pyVal)
def hBool(v): return BOOL.from_py(v)