Skip to content
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

Floatingpoint #97

Merged
merged 19 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ Some in-development items will have opened issues, as well. Feel free to create
- Sort
- [Bitonic sort](./components/sort.md#bitonic-sort)
- Arithmetic
- [Prefix Trees](./components/parallel_prefix_operations.md)
- [Prefix Trees](./components/parallel_prefix_operations.md) Several efficient components that leverage a variety of parallel prefix trees such as Ripple, Kogge-Stone, Sklansky, and Brent-Kung tree types.
- [Priority Encoder](./components/parallel_prefix_operations.md)
- [Or-scan](./components/parallel_prefix_operations.md)
- [Incrementer](./components/parallel_prefix_operations.md)
- [Decrementer](./components/parallel_prefix_operations.md)
- [Adders](./components/adder.md)
- [Sign Magnitude Adder](./components/adder.md#ripple-carry-adder)
- [Parallel Prefix Adder](./components/parallel_prefix_operations.md)
- Subtractors
- [One's Complement Adder Subtractor](./components/adder.md#ones-complement-adder-subtractor)
- Multipliers
Expand All @@ -48,11 +53,13 @@ Some in-development items will have opened issues, as well. Feel free to create
- Square root
- Inverse square root
- Floating point
- [Floating-Point Value Types](./components/floating_point.md)
- Double (64-bit)
- Float (32-bit)
- BFloat16 (16-bit)
- BFloat8 (8-bit)
- BFloat4 (4-bit)
- [Simple Floating-Point Adder](./componeents/floating_point.md#floatingpointadder)
- Fixed point
- Binary-Coded Decimal (BCD)
- [Rotate](./components/rotate.md)
Expand Down
4 changes: 4 additions & 0 deletions doc/components/floating_point.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ The `FloatingPoint` type is a `LogicStructure` which comprises the `Logic` bits
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 `FloatingPointValue` on the output. An option on input is the type of `ParallelPrefixTree` used in the internal addition of the mantissas.
desmonddak marked this conversation as resolved.
Show resolved Hide resolved

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.
61 changes: 0 additions & 61 deletions lib/src/arithmetic/multiplier_encoder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,64 +131,3 @@ class MultiplierEncoder {
return _encoder.encode(multiplierSlice.first);
}
}

/// A class accessing the multiples of the multiplicand at a position
class MultiplicandSelector {
/// radix of the selector
int radix;

/// The bit shift of the selector (typically overlaps 1)
int shift;

/// New width of partial products generated from the multiplicand
int get width => multiplicand.width + shift - 1;

/// Access the multiplicand
Logic multiplicand = Logic();

/// Place to store multiples of the multiplicand
late LogicArray multiples;

/// Generate required multiples of multiplicand
MultiplicandSelector(this.radix, this.multiplicand, {required bool signed})
: shift = log2Ceil(radix) {
if (radix > 16) {
throw RohdHclException('Radices beyond 16 are not yet supported');
}
final width = multiplicand.width + shift;
final numMultiples = radix ~/ 2;
multiples = LogicArray([numMultiples], width);
final extendedMultiplicand = signed
? multiplicand.signExtend(width)
: multiplicand.zeroExtend(width);

for (var pos = 0; pos < numMultiples; pos++) {
final ratio = pos + 1;
multiples.elements[pos] <=
switch (ratio) {
1 => extendedMultiplicand,
2 => extendedMultiplicand << 1,
3 => (extendedMultiplicand << 2) - extendedMultiplicand,
4 => extendedMultiplicand << 2,
5 => (extendedMultiplicand << 2) + extendedMultiplicand,
6 => (extendedMultiplicand << 3) - (extendedMultiplicand << 1),
7 => (extendedMultiplicand << 3) - extendedMultiplicand,
8 => extendedMultiplicand << 3,
_ => throw RohdHclException('Radix is beyond 16')
};
}
}

/// Retrieve the multiples of the multiplicand at current bit position
Logic getMultiples(int col) => [
for (var i = 0; i < multiples.elements.length; i++)
multiples.elements[i][col]
].swizzle().reversed;

Logic _select(Logic multiples, RadixEncode encode) =>
(encode.multiples & multiples).or() ^ encode.sign;

/// Select the partial product term from the multiples using a RadixEncode
Logic select(int col, RadixEncode encode) =>
_select(getMultiples(col), encode);
}
1 change: 1 addition & 0 deletions lib/src/arithmetic/multiplier_lib.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
//

export './addend_compressor.dart';
export './multiplicand_selector.dart';
export './multiplier_encoder.dart';
export './partial_product_generator.dart';
Loading