Skip to content

[API Proposal]: Expose System.Runtime.Intrinsics.X86.Aes256 and Aes512 #86952

Open

Description

@e4m2

Background and motivation

On some newer x86 CPUs VAES provides wider variants of encoding/decoding included in the older AES instruction set.

The 256-bit VEX-encoded variant (effectively operating on 2 AES blocks in parallel using a single instruction) has a separate CPUID flag and is not dependent on AVX512 support. Additionally, if AVX512F is supported, a 512-bit EVEX-encoded variant is available. As expected, EVEX-encoded 128 and 256-bit variants are available if AVX512VL is supported.

API Proposal

namespace System.Runtime.Intrinsics.X86;

[Intrinsic]
[CLSCompliant(false)]
public abstract class Aes256 : Aes
{
    internal Aes256() { }

    // This would depend on the VAES CPUID bit for VEX encoding and VAES + AVX512VL for EVEX
    public static new bool IsSupported { get => IsSupported; }

    [Intrinsic]
    public new abstract class X64 : Aes.X64
    {
        internal X64() { }

        public static new bool IsSupported { get => IsSupported; }
    }

    /// <summary>
    /// __m256i _mm256_aesdec_epi128(__m256i a, __m256i RoundKey)
    ///   VAESDEC ymm1, ymm2, ymm3/m256
    /// </summary>
    public static Vector256<byte> Decrypt(Vector256<byte> value, Vector256<byte> roundKey);

    /// <summary>
    /// __m256i _mm256_aesdeclast_epi128(__m256i a, __m256i RoundKey)
    ///   VAESDECLAST ymm1, ymm2, ymm3/m256
    /// </summary>
    public static Vector256<byte> DecryptLast(Vector256<byte> value, Vector256<byte> roundKey);

    /// <summary>
    /// __m256i _mm256_aesenc_epi128(__m256i a, __m256i RoundKey)
    ///   VAESENC ymm1, ymm2, ymm3/m256
    /// </summary>
    public static Vector256<byte> Encrypt(Vector256<byte> value, Vector256<byte> roundKey);
    
    /// <summary>
    /// __m256i _mm256_aesenclast_epi128(__m256i a, __m256i RoundKey)
    ///   VAESENCLAST ymm1, ymm2, ymm3/m256
    /// </summary>
    public static Vector256<byte> EncryptLast(Vector256<byte> value, Vector256<byte> roundKey);
}

[Intrinsic]
[CLSCompliant(false)]
public abstract class Aes512 : Aes
{
    internal Aes512() { }

    // This would depend on the VAES + AVX512F CPUID bits
    public static new bool IsSupported { get => IsSupported; }

    [Intrinsic]
    public new abstract class X64 : Aes.X64
    {
        internal X64() { }

        public static new bool IsSupported { get => IsSupported; }
    }
    
    /// <summary>
    /// __m512i _mm512_aesdec_epi128(__m512i a, __m512i RoundKey)
    ///   VAESDEC zmm1, zmm2, zmm3/m512
    /// </summary>
    public static Vector512<byte> Decrypt(Vector512<byte> value, Vector512<byte> roundKey);
    
    /// <summary>
    /// __m512i _mm512_aesdeclast_epi128(__m512i a, __m512i RoundKey)
    ///   VAESDECLAST zmm1, zmm2, zmm3/m512
    /// </summary>
    public static Vector512<byte> DecryptLast(Vector512<byte> value, Vector512<byte> roundKey);

    /// <summary>
    /// __m512i _mm512_aesenc_epi128(__m512i a, __m512i RoundKey)
    ///   VAESENC zmm1, zmm2, zmm3/m512
    /// </summary>
    public static Vector512<byte> Encrypt(Vector512<byte> value, Vector512<byte> roundKey);

    /// <summary>
    /// __m512i _mm512_aesenclast_epi128(__m512i a, __m512i RoundKey)
    ///   VAESENCLAST zmm1, zmm2, zmm3/m512
    /// </summary>
    public static Vector512<byte> EncryptLast(Vector512<byte> value, Vector512<byte> roundKey);
}

