def test_bitwise(): check_unary_operator(invert, "Invert", wrapped=False) check_unary_overloaded_operator(operator.invert, Invert(4)) binary_bits_ops = [ (and_, operator.and_, And(2, 4)), (or_, operator.or_, Or(2, 4)), (xor, operator.xor, XOr(2, 4)), ] for args in binary_bits_ops: print("Testing {}".format(args)) check_binary_operator(args[0], args[2]) check_binary_overloaded_operator(args[1], args[2]) check_unary_operator(neg, "Negate", wrapped=False) check_unary_overloaded_operator(operator.neg, Negate(4), T=SInt) binary_arith_ops = [ (add, operator.add, Add(4, cin=False)), (sub, operator.sub, Sub(4)), ] for args in binary_arith_ops: print("Testing {}".format(args)) check_binary_operator(args[0], args[2], T=Bits) check_binary_overloaded_operator(args[1], args[2], T=UInt) check_binary_overloaded_operator(args[1], args[2], T=SInt) compare_ops = [ # (eq, operator.eq, EQ(4) ), (lt, operator.lt, ULT(4), SLT(4)), (le, operator.le, ULE(4), SLE(4)), (gt, operator.gt, UGT(4), SGT(4)), (ge, operator.ge, UGE(4), SGE(4)) ] for args in compare_ops: print("Testing {}".format(args)) check_binary_operator(args[0], args[2], out_type=Bit) if args[0] == eq: check_binary_overloaded_operator(args[1], args[2], out_type=Bit) else: check_binary_overloaded_operator(args[1], args[2], T=UInt, out_type=Bit) check_binary_overloaded_operator(args[1], args[3], T=SInt, out_type=Bit)
def ge(I0, I1, **kwargs): width = get_length(I0) if isinstance(I0, SIntType): return SGE(width)(I0, I1) else: return UGE(width)(I0, I1)
def ge(width, I0, I1, **kwargs): if isinstance(I0, m.SIntType): return SGE(width, **kwargs)(I0, I1) else: return UGE(width, **kwargs)(I0, I1)
from magma import uint, bits, concat, wire, compile, EndCircuit from mantle import UGE from loam.boards.icestick import IceStick icestick = IceStick() for i in range(4): icestick.J1[i].input().on() icestick.D1.on() main = icestick.main() A = uint(concat(main.J1[0:2], bits(0, 6))) B = uint(concat(main.J1[2:4], bits(0, 6))) O = main.D1 uge = UGE(8) wire(uge(A, B), main.D1) EndCircuit()