#ifndef _COMPILER_H_ #define _COMPILER_H_ #include #ifdef __GNUC__ # define __packed __attribute__ ((packed)) # define __unused __attribute__ ((unused)) # define __noreturn __attribute__ ((noreturn)) # define likely(x) __builtin_expect(!!(x), 1) # define unlikely(x) __builtin_expect(!!(x), 0) static inline void prefetch(const void *ptr) { /* We could use some arch specific instructions here, but a GCC builtin is fine for now */ __builtin_prefetch(ptr, 0, 3); } static inline int32_t bswap_32(int32_t x) { return __builtin_bswap32(x); } #else # define __packed # define __unused # define __noreturn # define likely(x) (x) # define unlikely(x) (x) static inline prefetch(const void *ptr) { /* empty */ } static inline int32_t bswap_32(int32_t x) { int32_t ret = 0; ret |= ((x & 0xFF000000) >> 24); ret |= ((x & 0x00FF0000) >> 8); ret |= ((x & 0x0000FF00) << 8); ret |= ((x & 0x000000FF) << 24); return ret; } #endif /* __GNUC__ */ #ifndef offsetof # define offsetof(type, member) ((size_t) &((type *)0)->member) #endif /* offsetof */ #ifndef container_of # define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type, member) );}) #endif /* container_of */ #endif /* _COMPILER_H_ */