Re: [PATCH 0/5] x86/cpu: Introduce <asm/cpuid/types.h> and <asm/cpuid/api.h> and clean them up
From: H. Peter Anvin
Date: Tue Mar 18 2025 - 23:31:32 EST
On March 18, 2025 11:04:30 AM PDT, Ingo Molnar <mingo@xxxxxxxxxx> wrote:
>
>* H. Peter Anvin <hpa@xxxxxxxxx> wrote:
>
>> It would be nice to get rid of the bleacherous use of *eax and *ecx
>> as input-output operands. The use of four separate pointers is just
>> barely tolerable because the compiler can remove them when the asm is
>> inlined.
>
>So we have a nice structure of:
>
> struct cpuid_regs {
> u32 eax;
> u32 ebx;
> u32 ecx;
> u32 edx;
> };
>
>So instead of:
>
> static inline void cpuid_count(unsigned int op, int count,
> unsigned int *eax, unsigned int *ebx,
> unsigned int *ecx, unsigned int *edx)
>
>... we could have:
>
> static inline void cpuid_count(unsigned int op, int count, struct cpuid_regs *cregs)
>
>or so?
>
>plus we could implement the main CPUID call as:
>
> static inline void native_cpuid(struct cpuid_regs *cregs)
> {
> /* ecx is often an input as well as an output. */
> asm volatile("cpuid"
> : "=a" (cregs->eax),
> "=b" (cregs->ebx),
> "=c" (cregs->ecx),
> "=d" (cregs->edx)
> : "0" (cregs->eax), "2" (cregs->ecx)
> : "memory");
> }
>
>and thus we give the asm() statement only a single pointer in essence,
>'cregs'?
>
>Or do you mean something else?
>
>Thanks,
>
> Ingo
Yes, I attached an example, but I used the structure as a return.