authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2022-11-01 19:57:14-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2022-11-01 20:39:06-04:00
log771dadc5e08fc27c5cd4aa3483647b70a9f9cb0b
treedec193daa617a29fd4179b51d101d995982722dd
parent9b2db56d0fc3ed3b16179575a5d0d4fff2538fc2

x86: cleanup inline asm

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

1 files changed, 14 insertions(+), 20 deletions(-)

lib/std/zig/system/x86.zig+14-20
......@@ -528,26 +528,20 @@ const CpuidLeaf = packed struct {
528528};
529529
530530fn cpuid(leaf_id: u32, subid: u32) CpuidLeaf {
531 // Workaround for https://github.com/ziglang/zig/issues/215
532 // Inline assembly in zig only supports one output,
533 // so we pass a pointer to the struct.
534 var cpuid_leaf: CpuidLeaf = undefined;
535
536531 // valid for both x86 and x86_64
537 asm volatile (
538 \\ cpuid
539 \\ movl %%eax, 0(%[leaf_ptr])
540 \\ movl %%ebx, 4(%[leaf_ptr])
541 \\ movl %%ecx, 8(%[leaf_ptr])
542 \\ movl %%edx, 12(%[leaf_ptr])
543 :
544 : [leaf_id] "{eax}" (leaf_id),
545 [subid] "{ecx}" (subid),
546 [leaf_ptr] "r" (&cpuid_leaf),
547 : "ebx", "edx" // "eax" and "ecx" are already inputs
532 var eax: u32 = undefined;
533 var ebx: u32 = undefined;
534 var ecx: u32 = undefined;
535 var edx: u32 = undefined;
536 asm volatile ("cpuid"
537 : [_] "={eax}" (eax),
538 [_] "={ebx}" (ebx),
539 [_] "={ecx}" (ecx),
540 [_] "={edx}" (edx),
541 : [_] "{eax}" (leaf_id),
542 [_] "{ecx}" (subid),
548543 );
549
550 return cpuid_leaf;
544 return .{ .eax = eax, .ebx = ebx, .ecx = ecx, .edx = edx };
551545}
552546
553547// Read control register 0 (XCR0). Used to detect features such as AVX.
......@@ -555,8 +549,8 @@ fn getXCR0() u32 {
555549 return asm volatile (
556550 \\ xor %%ecx, %%ecx
557551 \\ xgetbv
558 : [ret] "={eax}" (-> u32),
552 : [_] "={eax}" (-> u32),
559553 :
560 : "edx", "ecx" // "eax" is already an output
554 : "edx", "ecx"
561555 );
562556}