-
Notifications
You must be signed in to change notification settings - Fork 5k
Improve Math.BigMul on x64 by adding new internal Multiply
hardware intrinsic to X86Base
#115966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Daniel-Svensson
wants to merge
20
commits into
dotnet:main
Choose a base branch
from
Daniel-Svensson:x86_multiply
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+237
−8
Draft
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
357995e
Improve BigMul to fix VarDecCmpSub regression #11243
Daniel-Svensson c0421a5
Fix typo
Daniel-Svensson 0921d91
Add multiply based on DivRem
Daniel-Svensson f61ea92
keep old behaviour on mono
Daniel-Svensson 8708639
Change Multiply to internal
Daniel-Svensson 41b2e1c
remove whitespace and remove some comments
Daniel-Svensson 82a0084
apply format.patch
Daniel-Svensson 0a1ea05
update PlatformNotSupported file
Daniel-Svensson 3b1560a
update #if
Daniel-Svensson 347ace2
#if MONO
Daniel-Svensson b184829
add back unsafe for mono
Daniel-Svensson 8bbfdaa
react to upstream changes
Daniel-Svensson 2f0f838
add assert
Daniel-Svensson de48455
merge upsteram/main Fix conflicts
Daniel-Svensson 598e790
rename Multiply to BigMul to handle name collision due to renamed to …
Daniel-Svensson 21c3310
lookupIns has changed signature
Daniel-Svensson 1564ecf
Rename Multiply methods to BigMul in `X86Base.PlatformNotSupported.cs`.
Daniel-Svensson 12758de
Emit mulx for X86Base.Multiply when supported
Daniel-Svensson dedc015
merge upstream/main
Daniel-Svensson 4ef7494
Updates:
Daniel-Svensson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2481,6 +2481,51 @@ int LinearScan::BuildHWIntrinsic(GenTreeHWIntrinsic* intrinsicTree, int* pDstCou | |
break; | ||
} | ||
|
||
case NI_X86Base_BigMul: | ||
case NI_X86Base_X64_BigMul: | ||
{ | ||
assert(numArgs == 2); | ||
assert(dstCount == 2); | ||
assert(isRMW); | ||
|
||
if ((baseType == TYP_ULONG || baseType == TYP_UINT) && | ||
compiler->compOpportunisticallyDependsOn(InstructionSet_AVX2)) | ||
{ | ||
isRMW = false; | ||
|
||
SingleTypeRegSet apxAwareRegCandidates = | ||
ForceLowGprForApxIfNeeded(op2, RBM_NONE, canHWIntrinsicUseApxRegs); | ||
// mulx, prefer op1 in EDX | ||
SingleTypeRegSet op1RegCandidates = op2->isContained() ? SRBM_EDX : apxAwareRegCandidates; | ||
srcCount = BuildOperandUses(op1, op1RegCandidates); | ||
srcCount += BuildOperandUses(op2, apxAwareRegCandidates); | ||
|
||
// result in any register | ||
SingleTypeRegSet apxAwareDestCandidates = | ||
ForceLowGprForApxIfNeeded(intrinsicTree, RBM_NONE, canHWIntrinsicUseApxRegs); | ||
BuildDef(intrinsicTree, apxAwareDestCandidates, 0); | ||
BuildDef(intrinsicTree, apxAwareDestCandidates, 1); | ||
} | ||
else // Signed multiply or normal unsigned multiply in one operand form | ||
{ | ||
SingleTypeRegSet apxAwareRegCandidates = | ||
ForceLowGprForApxIfNeeded(op2, RBM_NONE, canHWIntrinsicUseApxRegs); | ||
|
||
// mulEAX always use EAX, if one operand is contained, we use EAX as the target reg | ||
// if not then we do not fix it, we might get the second parameter in EAX | ||
SingleTypeRegSet op1RegCandidates = op2->isContained() ? SRBM_EAX : apxAwareRegCandidates; | ||
srcCount = BuildOperandUses(op1, op1RegCandidates); | ||
srcCount += BuildOperandUses(op2, apxAwareRegCandidates); | ||
|
||
// result put in EAX and EDX | ||
BuildDef(intrinsicTree, SRBM_EAX, 0); | ||
BuildDef(intrinsicTree, SRBM_EDX, 1); | ||
} | ||
|
||
buildUses = false; | ||
break; | ||
} | ||
|
||
case NI_AVX2_MultiplyNoFlags: | ||
case NI_AVX2_X64_MultiplyNoFlags: | ||
{ | ||
|
@@ -2999,9 +3044,11 @@ int LinearScan::BuildHWIntrinsic(GenTreeHWIntrinsic* intrinsicTree, int* pDstCou | |
} | ||
else | ||
{ | ||
// Currently dstCount = 2 is only used for DivRem, which has special constraints and is handled above | ||
// Currently dstCount = 2 is only used for DivRem and Multiply, which has special constraints and is handled | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Multiply is renamed to BigMul, can update comment later after review |
||
// above | ||
assert((dstCount == 0) || | ||
((dstCount == 2) && ((intrinsicId == NI_X86Base_DivRem) || (intrinsicId == NI_X86Base_X64_DivRem)))); | ||
((dstCount == 2) && ((intrinsicId == NI_X86Base_DivRem) || (intrinsicId == NI_X86Base_X64_DivRem) || | ||
(intrinsicId == NI_X86Base_BigMul) || (intrinsicId == NI_X86Base_X64_BigMul)))); | ||
} | ||
|
||
*pDstCount = dstCount; | ||
|
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.