2 This file is part of PulseAudio.
4 Copyright 2004-2006 Lennart Poettering
5 Copyright 2009 Wim Taymans <wim.taymans@collabora.co.uk.com>
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.
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.
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
27 #include <pulse/sample.h>
28 #include <pulse/volume.h>
29 #include <pulsecore/log.h>
30 #include <pulsecore/macro.h>
35 #define LOAD_SAMPLES \
36 " movq (%1), %%mm0 \n\t" \
37 " movq 8(%1), %%mm2 \n\t" \
38 " movq 16(%1), %%mm4 \n\t" \
39 " movq 24(%1), %%mm6 \n\t" \
40 " movq %%mm0, %%mm1 \n\t" \
41 " movq %%mm2, %%mm3 \n\t" \
42 " movq %%mm4, %%mm5 \n\t" \
43 " movq %%mm6, %%mm7 \n\t"
45 #define UNPACK_SAMPLES(s) \
46 " punpckl"#s" %%mm0, %%mm0 \n\t" \
47 " punpckh"#s" %%mm1, %%mm1 \n\t" \
48 " punpckl"#s" %%mm2, %%mm2 \n\t" \
49 " punpckh"#s" %%mm3, %%mm3 \n\t" \
50 " punpckl"#s" %%mm4, %%mm4 \n\t" \
51 " punpckh"#s" %%mm5, %%mm5 \n\t" \
52 " punpckl"#s" %%mm6, %%mm6 \n\t" \
53 " punpckh"#s" %%mm7, %%mm7 \n\t"
55 #define STORE_SAMPLES \
56 " movq %%mm0, (%0) \n\t" \
57 " movq %%mm1, 8(%0) \n\t" \
58 " movq %%mm2, 16(%0) \n\t" \
59 " movq %%mm3, 24(%0) \n\t" \
60 " movq %%mm4, 32(%0) \n\t" \
61 " movq %%mm5, 40(%0) \n\t" \
62 " movq %%mm6, 48(%0) \n\t" \
63 " movq %%mm7, 56(%0) \n\t" \
67 #define HANDLE_SINGLE_dq() \
68 " movd (%1), %%mm0 \n\t" \
69 " punpckldq %%mm0, %%mm0 \n\t" \
70 " movq %%mm0, (%0) \n\t" \
74 #define HANDLE_SINGLE_wd() \
75 " movw (%1), %w3 \n\t" \
76 " movd %3, %%mm0 \n\t" \
77 " punpcklwd %%mm0, %%mm0 \n\t" \
78 " movd %%mm0, (%0) \n\t" \
82 #define MONO_TO_STEREO(s,shift,mask) \
84 " sar $"#shift", %2 \n\t" \
95 " and $"#mask", %2 \n\t" \
104 #if defined (__i386__) || defined (__amd64__)
105 static void remap_mono_to_stereo_s16ne_mmx(pa_remap_t
*m
, void *dst
, const void *src
, unsigned n
) {
106 pa_reg_x86 temp
, temp2
;
108 __asm__
__volatile__ (
109 MONO_TO_STEREO(wd
,4,15) /* do words to doubles */
110 : "+r" (dst
), "+r" (src
), "=&r" (temp
), "=&r" (temp2
)
111 : "r" ((pa_reg_x86
)n
)
116 static void remap_mono_to_stereo_float32ne_mmx(pa_remap_t
*m
, void *dst
, const void *src
, unsigned n
) {
117 pa_reg_x86 temp
, temp2
;
119 __asm__
__volatile__ (
120 MONO_TO_STEREO(dq
,3,7) /* do doubles to quads */
121 : "+r" (dst
), "+r" (src
), "=&r" (temp
), "=&r" (temp2
)
122 : "r" ((pa_reg_x86
)n
)
127 /* set the function that will execute the remapping based on the matrices */
128 static void init_remap_mmx(pa_remap_t
*m
) {
131 n_oc
= m
->o_ss
.channels
;
132 n_ic
= m
->i_ss
.channels
;
134 /* find some common channel remappings, fall back to full matrix operation. */
135 if (n_ic
== 1 && n_oc
== 2 &&
136 m
->map_table_i
[0][0] == 0x10000 && m
->map_table_i
[1][0] == 0x10000) {
138 pa_log_info("Using MMX mono to stereo remapping");
139 pa_set_remap_func(m
, remap_mono_to_stereo_s16ne_mmx
, remap_mono_to_stereo_float32ne_mmx
);
142 #endif /* defined (__i386__) || defined (__amd64__) */
144 void pa_remap_func_init_mmx(pa_cpu_x86_flag_t flags
) {
145 #if defined (__i386__) || defined (__amd64__)
147 if (flags
& PA_CPU_X86_MMX
) {
148 pa_log_info("Initialising MMX optimized remappers.");
150 pa_set_init_remap_func((pa_init_remap_func_t
) init_remap_mmx
);
153 #endif /* defined (__i386__) || defined (__amd64__) */