diff options
| author | Jacob Young <jacobly0@users.noreply.github.com> | 2022-11-01 19:57:14 -0400 |
|---|---|---|
| committer | Jacob Young <jacobly0@users.noreply.github.com> | 2022-11-01 20:39:06 -0400 |
| commit | 771dadc5e08fc27c5cd4aa3483647b70a9f9cb0b (patch) | |
| tree | dec193daa617a29fd4179b51d101d995982722dd /lib/std | |
| parent | 9b2db56d0fc3ed3b16179575a5d0d4fff2538fc2 (diff) | |
| download | zig-771dadc5e08fc27c5cd4aa3483647b70a9f9cb0b.tar.gz zig-771dadc5e08fc27c5cd4aa3483647b70a9f9cb0b.zip | |
x86: cleanup inline asm
Multiple outputs work now, so use that instead of deleting clobbers.
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/zig/system/x86.zig | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/lib/std/zig/system/x86.zig b/lib/std/zig/system/x86.zig index 7be4b19c2f..66468ba6ff 100644 --- a/lib/std/zig/system/x86.zig +++ b/lib/std/zig/system/x86.zig @@ -528,26 +528,20 @@ const CpuidLeaf = packed struct { }; fn cpuid(leaf_id: u32, subid: u32) CpuidLeaf { - // Workaround for https://github.com/ziglang/zig/issues/215 - // Inline assembly in zig only supports one output, - // so we pass a pointer to the struct. - var cpuid_leaf: CpuidLeaf = undefined; - // valid for both x86 and x86_64 - asm volatile ( - \\ cpuid - \\ movl %%eax, 0(%[leaf_ptr]) - \\ movl %%ebx, 4(%[leaf_ptr]) - \\ movl %%ecx, 8(%[leaf_ptr]) - \\ movl %%edx, 12(%[leaf_ptr]) - : - : [leaf_id] "{eax}" (leaf_id), - [subid] "{ecx}" (subid), - [leaf_ptr] "r" (&cpuid_leaf), - : "ebx", "edx" // "eax" and "ecx" are already inputs + var eax: u32 = undefined; + var ebx: u32 = undefined; + var ecx: u32 = undefined; + var edx: u32 = undefined; + asm volatile ("cpuid" + : [_] "={eax}" (eax), + [_] "={ebx}" (ebx), + [_] "={ecx}" (ecx), + [_] "={edx}" (edx), + : [_] "{eax}" (leaf_id), + [_] "{ecx}" (subid), ); - - return cpuid_leaf; + return .{ .eax = eax, .ebx = ebx, .ecx = ecx, .edx = edx }; } // Read control register 0 (XCR0). Used to detect features such as AVX. @@ -555,8 +549,8 @@ fn getXCR0() u32 { return asm volatile ( \\ xor %%ecx, %%ecx \\ xgetbv - : [ret] "={eax}" (-> u32), + : [_] "={eax}" (-> u32), : - : "edx", "ecx" // "eax" is already an output + : "edx", "ecx" ); } |
