Example #1
0
def shift_right(value, size, signed=True):
    if isinstance(value, vtypes.Int):
        value = value.value

    if isinstance(value, int) and isinstance(size, int):
        return value >> size

    if isinstance(value, bool) and isinstance(size, int):
        return value >> size

    return vtypes.Mux(signed, vtypes.Sra(value, size), vtypes.Srl(value, size))
Example #2
0
 def __init__(self, left, right):
     lpoint = left.point if isinstance(left, _FixedBase) else 0
     rpoint = right.point if isinstance(right, _FixedBase) else 0
     lsigned = vtypes.get_signed(left)
     rsigned = vtypes.get_signed(right)
     point = _min_mux(_max_mux(lpoint, rpoint), lpoint + rpoint)
     signed = lsigned and rsigned if not self.overwrite_signed else False
     ldata = to_signed(left) if signed else left
     rdata = to_signed(right) if signed else right
     shift_size = lpoint + rpoint - point
     data = vtypes.Times(ldata, rdata)
     if signed:
         data = vtypes.Sra(data, shift_size)
     else:
         data = vtypes.Srl(data, shift_size)
     _FixedSkipUnaryOperator.__init__(self, data, point, signed)
Example #3
0
def shift_right(value, size, signed=True):
    if isinstance(value, vtypes.Int):
        value = value.value

    if isinstance(value, vtypes.Float):
        value = value.value

    if isinstance(value, int) and isinstance(size, int):
        return value >> size

    if isinstance(value, bool) and isinstance(size, int):
        return value >> size

    if isinstance(value, float) and isinstance(size, int):
        return value / (2 ** size)

    if signed:
        return vtypes.Sra(value, size)

    return vtypes.Srl(value, size)
Example #4
0
 def visit_Sra(self, node):
     left = self.visit(node.left)
     right = self.visit(node.right)
     return vtypes.Sra(left, right)
Example #5
0
 def int_part(self):
     return vtypes.Sra(self, self.point)