179dbabc1SYonghong Song // SPDX-License-Identifier: GPL-2.0 279dbabc1SYonghong Song 379dbabc1SYonghong Song #include <linux/bpf.h> 479dbabc1SYonghong Song #include <bpf/bpf_helpers.h> 579dbabc1SYonghong Song #include "bpf_misc.h" 679dbabc1SYonghong Song 7*0209fd51SPu Lehui #if (defined(__TARGET_ARCH_arm64) || defined(__TARGET_ARCH_x86) || \ 8*0209fd51SPu Lehui (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64)) && __clang_major__ >= 18 979dbabc1SYonghong Song 1079dbabc1SYonghong Song SEC("socket") 1179dbabc1SYonghong Song __description("BSWAP, 16") 1279dbabc1SYonghong Song __success __success_unpriv __retval(0x23ff) bswap_16(void)1379dbabc1SYonghong Song__naked void bswap_16(void) 1479dbabc1SYonghong Song { 1579dbabc1SYonghong Song asm volatile (" \ 1679dbabc1SYonghong Song r0 = 0xff23; \ 1779dbabc1SYonghong Song r0 = bswap16 r0; \ 1879dbabc1SYonghong Song exit; \ 1979dbabc1SYonghong Song " ::: __clobber_all); 2079dbabc1SYonghong Song } 2179dbabc1SYonghong Song 2279dbabc1SYonghong Song SEC("socket") 2379dbabc1SYonghong Song __description("BSWAP, 32") 2479dbabc1SYonghong Song __success __success_unpriv __retval(0x23ff0000) bswap_32(void)2579dbabc1SYonghong Song__naked void bswap_32(void) 2679dbabc1SYonghong Song { 2779dbabc1SYonghong Song asm volatile (" \ 2879dbabc1SYonghong Song r0 = 0xff23; \ 2979dbabc1SYonghong Song r0 = bswap32 r0; \ 3079dbabc1SYonghong Song exit; \ 3179dbabc1SYonghong Song " ::: __clobber_all); 3279dbabc1SYonghong Song } 3379dbabc1SYonghong Song 3479dbabc1SYonghong Song SEC("socket") 3579dbabc1SYonghong Song __description("BSWAP, 64") 3679dbabc1SYonghong Song __success __success_unpriv __retval(0x34ff12ff) bswap_64(void)3779dbabc1SYonghong Song__naked void bswap_64(void) 3879dbabc1SYonghong Song { 3979dbabc1SYonghong Song asm volatile (" \ 4079dbabc1SYonghong Song r0 = %[u64_val] ll; \ 4179dbabc1SYonghong Song r0 = bswap64 r0; \ 4279dbabc1SYonghong Song exit; \ 4379dbabc1SYonghong Song " : 4479dbabc1SYonghong Song : [u64_val]"i"(0xff12ff34ff56ff78ull) 4579dbabc1SYonghong Song : __clobber_all); 4679dbabc1SYonghong Song } 4779dbabc1SYonghong Song 4879dbabc1SYonghong Song #else 4979dbabc1SYonghong Song 5079dbabc1SYonghong Song SEC("socket") 5179dbabc1SYonghong Song __description("cpuv4 is not supported by compiler or jit, use a dummy test") 5279dbabc1SYonghong Song __success dummy_test(void)5379dbabc1SYonghong Songint dummy_test(void) 5479dbabc1SYonghong Song { 5579dbabc1SYonghong Song return 0; 5679dbabc1SYonghong Song } 5779dbabc1SYonghong Song 5879dbabc1SYonghong Song #endif 5979dbabc1SYonghong Song 6079dbabc1SYonghong Song char _license[] SEC("license") = "GPL"; 61