I’m trying to wrap cpuid
instruction. Something like this:
const CpuId = extern struct {
a: u32,
b: u32,
c: u32,
d: u32
};
export fn cpuid(leaf: u32) CpuId {
@setRuntimeSafety(false);
var a: u32 = undefined;
var b: u32 = undefined;
var c: u32 = undefined;
var d: u32 = undefined;
asm volatile(
\\cpuid
: [a]"=eax"(a),[b]"=ebx"(b),[c]"=ecx"(c),[d]"=edx"(d)
: [id]"eax"(leaf)
);
return .{ .a = a, .b = b, .c = c, .d = d };
}
But i get absolutely dumb assembly:
0000000000000000 <cpuid>:
0: c5 f9 6e c7 vmovd %edi,%xmm0
4: 0f a2 cpuid
6: c5 f9 7e d9 vmovd %xmm3,%ecx
a: c5 f9 7e ce vmovd %xmm1,%esi
e: c5 f9 7e d2 vmovd %xmm2,%edx
12: c5 f9 7e c0 vmovd %xmm0,%eax
16: 48 c1 e6 20 shl $0x20,%rsi
1a: 48 c1 e1 20 shl $0x20,%rcx
1e: 48 09 f0 or %rsi,%rax
21: 48 09 ca or %rcx,%rdx
24: c3 ret
So, how can i tell the compiler which registers cpuid
uses for output?