Last active
August 29, 2015 14:17
-
-
Save goyalankit/9abb2e281cae55b1b1c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define BIT_MASK(a, b) (size_t)(((size_t) -1 >> ((sizeof(size_t)*8) \ | |
- (b))) & ~((1U << (a)) - 1)) | |
unsigned address_to_set(size_t address) { | |
return ((address & BIT_MASK(6, 12)) >> 6); | |
} | |
typedef struct item_t { | |
double a1; | |
double b2; | |
double c3; | |
double d4; | |
double e5; | |
double f6; | |
double g7; | |
double h8; | |
int dummy; // padding | |
}; | |
void mul() | |
{ | |
struct item_t item[1024]; | |
/* | |
* 64 will make it jump to the next cache line in same | |
* set when the dummy variable is not present | |
* | |
* */ | |
int i; | |
for (i=0; i<1024; i+=64) { | |
item[i].b2 = 23; | |
#ifdef DEBUG | |
printf("%p\t%d\n", &(item[i]), address_to_set(&item[i])); | |
#endif | |
} | |
; | |
for (i=0; i<1024; i+=64) { | |
item[i].h8 = 23; | |
#ifdef DEBUG | |
printf("%p\t%d\n", &(item[i]), address_to_set(&item[i])); | |
#endif | |
} | |
} | |
int main(void) | |
{ | |
mul(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment