From: Shiyou Yin <yinshiyou-hf@loongson.cn> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH] avutil: [LA] use getauxval to do runtime check. Date: Tue, 14 Feb 2023 20:25:56 +0800 Message-ID: <20230214122556.24384-1-yinshiyou-hf@loongson.cn> (raw) Replace cpucfg with getauxval to avoid crash in case of some processor capabilities are not supportted by kernel used. --- 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; -- 2.20.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next reply other threads:[~2023-02-14 12:26 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-02-14 12:25 Shiyou Yin [this message] 2023-02-23 7:48 ` Steven Liu 2023-02-27 1:03 ` Shiyou Yin 2023-02-27 2:47 ` Steven Liu 2023-02-27 3:17 ` Steven Liu 2023-02-27 4:44 ` Steven Liu
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230214122556.24384-1-yinshiyou-hf@loongson.cn \ --to=yinshiyou-hf@loongson.cn \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git