comparison src/audio/SDL_mixer_MMX.c @ 539:a9e38f3b8e4d

Added MMX audio mixing code for gcc (thanks Stephane!)
author Sam Lantinga <slouken@libsdl.org>
date Sat, 09 Nov 2002 06:13:28 +0000
parents
children b4b64bb88f2f
comparison
equal deleted inserted replaced
538:d3abe873e3f7 539:a9e38f3b8e4d
1 // MMX assembler version of SDL_MixAudio for signed little endian 16 bit samples and signed 8 bit samples
2 // Copyright 2002 Stephane Marchesin (stephane.marchesin@wanadoo.fr)
3 // This code is licensed under the LGPL (see COPYING for details)
4 //
5 // Assumes buffer size in bytes is a multiple of 16
6 // Assumes SDL_MIX_MAXVOLUME = 128
7
8
9 ////////////////////////////////////////////////
10 // Mixing for 16 bit signed buffers
11 ////////////////////////////////////////////////
12
13 #if defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT)
14 void SDL_MixAudio_MMX_S16(char* dst,char* src,unsigned int size,int volume)
15 {
16 __asm__ __volatile__ (
17
18 " movl %0,%%edi\n" // edi = dst
19 " movl %1,%%esi\n" // esi = src
20 " movl %3,%%eax\n" // eax = volume
21
22 " movl %2,%%ebx\n" // ebx = size
23
24 " shrl $4,%%ebx\n" // process 16 bytes per iteration = 8 samples
25
26 " jz .endS16\n"
27
28 " pxor %%mm0,%%mm0\n"
29
30 " movd %%eax,%%mm0\n"
31 " movq %%mm0,%%mm1\n"
32 " psllq $16,%%mm0\n"
33 " por %%mm1,%%mm0\n"
34 " psllq $16,%%mm0\n"
35 " por %%mm1,%%mm0\n"
36 " psllq $16,%%mm0\n"
37 " por %%mm1,%%mm0\n" // mm0 = vol|vol|vol|vol
38
39 ".align 16\n"
40 " .mixloopS16:\n"
41
42 " movq (%%esi),%%mm1\n" // mm1 = a|b|c|d
43
44 " movq %%mm1,%%mm2\n" // mm2 = a|b|c|d
45
46 " movq 8(%%esi),%%mm4\n" // mm4 = e|f|g|h
47
48 // pré charger le buffer dst dans mm7
49 " movq (%%edi),%%mm7\n" // mm7 = dst[0]"
50
51 // multiplier par le volume
52 " pmullw %%mm0,%%mm1\n" // mm1 = l(a*v)|l(b*v)|l(c*v)|l(d*v)
53
54 " pmulhw %%mm0,%%mm2\n" // mm2 = h(a*v)|h(b*v)|h(c*v)|h(d*v)
55 " movq %%mm4,%%mm5\n" // mm5 = e|f|g|h
56
57 " pmullw %%mm0,%%mm4\n" // mm4 = l(e*v)|l(f*v)|l(g*v)|l(h*v)
58
59 " pmulhw %%mm0,%%mm5\n" // mm5 = h(e*v)|h(f*v)|h(g*v)|h(h*v)
60 " movq %%mm1,%%mm3\n" // mm3 = l(a*v)|l(b*v)|l(c*v)|l(d*v)
61
62 " punpckhwd %%mm2,%%mm1\n" // mm1 = a*v|b*v
63
64 " movq %%mm4,%%mm6\n" // mm6 = l(e*v)|l(f*v)|l(g*v)|l(h*v)
65 " punpcklwd %%mm2,%%mm3\n" // mm3 = c*v|d*v
66
67 " punpckhwd %%mm5,%%mm4\n" // mm4 = e*f|f*v
68
69 " punpcklwd %%mm5,%%mm6\n" // mm6 = g*v|h*v
70
71 // pré charger le buffer dst dans mm5
72 " movq 8(%%edi),%%mm5\n" // mm5 = dst[1]
73
74 // diviser par 128
75 " psrad $7,%%mm1\n" // mm1 = a*v/128|b*v/128 , 128 = SDL_MIX_MAXVOLUME
76 " addl $16,%%esi\n"
77
78 " psrad $7,%%mm3\n" // mm3 = c*v/128|d*v/128
79
80 " psrad $7,%%mm4\n" // mm4 = e*v/128|f*v/128
81
82 // mm1 = le sample avec le volume modifié
83 " packssdw %%mm1,%%mm3\n" // mm3 = s(a*v|b*v|c*v|d*v)
84
85 " psrad $7,%%mm6\n" // mm6= g*v/128|h*v/128
86 " paddsw %%mm7,%%mm3\n" // mm3 = adjust_volume(src)+dst
87
88 // mm4 = le sample avec le volume modifié
89 " packssdw %%mm4,%%mm6\n" // mm6 = s(e*v|f*v|g*v|h*v)
90 " movq %%mm3,(%%edi)\n"
91
92 " paddsw %%mm5,%%mm6\n" // mm6 = adjust_volume(src)+dst
93
94 " movq %%mm6,8(%%edi)\n"
95
96 " addl $16,%%edi\n"
97
98 " dec %%ebx\n"
99
100 " jnz .mixloopS16\n"
101
102 " emms\n"
103
104 ".endS16:\n"
105 :
106 : "m" (dst), "m"(src),"m"(size),
107 "m"(volume)
108 : "eax","ebx", "esi", "edi","memory"
109 );
110 }
111
112
113
114 ////////////////////////////////////////////////
115 // Mixing for 8 bit signed buffers
116 ////////////////////////////////////////////////
117
118 void SDL_MixAudio_MMX_S8(char* dst,char* src,unsigned int size,int volume)
119 {
120 __asm__ __volatile__ (
121
122 " movl %0,%%edi\n" // edi = dst
123 " movl %1,%%esi\n" // esi = src
124 " movl %3,%%eax\n" // eax = volume
125
126 " movd %%ebx,%%mm0\n"
127 " movq %%mm0,%%mm1\n"
128 " psllq $16,%%mm0\n"
129 " por %%mm1,%%mm0\n"
130 " psllq $16,%%mm0\n"
131 " por %%mm1,%%mm0\n"
132 " psllq $16,%%mm0\n"
133 " por %%mm1,%%mm0\n"
134
135 " movl %2,%%ebx\n" // ebx = size
136 " shr $3,%%ebx\n" // process 8 bytes per iteration = 8 samples
137
138 " cmp $0,%%ebx\n"
139 " je .endS8\n"
140
141 ".align 16\n"
142 " .mixloopS8:\n"
143
144 " pxor %%mm2,%%mm2\n" // mm2 = 0
145 " movq (%%esi),%%mm1\n" // mm1 = a|b|c|d|e|f|g|h
146
147 " movq %%mm1,%%mm3\n" // mm3 = a|b|c|d|e|f|g|h
148
149 // on va faire le "sign extension" en faisant un cmp avec 0 qui retourne 1 si <0, 0 si >0
150 " pcmpgtb %%mm1,%%mm2\n" // mm2 = 11111111|00000000|00000000....
151
152 " punpckhbw %%mm2,%%mm1\n" // mm1 = 0|a|0|b|0|c|0|d
153
154 " punpcklbw %%mm2,%%mm3\n" // mm3 = 0|e|0|f|0|g|0|h
155 " movq (%%edi),%%mm2\n" // mm2 = destination
156
157 " pmullw %%mm0,%%mm1\n" // mm1 = v*a|v*b|v*c|v*d
158 " addl $8,%%esi\n"
159
160 " pmullw %%mm0,%%mm3\n" // mm3 = v*e|v*f|v*g|v*h
161 " psraw $7,%%mm1\n" // mm1 = v*a/128|v*b/128|v*c/128|v*d/128
162
163 " psraw $7,%%mm3\n" // mm3 = v*e/128|v*f/128|v*g/128|v*h/128
164
165 " packsswb %%mm1,%%mm3\n" // mm1 = v*a/128|v*b/128|v*c/128|v*d/128|v*e/128|v*f/128|v*g/128|v*h/128
166
167 " paddsb %%mm2,%%mm3\n" // add to destination buffer
168
169 " movq %%mm3,(%%edi)\n" // store back to ram
170 " addl $8,%%edi\n"
171
172 " dec %%ebx\n"
173
174 " jnz .mixloopS8\n"
175
176 ".endS8:\n"
177 " emms\n"
178 :
179 : "m" (dst), "m"(src),"m"(size),
180 "m"(volume)
181 : "eax","ebx", "esi", "edi","memory"
182 );
183 }
184 #endif
185