Skip to content

Floating - #302

Open
desmonddak wants to merge 23 commits into
intel:mainfrom
desmonddak:floating
Open

desmonddak wants to merge 23 commits into
intel:mainfrom
desmonddak:floating

Conversation

@desmonddak

Copy link
Copy Markdown
Contributor

Description & Motivation

This PR is focused on resolving issues reported as well as TODOs documented on the arithmetic library portion of ROHD-HCL. The biggest fixes are around rounding and conversions.

Related Issue(s)

Features

Fixes

API Cleanup and Verification

  • Added StaticOrRuntimeControl<T> as the general static-or-runtime control
    abstraction; deprecated BooleanConfig and RuntimeConfig.
  • Expanded exhaustive conversion, rounding, arithmetic, and
    multiply-accumulate coverage.

Testing

All existing tests pass. Several new tests added to cover bugs reported and fixed.

Backwards-compatibility

Is this a breaking change that will not be backwards-compatible? If yes, how so?

Documentation

Does the change require any updates to documentation? If so, where? Are they included?

Yes. Relevant documentation was updated to match the new functionality introduced (e.g., StaticOrRuntimeControl.

@desmonddak

Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Mixed-sign MAC handling, IEEE status flags, converter sticky rounding, and subnormal square roots contain correctness issues.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Expands ROHD-HCL arithmetic with IEEE rounding, exact conversions, typed operations, configurable multiply-accumulate logic, and static/runtime controls.

Changes:

  • Adds rounding modes, floating-point status flags, NaN handling, and conversion fixes.
  • Adds typed fixed/floating arithmetic and configurable MAC behavior.
  • Expands tests, compatibility APIs, documentation, and release notes.
File summaries
File Description
test/summation/counter_test.dart Updates copyright.
test/static_or_runtime_control_test.dart Tests legacy import compatibility.
test/memory/resettable_entries_test.dart Tests runtime reset values.
test/arithmetic/sign_magnitude_adder_test.dart Tests carry-in behavior.
test/arithmetic/ones_complement_adder_test.dart Migrates subtraction control API.
test/arithmetic/multiplier_test.dart Expands MAC width and control tests.
test/arithmetic/multiplier_encoder_test.dart Reduces test widths and cleanup.
test/arithmetic/generic_multiply_accumulate_test.dart Tests generic MAC functionality.
test/arithmetic/floating_point/floating_point_test.dart Tests NaNs, comparisons, and operators.
test/arithmetic/floating_point/floating_point_status_test.dart Tests IEEE exception status.
test/arithmetic/floating_point/floating_point_sqrt_test.dart Tests square-root rounding and subnormals.
test/arithmetic/floating_point/floating_point_rounding_test.dart Tests all rounding modes.
test/arithmetic/floating_point/floating_point_conversion_test.dart Expands exhaustive conversion coverage.
test/arithmetic/floating_point/floating_point_adder_test.dart Uses exact value-side addition.
test/arithmetic/floating_point/floating_point_adder_dualpath_test.dart Expands dual-path rounding tests.
test/arithmetic/float_to_fixed_test.dart Tests exact and rounded conversions.
test/arithmetic/fixed_to_float_test.dart Tests rounding and explicit J bits.
test/arithmetic/fixed_point_test.dart Tests typed arithmetic and constants.
test/arithmetic/dotproduct_test.dart Tests dynamic partial-sum extension.
test/arithmetic/compound_adder_test.dart Migrates subtraction controls.
test/arithmetic/adder_test.dart Migrates subtraction controls.
test/apb_bfm_test.dart Updates copyright.
lib/src/static_or_runtime_parameter.dart Preserves the legacy import path.
lib/src/static_or_runtime_control.dart Adds generic static/runtime controls.
lib/src/models/memory_model.dart Updates copyright.
lib/src/arithmetic/values/floating_point_values/floating_point_rounding_mode.dart Adds exact BigInt rounding.
lib/src/arithmetic/values/floating_point_values/floating_point_8_e4m3_value.dart Corrects E4M3 limits and NaNs.
lib/src/arithmetic/values/fixed_point_value.dart Adds signed APIs and exact conversions.
lib/src/arithmetic/values/fixed_point_populator.dart Adds rounded exact population APIs.
lib/src/arithmetic/signals/floating_point_logics/floating_point_logic.dart Adds constants, arithmetic, and IEEE comparisons.
lib/src/arithmetic/signals/fixed_point_logic.dart Adds typed fixed-point arithmetic.
lib/src/arithmetic/sign_magnitude_adder.dart Adds carry-in support.
lib/src/arithmetic/ones_complement_adder.dart Unifies static/runtime subtraction.
lib/src/arithmetic/multiply_accumulate.dart Adds output widths and generic MAC.
lib/src/arithmetic/multiplier_components/partial_product_sign_extend.dart Narrows unused sign-extension logic.
lib/src/arithmetic/floating_point/floating_point.dart Exports status support.
lib/src/arithmetic/floating_point/floating_point_status.dart Defines IEEE status signals.
lib/src/arithmetic/floating_point/floating_point_sqrt.dart Adds rounding and status interfaces.
lib/src/arithmetic/floating_point/floating_point_sqrt_simple.dart Adds rounded subnormal-capable square root.
lib/src/arithmetic/floating_point/floating_point_rounding.dart Implements shared hardware rounders.
lib/src/arithmetic/floating_point/floating_point_multiplier.dart Adds multiplier status output.
lib/src/arithmetic/floating_point/floating_point_multiplier_simple.dart Adds narrowing, rounding, and status.
lib/src/arithmetic/floating_point/floating_point_converter.dart Adds rounded conversion and status.
lib/src/arithmetic/floating_point/floating_point_adder.dart Adds adder status output.
lib/src/arithmetic/floating_point/floating_point_adder_singlepath.dart Expands rounding and special handling.
lib/src/arithmetic/float_to_fixed.dart Adds rounding and overflow fixes.
lib/src/arithmetic/fixed_to_float.dart Adds shared rounding and explicit J bits.
lib/src/arithmetic/dotproduct.dart Corrects reduction widths and extension.
lib/src/arithmetic/compound_adder.dart Unifies subtraction configuration.
lib/rohd_hcl.dart Exports the new control API.
doc/static_or_runtime_parameters.md Documents static/runtime controls.
doc/README.md Links the new documentation.
doc/components/floating_point.md Documents floating-point operators.
doc/components/fixed_point.md Documents signed APIs and arithmetic.
CHANGELOG.md Records features, fixes, and deprecations.
Review details
  • Files reviewed: 62/62 changed files
  • Comments generated: 13
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lib/src/arithmetic/floating_point/floating_point_sqrt_simple.dart Outdated
Comment thread lib/src/arithmetic/multiply_accumulate.dart Outdated
Comment thread lib/src/arithmetic/compound_adder.dart Outdated
Comment thread lib/src/arithmetic/floating_point/floating_point_adder_dualpath.dart Outdated
Comment thread lib/src/arithmetic/floating_point/floating_point_multiplier_simple.dart Outdated
Comment thread lib/src/arithmetic/multiply_accumulate.dart Outdated
Comment thread lib/src/arithmetic/ones_complement_adder.dart Outdated
Comment thread doc/components/floating_point.md Outdated
Comment thread lib/src/arithmetic/values/fixed_point_value.dart

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Square-root handling, directed conversion overflow, MAC definition naming, and metadata consistency have unresolved correctness issues.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (3)

Previously missed (1) — in code that hasn't changed since the last review.

lib/src/arithmetic/fixed_to_float.dart:46

  • The new rounding mode affects significand rounding, but overflow still unconditionally emits infinity in the expoMoreThanMax branch. Directed/toward-zero modes must instead return the largest finite value when the rounding direction is away from infinity (for example, +15 converted to E3M2 with roundTowardsZero should become +14, not +infinity).

lib/src/arithmetic/floating_point/floating_point_sqrt_simple.dart:199

  • Underflow is hard-wired low even when the newly supported square root produces an inexact subnormal result. This contradicts FloatingPointStatus.underflow's “tiny result was inexact after rounding” contract; the smallest E3M5 subnormal exercised by the new test is one such case.
    internalStatus.underflow <= Const(0);

lib/src/arithmetic/values/fixed_point_value.dart:52

  • The PR's backwards-compatibility section says FixedPointValue now defaults to signed: true, but this constructor deliberately retains false (as does the deprecated populator), while the changelog describes that preservation. Align the PR description with this compatibility strategy, or change the implementation if the stated breaking default is intended.
  factory FixedPointValue(
          {required LogicValue integer,
          required LogicValue fraction,
          bool signed = false}) =>
      FixedPointValue.withSignedness(
          integer: integer, fraction: fraction, signed: signed);
  • Files reviewed: 62/62 changed files
  • Comments generated: 3
  • Review effort level: Balanced

Comment thread lib/src/arithmetic/float_to_fixed.dart Outdated
Comment thread lib/src/arithmetic/floating_point/floating_point_sqrt_simple.dart
Comment thread lib/src/arithmetic/multiply_accumulate.dart

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Mixed-signed MAC arithmetic, conversion overflow rounding, and square-root underflow status contain unresolved correctness issues.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (3)

lib/src/arithmetic/float_to_fixed.dart:173

  • Overflow is calculated from the unrounded magnitude and never includes rounder.doRound. For signed Q2.1, E4M4 input 3.625 with round-nearest-even truncates to raw 7 (apparently fitting), then rounds to raw 8, wraps to -4, and leaves overflow false. Compute overflow from the rounded magnitude so rounding carry across the positive limit is reported.
          overflow <
              (_signedGtConst(shift, threshold) |
                  (shift.eq(Const(threshold, width: shift.width)) &
                      ~(float.sign & atThresholdIsExactPowerOfTwo))),

lib/src/arithmetic/values/fixed_point_value.dart:52

  • The PR's backwards-compatibility section says FixedPointValue and its factory now default to signed: true, but this public factory still defaults to false and forwards that value. This also leaves the API mismatch from #249 in place for existing callers; either implement the documented breaking default or update the PR description to state that only the new withSignedness API uses the signed default.
  factory FixedPointValue(
          {required LogicValue integer,
          required LogicValue fraction,
          bool signed = false}) =>
      FixedPointValue.withSignedness(
          integer: integer, fraction: fraction, signed: signed);

lib/src/arithmetic/multiply_accumulate.dart:440

  • commonWidth + 1 is insufficient when exactly one operand is signed. For example, the new test computes unsigned 49 + signed 15: the exact result is 64, but in 7 bits bit 6 is mistaken for a sign bit and widening produces 192. Reserve two bits beyond the widest operand so every mixed-signed sum remains representable before fitAccumulateWidth.
    final commonWidth = (product.width < c.width ? c.width : product.width) + 1;
  • Files reviewed: 62/62 changed files
  • Comments generated: 3
  • Review effort level: Balanced

Comment thread lib/src/arithmetic/fixed_to_float.dart
Comment thread lib/src/arithmetic/floating_point/floating_point_sqrt_simple.dart Outdated
Comment thread test/arithmetic/generic_multiply_accumulate_test.dart Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Explicit-J encodings, conversion rounding, pipelined signedness, and generated definition naming contain unresolved correctness issues.

Get a fresh assessment by requesting another Copilot review.

Review details

Suppressed comments (4)

Previously missed (1) — in code that hasn't changed since the last review.

lib/src/arithmetic/floating_point/floating_point_converter.dart:190

  • The rounding branch is selected by stored mantissa width, but explicit-J formats spend one stored bit on the J bit. An implicit M4 source converted to an explicit M4 destination loses one fraction bit, yet this condition skips the rounder, so all rounding modes behave like truncation (for example, positive 1.0625 should become 1.125 when rounding toward +infinity). Compare effective fraction widths and adjust the retained windows accordingly.

lib/src/arithmetic/signals/floating_point_logics/floating_point_logic.dart:315

  • For explicit-J-bit formats this sets only the J bit, leaving every fraction bit zero. The resulting value is classified as infinity rather than NaN (isNaN checks the fractional portion), so FloatingPoint.nan(explicitJBit: true, ...) is broken. Build the constant through the value populator so the J bit and quiet-NaN bit are both encoded correctly.
    final mantissa =
        Const(BigInt.one << (mantissaWidth - 1), width: mantissaWidth);

lib/src/arithmetic/values/fixed_point_value.dart:52

  • The PR description says the FixedPointValue factory now defaults to signed: true, but this public factory still defaults to false (as does the deprecated populator). The code and changelog preserve backward compatibility, so either update the PR compatibility statement or change these defaults to match the stated breaking change.
  factory FixedPointValue(
          {required LogicValue integer,
          required LogicValue fraction,
          bool signed = false}) =>
      FixedPointValue.withSignedness(
          integer: integer, fraction: fraction, signed: signed);

lib/src/arithmetic/fixed_to_float.dart:242

  • For E4M3, expoMoreThanMax is still computed against encoded exponent 14 even though exponent 15 contains finite values. This branch therefore maps representable values such as 256 to the largest finite value (448). Derive the overflow limit from largestFinite.exponent rather than the generic infinity-reserving limit.
        ElseIf(expoMoreThanMax, [
          _convertedFloat.exponent < Const(largestFinite.exponent),
          _convertedFloat.mantissa < Const(largestFinite.mantissa),
  • Files reviewed: 62/62 changed files
  • Comments generated: 6
  • Review effort level: Balanced

Comment thread lib/src/arithmetic/fixed_to_float.dart
Comment thread lib/src/arithmetic/float_to_fixed.dart
Comment thread lib/src/arithmetic/multiply_accumulate.dart
Comment thread lib/src/arithmetic/fixed_to_float.dart

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Format-specific conversions and square-root boundary handling currently produce incorrect floating-point encodings.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 3 High severity · 3 Medium severity

Open (6)
Resolved since last review (6)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Handle zero biased exponents as subnormal results

lib/​src/​arithmetic/​floating_point/​floating_point_sqrt_simple.dart:152

Biased exponent zero is also a subnormal result, but this condition only detects negative roundedExponent. For example, sqrt(E3M5 raw 0 000 00010) is exactly raw 0 000 10000; here roundedExponent is zero, so the current normal path emits exponent zero with the hidden bit discarded (zero instead of 0.125). Include zero in the subnormal condition.

Comment thread lib/src/arithmetic/fixed_to_float.dart
Comment thread lib/src/arithmetic/floating_point/floating_point_converter.dart Outdated
Comment thread lib/src/arithmetic/signals/floating_point_logics/floating_point_logic.dart Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread lib/src/arithmetic/fixed_to_float.dart
Comment thread lib/src/arithmetic/float_to_fixed.dart
Comment thread lib/src/arithmetic/floating_point/floating_point_converter.dart
Comment thread lib/src/arithmetic/multiply_accumulate.dart Outdated
Signed-off-by: Desmond A. Kirkpatrick <desmond.a.kirkpatrick@intel.com>
Signed-off-by: Desmond A. Kirkpatrick <desmond.a.kirkpatrick@intel.com>
Signed-off-by: Desmond A. Kirkpatrick <desmond.a.kirkpatrick@intel.com>
Signed-off-by: Desmond A. Kirkpatrick <desmond.a.kirkpatrick@intel.com>
Signed-off-by: Desmond A. Kirkpatrick <desmond.a.kirkpatrick@intel.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread lib/src/arithmetic/dotproduct.dart
Comment thread lib/src/arithmetic/dotproduct.dart
Comment thread lib/src/arithmetic/signals/fixed_point_logic.dart Outdated
Comment thread test/arithmetic/generic_multiply_accumulate_test.dart Outdated
@desmonddak
desmonddak requested a balanced review from Copilot October 5, 2026 20:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants