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

cpu: semi-generic helper for hooking SIMD functions

parent b15b63e7
No related branches found
No related tags found
1 merge request!1429cpu: helper to probe DSP functions
Pipeline #193991 passed with stage
in 22 minutes and 48 seconds
......@@ -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 */
......@@ -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
......
......@@ -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);
}
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