00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef _MACHINE_ENDIAN_H_
00034 #define _MACHINE_ENDIAN_H_
00035
00036 #include <sys/cdefs.h>
00037 #include <sys/_types.h>
00038
00039 #ifdef __cplusplus
00040 extern "C" {
00041 #endif
00042
00043
00044
00045
00046 #define _QUAD_HIGHWORD 1
00047 #define _QUAD_LOWWORD 0
00048
00049
00050
00051
00052
00053 #define _LITTLE_ENDIAN 1234
00054 #define _BIG_ENDIAN 4321
00055 #define _PDP_ENDIAN 3412
00056
00057 #define _BYTE_ORDER _LITTLE_ENDIAN
00058
00059
00060
00061
00062
00063 #if __BSD_VISIBLE
00064 #define LITTLE_ENDIAN _LITTLE_ENDIAN
00065 #define BIG_ENDIAN _BIG_ENDIAN
00066 #define PDP_ENDIAN _PDP_ENDIAN
00067 #define BYTE_ORDER _BYTE_ORDER
00068 #endif
00069
00070 #ifdef __SYMBIAN32__
00071
00072 #define _BYTEORDER_FUNC_DEFINED
00073
00074 #else
00075
00076 #if defined(__GNUCLIKE_ASM) && defined(__GNUCLIKE_BUILTIN_CONSTANT_P)
00077
00078 #define __word_swap_int_var(x) \
00079 __extension__ ({ register __uint32_t __X = (x); \
00080 __asm ("rorl $16, %0" : "+r" (__X)); \
00081 __X; })
00082
00083 #ifdef __OPTIMIZE__
00084
00085 #define __word_swap_int_const(x) \
00086 ((((x) & 0xffff0000) >> 16) | \
00087 (((x) & 0x0000ffff) << 16))
00088 #define __word_swap_int(x) (__builtin_constant_p(x) ? \
00089 __word_swap_int_const(x) : __word_swap_int_var(x))
00090
00091 #else
00092
00093 #define __word_swap_int(x) __word_swap_int_var(x)
00094
00095 #endif
00096
00097 #define __byte_swap_int_var(x) \
00098 __extension__ ({ register __uint32_t __X = (x); \
00099 __asm ("bswap %0" : "+r" (__X)); \
00100 __X; })
00101
00102 #ifdef __OPTIMIZE__
00103
00104 #define __byte_swap_int_const(x) \
00105 ((((x) & 0xff000000) >> 24) | \
00106 (((x) & 0x00ff0000) >> 8) | \
00107 (((x) & 0x0000ff00) << 8) | \
00108 (((x) & 0x000000ff) << 24))
00109 #define __byte_swap_int(x) (__builtin_constant_p(x) ? \
00110 __byte_swap_int_const(x) : __byte_swap_int_var(x))
00111
00112 #else
00113
00114 #define __byte_swap_int(x) __byte_swap_int_var(x)
00115
00116 #endif
00117
00118 #define __byte_swap_word_var(x) \
00119 __extension__ ({ register __uint16_t __X = (x); \
00120 __asm ("xchgb %h0, %b0" : "+q" (__X)); \
00121 __X; })
00122
00123 #ifdef __OPTIMIZE__
00124
00125 #define __byte_swap_word_const(x) \
00126 ((((x) & 0xff00) >> 8) | \
00127 (((x) & 0x00ff) << 8))
00128
00129 #define __byte_swap_word(x) (__builtin_constant_p(x) ? \
00130 __byte_swap_word_const(x) : __byte_swap_word_var(x))
00131
00132 #else
00133
00134 #define __byte_swap_word(x) __byte_swap_word_var(x)
00135
00136 #endif
00137
00138 static __inline __uint64_t
00139 __bswap64(__uint64_t _x)
00140 {
00141
00142 return ((_x >> 56) | ((_x >> 40) & 0xff00) | ((_x >> 24) & 0xff0000) |
00143 ((_x >> 8) & 0xff000000) | ((_x << 8) & ((__uint64_t)0xff << 32)) |
00144 ((_x << 24) & ((__uint64_t)0xff << 40)) |
00145 ((_x << 40) & ((__uint64_t)0xff << 48)) | ((_x << 56)));
00146 }
00147
00148 static __inline __uint32_t
00149 __bswap32(__uint32_t _x)
00150 {
00151
00152 return (__byte_swap_int(_x));
00153 }
00154
00155 static __inline __uint16_t
00156 __bswap16(__uint16_t _x)
00157 {
00158
00159 return (__byte_swap_word(_x));
00160 }
00161
00162 #define __htonl(x) __bswap32(x)
00163 #define __htons(x) __bswap16(x)
00164 #define __ntohl(x) __bswap32(x)
00165 #define __ntohs(x) __bswap16(x)
00166
00167 #else
00168
00169
00170
00171
00172
00173
00174 #define _BYTEORDER_FUNC_DEFINED
00175
00176 #endif
00177 #endif
00178
00179 #ifdef __cplusplus
00180 }
00181 #endif
00182
00183 #endif