Changeset View
Changeset View
Standalone View
Standalone View
sys/mips/include/endian.h
Show First 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | |||||
#if __BSD_VISIBLE | #if __BSD_VISIBLE | ||||
#define LITTLE_ENDIAN _LITTLE_ENDIAN | #define LITTLE_ENDIAN _LITTLE_ENDIAN | ||||
#define BIG_ENDIAN _BIG_ENDIAN | #define BIG_ENDIAN _BIG_ENDIAN | ||||
#define PDP_ENDIAN _PDP_ENDIAN | #define PDP_ENDIAN _PDP_ENDIAN | ||||
#define BYTE_ORDER _BYTE_ORDER | #define BYTE_ORDER _BYTE_ORDER | ||||
#endif | #endif | ||||
#ifndef __ASSEMBLER__ | #ifndef __ASSEMBLER__ | ||||
#if defined(__GNUCLIKE_BUILTIN_CONSTANT_P) && defined(__OPTIMIZE__) | |||||
#define __is_constant(x) __builtin_constant_p(x) | |||||
#else | |||||
#define __is_constant(x) 0 | |||||
#endif | |||||
#define __bswap16_const(x) (((x) >> 8) | (((x) << 8) & 0xff00)) | #define __bswap16(x) __builtin_bswap16(x) | ||||
#define __bswap32_const(x) (((x) >> 24) | (((x) >> 8) & 0xff00) | \ | #define __bswap32(x) __builtin_bswap32(x) | ||||
(((x) << 8) & 0xff0000) | (((x) << 24) & 0xff000000)) | #define __bswap64(x) __builtin_bswap64(x) | ||||
#define __bswap64_const(x) (((x) >> 56) | (((x) >> 40) & 0xff00) | \ | |||||
(((x) >> 24) & 0xff0000) | (((x) >> 8) & 0xff000000) | \ | |||||
(((x) << 8) & ((__uint64_t)0xff << 32)) | \ | |||||
(((x) << 24) & ((__uint64_t)0xff << 40)) | \ | |||||
(((x) << 40) & ((__uint64_t)0xff << 48)) | (((x) << 56))) | |||||
static __inline __uint16_t | |||||
__bswap16_var(__uint16_t _x) | |||||
{ | |||||
return ((_x >> 8) | ((_x << 8) & 0xff00)); | |||||
} | |||||
static __inline __uint32_t | |||||
__bswap32_var(__uint32_t _x) | |||||
{ | |||||
return ((_x >> 24) | ((_x >> 8) & 0xff00) | ((_x << 8) & 0xff0000) | | |||||
((_x << 24) & 0xff000000)); | |||||
} | |||||
static __inline __uint64_t | |||||
__bswap64_var(__uint64_t _x) | |||||
{ | |||||
return ((_x >> 56) | ((_x >> 40) & 0xff00) | ((_x >> 24) & 0xff0000) | | |||||
((_x >> 8) & 0xff000000) | ((_x << 8) & ((__uint64_t)0xff << 32)) | | |||||
((_x << 24) & ((__uint64_t)0xff << 40)) | | |||||
((_x << 40) & ((__uint64_t)0xff << 48)) | ((_x << 56))); | |||||
} | |||||
#define __bswap16(x) ((__uint16_t)(__is_constant((x)) ? \ | |||||
__bswap16_const((__uint16_t)(x)) : __bswap16_var((__uint16_t)(x)))) | |||||
#define __bswap32(x) ((__uint32_t)(__is_constant((x)) ? \ | |||||
__bswap32_const((__uint32_t)(x)) : __bswap32_var((__uint32_t)(x)))) | |||||
#define __bswap64(x) ((__uint64_t)(__is_constant((x)) ? \ | |||||
__bswap64_const((__uint64_t)(x)) : __bswap64_var((__uint64_t)(x)))) | |||||
#ifdef __MIPSEB__ | #ifdef __MIPSEB__ | ||||
#define __htonl(x) ((__uint32_t)(x)) | #define __htonl(x) ((__uint32_t)(x)) | ||||
#define __htons(x) ((__uint16_t)(x)) | #define __htons(x) ((__uint16_t)(x)) | ||||
#define __ntohl(x) ((__uint32_t)(x)) | #define __ntohl(x) ((__uint32_t)(x)) | ||||
#define __ntohs(x) ((__uint16_t)(x)) | #define __ntohs(x) ((__uint16_t)(x)) | ||||
/* | /* | ||||
* Define the order of 32-bit words in 64-bit words. | * Define the order of 32-bit words in 64-bit words. | ||||
Show All 22 Lines |