-
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.
FloatingPointValue class to support floating-point building blocks * first simple floating_point components * improved arithmetic evaluation utilities, vecString utility with Markdown enabled * random FP adder testing --------- Co-authored-by: Max Korbel <[email protected]> Co-authored-by: soneryaldiz <[email protected]>
- Loading branch information
1 parent
317092f
commit 87783b8
Showing
17 changed files
with
1,981 additions
and
70 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
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,37 @@ | ||
# Floating-Point Components | ||
|
||
Floating-point operations require meticulous precision, and have standards like [IEEE-754](<https://standards.ieee.org/ieee/754/6210/>) which govern them. To support floating-point components, we have created a parallel to `Logic`/`LogicValue` which are part of [ROHD](<https://intel.github.io/rohd-website/>). Here, `FloatingPoint` is the `Logic` wire in a component that carries `FloatingPointValue` literal values. An important distinction is that these classes are parameterized to create arbitrary size floating-point values. | ||
|
||
## FloatingPointValue | ||
|
||
The `FloatingPointValue` class comprises the sign, exponent, and mantissa `LogicValue`s that represent a floating-point number. `FloatingPointValue`s can be converted to and from Dart native `Double`s, as well as constructed from integer and string representations of their fields. They can be operated on (+, -, *, /) and compared. | ||
|
||
A `FloatingPointValue` has a mantissa in $[0,2)$ with | ||
|
||
$$0 <= exponent <= maxExponent$$ | ||
|
||
A normal `isNormal` `FloatingPointValue` has: | ||
|
||
$$minExponent <= exponent <= maxExponent$$ | ||
|
||
And a mantissa in the range of $[1,2)$. Subnormal numbers are represented with a zero exponent and leading zeros in the mantissa capture the negative exponent value. | ||
|
||
The various IEEE constants representing corner cases of the field of floating-point values for a given size of `FloatingPointValue`: infinities, zeros, limits for normal (e.g. mantissa in the range of $[1,2])$ and sub-normal numbers (zero exponent, and mantissa <1). | ||
|
||
Appropriate string representations, comparison operations, and operators are available. The usefulness of `FloatingPointValue` is in the testing of `FloatingPoint` components, where we can leverage the abstraction of a floating-point value type to drive and compare floating-point values operated upon by floating-point components. | ||
|
||
As 32-bit single precision and 64-bit double-precision floating-point types are most common, we have `FloatingPoint32Value` and `FloatingPoint64Value` subclasses with direct converters from Dart native Double. | ||
|
||
Finally, we have a `FloatingPointValue` random generator for testing purposes, generating valid floating-point types, optionally constrained to normal range (mantissa in $[1, 2)$). | ||
|
||
## FloatingPoint | ||
|
||
The `FloatingPoint` type is a `LogicStructure` which comprises the `Logic` bits for the sign, exponent, and mantissa used in hardware floating-point. These types are provided to simplify and abstract the declaration and manipulation of floating-point types in hardware. This type is parameterized like `FloatingPointValue`, for exponent and mantissa width. | ||
|
||
Again, like `FloatingPointValue`, `FloatingPoint64` and `FloatingPoint32` subclasses are provided as these are the most common floating-point number types. | ||
|
||
## FloatingPointAdder | ||
|
||
A very basic `FloatingPointAdder` component is available which does not perform any rounding. It takes two `FloatingPoint` `LogicStructure`s and adds them, returning a normalized `FloatingPoint` on the output. An option on input is the type of `ParallelPrefixTree` used in the internal addition of the mantissas. | ||
|
||
Currently, the `FloatingPointAdder` is close in accuracy (as it has no rounding) and is not optimized for circuit performance, but only provides the key functionalities of alignment, addition, and normalization. Still, this component is a starting point for more realistic floating-point components that leverage the logical `FloatingPoint` and literal `FloatingPointValue` type abstractions. |
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
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
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
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,118 @@ | ||
// Copyright (C) 2024 Intel Corporation | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// | ||
// floating_point_test.dart | ||
// Tests of Floating Point stuff | ||
// | ||
// 2024 August 30 | ||
// Author: Desmond A Kirkpatrick <[email protected] | ||
|
||
// ignore_for_file: avoid_print | ||
|
||
import 'dart:math'; | ||
|
||
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. | ||
/// [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. | ||
/// 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, | ||
{int prefix = 10, | ||
int? alignHigh, | ||
int? sepPos, | ||
bool header = false, | ||
String sepChar = '*', | ||
int alignLow = 0, | ||
int extraSpace = 0, | ||
bool markDown = false}) { | ||
final str = StringBuffer(); | ||
final minHigh = min(alignHigh ?? width, width); | ||
final length = BigInt.from(minHigh).toString().length + extraSpace; | ||
// ignore: cascade_invocations | ||
const hdrSep = '| '; | ||
const hdrSepStart = '| '; | ||
const hdrSepEnd = '|'; | ||
|
||
final highLimit = ((alignHigh ?? width) - width) + width - 1; | ||
|
||
if (header) { | ||
str.write(markDown ? '$hdrSepStart Name' : ' ' * prefix); | ||
|
||
for (var col = highLimit; col >= alignLow; col--) { | ||
final chars = BigInt.from(col).toString().length + extraSpace; | ||
if (sepPos != null && sepPos == col) { | ||
str | ||
..write( | ||
markDown ? ' $hdrSep' : ' ' * (length - chars + 1 + extraSpace)) | ||
..write('$col$sepChar') | ||
..write(markDown ? ' $hdrSep' : ''); | ||
} else if (sepPos != null && sepPos == col + 1) { | ||
if (sepPos == max(alignHigh ?? width, width)) { | ||
str | ||
..write(sepChar) | ||
..write(markDown ? ' $hdrSep' : ' ' * (length - chars - 1)); | ||
} | ||
str.write('${' ' * (length - chars + extraSpace + 0)}$col'); | ||
} else { | ||
str | ||
..write( | ||
markDown ? ' $hdrSep' : ' ' * (length - chars + 1 + extraSpace)) | ||
..write('$col'); | ||
} | ||
} | ||
str.write(markDown ? ' $hdrSepEnd\n' : '\n'); | ||
if (markDown) { | ||
str.write(markDown ? '|:--:' : ' ' * prefix); | ||
for (var col = highLimit; col >= alignLow; col--) { | ||
str.write('|:--'); | ||
} | ||
str.write('-|\n'); | ||
} | ||
} | ||
const dataSepStart = '|'; | ||
const dataSep = '| '; | ||
const dataSepEnd = '|'; | ||
final String strPrefix; | ||
strPrefix = markDown | ||
? '$dataSepStart $name' | ||
: (name.length <= prefix) | ||
? name.padRight(prefix) | ||
: name.substring(0, prefix); | ||
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; | ||
if (sepPos != null && sepPos == pos) { | ||
str.write( | ||
markDown ? ' $dataSep$v $sepChar' : '${' ' * length}$v$sepChar'); | ||
} else if (sepPos != null && sepPos == pos + 1) { | ||
if (sepPos == minHigh) { | ||
str.write(sepChar); | ||
} | ||
str | ||
..write(markDown ? ' $dataSep' : ' ' * (length - 1)) | ||
..write(v); | ||
} else { | ||
str | ||
..write(markDown ? ' $dataSep' : ' ' * length) | ||
..write(v); | ||
} | ||
} | ||
if (markDown) { | ||
str.write(' $dataSepEnd'); | ||
} | ||
return str.toString(); | ||
} | ||
} |
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
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
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,6 @@ | ||
// Copyright (C) 2024 Intel Corporation | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
export 'floating_point_adder.dart'; | ||
export 'floating_point_logic.dart'; | ||
export 'floating_point_value.dart'; |
Oops, something went wrong.