|
7 | 7 | #ifndef __SBI_BYTEORDER_H__
|
8 | 8 | #define __SBI_BYTEORDER_H__
|
9 | 9 |
|
10 |
| -#include <sbi/sbi_types.h> |
| 10 | +#ifdef __ASSEMBLER__ |
| 11 | +# define _conv_cast(type, val) (val) |
| 12 | +#else |
| 13 | +# include <sbi/sbi_types.h> |
| 14 | +# define _conv_cast(type, val) ((type)(val)) |
| 15 | +#endif |
11 | 16 |
|
12 | 17 | #define BSWAP16(x) ((((x) & 0x00ff) << 8) | \
|
13 | 18 | (((x) & 0xff00) >> 8))
|
|
25 | 30 | (((x) & 0xff00000000000000ULL) >> 56))
|
26 | 31 |
|
27 | 32 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ /* CPU(little-endian) */
|
28 |
| -#define cpu_to_be16(x) ((uint16_t)BSWAP16(x)) |
29 |
| -#define cpu_to_be32(x) ((uint32_t)BSWAP32(x)) |
30 |
| -#define cpu_to_be64(x) ((uint64_t)BSWAP64(x)) |
| 33 | +#define cpu_to_be16(x) _conv_cast(uint16_t, BSWAP16(x)) |
| 34 | +#define cpu_to_be32(x) _conv_cast(uint32_t, BSWAP32(x)) |
| 35 | +#define cpu_to_be64(x) _conv_cast(uint64_t, BSWAP64(x)) |
31 | 36 |
|
32 |
| -#define be16_to_cpu(x) ((uint16_t)BSWAP16(x)) |
33 |
| -#define be32_to_cpu(x) ((uint32_t)BSWAP32(x)) |
34 |
| -#define be64_to_cpu(x) ((uint64_t)BSWAP64(x)) |
| 37 | +#define be16_to_cpu(x) _conv_cast(uint16_t, BSWAP16(x)) |
| 38 | +#define be32_to_cpu(x) _conv_cast(uint32_t, BSWAP32(x)) |
| 39 | +#define be64_to_cpu(x) _conv_cast(uint64_t, BSWAP64(x)) |
35 | 40 |
|
36 |
| -#define cpu_to_le16(x) ((uint16_t)(x)) |
37 |
| -#define cpu_to_le32(x) ((uint32_t)(x)) |
38 |
| -#define cpu_to_le64(x) ((uint64_t)(x)) |
| 41 | +#define cpu_to_le16(x) _conv_cast(uint16_t, (x)) |
| 42 | +#define cpu_to_le32(x) _conv_cast(uint32_t, (x)) |
| 43 | +#define cpu_to_le64(x) _conv_cast(uint64_t, (x)) |
39 | 44 |
|
40 |
| -#define le16_to_cpu(x) ((uint16_t)(x)) |
41 |
| -#define le32_to_cpu(x) ((uint32_t)(x)) |
42 |
| -#define le64_to_cpu(x) ((uint64_t)(x)) |
| 45 | +#define le16_to_cpu(x) _conv_cast(uint16_t, (x)) |
| 46 | +#define le32_to_cpu(x) _conv_cast(uint32_t, (x)) |
| 47 | +#define le64_to_cpu(x) _conv_cast(uint64_t, (x)) |
43 | 48 | #else /* CPU(big-endian) */
|
44 |
| -#define cpu_to_be16(x) ((uint16_t)(x)) |
45 |
| -#define cpu_to_be32(x) ((uint32_t)(x)) |
46 |
| -#define cpu_to_be64(x) ((uint64_t)(x)) |
| 49 | +#define cpu_to_be16(x) _conv_cast(uint16_t, (x)) |
| 50 | +#define cpu_to_be32(x) _conv_cast(uint32_t, (x)) |
| 51 | +#define cpu_to_be64(x) _conv_cast(uint64_t, (x)) |
47 | 52 |
|
48 |
| -#define be16_to_cpu(x) ((uint16_t)(x)) |
49 |
| -#define be32_to_cpu(x) ((uint32_t)(x)) |
50 |
| -#define be64_to_cpu(x) ((uint64_t)(x)) |
| 53 | +#define be16_to_cpu(x) _conv_cast(uint16_t, (x)) |
| 54 | +#define be32_to_cpu(x) _conv_cast(uint32_t, (x)) |
| 55 | +#define be64_to_cpu(x) _conv_cast(uint64_t, (x)) |
51 | 56 |
|
52 |
| -#define cpu_to_le16(x) ((uint16_t)BSWAP16(x)) |
53 |
| -#define cpu_to_le32(x) ((uint32_t)BSWAP32(x)) |
54 |
| -#define cpu_to_le64(x) ((uint64_t)BSWAP64(x)) |
| 57 | +#define cpu_to_le16(x) _conv_cast(uint16_t, BSWAP16(x)) |
| 58 | +#define cpu_to_le32(x) _conv_cast(uint32_t, BSWAP32(x)) |
| 59 | +#define cpu_to_le64(x) _conv_cast(uint64_t, BSWAP64(x)) |
55 | 60 |
|
56 |
| -#define le16_to_cpu(x) ((uint16_t)BSWAP16(x)) |
57 |
| -#define le32_to_cpu(x) ((uint32_t)BSWAP32(x)) |
58 |
| -#define le64_to_cpu(x) ((uint64_t)BSWAP64(x)) |
| 61 | +#define le16_to_cpu(x) _conv_cast(uint16_t, BSWAP16(x)) |
| 62 | +#define le32_to_cpu(x) _conv_cast(uint32_t, BSWAP32(x)) |
| 63 | +#define le64_to_cpu(x) _conv_cast(uint64_t, BSWAP64(x)) |
59 | 64 | #endif
|
60 | 65 |
|
61 | 66 | #if __riscv_xlen == 64
|
|
0 commit comments