Skip to content
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

Minor cleanups for System.Runtime.Numerics #53984

Merged
merged 10 commits into from
Aug 2, 2021

Conversation

huoyaoyuan
Copy link
Member

Mainly utilizing [^1] and BitOperations.

@ghost
Copy link

ghost commented Jun 10, 2021

Tagging subscribers to this area: @tannergooding, @pgovind
See info in area-owners.md if you want to be subscribed.

Issue Details

Mainly utilizing [^1] and BitOperations.

Author: huoyaoyuan
Assignees: -
Labels:

area-System.Numerics

Milestone: -

@MartyIX
Copy link
Contributor

MartyIX commented Jun 10, 2021

@huoyaoyuan Just out of curiosity: I understand what ^1 does but I'm not sure how it works under the hood. Is it transpiled to byteCount - 1 by Roslyn or is it supported by some IL instruction?

Sorry for off topic question. I hope you guys won't mind too much.

@huoyaoyuan
Copy link
Member Author

huoyaoyuan commented Jun 10, 2021

Yes. Roslyn will compose it. See sharplab

Roslyn will first find an indexer accepts System.Index. If not found, then it will find an integer indexer and a recognizable length property (it finds for Length and Count).

@@ -263,7 +263,7 @@ public BigInteger(ReadOnlySpan<byte> value, bool isUnsigned = false, bool isBigE
bool isNegative;
if (byteCount > 0)
{
byte mostSignificantByte = isBigEndian ? value[0] : value[byteCount - 1];
byte mostSignificantByte = isBigEndian ? value[0] : value[^1];
Copy link
Member

Choose a reason for hiding this comment

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

Does this impact codegen at all? I could imagine this being equivalent to value.Length - 1, which might result in a secondary read from memory.

Copy link
Member Author

Choose a reason for hiding this comment

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

Given the size of this method, I think 1 length load should be OK

Copy link
Member

Choose a reason for hiding this comment

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

Probably and for consistency, I'd just like to know if it is impactful at all, so we can more readily pin-point any changes in the perf issue triage.

Copy link
Member

@tannergooding tannergooding left a comment

Choose a reason for hiding this comment

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

CC. @pgovind can you review as well?

huoyaoyuan and others added 2 commits June 10, 2021 23:56
Co-authored-by: Tanner Gooding <tagoo@outlook.com>
Copy link

@pgovind pgovind left a comment

Choose a reason for hiding this comment

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

LGTM!

@tannergooding tannergooding added the api-approved API was approved in API review, it can be implemented label Jun 10, 2021
@tannergooding
Copy link
Member

tannergooding commented Jun 10, 2021

Video

Thanks for the cleanup here!

@tannergooding tannergooding removed the api-approved API was approved in API review, it can be implemented label Jun 11, 2021
@terrajobst terrajobst added the community-contribution Indicates that the PR has been added by a community member label Jul 19, 2021
@jeffhandley
Copy link
Member

As far as I can tell, this is ready to merge if the last leg turns green after re-running.

@pgovind I've assigned to you for follow-up before the RC1 snap, and I've restarted the leg.

@pgovind pgovind merged commit 65439de into dotnet:main Aug 2, 2021
@huoyaoyuan huoyaoyuan deleted the numerics-cleanup branch August 3, 2021 09:27
sakno added a commit to sakno/runtime that referenced this pull request Aug 5, 2021
tannergooding added a commit to tannergooding/runtime that referenced this pull request Aug 12, 2021
tannergooding added a commit that referenced this pull request Aug 12, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Sep 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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.

7 participants