Flush out an array from the cache on Intel Processors

The following C code flushes out the table from all caches. It works on Intel Core 2 Duo and above and doesn't work on Pentium 3. I haven't checked on Pentium 4.

#define CACHE_LINE_SIZE    64
unsigned char table[256];

void clean_tables()
{
    int i;
    for(i=0; i<256; i+=CACHE_LINE_SIZE){
        asm volatile("clflush (%0)" :: "r" (table+i));
    }
}

Followers