native 0.0.1
Vectors, masks and wide register packs for C++26
Loading...
Searching...
No Matches
vaes.h
1// SPDX-License-Identifier: BSD-2-Clause OR Apache-2.0
2#pragma once
3
4#include "native/config.h"
5#include <hint.h>
6#include "native/isa.h"
7#if NATIVE_HOST_X86
8#include <immintrin.h>
9
10namespace native::detail::x86_vaes {
11 template<isa<x86> Arch> requires(Arch.has(x86_feature::aes) && Arch.has(x86_feature::avx))
12 [[nodiscard]] hint_inline hint_const hint_target("avx,aes")
13 __m128i vaesenc(__m128i state, __m128i key) noexcept {
14 return _mm_aesenc_si128(state, key);
15 }
16
17 template<isa<x86> Arch> requires(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx))
18 [[nodiscard]] hint_inline hint_const hint_target("avx,vaes")
19 __m256i vaesenc(__m256i state, __m256i key) noexcept {
20 return _mm256_aesenc_epi128(state, key);
21 }
22
23 template<isa<x86> Arch> requires(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx512f))
24 [[nodiscard]] hint_inline hint_const hint_target("avx512f,vaes")
25 __m512i vaesenc(__m512i state, __m512i key) noexcept {
26 return _mm512_aesenc_epi128(state, key);
27 }
28
29 template<isa<x86> Arch, class... Args>
30 void vaesenc(Args...) = delete;
31
32 template<isa<x86> Arch> requires(Arch.has(x86_feature::aes) && Arch.has(x86_feature::avx))
33 [[nodiscard]] hint_inline hint_const hint_target("avx,aes")
34 __m128i vaesenclast(__m128i state, __m128i key) noexcept {
35 return _mm_aesenclast_si128(state, key);
36 }
37
38 template<isa<x86> Arch> requires(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx))
39 [[nodiscard]] hint_inline hint_const hint_target("avx,vaes")
40 __m256i vaesenclast(__m256i state, __m256i key) noexcept {
41 return _mm256_aesenclast_epi128(state, key);
42 }
43
44 template<isa<x86> Arch> requires(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx512f))
45 [[nodiscard]] hint_inline hint_const hint_target("avx512f,vaes")
46 __m512i vaesenclast(__m512i state, __m512i key) noexcept {
47 return _mm512_aesenclast_epi128(state, key);
48 }
49
50 template<isa<x86> Arch, class... Args>
51 void vaesenclast(Args...) = delete;
52
53 template<isa<x86> Arch> requires(Arch.has(x86_feature::aes) && Arch.has(x86_feature::avx))
54 [[nodiscard]] hint_inline hint_const hint_target("avx,aes")
55 __m128i vaesdec(__m128i state, __m128i key) noexcept {
56 return _mm_aesdec_si128(state, key);
57 }
58
59 template<isa<x86> Arch> requires(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx))
60 [[nodiscard]] hint_inline hint_const hint_target("avx,vaes")
61 __m256i vaesdec(__m256i state, __m256i key) noexcept {
62 return _mm256_aesdec_epi128(state, key);
63 }
64
65 template<isa<x86> Arch> requires(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx512f))
66 [[nodiscard]] hint_inline hint_const hint_target("avx512f,vaes")
67 __m512i vaesdec(__m512i state, __m512i key) noexcept {
68 return _mm512_aesdec_epi128(state, key);
69 }
70
71 template<isa<x86> Arch, class... Args>
72 void vaesdec(Args...) = delete;
73
74 template<isa<x86> Arch> requires(Arch.has(x86_feature::aes) && Arch.has(x86_feature::avx))
75 [[nodiscard]] hint_inline hint_const hint_target("avx,aes")
76 __m128i vaesdeclast(__m128i state, __m128i key) noexcept {
77 return _mm_aesdeclast_si128(state, key);
78 }
79
80 template<isa<x86> Arch> requires(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx))
81 [[nodiscard]] hint_inline hint_const hint_target("avx,vaes")
82 __m256i vaesdeclast(__m256i state, __m256i key) noexcept {
83 return _mm256_aesdeclast_epi128(state, key);
84 }
85
86 template<isa<x86> Arch> requires(Arch.has(x86_feature::vaes) && Arch.has(x86_feature::avx512f))
87 [[nodiscard]] hint_inline hint_const hint_target("avx512f,vaes")
88 __m512i vaesdeclast(__m512i state, __m512i key) noexcept {
89 return _mm512_aesdeclast_epi128(state, key);
90 }
91
92 template<isa<x86> Arch, class... Args>
93 void vaesdeclast(Args...) = delete;
94
95}
96#endif
97
98#include "native/x86/aes_constant.h"
99
100namespace native::detail::x86_vaes_constant {
101 // Every 128-bit lane is a separate AES state with its own round key. Reuse
102 // the AES substitution and field-mixing primitives without cross-lane work.
103 using x86_aes_constant::round;
104}