Fennel: /home/pub/open/dev/fennel/common/CompoundId.h Source File (original) (raw)

00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 #ifndef Fennel_CompoundId_Included 00025 #define Fennel_CompoundId_Included 00026 00027 FENNEL_BEGIN_NAMESPACE 00028 00029 00030 00031 00072 class FENNEL_COMMON_EXPORT CompoundId 00073 { 00074
00075 static const uint64_t DEVICE_ID_MASK = 0xFFF0000000000000ULL; 00076 static const uint64_t BYTE_OFFSET_MASK = 0x000FFFFF00000000ULL; 00077 static const uint64_t BLOCK_NUM_MASK = 0x00000000FFFFFFFFULL; 00078 00082 static const uint DEVICE_ID_SHIFT = 52; 00083 00087 static const uint BYTE_OFFSET_SHIFT = 32; 00088 00089 public: 00093 static const uint MAX_DEVICES = 0x1000; 00094 00098 static const uint MAX_BYTE_OFFSET = 0xFFFFF; 00099 00107 template 00108 static BlockNum getBlockNum(PageOrBlockId pageId) 00109 { 00110 return (opaqueToInt(pageId) & BLOCK_NUM_MASK); 00111 } 00112 00120 template 00121 static void setBlockNum(PageOrBlockId &pageId,BlockNum blockNum) 00122 { 00123 assert(blockNum == (blockNum & BLOCK_NUM_MASK)); 00124 pageId = PageOrBlockId( 00125 (opaqueToInt(pageId) & DEVICE_ID_MASK) | blockNum); 00126 } 00127 00133 template 00134 static void incBlockNum(PageOrBlockId &pageId) 00135 { 00136 setBlockNum(pageId,getBlockNum(pageId) + 1); 00137 } 00138 00144 template 00145 static void decBlockNum(PageOrBlockId &pageId) 00146 { 00147 setBlockNum(pageId,getBlockNum(pageId) - 1); 00148 } 00149 00157 template 00158 static DeviceId getDeviceId(PageOrBlockId pageId) 00159 { 00160 return DeviceId( 00161 (opaqueToInt(pageId) & DEVICE_ID_MASK) >> DEVICE_ID_SHIFT); 00162 } 00163 00171 template 00172 static void setDeviceId(PageOrBlockId &pageId,DeviceId deviceId) 00173 { 00174 assert(opaqueToInt(deviceId) < MAX_DEVICES); 00175 pageId = PageOrBlockId( 00176 (uint64_t(opaqueToInt(deviceId)) << DEVICE_ID_SHIFT) 00177 | getBlockNum(pageId)); 00178 } 00179 00187 static PageId getPageId(SegByteId segByteId) 00188 { 00189 return PageId(opaqueToInt(segByteId) & ~BYTE_OFFSET_MASK); 00190 } 00191 00199 static void setPageId(SegByteId &segByteId,PageId pageId) 00200 { 00201 segByteId = SegByteId( 00202 opaqueToInt(pageId) 00203 | (opaqueToInt(segByteId) & BYTE_OFFSET_MASK)); 00204 } 00205 00213 static uint getByteOffset(SegByteId segByteId) 00214 { 00215 return (opaqueToInt(segByteId) & BYTE_OFFSET_MASK) >> BYTE_OFFSET_SHIFT; 00216 } 00217 00225 static void setByteOffset(SegByteId &segByteId,uint offset) 00226 { 00227 assert(offset == (offset & (BYTE_OFFSET_MASK >> BYTE_OFFSET_SHIFT))); 00228 segByteId = SegByteId( 00229 opaqueToInt(getPageId(segByteId)) 00230 | (SegByteIdPrimitive(offset) << BYTE_OFFSET_SHIFT)); 00231 } 00232 00243 static int comparePageIds(PageId p1,PageId p2) 00244 { 00245 return (p1 > p2) ? 1 00246 : ((p1 < p2) ? -1 : 0); 00247 } 00248 00259 static int compareSegByteIds(SegByteId t1,SegByteId t2) 00260 { 00261 return (t1 > t2) ? 1 00262 : ((t1 < t2) ? -1 : 0); 00263 } 00264 00269 static uint getMaxDeviceCount() 00270 { 00271 return MAX_DEVICES; 00272 } 00273 }; 00274 00275 FENNEL_END_NAMESPACE 00276 00277 #endif 00278 00279