Skip to content

[API Implementation]: Support for Intel SHA extensions - #62999

Closed
deeprobin wants to merge 53 commits into
dotnet:mainfrom
deeprobin:issue-256
Closed

[API Implementation]: Support for Intel SHA extensions#62999
deeprobin wants to merge 53 commits into
dotnet:mainfrom
deeprobin:issue-256

Conversation

@deeprobin

@deeprobindeeprobin commented Dec 19, 2021

Copy link
Copy Markdown
Contributor

Proposal implementation of #256 (closes#256)

Proposal

namespaceSystem.Runtime.Intrinsics.X86{publicabstractclassSha:Sse2{publicabstractclassX64:Sse2.X64{publicstaticboolIsSupported{get;}}publicstaticboolIsSupported{get;}publicstaticVector128<byte>Sha1MessageSchedule1(Vector128<byte>a,Vector128<byte>b);publicstaticVector128<byte>Sha1MessageSchedule2(Vector128<byte>a,Vector128<byte>b);publicstaticVector128<byte>Sha1NextE(Vector128<byte>a,Vector128<byte>b);publicstaticVector128<byte>Sha1FourRounds(Vector128<byte>state1,Vector128<byte>state2,bytefunc);publicstaticVector128<byte>Sha256MessageSchedule1(Vector128<byte>a,Vector128<byte>b);publicstaticVector128<byte>Sha256MessageSchedule2(Vector128<byte>a,Vector128<byte>b);publicstaticVector128<byte>Sha256TwoRounds(Vector128<byte>state1,Vector128<byte>state2,Vector128<byte>message);}}

Current state of implementation

Used intrinsics

  • Sha1
    • Sha1MessageSchedule1 – __m128i _mm_sha1msg1_epu32 (__m128i a, __m128i b)
    • Sha1MessageSchedule2 – __m128i _mm_sha1msg2_epu32 (__m128i a, __m128i b)
    • Sha1NextE – __m128i _mm_sha1nexte_epu32 (__m128i a, __m128i b)
    • Sha1FourRounds – __m128i _mm_sha1rnds4_epu32 (__m128i a, __m128i b, const int func)
  • Sha256
    • Sha256MessageSchedule1 – __m128i _mm_sha256msg1_epu32 (__m128i a, __m128i b)
    • Sha256MessageSchedule2 – __m128i _mm_sha256msg2_epu32 (__m128i a, __m128i b)
    • Sha256TwoRounds – __m128i _mm_sha256rnds2_epu32 (__m128i a, __m128i b, __m128i k)

/cc @tannergooding

@ghost

Copy link
Copy Markdown

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost

Copy link
Copy Markdown

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@ghostghost added the community-contribution Indicates that the PR has been added by a community member label Dec 19, 2021
@deeprobin
deeprobin marked this pull request as ready for review December 19, 2021 20:28
@ghost

Copy link
Copy Markdown

Tagging subscribers to this area: @dotnet/area-system-runtime-intrinsics
See info in area-owners.md if you want to be subscribed.

Issue Details

Proposal implementation of #256 (closes #256)

Proposal

namespaceSystem.Runtime.Intrinsics.X86{publicclassSha1{publicstaticboolIsSupported{get;}publicstaticVector128<byte>MessageSchedule1(Vector128<byte>a,Vector128<byte>b);publicstaticVector128<byte>MessageSchedule2(Vector128<byte>a,Vector128<byte>b);publicstaticVector128<byte>NextE(Vector128<byte>a,Vector128<byte>b);publicstaticVector128<byte>FourRounds(Vector128<byte>a,Vector128<byte>b,bytefunc);}publicclassSha256{publicstaticboolIsSupported{get;}publicstaticVector128<byte>MessageSchedule1(Vector128<byte>a,Vector128<byte>b);publicstaticVector128<byte>MessageSchedule2(Vector128<byte>a,Vector128<byte>b);publicstaticVector128<byte>TwoRounds(Vector128<byte>a,Vector128<byte>b,Vector128<byte>k);}}

Current state of implementation

  • C++ CodeGen (JIT / NativeAOT) implementation (@tannergooding is this already implemented?)
  • C# Implementation
    • Ref Assembly
    • Intrinsic Implementation
  • Good documentation (suggestions?)

Used intrinsics

  • Sha1
    • MessageSchedule1 – __m128i _mm_sha1msg1_epu32 (__m128i a, __m128i b)
    • MessageSchedule2 – __m128i _mm_sha1msg2_epu32 (__m128i a, __m128i b)
    • NextE – __m128i _mm_sha1nexte_epu32 (__m128i a, __m128i b)
    • FourRounds – __m128i _mm_sha1rnds4_epu32 (__m128i a, __m128i b, const int func)
  • Sha256
    • MessageSchedule1 – __m128i _mm_sha256msg1_epu32 (__m128i a, __m128i b)
    • MessageSchedule2 – __m128i _mm_sha256msg2_epu32 (__m128i a, __m128i b)
    • TwoRounds – __m128i _mm_sha256rnds2_epu32 (__m128i a, __m128i b, __m128i k)

Tests

I think including tests for this is not relevant, since we trust the processor to execute the intrinsics correctly (there are only vector tests in System.Runtime.Intrinsics anyway).

/cc @tannergooding

Author:deeprobin
Assignees:-
Labels:

area-System.Runtime.Intrinsics, new-api-needs-documentation, community-contribution

Milestone:-

@deeprobin

deeprobin commented Dec 20, 2021

Copy link
Copy Markdown
ContributorAuthor

I'm working on the JIT implementation for these intrinsics (see deeprobin#3). Happy to review 😄

@tannergooding

Copy link
Copy Markdown
Member

I'm working on the JIT implementation for these intrinsics

Please let us know if you need any assistance here. There are a number of steps required to support new ISAs and you'll need to touch code in both the JIT and VM.

@deeprobin

deeprobin commented Jan 3, 2022

Copy link
Copy Markdown
ContributorAuthor

Please let us know if you need any assistance here. There are a number of steps required to support new ISAs and you'll need to touch code in both the JIT and VM.

Yes, I need some assistance.

Thats my current JIT change: deeprobin#3
I know that not everything will be right yet. However, it would be nice if you help me there a bit 😃 (What's missing, what's not quite right, ...).

* JIT implementation for SHA instructions
* Fix flags
* Add `cpuid` check for SHA (29th bit)
* Add EnableSHA config value
* Add incomplete CodeGen method called `genSHAIntrinsic`
Comment threadsrc/coreclr/jit/hwintrinsiccodegenxarch.cpp Outdated
Comment threadsrc/coreclr/jit/hwintrinsiccodegenxarch.cpp Outdated
@deeprobin
deeprobin marked this pull request as draft February 13, 2022 18:37
@ghostghost closed this Mar 15, 2022
@ghost

Copy link
Copy Markdown

Draft Pull Request was automatically closed for inactivity. Please let us know if you'd like to reopen it.

@deeprobin

Copy link
Copy Markdown
ContributorAuthor

@tannergooding This was auto-closed. As soon as you have time to look at the bug in the wrong SHA encoding, feel free to reopen the PR :)

@ghostghost locked as resolved and limited conversation to collaborators Apr 15, 2022
This pull request was closed.
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Runtime.Intrinsicscommunity-contributionIndicates that the PR has been added by a community membernew-api-needs-documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for Intel SHA extensions

4 participants

@deeprobin@tannergooding@MichalStrehovsky@SingleAccretion