|
2 | 2 |
|
3 | 3 | #![cfg_attr(feature = "cargo-clippy", allow(clippy::stutter))]
|
4 | 4 |
|
5 |
| -use mem; |
6 |
| - |
7 | 5 | #[cfg(test)]
|
8 | 6 | use stdsimd_test::assert_instr;
|
9 | 7 |
|
@@ -53,20 +51,26 @@ pub struct CpuidResult {
|
53 | 51 | #[cfg_attr(test, assert_instr(cpuid))]
|
54 | 52 | #[stable(feature = "simd_x86", since = "1.27.0")]
|
55 | 53 | 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 | + { |
58 | 60 | asm!("cpuid"
|
59 |
| - : "={eax}"(r.eax), "={ebx}"(r.ebx), "={ecx}"(r.ecx), "={edx}"(r.edx) |
| 61 | + : "={eax}"(eax), "={ebx}"(ebx), "={ecx}"(ecx), "={edx}"(edx) |
60 | 62 | : "{eax}"(leaf), "{ecx}"(sub_leaf)
|
61 | 63 | : :);
|
62 |
| - } else { |
| 64 | + } |
| 65 | + #[cfg(target_arch = "x86_64")] |
| 66 | + { |
63 | 67 | // x86-64 uses %rbx as the base register, so preserve it.
|
64 | 68 | 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) |
66 | 70 | : "{eax}"(leaf), "{ecx}"(sub_leaf)
|
67 | 71 | : "rbx" :);
|
68 | 72 | }
|
69 |
| - r |
| 73 | + CpuidResult { eax, ebx, ecx, edx } |
70 | 74 | }
|
71 | 75 |
|
72 | 76 | /// See [`__cpuid_count`](fn.__cpuid_count.html).
|
|
0 commit comments