diff --git a/src/linux/cpu.c b/src/linux/cpu.c index 8fe5b378c932404a7e19adc9de79421e6b09d980..1c963b3e1172758df91b1ad62bbb6c1aa33b53cb 100644 --- a/src/linux/cpu.c +++ b/src/linux/cpu.c @@ -82,71 +82,24 @@ unsigned vlc_CPU_raw(void) return flags; } -#else -#undef CPU_FLAGS -#if defined (__i386__) || defined (__x86_64__) -# define CPU_FLAGS "flags" - #elif defined (__riscv) -# include <vlc_strings.h> -# define CPU_FLAGS "isa" +# define HWCAP_RV(letter) (1LU << ((letter) - 'A')) -static unsigned vlc_CPU_RV_isa_parse(const char *isa) +unsigned vlc_CPU_raw(void) { - unsigned caps = 0; - int c; - - if (vlc_ascii_tolower((unsigned char)isa[0]) != 'r' - || vlc_ascii_tolower((unsigned char)isa[1]) != 'v') - return 0; - - isa += 2; - - if (strncmp(isa, "32", 2) == 0 || strncmp(isa, "64", 2) == 0) - isa += 2; - else if (strncmp(isa, "128", 3) == 0) - isa += 3; - else - return 0; - - while ((c = vlc_ascii_tolower((unsigned char)*isa)) != '\0') { - size_t extlen = 1; - - switch (c) { - case '_': - break; - - case 'z': - case 's': - case 'h': - case 'x': - extlen = 1 + strcspn(isa + 1, "_"); - break; - - default: - if (((unsigned)(c - 'a')) > 'y') - return 0; - - while (isa[extlen] && ((unsigned)(isa[extlen] - '0')) < 10) - extlen++; - - if (vlc_ascii_tolower(isa[extlen]) == 'p') { - extlen++; - - while (isa[extlen] && ((unsigned)(isa[extlen] - '0')) < 10) - extlen++; - } - } - - /* TODO: Zve extensions */ - if (c == 'v') - caps |= VLC_CPU_RV_V; + const unsigned long hwcap = getauxval(AT_HWCAP); + unsigned int flags = 0; - isa += extlen; - } + if (hwcap & HWCAP_RV('V')) + flags |= VLC_CPU_RV_V; - return caps; + return flags; } + +#else +#undef CPU_FLAGS +#if defined (__i386__) || defined (__x86_64__) +# define CPU_FLAGS "flags" #endif #ifdef CPU_FLAGS @@ -173,10 +126,6 @@ unsigned vlc_CPU_raw(void) if (*p != ':') continue; -#if defined (__riscv) - p += strspn(p, "\t "); - core_caps = vlc_CPU_RV_isa_parse(p); -#else while ((cap = strsep (&p, " ")) != NULL) { #if defined (__i386__) || defined (__x86_64__) @@ -208,7 +157,6 @@ unsigned vlc_CPU_raw(void) core_caps |= VLC_CPU_FMA4; #endif } -#endif /* Take the intersection of capabilities of each processor */ all_caps &= core_caps;