问题
CPUID can be used as a serializing instruction as described here and here. What is the minimal/simplest asm syntax to use it in that way in C++?
// Is that enough?
// What to do with registers and memory?
// Is volatile necessary?
asm volatile("CPUID":::);
回答1:
Is there a reason you're not using the fence operations? If the goal is to serialize a section of code you can do something like
asm __volatile__ (
" mfence \n"
" lfence \n"
);
Your code
asm __volatile__ (
" mfence \n"
" lfence \n"
);
来源:https://stackoverflow.com/questions/48502569/how-to-use-cpuid-as-a-serializing-instruction