def bitsBitOp(self, other, op, getVldFn, reduceCheckFn): """ :attention: If other is Bool signal, convert this to bool (not ideal, due VHDL event operator) """ other = toHVal(other, self._dtype) iamVal = isinstance(self, HValue) otherIsVal = isinstance(other, HValue) if iamVal and otherIsVal: other = other._auto_cast(self._dtype) return bitsBitOp__val(self, other, op._evalFn, getVldFn) else: s_t = self._dtype o_t = other._dtype if not isinstance(o_t, s_t.__class__): raise TypeError(o_t) if s_t == o_t: pass elif o_t == BOOL and s_t != BOOL: self = self._auto_cast(BOOL) return op._evalFn(self, other) elif o_t != BOOL and s_t == BOOL: other = other._auto_cast(BOOL) return op._evalFn(self, other) elif s_t.bit_length() == 1 and o_t.bit_length() == 1\ and s_t.signed is o_t.signed \ and s_t.force_vector != o_t.force_vector: if s_t.force_vector: self = self[0] else: other = other[0] else: raise TypeError("Can not apply operator %r (%r, %r)" % (op, self._dtype, other._dtype)) if otherIsVal: r = reduceCheckFn(self, other) if r is not None: return r elif iamVal: r = reduceCheckFn(other, self) if r is not None: return r return Operator.withRes(op, [self, other], self._dtype)
def bitsBitOp(self, other, op, getVldFn, reduceCheckFn): """ :attention: If other is Bool signal, convert this to bool (not ideal, due VHDL event operator) """ other = toHVal(other, self._dtype) iamVal = isinstance(self, Value) otherIsVal = isinstance(other, Value) if iamVal and otherIsVal: other = other._auto_cast(self._dtype) return bitsBitOp__val(self, other, op._evalFn, getVldFn) else: if self._dtype == other._dtype: pass elif other._dtype == BOOL and self._dtype != BOOL: self = self._auto_cast(BOOL) return op._evalFn(self, other) elif other._dtype != BOOL and self._dtype == BOOL: other = other._auto_cast(BOOL) return op._evalFn(self, other) else: raise TypeError("Can not apply operator %r (%r, %r)" % (op, self._dtype, other._dtype)) if otherIsVal: r = reduceCheckFn(self, other) if r is not None: return r elif iamVal: r = reduceCheckFn(other, self) if r is not None: return r return Operator.withRes(op, [self, other], self._dtype)
def bitsBitOp(self, other, op: OpDefinition, getVldFn, reduceCheckFn, selfReduceVal): """ Apply a generic bitwise binary operator :attention: If other is Bool signal, convert this to bool (not ideal, due VHDL event operator) :ivar self: operand 0 :ivar other: operand 1 :ivar op: operator used :ivar getVldFn: function to resolve invalid (X) states :ivar reduceCheckFn: function to reduce useless operators (partially evaluate the expression if possible) :ivar selfReduceVal: the value which is a result if operands are all same signal (e.g. a&a = a, b^b=0) """ other = toHVal(other, self._dtype) iamVal = isinstance(self, HValue) otherIsVal = isinstance(other, HValue) if iamVal and otherIsVal: other = other._auto_cast(self._dtype) return bitsBitOp__val(self, other, op._evalFn, getVldFn) else: s_t = self._dtype o_t = other._dtype if not isinstance(o_t, s_t.__class__): raise TypeError(o_t) if s_t == o_t: pass elif o_t == BOOL and s_t != BOOL: self = self._auto_cast(BOOL) return op._evalFn(self, other) elif o_t != BOOL and s_t == BOOL: other = other._auto_cast(BOOL) return op._evalFn(self, other) else: if s_t.signed is not o_t.signed and bool(s_t.signed) == bool( o_t.signed): # automatically cast unsigned to vector if s_t.signed == False and o_t.signed is None: self = self._vec() s_t = self._dtype elif s_t.signed is None and o_t.signed == False: other = other._vec() o_t = other._dtype else: raise ValueError("Invalid value for signed flag of type", s_t.signed, o_t.signed, s_t, o_t) if s_t == o_t: # due to previsous cast the type may become the same pass elif s_t.bit_length() == 1 and o_t.bit_length() == 1\ and s_t.signed is o_t.signed \ and s_t.force_vector != o_t.force_vector: # automatically cast to vector with a single item to a single bit if s_t.force_vector: self = self[0] else: other = other[0] else: raise TypeError("Can not apply operator %r (%r, %r)" % (op, self._dtype, other._dtype)) if otherIsVal: r = reduceCheckFn(self, other) if r is not None: return r elif iamVal: r = reduceCheckFn(other, self) if r is not None: return r elif self is other: return selfReduceVal return Operator.withRes(op, [self, other], self._dtype)