Skip to content

Commit fed2a62

Browse files
committed
Remove all usages of mem::uninitialized
1 parent 36e52fc commit fed2a62

File tree

5 files changed

+25
-19
lines changed

5 files changed

+25
-19
lines changed

coresimd/x86/avx.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -2875,7 +2875,8 @@ pub unsafe fn _mm256_zextpd128_pd256(a: __m128d) -> __m256d {
28752875
// This intrinsic has no corresponding instruction.
28762876
#[stable(feature = "simd_x86", since = "1.27.0")]
28772877
pub unsafe fn _mm256_undefined_ps() -> __m256 {
2878-
_mm256_set1_ps(mem::uninitialized())
2878+
// FIXME: this function should return MaybeUninit<__m256>
2879+
mem::MaybeUninit::<__m256>::uninitialized().into_inner()
28792880
}
28802881

28812882
/// Return vector of type `__m256d` with undefined elements.
@@ -2886,7 +2887,8 @@ pub unsafe fn _mm256_undefined_ps() -> __m256 {
28862887
// This intrinsic has no corresponding instruction.
28872888
#[stable(feature = "simd_x86", since = "1.27.0")]
28882889
pub unsafe fn _mm256_undefined_pd() -> __m256d {
2889-
_mm256_set1_pd(mem::uninitialized())
2890+
// FIXME: this function should return MaybeUninit<__m256d>
2891+
mem::MaybeUninit::<__m256d>::uninitialized().into_inner()
28902892
}
28912893

28922894
/// Return vector of type __m256i with undefined elements.
@@ -2897,7 +2899,8 @@ pub unsafe fn _mm256_undefined_pd() -> __m256d {
28972899
// This intrinsic has no corresponding instruction.
28982900
#[stable(feature = "simd_x86", since = "1.27.0")]
28992901
pub unsafe fn _mm256_undefined_si256() -> __m256i {
2900-
_mm256_set1_epi8(mem::uninitialized())
2902+
// FIXME: this function should return MaybeUninit<__m256i>
2903+
mem::MaybeUninit::<__m256i>::uninitialized().into_inner()
29012904
}
29022905

29032906
/// Set packed __m256 returned vector with the supplied values.

coresimd/x86/cpuid.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
33
#![cfg_attr(feature = "cargo-clippy", allow(clippy::stutter))]
44

5-
use mem;
6-
75
#[cfg(test)]
86
use stdsimd_test::assert_instr;
97

@@ -53,20 +51,26 @@ pub struct CpuidResult {
5351
#[cfg_attr(test, assert_instr(cpuid))]
5452
#[stable(feature = "simd_x86", since = "1.27.0")]
5553
pub unsafe fn __cpuid_count(leaf: u32, sub_leaf: u32) -> CpuidResult {
56-
let mut r = mem::uninitialized::<CpuidResult>();
57-
if cfg!(target_arch = "x86") {
54+
let eax;
55+
let ebx;
56+
let ecx;
57+
let edx;
58+
#[cfg(target_arch = "x86")]
59+
{
5860
asm!("cpuid"
59-
: "={eax}"(r.eax), "={ebx}"(r.ebx), "={ecx}"(r.ecx), "={edx}"(r.edx)
61+
: "={eax}"(eax), "={ebx}"(ebx), "={ecx}"(ecx), "={edx}"(edx)
6062
: "{eax}"(leaf), "{ecx}"(sub_leaf)
6163
: :);
62-
} else {
64+
}
65+
#[cfg(target_arch = "x86_64")]
66+
{
6367
// x86-64 uses %rbx as the base register, so preserve it.
6468
asm!("cpuid\n"
65-
: "={eax}"(r.eax), "={ebx}"(r.ebx), "={ecx}"(r.ecx), "={edx}"(r.edx)
69+
: "={eax}"(eax), "={ebx}"(ebx), "={ecx}"(ecx), "={edx}"(edx)
6670
: "{eax}"(leaf), "{ecx}"(sub_leaf)
6771
: "rbx" :);
6872
}
69-
r
73+
CpuidResult { eax, ebx, ecx, edx }
7074
}
7175

7276
/// See [`__cpuid_count`](fn.__cpuid_count.html).

coresimd/x86/sse.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1952,12 +1952,8 @@ pub unsafe fn _mm_prefetch(p: *const i8, strategy: i32) {
19521952
#[target_feature(enable = "sse")]
19531953
#[stable(feature = "simd_x86", since = "1.27.0")]
19541954
pub unsafe fn _mm_undefined_ps() -> __m128 {
1955-
__m128(
1956-
mem::uninitialized(),
1957-
mem::uninitialized(),
1958-
mem::uninitialized(),
1959-
mem::uninitialized(),
1960-
)
1955+
// FIXME: this function should return MaybeUninit<__m128>
1956+
mem::MaybeUninit::<__m128>::uninitialized().into_inner()
19611957
}
19621958

19631959
/// Transpose the 4x4 matrix formed by 4 rows of __m128 in place.

coresimd/x86/sse2.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -2847,7 +2847,8 @@ pub unsafe fn _mm_castsi128_ps(a: __m128i) -> __m128 {
28472847
#[target_feature(enable = "sse2")]
28482848
#[stable(feature = "simd_x86", since = "1.27.0")]
28492849
pub unsafe fn _mm_undefined_pd() -> __m128d {
2850-
_mm_set1_pd(mem::uninitialized())
2850+
// FIXME: this function should return MaybeUninit<__m128d>
2851+
mem::MaybeUninit::<__m128d>::uninitialized().into_inner()
28512852
}
28522853

28532854
/// Return vector of type __m128i with undefined elements.
@@ -2857,7 +2858,8 @@ pub unsafe fn _mm_undefined_pd() -> __m128d {
28572858
#[target_feature(enable = "sse2")]
28582859
#[stable(feature = "simd_x86", since = "1.27.0")]
28592860
pub unsafe fn _mm_undefined_si128() -> __m128i {
2860-
_mm_set1_epi8(mem::uninitialized())
2861+
// FIXME: this function should return MaybeUninit<__m128i>
2862+
mem::MaybeUninit::<__m128i>::uninitialized().into_inner()
28612863
}
28622864

28632865
/// The resulting `__m128d` element is composed by the low-order values of

crates/coresimd/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
stdsimd,
2727
staged_api,
2828
align_offset,
29+
maybe_uninit,
2930
doc_cfg,
3031
mmx_target_feature,
3132
tbm_target_feature,

0 commit comments

Comments
 (0)