]> code.delx.au - pulseaudio/blob - src/pulsecore/remap_sse.c
remap: Change remapping function argument type from void to int16_t / float as approp...
[pulseaudio] / src / pulsecore / remap_sse.c
1 /***
2 This file is part of PulseAudio.
3
4 Copyright 2004-2006 Lennart Poettering
5 Copyright 2009 Wim Taymans <wim.taymans@collabora.co.uk.com>
6
7 PulseAudio is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published
9 by the Free Software Foundation; either version 2.1 of the License,
10 or (at your option) any later version.
11
12 PulseAudio is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with PulseAudio; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA.
21 ***/
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <pulse/sample.h>
28 #include <pulse/volume.h>
29 #include <pulsecore/log.h>
30 #include <pulsecore/macro.h>
31
32 #include "cpu-x86.h"
33 #include "remap.h"
34
35 #define LOAD_SAMPLES \
36 " movdqu (%1), %%xmm0 \n\t" \
37 " movdqu 16(%1), %%xmm2 \n\t" \
38 " movdqu 32(%1), %%xmm4 \n\t" \
39 " movdqu 48(%1), %%xmm6 \n\t" \
40 " movdqa %%xmm0, %%xmm1 \n\t" \
41 " movdqa %%xmm2, %%xmm3 \n\t" \
42 " movdqa %%xmm4, %%xmm5 \n\t" \
43 " movdqa %%xmm6, %%xmm7 \n\t"
44
45 #define UNPACK_SAMPLES(s) \
46 " punpckl"#s" %%xmm0, %%xmm0 \n\t" \
47 " punpckh"#s" %%xmm1, %%xmm1 \n\t" \
48 " punpckl"#s" %%xmm2, %%xmm2 \n\t" \
49 " punpckh"#s" %%xmm3, %%xmm3 \n\t" \
50 " punpckl"#s" %%xmm4, %%xmm4 \n\t" \
51 " punpckh"#s" %%xmm5, %%xmm5 \n\t" \
52 " punpckl"#s" %%xmm6, %%xmm6 \n\t" \
53 " punpckh"#s" %%xmm7, %%xmm7 \n\t"
54
55 #define STORE_SAMPLES \
56 " movdqu %%xmm0, (%0) \n\t" \
57 " movdqu %%xmm1, 16(%0) \n\t" \
58 " movdqu %%xmm2, 32(%0) \n\t" \
59 " movdqu %%xmm3, 48(%0) \n\t" \
60 " movdqu %%xmm4, 64(%0) \n\t" \
61 " movdqu %%xmm5, 80(%0) \n\t" \
62 " movdqu %%xmm6, 96(%0) \n\t" \
63 " movdqu %%xmm7, 112(%0) \n\t" \
64 " add $64, %1 \n\t" \
65 " add $128, %0 \n\t"
66
67 #define HANDLE_SINGLE_dq() \
68 " movd (%1), %%xmm0 \n\t" \
69 " punpckldq %%xmm0, %%xmm0 \n\t" \
70 " movq %%xmm0, (%0) \n\t" \
71 " add $4, %1 \n\t" \
72 " add $8, %0 \n\t"
73
74 #define HANDLE_SINGLE_wd() \
75 " movw (%1), %w3 \n\t" \
76 " movd %3, %%xmm0 \n\t" \
77 " punpcklwd %%xmm0, %%xmm0 \n\t" \
78 " movd %%xmm0, (%0) \n\t" \
79 " add $2, %1 \n\t" \
80 " add $4, %0 \n\t"
81
82 #define MONO_TO_STEREO(s,shift,mask) \
83 " mov %4, %2 \n\t" \
84 " sar $"#shift", %2 \n\t" \
85 " cmp $0, %2 \n\t" \
86 " je 2f \n\t" \
87 "1: \n\t" \
88 LOAD_SAMPLES \
89 UNPACK_SAMPLES(s) \
90 STORE_SAMPLES \
91 " dec %2 \n\t" \
92 " jne 1b \n\t" \
93 "2: \n\t" \
94 " mov %4, %2 \n\t" \
95 " and $"#mask", %2 \n\t" \
96 " je 4f \n\t" \
97 "3: \n\t" \
98 HANDLE_SINGLE_##s() \
99 " dec %2 \n\t" \
100 " jne 3b \n\t" \
101 "4: \n\t"
102
103 #if defined (__i386__) || defined (__amd64__)
104 static void remap_mono_to_stereo_s16ne_sse2(pa_remap_t *m, int16_t *dst, const int16_t *src, unsigned n) {
105 pa_reg_x86 temp, temp2;
106
107 __asm__ __volatile__ (
108 MONO_TO_STEREO(wd, 5, 31) /* do words to doubles */
109 : "+r" (dst), "+r" (src), "=&r" (temp), "=&r" (temp2)
110 : "r" ((pa_reg_x86)n)
111 : "cc"
112 );
113 }
114
115 static void remap_mono_to_stereo_float32ne_sse2(pa_remap_t *m, float *dst, const float *src, unsigned n) {
116 pa_reg_x86 temp, temp2;
117
118 __asm__ __volatile__ (
119 MONO_TO_STEREO(dq, 4, 15) /* do doubles to quads */
120 : "+r" (dst), "+r" (src), "=&r" (temp), "=&r" (temp2)
121 : "r" ((pa_reg_x86)n)
122 : "cc"
123 );
124 }
125
126 /* set the function that will execute the remapping based on the matrices */
127 static void init_remap_sse2(pa_remap_t *m) {
128 unsigned n_oc, n_ic;
129
130 n_oc = m->o_ss.channels;
131 n_ic = m->i_ss.channels;
132
133 /* find some common channel remappings, fall back to full matrix operation. */
134 if (n_ic == 1 && n_oc == 2 &&
135 m->map_table_i[0][0] == 0x10000 && m->map_table_i[1][0] == 0x10000) {
136
137 pa_log_info("Using SSE2 mono to stereo remapping");
138 pa_set_remap_func(m, (pa_do_remap_func_t) remap_mono_to_stereo_s16ne_sse2,
139 (pa_do_remap_func_t) remap_mono_to_stereo_float32ne_sse2);
140 }
141 }
142 #endif /* defined (__i386__) || defined (__amd64__) */
143
144 void pa_remap_func_init_sse(pa_cpu_x86_flag_t flags) {
145 #if defined (__i386__) || defined (__amd64__)
146
147 if (flags & PA_CPU_X86_SSE2) {
148 pa_log_info("Initialising SSE2 optimized remappers.");
149 pa_set_init_remap_func ((pa_init_remap_func_t) init_remap_sse2);
150 }
151
152 #endif /* defined (__i386__) || defined (__amd64__) */
153 }