macros.h
changeset 2086 5c32d85b589a
parent 1981 3c9c682f1212
child 2159 f6284cf5fab0
equal deleted inserted replaced
2085:876f20a0e843 2086:5c32d85b589a
   151 	static inline uint16 READ_LE_UINT16(const void *b) {
   151 	static inline uint16 READ_LE_UINT16(const void *b) {
   152 		return ((const byte*)b)[0] + (((const byte*)b)[1] << 8);
   152 		return ((const byte*)b)[0] + (((const byte*)b)[1] << 8);
   153 	}
   153 	}
   154 #endif
   154 #endif
   155 
   155 
   156 // Fetch count bits starting at bit start from value
   156 /// Fetch n bits starting at bit s from x
   157 #define GB(value, start, count) (((value) >> (start)) & ((1 << (count)) - 1))
   157 #define GB(x, s, n) (((x) >> (s)) & ((1 << (n)) - 1))
   158 // Set count bits in value starting at bit start to data
   158 /// Set n bits in x starting at bit s to d
   159 #define SB(value, start, count, data) ((value) = ((value) & ~(((1 << (count)) - 1) << (start))) | ((data) << (start)))
   159 #define SB(x, s, n, d) ((x) = ((x) & ~(((1 << (n)) - 1) << (s))) | ((d) << (s)))
       
   160 
       
   161 /**
       
   162  * ROtate x Left/Right by n (must be >= 0)
       
   163  * @note Assumes a byte has 8 bits
       
   164  */
       
   165 #define ROL(x, n) ((x) << (n) | (x) >> (sizeof(x) * 8 - (n)))
       
   166 #define ROR(x, n) ((x) >> (n) | (x) << (sizeof(x) * 8 - (n)))
   160 
   167 
   161 #endif /* MACROS_H */
   168 #endif /* MACROS_H */