Skip to content

Reuse widening division results in integer and decimal arithmetic - #134517

Open
benaadams wants to merge 1 commit into
dotnet:mainfrom
benaadams:libraries/reuse-wide-division
Open

benaadams wants to merge 1 commit into
dotnet:mainfrom
benaadams:libraries/reuse-wide-division

Conversation

@benaadams

Copy link
Copy Markdown
Member

Reuse quotient/remainder results in wide-integer and decimal arithmetic instead of reconstructing remainders or decomposing inputs before an available widening divide:

  • Route 64-bit-target Int128 DivRem and remainder through UInt128.DivRem, preserving signed overflow and remainder semantics.
  • Prefer existing X86Base widening-divide intrinsics in BigIntegerCalculator when the quotient fits in one limb; reuse UInt128.DivRem in the fallback.
  • Feed separate limbs to Decimal's widening division and rounding paths.
  • Use full-limb division in the IEEE decimal wide power-of-ten helper.

Split from #134039 as suggested by @tannergooding. This uses existing APIs and JIT support and can merge independently of the new carry, multiply-chain and remainder-recognition optimizations.

Includes BigInteger-based boundary and randomized oracles for Int128, BigInteger limb division, decimal remainder/rounding, and the uint/ulong/UInt128 IEEE wide-division helper.

Validation:

  • Rebuilt Checked x64 runtime/CoreLib and Release System.Runtime.Numerics; focused tests passed with the baseline JIT, including register stress and disabled hardware intrinsics.
  • Final analyzer validation enabled IDE0005, code-style enforcement and documentation generation. No IDE0005 diagnostics in the changed files or new tests. Existing unused-import diagnostics elsewhere in CoreLib/Numerics were retained as warnings for this validation; an unrelated existing CA1018 diagnostic was excluded locally. No diagnostic suppressions are added by this PR.
  • The broad shared-framework build with documentation generation hit unrelated existing documentation diagnostics; focused affected-project validation was used instead.
  • git diff --check passed. No new throughput claim, native ARM64 run or x86 execution measurement is included in this extraction.

Copilot AI lite review requested due to automatic review settings September 23, 2026 13:16
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Sep 23, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-numerics
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

A moderate performance concern remains in the BigInteger widening-divide path and requires final human review.

Review effort: Lite
Findings: None

What changed in this PR

Optimizes wide integer and decimal division by reusing quotient/remainder results and widening-division intrinsics, with focused oracle-backed tests.

Changes:

  • Adds widening-division paths for Int128, BigInteger, and decimal arithmetic.
  • Reuses division results for remainder and rounding operations.
  • Adds boundary and randomized regression tests.
File Description
src/​tests/​JIT/​opt/​Add/​WideDivision.csproj Configures wide-division tests.
src/​tests/​JIT/​opt/​Add/​WideDivision.cs Tests integer, BigInteger, and decimal division.
src/​tests/​JIT/​opt/​Add/​DecimalWideDivision.csproj Configures IEEE decimal tests.
src/​tests/​JIT/​opt/​Add/​DecimalWideDivision.cs Tests wide power-of-ten division.
src/​libraries/​System.Private.CoreLib/​src/​System/​Numerics/​BigIntegerCalculator.Shared.cs Adds widening-divide fast paths and fallback reuse.
src/​libraries/​System.Private.CoreLib/​src/​System/​Number.DecimalIeee754.cs Adds full-limb IEEE decimal division.
src/​libraries/​System.Private.CoreLib/​src/​System/​Int128.cs Reuses unsigned division results for signed operations.
src/​libraries/​System.Private.CoreLib/​src/​System/​Decimal.DecCalc.cs Reuses widening division for decimal remainder and rounding.

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

area-System.Numerics community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants