OnesComplementAdder constructor
- Logic a,
- Logic b, {
- Adder adderGen(}) = NativeAdder.new,
- Logic? subtractIn,
- bool generateEndAroundCarry = false,
- Logic? carryIn,
- bool subtract = false,
- bool chainable = false,
- bool reserveName = false,
- bool reserveDefinitionName = false,
- String? definitionName,
- String name = 'ones_complement_adder',
OnesComplementAdder constructor with an adder functor adderGen.
- A subtractor is created if
subtractis set totrue. Alternatively, ifsubtractconfiguration isfalse, and a Lgic control signalsubtractInis provided, then subtraction can be dynamically selected. Otherwise an adder is constructed. - If
generateEndAroundCarryistrue, then the end-around carry is not performed and is provided as output endAroundCarry. IfgenerateEndAroundCarryisfalse, extra hardware takes care of adding the end-around carry to sum. carryInallows for another adder to chain into this one.chainabletells this adder to not store the endAroundCarry in the sign bit as well, but to zero that to allow adders to be chained such as for use in the CarrySelectCompoundAdder.
Implementation
OnesComplementAdder(super.a, super.b,
{Adder Function(Logic, Logic, {Logic? carryIn}) adderGen =
NativeAdder.new,
Logic? subtractIn,
this.generateEndAroundCarry = false,
super.carryIn,
bool subtract = false,
bool chainable = false,
super.reserveName,
super.reserveDefinitionName,
String? definitionName,
super.name = 'ones_complement_adder'})
: super(
definitionName:
definitionName ?? 'OnesComplementAdder_W${a.width}') {
if (generateEndAroundCarry) {
addOutput('endAroundCarry');
}
if ((subtractIn != null) & subtract) {
throw RohdHclException(
"either provide a Logic signal 'subtractIn' for runtime "
" configuration, or a boolean parameter 'subtract' for "
'generation time configuration, but not both.');
}
this.subtractIn =
(subtractIn != null) ? addInput('subtractIn', subtractIn) : null;
_sign = addOutput('sign');
final doSubtract =
(this.subtractIn ?? (subtract ? Const(subtract) : Const(0)))
.named('dosubtract', naming: Naming.mergeable);
final adderSum =
adderGen(a, mux(doSubtract, ~b, b), carryIn: carryIn ?? Const(0))
.sum
.named('adderSum', naming: Naming.mergeable);
if (generateEndAroundCarry) {
endAroundCarry! <= adderSum[-1];
}
final endAround = adderSum[-1].named('endaround');
final magnitude = adderSum.slice(a.width - 1, 0).named('magnitude');
final Logic magnitudep1;
if (!generateEndAroundCarry) {
final incrementer = ParallelPrefixIncr(magnitude);
magnitudep1 = incrementer.out.named('magnitude_plus1');
} else {
magnitudep1 = Const(0);
}
sum <=
mux(
doSubtract,
[
if (chainable) endAround else Const(0),
mux(
[if (chainable) Const(0) else endAround].first,
[if (generateEndAroundCarry) magnitude else magnitudep1]
.first,
~magnitude)
].swizzle(),
adderSum);
_sign <= mux(doSubtract, ~endAround, Const(0));
}