comparison src/audio/SDL_mixer_MMX_VC.c @ 1721:1cc762cafff8 SDL-1.3

Fixed indenting in MSVC inline assembly
author Sam Lantinga <slouken@libsdl.org>
date Fri, 30 Jun 2006 05:50:35 +0000
parents a1ebb17f9c52
children 5daa04d862f1
comparison
equal deleted inserted replaced
1720:a1ebb17f9c52 1721:1cc762cafff8
38 //////////////////////////////////////////////// 38 ////////////////////////////////////////////////
39 39
40 void 40 void
41 SDL_MixAudio_MMX_S16_VC(char *dst, char *src, unsigned int nSize, int volume) 41 SDL_MixAudio_MMX_S16_VC(char *dst, char *src, unsigned int nSize, int volume)
42 { 42 {
43 /* *INDENT-OFF* */ 43 /* *INDENT-OFF* */
44 __asm { 44 __asm
45 push edi 45 {
46 push esi 46
47 push ebx 47 push edi
48 mov edi, dst // edi = dst 48 push esi
49 mov esi, src // esi = src 49 push ebx
50 mov eax, volume // eax = volume 50
51 mov ebx, nSize // ebx = size 51 mov edi, dst // edi = dst
52 shr ebx, 4 // process 16 bytes per iteration = 8 samples 52 mov esi, src // esi = src
53 jz endS16 53 mov eax, volume // eax = volume
54 pxor mm0, mm0 54 mov ebx, nSize // ebx = size
55 movd mm0, eax //%%eax,%%mm0 55 shr ebx, 4 // process 16 bytes per iteration = 8 samples
56 movq mm1, mm0 //%%mm0,%%mm1 56 jz endS16
57 psllq mm0, 16 //$16,%%mm0 57
58 por mm0, mm1 //%%mm1,%%mm0 58 pxor mm0, mm0
59 psllq mm0, 16 //$16,%%mm0 59 movd mm0, eax //%%eax,%%mm0
60 por mm0, mm1 //%%mm1,%%mm0 60 movq mm1, mm0 //%%mm0,%%mm1
61 psllq mm0, 16 //$16,%%mm0 61 psllq mm0, 16 //$16,%%mm0
62 por mm0, mm1 //%%mm1,%%mm0 // mm0 = vol|vol|vol|vol 62 por mm0, mm1 //%%mm1,%%mm0
63 #ifndef __WATCOMC__ 63 psllq mm0, 16 //$16,%%mm0
64 align 16 64 por mm0, mm1 //%%mm1,%%mm0
65 #endif 65 psllq mm0, 16 //$16,%%mm0
66 mixloopS16: 66 por mm0, mm1 //%%mm1,%%mm0 // mm0 = vol|vol|vol|vol
67 movq mm1,[esi] //(%%esi),%%mm1\n" // mm1 = a|b|c|d 67
68 movq mm2, mm1 //%%mm1,%%mm2\n" // mm2 = a|b|c|d 68 #ifndef __WATCOMC__
69 movq mm4,[esi + 8] //8(%%esi),%%mm4\n" // mm4 = e|f|g|h 69 align 16
70 // pre charger le buffer dst dans mm7 70 #endif
71 movq mm7,[edi] //(%%edi),%%mm7\n" // mm7 = dst[0]" 71 mixloopS16:
72 // multiplier par le volume 72 movq mm1, [esi] //(%%esi),%%mm1\n" // mm1 = a|b|c|d
73 pmullw mm1, mm0 //%%mm0,%%mm1\n" // mm1 = l(a*v)|l(b*v)|l(c*v)|l(d*v) 73 movq mm2, mm1 //%%mm1,%%mm2\n" // mm2 = a|b|c|d
74 pmulhw mm2, mm0 //%%mm0,%%mm2\n" // mm2 = h(a*v)|h(b*v)|h(c*v)|h(d*v) 74 movq mm4, [esi + 8] //8(%%esi),%%mm4\n" // mm4 = e|f|g|h
75 movq mm5, mm4 //%%mm4,%%mm5\n" // mm5 = e|f|g|h 75 // pre charger le buffer dst dans mm7
76 pmullw mm4, mm0 //%%mm0,%%mm4\n" // mm4 = l(e*v)|l(f*v)|l(g*v)|l(h*v) 76 movq mm7, [edi] //(%%edi),%%mm7\n" // mm7 = dst[0]"
77 pmulhw mm5, mm0 //%%mm0,%%mm5\n" // mm5 = h(e*v)|h(f*v)|h(g*v)|h(h*v) 77 // multiplier par le volume
78 movq mm3, mm1 //%%mm1,%%mm3\n" // mm3 = l(a*v)|l(b*v)|l(c*v)|l(d*v) 78 pmullw mm1, mm0 //%%mm0,%%mm1\n" // mm1 = l(a*v)|l(b*v)|l(c*v)|l(d*v)
79 punpckhwd mm1, mm2 //%%mm2,%%mm1\n" // mm1 = a*v|b*v 79 pmulhw mm2, mm0 //%%mm0,%%mm2\n" // mm2 = h(a*v)|h(b*v)|h(c*v)|h(d*v)
80 movq mm6, mm4 //%%mm4,%%mm6\n" // mm6 = l(e*v)|l(f*v)|l(g*v)|l(h*v) 80 movq mm5, mm4 //%%mm4,%%mm5\n" // mm5 = e|f|g|h
81 punpcklwd mm3, mm2 //%%mm2,%%mm3\n" // mm3 = c*v|d*v 81 pmullw mm4, mm0 //%%mm0,%%mm4\n" // mm4 = l(e*v)|l(f*v)|l(g*v)|l(h*v)
82 punpckhwd mm4, mm5 //%%mm5,%%mm4\n" // mm4 = e*f|f*v 82 pmulhw mm5, mm0 //%%mm0,%%mm5\n" // mm5 = h(e*v)|h(f*v)|h(g*v)|h(h*v)
83 punpcklwd mm6, mm5 //%%mm5,%%mm6\n" // mm6 = g*v|h*v 83 movq mm3, mm1 //%%mm1,%%mm3\n" // mm3 = l(a*v)|l(b*v)|l(c*v)|l(d*v)
84 // pre charger le buffer dst dans mm5 84 punpckhwd mm1, mm2 //%%mm2,%%mm1\n" // mm1 = a*v|b*v
85 movq mm5,[edi + 8] //8(%%edi),%%mm5\n" // mm5 = dst[1] 85 movq mm6, mm4 //%%mm4,%%mm6\n" // mm6 = l(e*v)|l(f*v)|l(g*v)|l(h*v)
86 // diviser par 128 86 punpcklwd mm3, mm2 //%%mm2,%%mm3\n" // mm3 = c*v|d*v
87 psrad mm1, 7 //$7,%%mm1\n" // mm1 = a*v/128|b*v/128 , 128 = SDL_MIX_MAXVOLUME 87 punpckhwd mm4, mm5 //%%mm5,%%mm4\n" // mm4 = e*f|f*v
88 add esi, 16 //$16,%%esi\n" 88 punpcklwd mm6, mm5 //%%mm5,%%mm6\n" // mm6 = g*v|h*v
89 psrad mm3, 7 //$7,%%mm3\n" // mm3 = c*v/128|d*v/128 89 // pre charger le buffer dst dans mm5
90 psrad mm4, 7 //$7,%%mm4\n" // mm4 = e*v/128|f*v/128 90 movq mm5, [edi + 8] //8(%%edi),%%mm5\n" // mm5 = dst[1]
91 // mm1 = le sample avec le volume modifie 91 // diviser par 128
92 packssdw mm3, mm1 //%%mm1,%%mm3\n" // mm3 = s(a*v|b*v|c*v|d*v) 92 psrad mm1, 7 //$7,%%mm1\n" // mm1 = a*v/128|b*v/128 , 128 = SDL_MIX_MAXVOLUME
93 psrad mm6, 7 //$7,%%mm6\n" // mm6= g*v/128|h*v/128 93 add esi, 16 //$16,%%esi\n"
94 paddsw mm3, mm7 //%%mm7,%%mm3\n" // mm3 = adjust_volume(src)+dst 94 psrad mm3, 7 //$7,%%mm3\n" // mm3 = c*v/128|d*v/128
95 // mm4 = le sample avec le volume modifie 95 psrad mm4, 7 //$7,%%mm4\n" // mm4 = e*v/128|f*v/128
96 packssdw mm6, mm4 //%%mm4,%%mm6\n" // mm6 = s(e*v|f*v|g*v|h*v) 96 // mm1 = le sample avec le volume modifie
97 movq[edi], mm3 //%%mm3,(%%edi)\n" 97 packssdw mm3, mm1 //%%mm1,%%mm3\n" // mm3 = s(a*v|b*v|c*v|d*v)
98 paddsw mm6, mm5 //%%mm5,%%mm6\n" // mm6 = adjust_volume(src)+dst 98 psrad mm6, 7 //$7,%%mm6\n" // mm6= g*v/128|h*v/128
99 movq[edi + 8], mm6 //%%mm6,8(%%edi)\n" 99 paddsw mm3, mm7 //%%mm7,%%mm3\n" // mm3 = adjust_volume(src)+dst
100 add edi, 16 //$16,%%edi\n" 100 // mm4 = le sample avec le volume modifie
101 dec ebx //%%ebx\n" 101 packssdw mm6, mm4 //%%mm4,%%mm6\n" // mm6 = s(e*v|f*v|g*v|h*v)
102 jnz mixloopS16 102 movq [edi], mm3 //%%mm3,(%%edi)\n"
103 ends16: 103 paddsw mm6, mm5 //%%mm5,%%mm6\n" // mm6 = adjust_volume(src)+dst
104 emms 104 movq [edi + 8], mm6 //%%mm6,8(%%edi)\n"
105 pop ebx 105 add edi, 16 //$16,%%edi\n"
106 pop esi 106 dec ebx //%%ebx\n"
107 pop edi 107 jnz mixloopS16
108
109 ends16:
110 emms
111
112 pop ebx
113 pop esi
114 pop edi
108 } 115 }
109 /* *INDENT-ON* */ 116 /* *INDENT-ON* */
110 } 117 }
111 118
112 //////////////////////////////////////////////// 119 ////////////////////////////////////////////////
113 // Mixing for 8 bit signed buffers 120 // Mixing for 8 bit signed buffers
114 //////////////////////////////////////////////// 121 ////////////////////////////////////////////////
115 122
116 void 123 void
117 SDL_MixAudio_MMX_S8_VC(char *dst, char *src, unsigned int nSize, int volume) 124 SDL_MixAudio_MMX_S8_VC(char *dst, char *src, unsigned int nSize, int volume)
118 { 125 {
119 /* *INDENT-OFF* */ 126 /* *INDENT-OFF* */
120 _asm { 127 _asm
128 {
121 129
122 push edi 130 push edi
123 push esi 131 push esi
124 push ebx 132 push ebx
125 mov edi, dst //%0,%%edi // edi = dst 133
126 mov esi, src //%1,%%esi // esi = src 134 mov edi, dst //movl %0,%%edi // edi = dst
127 mov eax, volume //%3,%%eax // eax = volume 135 mov esi, src //%1,%%esi // esi = src
128 movd mm0, eax //%%eax,%%mm0 136 mov eax, volume //%3,%%eax // eax = volume
129 movq mm1, mm0 //%%mm0,%%mm1 137
130 psllq mm0, 16 //$16,%%mm0 138 movd mm0, eax //%%eax,%%mm0
131 por mm0, mm1 //%%mm1,%%mm0 139 movq mm1, mm0 //%%mm0,%%mm1
132 psllq mm0, 16 //$16,%%mm0 140 psllq mm0, 16 //$16,%%mm0
133 por mm0, mm1 //%%mm1,%%mm0 141 por mm0, mm1 //%%mm1,%%mm0
134 psllq mm0, 16 //$16,%%mm0 142 psllq mm0, 16 //$16,%%mm0
135 por mm0, mm1 //%%mm1,%%mm0 143 por mm0, mm1 //%%mm1,%%mm0
136 mov ebx, nSize //%2,%%ebx // ebx = size 144 psllq mm0, 16 //$16,%%mm0
137 shr ebx, 3 //$3,%%ebx // process 8 bytes per iteration = 8 samples 145 por mm0, mm1 //%%mm1,%%mm0
138 cmp ebx, 0 //$0,%%ebx 146
139 je endS8 147 mov ebx, nSize //%2,%%ebx // ebx = size
140 #ifndef __WATCOMC__ 148 shr ebx, 3 //$3,%%ebx // process 8 bytes per iteration = 8 samples
141 align 16 149 cmp ebx, 0 //$0,%%ebx
142 #endif 150 je endS8
143 mixloopS8: 151
144 pxor mm2, mm2 //%%mm2,%%mm2 // mm2 = 0 152 #ifndef __WATCOMC__
145 movq mm1,[esi] //(%%esi),%%mm1 // mm1 = a|b|c|d|e|f|g|h 153 align 16
146 movq mm3, mm1 //%%mm1,%%mm3 // mm3 = a|b|c|d|e|f|g|h 154 #endif
147 // on va faire le "sign extension" en faisant un cmp avec 0 qui retourne 1 si <0, 0 si >0 155 mixloopS8:
148 pcmpgtb mm2, mm1 //%%mm1,%%mm2 // mm2 = 11111111|00000000|00000000.... 156 pxor mm2, mm2 //%%mm2,%%mm2 // mm2 = 0
149 punpckhbw mm1, mm2 //%%mm2,%%mm1 // mm1 = 0|a|0|b|0|c|0|d 157 movq mm1, [esi] //(%%esi),%%mm1 // mm1 = a|b|c|d|e|f|g|h
150 punpcklbw mm3, mm2 //%%mm2,%%mm3 // mm3 = 0|e|0|f|0|g|0|h 158 movq mm3, mm1 //%%mm1,%%mm3 // mm3 = a|b|c|d|e|f|g|h
151 movq mm2,[edi] //(%%edi),%%mm2 // mm2 = destination 159 // on va faire le "sign extension" en faisant un cmp avec 0 qui retourne 1 si <0, 0 si >0
152 pmullw mm1, mm0 //%%mm0,%%mm1 // mm1 = v*a|v*b|v*c|v*d 160 pcmpgtb mm2, mm1 //%%mm1,%%mm2 // mm2 = 11111111|00000000|00000000....
153 add esi, 8 //$8,%%esi 161 punpckhbw mm1, mm2 //%%mm2,%%mm1 // mm1 = 0|a|0|b|0|c|0|d
154 pmullw mm3, mm0 //%%mm0,%%mm3 // mm3 = v*e|v*f|v*g|v*h 162 punpcklbw mm3, mm2 //%%mm2,%%mm3 // mm3 = 0|e|0|f|0|g|0|h
155 psraw mm1, 7 //$7,%%mm1 // mm1 = v*a/128|v*b/128|v*c/128|v*d/128 163 movq mm2, [edi] //(%%edi),%%mm2 // mm2 = destination
156 psraw mm3, 7 //$7,%%mm3 // mm3 = v*e/128|v*f/128|v*g/128|v*h/128 164 pmullw mm1, mm0 //%%mm0,%%mm1 // mm1 = v*a|v*b|v*c|v*d
157 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 165 add esi, 8 //$8,%%esi
158 paddsb mm3, mm2 //%%mm2,%%mm3 // add to destination buffer 166 pmullw mm3, mm0 //%%mm0,%%mm3 // mm3 = v*e|v*f|v*g|v*h
159 movq[edi], mm3 //%%mm3,(%%edi) // store back to ram 167 psraw mm1, 7 //$7,%%mm1 // mm1 = v*a/128|v*b/128|v*c/128|v*d/128
160 add edi, 8 //$8,%%edi 168 psraw mm3, 7 //$7,%%mm3 // mm3 = v*e/128|v*f/128|v*g/128|v*h/128
161 dec ebx //%%ebx 169 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
162 jnz mixloopS8 170 paddsb mm3, mm2 //%%mm2,%%mm3 // add to destination buffer
163 endS8: 171 movq [edi], mm3 //%%mm3,(%%edi) // store back to ram
164 emms 172 add edi, 8 //$8,%%edi
165 pop ebx 173 dec ebx //%%ebx
166 pop esi 174 jnz mixloopS8
167 pop edi 175
176 endS8:
177 emms
178
179 pop ebx
180 pop esi
181 pop edi
168 } 182 }
169 /* *INDENT-ON* */ 183 /* *INDENT-ON* */
170 } 184 }
171 185
172 #endif /* SDL_ASSEMBLY_ROUTINES */ 186 #endif /* SDL_ASSEMBLY_ROUTINES */
173
174 /* vi: set ts=4 sw=4 expandtab: */