mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
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@kuaishou.com>
This commit is contained in:
parent
ac6eec1fc2
commit
b09f31af1b
@ -21,26 +21,18 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
|
#include <sys/auxv.h>
|
||||||
|
|
||||||
#define LOONGARCH_CFG2 0x2
|
#define LA_HWCAP_LSX (1<<4)
|
||||||
#define LOONGARCH_CFG2_LSX (1 << 6)
|
#define LA_HWCAP_LASX (1<<5)
|
||||||
#define LOONGARCH_CFG2_LASX (1 << 7)
|
static int cpu_flags_getauxval(void)
|
||||||
|
|
||||||
static int cpu_flags_cpucfg(void)
|
|
||||||
{
|
{
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
uint32_t cfg2 = 0;
|
int flag = (int)getauxval(AT_HWCAP);
|
||||||
|
|
||||||
__asm__ volatile(
|
if (flag & LA_HWCAP_LSX)
|
||||||
"cpucfg %0, %1 \n\t"
|
|
||||||
: "+&r"(cfg2)
|
|
||||||
: "r"(LOONGARCH_CFG2)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (cfg2 & LOONGARCH_CFG2_LSX)
|
|
||||||
flags |= AV_CPU_FLAG_LSX;
|
flags |= AV_CPU_FLAG_LSX;
|
||||||
|
if (flag & LA_HWCAP_LASX)
|
||||||
if (cfg2 & LOONGARCH_CFG2_LASX)
|
|
||||||
flags |= AV_CPU_FLAG_LASX;
|
flags |= AV_CPU_FLAG_LASX;
|
||||||
|
|
||||||
return flags;
|
return flags;
|
||||||
@ -49,7 +41,7 @@ static int cpu_flags_cpucfg(void)
|
|||||||
int ff_get_cpu_flags_loongarch(void)
|
int ff_get_cpu_flags_loongarch(void)
|
||||||
{
|
{
|
||||||
#if defined __linux__
|
#if defined __linux__
|
||||||
return cpu_flags_cpucfg();
|
return cpu_flags_getauxval();
|
||||||
#else
|
#else
|
||||||
/* Assume no SIMD ASE supported */
|
/* Assume no SIMD ASE supported */
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user