[pulseaudio-commits] 9 commits - configure.ac src/Makefile.am src/pulsecore src/tests

Arun Raghavan arun at kemper.freedesktop.org
Mon Oct 29 02:58:04 PDT 2012


 configure.ac               |   28 +++++++++++
 src/Makefile.am            |   15 +++++
 src/pulsecore/cpu-arm.c    |    4 +
 src/pulsecore/cpu-arm.h    |    8 +++
 src/pulsecore/sconv_neon.c |  106 ++++++++++++++++++++++++++++++++++++++++++
 src/tests/cpu-test.c       |  113 ++++++++++++++++++++++++++++++++++++++++++---
 6 files changed, 266 insertions(+), 8 deletions(-)

New commits:
commit a423ee0f3d36b98baff64cc31558632e738b402d
Author: Tanu Kaskinen <tanuk at iki.fi>
Date:   Sat Oct 6 14:43:07 2012 +0300

    build: Add a2dp-codecs.h to libbluetooth-util sources.

diff --git a/src/Makefile.am b/src/Makefile.am
index 84598b2..88054cb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1960,7 +1960,10 @@ module_bluetooth_discover_la_LIBADD = $(MODULE_LIBADD) $(DBUS_LIBS) libbluetooth
 module_bluetooth_discover_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS)
 
 
-libbluetooth_util_la_SOURCES = modules/bluetooth/bluetooth-util.c modules/bluetooth/bluetooth-util.h
+libbluetooth_util_la_SOURCES = \
+		modules/bluetooth/a2dp-codecs.h \
+		modules/bluetooth/bluetooth-util.c \
+		modules/bluetooth/bluetooth-util.h
 libbluetooth_util_la_LDFLAGS = -avoid-version
 libbluetooth_util_la_LIBADD = $(MODULE_LIBADD) $(DBUS_LIBS)
 libbluetooth_util_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS)

commit 654444eda9e57cd8a9326f6ad0e6aeb354e9b83d
Author: Arun Raghavan <arun.raghavan at collabora.co.uk>
Date:   Mon Oct 29 14:40:00 2012 +0530

    tests: Minor cpu-test fixes for non-NEON builds
    
    The s16->float test is only run on ARM with NEOn at the moment, so we
    don't define that code in other cases.

diff --git a/src/tests/cpu-test.c b/src/tests/cpu-test.c
index f3308d9..e38e632 100644
--- a/src/tests/cpu-test.c
+++ b/src/tests/cpu-test.c
@@ -255,6 +255,9 @@ static void run_conv_test_float_to_s16(pa_convert_func_t func, pa_convert_func_t
     }
 }
 
+/* This test is currently only run under NEON */
+#if defined (__arm__) && defined (__linux__)
+#ifdef HAVE_NEON
 static void run_conv_test_s16_to_float(pa_convert_func_t func, pa_convert_func_t orig_func, int align, pa_bool_t correct,
         pa_bool_t perf) {
     PA_DECLARE_ALIGNED(8, float, f[SAMPLES]) = { 0 };
@@ -298,6 +301,8 @@ static void run_conv_test_s16_to_float(pa_convert_func_t func, pa_convert_func_t
         } PA_CPU_TEST_RUN_STOP
     }
 }
