+class MaskedFullAdder(FullAdder):
+ """Masked Full Adder.
+
+ :attribute mask: the carry partition mask
+ :attribute in0: the first input
+ :attribute in1: the second input
+ :attribute in2: the third input
+ :attribute sum: the sum output
+ :attribute mcarry: the masked carry output
+
+ FullAdders are always used with a "mask" on the output. To keep
+ the graphviz "clean", this class performs the masking here rather
+ than inside a large for-loop.
+ """
+
+ def __init__(self, width):
+ """Create a ``MaskedFullAdder``.
+
+ :param width: the bit width of the input and output
+ """
+ FullAdder.__init__(self, width)
+ self.mask = Signal(width)
+ self.mcarry = Signal(width)
+
+ def elaborate(self, platform):
+ """Elaborate this module."""
+ m = FullAdder.elaborate(self, platform)
+ m.d.comb += self.mcarry.eq((self.carry << 1) & self.mask)
+ return m
+
+