-
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.
split/reorganize integer multiplication files
- Loading branch information
1 parent
ac60259
commit ae9055f
Showing
12 changed files
with
659 additions
and
99 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
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,73 @@ | ||
// Copyright (C) 2024 Intel Corporation | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// | ||
// multiplicand_selector.dart | ||
// Selection of muliples of the multiplicand for booth recoding | ||
// | ||
// 2024 May 15 | ||
// Author: Desmond Kirkpatrick <[email protected]> | ||
|
||
import 'package:rohd/rohd.dart'; | ||
import 'package:rohd_hcl/rohd_hcl.dart'; | ||
import 'package:rohd_hcl/src/arithmetic/multiplier_encoder.dart'; | ||
|
||
/// 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, {bool signed = true}) | ||
: 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); | ||
} |
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 |
---|---|---|
@@ -1,23 +1,19 @@ | ||
// Copyright (C) 2024 Intel Corporation | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// | ||
// booth.dart | ||
// muliplier_encoder.dart | ||
// Generation of Booth Encoded partial products for multiplication | ||
// | ||
// 2024 May 15 | ||
// Author: Desmond Kirkpatrick <[email protected]> | ||
|
||
import 'dart:io'; | ||
import 'dart:math'; | ||
|
||
import 'package:rohd/rohd.dart'; | ||
import 'package:rohd_hcl/rohd_hcl.dart'; | ||
|
||
/// Simplest version of bit string representation | ||
// String bitString(LogicValue value) => value.toString(includeWidth: false); | ||
|
||
/// A bundle for the leaf radix compute nodes | ||
/// This holds the multiples of the multiplicand that are needed for encoding | ||
/// A bundle for the leaf radix compute nodes. This holds the multiples | ||
/// of the multiplicand that are needed for encoding | ||
class RadixEncode extends LogicStructure { | ||
/// Which multiples need to be selected | ||
final Logic multiples; | ||
|
@@ -84,11 +80,13 @@ class RadixEncoder { | |
/// A class that generates the Booth encoding of the multipler | ||
class MultiplierEncoder { | ||
/// Access the multiplier | ||
Logic multiplier = Logic(); | ||
final Logic multiplier; | ||
|
||
/// Number of row radixEncoders | ||
late final int rows; | ||
|
||
/// The multiplier value, sign extended as appropriate to be divisible | ||
/// by the RadixEncoder overlapping bitslices. | ||
Logic _extendedMultiplier = Logic(); | ||
late final RadixEncoder _encoder; | ||
late final int _sliceWidth; | ||
|
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.