CarrySelectOnesComplementCompoundAdder constructor
- Logic a,
- Logic b, {
- Adder adderGen(}) = NativeAdder.new,
- Logic? subtractIn,
- bool generateCarryOut = false,
- bool generateCarryOutP1 = false,
- bool subtract = false,
- List<
int> widthGen() = CarrySelectCompoundAdder.splitSelectAdderAlgorithmSingleBlock, - String name = 'compound_adder',
- bool reserveName = false,
- bool reserveDefinitionName = false,
- String? definitionName,
Constructs a CarrySelectCompoundAdder using a set of
OnesComplementAdder in a carry-select configuration. Adds (or subtracts)
a
and b
to produce sum and sumP1 (sum plus 1).
adderGen
is the adder generator Function inside the OnesComplementAdder.subtractIn
is an optional Logic control for subtraction.subtract
is a boolean control for subtraction. It must befalse
(default) if asubtractIn
Logic is provided.generateCarryOut
set totrue
will create output carryOut and employ the ones-complement optimization of not adding '1' to convert back to 2s complement during subtraction on the sum.generateCarryOutP1
set totrue
will create output carryOutP1 and employ the ones-complement optimization of not adding '1' to convert back to 2s complement during subtraction on the sumP1.widthGen
is a Function which produces a list for splitting the adder for the carry-select chain. The default is CarrySelectCompoundAdder.splitSelectAdderAlgorithmSingleBlock,
Implementation
CarrySelectOnesComplementCompoundAdder(super.a, super.b,
{Adder Function(Logic, Logic, {Logic? carryIn}) adderGen =
NativeAdder.new,
Logic? subtractIn,
bool generateCarryOut = false,
bool generateCarryOutP1 = false,
bool subtract = false,
List<int> Function(int) widthGen =
CarrySelectCompoundAdder.splitSelectAdderAlgorithmSingleBlock,
super.name,
super.reserveName,
super.reserveDefinitionName,
String? definitionName})
: super(
definitionName: definitionName ??
'CarrySelectOnesComplementCompoundAdder_W${a.width}') {
subtractIn = (subtractIn != null)
? addInput('subtractIn', subtractIn, width: subtractIn.width)
: null;
if (generateCarryOut) {
addOutput('carryOut');
}
if (generateCarryOutP1) {
addOutput('carryOutP1');
}
final doSubtract = subtractIn ?? (subtract ? Const(subtract) : Const(0));
final csadder = CarrySelectCompoundAdder(a, b,
widthGen: widthGen,
subtractIn: subtractIn,
adderGen: (a, b, {carryIn, subtractIn, name = 'ones_complement'}) =>
OnesComplementAdder(a, b,
adderGen: adderGen,
carryIn: carryIn,
generateEndAroundCarry: true,
subtract: subtract,
chainable: true,
subtractIn: subtractIn));
addOutput('sign') <= mux(doSubtract, ~csadder.sum[-1], Const(0));
addOutput('signP1') <= mux(doSubtract, ~csadder.sumP1[-1], Const(0));
final sumPlus1 =
mux(doSubtract & csadder.sumP1[-1], ~csadder.sumP1, csadder.sumP1);
if (generateCarryOutP1) {
sumP1 <= sumPlus1;
carryOutP1! <= csadder.sumP1[-1];
} else {
sumP1 <=
mux(csadder.sumP1[-1],
ParallelPrefixIncr(sumPlus1).out.named('sumPlus2'), sumPlus1);
}
if (generateCarryOut) {
sum <= mux(doSubtract & csadder.sum[-1], ~csadder.sum, csadder.sum);
carryOut! <= csadder.sum[-1];
} else {
sum <= mux(doSubtract & csadder.sum[-1], sumPlus1, csadder.sum);
}
}