Rev 2479 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2479 | Rev 2795 | ||
---|---|---|---|
Line 35... | Line 35... | ||
35 | #ifndef LIBC_ENDIAN_H_ |
35 | #ifndef LIBC_ENDIAN_H_ |
36 | #define LIBC_ENDIAN_H_ |
36 | #define LIBC_ENDIAN_H_ |
37 | 37 | ||
38 | #define __LITTLE_ENDIAN 1234 |
38 | #define __LITTLE_ENDIAN 1234 |
39 | #define __BIG_ENDIAN 4321 |
39 | #define __BIG_ENDIAN 4321 |
40 | #define __PDP_ENDIAN 3412 |
- | |
41 | 40 | ||
- | 41 | #include <stdint.h> |
|
42 | #include <libarch/endian.h> |
42 | #include <libarch/endian.h> |
43 | 43 | ||
- | 44 | #if (__BYTE_ORDER == __BIG_ENDIAN) |
|
- | 45 | ||
- | 46 | #define uint16_t_le2host(n) uint16_t_byteorder_swap(n) |
|
- | 47 | #define uint32_t_le2host(n) uint32_t_byteorder_swap(n) |
|
- | 48 | #define uint64_t_le2host(n) uint64_t_byteorder_swap(n) |
|
- | 49 | ||
- | 50 | #define uint16_t_be2host(n) (n) |
|
- | 51 | #define uint32_t_be2host(n) (n) |
|
- | 52 | #define uint64_t_be2host(n) (n) |
|
- | 53 | ||
- | 54 | #else |
|
- | 55 | ||
- | 56 | #define uint16_t_le2host(n) (n) |
|
- | 57 | #define uint32_t_le2host(n) (n) |
|
- | 58 | #define uint64_t_le2host(n) (n) |
|
- | 59 | ||
- | 60 | #define uint16_t_be2host(n) uint16_t_byteorder_swap(n) |
|
- | 61 | #define uint32_t_be2host(n) uint32_t_byteorder_swap(n) |
|
- | 62 | #define uint64_t_be2host(n) uint64_t_byteorder_swap(n) |
|
- | 63 | ||
- | 64 | #endif |
|
- | 65 | ||
- | 66 | ||
- | 67 | static inline uint64_t uint64_t_byteorder_swap(uint64_t n) |
|
- | 68 | { |
|
- | 69 | return ((n & 0xff) << 56) | |
|
- | 70 | ((n & 0xff00) << 40) | |
|
- | 71 | ((n & 0xff0000) << 24) | |
|
- | 72 | ((n & 0xff000000LL) << 8) | |
|
- | 73 | ((n & 0xff00000000LL) >> 8) | |
|
- | 74 | ((n & 0xff0000000000LL) >> 24) | |
|
- | 75 | ((n & 0xff000000000000LL) >> 40) | |
|
- | 76 | ((n & 0xff00000000000000LL) >> 56); |
|
- | 77 | } |
|
- | 78 | ||
- | 79 | static inline uint32_t uint32_t_byteorder_swap(uint32_t n) |
|
- | 80 | { |
|
- | 81 | return ((n & 0xff) << 24) | |
|
- | 82 | ((n & 0xff00) << 8) | |
|
- | 83 | ((n & 0xff0000) >> 8) | |
|
- | 84 | ((n & 0xff000000) >> 24); |
|
- | 85 | } |
|
- | 86 | ||
- | 87 | static inline uint16_t uint16_t_byteorder_swap(uint16_t n) |
|
- | 88 | { |
|
- | 89 | return ((n & 0xff) << 8) | |
|
- | 90 | ((n & 0xff00) >> 8); |
|
- | 91 | } |
|
- | 92 | ||
44 | #endif |
93 | #endif |
45 | 94 | ||
46 | /** @} |
95 | /** @} |
47 | */ |
96 | */ |