Skip to content

Commit

Permalink
Naming definition (#160)
Browse files Browse the repository at this point in the history
* Adding Module.definitionName entries for components so that Verilog has fewer unique modules generated and names
are more meaningful.

* Added NativeMultiplier wrapper for use in generating Verilog to use native multipliers.

 * Moved optional clocking into base Multiplier class.

* Variable width optional output for FloatingPointMultiplier.
  • Loading branch information
desmonddak authored Jan 31, 2025
1 parent dd22bf5 commit 3302e0e
Show file tree
Hide file tree
Showing 41 changed files with 207 additions and 97 deletions.
14 changes: 7 additions & 7 deletions doc/components/floating_point.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Appropriate string representations, comparison operations, and operators are ava

### Floating Point Constants

The various IEEE constants representing corner cases of the field of floating-point values for a given size of [FloatingPointValue](https://intel.github.io/rohd-hcl/rohd_hcl/FloatingPointValue-class.html): infinities, zeros, limits for normal (e.g. mantissa in the range of $[1,2)$ and sub-normal numbers (zero exponent, and mantissa <1).
The various IEEE constants representing corner cases of the field of floating-point values for a given size of [FloatingPointValue](https://intel.github.io/rohd-hcl/rohd_hcl/FloatingPointValue-class.html): infinities, zeros, limits for normal (e.g. mantissa in the range of $[1,2)$) and sub-normal numbers (zero exponent, and mantissa <1).

For any basic arbitrary width `FloatingPointValue` ROHD-HCL supports the following constants in that format.

Expand All @@ -36,8 +36,8 @@ For any basic arbitrary width `FloatingPointValue` ROHD-HCL supports the followi
- `one`: The number one
- `smallestLargerThanOne`: Smallest number greater than one
- `largestNormal`: Largest positive number, most positive exponent, full mantissa
- `infinity`: Largest possible number: all 1s in the exponent, all 0s in the mantissa
- `nan`: Not a Number, demarked by all 1s in exponent and any 1 in mantissa (we use the LSB)
- `infinity`: Largest possible number: all 1s in the exponent, all 0s in the mantissa
- `nan`: Not a Number, designated by all 1s in exponent and any 1 in mantissa (we use the LSB)

### Special subtypes

Expand Down Expand Up @@ -73,7 +73,7 @@ A very basic [FloatingPointMultiplierSimple] component is available which does n

It has options to control its performance:

- 'radix': used to specify the radix of the Booth encoder (default radix=4: options are [2,4,8,16])'.

- 'adderGen': used to specify the kind of [Adder] used for key functions like the mantiss addition. Defaults to [NativeAdder], but you can select a [ParallelPrefixAdder] of your choice.
- 'ppTree': used to specify the type of ['ParallelPrefix'](https://intel.github.io/rohd-hcl/rohd_hcl/ParallelPrefix-class.html) used in the pther critical functions like leading-one detect.
- `radix`: used to specify the radix of the Booth encoder (default radix=4: options are [2,4,8,16])'.
- `adderGen`: used to specify the kind of [Adder] used for key functions like the mantissa addition. Defaults to [NativeAdder], but you can select a [ParallelPrefixAdder] of your choice.
- `seGen`: type of sign extension routine used, base class is [PartialProductSignExtension].
- `ppTree`: used to specify the type of ['ParallelPrefix'](https://intel.github.io/rohd-hcl/rohd_hcl/ParallelPrefix-class.html) used in the other critical functions like leading-one detect.
6 changes: 4 additions & 2 deletions lib/src/arbiters/arbiter.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2023-2024 Intel Corporation
// Copyright (C) 2023-2025 Intel Corporation
// SPDX-License-Identifier: BSD-3-Clause
//
// arbiter.dart
Expand Down Expand Up @@ -32,7 +32,9 @@ abstract class Arbiter extends Module {

/// Constructs an arbiter where each element in [requests] is a one-bit signal
/// requesting a corresponding bit from [grants].
Arbiter(List<Logic> requests, {super.name = 'arbiter'}) {
Arbiter(List<Logic> requests,
{super.name = 'arbiter', String? definitionName})
: super(definitionName: definitionName ?? 'Arbiter_W${requests.length}') {
for (var i = 0; i < requests.length; i++) {
if (requests[i].width != 1) {
throw RohdHclException('Each request must be 1 bit,'
Expand Down
5 changes: 3 additions & 2 deletions lib/src/arbiters/mask_round_robin_arbiter.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2023-2024 Intel Corporation
// Copyright (C) 2023-2025 Intel Corporation
// SPDX-License-Identifier: BSD-3-Clause
//
// mask_round_robin_arbiter.dart
Expand Down Expand Up @@ -34,7 +34,8 @@ class MaskRoundRobinArbiter extends StatefulArbiter
/// and keeping record of requests already granted, in order to mask it until
/// granting the turn of each request to start again
MaskRoundRobinArbiter(super.requests,
{required super.clk, required super.reset}) {
{required super.clk, required super.reset})
: super(definitionName: 'MaskRoundRobinArbiter_W${requests.length}') {
_requestMask = List.generate(count, (i) => Logic(name: 'requestMask$i'));
_grantMask = List.generate(count, (i) => Logic(name: 'grantMask$i'));
Sequential(clk, [
Expand Down
5 changes: 3 additions & 2 deletions lib/src/arbiters/priority_arbiter.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2023-2024 Intel Corporation
// Copyright (C) 2023-2025 Intel Corporation
// SPDX-License-Identifier: BSD-3-Clause
//
// priority_arbiter.dart
Expand All @@ -14,7 +14,8 @@ import 'package:rohd_hcl/rohd_hcl.dart';
class PriorityArbiter extends Arbiter {
/// Constructs an arbiter where the grant is given to the lowest-indexed
/// request.
PriorityArbiter(super.requests, {super.name = 'priority_arbiter'}) {
PriorityArbiter(super.requests, {super.name = 'priority_arbiter'})
: super(definitionName: 'PriorityArbiter_W${requests.length}') {
Combinational([
CaseZ(requests.rswizzle(), conditionalType: ConditionalType.priority, [
for (var i = 0; i < count; i++)
Expand Down
5 changes: 3 additions & 2 deletions lib/src/arbiters/rotate_round_robin_arbiter.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2023-2024 Intel Corporation
// Copyright (C) 2023-2025 Intel Corporation
// SPDX-License-Identifier: BSD-3-Clause
//
// rotate_round_robin_arbiter.dart
Expand All @@ -15,7 +15,8 @@ class RotateRoundRobinArbiter extends StatefulArbiter
implements RoundRobinArbiter {
/// Creates an [Arbiter] that fairly takes turns between [requests].
RotateRoundRobinArbiter(super.requests,
{required super.clk, required super.reset}) {
{required super.clk, required super.reset})
: super(definitionName: 'RotateRoundRobinArbiter_W${requests.length}') {
final preference = Logic(name: 'preference', width: log2Ceil(count));

final rotatedReqs = requests
Expand Down
8 changes: 6 additions & 2 deletions lib/src/arbiters/stateful_arbiter.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2023-2024 Intel Corporation
// Copyright (C) 2023-2025 Intel Corporation
// SPDX-License-Identifier: BSD-3-Clause
//
// stateful_arbiter.dart
Expand Down Expand Up @@ -26,7 +26,11 @@ abstract class StatefulArbiter extends Arbiter {
late final Logic reset = input('reset');

/// Creates a new [StatefulArbiter] with associated [clk] and [reset].
StatefulArbiter(super.requests, {required Logic clk, required Logic reset}) {
StatefulArbiter(super.requests,
{required Logic clk, required Logic reset, String? definitionName})
: super(
definitionName:
definitionName ?? 'StatefulArbiter_W${requests.length}') {
addInput('clk', clk);
addInput('reset', reset);
}
Expand Down
6 changes: 4 additions & 2 deletions lib/src/arithmetic/adder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ abstract class Adder extends Module {

/// Takes in input [a] and input [b] and return the [sum] of the addition
/// result. The width of input [a] and [b] must be the same.
Adder(Logic a, Logic b, {Logic? carryIn, super.name}) : super() {
Adder(Logic a, Logic b, {Logic? carryIn, super.name, String? definitionName})
: super(definitionName: definitionName ?? 'Adder_W${a.width}') {
if (a.width != b.width) {
throw RohdHclException('inputs of a and b should have same width.');
}
Expand Down Expand Up @@ -72,7 +73,8 @@ class FullAdder extends Adder {
/// into other modules as a parameter for using the native operation.
class NativeAdder extends Adder {
/// The width of input [a] and [b] must be the same.
NativeAdder(super.a, super.b, {super.carryIn, super.name = 'native_adder'}) {
NativeAdder(super.a, super.b, {super.carryIn, super.name = 'native_adder'})
: super(definitionName: 'NativeAdder_W${a.width}') {
if (a.width != b.width) {
throw RohdHclException('inputs of a and b should have same width.');
}
Expand Down
5 changes: 4 additions & 1 deletion lib/src/arithmetic/carry_save_mutiplier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ class CarrySaveMultiplier extends Multiplier {
{required Logic clk,
required Logic reset,
super.name = 'carry_save_multiplier'})
: super(signedMultiplicand: false, signedMultiplier: false) {
: super(
signedMultiplicand: false,
signedMultiplier: false,
definitionName: 'CarrySaveMultiplier_W${a.width}') {
if (a.width != b.width) {
throw RohdHclException('inputs of a and b should have same width.');
}
Expand Down
6 changes: 4 additions & 2 deletions lib/src/arithmetic/divider.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2024 Intel Corporation
// Copyright (C) 2024-2025 Intel Corporation
// SPDX-License-Identifier: BSD-3-Clause
//
// divider.dart
Expand Down Expand Up @@ -128,7 +128,9 @@ class MultiCycleDivider extends Module {
MultiCycleDivider(MultiCycleDividerInterface interface)
: dataWidth = interface.dataWidth,
logDataWidth = log2Ceil(interface.dataWidth),
super(name: 'divider') {
super(
name: 'divider',
definitionName: 'MultiCycleDivider_W${interface.dataWidth}') {
intf = MultiCycleDividerInterface.match(interface)
..pairConnectIO(
this,
Expand Down
5 changes: 4 additions & 1 deletion lib/src/arithmetic/fixed_to_float.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ class FixedToFloat extends Module {
FixedToFloat(FixedPoint fixed,
{required this.exponentWidth,
required this.mantissaWidth,
super.name = 'FixedToFloat'}) {
super.name = 'FixedToFloat'})
: super(
definitionName:
'Fixed${fixed.width}ToFloatE${exponentWidth}M$mantissaWidth') {
fixed = fixed.clone()..gets(addInput('fixed', fixed, width: fixed.width));
addOutput('float', width: _float.width) <= _float;

Expand Down
5 changes: 4 additions & 1 deletion lib/src/arithmetic/float_to_fixed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ class FloatToFixed extends Module {
late final FixedPoint fixed = _fixed.clone()..gets(output('fixed'));

/// Constructor
FloatToFixed(FloatingPoint float, {super.name = 'FloatToFixed'}) {
FloatToFixed(FloatingPoint float, {super.name = 'FloatToFixed'})
: super(
definitionName: 'FloatE${float.exponent.width}'
'M${float.mantissa.width}ToFixed') {
float = float.clone()..gets(addInput('float', float, width: float.width));

final bias = FloatingPointValue.computeBias(float.exponent.width);
Expand Down
8 changes: 6 additions & 2 deletions lib/src/arithmetic/floating_point/floating_point_adder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ abstract class FloatingPointAdder extends Module {
{Logic? clk,
Logic? reset,
Logic? enable,
super.name = 'floating_point_adder'})
super.name = 'floating_point_adder',
String? definitionName})
: exponentWidth = a.exponent.width,
mantissaWidth = a.mantissa.width,
super() {
super(
definitionName: definitionName ??
'FloatingPointAdder_E${a.exponent.width}'
'M${a.mantissa.width}') {
if (b.exponent.width != exponentWidth ||
b.mantissa.width != mantissaWidth) {
throw RohdHclException('FloatingPoint widths must match');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ class FloatingPointAdderRound extends FloatingPointAdder {
ParallelPrefix Function(
List<Logic> inps, Logic Function(Logic term1, Logic term2) op)
ppTree = KoggeStone.new,
super.name = 'floating_point_adder_round'}) {
super.name = 'floating_point_adder_round'})
: super(
definitionName: 'FloatingPointAdderRound_'
'E${a.exponent.width}M${a.mantissa.width}') {
final outputSum = FloatingPoint(
exponentWidth: exponentWidth, mantissaWidth: mantissaWidth);
output('sum') <= outputSum;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ class FloatingPointAdderSimple extends FloatingPointAdder {
List<Logic> inps, Logic Function(Logic term1, Logic term2) op)
ppTree = KoggeStone.new,
super.name = 'floatingpoint_adder_simple'})
: super() {
: super(
definitionName: 'FloatingPointAdderSimple_'
'E${a.exponent.width}M${a.mantissa.width}') {
final outputSum = FloatingPoint(
exponentWidth: exponentWidth,
mantissaWidth: mantissaWidth,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ abstract class FloatingPointMultiplier extends Module {
// ignore: avoid_unused_constructor_parameters
ParallelPrefix Function(List<Logic>, Logic Function(Logic, Logic)) ppGen =
KoggeStone.new,
super.name = 'floating_point_multiplier'}) {
super.name = 'floating_point_multiplier',
String? definitionName})
: super(
definitionName: definitionName ??
'FloatingPointMultiplier_E${a.exponent.width}'
'M${a.mantissa.width}') {
if (b.exponent.width != a.exponent.width ||
b.mantissa.width != a.mantissa.width) {
throw RohdHclException('FloatingPoint widths must match');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ class FloatingPointMultiplierSimple extends FloatingPointMultiplier {
ParallelPrefix Function(
List<Logic> inps, Logic Function(Logic term1, Logic term2) op)
ppTree = KoggeStone.new,
super.name}) {
super.name})
: super(
definitionName: 'FloatingPointMultiplierSimple_'
'E${a.exponent.width}M${a.mantissa.width}'
'${outProduct != null ? '_OE${outProduct.exponent.width}_'
'OM${outProduct.mantissa.width}' : ''}') {
if (exponentWidth < a.exponent.width) {
throw RohdHclException('product exponent width must be >= '
' input exponent width');
Expand Down
26 changes: 22 additions & 4 deletions lib/src/arithmetic/multiplier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ abstract class Multiplier extends Module {
this.signedMultiplier = false,
Logic? selectSignedMultiplicand,
Logic? selectSignedMultiplier,
super.name = 'multiplier'}) {
super.name = 'multiplier',
String? definitionName})
: super(
definitionName:
definitionName ?? 'Multiplier_W${a.width}x${b.width}') {
if (signedMultiplicand && (selectSignedMultiplicand != null)) {
throw RohdHclException('multiplicand sign reconfiguration requires '
'signedMultiplicand=false');
Expand Down Expand Up @@ -136,7 +140,8 @@ class NativeMultiplier extends Multiplier {
super.signedMultiplier = false,
super.selectSignedMultiplicand,
super.selectSignedMultiplier,
super.name = 'native_multiplier'}) {
super.name = 'native_multiplier'})
: super(definitionName: 'NativeMultiplier_W${a.width}') {
if (a.width != b.width) {
throw RohdHclException('inputs of a and b should have same width.');
}
Expand Down Expand Up @@ -267,7 +272,12 @@ abstract class MultiplyAccumulate extends Module {
Logic? selectSignedMultiplicand,
Logic? selectSignedMultiplier,
Logic? selectSignedAddend,
super.name}) {
super.name,
String? definitionName})
: super(
definitionName: definitionName ??
'MultiplyAccumulate_W${a.width}x${b.width}_'
'Acc${c.width}') {
this.clk = (clk != null) ? addInput('clk', clk) : null;
this.reset = (reset != null) ? addInput('reset', reset) : null;
this.enable = (enable != null) ? addInput('enable', enable) : null;
Expand Down Expand Up @@ -343,7 +353,15 @@ class CompressionTreeMultiplier extends Multiplier {
PartialProductSignExtension Function(PartialProductGeneratorBase pp,
{String name})
seGen = CompactRectSignExtension.new,
super.name = 'compression_tree_multiplier'}) {
super.name = 'compression_tree_multiplier'})
: super(
definitionName: 'CompressionTreeMultiplier_W${a.width}x'
'${b.width}_'
'${signedMultiplicand ? 'SD_' : ''}'
'${signedMultiplier ? 'SM_' : ''}'
'${selectSignedMultiplicand != null ? 'SSD_' : ''}'
'${selectSignedMultiplier != null ? 'SSM_' : ''}'
'with${adderGen(a, b).definitionName}') {
// Should be done in base TODO(desmonddak):
final product = addOutput('product', width: a.width + b.width);
final pp = PartialProductGenerator(
Expand Down
3 changes: 2 additions & 1 deletion lib/src/arithmetic/ones_complement_adder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class OnesComplementAdder extends Adder {
Logic? carryOut,
Logic? carryIn,
bool? subtract,
super.name = 'ones_complement_adder'}) {
super.name = 'ones_complement_adder'})
: super(definitionName: 'OnesComplementAdder_W${a.width}') {
if (subtractIn != null) {
subtractIn = addInput('subtractIn', subtractIn);
}
Expand Down
23 changes: 16 additions & 7 deletions lib/src/arithmetic/parallel_prefix_operations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ class ParallelPrefix extends Module {
List<Logic> get val => UnmodifiableListView(_oseq);

/// ParallePrefix recursion
ParallelPrefix(List<Logic> inps, String name) : super(name: name) {
ParallelPrefix(List<Logic> inps, String name)
: super(
name: name,
definitionName: 'ParallelPrefix_${name}_W${inps.length}') {
if (inps.isEmpty) {
throw Exception("Don't use {name} with an empty sequence");
}
Expand Down Expand Up @@ -169,7 +172,8 @@ class ParallelPrefixOrScan extends Module {
{ParallelPrefix Function(
List<Logic> inps, Logic Function(Logic term1, Logic term2) op)
ppGen = KoggeStone.new,
super.name = 'parallel_prefix_orscan'}) {
super.name = 'parallel_prefix_orscan'})
: super(definitionName: 'ParallelPrefixOrScan_W${inp.width}') {
inp = addInput('inp', inp, width: inp.width);
final u = ppGen(inp.elements, (a, b) => a | b);
addOutput('out', width: inp.width) <= u.val.rswizzle();
Expand All @@ -187,7 +191,8 @@ class ParallelPrefixPriorityFinder extends Module {
{ParallelPrefix Function(
List<Logic> inps, Logic Function(Logic term1, Logic term2) op)
ppGen = KoggeStone.new,
super.name = 'parallel_prefix_finder'}) {
super.name = 'parallel_prefix_finder'})
: super(definitionName: 'ParallelPrefixPriorityFinder_W${inp.width}') {
inp = addInput('inp', inp, width: inp.width);
final u = ParallelPrefixOrScan(inp, ppGen: ppGen);
addOutput('out', width: inp.width) <=
Expand Down Expand Up @@ -219,7 +224,8 @@ class ParallelPrefixPriorityEncoder extends Module {
List<Logic> inps, Logic Function(Logic term1, Logic term2) op)
ppGen = KoggeStone.new,
Logic? valid,
super.name = 'parallel_prefix_encoder'}) {
super.name = 'parallel_prefix_encoder'})
: super(definitionName: 'ParallelPrefixPriorityEncoder_W${inp.width}') {
inp = addInput('inp', inp, width: inp.width);
final sz = log2Ceil(inp.width + 1);
addOutput('out', width: sz);
Expand Down Expand Up @@ -249,7 +255,8 @@ class ParallelPrefixAdder extends Adder {
ParallelPrefix Function(
List<Logic> inps, Logic Function(Logic term1, Logic term2) op)
ppGen = KoggeStone.new,
super.name = 'parallel_prefix_adder'}) {
super.name = 'parallel_prefix_adder'})
: super(definitionName: 'ParallelPrefixAdder_W${a.width}') {
final l = List<Logic>.generate(a.width - 1,
(i) => [a[i + 1] & b[i + 1], a[i + 1] | b[i + 1]].swizzle());
final cin = carryIn ?? Const(0);
Expand Down Expand Up @@ -286,7 +293,8 @@ class ParallelPrefixIncr extends Module {
{ParallelPrefix Function(
List<Logic> inps, Logic Function(Logic term1, Logic term2) op)
ppGen = KoggeStone.new,
super.name = 'parallel_prefix_incr'}) {
super.name = 'parallel_prefix_incr'})
: super(definitionName: 'ParallelPrefixIncr_W${inp.width}') {
inp = addInput('inp', inp, width: inp.width);
final u = ppGen(inp.elements, (lhs, rhs) => rhs & lhs);
addOutput('out', width: inp.width) <=
Expand All @@ -308,7 +316,8 @@ class ParallelPrefixDecr extends Module {
{ParallelPrefix Function(
List<Logic> inps, Logic Function(Logic term1, Logic term2) op)
ppGen = KoggeStone.new,
super.name = 'parallel_prefix_decr'}) {
super.name = 'parallel_prefix_decr'})
: super(definitionName: 'ParallelPrefixDecr_W${inp.width}') {
inp = addInput('inp', inp, width: inp.width);
final u = ppGen((~inp).elements, (lhs, rhs) => rhs & lhs);
addOutput('out', width: inp.width) <=
Expand Down
Loading

0 comments on commit 3302e0e

Please sign in to comment.