File tree Expand file tree Collapse file tree 1 file changed +6
-12
lines changed Expand file tree Collapse file tree 1 file changed +6
-12
lines changed Original file line number Diff line number Diff line change 33#ifndef _RISCV_BYTEORDER_H
44#define _RISCV_BYTEORDER_H
55
6- #include " config.h"
76#include < stdint.h>
7+ #include < arpa/inet.h>
88
99static inline uint8_t swap (uint8_t n) { return n; }
1010static inline uint16_t swap (uint16_t n) { return (n >> 8 ) | (n << 8 ); }
@@ -22,17 +22,11 @@ static inline uint128_t swap(uint128_t n) { return (uint128_t(swap(uint64_t(n)))
2222static inline int128_t swap (int128_t n) { return int128_t (swap (uint128_t (n))); }
2323#endif
2424
25- #ifdef WORDS_BIGENDIAN
26- template <typename T> static inline T from_be (T n) { return n; }
27- template <typename T> static inline T to_be (T n) { return n; }
28- template <typename T> static inline T from_le (T n) { return swap (n); }
29- template <typename T> static inline T to_le (T n) { return swap (n); }
30- #else
31- template <typename T> static inline T from_le (T n) { return n; }
32- template <typename T> static inline T to_le (T n) { return n; }
33- template <typename T> static inline T from_be (T n) { return swap (n); }
34- template <typename T> static inline T to_be (T n) { return swap (n); }
35- #endif
25+ static inline bool is_be () { return htonl (1 ) == 1 ; }
26+ template <typename T> static inline T from_be (T n) { return is_be () ? n : swap (n); }
27+ template <typename T> static inline T to_be (T n) { return from_be (n); }
28+ template <typename T> static inline T from_le (T n) { return is_be () ? swap (n) : n; }
29+ template <typename T> static inline T to_le (T n) { return from_le (n); }
3630
3731// Wrapper to mark a value as target endian, to guide conversion code
3832
You can’t perform that action at this time.
0 commit comments