Repository navigation
Description
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
MichalPetryka commentedon Jun 10, 2023
What's the benefit of exposing the EVEX variants separately?
colejohnson66 commentedon Feb 8, 2024
Technically,
VAESandAVX512-Fonly indicate 512-bit operation;AVX512-VLis 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.tannergooding commentedon Feb 8, 2024
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 broadcastorembedded 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.VLGiven that, given the future for Avx10, and given what we had previously opted for with
VPCLMULQDQ(#95772), we should likely name theseAes256andAes512, respectively.However, depending on how we decide to do
Avx10, it may be "better" to have these in nestedV256/V512classes underAesandPclmulqdqinstead.tannergooding commentedon Feb 8, 2024
@e4m2, could you update to follow the same general pattern as
Pclmulqdqfor now and then I can get this reviewed after or as part of theAvx10work, at which point we'll know the desired pattern?[-][API Proposal]: Expose System.Runtime.Intrinsics.X86.Vaes and Avx512Vaes[/-][+][API Proposal]: Expose System.Runtime.Intrinsics.X86.Aes256 and Aes512[/+]e4m2 commentedon Feb 8, 2024
Thanks for the input. Updated!
terrajobst commentedon Feb 29, 2024
Video
jamesburton commentedon Aug 11, 2026
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_V512sets 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/Aes512with the nested V256/V512 pattern) still current? If so I'll get going. I can validate on Zen 5 (VAES + AVX-512).HMBSbige commentedon Nov 16, 2026
@tannergooding In the approved shape,
V512has noIsSupported, andV256.IsSupportedstill has thenewfromAes256 : Aes. Both look like leftovers from the edit to the nested form; the earlier revision hadIsSupportedon both. Should it be:@jamesburton, are you still planning to work on this? If not, I'd like to take it.
jamesburton commentedon Nov 20, 2026
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 ininstrsxarch.h), theAes.V256/Aes.V512nested 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-bitAesintrinsics, and the X86 HWIntrinsics suite passes in full.On the shape: what I built matches your suggestion, with
IsSupportedon bothV256andV512and nonewon either, since neither nested class derives fromAes.@tannergooding, could you confirm that is the intended shape, i.e. that the
newonV256.IsSupportedand the missingV512.IsSupportedin 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.