diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-03-06 20:02:08 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-03-06 20:02:08 -0500 |
| commit | e0d5f94a70faafbb07978f39394077820ff007ec (patch) | |
| tree | 259c43a1d3d9838036db9188f1ee1ccc4f6957e0 /lib/std | |
| parent | 49817c6adde3e9e98282dcecd017ab076faa1d85 (diff) | |
| download | zig-e0d5f94a70faafbb07978f39394077820ff007ec.tar.gz zig-e0d5f94a70faafbb07978f39394077820ff007ec.zip | |
simplify the inline assembly
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/zig/system/x86.zig | 47 |
1 files changed, 15 insertions, 32 deletions
diff --git a/lib/std/zig/system/x86.zig b/lib/std/zig/system/x86.zig index 96ce98d7f4..b7d2c6a227 100644 --- a/lib/std/zig/system/x86.zig +++ b/lib/std/zig/system/x86.zig @@ -519,38 +519,21 @@ fn cpuid(leaf_id: u32, subid: u32) CpuidLeaf { // Inline assembly in zig only supports one output, // so we pass a pointer to the struct. var cpuid_leaf = CpuidLeaf{ .eax = 0, .ebx = 0, .ecx = 0, .edx = 0 }; - var leaf_ptr = &cpuid_leaf; - switch (Target.current.cpu.arch) { - .i386 => { - _ = asm volatile ( - \\ cpuid - \\ movl %%eax, (%%edi) - \\ movl %%ebx, 4(%%edi) - \\ movl %%ecx, 8(%%edi) - \\ movl %%edx, 12(%%edi) - : - : [leaf_id] "{eax}" (leaf_id), - [subid] "{ecx}" (subid), - [leaf_ptr] "{edi}" (leaf_ptr) - : "eax", "ebx", "ecx", "edx" - ); - }, - .x86_64 => { - _ = asm volatile ( - \\ cpuid - \\ movl %%eax, (%%rdi) - \\ movl %%ebx, 4(%%rdi) - \\ movl %%ecx, 8(%%rdi) - \\ movl %%edx, 12(%%rdi) - : - : [leaf_id] "{eax}" (leaf_id), - [subid] "{ecx}" (subid), - [leaf_ptr] "{rdi}" (leaf_ptr) - : "eax", "ebx", "ecx", "edx" - ); - }, - else => unreachable, - } + const leaf_ptr = &cpuid_leaf; + + // valid for both x86 and x86_64 + asm volatile ( + \\ cpuid + \\ movl %%eax, (%[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" (leaf_ptr) + : "eax", "ebx", "ecx", "edx" + ); return cpuid_leaf; } |
