hwt/hdl/types/bitsCast.py
def convertBits(self, sigOrVal, toType):
    """
    Cast signed-unsigned, to int or bool
    """
    if isinstance(sigOrVal, Value):
        return convertBits__val(self, sigOrVal, toType)
    elif isinstance(toType, HBool):
        if self.bit_length() == 1:
            v = 0 if sigOrVal._dtype.negated else 1
            return sigOrVal._eq(self.getValueCls().fromPy(v, self))
    elif isinstance(toType, Bits):
        if self.bit_length() == toType.bit_length():
            return sigOrVal._convSign(toType.signed)
    elif toType == INT:
        return Operator.withRes(AllOps.BitsToInt, [sigOrVal], toType)

    return default_auto_cast_fn(self, sigOrVal, toType)
def convertBits(self, sigOrVal, toType):
    """
    Cast signed-unsigned, to int or bool
    """
    if isinstance(sigOrVal, Value):
        return convertBits__val(self, sigOrVal, toType)
    elif isinstance(toType, HBool):
        if self.bit_length() == 1:
            v = 0 if sigOrVal._dtype.negated else 1
            return sigOrVal._eq(self.getValueCls().fromPy(v, self))
    elif isinstance(toType, Bits):
        if self.bit_length() == toType.bit_length():
            return sigOrVal._convSign(toType.signed)
    elif toType == INT:
        return Operator.withRes(AllOps.BitsToInt, [sigOrVal], toType)

    return default_auto_cast_fn(self, sigOrVal, toType)
def convertBits ( self , sigOrVal , toType ) : if isinstance ( sigOrVal , Value ) : return convertBits__val ( self , sigOrVal , toType ) elif isinstance ( toType , HBool ) : if self . bit_length ( ) == 1 : v = 0 if sigOrVal . _dtype . negated else 1 return sigOrVal . _eq ( self . getValueCls ( ) . fromPy ( v , self ) ) elif isinstance ( toType , Bits ) : if self . bit_length ( ) == toType . bit_length ( ) : return sigOrVal . _convSign ( toType . signed ) elif toType == INT : return Operator . withRes ( AllOps . BitsToInt , [ sigOrVal ] , toType ) return default_auto_cast_fn ( self , sigOrVal , toType )
Cast signed-unsigned, to int or bool
Cast signed - unsigned to int or bool