From 88d06f042ab317685ea032b730468f8149529e2c Mon Sep 17 00:00:00 2001 From: Franziskus Kiefer Date: Fri, 27 Sep 2024 12:11:28 +0200 Subject: [PATCH] add neon to/from bytes --- libcrux-ml-kem/src/vector/neon.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/libcrux-ml-kem/src/vector/neon.rs b/libcrux-ml-kem/src/vector/neon.rs index 68539971e..2ffe7a1a9 100644 --- a/libcrux-ml-kem/src/vector/neon.rs +++ b/libcrux-ml-kem/src/vector/neon.rs @@ -30,6 +30,28 @@ impl Operations for SIMD128Vector { to_i16_array(x) } + fn to_bytes(x: Self, out: &mut [u8]) { + libcrux_intrinsics::arm64::_vst1q_u8( + out, + libcrux_intrinsics::arm64::_vreinterpretq_u8_s16(x.high), + ); + libcrux_intrinsics::arm64::_vst1q_u8( + &mut out[16..], + libcrux_intrinsics::arm64::_vreinterpretq_u8_s16(x.low), + ); + } + + fn from_bytes(bytes: &[u8]) -> Self { + Self { + low: libcrux_intrinsics::arm64::_vreinterpretq_s16_u8( + libcrux_intrinsics::arm64::_vld1q_u8(&bytes[16..]), + ), + high: libcrux_intrinsics::arm64::_vreinterpretq_s16_u8( + libcrux_intrinsics::arm64::_vld1q_u8(bytes), + ), + } + } + fn add(lhs: Self, rhs: &Self) -> Self { add(lhs, rhs) }