def __rrshift__(self, other):
return Operator(">>", [other, self])
- def add_op(self, op1, op2):
+ def add_op(self, op1, op2, carry):
op1 = getsig(op1)
op2 = getsig(op2)
shape = op1.shape()
comb = self.m.d.comb
comb += pa.a.eq(op1)
comb += pa.b.eq(op2)
- return pa.output
+ comb += pa.carry_in.eq(carry)
+ return (pa.output, pa.carry_out)
def __add__(self, other):
- return self.add_op(self, other)
+ result, _ =self.add_op(self, other, carry=0)
+ return result
- def addc(self, other, carry):
- shape = self.sig.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(self.sig)
- comb += pa.carry_in.eq(carry)
- if isinstance(other, PartitionedSignal):
- comb += pa.b.eq(other.sig)
- else:
- comb += pa.b.eq(other)
- return (pa.output, pa.carry_out)
def __radd__(self, other):
return self.add_op(other, self)
m.d.comb += self.gt_output.eq(self.a > self.b)
m.d.comb += self.eq_output.eq(self.a == self.b)
m.d.comb += self.ge_output.eq(self.a >= self.b)
- add_out, add_carry = self.a.addc(self.b, self.carry_in)
+ add_out, add_carry = self.a.add_op(self.a, self.b,
+ self.carry_in)
m.d.comb += self.add_output.eq(add_out)
m.d.comb += self.carry_out.eq(add_carry)
ppts = self.partpoints