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 10SEC("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 22SEC("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 34SEC("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 50SEC("socket") 51__description("cpuv4 is not supported by compiler or jit, use a dummy test") 52__success 53int dummy_test(void) 54{ 55 return 0; 56} 57 58#endif 59 60char _license[] SEC("license") = "GPL"; 61