Skip to content

Conversation

@huoyaoyuan
Copy link
Member

Mainly utilizing [^1] and BitOperations.

@ghost ghost added the area-System.Numerics label Jun 10, 2021
@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).

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?

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