[vlc-commits] [Git][videolan/vlc][master] 5 commits: cpu: compile-time RISC-V FPU detection

Rémi Denis-Courmont (@Courmisch) gitlab at videolan.org
Tue Feb 1 16:13:20 UTC 2022



Rémi Denis-Courmont pushed to branch master at VideoLAN / VLC


Commits:
96ae6359 by Rémi Denis-Courmont at 2022-02-01T14:52:06+00:00
cpu: compile-time RISC-V FPU detection

- - - - -
2188dd74 by Rémi Denis-Courmont at 2022-02-01T14:52:06+00:00
cpu: compile-time RISC-V "V" V.E. detection

This detects compiler support for the RISC-V "V" Vector Extension if it
enabled in the compiler flags (or compiler machine definition).

- - - - -
af17c09e by Rémi Denis-Courmont at 2022-02-01T14:52:06+00:00
linux: allow variable tabbing in cpuinfo

The number of tabulation character can vary with versions. Case in
point, RISC-V started with one tabluration, but has two in more recent
kernel versions, to maintain visual alignment.

- - - - -
ad438a0c by Rémi Denis-Courmont at 2022-02-01T14:52:06+00:00
linux: run-time RV-V detection

This detects support for the RISC-V "V" Vector Extension at run-time
from the device tree via /proc/cpuinfo.

- - - - -
169d1d8f by Rémi Denis-Courmont at 2022-02-01T14:52:06+00:00
configure: detect RISC-V V assembler support

This follows the established cargo cult of not assuming that the
toolchain supports SIMD.

- - - - -


4 changed files:

- configure.ac
- include/vlc_cpu.h
- src/linux/cpu.c
- src/misc/cpu.c


Changes:

=====================================
configure.ac
=====================================
@@ -1775,6 +1775,28 @@ AS_IF([test "${enable_altivec}" = "yes"], [
 AC_SUBST([ALTIVEC_CFLAGS])
 AM_CONDITIONAL([HAVE_ALTIVEC], [test "$have_altivec" = "yes"])
 
+
+AC_ARG_ENABLE([rvv],
+  AS_HELP_STRING([--disable-rvv],
+    [disable RISC-V Vector extension (default auto)]),, [
+  AS_CASE([${host_cpu}], [riscv*], [enable_rvv="yes"], [enable_rvv="no"])
+])
+AS_IF([test "${enable_rvv}" != "no"], [
+  AC_CACHE_CHECK([if $CCAS groks RISC-V V assembly], [ac_cv_riscv_v], [
+    AC_COMPILE_IFELSE([
+      AC_LANG_PROGRAM(,[[
+asm volatile(".option arch, +v\nvsetvli x0, x0, e8");
+]])
+    ], [
+      ac_cv_riscv_v="yes"
+    ], [
+      ac_cv_riscv_v="no"
+    ])
+  ])
+])
+AM_CONDITIONAL([HAVE_RVV], [test "${ac_cv_riscv_v}" = "yes"])
+
+
 dnl
 dnl  Memory usage
 dnl


=====================================
include/vlc_cpu.h
=====================================
@@ -197,6 +197,18 @@ unsigned vlc_CPU_raw(void);
 # elif defined (__mips_hard_float)
 #  define HAVE_FPU 1
 
+# elif defined (__riscv)
+#  ifdef __riscv_flen
+#   define HAVE_FPU 1
+#  endif
+#  define VLC_CPU_RV_V 0x1
+
+#  ifdef __riscv_v
+#   define vlc_CPU_RV_V() (1)
+#  else
+#   define vlc_CPU_RV_V() ((vlc_CPU() & VLC_CPU_RV_V) != 0)
+#  endif
+
 # else
 /**
  * Are single precision floating point operations "fast"?


=====================================
src/linux/cpu.c
=====================================
@@ -29,14 +29,74 @@
 
 #undef CPU_FLAGS
 #if defined (__arm__) || defined (__aarch64__)
-# define CPU_FLAGS "Features\t:"
+# define CPU_FLAGS "Features"
 
 #elif defined (__i386__) || defined (__x86_64__)
-# define CPU_FLAGS "flags\t\t:"
+# define CPU_FLAGS "flags"
 
 #elif defined (__powerpc__) || defined (__powerpc64__)
-# define CPU_FLAGS "cpu\t\t:"
+# define CPU_FLAGS "cpu"
 
+#elif defined (__riscv)
+# include <vlc_strings.h>
+# define CPU_FLAGS "isa"
+
+static unsigned vlc_CPU_RV_isa_parse(const char *isa)
+{
+    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;
+
+        isa += extlen;
+    }
+
+    return caps;
+}
 #endif
 
 #ifdef CPU_FLAGS
@@ -52,7 +112,7 @@ unsigned vlc_CPU_raw(void)
 
     while (getline (&line, &linelen, info) != -1)
     {
-        char *p = line, *cap;
+        char *p, *cap;
         uint_fast32_t core_caps = 0;
 
 #if defined (__arm__)
@@ -63,6 +123,15 @@ unsigned vlc_CPU_raw(void)
         if (strncmp (line, CPU_FLAGS, strlen (CPU_FLAGS)))
             continue;
 
+        p = line + strlen(CPU_FLAGS);
+        p += strspn(p, "\t");
+        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 (__arm__) || defined (__aarch64__)
@@ -106,6 +175,7 @@ unsigned vlc_CPU_raw(void)
                 core_caps |= VLC_CPU_ALTIVEC;
 #endif
         }
+#endif
 
         /* Take the intersection of capabilities of each processor */
         all_caps &= core_caps;


=====================================
src/misc/cpu.c
=====================================
@@ -293,6 +293,10 @@ void vlc_CPU_dump (vlc_object_t *obj)
     if (vlc_CPU_ARM_NEON())
         vlc_memstream_puts(&stream, "ARM_NEON ");
 
+#elif defined (__riscv)
+    if (vlc_CPU_RV_V())
+        vlc_memstream_puts(&stream, "V ");
+
 #endif
 
 #if HAVE_FPU



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/a7963fdf2152aacad4491ab99bd6bd36f210c6fd...169d1d8f2f04288fd7701e9a31471fc553d26a1e

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/a7963fdf2152aacad4491ab99bd6bd36f210c6fd...169d1d8f2f04288fd7701e9a31471fc553d26a1e
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list