00001 // one element per cache line storage -*- C++ -*- 00002 /* 00003 Galois, a framework to exploit amorphous data-parallelism in irregular 00004 programs. 00005 00006 Copyright (C) 2011, The University of Texas at Austin. All rights reserved. 00007 UNIVERSITY EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES CONCERNING THIS SOFTWARE 00008 AND DOCUMENTATION, INCLUDING ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR ANY 00009 PARTICULAR PURPOSE, NON-INFRINGEMENT AND WARRANTIES OF PERFORMANCE, AND ANY 00010 WARRANTY THAT MIGHT OTHERWISE ARISE FROM COURSE OF DEALING OR USAGE OF TRADE. 00011 NO WARRANTY IS EITHER EXPRESS OR IMPLIED WITH RESPECT TO THE USE OF THE 00012 SOFTWARE OR DOCUMENTATION. Under no circumstances shall University be liable 00013 for incidental, special, indirect, direct or consequential damages or loss of 00014 profits, interruption of business, or related expenses which may arise from use 00015 of Software or Documentation, including but not limited to those resulting from 00016 defects in Software and/or Documentation, or loss or inaccuracy of data of any 00017 kind. 00018 */ 00019 00020 #ifndef __CACHE_LINE_STORAGE_H 00021 #define __CACHE_LINE_STORAGE_H 00022 00023 namespace GaloisRuntime { 00024 00025 //xeons have 64 byte cache lines, but will prefetch 2 at a time 00026 #define CACHE_LINE_SIZE 128 00027 00028 // Store an item with padding 00029 template<typename T> 00030 struct cache_line_storage { 00031 T data __attribute__((aligned(CACHE_LINE_SIZE))); 00032 char pad[ CACHE_LINE_SIZE % sizeof(T) ? 00033 CACHE_LINE_SIZE - (sizeof(T) % CACHE_LINE_SIZE) : 00034 0 ]; 00035 cache_line_storage() :data() {} 00036 }; 00037 00038 // Store an item with padding 00039 template<typename T> 00040 class cache_line_storage2 { 00041 T data __attribute__((aligned(CACHE_LINE_SIZE))); 00042 char pad[ CACHE_LINE_SIZE % sizeof(T) ? 00043 CACHE_LINE_SIZE - (sizeof(T) % CACHE_LINE_SIZE) : 00044 0 ]; 00045 cache_line_storage2() :data() {} 00046 explicit cache_line_storage2(const T& d) :data(d) {} 00047 }; 00048 00049 } 00050 00051 #endif