Improve Math.BigMul performance on x64#117261
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
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
BigMulmethods for 32-, 64-, and pointer-size integers inX86Baseand their platform-not-supported stubs. - Updates
Math.BigMulto prefer the newX86Base.X64.BigMulpath on non-MONO x64, falling back as before. - Enhances JIT (linear scan, lowering, import, list, codegen, tree layout) to recognize and generate
BigMulintrinsics.
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 whenX86Base.X64.IsSupportedis true/false.
#if !MONO // X64.BigMul is not yet implemented in MONO
This was referenced Jul 3, 2025
Member
|
@EgorBo, PTAL. |
EgorBo
reviewed
Jul 31, 2025
Member
|
Rerunning failed test. |
EgorBo
reviewed
Jan 12, 2026
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>
- 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>
This was referenced May 3, 2026
EgorBo
enabled auto-merge (squash)
May 10, 2026 18:08
Contributor
Author
|
@EgorBo i think a flaky test is preventing your automerge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Feel free to close it if you prefer to work with the original PR