Skip to content

Improve Math.BigMul performance on x64#117261

Merged
EgorBo merged 21 commits into
dotnet:mainfrom
Daniel-Svensson:x86_bigmul
May 21, 2026
Merged

Improve Math.BigMul performance on x64#117261
EgorBo merged 21 commits into
dotnet:mainfrom
Daniel-Svensson:x86_bigmul

Conversation

@Daniel-Svensson

Copy link
Copy Markdown
Contributor

This #115966 but without the mulx support.
See the old PR for benchmarks results and generated code

The reason for opening a separate PR is

  • Rerun all tests without the mulx code to increase confident that it works on non-AVX2 hardware
  • Make it easy for the team pick only this specific part of the PR (in case it makes review, benchmarks follow up or similar easier)

Feel free to close it if you prefer to work with the original PR

Copilot AI review requested due to automatic review settings July 3, 2025 09:36
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jul 3, 2025
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Jul 3, 2025

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.

Pull Request Overview

This PR backports the Math.BigMul hardware intrinsic support on x64 without the mulx instruction extension. It adds new BigMul overloads in the X86Base APIs, hooks them into Math.BigMul, and extends the JIT to lower, schedule, and codegen these multi-register intrinsics.

  • Introduces BigMul methods for 32-, 64-, and pointer-size integers in X86Base and their platform-not-supported stubs.
  • Updates Math.BigMul to prefer the new X86Base.X64.BigMul path on non-MONO x64, falling back as before.
  • Enhances JIT (linear scan, lowering, import, list, codegen, tree layout) to recognize and generate BigMul intrinsics.

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/System.Private.CoreLib/src/System/Runtime/Intrinsics/X86/X86Base.cs Added BigMul intrinsics for various operand widths
src/System.Private.CoreLib/src/System/Runtime/Intrinsics/X86/X86Base.PlatformNotSupported.cs Added BigMul stubs throwing on unsupported platforms
src/System.Private.CoreLib/src/System/Math.cs Routed Math.BigMul to use the new intrinsics on x64
src/coreclr/jit/lsraxarch.cpp Updated register allocator for BigMul multi-reg defs
src/coreclr/jit/lowerxarch.cpp Enabled containment checks for BigMul
src/coreclr/jit/hwintrinsicxarch.cpp Imported BigMul as a multi-register HW intrinsic
src/coreclr/jit/hwintrinsiclistxarch.h Listed BigMul in the x86 and x64 HW intrinsic tables
src/coreclr/jit/hwintrinsiccodegenxarch.cpp Emitting MUL/IMUL sequence for BigMul
src/coreclr/jit/hwintrinsic.h Updated multi-reg return count for BigMul
src/coreclr/jit/gentree.cpp Defined struct layout for BigMul return
Comments suppressed due to low confidence (3)

src/libraries/System.Private.CoreLib/src/System/Math.cs:205

  • Consider adding unit tests that validate the new Math.BigMul(ulong, ulong, out ulong) path on x64 and ensure correct behavior when X86Base.X64.IsSupported is true/false.
#if !MONO // X64.BigMul is not yet implemented in MONO

@JulieLeeMSFT

Copy link
Copy Markdown
Member

@EgorBo, PTAL.

Comment thread src/coreclr/jit/hwintrinsiccodegenxarch.cpp
@JulieLeeMSFT

Copy link
Copy Markdown
Member

Rerunning failed test.

@EgorBo

EgorBo commented Feb 23, 2026

Copy link
Copy Markdown
Member

Sorry for the slow feedback loop, I think it's looking good, let's see what CI thinks

The test file was added under Shared/ which is reserved for templates and
helpers, and was not referenced by any csproj, so the tests never ran.
Move it into X86Base.X64/ and include it from the _r and _ro csprojs.
Also hook the previously unreferenced TestOutParameterConsistency and
TestPropertyInputs methods into TestEntryPoint.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 3, 2026 12:23

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.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Comment thread src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/X86/X86Base.cs Outdated
Comment thread src/libraries/System.Private.CoreLib/src/System/Math.cs Outdated
Comment thread src/coreclr/jit/lsraxarch.cpp Outdated
Comment thread src/coreclr/jit/lsraxarch.cpp Outdated
- Math.cs: clarify Bmi2.X64.MultiplyNoFlags vs X86Base.X64.BigMul reference and use full GH issue link for dotnet#11782

- X86Base.cs: fix MULX wording and add terminating period

- lsraxarch.cpp: fix grammar in BigMul LSRA comment (uses, don't)

- lsraxarch.cpp: fix grammar in dstCount=2 assert comment (have/are)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 4, 2026 12:12

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.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.

@EgorBo
EgorBo enabled auto-merge (squash) May 10, 2026 18:08
@Daniel-Svensson

Copy link
Copy Markdown
Contributor Author

@EgorBo i think a flaky test is preventing your automerge

Copilot AI review requested due to automatic review settings May 20, 2026 20:25

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.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Comment thread src/tests/JIT/HardwareIntrinsics/X86/X86Base.X64/BigMul.cs
Comment thread src/tests/JIT/HardwareIntrinsics/X86/X86Base.X64/BigMul.cs
Comment thread src/tests/JIT/HardwareIntrinsics/X86/X86Base.X64/BigMul.cs
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI 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.

4 participants