comparison src/audio/SDL_mixer_MMX_VC.c @ 574:64fe373be3dc

Cth converted the MMX audio mixing routines to VC++ syntax
author Sam Lantinga <slouken@libsdl.org>
date Mon, 20 Jan 2003 16:01:20 +0000
parents
children 72ef7ce609ef
comparison
equal deleted inserted replaced
573:6c3fa3b5e397 574:64fe373be3dc
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 // Converted to Intel ASM notation by Cth
4 // This code is licensed under the LGPL (see COPYING for details)
5 //
6 // Assumes buffer size in bytes is a multiple of 16
7 // Assumes SDL_MIX_MAXVOLUME = 128
8
9
10 ////////////////////////////////////////////////
11 // Mixing for 16 bit signed buffers
12 ////////////////////////////////////////////////
13
14 #if defined(USE_ASM_MIXER_VC)
15 #include <windows.h>
16 #include <stdio.h>
17
18 void SDL_MixAudio_MMX_S16_VC(char* dst,char* src,unsigned int nSize,int volume)
19 {
20 __asm
21 {
22 align 16
23
24 push edi
25 push esi
26 push ebx
27
28 mov edi, dst // edi = dst
29 mov esi, src // esi = src
30 mov eax, volume // eax = volume
31 mov ebx, nSize // ebx = size
32 shr ebx, 4 // process 16 bytes per iteration = 8 samples
33 jz endS16
34
35 pxor mm0, mm0
36 movd mm0, eax //%%eax,%%mm0
37 movq mm1, mm0 //%%mm0,%%mm1
38 psllq mm0, 16 //$16,%%mm0
39 por mm0, mm1 //%%mm1,%%mm0
40 psllq mm0, 16 //$16,%%mm0
41 por mm0, mm1 //%%mm1,%%mm0
42 psllq mm0, 16 //$16,%%mm0
43 por mm0, mm1 //%%mm1,%%mm0 // mm0 = vol|vol|vol|vol
44
45 mixloopS16:
46 movq mm1, [esi] //(%%esi),%%mm1\n" // mm1 = a|b|c|d
47 movq mm2, mm1 //%%mm1,%%mm2\n" // mm2 = a|b|c|d
48 movq mm4, [esi + 8] //8(%%esi),%%mm4\n" // mm4 = e|f|g|h
49 // pre charger le buffer dst dans mm7
50 movq mm7, [edi] //(%%edi),%%mm7\n" // mm7 = dst[0]"
51 // multiplier par le volume
52 pmullw mm1, mm0 //%%mm0,%%mm1\n" // mm1 = l(a*v)|l(b*v)|l(c*v)|l(d*v)
53 pmulhw mm2, mm0 //%%mm0,%%mm2\n" // mm2 = h(a*v)|h(b*v)|h(c*v)|h(d*v)
54 movq mm5, mm4 //%%mm4,%%mm5\n" // mm5 = e|f|g|h
55 pmullw mm4, mm0 //%%mm0,%%mm4\n" // mm4 = l(e*v)|l(f*v)|l(g*v)|l(h*v)
56 pmulhw mm5, mm0 //%%mm0,%%mm5\n" // mm5 = h(e*v)|h(f*v)|h(g*v)|h(h*v)
57 movq mm3, mm1 //%%mm1,%%mm3\n" // mm3 = l(a*v)|l(b*v)|l(c*v)|l(d*v)
58 punpckhwd mm1, mm2 //%%mm2,%%mm1\n" // mm1 = a*v|b*v
59 movq mm6, mm4 //%%mm4,%%mm6\n" // mm6 = l(e*v)|l(f*v)|l(g*v)|l(h*v)
60 punpcklwd mm3, mm2 //%%mm2,%%mm3\n" // mm3 = c*v|d*v
61 punpckhwd mm4, mm5 //%%mm5,%%mm4\n" // mm4 = e*f|f*v
62 punpcklwd mm6, mm5 //%%mm5,%%mm6\n" // mm6 = g*v|h*v
63 // pre charger le buffer dst dans mm5
64 movq mm5, [edi + 8] //8(%%edi),%%mm5\n" // mm5 = dst[1]
65 // diviser par 128
66 psrad mm1, 7 //$7,%%mm1\n" // mm1 = a*v/128|b*v/128 , 128 = SDL_MIX_MAXVOLUME
67 add esi, 16 //$16,%%esi\n"
68 psrad mm3, 7 //$7,%%mm3\n" // mm3 = c*v/128|d*v/128
69 psrad mm4, 7 //$7,%%mm4\n" // mm4 = e*v/128|f*v/128
70 // mm1 = le sample avec le volume modifie
71 packssdw mm3, mm1 //%%mm1,%%mm3\n" // mm3 = s(a*v|b*v|c*v|d*v)
72 psrad mm6, 7 //$7,%%mm6\n" // mm6= g*v/128|h*v/128
73 paddsw mm3, mm7 //%%mm7,%%mm3\n" // mm3 = adjust_volume(src)+dst
74 // mm4 = le sample avec le volume modifie
75 packssdw mm6, mm4 //%%mm4,%%mm6\n" // mm6 = s(e*v|f*v|g*v|h*v)
76 movq [edi], mm3 //%%mm3,(%%edi)\n"
77 paddsw mm6, mm5 //%%mm5,%%mm6\n" // mm6 = adjust_volume(src)+dst
78 movq [edi + 8], mm6 //%%mm6,8(%%edi)\n"
79 add edi, 16 //$16,%%edi\n"
80 dec ebx //%%ebx\n"
81 jnz mixloopS16
82
83 ends16:
84 emms
85
86 pop ebx
87 pop esi
88 pop edi
89 }
90
91 }
92
93 ////////////////////////////////////////////////
94 // Mixing for 8 bit signed buffers
95 ////////////////////////////////////////////////
96
97 void SDL_MixAudio_MMX_S8_VC(char* dst,char* src,unsigned int nSize,int volume)
98 {
99 _asm
100 {
101 align 16
102
103 push edi
104 push esi
105 push ebx
106
107 mov edi, dst //movl %0,%%edi // edi = dst
108 mov esi, src //%1,%%esi // esi = src
109 mov eax, volume //%3,%%eax // eax = volume
110
111 movd mm0, ebx //%%ebx,%%mm0
112 movq mm1, mm0 //%%mm0,%%mm1
113 psllq mm0, 16 //$16,%%mm0
114 por mm0, mm1 //%%mm1,%%mm0
115 psllq mm0, 16 //$16,%%mm0
116 por mm0, mm1 //%%mm1,%%mm0
117 psllq mm0, 16 //$16,%%mm0
118 por mm0, mm1 //%%mm1,%%mm0
119
120 mov ebx, nSize //%2,%%ebx // ebx = size
121 shr ebx, 3 //$3,%%ebx // process 8 bytes per iteration = 8 samples
122 cmp ebx, 0 //$0,%%ebx
123 je endS8
124
125 mixloopS8:
126 pxor mm2, mm2 //%%mm2,%%mm2 // mm2 = 0
127 movq mm1, [esi] //(%%esi),%%mm1 // mm1 = a|b|c|d|e|f|g|h
128 movq mm3, mm1 //%%mm1,%%mm3 // mm3 = a|b|c|d|e|f|g|h
129 // on va faire le "sign extension" en faisant un cmp avec 0 qui retourne 1 si <0, 0 si >0
130 pcmpgtb mm2, mm1 //%%mm1,%%mm2 // mm2 = 11111111|00000000|00000000....
131 punpckhbw mm1, mm2 //%%mm2,%%mm1 // mm1 = 0|a|0|b|0|c|0|d
132 punpcklbw mm3, mm2 //%%mm2,%%mm3 // mm3 = 0|e|0|f|0|g|0|h
133 movq mm2, [edi] //(%%edi),%%mm2 // mm2 = destination
134 pmullw mm1, mm0 //%%mm0,%%mm1 // mm1 = v*a|v*b|v*c|v*d
135 add esi, 8 //$8,%%esi
136 pmullw mm3, mm0 //%%mm0,%%mm3 // mm3 = v*e|v*f|v*g|v*h
137 psraw mm1, 7 //$7,%%mm1 // mm1 = v*a/128|v*b/128|v*c/128|v*d/128
138 psraw mm3, 7 //$7,%%mm3 // mm3 = v*e/128|v*f/128|v*g/128|v*h/128
139 packsswb mm3, mm1 //%%mm1,%%mm3 // 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
140 paddsb mm3, mm2 //%%mm2,%%mm3 // add to destination buffer
141 movq [edi], mm3 //%%mm3,(%%edi) // store back to ram
142 add edi, 8 //$8,%%edi
143 dec ebx //%%ebx
144 jnz mixloopS8
145
146 endS8:
147 emms
148
149 pop ebx
150 pop esi
151 pop edi
152 }
153 }
154
155 int _SDL_IsMMX_VC()
156 {
157 // This bit flag can get set on calling cpuid
158 // with register eax set to 1
159 const int _MMX_FEATURE_BIT = 0x00800000;
160 DWORD dwFeature = 0;
161 __try {
162 _asm {
163 mov eax,1
164 cpuid
165 mov dwFeature,edx
166 }
167 } __except ( EXCEPTION_EXECUTE_HANDLER) {
168 return 0;
169 }
170 if (dwFeature & _MMX_FEATURE_BIT) {
171 __try {
172 __asm {
173 pxor mm0, mm0
174 emms
175 }
176 } __except (EXCEPTION_EXECUTE_HANDLER) {
177 return(0);
178 }
179 return 1;
180 }
181
182 return 0;
183 }
184
185 static int _notTwice = 2;
186
187 int SDL_IsMMX_VC()
188 {
189 if (_notTwice > 1)
190 {
191 _notTwice = _SDL_IsMMX_VC();
192 /*
193 #ifdef _DEBUG
194 if (_notTwice)
195 MessageBox( NULL, "Using MMX!!!", "Error", MB_OK | MB_ICONINFORMATION );
196 else
197 MessageBox( NULL, "Not sing MMX!!!", "Error", MB_OK | MB_ICONINFORMATION );
198 #endif
199 */
200 }
201 return _notTwice;
202 }
203
204 #endif
205