Skip to content

Commit 944d4e8

Browse files
committed
Define _mm_aes*_si128 intrinsics
1 parent 536013b commit 944d4e8

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

coresimd/src/x86/x86_64/aes.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
use x86::__m128i;
2+
3+
#[allow(improper_ctypes)]
4+
extern "C" {
5+
#[link_name = "llvm.x86.aesni.aesdec"]
6+
fn aesdec(a: __m128i, round_key: __m128i) -> __m128i;
7+
#[link_name = "llvm.x86.aesni.aesdeclast"]
8+
fn aesdeclast(a: __m128i, round_key: __m128i) -> __m128i;
9+
#[link_name = "llvm.x86.aesni.aesenc"]
10+
fn aesenc(a: __m128i, round_key: __m128i) -> __m128i;
11+
#[link_name = "llvm.x86.aesni.aesenclast"]
12+
fn aesenclast(a: __m128i, round_key: __m128i) -> __m128i;
13+
#[link_name = "llvm.x86.aesni.aesimc"]
14+
fn aesimc(a: __m128i) -> __m128i;
15+
#[link_name = "llvm.x86.aesni.aeskeygenassist"]
16+
fn aeskeygenassist(a: __m128i, imm8: u8) -> __m128i;
17+
}
18+
19+
/// Perform one round of an AES decryption flow on data (state) in `a`.
20+
#[inline]
21+
#[target_feature(enable = "aes")]
22+
#[cfg_attr(test, assert_instr(aesdec))]
23+
pub unsafe fn _mm_aesdec_si128(a: __m128i, round_key: __m128i) -> __m128i {
24+
aesdec(a, round_key)
25+
}
26+
27+
/// Perform the last round of an AES decryption flow on data (state) in `a`.
28+
#[inline]
29+
#[target_feature(enable = "aes")]
30+
#[cfg_attr(test, assert_instr(aesdeclast))]
31+
pub unsafe fn _mm_aesdeclast_si128(a: __m128i, round_key: __m128i) -> __m128i {
32+
aesdeclast(a, round_key)
33+
}
34+
35+
/// Perform one round of an AES encryption flow on data (state) in `a`.
36+
#[inline]
37+
#[target_feature(enable = "aes")]
38+
#[cfg_attr(test, assert_instr(aesenc))]
39+
pub unsafe fn _mm_aesenc_si128(a: __m128i, round_key: __m128i) -> __m128i {
40+
aesenc(a, round_key)
41+
}
42+
43+
/// Perform the last round of an AES encryption flow on data (state) in `a`.
44+
#[inline]
45+
#[target_feature(enable = "aes")]
46+
#[cfg_attr(test, assert_instr(aesenclast))]
47+
pub unsafe fn _mm_aesenclast_si128(a: __m128i, round_key: __m128i) -> __m128i {
48+
aesenclast(a, round_key)
49+
}
50+
51+
/// Perform the “InvMixColumns” transformation on `a`.
52+
#[inline]
53+
#[target_feature(enable = "aes")]
54+
#[cfg_attr(test, assert_instr(aesimc))]
55+
pub unsafe fn _mm_aesimc_si128(a: __m128i) -> __m128i {
56+
aesimc(a)
57+
}
58+
59+
/// Assist in expanding the AES cipher key.
60+
///
61+
/// Assist in expanding the AES cipher key by computing steps towards generating
62+
/// a round key for encryption cipher using data from `a` and an 8-bit round constant.
63+
#[inline]
64+
#[target_feature(enable = "aes")]
65+
#[cfg_attr(test, assert_instr(aeskeygenassist))]
66+
pub unsafe fn _mm_aeskeygenassist_si128(a: __m128i, imm8: u8) -> __m128i {
67+
aeskeygenassist(a, imm8)
68+
}

coresimd/src/x86/x86_64/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ pub use self::xsave::*;
2323
mod abm;
2424
pub use self::abm::*;
2525

26+
mod aes;
27+
pub use self::aes::*;
28+
2629
mod avx;
2730
pub use self::avx::*;
2831

0 commit comments

Comments
 (0)