Page 1 of 1

problem with inline assembly [solved]

Posted: Tue Oct 09, 2007 4:59 am
by os64dev
Hi all,

Maybe you can help, because i am flabbergasted by this.

i have the following code for CPUID:

Code: Select all

inline void     cpuid(int32u fnc, int32u * regs) {
    asm volatile ("cpuid;"
                  : "=a"(regs[0]), "=b"(regs[1]), "=c"(regs[2]), "=d"(regs[3])
                  : "a"(fnc)
                 );
}
when i use it to get for instance the capabilities:

Code: Select all

int32u regs[4];
cpuid(1,regs);
f_capabilities = regs[2];
i get the following assembly :

Code: Select all

 170:	53                   	push   %rbx
 171:	b8 01 00 00 00       	mov    $0x1,%eax
 176:	0f a2                	cpuid  
 178:	89 4c 24 f8          	mov    %ecx,0xfffffffffffffff8(%rsp)
 17c:	89 c8                	mov    %ecx,%eax
 17e:	5b                   	pop    %rbx
 17f:	48 89 07             	mov    %rax,(%rdi)
so my question is:

how can i get rid of the stupid 'mov %ecx,0xfffffffffffffff8(%rsp)' statement as it is not needed at all.

edit:
changing the implementation of cpuid fixed everything way less generated code:

Code: Select all

nline void     cpuid(int32u fnc, int32u eax, int32u ebx, int32u ecx, int32u edx) {
    asm volatile ("cpuid;"
                  : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
                  : "a"(fnc)
                 );
}