]> code.delx.au - pulseaudio/commitdiff
svolume: add ARM optimized volume scaling
authorWim Taymans <wim.taymans@collabora.co.uk>
Wed, 19 Aug 2009 14:09:14 +0000 (16:09 +0200)
committerWim Taymans <wim.taymans@collabora.co.uk>
Thu, 20 Aug 2009 09:31:03 +0000 (11:31 +0200)
src/Makefile.am
src/daemon/main.c
src/pulsecore/cpu-arm.c [new file with mode: 0644]
src/pulsecore/cpu-arm.h [new file with mode: 0644]
src/pulsecore/svolume_arm.c [new file with mode: 0644]

index 4e90d79391dc729c12e2ff3d6ff0b702f5417c92..eca68b169d35d20f5bba759b9ad2ed19cc86d2e9 100644 (file)
@@ -825,8 +825,8 @@ libpulsecore_@PA_MAJORMINORMICRO@_la_SOURCES = \
                pulsecore/resampler.c pulsecore/resampler.h \
                pulsecore/rtpoll.c pulsecore/rtpoll.h \
                pulsecore/sample-util.c pulsecore/sample-util.h \
-               pulsecore/cpu-x86.c \
-               pulsecore/svolume_c.c \
+               pulsecore/cpu-arm.c pulsecore/cpu-x86.c \
+               pulsecore/svolume_c.c pulsecore/svolume_arm.c\
                pulsecore/svolume_mmx.c pulsecore/svolume_sse.c \
                pulsecore/sconv-s16be.c pulsecore/sconv-s16be.h \
                pulsecore/sconv-s16le.c pulsecore/sconv-s16le.h \
index 31e434d9d86edf81fc0d3bf46c32601fd6e0b6f1..ec8ff400c35578dfbeecdf7cfdb423575c9eb040 100644 (file)
@@ -93,6 +93,7 @@
 #ifdef HAVE_DBUS
 #include <pulsecore/dbus-shared.h>
 #endif
+#include <pulsecore/cpu-arm.h>
 #include <pulsecore/cpu-x86.h>
 
 #include "cmdline.h"