+#endif /* HAVE_NEON */
+#endif /* defined (__arm__) && defined (__linux__) */
 
 #if defined (__i386__) || defined (__amd64__)
 START_TEST (sconv_sse_test) {
@@ -329,6 +334,7 @@ END_TEST
 #endif /* defined (__i386__) || defined (__amd64__) */
 
 #if defined (__arm__) && defined (__linux__)
+#ifdef HAVE_NEON
 START_TEST (sconv_neon_test) {
     pa_cpu_arm_flag_t flags = 0;
     pa_convert_func_t orig_from_func, neon_from_func;
@@ -368,6 +374,7 @@ START_TEST (sconv_neon_test) {
     run_conv_test_s16_to_float(neon_to_func, orig_to_func, 7, TRUE, TRUE);
 }
 END_TEST
+#endif /* HAVE_NEON */
 #endif /* defined (__arm__) && defined (__linux__) */
 
 #undef SAMPLES

commit 2ec891d892d995f09f119fb0a36b976d3a53e013
Author: Arun Raghavan <arun.raghavan at collabora.co.uk>
Date:   Mon Oct 29 13:26:25 2012 +0530

    tests: Print average outer-loop iteration time in cpu-test

diff --git a/src/tests/cpu-test.c b/src/tests/cpu-test.c
index b791e7f..f3308d9 100644
--- a/src/tests/cpu-test.c
+++ b/src/tests/cpu-test.c
@@ -55,8 +55,12 @@
         _s1 += _stop - _start;                                  \
         _s2 += (_stop - _start) * (_stop - _start);             \
     }                                                           \
-    pa_log_debug("%s: %llu usec (min = %llu, max = %llu, stddev = %g).", _label, (long long unsigned int)_s1,           \
-            (long long unsigned int)_min, (long long unsigned int)_max, sqrt(_times2 * _s2 - _s1 * _s1) / _times2);     \
+    pa_log_debug("%s: %llu usec (avg: %g, min = %llu, max = %llu, stddev = %g).", _label, \
+            (long long unsigned int)_s1,                        \
+            ((double)_s1 / _times2),                            \
+            (long long unsigned int)_min,                       \
+            (long long unsigned int)_max,                       \
+            sqrt(_times2 * _s2 - _s1 * _s1) / _times2);         \
 }
 
 /* Common defines for svolume tests */

commit 17b5a3613022837525fe853de55df7fa6897ce50
Author: Arun Raghavan <arun.raghavan at collabora.co.uk>
Date:   Fri Oct 26 16:45:32 2012 +0530

    tests: Increase sconv cpu-test timeout
    
    This takes longer on ARM CPUs, especially older ones.

