staging: rtl8192u: remove redundant assignment to pointer crypt
[linux/fpc-iii.git] / tools / testing / selftests / bpf / bpf_endian.h
blob05f036df8a4c51b7c32fd72f65b9766e13ac7689
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __BPF_ENDIAN__
3 #define __BPF_ENDIAN__
5 #include <linux/stddef.h>
6 #include <linux/swab.h>
8 /* LLVM's BPF target selects the endianness of the CPU
9 * it compiles on, or the user specifies (bpfel/bpfeb),
10 * respectively. The used __BYTE_ORDER__ is defined by
11 * the compiler, we cannot rely on __BYTE_ORDER from
12 * libc headers, since it doesn't reflect the actual
13 * requested byte order.
15 * Note, LLVM's BPF target has different __builtin_bswapX()
16 * semantics. It does map to BPF_ALU | BPF_END | BPF_TO_BE
17 * in bpfel and bpfeb case, which means below, that we map
18 * to cpu_to_be16(). We could use it unconditionally in BPF
19 * case, but better not rely on it, so that this header here
20 * can be used from application and BPF program side, which
21 * use different targets.
23 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
24 # define __bpf_ntohs(x) __builtin_bswap16(x)
25 # define __bpf_htons(x) __builtin_bswap16(x)
26 # define __bpf_constant_ntohs(x) ___constant_swab16(x)
27 # define __bpf_constant_htons(x) ___constant_swab16(x)
28 # define __bpf_ntohl(x) __builtin_bswap32(x)
29 # define __bpf_htonl(x) __builtin_bswap32(x)
30 # define __bpf_constant_ntohl(x) ___constant_swab32(x)
31 # define __bpf_constant_htonl(x) ___constant_swab32(x)
32 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
33 # define __bpf_ntohs(x) (x)
34 # define __bpf_htons(x) (x)
35 # define __bpf_constant_ntohs(x) (x)
36 # define __bpf_constant_htons(x) (x)
37 # define __bpf_ntohl(x) (x)
38 # define __bpf_htonl(x) (x)
39 # define __bpf_constant_ntohl(x) (x)
40 # define __bpf_constant_htonl(x) (x)
41 #else
42 # error "Fix your compiler's __BYTE_ORDER__?!"
43 #endif
45 #define bpf_htons(x) \
46 (__builtin_constant_p(x) ? \
47 __bpf_constant_htons(x) : __bpf_htons(x))
48 #define bpf_ntohs(x) \
49 (__builtin_constant_p(x) ? \
50 __bpf_constant_ntohs(x) : __bpf_ntohs(x))
51 #define bpf_htonl(x) \
52 (__builtin_constant_p(x) ? \
53 __bpf_constant_htonl(x) : __bpf_htonl(x))
54 #define bpf_ntohl(x) \
55 (__builtin_constant_p(x) ? \
56 __bpf_constant_ntohl(x) : __bpf_ntohl(x))
58 #endif /* __BPF_ENDIAN__ */