I'm writing codes to get cpu information to identify a cpu. And I find answer from this is exactly what I need.
void getCpuid(std::uint32_t *p)
{
__asm__ __volatile__ ("cpuid"
: "=a"(p[0]),
"=b"(p[1]),
"=c"(p[2]),
"=d"(p[3])
: "0"(p[0]), "2"(p[2])
: "memory");
}
Call it by: std::uint32_t cpuinfo[4]={1,0,0,0}; getCpuid(cpuinfo);
.
When I compile these codes under a docker(arm-ubuntu 18.04 for Nvidia jetson), errors show up:
xxx.cpp:20:34: error: impossible constraint in 'asm'
Firstly, I thought some syntax errors(I don‘t know this asm
keyword before and don't know anything about assemble codes), so I searched a lot threads, but none helps。But then, I tried compile this in my host device(x86 ubuntu 18.04). It compiles! And run it I get the cpu information.
Now, I'm confused.