1 // SPDX-License-Identifier: GPL-2.0
2 
3 #include <linux/bpf.h>
4 #include <bpf/bpf_helpers.h>
5 #include "bpf_misc.h"
6 
7 #if (defined(__TARGET_ARCH_arm64) || defined(__TARGET_ARCH_x86) || \
8      (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64)) && __clang_major__ >= 18
9 
10 SEC("socket")
11 __description("BSWAP, 16")
12 __success __success_unpriv __retval(0x23ff)
13 __naked void bswap_16(void)
14 {
15 	asm volatile ("					\
16 	r0 = 0xff23;					\
17 	r0 = bswap16 r0;				\
18 	exit;						\
19 "	::: __clobber_all);
20 }
21 
22 SEC("socket")
23 __description("BSWAP, 32")
24 __success __success_unpriv __retval(0x23ff0000)
25 __naked void bswap_32(void)
26 {
27 	asm volatile ("					\
28 	r0 = 0xff23;					\
29 	r0 = bswap32 r0;				\
30 	exit;						\
31 "	::: __clobber_all);
32 }
33 
34 SEC("socket")
35 __description("BSWAP, 64")
36 __success __success_unpriv __retval(0x34ff12ff)
37 __naked void bswap_64(void)
38 {
39 	asm volatile ("					\
40 	r0 = %[u64_val] ll;					\
41 	r0 = bswap64 r0;				\
42 	exit;						\
43 "	:
44 	: [u64_val]"i"(0xff12ff34ff56ff78ull)
45 	: __clobber_all);
46 }
47 
48 #else
49 
50 SEC("socket")
51 __description("cpuv4 is not supported by compiler or jit, use a dummy test")
52 __success
53 int dummy_test(void)
54 {
55 	return 0;
56 }
57 
58 #endif
59 
60 char _license[] SEC("license") = "GPL";
61