-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated partialProduct printout with listString, tests for same and s…
…et,muxAbsolute,All
- Loading branch information
1 parent
8c64e84
commit d27cecf
Showing
5 changed files
with
373 additions
and
217 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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
// Copyright (C) 2024 Intel Corporation | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// | ||
// floating_point_test.dart | ||
// Tests of Floating Point stuff | ||
// arithmetic_utils.dart | ||
// Utlities for arithmetic visualization | ||
// | ||
// 2024 August 30 | ||
// Author: Desmond A Kirkpatrick <[email protected] | ||
|
@@ -15,35 +15,44 @@ import 'package:rohd/rohd.dart'; | |
import 'package:rohd_hcl/rohd_hcl.dart'; | ||
|
||
/// Helper evaluation methods for printing aligned arithmetic bitvectors. | ||
extension NumericVector on LogicValue { | ||
/// Print aligned bitvector with an optional header. | ||
extension LogicList on List<Logic> { | ||
/// Print aligned bitvector with an optional header from List<Logic>. | ||
/// [name] is printed at the LHS of the line, trimmed by [prefix]. | ||
/// [prefix] is the distance from the margin bebore the vector is printed. | ||
/// You can align with longer bitvectors by stating the length [alignHigh]. | ||
/// [alignLow] will trim the vector below this bit position. | ||
/// [alignHigh] is highest column (MSB) to which to align | ||
/// [alignLow] will trim the vector below this bit position (LSB). | ||
/// [shift] will allow you to shift your list positions | ||
/// You can insert a separator [sepChar] at position [sepPos]. | ||
/// A header can be printed by setting [header] to true. | ||
/// Markdown format can be produced by setting [markDown] to true. | ||
/// The output can have space by setting [extraSpace] | ||
String vecString(String name, | ||
/// if [intValue] is true, then the integer value (signed version in parens) | ||
/// will be printed at the end of the vector. | ||
String listString(String name, | ||
{int prefix = 10, | ||
int? alignHigh, | ||
int? sepPos, | ||
bool header = false, | ||
String sepChar = '*', | ||
int alignLow = 0, | ||
int extraSpace = 0, | ||
int shift = 0, | ||
bool intValue = false, | ||
bool markDown = false}) { | ||
final str = StringBuffer(); | ||
final maxHigh = max(alignHigh ?? width, width); | ||
final minHigh = min(alignHigh ?? width, width); | ||
final length = BigInt.from(maxHigh).toString().length + extraSpace; | ||
final maxHigh = max(alignHigh ?? length, length); | ||
final minHigh = min(alignHigh ?? length, length) - shift; | ||
final colWidth = BigInt.from(maxHigh).toString().length + extraSpace; | ||
// ignore: cascade_invocations | ||
const hdrSep = '| '; | ||
const hdrSepStart = '| '; | ||
const hdrSepEnd = '|'; | ||
|
||
final highLimit = ((alignHigh ?? width) - width) + width - 1; | ||
if (markDown && sepChar.contains('|')) { | ||
throw RohdHclException('markDown cannot use | as a sepChar'); | ||
} | ||
|
||
final highLimit = ((alignHigh ?? length) - length) + length - 1; | ||
|
||
if (header) { | ||
str.write(markDown ? '$hdrSepStart Name' : ' ' * prefix); | ||
|
@@ -52,30 +61,38 @@ extension NumericVector on LogicValue { | |
final chars = BigInt.from(col).toString().length + extraSpace; | ||
if (sepPos != null && sepPos == col) { | ||
str | ||
..write( | ||
markDown ? ' $hdrSep' : ' ' * (length - chars + 1 + extraSpace)) | ||
..write(markDown | ||
? ' $hdrSep' | ||
: ' ' * (colWidth - chars + 1 + extraSpace)) | ||
..write('$col$sepChar') | ||
..write(markDown ? ' $hdrSep' : ''); | ||
} else if (sepPos != null && sepPos == col + 1) { | ||
if (sepPos == max(alignHigh ?? width, width)) { | ||
if (sepPos == max(alignHigh ?? length, length)) { | ||
str | ||
..write(sepChar) | ||
..write(markDown ? ' $hdrSep' : ' ' * (length - chars - 1)); | ||
..write(markDown ? ' $hdrSep' : ' ' * (colWidth - chars - 1)); | ||
} | ||
str.write('${' ' * (length - chars + extraSpace + 0)}$col'); | ||
str.write('${' ' * (colWidth - chars + extraSpace + 0)}$col'); | ||
} else { | ||
str | ||
..write( | ||
markDown ? ' $hdrSep' : ' ' * (length - chars + 1 + extraSpace)) | ||
..write(markDown | ||
? ' $hdrSep' | ||
: ' ' * (colWidth - chars + 1 + extraSpace)) | ||
..write('$col'); | ||
} | ||
} | ||
str.write(markDown ? ' $hdrSepEnd\n' : '\n'); | ||
str | ||
..write(intValue & markDown ? hdrSepEnd : '') | ||
..write(markDown ? hdrSepEnd : '') | ||
..write('\n'); | ||
if (markDown) { | ||
str.write(markDown ? '|:--:' : ' ' * prefix); | ||
str.write(markDown ? '|:--' : ' ' * prefix); | ||
for (var col = highLimit; col >= alignLow; col--) { | ||
str.write('|:--'); | ||
} | ||
if (intValue) { | ||
str.write('-|:--'); | ||
} | ||
str.write('-|\n'); | ||
} | ||
} | ||
|
@@ -88,29 +105,78 @@ extension NumericVector on LogicValue { | |
: (name.length <= prefix) | ||
? name.padRight(prefix) | ||
: name.substring(0, prefix); | ||
|
||
// Column calculations for overlapping vector with range | ||
final startCol = highLimit; | ||
final endCol = alignLow; | ||
final startPos = length + shift - 1; | ||
final endPos = shift; | ||
final startOvl = min(startCol, startPos); | ||
final endOvl = max(endCol, endPos); | ||
final startIdx = startOvl - shift; | ||
final endIdx = endOvl - shift; | ||
|
||
final emptyLeft = (startCol - max(alignLow - 1, startOvl)).toInt(); | ||
final emptyRight = min(highLimit + 1, endPos) - endCol; | ||
str | ||
..write(strPrefix) | ||
..write((markDown ? dataSep : ' ' * (length + 1)) * | ||
((alignHigh ?? width) - width)); | ||
for (var col = alignLow; col < minHigh; col++) { | ||
final pos = minHigh - 1 - col + alignLow; | ||
final v = this[pos].bitString; | ||
..write((markDown ? dataSepStart : ' ' * (colWidth + 1)) * emptyLeft); | ||
|
||
for (var pos = startIdx; pos >= endIdx; pos--) { | ||
final bit = this[pos]; | ||
final String v; | ||
if (bit is SignBit) { | ||
if (bit.value == LogicValue.zero) { | ||
v = markDown | ||
? bit.inverted | ||
? r'$\overline 0$' | ||
: r'$\underline 0$' | ||
: bit.inverted | ||
? 'i' | ||
: 's'; | ||
} else { | ||
v = markDown | ||
? bit.inverted | ||
? r'$\overline 1$' | ||
: r'$\underline 1$' | ||
: bit.inverted | ||
? 'I' | ||
: 'S'; | ||
} | ||
} else { | ||
v = this[pos].value.bitString; | ||
} | ||
if (sepPos != null && sepPos == pos) { | ||
str.write( | ||
markDown ? ' $dataSep$v $sepChar' : '${' ' * length}$v$sepChar'); | ||
markDown ? ' $dataSep$v $sepChar' : '${' ' * colWidth}$v$sepChar'); | ||
} else if (sepPos != null && sepPos == pos + 1) { | ||
if (sepPos == minHigh) { | ||
str.write(sepChar); | ||
} | ||
str | ||
..write(markDown ? ' $dataSep' : ' ' * (length - 1)) | ||
..write(markDown ? ' $dataSep' : ' ' * (colWidth - 1)) | ||
..write(v); | ||
} else { | ||
str | ||
..write(markDown ? ' $dataSep' : ' ' * length) | ||
..write(markDown ? ' $dataSep' : ' ' * colWidth) | ||
..write(v); | ||
} | ||
} | ||
|
||
str.write(markDown ? dataSepStart : ' ' * emptyRight * (colWidth + 1)); | ||
if (intValue) { | ||
final vec = (shift >= 0) | ||
? this.rswizzle().zeroExtend(maxHigh) << shift | ||
: this.rswizzle().zeroExtend(maxHigh) >>> -shift; | ||
|
||
final vecC = vec.slice(highLimit, 0); | ||
final v = vecC.value.toBigInt().toUnsigned(maxHigh); | ||
final spacer = | ||
colWidth - ((sepPos != null) && (sepPos == endCol) ? 1 : 0); | ||
str | ||
..write(markDown ? dataSep : '${' ' * spacer} = ') | ||
..write('$v (${v.toSigned(maxHigh)})'); | ||
} | ||
if (markDown) { | ||
str.write(' $dataSepEnd'); | ||
} | ||
|
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
Oops, something went wrong.