00001 #ifndef _BYTESEX_H
00002 #define _BYTESEX_H
00003
00004
00005
00006
00007
00008 #define const_bswap16(x) \
00009 ((uint16_t)( \
00010 (((uint16_t)(x) & (uint16_t)0x00ffU) << 8) | \
00011 (((uint16_t)(x) & (uint16_t)0xff00U) >> 8)))
00012
00013 #define const_bswap32(x) \
00014 ((uint32_t)( \
00015 (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) | \
00016 (((uint32_t)(x) & (uint32_t)0x0000ff00UL) << 8) | \
00017 (((uint32_t)(x) & (uint32_t)0x00ff0000UL) >> 8) | \
00018 (((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24)))
00019
00020 static inline uint16_t sys_bswap16(uint16_t x)
00021 {
00022 return const_bswap16(x);
00023 }
00024
00025 static inline uint32_t sys_bswap32(uint32_t x)
00026 {
00027 return const_bswap32(x);
00028 }
00029
00030 static inline uint32_t sys_bswapf(uint32_t x)
00031 {
00032 return const_bswap32(((float)x));
00033 }
00034
00035 #if __BYTE_ORDER == __BIG_ENDIAN && !_OS__WIN32
00036 #define sys_lefloat(x) sys_bswapf(x)
00037 #define sys_le32(x) sys_bswap32(x)
00038 #define sys_le16(x) sys_bswap16(x)
00039 #define sys_befloat(x) (x)
00040 #define sys_be32(x) (x)
00041 #define sys_be16(x) (x)
00042 #define const_le32(x) const_bswap32(x)
00043 #define const_le16(x) const_bswap16(x)
00044 #define const_be32(x) (x)
00045 #define const_be16(x) (x)
00046 #elif __BYTE_ORDER == __LITTLE_ENDIAN
00047 #define sys_lefloat(x) (x)
00048 #define sys_le32(x) (x)
00049 #define sys_le16(x) (x)
00050 #define sys_befloat(x) sys_bswapf(x)
00051 #define sys_be32(x) sys_bswap32(x)
00052 #define sys_be16(x) sys_bswap16(x)
00053 #define const_le32(x) (x)
00054 #define const_le16(x) (x)
00055 #define const_be32(x) const_bswap32(x)
00056 #define const_be16(x) const_bswap16(x)
00057 #else
00058 #error "PDP-11 huh?"
00059 #endif
00060
00061 #endif