Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __BARRY_ENDIAN_H__
00023 #define __BARRY_ENDIAN_H__
00024
00025
00026
00027 #include "config.h"
00028 #include <stdint.h>
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 static inline unsigned short bbswap_16(unsigned short x) {
00039 return (x>>8) | (x<<8);
00040 }
00041
00042 static inline unsigned int bbswap_32(unsigned int x) {
00043 return (bbswap_16(x&0xffff)<<16) | (bbswap_16(x>>16));
00044 }
00045
00046 static inline uint64_t bbswap_64(uint64_t x) {
00047 return (((uint64_t)bbswap_32(x&0xffffffffull))<<32) | (bbswap_32(x>>32));
00048 }
00049
00050 #ifndef WORDS_BIGENDIAN
00051
00052
00053 #define btohs(x) x // for uint16_t
00054 #define btohl(x) x // for uint32_t
00055 #define btohll(x) x // for uint64_t
00056 #define htobs(x) x // for uint16_t
00057 #define htobl(x) x // for uint32_t
00058 #define htobll(x) x // for uint64_t
00059
00060
00061 #define be_btohs(x) bbswap_16(x) // for uint16_t
00062 #define be_btohl(x) bbswap_32(x) // for uint32_t
00063 #define be_btohll(x) bbswap_64(x) // for uint64_t
00064 #define be_htobs(x) bbswap_16(x) // for uint16_t
00065 #define be_htobl(x) bbswap_32(x) // for uint32_t
00066 #define be_htobll(x) bbswap_64(x) // for uint64_t
00067
00068 #else
00069
00070
00071 #define btohs(x) bbswap_16(x) // for uint16_t
00072 #define btohl(x) bbswap_32(x) // for uint32_t
00073 #define btohll(x) bbswap_64(x) // for uint64_t
00074 #define htobs(x) bbswap_16(x) // for uint16_t
00075 #define htobl(x) bbswap_32(x) // for uint32_t
00076 #define htobll(x) bbswap_64(x) // for uint64_t
00077
00078
00079 #define be_btohs(x) x // for uint16_t
00080 #define be_btohl(x) x // for uint32_t
00081 #define be_btohll(x) x // for uint64_t
00082 #define be_htobs(x) x // for uint16_t
00083 #define be_htobl(x) x // for uint32_t
00084 #define be_htobll(x) x // for uint64_t
00085
00086 #endif
00087
00088 #endif
00089