Skip to content

Commit

Permalink
Merge branch 'fpfixes' of https://github.com/desmonddak/rohd-hcl into…
Browse files Browse the repository at this point in the history
… desmonddak-fpfixes
  • Loading branch information
desmonddak committed Nov 12, 2024
2 parents 438e35e + 90eb653 commit de30796
Show file tree
Hide file tree
Showing 21 changed files with 79 additions and 102 deletions.
1 change: 1 addition & 0 deletions lib/rohd_hcl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

export 'src/arbiters/arbiters.dart';
export 'src/arithmetic/arithmetic.dart';

export 'src/binary_gray.dart';
export 'src/clock_gating.dart';
export 'src/component_config/component_config.dart';
Expand Down
2 changes: 2 additions & 0 deletions lib/src/arithmetic/arithmetic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ export 'parallel_prefix_operations.dart';
export 'ripple_carry_adder.dart';
export 'sign_magnitude_adder.dart';
export 'signals/fixed_point_logic.dart';
export 'signals/floating_point_logic.dart';
export 'values/fixed_point_value.dart';
export 'values/floating_point_values/floating_point_values.dart';
2 changes: 1 addition & 1 deletion lib/src/arithmetic/compound_adder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ abstract class CompoundAdder extends Adder {
/// Takes in input [a] and input [b] and return the [sum] of the addition
/// result and [sum1] sum + 1.
/// The width of input [a] and [b] must be the same.
CompoundAdder(super.a, super.b, {super.name}) {
CompoundAdder(super.a, super.b, {super.name = 'compound_adders'}) {
if (a.width != b.width) {
throw RohdHclException('inputs of a and b should have same width.');
}
Expand Down
2 changes: 0 additions & 2 deletions lib/src/arithmetic/floating_point/floating_point.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@

export 'floating_point_adder_round.dart';
export 'floating_point_adder_simple.dart';
export 'floating_point_logic.dart';
export 'floating_point_values/floating_point_values.dart';
40 changes: 23 additions & 17 deletions lib/src/arithmetic/floating_point/floating_point_adder_round.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class FloatingPointAdderRound extends Module {
Adder Function(Logic, Logic) adderGen = ParallelPrefixAdder.new,
ParallelPrefix Function(List<Logic>, Logic Function(Logic, Logic))
ppTree = KoggeStone.new,
super.name = 'floating_point_adder'})
super.name = 'floating_point_adder_round'})
: exponentWidth = a.exponent.width,
mantissaWidth = a.mantissa.width {
if (b.exponent.width != exponentWidth ||
Expand All @@ -116,7 +116,7 @@ class FloatingPointAdderRound extends Module {
addOutput('sum', width: _sum.width) <= _sum;

final exponentSubtractor = OnesComplementAdder(a.exponent, b.exponent,
subtract: true, adderGen: adderGen);
subtract: true, adderGen: adderGen, name: 'exponent_sub');
final signDelta = exponentSubtractor.sign;

final delta = exponentSubtractor.sum;
Expand Down Expand Up @@ -183,14 +183,16 @@ class FloatingPointAdderRound extends Module {
largeOperandLatched, smallerOperandRPathLatched,
subtractIn: effectiveSubtractionLatched,
carryOut: carryRPath,
adderGen: adderGen);
adderGen: adderGen,
name: 'rpath_significand_adder');

final lowBitsRPath =
smallerAlignRPathLatched.slice(extendWidthRPath - 1, 0);
final lowAdderRPath = OnesComplementAdder(
carryRPath.zeroExtend(extendWidthRPath),
mux(effectiveSubtractionLatched, ~lowBitsRPath, lowBitsRPath),
adderGen: adderGen);
adderGen: adderGen,
name: 'rpath_lowadder');

