Advertisement
Guest User

Untitled

a guest
May 4th, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define BIT_MASK(a, b) (size_t)(((size_t) -1 >> ((sizeof(size_t)*8) \
  4. - (b))) & ~((1U << (a)) - 1))
  5.  
  6. unsigned address_to_set(size_t address) {
  7. return ((address & BIT_MASK(6, 12)) >> 6);
  8. }
  9.  
  10. typedef struct item_t {
  11. double a1;
  12. double b2;
  13. double c3;
  14. double d4;
  15. double e5;
  16. double f6;
  17. double g7;
  18. double h8;
  19. int dummy; // padding
  20. };
  21.  
  22.  
  23. void mul()
  24. {
  25. struct item_t item[1024];
  26.  
  27. /*
  28. * 64 will make it jump to the next cache line in same
  29. * set when the dummy variable is not present
  30. *
  31. * */
  32. int i;
  33. for (i=0; i<1024; i+=64) {
  34. item[i].b2 = 23;
  35. #ifdef DEBUG
  36. printf("%p\t%d\n", &(item[i]), address_to_set(&item[i]));
  37. #endif
  38. }
  39.  
  40. ;
  41. for (i=0; i<1024; i+=64) {
  42. item[i].h8 = 23;
  43. #ifdef DEBUG
  44. printf("%p\t%d\n", &(item[i]), address_to_set(&item[i]));
  45. #endif
  46. }
  47.  
  48. }
  49.  
  50.  
  51. int main(void)
  52. {
  53. mul();
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement