Here is teh code
Normal memory increment never takes more than couple of hundreds nanoseconds. Unless it is a locked cache line split increment. Good catch, obvious reasons.
static unsigned char array[128];
void main()
{
for (i = 0; i < 64; i++) if ((int)(array + i) % 64 == 63) break;
lock = (unsigned int*)(array + i);
for (i = 0; i < 1024; i++) *(lock)++; // prime
// TSC1
for (i = 0; i < 1024*8; i++)
{
asm volatile (
"lock xaddl %1, (%0)\n"
: // no output
: "r" (lock), "r" (1));
}
// TSC2
printf(" %i\n", (TSC2-TSC1)/1024*8);
}Normal memory increment never takes more than couple of hundreds nanoseconds. Unless it is a locked cache line split increment. Good catch, obvious reasons.