https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77756
--- Comment #6 from Uroš Bizjak <ubizjak at gmail dot com> ---
(In reply to H.J. Lu from comment #5)
> For level >= 7, ECX may have other input values. It is incorrect to
> assume that ECX only takes 0 or 1. We should get another macro for
> level >= 7 with input for ECX:
We can extend __get_cpuid to assume subleaf = 0 and introduce new
__get_cpuid_subleaf, in effect:
--cut here--
static __inline int
__get_cpuid (unsigned int __level,
unsigned int *__eax, unsigned int *__ebx,
unsigned int *__ecx, unsigned int *__edx)
{
unsigned int __ext = __level & 0x80000000;
if (__get_cpuid_max (__ext, 0) < __level)
return 0;
if (__ext)
__cpuid (__level, *__eax, *__ebx, *__ecx, *__edx);
else if (__level >= 7)
__cpuid_count (__level, 0, *__eax, *__ebx, *__ecx, *__edx);
else
__cpuid (__level, *__eax, *__ebx, *__ecx, *__edx);
return 1;
}
static __inline int
__get_cpuid_subleaf (unsigned int __level, unsigned int __subleaf,
unsigned int *__eax, unsigned int *__ebx,
unsigned int *__ecx, unsigned int *__edx)
{
unsigned int __ext = __level & 0x80000000;
if (__get_cpuid_max (__ext, 0) < __level)
return 0;
if (__ext)
__cpuid (__level, *__eax, *__ebx, *__ecx, *__edx);
else if (__level >= 7)
{
__cpuid_count (__level, 0, *__eax, *__ebx, *__ecx, *__edx);
if (__subleaf > *__eax)
return 0;
if (__subleaf)
__cpuid_count (__level, __subleaf, *__eax, *__ebx, *__ecx, *__edx);
}
else
__cpuid (__level, *__eax, *__ebx, *__ecx, *__edx);
return 1;
}
--cut here--
Please note that the above __get_cpuid_subleaf also checks return value from
subleaf = 0 and fails if requested subleaf is out of allowed range.