Reputation: 88
I am trying compile a c++ code. but I am getting an error on power8 architecture. which is working fine in x86_64 architectures. below is the error I am getting.
error: impossible register constraint in 'asm'
: "a"(func));
^
Below is the code block where I am getting that error.
static INLINE void cpuid(int *dest, int func)
{
__asm__ volatile("cpuid"
: "=a"(dest[0]), "=b"(dest[1]), "=c"(dest[2]), "=d"(dest[3])
: "a"(func));
}
is something is wrong in this code or I am missing something?
Or is there any other way to get the cpu id?
Thanks in advance!
Upvotes: 1
Views: 812
Reputation: 22348
As mentioned, cpuid
is an instruction in x86-64 (AMD64 / EMT64) and later x86 (IA32) processors, and has nothing to do with powerpc. As far as I know, there's no equivalent of such an instruction for powerpc (at least not unprivileged instructions) mandated by the powerpc specification, so operating systems have their own approaches.
On some systems, e.g., BSD variants, this might be as simple as: sysctl <option>
You could have a look at the strategies used by gcc
to determine the powerpc
and power
processor versions for different operating systems:
From the current gcc-8.1.0
source: driver-powerpcspe.c
, driver-rs6000.c
might provide some code you can adapt.
Another interesting source might be the autotools infrastructure for the GMP library; specifically, the top-level config.guess
and configure.ac
files.
Also: gcc -march=native -E -dM - < /dev/null
on a power[pc] host might allow you to grep for a CPU and/or subtype string.
Upvotes: 3