From 1e4e586150b78e1d3999b9bcafecf34363ffff97 Mon Sep 17 00:00:00 2001
From: Peter Meerwald
Date: Wed, 13 Feb 2013 17:27:09 +0100
Subject: [PATCH] mix: Add optimized mix code path for ARM NEON
Signed-off-by: Peter Meerwald
---
src/Makefile.am | 6 ++--
src/pulsecore/cpu-arm.c | 4 ++-
src/pulsecore/cpu-arm.h | 1 +
src/pulsecore/mix_neon.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 102 insertions(+), 3 deletions(-)
create mode 100644 src/pulsecore/mix_neon.c
diff --git a/src/Makefile.am b/src/Makefile.am
index e551810..cf643da 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -889,10 +889,12 @@ libpulsecore_@PA_MAJORMINOR@_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version
libpulsecore_@PA_MAJORMINOR@_la_LIBADD = $(AM_LIBADD) $(LIBLTDL) $(LIBSAMPLERATE_LIBS) $(LIBSPEEX_LIBS) $(LIBSNDFILE_LIBS) $(WINSOCK_LIBS) $(LTLIBICONV) libpulsecommon-@PA_MAJORMINOR@.la libpulse.la libpulsecore-foreign.la
if HAVE_NEON
-noinst_LTLIBRARIES += libpulsecore_sconv_neon.la
+noinst_LTLIBRARIES += libpulsecore_sconv_neon.la libpulsecore_mix_neon.la
libpulsecore_sconv_neon_la_SOURCES = pulsecore/sconv_neon.c
libpulsecore_sconv_neon_la_CFLAGS = $(AM_CFLAGS) $(NEON_CFLAGS)
-libpulsecore_@PA_MAJORMINOR@_la_LIBADD += libpulsecore_sconv_neon.la
+libpulsecore_mix_neon_la_SOURCES = pulsecore/mix_neon.c
+libpulsecore_mix_neon_la_CFLAGS = $(AM_CFLAGS) $(NEON_CFLAGS)
+libpulsecore_@PA_MAJORMINOR@_la_LIBADD += libpulsecore_sconv_neon.la libpulsecore_mix_neon.la
endif
if HAVE_ORC
diff --git a/src/pulsecore/cpu-arm.c b/src/pulsecore/cpu-arm.c
index 05668f1..1378124 100644
--- a/src/pulsecore/cpu-arm.c
+++ b/src/pulsecore/cpu-arm.c
@@ -143,8 +143,10 @@ pa_bool_t pa_cpu_init_arm(pa_cpu_arm_flag_t *flags) {
if (*flags & PA_CPU_ARM_V6)
pa_volume_func_init_arm(*flags);
#ifdef HAVE_NEON
- if (*flags & PA_CPU_ARM_NEON)
+ if (*flags & PA_CPU_ARM_NEON) {
pa_convert_func_init_neon(*flags);
+ pa_mix_func_init_neon(*flags);
+ }
#endif
return TRUE;
diff --git a/src/pulsecore/cpu-arm.h b/src/pulsecore/cpu-arm.h
index d2d3f5c..d9dc3d5 100644
--- a/src/pulsecore/cpu-arm.h
+++ b/src/pulsecore/cpu-arm.h
@@ -47,6 +47,7 @@ void pa_volume_func_init_arm(pa_cpu_arm_flag_t flags);
#ifdef HAVE_NEON
void pa_convert_func_init_neon(pa_cpu_arm_flag_t flags);
+void pa_mix_func_init_neon(pa_cpu_arm_flag_t flags);
#endif
#endif /* foocpuarmhfoo */
diff --git a/src/pulsecore/mix_neon.c b/src/pulsecore/mix_neon.c
new file mode 100644
index 0000000..ff05ccf
--- /dev/null
+++ b/src/pulsecore/mix_neon.c
@@ -0,0 +1,94 @@
+/***
+ This file is part of PulseAudio.
+
+ Copyright 2013 Peter Meerwald
+
+ PulseAudio is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License,
+ or (at your option) any later version.
+
+ PulseAudio is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include
+#endif
+
+#include
+#include
+
+#include "cpu-arm.h"
+#include "mix.h"
+
+#include
+
+static pa_do_mix_func_t fallback;
+
+/* special case: mix s16ne streams, 2 channels each */
+static void pa_mix_ch2_s16ne_neon(pa_mix_info streams[], unsigned nstreams, uint8_t *data, unsigned length) {
+ const unsigned mask = sizeof(int16_t) * 8 - 1;
+ const uint8_t *end = data + (length & ~mask);
+
+ while (data < end) {
+ int32x4_t sum0, sum1;
+ unsigned i;
+
+ __asm__ __volatile__ (
+ "veor.s32 %q[sum0], %q[sum0] \n\t"
+ "veor.s32 %q[sum1], %q[sum1] \n\t"
+ : [sum0] "=w" (sum0), [sum1] "=w" (sum1)
+ :
+ : "cc" /* clobber list */
+ );
+
+ for (i = 0; i < nstreams; i++) {
+ pa_mix_info *m = streams + i;
+ int32_t cv0 = m->linear[0].i;
+ int32_t cv1 = m->linear[1].i;
+
+ __asm__ __volatile__ (
+ "vld2.s16 {d0,d2}, [%[ptr]]! \n\t"
+ "vmov.s32 d4[0], %[cv0] \n\t"
+ "vmov.s32 d4[1], %[cv1] \n\t"
+ "vshll.s16 q0, d0, #15 \n\t"
+ "vshll.s16 q1, d2, #15 \n\t"
+ "vqdmulh.s32 q0, q0, d4[0] \n\t"
+ "vqdmulh.s32 q1, q1, d4[1] \n\t"
+ "vqadd.s32 %q[sum0], %q[sum0], q0 \n\t"
+ "vqadd.s32 %q[sum1], %q[sum1], q1 \n\t"
+ : [ptr] "+r" (m->ptr), [sum0] "+w" (sum0), [sum1] "+w" (sum1)
+ : [cv0] "r" (cv0), [cv1] "r" (cv1)
+ : "memory", "cc", "q0", "q1", "d4" /* clobber list */
+ );
+ }
+
+ __asm__ __volatile__ (
+ "vqmovn.s32 d0, %q[sum0] \n\t"
+ "vqmovn.s32 d1, %q[sum1] \n\t"
+ "vst2.s16 {d0,d1}, [%[data]]! \n\t"
+ : [data] "+r" (data)
+ : [sum0] "w" (sum0), [sum1] "w" (sum1)
+ : "memory", "cc", "q0" /* clobber list */
+ );
+ }
+
+ fallback(streams, nstreams, 2, data, length & mask);
+}
+
+static void pa_mix_s16ne_neon(pa_mix_info streams[], unsigned nstreams, unsigned nchannels, void *data, unsigned length) {
+ if (nchannels == 2)
+ pa_mix_ch2_s16ne_neon(streams, nstreams, data, length);
+ else
+ fallback(streams, nstreams, nchannels, data, length);
+}
+
+void pa_mix_func_init_neon(pa_cpu_arm_flag_t flags) {
+ pa_log_info("Initialising ARM NEON optimized mixing functions.");
+
+ fallback = pa_get_mix_func(PA_SAMPLE_S16NE);
+ pa_set_mix_func(PA_SAMPLE_S16NE, (pa_do_mix_func_t) pa_mix_s16ne_neon);
+}
--
2.7.4