CarrySelectOnesComplementCompoundAdder constructor
- Logic a,
- Logic b, {
- Adder adderGen(}) = NativeAdder.new,
- @Deprecated('Use subtract with a 1-bit Logic instead.') Logic? subtractIn,
- bool generateCarryOut = false,
- bool generateCarryOutP1 = false,
- dynamic subtract,
- 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).
adderGenis the adder generator Function inside the OnesComplementAdder.subtractconfigures subtraction statically with aboolor at runtime with a 1-bit Logic. It defaults to addition.subtractInis a deprecated runtime subtraction control. It may be provided with an explicitsubtract: falsefor compatibility.generateCarryOutset totruewill create output carryOut and employ the ones-complement optimization of not adding '1' to convert back to 2s complement during subtraction on the sum.generateCarryOutP1set totruewill create output carryOutP1 and employ the ones-complement optimization of not adding '1' to convert back to 2s complement during subtraction on the sumP1.widthGenis 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,
@Deprecated('Use subtract with a 1-bit Logic instead.') Logic? subtractIn,
bool generateCarryOut = false,
bool generateCarryOutP1 = false,
dynamic subtract,
List<int> Function(int) widthGen =
CarrySelectCompoundAdder.splitSelectAdderAlgorithmSingleBlock,
super.name,
super.reserveName,
super.reserveDefinitionName,
String? definitionName})
: super(
definitionName: definitionName ??
'CarrySelectOnesComplementCompoundAdder_W${a.width}') {
final subtractIsActive =
subtract != null && (subtract is! bool || subtract);
if (subtractIn != null && subtractIsActive) {
throw RohdHclException(
"Provide either deprecated 'subtractIn' or 'subtract', "
'but not both.');
}
subtractParameter = subtractIn != null
? StaticOrRuntimeParameter(
name: 'subtractIn', runtimeConfig: subtractIn)
: StaticOrRuntimeParameter.ofDynamic(subtract);
if (generateCarryOut) {
addOutput('carryOut');
}
if (generateCarryOutP1) {
addOutput('carryOutP1');
}
final doSubtract = subtractParameter.getLogic(this);
final csadder = CarrySelectCompoundAdder(a, b,
widthGen: widthGen,
subtractIn: doSubtract,
adderGen: (a, b, {carryIn, subtractIn, name = 'ones_complement'}) =>
OnesComplementAdder(a, b,
adderGen: adderGen,
carryIn: carryIn,
generateEndAroundCarry: true,
chainable: true,
subtract: 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);
}
}