[vlc-commits] [Git][videolan/vlc][master] cpu: semi-generic helper for hooking SIMD functions

Rémi Denis-Courmont (@Courmisch) gitlab at videolan.org
Thu Feb 24 18:43:56 UTC 2022



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


Commits:
b1355543 by Rémi Denis-Courmont at 2022-02-24T17:43:59+00:00
cpu: semi-generic helper for hooking SIMD functions

- - - - -


3 changed files:

- include/vlc_cpu.h
- src/libvlccore.sym
- src/misc/cpu.c


Changes:

=====================================
include/vlc_cpu.h
=====================================
@@ -219,4 +219,46 @@ unsigned vlc_CPU_raw(void);
 
 # endif
 
+/**
+ * Initialises DSP functions.
+ *
+ * This helper looks for accelerated Digital Signal Processing functions
+ * identified by the supplied type name. Those functions ares typically
+ * implemented using architecture-specific assembler code with
+ * Single Instruction Multiple Data (SIMD) opcodes for faster processing..
+ *
+ * The exact purposes and semantics of the DSP functions is uniquely identified
+ * by a nul-terminated string.
+ *
+ * \note This function should not be used directly. It is recommended to use
+ * the convenience wrapper vlc_CPU_functions_init_once() instead.
+ *
+ * \param name nul-terminated type identifier (cannot be NULL)
+ * \param [inout] funcs type-specific data structure to be initialised
+ */
+VLC_API void vlc_CPU_functions_init(const char *name, void *restrict funcs);
+
+# ifndef __cplusplus
+/**
+ * Initialises DSP functions once.
+ *
+ * This is a convenience wrapper for vlc_CPU_functions_init().
+ * It only initialises the functions the first time it is evaluated.
+ */
+static inline void vlc_CPU_functions_init_once(const char *name,
+                                               void *restrict funcs)
+{
+    static vlc_once_t once = VLC_STATIC_ONCE;
+
+    if (!vlc_once_begin(&once)) {
+        vlc_CPU_functions_init(name, funcs);
+        vlc_once_complete(&once);
+    }
+}
+# endif
+
+#define set_cpu_funcs(name, activate, priority) \
+    set_callback(VLC_CHECKED_TYPE(void (*)(void *), activate)) \
+    set_capability(name, priority)
+
 #endif /* !VLC_CPU_H */


=====================================
src/libvlccore.sym
=====================================
@@ -553,6 +553,7 @@ vlc_sem_trywait
 vlc_control_cancel
 vlc_GetCPUCount
 vlc_CPU
+vlc_CPU_functions_init
 vlc_event_attach
 vlc_event_detach
 vlc_filenamecmp


=====================================
src/misc/cpu.c
=====================================
@@ -34,6 +34,7 @@
 #include <vlc_common.h>
 #include <vlc_cpu.h>
 #include <vlc_memstream.h>
+#include <vlc_modules.h>
 #include "libvlc.h"
 
 #include <assert.h>
@@ -305,3 +306,17 @@ void vlc_CPU_dump (vlc_object_t *obj)
         free(stream.ptr);
     }
 }
+
+void vlc_CPU_functions_init(const char *capability, void *restrict funcs)
+{
+    module_t **mods;
+    ssize_t n = vlc_module_match(capability, NULL, false, &mods, NULL);
+
+    for (ssize_t i = 0; i < n; i++) {
+        void (*init)(void *) = vlc_module_map(NULL, mods[i]);
+        if (likely(init != NULL))
+            init(funcs);
+    }
+
+    free(mods);
+}



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/b13555433ef826b8f3cdbd0d6a7e2fe9b892e39c

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/b13555433ef826b8f3cdbd0d6a7e2fe9b892e39c
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list