authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-06 20:02:08-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-06 20:02:08-05:00
loge0d5f94a70faafbb07978f39394077820ff007ec
tree259c43a1d3d9838036db9188f1ee1ccc4f6957e0
parent49817c6adde3e9e98282dcecd017ab076faa1d85
signaturelock-open Commit is signed but in an unrecognized format.

simplify the inline assembly


1 files changed, 15 insertions(+), 32 deletions(-)

lib/std/zig/system/x86.zig+15-32
......@@ -519,38 +519,21 @@ fn cpuid(leaf_id: u32, subid: u32) CpuidLeaf {
519519 // Inline assembly in zig only supports one output,
520520 // so we pass a pointer to the struct.
521521 var cpuid_leaf = CpuidLeaf{ .eax = 0, .ebx = 0, .ecx = 0, .edx = 0 };
522 var leaf_ptr = &cpuid_leaf;
523 switch (Target.current.cpu.arch) {
524 .i386 => {
525 _ = asm volatile (
526 \\ cpuid
527 \\ movl %%eax, (%%edi)
528 \\ movl %%ebx, 4(%%edi)
529 \\ movl %%ecx, 8(%%edi)
530 \\ movl %%edx, 12(%%edi)
531 :
532 : [leaf_id] "{eax}" (leaf_id),
533 [subid] "{ecx}" (subid),
534 [leaf_ptr] "{edi}" (leaf_ptr)
535 : "eax", "ebx", "ecx", "edx"
536 );
537 },
538 .x86_64 => {
539 _ = asm volatile (
540 \\ cpuid
541 \\ movl %%eax, (%%rdi)
542 \\ movl %%ebx, 4(%%rdi)
543 \\ movl %%ecx, 8(%%rdi)
544 \\ movl %%edx, 12(%%rdi)
545 :
546 : [leaf_id] "{eax}" (leaf_id),
547 [subid] "{ecx}" (subid),
548 [leaf_ptr] "{rdi}" (leaf_ptr)
549 : "eax", "ebx", "ecx", "edx"
550 );
551 },
552 else => unreachable,
553 }
522 const leaf_ptr = &cpuid_leaf;
523
524 // valid for both x86 and x86_64
525 asm volatile (
526 \\ cpuid
527 \\ movl %%eax, (%[leaf_ptr])
528 \\ movl %%ebx, 4(%[leaf_ptr])
529 \\ movl %%ecx, 8(%[leaf_ptr])
530 \\ movl %%edx, 12(%[leaf_ptr])
531 :
532 : [leaf_id] "{eax}" (leaf_id),
533 [subid] "{ecx}" (subid),
534 [leaf_ptr] "r" (leaf_ptr)
535 : "eax", "ebx", "ecx", "edx"
536 );
554537 return cpuid_leaf;
555538}
556539