OnesComplementAdder constructor
- Logic a,
- Logic b, {
- Adder adderGen(}) = NativeAdder.new,
- @Deprecated('Use subtract with a 1-bit Logic instead.') Logic? subtractIn,
- bool generateEndAroundCarry = false,
- Logic? carryIn,
- dynamic subtract,
- bool chainable = false,
- bool reserveName = false,
- bool reserveDefinitionName = false,
- String? definitionName,
- String name = 'ones_complement_adder',
OnesComplementAdder constructor with an adder functor adderGen.
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.- 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,
@Deprecated('Use subtract with a 1-bit Logic instead.') Logic? subtractIn,
this.generateEndAroundCarry = false,
super.carryIn,
dynamic subtract,
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');
}
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);
_sign = addOutput('sign');
final doSubtract = subtractParameter
.getLogic(this)
.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));
}