]> code.delx.au - pulseaudio/blob - src/pulsecore/sconv_neon.c
Style fix: Remove new lines from opening brackets
[pulseaudio] / src / pulsecore / sconv_neon.c
1 /***
2 This file is part of PulseAudio.
3
4 Copyright 2012 Peter Meerwald <p.meerwald@bct-electronic.com>
5
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2.1 of the License,
9 or (at your option) any later version.
10
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15 ***/
16
17 #ifdef HAVE_CONFIG_H
18 #include <config.h>
19 #endif
20
21 #include <pulse/rtclock.h>
22
23 #include <pulsecore/macro.h>
24 #include <pulsecore/endianmacros.h>
25
26 #include "cpu-arm.h"
27 #include "sconv.h"
28
29 #include <math.h>
30 #include <arm_neon.h>
31
32 static void pa_sconv_s16le_from_f32ne_neon(unsigned n, const float *src, int16_t *dst) {
33 unsigned i = n & 3;
34
35 __asm__ __volatile__ (
36 "movs %[n], %[n], lsr #2 \n\t"
37 "beq 2f \n\t"
38
39 "vdup.f32 q1, %[scale] \n\t"
40
41 "1: \n\t"
42 "vld1.32 {q0}, [%[src]]! \n\t"
43 "vmul.f32 q0, q0, q1 \n\t" /* scale */
44 "vcvt.s32.f32 q0, q0, #16 \n\t" /* s32<-f32 as 16:16 fixed-point */
45 "vqrshrn.s32 d0, q0, #16 \n\t" /* shift, round, narrow */
46 "subs %[n], %[n], #1 \n\t"
47 "vst1.16 {d0}, [%[dst]]! \n\t"
48 "bgt 1b \n\t"
49
50 "2: \n\t"
51
52 : [dst] "+r" (dst), [src] "+r" (src), [n] "+r" (n) /* output operands (or input operands that get modified) */
53 : [scale] "r" (32768.0f) /* input operands */
54 : "memory", "cc", "q0", "q1" /* clobber list */
55 );
56
57 /* leftovers */
58 while (i--) {
59 *dst++ = (int16_t) PA_CLAMP_UNLIKELY(lrintf(*src * (1 << 15)), -0x8000, 0x7FFF);
60 src++;
61 }
62 }
63
64 static void pa_sconv_s16le_to_f32ne_neon(unsigned n, const int16_t *src, float *dst) {
65 unsigned i = n & 3;
66
67 const float invscale = 1.0f / (1 << 15);
68
69 __asm__ __volatile__ (
70 "movs %[n], %[n], lsr #2 \n\t"
71 "beq 2f \n\t"
72
73 "vdup.f32 q1, %[invscale] \n\t"
74
75 "1: \n\t"
76 "vld1.16 {d0}, [%[src]]! \n\t"
77 "vmovl.s16 q0, d0 \n\t" /* widen */
78 "vcvt.f32.s32 q0, q0 \n\t" /* f32<-s32 */
79 "vmul.f32 q0, q0, q1 \n\t"
80 "subs %[n], %[n], #1 \n\t"
81 "vst1.32 {q0}, [%[dst]]! \n\t"
82 "bgt 1b \n\t"
83
84 "2: \n\t"
85
86 : [dst] "+r" (dst), [src] "+r" (src), [n] "+r" (n) /* output operands (or input operands that get modified) */
87 : [invscale] "r" (invscale) /* input operands */
88 : "memory", "cc", "q0", "q1" /* clobber list */
89 );
90
91 /* leftovers */
92 while (i--) {
93 *dst++ = *src++ * invscale;
94 }
95 }
96
97 void pa_convert_func_init_neon(pa_cpu_arm_flag_t flags) {
98 pa_log_info("Initialising ARM NEON optimized conversions.");
99 pa_set_convert_from_float32ne_function(PA_SAMPLE_S16LE, (pa_convert_func_t) pa_sconv_s16le_from_f32ne_neon);
100 pa_set_convert_to_float32ne_function(PA_SAMPLE_S16LE, (pa_convert_func_t) pa_sconv_s16le_to_f32ne_neon);
101 }