Browse Source

[FIXUP] __rt_clz loss in aarch64

Signed-off-by: GuEe-GUI <2991707448@qq.com>
GuEe-GUI 4 months ago
parent
commit
78f318aa8f
2 changed files with 16 additions and 0 deletions
  1. 1 0
      include/rtthread.h
  2. 15 0
      libcpu/aarch64/common/cpuport.c

+ 1 - 0
include/rtthread.h

@@ -794,6 +794,7 @@ rt_device_t rt_console_get_device(void);
 
 
 int __rt_ffs(int value);
 int __rt_ffs(int value);
 unsigned long __rt_ffsl(unsigned long value);
 unsigned long __rt_ffsl(unsigned long value);
+unsigned long __rt_clz(unsigned long value);
 
 
 void rt_show_version(void);
 void rt_show_version(void);
 
 

+ 15 - 0
libcpu/aarch64/common/cpuport.c

@@ -56,4 +56,19 @@ unsigned long __rt_ffsl(unsigned long value)
 #endif
 #endif
 }
 }
 
 
+unsigned long __rt_clz(unsigned long value)
+{
+#ifdef __GNUC__
+    return __builtin_clz(value);
+#else
+    unsigned long val;
+
+    __asm__ volatile ("clz %0, %1"
+        :"=r"(val)
+        :"r"(value));
+
+    return val;
+#endif
+}
+
 #endif /* RT_USING_CPU_FFS */
 #endif /* RT_USING_CPU_FFS */