diff --git a/src/tests/cpu-test.c b/src/tests/cpu-test.c
index dd21607..b791e7f 100644
--- a/src/tests/cpu-test.c
+++ b/src/tests/cpu-test.c
@@ -403,6 +403,7 @@ int main(int argc, char *argv[]) {
     tcase_add_test(tc, sconv_neon_test);
 #endif
 #endif
+    tcase_set_timeout(tc, 120);
     suite_add_tcase(s, tc);
 
     sr = srunner_create(s);

commit 32b4e848aeddaf1dc57a6fbb9327df216162a410
Author: Arun Raghavan <arun.raghavan at collabora.co.uk>
Date:   Fri Oct 26 16:39:11 2012 +0530

    tests: Allow off-by-one error in sconv test
    
    With some optimised sconv implementations (read NEON), rounding
    inaccuracy might lead to a difference of 1 with the reference
    implementation. The inaccuracy is worth the performance gain.
    
    Also increases floating-point accuracy while printing errors to make
    errors easier to analyse.

diff --git a/src/tests/cpu-test.c b/src/tests/cpu-test.c
index 3c7ad7d..dd21607 100644
--- a/src/tests/cpu-test.c
+++ b/src/tests/cpu-test.c
@@ -231,8 +231,8 @@ static void run_conv_test_float_to_s16(pa_convert_func_t func, pa_convert_func_t
         func(nsamples, floats, samples);
 
         for (i = 0; i < nsamples; i++) {
-            if (samples[i] != samples_ref[i]) {
-                pa_log_debug("%d: %04x != %04x (%f)\n", i, samples[i], samples_ref[i], floats[i]);
+            if (abs(samples[i] - samples_ref[i]) > 1) {
+                pa_log_debug("%d: %04x != %04x (%.24f)\n", i, samples[i], samples_ref[i], floats[i]);
                 fail();
             }
         }
@@ -248,8 +248,6 @@ static void run_conv_test_float_to_s16(pa_convert_func_t func, pa_convert_func_t
         PA_CPU_TEST_RUN_START("orig", TIMES, TIMES2) {
             orig_func(nsamples, floats, samples_ref);
         } PA_CPU_TEST_RUN_STOP
-
-        fail_unless(memcmp(samples_ref, samples, sizeof(nsamples)) == 0);
     }
 }
 
@@ -277,8 +275,8 @@ static void run_conv_test_s16_to_float(pa_convert_func_t func, pa_convert_func_t
         func(nsamples, samples, floats);
 
         for (i = 0; i < nsamples; i++) {
-            if (floats[i] != floats_ref[i]) {
-                pa_log_debug("%d: %f != %f (%d)\n", i, floats[i], floats_ref[i], samples[i]);
+            if (abs(floats[i] - floats_ref[i]) > 1) {
+                pa_log_debug("%d: %.24f != %.24f (%d)\n", i, floats[i], floats_ref[i], samples[i]);
                 fail();
             }
         }
@@ -294,8 +292,6 @@ static void run_conv_test_s16_to_float(pa_convert_func_t func, pa_convert_func_t
         PA_CPU_TEST_RUN_START("orig", TIMES, TIMES2) {
             orig_func(nsamples, samples, floats_ref);
         } PA_CPU_TEST_RUN_STOP
-
-        fail_unless(memcmp(floats_ref, floats, nsamples * sizeof(float)) == 0);
     }
 }
 

commit 1a8ec3c3e05f0f085c6831ee46205c1238fd2a08
Author: Arun Raghavan <arun.raghavan at collabora.co.uk>
Date:   Fri Oct 26 16:36:49 2012 +0530

    sconv: Fix NEON sconv rounding code
    
    Rounding with 0.5 causes us to always round up for any value of the form
    x.5. IEEE754 specifies round-to-nearest-even as the behaviour in this
    case. This might not always be possible with NEON code, but this change
    gets us much closer to it.

diff --git a/src/pulsecore/sconv_neon.c b/src/pulsecore/sconv_neon.c
index 81dd97e..6fd966d 100644
--- a/src/pulsecore/sconv_neon.c
+++ b/src/pulsecore/sconv_neon.c
@@ -40,18 +40,14 @@ static void pa_sconv_s16le_from_f32ne_neon(unsigned n, const float *src, int16_t
         "vneg.f32   q3, q2                  \n\t"
         "vdup.f32   q4, %[scale]            \n\t"
         "vdup.u32   q5, %[mask]             \n\t"
-        "vdup.f32   q6, %[half]             \n\t"
 
         "1:                                 \n\t"
         "vld1.32    {q0}, [%[src]]!         \n\t"
         "vmin.f32   q0, q0, q2              \n\t" /* clamp */
         "vmax.f32   q0, q0, q3              \n\t"
         "vmul.f32   q0, q0, q4              \n\t" /* scale */
-        "vand.u32   q1, q0, q5              \n\t"
-        "vorr.u32   q1, q1, q6              \n\t" /* round */
-        "vadd.f32   q0, q0, q1              \n\t"
-        "vcvt.s32.f32 q0, q0                \n\t" /* narrow */
-        "vmovn.i32  d0, q0                  \n\t"
+        "vcvt.s32.f32 q0, q0, #16           \n\t" /* narrow */
+        "vrshrn.s32  d0, q0, #16            \n\t"
         "subs       %[n], %[n], #1          \n\t"
         "vst1.16    {d0}, [%[dst]]!         \n\t"
         "bgt        1b                      \n\t"
@@ -59,7 +55,7 @@ static void pa_sconv_s16le_from_f32ne_neon(unsigned n, const float *src, int16_t
         "2:                                 \n\t"
 
         : [dst] "+r" (dst), [src] "+r" (src), [n] "+r" (n) /* output operands (or input operands that get modified) */
-        : [plusone] "r" (1.0f), [scale] "r" (32767.0f), [half] "r" (0.5f), [mask] "r" (0x80000000) /* input operands */
+        : [plusone] "r" (1.0f), [scale] "r" (32767.0f), [mask] "r" (0x80000000) /* input operands */
         : "memory", "cc", "q0", "q1", "q2", "q3", "q4", "q5", "q6" /* clobber list */
     );
 

commit f558327cca3188bd9ed04165d96d111efa078870
Author: Peter Meerwald <p.meerwald at bct-electronic.com>
Date:   Sat Oct 27 14:59:43 2012 +0200

    tests: Implement test code for ARM NEON sconv s16_to_float
    
    Signed-off-by: Peter Meerwald <p.meerwald at bct-electronic.com>

diff --git a/src/tests/cpu-test.c b/src/tests/cpu-test.c
index 35775bd..3c7ad7d 100644
--- a/src/tests/cpu-test.c
+++ b/src/tests/cpu-test.c
@@ -253,6 +253,52 @@ static void run_conv_test_float_to_s16(pa_convert_func_t func, pa_convert_func_t
     }
 }
 
+static void run_conv_test_s16_to_float(pa_convert_func_t func, pa_convert_func_t orig_func, int align, pa_bool_t correct,
+        pa_bool_t perf) {
+    PA_DECLARE_ALIGNED(8, float, f[SAMPLES]) = { 0 };
+    PA_DECLARE_ALIGNED(8, float, f_ref[SAMPLES]) = { 0 };
+    PA_DECLARE_ALIGNED(8, int16_t, s[SAMPLES]);
+    float *floats, *floats_ref;
+    int16_t *samples;
+    int i, nsamples;
+
+    /* Force sample alignment as requested */
+    floats = f + (8 - align);
+    floats_ref = f_ref + (8 - align);
+    samples = s + (8 - align);
+    nsamples = SAMPLES - (8 - align);
+
+    pa_random(samples, nsamples * sizeof(int16_t));
+
+    if (correct) {
+        pa_log_debug("Testing sconv correctness with %d byte alignment", align);
+
+        orig_func(nsamples, samples, floats_ref);
+        func(nsamples, samples, floats);
+
+        for (i = 0; i < nsamples; i++) {
+            if (floats[i] != floats_ref[i]) {
+                pa_log_debug("%d: %f != %f (%d)\n", i, floats[i], floats_ref[i], samples[i]);
+                fail();
+            }
+        }
+    }
+
+    if (perf) {
+        pa_log_debug("Testing sconv performance with %d byte alignment", align);
+
+        PA_CPU_TEST_RUN_START("func", TIMES, TIMES2) {
+            func(nsamples, samples, floats);
+        } PA_CPU_TEST_RUN_STOP
+
+        PA_CPU_TEST_RUN_START("orig", TIMES, TIMES2) {
+            orig_func(nsamples, samples, floats_ref);
+        } PA_CPU_TEST_RUN_STOP
+
+        fail_unless(memcmp(floats_ref, floats, nsamples * sizeof(float)) == 0);
+    }
+}
+
 #if defined (__i386__) || defined (__amd64__)
 START_TEST (sconv_sse_test) {
     pa_cpu_x86_flag_t flags = 0;
@@ -285,7 +331,8 @@ END_TEST
 #if defined (__arm__) && defined (__linux__)
 START_TEST (sconv_neon_test) {
     pa_cpu_arm_flag_t flags = 0;
-    pa_convert_func_t orig_func, neon_func;
+    pa_convert_func_t orig_from_func, neon_from_func;
+    pa_convert_func_t orig_to_func, neon_to_func;
 
     pa_cpu_get_arm_flags(&flags);
 
@@ -294,19 +341,31 @@ START_TEST (sconv_neon_test) {
         return;
     }
 
-    orig_func = pa_get_convert_from_float32ne_function(PA_SAMPLE_S16LE);
+    orig_from_func = pa_get_convert_from_float32ne_function(PA_SAMPLE_S16LE);
+    orig_to_func = pa_get_convert_to_float32ne_function(PA_SAMPLE_S16LE);
     pa_convert_func_init_neon(flags);
-    neon_func = pa_get_convert_from_float32ne_function(PA_SAMPLE_S16LE);
+    neon_from_func = pa_get_convert_from_float32ne_function(PA_SAMPLE_S16LE);
+    neon_to_func = pa_get_convert_to_float32ne_function(PA_SAMPLE_S16LE);
 
     pa_log_debug("Checking NEON sconv (float -> s16)");
-    run_conv_test_float_to_s16(neon_func, orig_func, 0, TRUE, FALSE);
-    run_conv_test_float_to_s16(neon_func, orig_func, 1, TRUE, FALSE);
-    run_conv_test_float_to_s16(neon_func, orig_func, 2, TRUE, FALSE);
-    run_conv_test_float_to_s16(neon_func, orig_func, 3, TRUE, FALSE);
-    run_conv_test_float_to_s16(neon_func, orig_func, 4, TRUE, FALSE);
-    run_conv_test_float_to_s16(neon_func, orig_func, 5, TRUE, FALSE);
-    run_conv_test_float_to_s16(neon_func, orig_func, 6, TRUE, FALSE);
-    run_conv_test_float_to_s16(neon_func, orig_func, 7, TRUE, TRUE);
+    run_conv_test_float_to_s16(neon_from_func, orig_from_func, 0, TRUE, FALSE);
+    run_conv_test_float_to_s16(neon_from_func, orig_from_func, 1, TRUE, FALSE);
+    run_conv_test_float_to_s16(neon_from_func, orig_from_func, 2, TRUE, FALSE);
+    run_conv_test_float_to_s16(neon_from_func, orig_from_func, 3, TRUE, FALSE);
+    run_conv_test_float_to_s16(neon_from_func, orig_from_func, 4, TRUE, FALSE);
+    run_conv_test_float_to_s16(neon_from_func, orig_from_func, 5, TRUE, FALSE);
+    run_conv_test_float_to_s16(neon_from_func, orig_from_func, 6, TRUE, FALSE);
+    run_conv_test_float_to_s16(neon_from_func, orig_from_func, 7, TRUE, TRUE);
+
+    pa_log_debug("Checking NEON sconv (s16 -> float)");
+    run_conv_test_s16_to_float(neon_to_func, orig_to_func, 0, TRUE, FALSE);
+    run_conv_test_s16_to_float(neon_to_func, orig_to_func, 1, TRUE, FALSE);
+    run_conv_test_s16_to_float(neon_to_func, orig_to_func, 2, TRUE, FALSE);
+    run_conv_test_s16_to_float(neon_to_func, orig_to_func, 3, TRUE, FALSE);
+    run_conv_test_s16_to_float(neon_to_func, orig_to_func, 4, TRUE, FALSE);
+    run_conv_test_s16_to_float(neon_to_func, orig_to_func, 5, TRUE, FALSE);
+    run_conv_test_s16_to_float(neon_to_func, orig_to_func, 6, TRUE, FALSE);
+    run_conv_test_s16_to_float(neon_to_func, orig_to_func, 7, TRUE, TRUE);
 }
 END_TEST
 #endif /* defined (__arm__) && defined (__linux__) */

commit bd7229b38a4d2ddd08af65cccec8b1df905ea3a8
Author: Peter Meerwald <p.meerwald at bct-electronic.com>
Date:   Fri Oct 26 13:04:47 2012 +0200

    tests: Fix test description in cpu-test
    
    Signed-off-by: Peter Meerwald <p.meerwald at bct-electronic.com>

diff --git a/src/tests/cpu-test.c b/src/tests/cpu-test.c
index 56b0cd7..35775bd 100644
--- a/src/tests/cpu-test.c
+++ b/src/tests/cpu-test.c
@@ -269,7 +269,7 @@ START_TEST (sconv_sse_test) {
     pa_convert_func_init_sse(flags);
     sse_func = pa_get_convert_from_float32ne_function(PA_SAMPLE_S16LE);
 
-    pa_log_debug("Checking SSE sconv (s16 -> float)");
+    pa_log_debug("Checking SSE sconv (float -> s16)");
     run_conv_test_float_to_s16(sse_func, orig_func, 0, TRUE, FALSE);
     run_conv_test_float_to_s16(sse_func, orig_func, 1, TRUE, FALSE);
     run_conv_test_float_to_s16(sse_func, orig_func, 2, TRUE, FALSE);
@@ -298,7 +298,7 @@ START_TEST (sconv_neon_test) {
     pa_convert_func_init_neon(flags);
     neon_func = pa_get_convert_from_float32ne_function(PA_SAMPLE_S16LE);
 
-    pa_log_debug("Checking NEON sconv (s16 -> float)");
+    pa_log_debug("Checking NEON sconv (float -> s16)");
     run_conv_test_float_to_s16(neon_func, orig_func, 0, TRUE, FALSE);
     run_conv_test_float_to_s16(neon_func, orig_func, 1, TRUE, FALSE);
     run_conv_test_float_to_s16(neon_func, orig_func, 2, TRUE, FALSE);

commit 1319c4533a7d3a2562907d043d238bfe3d51d335
Author: Peter Meerwald <p.meerwald at bct-electronic.com>
Date:   Tue Oct 23 17:54:57 2012 +0200

    core: Add ARM NEON optimized sample conversion code
    
    final:
    * includes some minor style fixes and build-time changes to allow
      building a single binary for neon and non-neon systems
    v4:
    * fix for sample length < 4
    v3:
    * convert from intrinsics to inline assembly
    v2:
    * load and store data with vld1/vld1q and vst1/vst1q, resp., to work
      around alignment issues of compiler-generated vldmia instruction
    * remove redundant check for NEON flags
    
    Ubuntu/Linaro gcc 4.6.3
    arm-linux-gnueabi-gcc -O2 -mcpu=cortex-a8 -mfloat-abi=softfp -mfpu=neon
    
    runtime on beagle-xm:
    
    D: [pulseaudio] sconv_neon.c: checking NEON sconv_s16le_from_float
    I: [pulseaudio] sconv_neon.c: NEON: 3754 usec.
    I: [pulseaudio] sconv_neon.c: ref: 58594 usec.
    D: [pulseaudio] sconv_neon.c: checking NEON sconv_s16le_to_float
    I: [pulseaudio] sconv_neon.c: NEON: 1831 usec.
    I: [pulseaudio] sconv_neon.c: ref: 10528 usec.
    I: [pulseaudio] sconv_neon.c: Initialising ARM NEON optimized conversions.
    
    conversion may be off by one for some samples due to rounding issues

diff --git a/configure.ac b/configure.ac
index 2154429..c91c572 100644
--- a/configure.ac
+++ b/configure.ac
@@ -317,6 +317,34 @@ case $host in
   ;;
 esac
 
+#### NEON optimisations ####
+AC_ARG_ENABLE([neon-opt],
+    AS_HELP_STRING([--enable-neon-opt], [Enable NEON optimisations on ARM CPUs that support it]))
+
+AS_IF([test "x$enable_neon_opt" != "xno"],
+    [save_CFLAGS="$CFLAGS"; CFLAGS="$CFLAGS -mfpu=neon"
+     AC_COMPILE_IFELSE(
+        AC_LANG_PROGRAM([], []),
+        [
+         HAVE_NEON=1
+         NEON_CFLAGS="-mfpu=neon"
+        ],
+        [
+         HAVE_NEON=0
+         NEON_CFLAGS=
+        ])
+     CFLAGS="$save_CFLAGS"
+    ],
+    [HAVE_NEON=0])
+
+AS_IF([test "x$enable_neon_opt" = "xyes" && test "x$HAVE_NEON" = "x0"],
+      [AC_MSG_ERROR([*** Compiler does not support -mfpu=neon])])
+
+AC_SUBST(HAVE_NEON)
+AC_SUBST(NEON_CFLAGS)
+AM_CONDITIONAL([HAVE_NEON], [test "x$HAVE_NEON" = x1])
+AS_IF([test "x$HAVE_NEON" = "x1"], AC_DEFINE([HAVE_NEON], 1, [Have NEON support?]))
+
 
 #### libtool stuff ####
 
diff --git a/src/Makefile.am b/src/Makefile.am
index f80c448..84598b2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -813,6 +813,7 @@ libpulsedsp_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version -disable-static
 ###################################
 
 lib_LTLIBRARIES += libpulsecore- at PA_MAJORMINOR@.la
+noinst_LTLIBRARIES =
 
 # Pure core stuff
 libpulsecore_ at PA_MAJORMINOR@_la_SOURCES = \
@@ -870,6 +871,13 @@ libpulsecore_ at PA_MAJORMINOR@_la_CFLAGS = $(AM_CFLAGS) $(SERVER_CFLAGS) $(LIBSAMP
 libpulsecore_ at PA_MAJORMINOR@_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version
 libpulsecore_ at PA_MAJORMINOR@_la_LIBADD = $(AM_LIBADD) $(LIBLTDL) $(LIBSAMPLERATE_LIBS) $(LIBSPEEX_LIBS) $(LIBSNDFILE_LIBS) $(WINSOCK_LIBS) $(LTLIBICONV) libpulsecommon- at PA_MAJORMINOR@.la libpulse.la libpulsecore-foreign.la
 
+if HAVE_NEON
+noinst_LTLIBRARIES += libpulsecore_sconv_neon.la
+libpulsecore_sconv_neon_la_SOURCES = pulsecore/sconv_neon.c
+libpulsecore_sconv_neon_la_CFLAGS = $(AM_CFLAGS) $(NEON_CFLAGS)
+libpulsecore_ at PA_MAJORMINOR@_la_LIBADD += libpulsecore_sconv_neon.la
+endif
+
 if HAVE_ORC
 ORC_SOURCE += pulsecore/svolume
 libpulsecore_ at PA_MAJORMINOR@_la_SOURCES += pulsecore/svolume_orc.c
@@ -909,7 +917,7 @@ libpulsecore_ at PA_MAJORMINOR@_la_SOURCES += pulsecore/database-simple.c
 endif
 
 # We split the foreign code off to not be annoyed by warnings we don't care about
-noinst_LTLIBRARIES = libpulsecore-foreign.la
+noinst_LTLIBRARIES += libpulsecore-foreign.la
 
 libpulsecore_foreign_la_SOURCES = \
 		pulsecore/ffmpeg/resample2.c pulsecore/ffmpeg/avcodec.h pulsecore/ffmpeg/dsputil.h
diff --git a/src/pulsecore/cpu-arm.c b/src/pulsecore/cpu-arm.c
index 934c7fe..05668f1 100644
--- a/src/pulsecore/cpu-arm.c
+++ b/src/pulsecore/cpu-arm.c
@@ -142,6 +142,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)
+        pa_convert_func_init_neon(*flags);
+#endif
 
     return TRUE;
 
diff --git a/src/pulsecore/cpu-arm.h b/src/pulsecore/cpu-arm.h
index 91aa659..d2d3f5c 100644
--- a/src/pulsecore/cpu-arm.h
+++ b/src/pulsecore/cpu-arm.h
@@ -26,6 +26,10 @@
 #include <stdint.h>
 #include <pulsecore/macro.h>
 
+#ifndef PACKAGE
+#error "Please include config.h before including this file!"
+#endif
+
 typedef enum pa_cpu_arm_flag {
     PA_CPU_ARM_V6       = (1 << 0),
     PA_CPU_ARM_V7       = (1 << 1),
@@ -41,4 +45,8 @@ pa_bool_t pa_cpu_init_arm(pa_cpu_arm_flag_t *flags);
 /* some optimized functions */
 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);
+#endif
+
 #endif /* foocpuarmhfoo */
diff --git a/src/pulsecore/sconv_neon.c b/src/pulsecore/sconv_neon.c
new file mode 100644
index 0000000..81dd97e
--- /dev/null
+++ b/src/pulsecore/sconv_neon.c
@@ -0,0 +1,110 @@
+/***
+  This file is part of PulseAudio.
+
+  Copyright 2012 Peter Meerwald <p.meerwald at bct-electronic.com>
+
+  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 <config.h>
+#endif
+
+#include <pulse/rtclock.h>
+
+#include <pulsecore/macro.h>
+#include <pulsecore/endianmacros.h>
+
+#include "cpu-arm.h"
+#include "sconv.h"
+
+#include <math.h>
+#include <arm_neon.h>
+
+static void pa_sconv_s16le_from_f32ne_neon(unsigned n, const float *src, int16_t *dst) {
+    unsigned i = n & 3;
+
+    __asm__ __volatile__ (
+        "movs       %[n], %[n], lsr #2      \n\t"
+        "beq        2f                      \n\t"
+
+        "vdup.f32   q2, %[plusone]          \n\t"
+        "vneg.f32   q3, q2                  \n\t"
+        "vdup.f32   q4, %[scale]            \n\t"
+        "vdup.u32   q5, %[mask]             \n\t"
+        "vdup.f32   q6, %[half]             \n\t"
+
+        "1:                                 \n\t"
+        "vld1.32    {q0}, [%[src]]!         \n\t"
+        "vmin.f32   q0, q0, q2              \n\t" /* clamp */
+        "vmax.f32   q0, q0, q3              \n\t"
+        "vmul.f32   q0, q0, q4              \n\t" /* scale */
+        "vand.u32   q1, q0, q5              \n\t"
+        "vorr.u32   q1, q1, q6              \n\t" /* round */
+        "vadd.f32   q0, q0, q1              \n\t"
+        "vcvt.s32.f32 q0, q0                \n\t" /* narrow */
+        "vmovn.i32  d0, q0                  \n\t"
+        "subs       %[n], %[n], #1          \n\t"
+        "vst1.16    {d0}, [%[dst]]!         \n\t"
+        "bgt        1b                      \n\t"
+
+        "2:                                 \n\t"
+
+        : [dst] "+r" (dst), [src] "+r" (src), [n] "+r" (n) /* output operands (or input operands that get modified) */
+        : [plusone] "r" (1.0f), [scale] "r" (32767.0f), [half] "r" (0.5f), [mask] "r" (0x80000000) /* input operands */
+        : "memory", "cc", "q0", "q1", "q2", "q3", "q4", "q5", "q6" /* clobber list */
+    );
+
+    /* leftovers */
+    while (i--) {
+        *dst++ = (int16_t) lrintf(PA_CLAMP_UNLIKELY(*src, -1.0f, 1.0f) * 0x7FFF);
+        src++;
+    }
+}
+
+static void pa_sconv_s16le_to_f32ne_neon(unsigned n, const int16_t *src, float *dst) {
+    unsigned i = n & 3;
+
+    const float invscale = 1.0f / 0x7FFF;
+
+    __asm__ __volatile__ (
+        "movs        %[n], %[n], lsr #2     \n\t"
+        "beq        2f                      \n\t"
+
+        "vdup.f32   q1, %[invscale]         \n\t"
+
+        "1:                                 \n\t"
+        "vld1.16    {d0}, [%[src]]!         \n\t"
+        "vmovl.s16  q0, d0                  \n\t"
+        "vcvt.f32.s32 q0, q0                \n\t"
+        "vmul.f32   q0, q0, q1              \n\t"
+        "subs       %[n], %[n], #1          \n\t"
+        "vst1.32    {q0}, [%[dst]]!         \n\t"
+        "bgt        1b                      \n\t"
+
+        "2:                                 \n\t"
+
+        : [dst] "+r" (dst), [src] "+r" (src), [n] "+r" (n) /* output operands (or input operands that get modified) */
+        : [invscale] "r" (invscale) /* input operands */
+        : "memory", "cc", "q0", "q1" /* clobber list */
+    );
+
+    /* leftovers */
+    while (i--) {
+        *dst++ = *src++ * invscale;
+    }
+}
+
+void pa_convert_func_init_neon(pa_cpu_arm_flag_t flags) {
+    pa_log_info("Initialising ARM NEON optimized conversions.");
+    pa_set_convert_from_float32ne_function(PA_SAMPLE_S16LE, (pa_convert_func_t) pa_sconv_s16le_from_f32ne_neon);
+    pa_set_convert_to_float32ne_function(PA_SAMPLE_S16LE, (pa_convert_func_t) pa_sconv_s16le_to_f32ne_neon);
+}
diff --git a/src/tests/cpu-test.c b/src/tests/cpu-test.c
index 5b83d84..56b0cd7 100644
--- a/src/tests/cpu-test.c
+++ b/src/tests/cpu-test.c
@@ -282,6 +282,35 @@ START_TEST (sconv_sse_test) {
 END_TEST
 #endif /* defined (__i386__) || defined (__amd64__) */
 
+#if defined (__arm__) && defined (__linux__)
+START_TEST (sconv_neon_test) {
+    pa_cpu_arm_flag_t flags = 0;
+    pa_convert_func_t orig_func, neon_func;
+
+    pa_cpu_get_arm_flags(&flags);
+
+    if (!(flags & PA_CPU_ARM_NEON)) {
+        pa_log_info("NEON not supported. Skipping");
+        return;
+    }
+
+    orig_func = pa_get_convert_from_float32ne_function(PA_SAMPLE_S16LE);
+    pa_convert_func_init_neon(flags);
+    neon_func = pa_get_convert_from_float32ne_function(PA_SAMPLE_S16LE);
+
+    pa_log_debug("Checking NEON sconv (s16 -> float)");
+    run_conv_test_float_to_s16(neon_func, orig_func, 0, TRUE, FALSE);
+    run_conv_test_float_to_s16(neon_func, orig_func, 1, TRUE, FALSE);
+    run_conv_test_float_to_s16(neon_func, orig_func, 2, TRUE, FALSE);
+    run_conv_test_float_to_s16(neon_func, orig_func, 3, TRUE, FALSE);
+    run_conv_test_float_to_s16(neon_func, orig_func, 4, TRUE, FALSE);
+    run_conv_test_float_to_s16(neon_func, orig_func, 5, TRUE, FALSE);
+    run_conv_test_float_to_s16(neon_func, orig_func, 6, TRUE, FALSE);
+    run_conv_test_float_to_s16(neon_func, orig_func, 7, TRUE, TRUE);
+}
+END_TEST
+#endif /* defined (__arm__) && defined (__linux__) */
+
 #undef SAMPLES
 #undef TIMES
 /* End conversion tests */
@@ -314,6 +343,11 @@ int main(int argc, char *argv[]) {
 #if defined (__i386__) || defined (__amd64__)
     tcase_add_test(tc, sconv_sse_test);
 #endif
+#if defined (__arm__) && defined (__linux__)
+#if HAVE_NEON
+    tcase_add_test(tc, sconv_neon_test);
+#endif
+#endif
     suite_add_tcase(s, tc);
 
     sr = srunner_create(s);



More information about the pulseaudio-commits mailing list