Changeset 4622
 Timestamp:
 Jun 30, 2009, 1:23:31 AM (15 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

source/ariba/utility/serialization/DataUtilities.hpp
r3690 r4622 71 71 #include <string> 72 72 73 template<typename X> finline 74 static X shr( const X& value, unsigned int bits ) { 75 return (sizeof(X)*8 == bits) ? 0 : (value >> bits); 76 } 77 78 template<typename X> finline 79 static X shl( const X& value, unsigned int bits ) { 80 return (sizeof(X)*8 == bits) ? 0 : (value << bits); 81 } 82 73 83 /** 74 84 * TODO: Doc … … 77 87 static X bitblk(size_t index, size_t length, bool value, if_uint(X)) { 78 88 if (index == 0 && length >= sizeof(X) * 8) return value ? ~0 : 0; 79 X x = ((((X) 1) << length)  1) << index;89 X x = shl(( shl( ((X) 1), length)  1), index); 80 90 return value ? x : ~x; 81 91 } … … 107 117 if (srcInvert) srcIdx = sizeof(X) * 8  srcIdx  len; 108 118 if (dstInvert) dstIdx = sizeof(Y) * 8  dstIdx  len; 109 Y value = ((Y) (src >>srcIdx)) << dstIdx;119 Y value = ((Y)shr(src, srcIdx)) << dstIdx; 110 120 Y mask = bitblk<Y, 0> (dstIdx, len); 111 121 return (dst & mask)  (value & ~mask); … … 136 146 // check if first word only is affected 137 147 if ((dwp + len) <= w) { 138 X fw = (src[0] << swp)  (src[1] >>iswp);148 X fw = shl(src[0],swp)  shr(src[1],iswp); 139 149 *dst = bitcpy(fw, 0, *dst, dwp, len, true, true); 140 150 return; … … 143 153 // set first word 144 154 if (idwp != 0) { 145 X fw = (src[0] << swp)  (src[1] >>iswp);146 *dst = (*dst & ~(((X) 1 << idwp)  1))  (fw >>dwp);155 X fw = shl(src[0],swp)  shr(src[1],iswp); 156 *dst = (*dst & ~(((X) 1 << idwp)  1))  shr(fw,dwp); 147 157 148 158 // recalculate indexes & lengths … … 169 179 a = src[0], b = src[1]; 170 180 while (len >= w) { 171 *dst = (a << swp)  (b >>iswp);181 *dst = shl(a,swp)  shr(b,iswp); 172 182 dst++; 173 183 src++; … … 179 189 180 190 // set last word 181 X lw = (a << swp)  (b >> iswp), lm = (((X) 1 <<(w  len))  1);191 X lw = shl(a,swp)  shr(b,iswp), lm = (shl((X) 1,(w  len))  1); 182 192 *dst = (*dst & lm)  (lw & ~lm); 183 193 } 194 195 184 196 185 197 /** … … 205 217 src++; 206 218 while (len >= w) { 207 X x = (a << swp)  (b >>iswp);219 X x = shl(a,swp)  shr(b,iswp); 208 220 value <<= w; 209 221 value = x; … … 216 228 if ( len> 0 ) { 217 229 value <<= len; 218 value = (( (a << swp)  (b >> iswp)) >> (w  len)) & ((1 <<len)1);230 value = ((shl(a,swp)  shr(b,iswp)) >> (w  len)) & (shl(1,len)1); 219 231 } 220 232 … … 254 266 size_t idwp = w  dwp; 255 267 src >>= srcIdx; 256 X mask1 = ~( (1 <<idwp)  1);257 dst[0] = (dst[0] & mask1)  ( (src >>(len  idwp)) & ~mask1);258 X mask2 = (1 <<(w  len + idwp))  1;259 dst[1] = (dst[1] & mask2)  ( (src <<(w  len + idwp)) & ~mask2);268 X mask1 = ~(shl(1,idwp)  1); 269 dst[0] = (dst[0] & mask1)  (shr(src,(len  idwp)) & ~mask1); 270 X mask2 = shl(1,(w  len + idwp))  1; 271 dst[1] = (dst[1] & mask2)  (shl(src, (w  len + idwp)) & ~mask2); 260 272 } 261 273 } … … 277 289 // check inversion 278 290 if (srcInvert) srcIdx = sizeof(Y) * 8  srcIdx  len; 279 src >>= srcIdx;291 src = shr(src, srcIdx); 280 292 281 293 const size_t dw = sizeof(X)*8; 282 294 while (len >= dw) { 283 X word = (X) (src >>(lendw));295 X word = (X)shr(src,(lendw)); 284 296 bitcpy(word,0,dst,dstIdx,dw); 285 297 dstIdx += dw;
Note:
See TracChangeset
for help on using the changeset viewer.