00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef PED_ENDIAN_H_INCLUDED
00023 #define PED_ENDIAN_H_INCLUDED
00024
00025 #include <config.h>
00026 #include <stdint.h>
00027
00028
00029 #define _GET_BYTE(x, n) ( ((x) >> (8 * (n))) & 0xff )
00030
00031 #define _PED_SWAP16(x) ( (_GET_BYTE(x, 0) << 8) \
00032 + (_GET_BYTE(x, 1) << 0) )
00033
00034 #define _PED_SWAP32(x) ( (_GET_BYTE(x, 0) << 24) \
00035 + (_GET_BYTE(x, 1) << 16) \
00036 + (_GET_BYTE(x, 2) << 8) \
00037 + (_GET_BYTE(x, 3) << 0) )
00038
00039 #define _PED_SWAP64(x) ( (_GET_BYTE(x, 0) << 56) \
00040 + (_GET_BYTE(x, 1) << 48) \
00041 + (_GET_BYTE(x, 2) << 40) \
00042 + (_GET_BYTE(x, 3) << 32) \
00043 + (_GET_BYTE(x, 4) << 24) \
00044 + (_GET_BYTE(x, 5) << 16) \
00045 + (_GET_BYTE(x, 6) << 8) \
00046 + (_GET_BYTE(x, 7) << 0) )
00047
00048 #define PED_SWAP16(x) ((uint16_t) _PED_SWAP16( (uint16_t) (x) ))
00049 #define PED_SWAP32(x) ((uint32_t) _PED_SWAP32( (uint32_t) (x) ))
00050 #define PED_SWAP64(x) ((uint64_t) _PED_SWAP64( (uint64_t) (x) ))
00051
00052 #ifdef WORDS_BIGENDIAN
00053
00054 #define PED_CPU_TO_LE16(x) PED_SWAP16(x)
00055 #define PED_CPU_TO_BE16(x) (x)
00056 #define PED_CPU_TO_LE32(x) PED_SWAP32(x)
00057 #define PED_CPU_TO_BE32(x) (x)
00058 #define PED_CPU_TO_LE64(x) PED_SWAP64(x)
00059 #define PED_CPU_TO_BE64(x) (x)
00060
00061 #define PED_LE16_TO_CPU(x) PED_SWAP16(x)
00062 #define PED_BE16_TO_CPU(x) (x)
00063 #define PED_LE32_TO_CPU(x) PED_SWAP32(x)
00064 #define PED_BE32_TO_CPU(x) (x)
00065 #define PED_LE64_TO_CPU(x) PED_SWAP64(x)
00066 #define PED_BE64_TO_CPU(x) (x)
00067
00068 #else
00069
00070 #define PED_CPU_TO_LE16(x) (x)
00071 #define PED_CPU_TO_BE16(x) PED_SWAP16(x)
00072 #define PED_CPU_TO_LE32(x) (x)
00073 #define PED_CPU_TO_BE32(x) PED_SWAP32(x)
00074 #define PED_CPU_TO_LE64(x) (x)
00075 #define PED_CPU_TO_BE64(x) PED_SWAP64(x)
00076
00077 #define PED_LE16_TO_CPU(x) (x)
00078 #define PED_BE16_TO_CPU(x) PED_SWAP16(x)
00079 #define PED_LE32_TO_CPU(x) (x)
00080 #define PED_BE32_TO_CPU(x) PED_SWAP32(x)
00081 #define PED_LE64_TO_CPU(x) (x)
00082 #define PED_BE64_TO_CPU(x) PED_SWAP64(x)
00083
00084 #endif
00085
00086 #endif
00087