Skip to content

Commit

Permalink
ensure multiplier tests sweep sign extension
Browse files Browse the repository at this point in the history
  • Loading branch information
desmonddak committed Jan 16, 2025
1 parent 599a6d3 commit 4eee34c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class FloatingPointAdderRound extends FloatingPointAdder {

final exponentSubtractor = OnesComplementAdder(
super.a.exponent, super.b.exponent,

subtract: true, adderGen: adderGen, name: 'exponent_sub');
final signDelta = Logic(name: 'signDelta')..gets(exponentSubtractor.sign);

Expand All @@ -71,7 +70,6 @@ class FloatingPointAdderRound extends FloatingPointAdder {
[smaller.mantissa, Const(0)].swizzle(),
));


// Seidel: flp larger preshift, normally in [2,4)
final sigWidth = fl.width + 1;
final largeShift = nameLogic(
Expand Down Expand Up @@ -114,7 +112,6 @@ class FloatingPointAdderRound extends FloatingPointAdder {
final isNaNFlopped = localFlop(isNaN);

final carryRPath = Logic(name: 'carry_rpath');

final significandAdderRPath = OnesComplementAdder(
largeOperandFlopped, smallerOperandRPathFlopped,
subtractIn: effectiveSubtractionFlopped,
Expand Down Expand Up @@ -237,7 +234,6 @@ class FloatingPointAdderRound extends FloatingPointAdder {
significandSubtractorNPath.sum.slice(smallOperandNPath.width - 1, 0));

final validLeadOneNPath = Logic(name: 'valid_lead1_npath');

final leadOneNPathPre = ParallelPrefixPriorityEncoder(
significandNPath.reversed,
ppGen: ppTree,
Expand All @@ -264,7 +260,6 @@ class FloatingPointAdderRound extends FloatingPointAdder {
final largerSignFlopped = localFlop(larger.sign);
final smallerSignFlopped = localFlop(smaller.sign);


final expCalcNPath = OnesComplementAdder(
largerExpFlopped, leadOneNPathFlopped.zeroExtend(exponentWidth),
subtractIn: effectiveSubtractionFlopped,
Expand Down Expand Up @@ -317,7 +312,6 @@ class FloatingPointAdderRound extends FloatingPointAdder {
], orElse: [
If(isR, then: [
outputSum.sign < largerSignFlopped,

outputSum.exponent < exponentRPath,
outputSum.mantissa <
mantissaRPath.slice(mantissaRPath.width - 2, 1),
Expand Down
1 change: 0 additions & 1 deletion lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,3 @@ Logic condFlop(
/// operation.
Logic nameLogic(String name, Logic logic, {Naming? naming}) =>
Logic(name: name, width: logic.width, naming: naming)..gets(logic);

43 changes: 29 additions & 14 deletions test/arithmetic/multiplier_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class SimpleMultiplier extends Multiplier {
: super(a, b) {
addOutput('product', width: a.width + b.width);
final mult = CompressionTreeMultiplier(a, b, 4,
adderGen: ParallelPrefixAdder.new,
selectSignedMultiplicand: selSignedMultiplicand,
selectSignedMultiplier: selSignedMultiplier);
product <= mult.product;
Expand Down Expand Up @@ -187,12 +188,14 @@ void main() {
});

MultiplierCallback curryCompressionTreeMultiplier(int radix,
ParallelPrefix Function(List<Logic>, Logic Function(Logic, Logic)) ppTree,
{SignExtensionFunction seGen = CompactRectSignExtension.new,
Adder Function(Logic a, Logic b, {Logic? carryIn, String name}) adderGen =
NativeAdder.new,
bool signedMultiplicand = false,
bool signedMultiplier = false,
Logic? selectSignedMultiplicand,
Logic? selectSignedMultiplier}) {
String adderName(Logic a, Logic b) => adderGen(a, b).name;
String genName(Logic a, Logic b) =>
seGen(PartialProductGeneratorBasic(a, b, RadixEncoder(radix))).name;
final signage = ' SD=${signedMultiplicand ? 1 : 0}'
Expand All @@ -205,15 +208,17 @@ void main() {
signedMultiplier: signedMultiplier,
selectSignedMultiplicand: selectSignedMultiplicand,
selectSignedMultiplier: selectSignedMultiplier,
seGen: seGen,
adderGen: adderGen,
name: 'Compression Tree Multiplier: '
'${ppTree([Logic()], (a, b) => Logic()).name}'
'${adderName(a, b)}'
'$signage R${radix}_E${genName(a, b)}');
}

MultiplyAccumulateCallback curryMultiplierAsMultiplyAccumulate(int radix,
{ParallelPrefix Function(List<Logic>, Logic Function(Logic, Logic))
ppTree = KoggeStone.new,
SignExtensionFunction seGen = CompactRectSignExtension.new,
{SignExtensionFunction seGen = CompactRectSignExtension.new,
Adder Function(Logic a, Logic b, {Logic? carryIn, String name})
adderGen = NativeAdder.new,
bool signedMultiplicand = false,
bool signedMultiplier = false,
Logic? selectSignedMultiplicand,
Expand All @@ -228,7 +233,7 @@ void main() {
selectSignedMultiplier: selectSignedMultiplier,
curryCompressionTreeMultiplier(
radix,
ppTree,
adderGen: adderGen,
seGen: seGen,
signedMultiplicand: signedMultiplicand,
signedMultiplier: signedMultiplier,
Expand All @@ -238,8 +243,8 @@ void main() {

MultiplyAccumulateCallback curryMultiplyAccumulate(
int radix, {
ParallelPrefix Function(List<Logic>, Logic Function(Logic, Logic)) ppTree =
KoggeStone.new,
Adder Function(Logic a, Logic b, {Logic? carryIn, String name}) adderGen =
NativeAdder.new,
SignExtensionFunction seGen = CompactRectSignExtension.new,
bool signedMultiplicand = false,
bool signedMultiplier = false,
Expand All @@ -256,24 +261,26 @@ void main() {
' SelM=${(selectSignedMultiplier != null) ? 1 : 0}';

return (a, b, c) => CompressionTreeMultiplyAccumulate(a, b, c, radix,
adderGen: adderGen,
seGen: seGen,
signedMultiplicand: signedMultiplicand,
signedMultiplier: signedMultiplier,
signedAddend: signedAddend,
selectSignedMultiplicand: selectSignedMultiplicand,
selectSignedMultiplier: selectSignedMultiplier,
selectSignedAddend: selectSignedAddend,
name: 'Compression Tree MAC: ${ppTree.call([
Logic()
], (a, b) => Logic()).name}'
name: 'Compression Tree MAC: '
' $signage R$radix E${genName(a, b)}');
}

group('Compression Tree Multiplier: curried random radix/ptree/width', () {
for (final radix in [2, 4]) {
for (final width in [3, 4]) {
for (final ppTree in [KoggeStone.new, BrentKung.new, Sklansky.new]) {
Adder adderFn(Logic a, Logic b, {Logic? carryIn, String? name}) =>
ParallelPrefixAdder(a, b, carryIn: carryIn, ppGen: ppTree);
testMultiplyAccumulateRandom(width, 10,
curryMultiplierAsMultiplyAccumulate(radix, ppTree: ppTree));
curryMultiplierAsMultiplyAccumulate(radix, adderGen: adderFn));
}
}
}
Expand All @@ -285,8 +292,11 @@ void main() {
for (final signExtension
in SignExtension.values.where((e) => e != SignExtension.none)) {
final seg = currySignExtensionFunction(signExtension);
testMultiplyAccumulateRandom(width, 10,
curryMultiplierAsMultiplyAccumulate(radix, seGen: seg));
testMultiplyAccumulateRandom(
width,
10,
curryMultiplierAsMultiplyAccumulate(radix,
adderGen: ParallelPrefixAdder.new, seGen: seg));
}
}
}
Expand All @@ -305,6 +315,7 @@ void main() {
width,
10,
curryMultiplierAsMultiplyAccumulate(radix,
adderGen: ParallelPrefixAdder.new,
signedMultiplicand: signedMultiplicand,
signedMultiplier: signedMultiplier,
selectSignedMultiplicand: selectSignedMultiplicand,
Expand Down Expand Up @@ -333,6 +344,7 @@ void main() {
width,
10,
curryMultiplyAccumulate(radix,
adderGen: ParallelPrefixAdder.new,
signedMultiplicand: signedMultiplicand,
signedMultiplier: signedMultiplier,
signedAddend: signedAddend,
Expand Down Expand Up @@ -360,6 +372,7 @@ void main() {
final bB = BigInt.from(-10).toSigned(width);
final mod = CompressionTreeMultiplier(a, b, 4,
clk: clk,
adderGen: ParallelPrefixAdder.new,
selectSignedMultiplicand: signedSelect,
selectSignedMultiplier: signedSelect);
unawaited(Simulator.run());
Expand Down Expand Up @@ -392,6 +405,7 @@ void main() {

final mod = CompressionTreeMultiplyAccumulate(a, b, c, 4,
clk: clk,
adderGen: ParallelPrefixAdder.new,
selectSignedMultiplicand: signedSelect,
selectSignedMultiplier: signedSelect,
selectSignedAddend: signedSelect);
Expand Down Expand Up @@ -436,6 +450,7 @@ void main() {
b.put(bB);

final mod = CompressionTreeMultiplier(a, b, 4,
adderGen: ParallelPrefixAdder.new,
signedMultiplier: !useSignedLogic && signed,
selectSignedMultiplicand: signedSelect,
selectSignedMultiplier: signedSelect);
Expand Down

0 comments on commit 4eee34c

Please sign in to comment.