@@ -821,6 +822,7 @@ int main(int argc, char *argv[]) {
     pa_memtrap_install();
 
     pa_cpu_init_x86();
+    pa_cpu_init_arm();
 
     pa_assert_se(mainloop = pa_mainloop_new());
 
diff --git a/src/pulsecore/cpu-arm.c b/src/pulsecore/cpu-arm.c
new file mode 100644 (file)
index 0000000..75646fe
--- /dev/null
@@ -0,0 +1,43 @@
+/***
+  This file is part of PulseAudio.
+
+  Copyright 2004-2006 Lennart Poettering
+  Copyright 2009 Wim Taymans <wim.taymans@collabora.co.uk> 
+
+  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.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with PulseAudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdint.h>
+
+#include <pulsecore/log.h>
+
+#include "cpu-arm.h"
+
+static pa_cpu_arm_flag_t pa_cpu_arm_flags;
+
+void pa_cpu_init_arm (void) {
+#if defined (__arm__)
+    pa_cpu_arm_flags = 0;
+   
+    pa_log ("ARM init\n");
+
+    pa_volume_func_init_arm (pa_cpu_arm_flags);
+#endif /* defined (__arm__) */
+}
diff --git a/src/pulsecore/cpu-arm.h b/src/pulsecore/cpu-arm.h
new file mode 100644 (file)
index 0000000..1a0ac27
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef foocpuarmhfoo
+#define foocpuarmhfoo
+
+/***
+  This file is part of PulseAudio.
+
+  Copyright 2004-2006 Lennart Poettering
+  Copyright 2009 Wim Taymans <wim.taymans@collabora.co.uk> 
+
+  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.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with PulseAudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#include <stdint.h>
+
+typedef enum pa_cpu_arm_flag {
+    PA_CPU_ARM_V6       = (1 << 0),
+    PA_CPU_ARM_NEON     = (1 << 1),
+    PA_CPU_ARM_VFP      = (1 << 2)
+} pa_cpu_arm_flag_t;
+
+void pa_cpu_init_arm (void);
+
+/* some optimized functions */
+void pa_volume_func_init_arm(pa_cpu_arm_flag_t flags);
+
+#endif /* foocpuarmhfoo */
diff --git a/src/pulsecore/svolume_arm.c b/src/pulsecore/svolume_arm.c
new file mode 100644 (file)
index 0000000..7e25a13
--- /dev/null
@@ -0,0 +1,195 @@
+/***
+  This file is part of PulseAudio.
+
+  Copyright 2004-2006 Lennart Poettering
+  Copyright 2009 Wim Taymans <wim.taymans@collabora.co.uk>
+
+  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.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with PulseAudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <pulse/timeval.h>
+#include <pulsecore/random.h>
+#include <pulsecore/macro.h>
+#include <pulsecore/g711.h>
+#include <pulsecore/core-util.h>
+
+#include "cpu-arm.h"
+
+#include "sample-util.h"
+#include "endianmacros.h"
+
+#if defined (__arm__)
+
+#define MOD_INC() \
+    " subs  r0, r6, %2              \n\t" \
+    " addcs r0, %1                  \n\t" \
+    " movcs r6, r0                  \n\t" 
+
+static void
+pa_volume_s16ne_arm (int16_t *samples, int32_t *volumes, unsigned channels, unsigned length)
+{
+  int32_t *ve;
+
+  channels = MAX (4, channels);
+  ve = volumes + channels;
+
+  __asm__ __volatile__ (
+    " mov r6, %1                      \n\t"
+    " mov %3, %3, LSR #1              \n\t" /* length /= sizeof (int16_t) */
+    " tst %3, #1                      \n\t" /* check for odd samples */
+    " beq  2f                         \n\t"
+
+    "1:                               \n\t"
+    " ldr  r0, [r6], #4               \n\t" /* odd samples volumes */
+    " ldrh r2, [%0]                   \n\t" 
+
+    " smulwb r0, r0, r2               \n\t"
+    " ssat r0, #16, r0                \n\t"
+    
+    " strh r0, [%0], #2               \n\t"
+
+    MOD_INC()
+
+    "2:                               \n\t"
+    " mov %3, %3, LSR #1              \n\t" 
+    " tst %3, #1                      \n\t" /* check for odd samples */
+    " beq  4f                         \n\t" 
+
+    "3:                               \n\t"
+    " ldrd r2, [r6], #8               \n\t" /* 2 samples at a time */
+    " ldr  r0, [%0]                   \n\t"
+
+    " smulwt r2, r2, r0               \n\t"
+    " smulwb r3, r3, r0               \n\t"
+
+    " ssat r2, #16, r2                \n\t"
+    " ssat r3, #16, r3                \n\t"
+    
+    " pkhbt r0, r3, r2, LSL #16       \n\t"
+    " str  r0, [%0], #4               \n\t"
+
+    MOD_INC()
+
+    "4:                               \n\t"
+    " movs %3, %3, LSR #1             \n\t" 
+    " beq  6f                         \n\t" 
+
+    "5:                               \n\t"
+    " ldrd r2, [r6], #8               \n\t" /* 4 samples at a time */
+    " ldrd r4, [r6], #8               \n\t"
+    " ldrd r0, [%0]                   \n\t"
+
+    " smulwt r2, r2, r0               \n\t"
+    " smulwb r3, r3, r0               \n\t"
+    " smulwt r4, r4, r1               \n\t"
+    " smulwb r5, r5, r1               \n\t"
+
+    " ssat r2, #16, r2                \n\t"
+    " ssat r3, #16, r3                \n\t"
+    " ssat r4, #16, r4                \n\t"
+    " ssat r5, #16, r5                \n\t"
+    
+    " pkhbt r0, r3, r2, LSL #16       \n\t"
+    " pkhbt r1, r5, r4, LSL #16       \n\t"
+    " strd  r0, [%0], #8              \n\t"
+
+    MOD_INC()
+    
+    " subs %3, %3, #1                 \n\t"
+    " bne 5b                          \n\t"
+    "6:                               \n\t"
+
+    : "+r" (samples), "+r" (volumes), "+r" (ve), "+r" (length)
+    :
+    : "r6", "r5", "r4", "r3", "r2", "r1", "r0", "cc"
+  );
+}
+
+#undef RUN_TEST
+
+#ifdef RUN_TEST
+#define CHANNELS 2
+#define SAMPLES 1023
+#define TIMES 1000
+#define PADDING 16
+
+static void run_test (void) {
+  int16_t samples[SAMPLES];
+  int16_t samples_ref[SAMPLES];
+  int16_t samples_orig[SAMPLES];
+  int32_t volumes[CHANNELS + PADDING];
+  int i, j, padding;
+  pa_do_volume_func_t func;
+  struct timeval start, stop;
+
+  func = pa_get_volume_func (PA_SAMPLE_S16NE);
+
+  printf ("checking ARM %zd\n", sizeof (samples));
+
+  pa_random (samples, sizeof (samples));
+  memcpy (samples_ref, samples, sizeof (samples));
+  memcpy (samples_orig, samples, sizeof (samples));
+
+  for (i = 0; i < CHANNELS; i++)
+    volumes[i] = rand() >> 1;
+  for (padding = 0; padding < PADDING; padding++, i++)
+    volumes[i] = volumes[padding];
+
+  func (samples_ref, volumes, CHANNELS, sizeof (samples));
+  pa_volume_s16ne_arm (samples, volumes, CHANNELS, sizeof (samples));
+  for (i = 0; i < SAMPLES; i++) {
+    if (samples[i] != samples_ref[i]) {
+      printf ("%d: %04x != %04x (%04x * %04x)\n", i, samples[i], samples_ref[i],
+          samples_orig[i], volumes[i % CHANNELS]);
+    }
+  }
+
+  pa_gettimeofday(&start);
+  for (j = 0; j < TIMES; j++) {
+    memcpy (samples, samples_orig, sizeof (samples));
+    pa_volume_s16ne_arm (samples, volumes, CHANNELS, sizeof (samples));
+  }
+  pa_gettimeofday(&stop);
+  pa_log_info("ARM: %llu usec.", (long long unsigned int)pa_timeval_diff (&stop, &start));
+
+  pa_gettimeofday(&start);
+  for (j = 0; j < TIMES; j++) {
+    memcpy (samples_ref, samples_orig, sizeof (samples));
+    func (samples_ref, volumes, CHANNELS, sizeof (samples));
+  }
+  pa_gettimeofday(&stop);
+  pa_log_info("ref: %llu usec.", (long long unsigned int)pa_timeval_diff (&stop, &start));
+}
+#endif
+
+#endif /* defined (__arm__) */
+
+
+void pa_volume_func_init_arm (pa_cpu_arm_flag_t flags) {
+#if defined (__arm__)
+  pa_log_info("Initialising ARM optimized functions.");
+
+#ifdef RUN_TEST
+  run_test ();
+#endif
+
+  pa_set_volume_func (PA_SAMPLE_S16NE,     (pa_do_volume_func_t) pa_volume_s16ne_arm);
+#endif /* defined (__arm__) */
+}