-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test cleanup and more reorg of multiplier code
- Loading branch information
1 parent
fe18879
commit 3e29ad1
Showing
3 changed files
with
118 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// Copyright (C) 2023-2024 Intel Corporation | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// | ||
// compressor_test.dart | ||
// Tests for the select interface of Booth encoding | ||
// | ||
// 2024 June 04 | ||
// Author: Desmond Kirkpatrick <[email protected]> | ||
|
||
import 'dart:io'; | ||
import 'dart:math'; | ||
import 'package:rohd/rohd.dart'; | ||
import 'package:rohd_hcl/rohd_hcl.dart'; | ||
import 'package:rohd_hcl/src/arithmetic/multiplier_lib.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
enum SignExtension { brute, stop, compact } | ||
|
||
void testCompressionExhaustive(PartialProductGenerator pp) { | ||
final widthX = pp.selector.multiplicand.width; | ||
final widthY = pp.encoder.multiplier.width; | ||
|
||
final compressor = ColumnCompressor(pp); | ||
|
||
final limitX = pow(2, widthX); | ||
final limitY = pow(2, widthY); | ||
for (var i = 0; i < limitX; i++) { | ||
for (var j = 0; j < limitY; j++) { | ||
final X = pp.signed | ||
? BigInt.from(i).toSigned(widthX) | ||
: BigInt.from(i).toUnsigned(widthX); | ||
final Y = pp.signed | ||
? BigInt.from(j).toSigned(widthY) | ||
: BigInt.from(j).toUnsigned(widthY); | ||
final product = X * Y; | ||
|
||
pp.multiplicand.put(X); | ||
pp.multiplier.put(Y); | ||
final value = pp.evaluate(); | ||
expect(value, equals(product), | ||
reason: 'Fail: $i($X) * $j($Y): $value ' | ||
'vs expected $product' | ||
'\n$pp'); | ||
final evaluateValue = compressor.evaluate(); | ||
if (evaluateValue != product) { | ||
stdout | ||
..write('Fail: $i($X)[$widthX] * $j($Y)[$widthY]: $evaluateValue ' | ||
'vs expected $product\n') | ||
..write(pp); | ||
} | ||
compressor.compress(); | ||
final compressedValue = compressor.evaluate(); | ||
expect(compressedValue, equals(product), | ||
reason: 'Fail: $i($X)[$widthX] * $j($Y)[$widthY]: $compressedValue ' | ||
'vs expected $product' | ||
'\n$pp'); | ||
final compressedLogicValue = compressor.evaluate(logic: true); | ||
expect(compressedLogicValue, equals(product), | ||
reason: | ||
'Fail: $i($X)[$widthX] * $j($Y)[$widthY]: $compressedLogicValue ' | ||
'vs expected $product' | ||
'\n$pp'); | ||
|
||
final a = compressor.extractRow(0); | ||
final b = compressor.extractRow(1); | ||
final adder = ParallelPrefixAdder(a, b, KoggeStone.new); | ||
final adderValue = | ||
adder.out.value.toBigInt().toSigned(compressor.columns.length); | ||
expect(adderValue, equals(product), | ||
reason: 'Fail: $i($X)[$widthX] * $j($Y)[$widthY]: ' | ||
'$adderValue vs expected $product' | ||
'\n$pp'); | ||
} | ||
} | ||
} | ||
|
||
void main() { | ||
test('exhaustive compression evaluate: square radix-4, all SignExtension', | ||
() async { | ||
stdout.write('\n'); | ||
|
||
for (final signed in [false, true]) { | ||
for (var radix = 4; radix < 32; radix *= 2) { | ||
final encoder = RadixEncoder(2); | ||
// stdout.write('encoding with radix=$radix\n'); | ||
final shift = log2Ceil(encoder.radix); | ||
for (var width = shift + 1; width < 2 * shift + 1; width++) { | ||
for (final signExtension in SignExtension.values) { | ||
final pp = PartialProductGenerator(Logic(name: 'X', width: width), | ||
Logic(name: 'Y', width: width), encoder, | ||
signed: signed); | ||
switch (signExtension) { | ||
case SignExtension.brute: | ||
pp.bruteForceSignExtend(); | ||
case SignExtension.stop: | ||
pp.signExtendWithStopBitsRect(); | ||
case SignExtension.compact: | ||
pp.signExtendCompact(); | ||
} | ||
testCompressionExhaustive(pp); | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters