Reputation: 1857
I found that in Linux kernel, the clflush
function is implemented as
asm volatile("clflush %0" : "+m" (*(volatile char __force *)__p));
I don't quite understand why +m is used here?
In my understanding, shouldn't it be implemented as
asm volatile ("clflush (%0)" :: "r"(p));
Upvotes: 1
Views: 454
Reputation: 11706
Either form of the instruction works since they both refer to the same address. However, by using +m
as the constraint, it ensures that any optimization done with the code (since the function is inline) doesn't assume the data stored in the pointer __p
is preserved. In other words, it prevents invalid optimization.
Upvotes: 3