comb += pa.carry_in.eq(carry)
return (pa.output, pa.carry_out)
+ def sub_op(self, op1, op2, carry=~0):
+ op1 = getsig(op1)
+ op2 = getsig(op2)
+ shape = op1.shape()
+ pa = PartitionedAdder(shape[0], self.partpoints)
+ setattr(self.m.submodules, self.get_modname('add'), pa)
+ comb = self.m.d.comb
+ comb += pa.a.eq(op1)
+ comb += pa.b.eq(~op2)
+ comb += pa.carry_in.eq(carry)
+ return (pa.output, pa.carry_out)
+
def __add__(self, other):
result, _ =self.add_op(self, other, carry=0)
return result
-
def __radd__(self, other):
- return self.add_op(other, self)
+ result, _ =self.add_op(other, self)
+ return result
def __sub__(self, other):
- return self.sub_op(self, other) # TODO, subop
+ result, _ = self.sub_op(self, other) # TODO, subop
+ return result
def __rsub__(self, other):
- return self.sub_op(other, self) # TODO, subop
+ result, _ = self.sub_op(other, self) # TODO, subop
+ return result
def __mul__(self, other):
return Operator("*", [self, other])
self.a = PartitionedSignal(partpoints, width)
self.b = PartitionedSignal(partpoints, width)
self.add_output = Signal(width)
+ self.sub_output = Signal(width)
self.eq_output = Signal(len(partpoints)+1)
self.gt_output = Signal(len(partpoints)+1)
self.ge_output = Signal(len(partpoints)+1)
return mask & ((a & mask) + (b & mask) + lsb)
def test_sub_fn(carry_in, a, b, mask):
- raise NotImplementedError
- # TODO
lsb = mask & ~(mask-1) if carry_in else 0
- return mask & ((a & mask) + (b & mask) + lsb)
+ return mask & ((a & mask) + (~b & mask) + lsb)
def test_op(msg_prefix, carry, test_fn, mod_attr, *mask_list):
rand_data = []
self.assertEqual(y, outval, msg)
for (test_fn, mod_attr) in ((test_add_fn, "add"),
- #(test_sub_fn, "sub"),
+ (test_sub_fn, "sub"),
):
yield part_mask.eq(0)
yield from test_op("16-bit", 1, test_fn, mod_attr, 0xFFFF)