final preStickyRPath =
lowAdderRPath.sum.slice(lowAdderRPath.sum.width - 4, 0).or();
Expand Down Expand Up @@ -235,22 +237,21 @@ class FloatingPointAdderRound extends Module {

final firstZeroRPath = mux(selectRPath, ~sumP1RPath[-1], ~sumRPath[-1]);

final expDecr = ParallelPrefixDecr(largerExpLatched,
ppGen: ppTree, name: 'exp_decrement');
final expIncr = ParallelPrefixIncr(largerExpLatched,
ppGen: ppTree, name: 'exp_increment');
final exponentRPath = Logic(width: exponentWidth);
Combinational([
If.block([
// Subtract 1 from exponent
Iff(~incExpRPath & effectiveSubtractionLatched & firstZeroRPath, [
exponentRPath <
ParallelPrefixDecr(largerExpLatched, ppGen: ppTree).out
]),
Iff(~incExpRPath & effectiveSubtractionLatched & firstZeroRPath,
[exponentRPath < expDecr.out]),
// Add 1 to exponent
ElseIf(
~effectiveSubtractionLatched &
(incExpRPath & firstZeroRPath | ~incExpRPath & ~firstZeroRPath),
[
exponentRPath <
ParallelPrefixIncr(largerExpLatched, ppGen: ppTree).out
]),
[exponentRPath < expIncr.out]),
// Add 2 to exponent
ElseIf(incExpRPath & effectiveSubtractionLatched & ~firstZeroRPath,
[exponentRPath < largerExpLatched << 1]),
Expand All @@ -270,14 +271,17 @@ class FloatingPointAdderRound extends Module {

final significandSubtractorNPath = OnesComplementAdder(
largeOperand, smallOperandNPath,
subtractIn: effectiveSubtraction, adderGen: adderGen);
subtractIn: effectiveSubtraction,
adderGen: adderGen,
name: 'npath_significand_sub');

final significandNPath =
significandSubtractorNPath.sum.slice(smallOperandNPath.width - 1, 0);

final leadOneNPath = mux(
significandNPath.or(),
ParallelPrefixPriorityEncoder(significandNPath.reversed, ppGen: ppTree)
ParallelPrefixPriorityEncoder(significandNPath.reversed,
ppGen: ppTree, name: 'npath_leadingOne')
.out
.zeroExtend(exponentWidth),
Const(15, width: exponentWidth));
Expand All @@ -297,7 +301,9 @@ class FloatingPointAdderRound extends Module {

final expCalcNPath = OnesComplementAdder(
largerExpLatched, leadOneNPathLatched.zeroExtend(exponentWidth),
subtractIn: effectiveSubtractionLatched, adderGen: adderGen);
subtractIn: effectiveSubtractionLatched,
adderGen: adderGen,
name: 'npath_expcalc');

final preExpNPath = expCalcNPath.sum.slice(exponentWidth - 1, 0);

Expand All @@ -307,8 +313,8 @@ class FloatingPointAdderRound extends Module {

final preMinShiftNPath = ~leadOneNPathLatched.or() | ~largerExpLatched.or();

final minShiftNPath = mux(posExpNPath | preMinShiftNPath,
leadOneNPathLatched, largerExpLatched - 1);
final minShiftNPath =
mux(posExpNPath | preMinShiftNPath, leadOneNPathLatched, expDecr.out);
final notSubnormalNPath = aIsNormalLatched | bIsNormalLatched;

final shiftedSignificandNPath =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class FloatingPointAdderSimple extends Module {
FloatingPointAdderSimple(FloatingPoint a, FloatingPoint b,
{ParallelPrefix Function(List<Logic>, Logic Function(Logic, Logic))
ppGen = KoggeStone.new,
super.name})
super.name = 'floatingpoint_adder_simple'})
: exponentWidth = a.exponent.width,
mantissaWidth = a.mantissa.width {
if (b.exponent.width != exponentWidth ||
Expand Down
14 changes: 4 additions & 10 deletions lib/src/arithmetic/multiplier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,8 @@ class CompressionTreeMultiplier extends Multiplier {
{Logic? selectSigned,
ParallelPrefix Function(List<Logic>, Logic Function(Logic, Logic))
ppTree = KoggeStone.new,
super.signed = false})
: super(
name: 'Compression Tree Multiplier: '
'R${radix}_${ppTree.call([
Logic()
], (a, b) => Logic()).runtimeType}') {
super.signed = false,
super.name = 'compression_tree_multiplier'}) {
final product = addOutput('product', width: a.width + b.width);
final pp = PartialProductGeneratorCompactRectSignExtension(
a, b, RadixEncoder(radix),
Expand Down Expand Up @@ -128,10 +124,8 @@ class CompressionTreeMultiplyAccumulate extends MultiplyAccumulate {
{required super.signed,
Logic? selectSigned,
ParallelPrefix Function(List<Logic>, Logic Function(Logic, Logic))
ppTree = KoggeStone.new})
: super(
name: 'Compression Tree Multiply Accumulate: '
'R${radix}_${ppTree.call([Logic()], (a, b) => Logic()).name}') {
ppTree = KoggeStone.new,
super.name = 'compression_tree_mac'}) {
final accumulate = addOutput('accumulate', width: a.width + b.width + 1);
final pp = PartialProductGeneratorCompactRectSignExtension(
a, b, RadixEncoder(radix),
Expand Down
6 changes: 2 additions & 4 deletions lib/src/arithmetic/ones_complement_adder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ class OnesComplementAdder extends Adder {
{Adder Function(Logic, Logic) adderGen = ParallelPrefixAdder.new,
Logic? subtractIn,
Logic? carryOut,
bool subtract = false})
: super(
name: 'Ones Complement Adder: '
'${adderGen.call(Logic(), Logic()).name}') {
bool subtract = false,
super.name = 'ones_complement_adder'}) {
if (subtractIn != null) {
subtractIn = addInput('subtractIn', subtractIn);
}
Expand Down
42 changes: 12 additions & 30 deletions lib/src/arithmetic/parallel_prefix_operations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,8 @@ class ParallelPrefixOrScan extends Module {
/// OrScan constructor
ParallelPrefixOrScan(Logic inp,
{ParallelPrefix Function(List<Logic>, Logic Function(Logic, Logic))
ppGen = KoggeStone.new})
: super(
name: 'ParallelPrefixOrScan: ${ppGen.call([
Logic()
], (a, b) => Logic()).name}') {
ppGen = KoggeStone.new,
super.name = 'parallel_prefix_orscan'}) {
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 @@ -183,11 +180,8 @@ class ParallelPrefixPriorityFinder extends Module {
/// Priority Finder constructor
ParallelPrefixPriorityFinder(Logic inp,
{ParallelPrefix Function(List<Logic>, Logic Function(Logic, Logic))
ppGen = KoggeStone.new})
: super(
name: 'ParallelPrefixFinder: ${ppGen.call([
Logic()
], (a, b) => Logic()).name}') {
ppGen = KoggeStone.new,
super.name = 'parallel_prefix_finder'}) {
inp = addInput('inp', inp, width: inp.width);
final u = ParallelPrefixOrScan(inp, ppGen: ppGen);
addOutput('out', width: inp.width) <= (u.out & ~(u.out << Const(1)));
Expand All @@ -203,11 +197,8 @@ class ParallelPrefixPriorityEncoder extends Module {
/// PriorityEncoder constructor
ParallelPrefixPriorityEncoder(Logic inp,
{ParallelPrefix Function(List<Logic>, Logic Function(Logic, Logic))
ppGen = KoggeStone.new})
: super(
name: 'ParallelPrefixEncoder: ${ppGen.call([
Logic()
], (a, b) => Logic()).name}') {
ppGen = KoggeStone.new,
super.name = 'parallel_prefix_encoder'}) {
inp = addInput('inp', inp, width: inp.width);
addOutput('out', width: log2Ceil(inp.width));
final u = ParallelPrefixPriorityFinder(inp, ppGen: ppGen);
Expand All @@ -220,11 +211,8 @@ class ParallelPrefixAdder extends Adder {
/// Adder constructor
ParallelPrefixAdder(super.a, super.b,
{ParallelPrefix Function(List<Logic>, Logic Function(Logic, Logic))
ppGen = KoggeStone.new})
: super(
name: 'ParallelPrefixAdder: ${ppGen.call([
Logic()
], (a, b) => Logic()).name}') {
ppGen = KoggeStone.new,
super.name = 'parallel_prefix_adder'}) {
final u = ppGen(
List<Logic>.generate(
a.width, (i) => [a[i] & b[i], a[i] | b[i]].swizzle()),
Expand All @@ -247,11 +235,8 @@ class ParallelPrefixIncr extends Module {
/// Increment constructor
ParallelPrefixIncr(Logic inp,
{ParallelPrefix Function(List<Logic>, Logic Function(Logic, Logic))
ppGen = KoggeStone.new})
: super(
name: 'ParallelPrefixIncr: ${ppGen.call([
Logic()
], (a, b) => Logic()).name}') {
ppGen = KoggeStone.new,
super.name = 'parallel_prefix_incr'}) {
inp = addInput('inp', inp, width: inp.width);
final u = ppGen(inp.elements, (lhs, rhs) => rhs & lhs);
addOutput('out', width: inp.width) <=
Expand All @@ -269,11 +254,8 @@ class ParallelPrefixDecr extends Module {
/// Decrement constructor
ParallelPrefixDecr(Logic inp,
{ParallelPrefix Function(List<Logic>, Logic Function(Logic, Logic))
ppGen = KoggeStone.new})
: super(
name: 'ParallelPrefixDecr: ${ppGen.call([
Logic()
], (a, b) => Logic()).name}') {
ppGen = KoggeStone.new,
super.name = 'parallel_prefix_decr'}) {
inp = addInput('inp', inp, width: inp.width);
final u = ppGen((~inp).elements, (lhs, rhs) => rhs & lhs);
addOutput('out', width: inp.width) <=
Expand Down
6 changes: 2 additions & 4 deletions lib/src/arithmetic/sign_magnitude_adder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ class SignMagnitudeAdder extends Adder {
// TODO(desmonddak): this adder may need a carry-in for rounding
SignMagnitudeAdder(this.aSign, super.a, this.bSign, super.b,
Adder Function(Logic, Logic) adderGen,
{this.largestMagnitudeFirst = false})
: super(
name: 'Sign Magnitude Adder: '
'${adderGen.call(Logic(), Logic()).name}') {
{this.largestMagnitudeFirst = false,
super.name = 'sign_magnitude_adder'}) {
aSign = addInput('aSign', aSign);
bSign = addInput('bSign', bSign);
_sign = addOutput('sign');
Expand Down
Loading

0 comments on commit de30796

Please sign in to comment.