Skip to content
Snippets Groups Projects
Commit d7b1f8e2 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont
Browse files

linux: use getauxval() for RISC-V CPU detection

parent e75a33e4
No related branches found
No related tags found
1 merge request!1439linux: use auxv for CPU detection
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment