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

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

Closed
wants to merge 53 commits into from

Conversation

deeprobin
Copy link
Contributor

@deeprobin deeprobin commented Dec 19, 2021

Proposal implementation of #256 (closes #256)

Proposal

namespace System.Runtime.Intrinsics.X86
{
    public abstract class Sha : Sse2
    {
       public abstract class X64 : Sse2.X64
       {
          public static bool IsSupported { get; }
       }

        public static bool IsSupported { get; }
        public static Vector128<byte> Sha1MessageSchedule1(Vector128<byte> a, Vector128<byte> b);
        public static Vector128<byte> Sha1MessageSchedule2(Vector128<byte> a, Vector128<byte> b);
        public static Vector128<byte> Sha1NextE(Vector128<byte> a, Vector128<byte> b);
        public static Vector128<byte> Sha1FourRounds(Vector128<byte> state1, Vector128<byte> state2, byte func);
        public static Vector128<byte> Sha256MessageSchedule1(Vector128<byte> a, Vector128<byte> b);
        public static Vector128<byte> Sha256MessageSchedule2(Vector128<byte> a, Vector128<byte> b);
        public static Vector128<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

@dotnet-issue-labeler
Copy link

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.

@dotnet-issue-labeler
Copy link

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.

@ghost ghost 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

ghost commented Dec 19, 2021

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

namespace System.Runtime.Intrinsics.X86
{
    public class Sha1
    {
        public static bool IsSupported { get; }
        public static Vector128<byte> MessageSchedule1(Vector128<byte> a, Vector128<byte> b);
        public static Vector128<byte> MessageSchedule2(Vector128<byte> a, Vector128<byte> b);
        public static Vector128<byte> NextE(Vector128<byte> a, Vector128<byte> b);
        public static Vector128<byte> FourRounds(Vector128<byte> a, Vector128<byte> b, byte func);
    }

    public class Sha256
    {
        public static bool IsSupported { get; }
        public static Vector128<byte> MessageSchedule1(Vector128<byte> a, Vector128<byte> b);
        public static Vector128<byte> MessageSchedule2(Vector128<byte> a, Vector128<byte> b);
        public static Vector128<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
Copy link
Contributor Author

deeprobin commented Dec 20, 2021

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

@tannergooding
Copy link
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
Copy link
Contributor Author

deeprobin commented Jan 3, 2022

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`
@deeprobin deeprobin marked this pull request as draft February 13, 2022 18:37
@ghost ghost closed this Mar 15, 2022
@ghost
Copy link

ghost commented Mar 15, 2022

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

@deeprobin
Copy link
Contributor Author

@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 :)

@ghost ghost locked as resolved and limited conversation to collaborators Apr 15, 2022
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Runtime.Intrinsics community-contribution Indicates that the PR has been added by a community member new-api-needs-documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for Intel SHA extensions
4 participants