Note VAES doesn't include round key assist or inverse mix columns instructions.

API Usage

Same as AES intrinsics, except using wider vector types.

Alternative Designs

No response

Risks

No response

References

https://en.wikichip.org/wiki/x86/vaes
https://en.wikipedia.org/wiki/AVX-512#VAES
https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#othertechs=VAES

Activity

  1. added
    api-suggestion
    on May 31, 2023
  2. ghost added
    untriaged
    on May 31, 2023
  3. MichalPetryka commented on Jun 10, 2023

    @MichalPetryka
    Contributor
        public new abstract class VL : Avx512F.VL
        {
            public static new bool IsSupported { get; }
    
            public static Vector128<byte> Decrypt(Vector128<byte> value, Vector128<byte> roundKey);
            public static Vector128<byte> DecryptLast(Vector128<byte> value, Vector128<byte> roundKey);
    
            public static Vector256<byte> Encrypt(Vector256<byte> value, Vector256<byte> roundKey);
            public static Vector256<byte> EncryptLast(Vector256<byte> value, Vector256<byte> roundKey);
        }

    What's the benefit of exposing the EVEX variants separately?

  4. colejohnson66 commented on Feb 8, 2024

    @colejohnson66
    Contributor

    Technically, VAES and AVX512-F only indicate 512-bit operation; AVX512-VL is required to use 128-bit and 256-bit vectors, hence the dedicated subclass. If you're asking why they exist when the VEX forms exist, it's probably just to allow the user to choose which prefix to use, or for consistency.

  5. tannergooding commented on Feb 8, 2024

    @tannergooding
    Member

    If you're asking why they exist when the VEX forms exist, it's probably just to allow the user to choose which prefix to use, or for consistency.

    Users don't get to pick the prefix, the JIT picks based on the most optimal form. For V512, it's required to use EVEX. For V128/V256 it will pick VEX if only the lower 16 SIMD registers are used. If LSRA must allocate an extended SIMD register (one of the upper 16) or decides that it can take advantage of another EVEX only feature such as embedded broadcast or embedded masking, then it may use EVEX instead (assuming the hardware is capable of course).

    We intentionally do not duplicate APIs needlessly, and so we shouldn't need them under Avx512Vaes.VL


    Given that, given the future for Avx10, and given what we had previously opted for with VPCLMULQDQ (#95772), we should likely name these Aes256 and Aes512, respectively.

    However, depending on how we decide to do Avx10, it may be "better" to have these in nested V256/V512 classes under Aes and Pclmulqdq instead.

  6. tannergooding commented on Feb 8, 2024

    @tannergooding
    Member

    @e4m2, could you update to follow the same general pattern as Pclmulqdq for now and then I can get this reviewed after or as part of the Avx10 work, at which point we'll know the desired pattern?

  7. changed the title [-][API Proposal]: Expose System.Runtime.Intrinsics.X86.Vaes and Avx512Vaes[/-] [+][API Proposal]: Expose System.Runtime.Intrinsics.X86.Aes256 and Aes512[/+] on Feb 8, 2024
  8. e4m2 commented on Feb 8, 2024

    @e4m2
    Author

    Thanks for the input. Updated!

  9. added
    api-ready-for-review
    and removed
    api-suggestion
    untriaged
    on Feb 8, 2024
  10. terrajobst commented on Feb 29, 2024

    @terrajobst
    Contributor

    Video

    • Looks good as proposed, we opted to change the surface area slightly to match the approach approved for Avx10 where we have a nested V256 and V512 class
    namespace System.Runtime.Intrinsics.X86;
    
    public abstract class Aes
    {
        public abstract class V256
        {
            public static new bool IsSupported { get; }
    
            public static Vector256<byte> Decrypt(Vector256<byte> value, Vector256<byte> roundKey);
            public static Vector256<byte> DecryptLast(Vector256<byte> value, Vector256<byte> roundKey);
            public static Vector256<byte> Encrypt(Vector256<byte> value, Vector256<byte> roundKey);   
            public static Vector256<byte> EncryptLast(Vector256<byte> value, Vector256<byte> roundKey);
        }
    
        public abstract class V512
        {
            public static Vector512<byte> Decrypt(Vector512<byte> value, Vector512<byte> roundKey);   
            public static Vector512<byte> DecryptLast(Vector512<byte> value, Vector512<byte> roundKey);
            public static Vector512<byte> Encrypt(Vector512<byte> value, Vector512<byte> roundKey);
            public static Vector512<byte> EncryptLast(Vector512<byte> value, Vector512<byte> roundKey);
        }
    }
  11. added
    api-approved
    and removed
    api-ready-for-review
    on Feb 29, 2024
  12. added this to the 10.0.0 milestone on Jul 19, 2024
  13. modified the milestones: 10.0.0, Future on Jul 14, 2025
  14. jamesburton commented on Aug 11, 2026

    @jamesburton
    Contributor

    Hi @tannergooding — I'd be glad to take this one on as well. From a quick look the instruction-set scaffolding is partly in place (the Aes_V256/Aes_V512 sets already exist), though it looks like the EVEX-512 VAES encodings would still need wiring up in the emitter — so a little more involved than a pure ISA-exposure PR, but very doable.

    Before I start: is the Feb-2024 api-approved shape (Aes256/Aes512 with the nested V256/V512 pattern) still current? If so I'll get going. I can validate on Zen 5 (VAES + AVX-512).

  15. HMBSbige commented on Nov 16, 2026

    @HMBSbige

    @tannergooding In the approved shape, V512 has no IsSupported, and V256.IsSupported still has the new from Aes256 : Aes. Both look like leftovers from the edit to the nested form; the earlier revision had IsSupported on both. Should it be:

    namespace System.Runtime.Intrinsics.X86;
    
    public abstract class Aes
    {
        public abstract class V256
        {
            public static bool IsSupported { get; }
    
            public static Vector256<byte> Decrypt(Vector256<byte> value, Vector256<byte> roundKey);
            public static Vector256<byte> DecryptLast(Vector256<byte> value, Vector256<byte> roundKey);
            public static Vector256<byte> Encrypt(Vector256<byte> value, Vector256<byte> roundKey);
            public static Vector256<byte> EncryptLast(Vector256<byte> value, Vector256<byte> roundKey);
        }
    
        public abstract class V512
        {
            public static bool IsSupported { get; }
    
            public static Vector512<byte> Decrypt(Vector512<byte> value, Vector512<byte> roundKey);
            public static Vector512<byte> DecryptLast(Vector512<byte> value, Vector512<byte> roundKey);
            public static Vector512<byte> Encrypt(Vector512<byte> value, Vector512<byte> roundKey);
            public static Vector512<byte> EncryptLast(Vector512<byte> value, Vector512<byte> roundKey);
        }
    }

    @jamesburton, are you still planning to work on this? If not, I'd like to take it.

  16. jamesburton commented on Nov 20, 2026

    @jamesburton
    Contributor

    Hi @HMBSbige, thanks for the check. Yes, I'm still working on this and would like to keep it.

    The implementation is done locally and validated on Zen 5 (VAES + AVX-512): the JIT wiring for VAES under EVEX (the four aes* rows in instrsxarch.h), the Aes.V256 / Aes.V512 nested classes in CoreLib, the ref assembly, the PlatformNotSupported stubs, and generated HWIntrinsic tests with known-answer vectors. The 256-bit and 512-bit results were checked lane by lane against the existing 128-bit Aes intrinsics, and the X86 HWIntrinsics suite passes in full.

    On the shape: what I built matches your suggestion, with IsSupported on both V256 and V512 and no new on either, since neither nested class derives from Aes.

    @tannergooding, could you confirm that is the intended shape, i.e. that the new on V256.IsSupported and the missing V512.IsSupported in the approved text were leftovers from the edit? If so I'll open the PR against main (now 12.0) as soon as that's settled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-approvedarea-System.Runtime.Intrinsics

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions