Skip to content
This repository has been archived by the owner on Jun 29, 2024. It is now read-only.

Commit

Permalink
refactor: replace load_32x4 with load_u32
Browse files Browse the repository at this point in the history
  • Loading branch information
codahale committed Nov 9, 2023
1 parent a530665 commit f4d1449
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
15 changes: 5 additions & 10 deletions src/intrinsics/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@ use core::arch::asm;

pub use core::arch::aarch64::uint8x16_t as AesBlock;

#[inline]
pub fn load_32x4(a: u32, b: u32, c: u32, d: u32) -> AesBlock {
unsafe {
vreinterpretq_u8_u32(vsetq_lane_u32::<3>(
d,
vsetq_lane_u32::<2>(c, vsetq_lane_u32::<1>(b, vmovq_n_u32(a))),
))
}
}

#[inline]
pub fn zero() -> AesBlock {
unsafe { vmovq_n_u8(0) }
Expand All @@ -28,6 +18,11 @@ pub fn store(bytes: &mut [u8], block: AesBlock) {
unsafe { vst1q_u8(bytes.as_mut_ptr(), block) };
}

#[inline]
pub fn load_u32(words: &[u32]) -> AesBlock {
unsafe { vreinterpretq_u8_u32(vld1q_u32(words.as_ptr())) }
}

#[inline]
pub fn store_u32(bytes: &mut [u32], block: AesBlock) {
unsafe { vst1q_u32(bytes.as_mut_ptr(), vreinterpretq_u32_u8(block)) };
Expand Down
10 changes: 5 additions & 5 deletions src/intrinsics/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ pub fn zero() -> AesBlock {
unsafe { _mm_setzero_si128() }
}

#[inline]
pub fn load_32x4(a: u32, b: u32, c: u32, d: u32) -> AesBlock {
unsafe { _mm_set_epi32(d as i32, c as i32, b as i32, a as i32) }
}

#[inline]
pub fn load(bytes: &[u8]) -> AesBlock {
unsafe { _mm_loadu_si128(bytes.as_ptr() as *const __m128i) }
Expand All @@ -22,6 +17,11 @@ pub fn store(bytes: &mut [u8], block: AesBlock) {
unsafe { _mm_storeu_si128(bytes.as_mut_ptr() as *mut __m128i, block) };
}

#[inline]
pub fn load_u32(words: &[u32]) -> AesBlock {
unsafe { _mm_loadu_si128(words.as_ptr() as *const __m128i) }
}

#[inline]
pub fn store_u32(bytes: &mut [u32], block: AesBlock) {
unsafe { _mm_storeu_si128(bytes.as_mut_ptr() as *mut __m128i, block) };
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ pub fn areion512_dm(
store_u32(&mut x[12..], x3_p);

(
load_32x4(x[2], x[3], x[6], x[7]),
load_32x4(x[8], x[9], x[12], x[13]),
load_u32(&[x[2], x[3], x[6], x[7]]),
load_u32(&[x[8], x[9], x[12], x[13]]),
)
}

Expand Down

0 comments on commit f4d1449

Please sign in to comment.