zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 771dadc5e08fc27c5cd4aa3483647b70a9f9cb0b (tree)
parent 9b2db56d0fc3ed3b16179575a5d0d4fff2538fc2
Author: Jacob Young <jacobly0@users.noreply.github.com>
Date:   Tue,  1 Nov 2022 19:57:14 -0400

x86: cleanup inline asm

Multiple outputs work now, so use that instead of deleting clobbers.

Diffstat:
Mlib/std/zig/system/x86.zig | 34++++++++++++++--------------------
1 file changed, 14 insertions(+), 20 deletions(-)

diff --git 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" ); }