64bit Applications and Inline Assembly

Visual C++ does not support inline assembly for x64 (or ARM) processors, because generally using inline assembly is a bad idea. Usually compilers produce better assembly than humans. Even if you can produce better assembly than the compiler, using inline assembly generally defeats code optimizers of any type. Sure, your bit of hand optimized code … Read more

x86/x64 CPUID in C#

I’m fairly certain you’re being blocked by DEP. The x_CPUIDy_INSNS byte arrays are in a segment of memory marked as data and non-executable. EDIT: That being said, I’ve gotten a version that compiles and runs, but I don’t think gets the right values. Perhaps this will get you along your way. EDIT 2: I think … Read more

Reading a register value into a C variable [duplicate]

Editor’s note: this way of using a local register-asm variable is now documented by GCC as “not supported”. It still usually happens to work on GCC, but breaks with clang. (This wording in the documentation was added after this answer was posted, I think.) The global fixed-register variable version has a large performance cost for … Read more

What is the difference between ‘asm’, ‘__asm’ and ‘__asm__’?

There’s a massive difference between MSVC inline asm and GNU C inline asm. GCC syntax is designed for optimal output without wasted instructions, for wrapping a single instruction or something. MSVC syntax is designed to be fairly simple, but AFAICT it’s impossible to use without the latency and extra instructions of a round trip through … Read more

What does __asm__ __volatile__ do in C?

The __volatile__ modifier on an __asm__ block forces the compiler’s optimizer to execute the code as-is. Without it, the optimizer may think it can be either removed outright, or lifted out of a loop and cached. This is useful for the rdtsc instruction like so: __asm__ __volatile__(“rdtsc”: “=a” (a), “=d” (d) ) This takes no … Read more

tech