m.d.comb += both_ones.eq(self.a & self.b)
# `different` is set if there are a different number of leading
# zeros so far
- m.d.comb += different.eq(~(self.a ^ self.b))
+ m.d.comb += different.eq(self.a ^ self.b)
# now [ab]use add: the last bit [carry-out] is the result
csum = Signal(self.width + 1)
carry_in = 1 # both have no leading zeros so far, so set carry
- m.d.comb += csum.eq(both_ones + different + carry_in)
+ m.d.comb += csum.eq(both_ones + (~different) + carry_in)
m.d.comb += self.out.eq(csum[self.width]) # out is carry-out
return m