[vlc-devel] [PATCH 04/25] cpu: add CPU feature masking
Victorien Le Couviour--Tuffet
victorien.lecouviour.tuffet at gmail.com
Tue Apr 14 12:40:15 CEST 2020
This is allows to temporarily mask a CPU feature.
It can for example be useful for testing a function with several
underlying SIMD implementations.
It adds vlc_CPU_mask and vlc_CPU_unmask to the core API.
---
include/vlc_cpu.h | 2 ++
src/libvlccore.sym | 2 ++
src/misc/cpu.c | 14 +++++++++++++-
3 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/include/vlc_cpu.h b/include/vlc_cpu.h
index 4222eee3ac..4509cbdc77 100644
--- a/include/vlc_cpu.h
+++ b/include/vlc_cpu.h
@@ -30,6 +30,8 @@
* Retrieves CPU capability flags.
*/
VLC_API unsigned vlc_CPU(void);
+VLC_API void vlc_CPU_mask(unsigned cap);
+VLC_API void vlc_CPU_unmask(unsigned cap);
/**
* Computes CPU capability flags.
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index b44431d3fd..7508a06be3 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -522,6 +522,8 @@ vlc_sem_timedwait
vlc_control_cancel
vlc_GetCPUCount
vlc_CPU
+vlc_CPU_mask
+vlc_CPU_unmask
vlc_event_attach
vlc_event_detach
vlc_filenamecmp
diff --git a/src/misc/cpu.c b/src/misc/cpu.c
index 504492280d..08471caeec 100644
--- a/src/misc/cpu.c
+++ b/src/misc/cpu.c
@@ -257,6 +257,8 @@ out:
return i_capabilities;
}
+static uint32_t cpu_mask = 0;
+
unsigned vlc_CPU(void)
{
static atomic_uint cpu_flags = ATOMIC_VAR_INIT(-1);
@@ -267,7 +269,17 @@ unsigned vlc_CPU(void)
atomic_store_explicit(&cpu_flags, flags, memory_order_relaxed);
}
- return flags;
+ return flags & ~cpu_mask;
+}
+
+void vlc_CPU_mask(unsigned cap)
+{
+ cpu_mask |= cap;
+}
+
+void vlc_CPU_unmask(unsigned cap)
+{
+ cpu_mask &= ~cap;
}
void vlc_CPU_dump (vlc_object_t *obj)
--
2.24.1
More information about the vlc-devel
mailing list