-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring of FloatingPointValue
constructors for ease of use and extension
#110
Open
mkorbel1
wants to merge
8
commits into
main
Choose a base branch
from
fpv_refactor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
56c5f0d
Started refactoring floating point value constructors, WIP
mkorbel1 59a07a4
refactored constructors and updated tests
desmonddak bc06df8
slight change to double conversion
desmonddak c82acc0
fixed the factory methods for fp8
desmonddak 9de2190
fixed file headers, added more standard formats
desmonddak 063ee02
added new fp formats to map
desmonddak 963f235
line length violation
desmonddak 0a16197
cleanup comments, fix FP8 tests
desmonddak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
91 changes: 91 additions & 0 deletions
91
lib/src/arithmetic/floating_point/floating_point_values/floating_point_32_value.dart
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,91 @@ | ||
// Copyright (C) 2024 Intel Corporation | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// | ||
// floating_point_32_value.dart | ||
// Implementation of 32-bit Floating-Point value representations. | ||
// | ||
// 2024 October 15 | ||
// Authors: | ||
// Max Korbel <[email protected]> | ||
// Desmond A Kirkpatrick <[email protected]> | ||
|
||
import 'dart:typed_data'; | ||
import 'package:meta/meta.dart'; | ||
import 'package:rohd/rohd.dart'; | ||
import 'package:rohd_hcl/rohd_hcl.dart'; | ||
|
||
/// A representation of a single-precision floating-point value. | ||
class FloatingPoint32Value extends FloatingPointValue { | ||
/// The exponent width | ||
static const int exponentWidth = 8; | ||
|
||
/// The mantissa width | ||
static const int mantissaWidth = 23; | ||
|
||
@override | ||
@protected | ||
int get constrainedExponentWidth => exponentWidth; | ||
|
||
@override | ||
@protected | ||
int get constrainedMantissaWidth => mantissaWidth; | ||
|
||
/// Constructor for a single precision floating point value | ||
FloatingPoint32Value( | ||
{required super.sign, required super.exponent, required super.mantissa}); | ||
|
||
/// Return the [FloatingPoint32Value] representing the constant specified | ||
factory FloatingPoint32Value.getFloatingPointConstant( | ||
FloatingPointConstants constantFloatingPoint) => | ||
FloatingPoint32Value.fromLogic( | ||
FloatingPointValue.getFloatingPointConstant( | ||
constantFloatingPoint, exponentWidth, mantissaWidth) | ||
.value); | ||
|
||
/// [FloatingPoint32Value] constructor from string representation of | ||
/// individual bitfields | ||
FloatingPoint32Value.ofBinaryStrings( | ||
super.sign, super.exponent, super.mantissa) | ||
: super.ofBinaryStrings(); | ||
|
||
/// [FloatingPoint32Value] constructor from spaced string representation of | ||
/// individual bitfields | ||
FloatingPoint32Value.ofSpacedBinaryString(super.fp) | ||
: super.ofSpacedBinaryString(); | ||
|
||
/// [FloatingPoint32Value] constructor from a single string representing | ||
/// space-separated bitfields | ||
FloatingPoint32Value.ofString(String fp, {super.radix}) | ||
: super.ofString(fp, exponentWidth, mantissaWidth); | ||
|
||
/// [FloatingPoint32Value] constructor from a set of [BigInt]s of the binary | ||
/// representation | ||
FloatingPoint32Value.ofBigInts(super.exponent, super.mantissa, {super.sign}) | ||
: super.ofBigInts(); | ||
|
||
/// [FloatingPoint32Value] constructor from a set of [int]s of the binary | ||
/// representation | ||
FloatingPoint32Value.ofInts(super.exponent, super.mantissa, {super.sign}) | ||
: super.ofInts(); | ||
|
||
/// Numeric conversion of a [FloatingPoint32Value] from a host double | ||
factory FloatingPoint32Value.fromDouble(double inDouble) { | ||
final byteData = ByteData(4)..setFloat32(0, inDouble); | ||
final accum = byteData.buffer | ||
.asUint8List() | ||
.map((b) => LogicValue.ofInt(b, 32)) | ||
.reduce((accum, v) => (accum << 8) | v); | ||
|
||
return FloatingPoint32Value( | ||
sign: accum[-1], | ||
exponent: accum.slice(exponentWidth + mantissaWidth - 1, mantissaWidth), | ||
mantissa: accum.slice(mantissaWidth - 1, 0)); | ||
} | ||
|
||
/// Construct a [FloatingPoint32Value] from a Logic word | ||
factory FloatingPoint32Value.fromLogic(LogicValue val) => | ||
FloatingPoint32Value( | ||
sign: val[-1], | ||
exponent: val.slice(exponentWidth + mantissaWidth - 1, mantissaWidth), | ||
mantissa: val.slice(mantissaWidth - 1, 0)); | ||
} |
93 changes: 93 additions & 0 deletions
93
lib/src/arithmetic/floating_point/floating_point_values/floating_point_64_value.dart
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,93 @@ | ||
// Copyright (C) 2024 Intel Corporation | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// | ||
// floating_point_64_value.dart | ||
// Implementation of 64-bit Floating-Point value representations. | ||
// | ||
// 2024 October 15 | ||
// Authors: | ||
// Max Korbel <[email protected]> | ||
// Desmond A Kirkpatrick <[email protected]> | ||
|
||
import 'dart:typed_data'; | ||
|
||
import 'package:rohd/rohd.dart'; | ||
import 'package:rohd_hcl/rohd_hcl.dart'; | ||
|
||
/// A representation of a double-precision floating-point value. | ||
class FloatingPoint64Value extends FloatingPointValue { | ||
/// The exponent width | ||
static const int _exponentWidth = 11; | ||
|
||
/// The mantissa width | ||
static const int _mantissaWidth = 52; | ||
|
||
/// return the exponent width | ||
static int get exponentWidth => _exponentWidth; | ||
|
||
/// return the mantissa width | ||
static int get mantissaWidth => _mantissaWidth; | ||
|
||
/// Constructor for a double precision floating point value | ||
FloatingPoint64Value( | ||
{required super.sign, required super.mantissa, required super.exponent}); | ||
|
||
/// Return the [FloatingPoint64Value] representing the constant specified | ||
factory FloatingPoint64Value.getFloatingPointConstant( | ||
FloatingPointConstants constantFloatingPoint) => | ||
FloatingPoint64Value.fromLogic( | ||
FloatingPointValue.getFloatingPointConstant( | ||
constantFloatingPoint, _exponentWidth, _mantissaWidth) | ||
.value); | ||
|
||
/// [FloatingPoint64Value] constructor from string representation of | ||
/// individual bitfields | ||
factory FloatingPoint64Value.ofBinaryStrings( | ||
String sign, String exponent, String mantissa) => | ||
FloatingPoint64Value( | ||
sign: LogicValue.of(sign), | ||
exponent: LogicValue.of(exponent), | ||
mantissa: LogicValue.of(mantissa)); | ||
|
||
/// [FloatingPoint64Value] constructor from spaced string representation of | ||
/// individual bitfields | ||
FloatingPoint64Value.ofSpacedBinaryString(super.fp) | ||
: super.ofSpacedBinaryString(); | ||
|
||
/// [FloatingPoint64Value] constructor from a single string representing | ||
/// space-separated bitfields | ||
FloatingPoint64Value.ofString(String fp, {super.radix}) | ||
: super.ofString(fp, exponentWidth, mantissaWidth); | ||
|
||
/// [FloatingPoint64Value] constructor from a set of [BigInt]s of the binary | ||
/// representation | ||
FloatingPoint64Value.ofBigInts(super.exponent, super.mantissa, {super.sign}) | ||
: super.ofBigInts(); | ||
|
||
/// [FloatingPoint64Value] constructor from a set of [int]s of the binary | ||
/// representation | ||
FloatingPoint64Value.ofInts(super.exponent, super.mantissa, {super.sign}) | ||
: super.ofInts(); | ||
|
||
/// Numeric conversion of a [FloatingPoint64Value] from a host double | ||
factory FloatingPoint64Value.fromDouble(double inDouble) { | ||
final byteData = ByteData(8)..setFloat64(0, inDouble); | ||
final accum = byteData.buffer | ||
.asUint8List() | ||
.map((b) => LogicValue.ofInt(b, 64)) | ||
.reduce((accum, v) => (accum << 8) | v); | ||
|
||
return FloatingPoint64Value( | ||
sign: accum[-1], | ||
exponent: | ||
accum.slice(_exponentWidth + _mantissaWidth - 1, _mantissaWidth), | ||
mantissa: accum.slice(_mantissaWidth - 1, 0)); | ||
} | ||
|
||
/// Construct a [FloatingPoint32Value] from a Logic word | ||
factory FloatingPoint64Value.fromLogic(LogicValue val) => | ||
FloatingPoint64Value( | ||
sign: val[-1], | ||
exponent: val.slice(exponentWidth + mantissaWidth - 1, mantissaWidth), | ||
mantissa: val.slice(mantissaWidth - 1, 0)); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these don't need to be factorys, and also should also be updatd to
fromLogicValue