-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
zeroize: add support for x86(_64) SIMD registers
Adds `Zeroize` impls for the following x86/x86_64 SIMD register types, gated on the corresponding `target_feature`s they depend upon: - `__m128` - `__m128d` - `__m128i` - `__m256` - `__m256d` - `__m256i`
- Loading branch information
1 parent
a74b730
commit 6c11a48
Showing
3 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//! [`Zeroize`] impls for x86 SIMD registers | ||
use crate::{atomic_fence, volatile_write, Zeroize}; | ||
|
||
#[cfg(target_arch = "x86")] | ||
use core::arch::x86::*; | ||
|
||
#[cfg(target_arch = "x86_64")] | ||
use core::arch::x86_64::*; | ||
|
||
macro_rules! impl_zeroize_for_simd_register { | ||
($type:ty, $feature:expr, $zero_value:ident) => { | ||
#[cfg_attr(docsrs, doc(cfg(target_arch = "x86")))] // also `x86_64` | ||
#[cfg_attr(docsrs, doc(cfg(target_feature = $feature)))] | ||
impl Zeroize for $type { | ||
fn zeroize(&mut self) { | ||
volatile_write(self, unsafe { $zero_value() }); | ||
atomic_fence(); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
#[cfg(target_feature = "sse")] | ||
impl_zeroize_for_simd_register!(__m128, "sse", _mm_setzero_ps); | ||
|
||
#[cfg(target_feature = "sse2")] | ||
impl_zeroize_for_simd_register!(__m128d, "sse2", _mm_setzero_pd); | ||
|
||
#[cfg(target_feature = "sse2")] | ||
impl_zeroize_for_simd_register!(__m128i, "sse2", _mm_setzero_si128); | ||
|
||
#[cfg(target_feature = "avx")] | ||
impl_zeroize_for_simd_register!(__m256, "avx", _mm256_setzero_ps); | ||
|
||
#[cfg(target_feature = "avx")] | ||
impl_zeroize_for_simd_register!(__m256d, "avx", _mm256_setzero_pd); | ||
|
||
#[cfg(target_feature = "avx")] | ||
impl_zeroize_for_simd_register!(__m256i, "avx", _mm256_setzero_si256); |