[pulseaudio-discuss] [PATCH v2 03/14] cpu: Add force_generic_code flag to cpu_info struct

Peter Meerwald pmeerw at pmeerw.net
Wed Sep 10 07:40:04 PDT 2014


From: Peter Meerwald <p.meerwald at bct-electronic.com>

The remapper and channel mixing code have (faster) specialized and (slower)
generic code certain code path. The flag force_generic_code can be set to
force the generic code path which is useful for testing. Code duplication
(such as in mix-special-test) can be avoided, cleanup patches follow.

Signed-off-by: Peter Meerwald <pmeerw at pmeerw.net>
---
 src/pulsecore/cpu.c   |  5 +++++
 src/pulsecore/cpu.h   |  4 ++++
 src/pulsecore/mix.c   |  8 ++++++++
 src/pulsecore/remap.c | 14 ++++++++++++++
 4 files changed, 31 insertions(+)

diff --git a/src/pulsecore/cpu.c b/src/pulsecore/cpu.c
index 814abf6..e0c110e 100644
--- a/src/pulsecore/cpu.c
+++ b/src/pulsecore/cpu.c
@@ -23,6 +23,8 @@
 
 void pa_cpu_init(pa_cpu_info *cpu_info) {
     cpu_info->cpu_type = PA_CPU_UNDEFINED;
+    /* don't force generic code, used for testing only */
+    cpu_info->force_generic_code = false;
     if (!getenv("PULSE_NO_SIMD")) {
         if (pa_cpu_init_x86(&cpu_info->flags.x86))
             cpu_info->cpu_type = PA_CPU_X86;
@@ -30,4 +32,7 @@ void pa_cpu_init(pa_cpu_info *cpu_info) {
             cpu_info->cpu_type = PA_CPU_ARM;
         pa_cpu_init_orc(*cpu_info);
     }
+
+    pa_remap_func_init(cpu_info);
+    pa_mix_func_init(cpu_info);
 }
diff --git a/src/pulsecore/cpu.h b/src/pulsecore/cpu.h
index 23262b5..03507de 100644
--- a/src/pulsecore/cpu.h
+++ b/src/pulsecore/cpu.h
@@ -40,8 +40,12 @@ struct pa_cpu_info {
         pa_cpu_x86_flag_t x86;
         pa_cpu_arm_flag_t arm;
     } flags;
+    bool force_generic_code;
 };
 
 void pa_cpu_init(pa_cpu_info *cpu_info);
 
+void pa_remap_func_init(const pa_cpu_info *cpu_info);
+void pa_mix_func_init(const pa_cpu_info *cpu_info);
+
 #endif /* foocpuhfoo */
diff --git a/src/pulsecore/mix.c b/src/pulsecore/mix.c
index 03c71f0..06b22bd 100644
--- a/src/pulsecore/mix.c
+++ b/src/pulsecore/mix.c
@@ -32,6 +32,7 @@
 #include <pulsecore/g711.h>
 #include <pulsecore/endianmacros.h>
 
+#include "cpu.h"
 #include "mix.h"
 
 #define VOLUME_PADDING 32
@@ -606,6 +607,13 @@ static pa_do_mix_func_t do_mix_table[] = {
     [PA_SAMPLE_S24_32RE]  = (pa_do_mix_func_t) pa_mix_s24_32re_c
 };
 
+void pa_mix_func_init(const pa_cpu_info *cpu_info) {
+    if (cpu_info->force_generic_code)
+        do_mix_table[PA_SAMPLE_S16NE] = (pa_do_mix_func_t) pa_mix_generic_s16ne;
+    else
+        do_mix_table[PA_SAMPLE_S16NE] = (pa_do_mix_func_t) pa_mix_s16ne_c;
+}
+
 size_t pa_mix(
         pa_mix_info streams[],
         unsigned nstreams,
diff --git a/src/pulsecore/remap.c b/src/pulsecore/remap.c
index 09d4837..d9b121e 100644
--- a/src/pulsecore/remap.c
+++ b/src/pulsecore/remap.c
@@ -32,6 +32,7 @@
 #include <pulsecore/log.h>
 #include <pulsecore/macro.h>
 
+#include "cpu.h"
 #include "remap.h"
 
 static void remap_mono_to_stereo_s16ne_c(pa_remap_t *m, int16_t *dst, const int16_t *src, unsigned n) {
@@ -361,6 +362,8 @@ void pa_set_remap_func(pa_remap_t *m, pa_do_remap_func_t func_s16,
         pa_assert_not_reached();
 }
 
+static bool force_generic_code = false;
+
 /* set the function that will execute the remapping based on the matrices */
 static void init_remap_c(pa_remap_t *m) {
     unsigned n_oc, n_ic;
@@ -370,6 +373,13 @@ static void init_remap_c(pa_remap_t *m) {
     n_ic = m->i_ss.channels;
 
     /* find some common channel remappings, fall back to full matrix operation. */
+    if (force_generic_code) {
+        pa_log_info("Forced to use generic matrix remapping");
+        pa_set_remap_func(m, (pa_do_remap_func_t) remap_channels_matrix_s16ne_c,
+            (pa_do_remap_func_t) remap_channels_matrix_float32ne_c);
+        return;
+    }
+
     if (n_ic == 1 && n_oc == 2 &&
             m->map_table_i[0][0] == 0x10000 && m->map_table_i[1][0] == 0x10000) {
 
@@ -452,3 +462,7 @@ pa_init_remap_func_t pa_get_init_remap_func(void) {
 void pa_set_init_remap_func(pa_init_remap_func_t func) {
     init_remap_func = func;
 }
+
+void pa_remap_func_init(const pa_cpu_info *cpu_info) {
+    force_generic_code = cpu_info->force_generic_code;
+}
-- 
1.9.1



More information about the pulseaudio-discuss mailing list