fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct sse_t1 {
  5. float sse_data[4];
  6. };
  7.  
  8. // the array "cacheline" will be aligned to 64-byte boundary
  9. struct sse_t1 alignas(64) cacheline1[1000000];
  10.  
  11. // every object of type sse_t will be aligned to 64-byte boundary
  12. struct sse_t2 {
  13. float sse_data[4];
  14. } __attribute((aligned(64)));
  15.  
  16. struct sse_t2 cacheline2[1000000];
  17.  
  18. int main() {
  19. cout << "sizeof(sse_t1) = " << sizeof(sse_t1) << endl;
  20. cout << "sizeof(sse_t2) = " << sizeof(sse_t2) << endl;
  21.  
  22. cout << "array cacheline1 " << (((size_t)(cacheline1) % 64 == 0)?"aligned to 64":"not aligned to 64") << endl;
  23. cout << "array cacheline2 " << (((size_t)(cacheline2) % 64 == 0)?"aligned to 64":"not aligned to 64") << endl;
  24.  
  25. cout << "cacheline1[0] - cacheline1[1] = " << (size_t)&(cacheline1[1]) - (size_t)&(cacheline1[0]) << endl;
  26. cout << "cacheline2[0] - cacheline2[1] = " << (size_t)&(cacheline2[1]) - (size_t)&(cacheline2[0]) << endl;
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0s 81408KB
stdin
Standard input is empty
stdout
sizeof(sse_t1) = 16
sizeof(sse_t2) = 64
array cacheline1 aligned to 64
array cacheline2 aligned to 64
cacheline1[0] - cacheline1[1] = 16
cacheline2[0] - cacheline2[1] = 64