I have been porting a linux application to windows platform.
Here is the linux code,
__asm__ __volatile__ ("lock; cmpxchgl %1, %2"
: "=a" (prev)
: "q" (new_value), "m" (*ptr), "0" (old_value)
: "memory");
I tried using _asm volatile but I get an error saying "inline assembler syntax error in 'opcode'; found 'data type'" in Visual studio 2012.
I need something windows equivalent code. Any info/suggestion please.
In general, I prefer external assembly modules to inline assembly - it's more portable (yeah, portable and assembly used in the same sentence). Assemblers like nasm and yasm are available for multiple platforms, and can produce multiple object file formats.
External assembly modules aren't good for really performance-critical one-liners like your code - consider using compiler intrinsics instead of inline assembly. You might want to check out Portable Compare And Swap.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With