1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
use coresimd::x86::__m128i;
#[cfg(test)]
use stdsimd_test::assert_instr;
#[allow(improper_ctypes)]
extern "C" {
#[link_name = "llvm.x86.aesni.aesdec"]
fn aesdec(a: __m128i, round_key: __m128i) -> __m128i;
#[link_name = "llvm.x86.aesni.aesdeclast"]
fn aesdeclast(a: __m128i, round_key: __m128i) -> __m128i;
#[link_name = "llvm.x86.aesni.aesenc"]
fn aesenc(a: __m128i, round_key: __m128i) -> __m128i;
#[link_name = "llvm.x86.aesni.aesenclast"]
fn aesenclast(a: __m128i, round_key: __m128i) -> __m128i;
#[link_name = "llvm.x86.aesni.aesimc"]
fn aesimc(a: __m128i) -> __m128i;
#[link_name = "llvm.x86.aesni.aeskeygenassist"]
fn aeskeygenassist(a: __m128i, imm8: u8) -> __m128i;
}
#[inline]
#[target_feature(enable = "aes")]
#[cfg_attr(test, assert_instr(aesdec))]
#[stable(feature = "simd_x86", since = "1.27.0")]
pub unsafe fn _mm_aesdec_si128(a: __m128i, round_key: __m128i) -> __m128i {
aesdec(a, round_key)
}
#[inline]
#[target_feature(enable = "aes")]
#[cfg_attr(test, assert_instr(aesdeclast))]
#[stable(feature = "simd_x86", since = "1.27.0")]
pub unsafe fn _mm_aesdeclast_si128(a: __m128i, round_key: __m128i) -> __m128i {
aesdeclast(a, round_key)
}
#[inline]
#[target_feature(enable = "aes")]
#[cfg_attr(test, assert_instr(aesenc))]
#[stable(feature = "simd_x86", since = "1.27.0")]
pub unsafe fn _mm_aesenc_si128(a: __m128i, round_key: __m128i) -> __m128i {
aesenc(a, round_key)
}
#[inline]
#[target_feature(enable = "aes")]
#[cfg_attr(test, assert_instr(aesenclast))]
#[stable(feature = "simd_x86", since = "1.27.0")]
pub unsafe fn _mm_aesenclast_si128(a: __m128i, round_key: __m128i) -> __m128i {
aesenclast(a, round_key)
}
#[inline]
#[target_feature(enable = "aes")]
#[cfg_attr(test, assert_instr(aesimc))]
#[stable(feature = "simd_x86", since = "1.27.0")]
pub unsafe fn _mm_aesimc_si128(a: __m128i) -> __m128i {
aesimc(a)
}
#[inline]
#[target_feature(enable = "aes")]
#[cfg_attr(test, assert_instr(aeskeygenassist, imm8 = 0))]
#[rustc_args_required_const(1)]
#[stable(feature = "simd_x86", since = "1.27.0")]
pub unsafe fn _mm_aeskeygenassist_si128(a: __m128i, imm8: i32) -> __m128i {
macro_rules! call {
($imm8:expr) => {
aeskeygenassist(a, $imm8)
};
}
constify_imm8!(imm8, call)
}
#[cfg(test)]
mod tests {
#![allow(overflowing_literals)]
use stdsimd_test::simd_test;
use coresimd::x86::*;
#[simd_test(enable = "aes")]
unsafe fn test_mm_aesdec_si128() {
let a = _mm_set_epi64x(0x0123456789abcdef, 0x8899aabbccddeeff);
let k = _mm_set_epi64x(0x1133557799bbddff, 0x0022446688aaccee);
let e = _mm_set_epi64x(0x044e4f5176fec48f, 0xb57ecfa381da39ee);
let r = _mm_aesdec_si128(a, k);
assert_eq_m128i(r, e);
}
#[simd_test(enable = "aes")]
unsafe fn test_mm_aesdeclast_si128() {
let a = _mm_set_epi64x(0x0123456789abcdef, 0x8899aabbccddeeff);
let k = _mm_set_epi64x(0x1133557799bbddff, 0x0022446688aaccee);
let e = _mm_set_epi64x(0x36cad57d9072bf9e, 0xf210dd981fa4a493);
let r = _mm_aesdeclast_si128(a, k);
assert_eq_m128i(r, e);
}
#[simd_test(enable = "aes")]
unsafe fn test_mm_aesenc_si128() {
let a = _mm_set_epi64x(0x0123456789abcdef, 0x8899aabbccddeeff);
let k = _mm_set_epi64x(0x1133557799bbddff, 0x0022446688aaccee);
let e = _mm_set_epi64x(0x16ab0e57dfc442ed, 0x28e4ee1884504333);
let r = _mm_aesenc_si128(a, k);
assert_eq_m128i(r, e);
}
#[simd_test(enable = "aes")]
unsafe fn test_mm_aesenclast_si128() {
let a = _mm_set_epi64x(0x0123456789abcdef, 0x8899aabbccddeeff);
let k = _mm_set_epi64x(0x1133557799bbddff, 0x0022446688aaccee);
let e = _mm_set_epi64x(0xb6dd7df25d7ab320, 0x4b04f98cf4c860f8);
let r = _mm_aesenclast_si128(a, k);
assert_eq_m128i(r, e);
}
#[simd_test(enable = "aes")]
unsafe fn test_mm_aesimc_si128() {
let a = _mm_set_epi64x(0x0123456789abcdef, 0x8899aabbccddeeff);
let e = _mm_set_epi64x(0xc66c82284ee40aa0, 0x6633441122770055);
let r = _mm_aesimc_si128(a);
assert_eq_m128i(r, e);
}
#[simd_test(enable = "aes")]
unsafe fn test_mm_aeskeygenassist_si128() {
let a = _mm_set_epi64x(0x0123456789abcdef, 0x8899aabbccddeeff);
let e = _mm_set_epi64x(0x857c266b7c266e85, 0xeac4eea9c4eeacea);
let r = _mm_aeskeygenassist_si128(a, 5);
assert_eq_m128i(r, e);
}
}