-
Notifications
You must be signed in to change notification settings - Fork 5.4k
[API Proposal]: Math.MulHigh #68207
Copy link
Copy link
Closed as not planned
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Numericsneeds-further-triageIssue has been initially triaged, but needs deeper consideration or reconsiderationIssue has been initially triaged, but needs deeper consideration or reconsideration
Milestone
Metadata
Metadata
Assignees
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Numericsneeds-further-triageIssue has been initially triaged, but needs deeper consideration or reconsiderationIssue has been initially triaged, but needs deeper consideration or reconsideration
Type
Fields
Give feedbackNo fields configured for issues without a type.
Background and motivation
On Arm64, there is already a
MultiplyHighintrinsic that returns only the high part of an integer multiply. On x86/x64,mulandimulcalculate the high part and low part at the same time can return the results in 2 registers, however there is no intrinsic that gives access to the high part of the result.At present, the only way to get the high part of an integer multiply on x86/x64 is to use
Math.BigMuland discard the low part of the result.BigMulis not currently optimized, although there is an open proposal for a multiply intrinsic that returns both halves of the result in a tuple #58263I would like to propose a cross-platform way of accessing this functionality, as
Math.MulHigh.API Proposal
API Usage
Alternative Designs
Most C compilers recognize a large multiply followed by a shift right as a smaller multiply high. Something like:
With the new
Int128type coming to .NET, this could be a possibililty.#58263 proposes a tuple-returning multiply that would return both halves of the result. It would be possible to simply ignore the lower half as long as JIT could optimize this.
Or
Math.BigMulcould be optimized to use mul/imul and JIT could be made to recognize a discard of the low part parameter of , such thatwould generate optimal code.
Risks
No response