From 77a47a4e6fb5f84184e3b1d81ff6fb2dca5ec1f5 Mon Sep 17 00:00:00 2001 From: "Desmond A. Kirkpatrick" Date: Fri, 9 Aug 2024 08:31:43 -0700 Subject: [PATCH] reorganized multiplier code --- .../{compressor.dart => addend_compressor.dart} | 15 ++++++++------- lib/src/arithmetic/multiplicand_selector.dart | 2 +- lib/src/arithmetic/multiplier.dart | 1 + lib/src/arithmetic/multiplier_lib.dart | 15 +++++++++++++++ lib/src/arithmetic/partial_product_generator.dart | 1 + 5 files changed, 26 insertions(+), 8 deletions(-) rename lib/src/arithmetic/{compressor.dart => addend_compressor.dart} (96%) create mode 100644 lib/src/arithmetic/multiplier_lib.dart diff --git a/lib/src/arithmetic/compressor.dart b/lib/src/arithmetic/addend_compressor.dart similarity index 96% rename from lib/src/arithmetic/compressor.dart rename to lib/src/arithmetic/addend_compressor.dart index 5304dcd3a..8852607ff 100644 --- a/lib/src/arithmetic/compressor.dart +++ b/lib/src/arithmetic/addend_compressor.dart @@ -1,7 +1,7 @@ // Copyright (C) 2024 Intel Corporation // SPDX-License-Identifier: BSD-3-Clause // -// compressor.dart +// addend_compressor.dart // Column compression of partial prodcuts // // 2024 June 04 @@ -11,12 +11,13 @@ import 'dart:io'; import 'package:collection/collection.dart'; import 'package:meta/meta.dart'; import 'package:rohd/rohd.dart'; -import 'package:rohd_hcl/rohd_hcl.dart'; +import 'package:rohd_hcl/src/arithmetic/multiplier_lib.dart'; +import 'package:rohd_hcl/src/utils.dart'; // TODO(desmonddak): Logic and LogicValue majority() functions /// Base class for column compressor function -abstract class Compressor extends Module { +abstract class AddendCompressor extends Module { /// Input bits to compress @protected late final Logic compressBits; @@ -28,7 +29,7 @@ abstract class Compressor extends Module { Logic get carry => output('carry'); /// Construct a column compressor - Compressor(Logic compressBits) { + AddendCompressor(Logic compressBits) { this.compressBits = addInput( 'compressBits', compressBits, @@ -40,7 +41,7 @@ abstract class Compressor extends Module { } /// 2-input column compressor (half-adder) -class Compressor2 extends Compressor { +class Compressor2 extends AddendCompressor { /// Construct a 2-input compressor (half-adder) Compressor2(super.compressBits) { sum <= compressBits.xor(); @@ -49,7 +50,7 @@ class Compressor2 extends Compressor { } /// 3-input column compressor (full-adder) -class Compressor3 extends Compressor { +class Compressor3 extends AddendCompressor { /// Construct a 3-input column compressor (full-adder) Compressor3(super.compressBits) { sum <= compressBits.xor(); @@ -298,7 +299,7 @@ class ColumnCompressor { final first = queue.removeFirst(); final second = queue.removeFirst(); final inputs = [first, second]; - Compressor compressor; + AddendCompressor compressor; if (depth > 3) { inputs.add(queue.removeFirst()); compressor = diff --git a/lib/src/arithmetic/multiplicand_selector.dart b/lib/src/arithmetic/multiplicand_selector.dart index fcc8727f2..47671ed6a 100644 --- a/lib/src/arithmetic/multiplicand_selector.dart +++ b/lib/src/arithmetic/multiplicand_selector.dart @@ -9,7 +9,7 @@ import 'package:rohd/rohd.dart'; import 'package:rohd_hcl/rohd_hcl.dart'; -import 'package:rohd_hcl/src/arithmetic/multiplier_encoder.dart'; +import 'package:rohd_hcl/src/arithmetic/multiplier_lib.dart'; /// A class accessing the multiples of the multiplicand at a position class MultiplicandSelector { diff --git a/lib/src/arithmetic/multiplier.dart b/lib/src/arithmetic/multiplier.dart index 18f11c998..1538a7a69 100644 --- a/lib/src/arithmetic/multiplier.dart +++ b/lib/src/arithmetic/multiplier.dart @@ -11,6 +11,7 @@ import 'package:meta/meta.dart'; import 'package:rohd/rohd.dart'; import 'package:rohd_hcl/rohd_hcl.dart'; +import 'package:rohd_hcl/src/arithmetic/multiplier_lib.dart'; /// An abstract class for all multiplier implementations. abstract class Multiplier extends Module { diff --git a/lib/src/arithmetic/multiplier_lib.dart b/lib/src/arithmetic/multiplier_lib.dart new file mode 100644 index 000000000..47760e5fc --- /dev/null +++ b/lib/src/arithmetic/multiplier_lib.dart @@ -0,0 +1,15 @@ +// Copyright (C) 2024 Intel Corporation +// SPDX-License-Identifier: BSD-3-Clause +// +// multiplier_lib.dart +// Consolidate exports of the main components for multiplication: encoder, +// selector, partial_product_generator, compressor +// +// 2024 August 9 +// Author: Desmond Kirkpatrick +// +// + +// Just exporting encoder exports all the symbols we use +export './compressor.dart'; +export './multiplier_encoder.dart'; diff --git a/lib/src/arithmetic/partial_product_generator.dart b/lib/src/arithmetic/partial_product_generator.dart index 3ba3d8886..e87199afb 100644 --- a/lib/src/arithmetic/partial_product_generator.dart +++ b/lib/src/arithmetic/partial_product_generator.dart @@ -11,6 +11,7 @@ import 'dart:math'; import 'package:rohd/rohd.dart'; import 'package:rohd_hcl/rohd_hcl.dart'; +import 'package:rohd_hcl/src/arithmetic/multiplier_lib.dart'; /// A class that generates a set of partial products. Essentially a set of /// shifted rows of [Logic] addends generated by Booth recoding and