[FFmpeg-cvslog] avutil: [LA] use getauxval to do runtime check.

Shiyou Yin git at videolan.org
Mon Feb 27 05:27:17 EET 2023


ffmpeg | branch: master | Shiyou Yin <yinshiyou-hf at loongson.cn> | Tue Feb 14 20:25:56 2023 +0800| [b09f31af1b5e483e614d0f5d673753c5ab778034] | committer: Steven Liu

avutil: [LA] use getauxval to do runtime check.

Replace cpucfg with getauxval to avoid crash in case of
some processor capabilities are not supportted by kernel used.

Reviewed-by: Steven Liu <liuqi05 at kuaishou.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b09f31af1b5e483e614d0f5d673753c5ab778034
---

 libavutil/loongarch/cpu.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/libavutil/loongarch/cpu.c b/libavutil/loongarch/cpu.c
index e4b240bc44..cad8504fde 100644
--- a/libavutil/loongarch/cpu.c
+++ b/libavutil/loongarch/cpu.c
@@ -21,26 +21,18 @@
 
 #include <stdint.h>
 #include "cpu.h"
+#include <sys/auxv.h>
 
-#define LOONGARCH_CFG2 0x2
-#define LOONGARCH_CFG2_LSX    (1 << 6)
-#define LOONGARCH_CFG2_LASX   (1 << 7)
-
-static int cpu_flags_cpucfg(void)
+#define LA_HWCAP_LSX    (1<<4)
+#define LA_HWCAP_LASX   (1<<5)
+static int cpu_flags_getauxval(void)
 {
     int flags = 0;
-    uint32_t cfg2 = 0;
-
-    __asm__ volatile(
-        "cpucfg %0, %1 \n\t"
-        : "+&r"(cfg2)
-        : "r"(LOONGARCH_CFG2)
-    );
+    int flag  = (int)getauxval(AT_HWCAP);
 
-    if (cfg2 & LOONGARCH_CFG2_LSX)
+    if (flag & LA_HWCAP_LSX)
         flags |= AV_CPU_FLAG_LSX;
-
-    if (cfg2 & LOONGARCH_CFG2_LASX)
+    if (flag & LA_HWCAP_LASX)
         flags |= AV_CPU_FLAG_LASX;
 
     return flags;
@@ -49,7 +41,7 @@ static int cpu_flags_cpucfg(void)
 int ff_get_cpu_flags_loongarch(void)
 {
 #if defined __linux__
-    return cpu_flags_cpucfg();
+    return cpu_flags_getauxval();
 #else
     /* Assume no SIMD ASE supported */
     return 0;



More information about the ffmpeg-cvslog mailing list