From 0e3c4bd26b34a54910db4da6b0a99bc470c65b08 Mon Sep 17 00:00:00 2001 From: 张衍 Date: Mon, 22 Jul 2024 02:33:39 +0000 Subject: [BSP/Phytium]适配最新裸机驱动 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libcpu/aarch64/common/cpuport.c | 43 +++++++++++++++++++++++++++++++++ libcpu/aarch64/common/include/cpuport.h | 30 ----------------------- 2 files changed, 43 insertions(+), 30 deletions(-) create mode 100644 libcpu/aarch64/common/cpuport.c (limited to 'libcpu') diff --git a/libcpu/aarch64/common/cpuport.c b/libcpu/aarch64/common/cpuport.c new file mode 100644 index 0000000000..4c1bf01cf3 --- /dev/null +++ b/libcpu/aarch64/common/cpuport.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2024-06-21 Zhangyan first version + */ + +#include +#include +#include + +#ifdef RT_USING_CPU_FFS +/** + * This function finds the first bit set (beginning with the least significant bit) + * in value and return the index of that bit. + * + * Bits are numbered starting at 1 (the least significant bit). A return value of + * zero from any of these functions means that the argument was zero. + * + * @return return the index of the first bit set. If value is 0, then this function + * shall return 0. + */ +int __rt_ffs(int value) +{ +#ifdef __GNUC__ + return __builtin_ffs(value); +#else + __asm__ volatile ( + "rbit w1, %w0\n" + "cmp %w0, 0\n" + "clz w1, w1\n" + "csinc %w0, wzr, w1, eq\n" + : "=r"(value) + : "0"(value) + ); + return value; +#endif +} + +#endif /* RT_USING_CPU_FFS */ \ No newline at end of file diff --git a/libcpu/aarch64/common/include/cpuport.h b/libcpu/aarch64/common/include/cpuport.h index 217f477aaf..cbd04500a0 100644 --- a/libcpu/aarch64/common/include/cpuport.h +++ b/libcpu/aarch64/common/include/cpuport.h @@ -53,36 +53,6 @@ typedef struct void _thread_start(void); -#ifdef RT_USING_CPU_FFS -/** - * This function finds the first bit set (beginning with the least significant bit) - * in value and return the index of that bit. - * - * Bits are numbered starting at 1 (the least significant bit). A return value of - * zero from any of these functions means that the argument was zero. - * - * @return return the index of the first bit set. If value is 0, then this function - * shall return 0. - */ -rt_inline int __rt_ffs(int value) -{ -#ifdef __GNUC__ - return __builtin_ffs(value); -#else - __asm__ volatile ( - "rbit w1, %w0\n" - "cmp %w0, 0\n" - "clz w1, w1\n" - "csinc %w0, wzr, w1, eq\n" - : "=r"(value) - : "0"(value) - ); - return value; -#endif -} - -#endif /* RT_USING_CPU_FFS */ - #ifdef ARCH_USING_HW_THREAD_SELF rt_inline struct rt_thread *rt_hw_thread_self(void) { -- cgit v1.3.1