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