src/audio/SDL_mixer_MMX.c
changeset 1612 97d0966f4bf7
parent 1411 efb34e597d21
child 1662 782fd950bd46
child 1895 c121d94672cb
child 4159 a1b03ba2fcd0
equal deleted inserted replaced
1611:ec3466b08f17 1612:97d0966f4bf7
    38 #if defined(__GNUC__) && defined(__i386__) && defined(SDL_ASSEMBLY_ROUTINES)
    38 #if defined(__GNUC__) && defined(__i386__) && defined(SDL_ASSEMBLY_ROUTINES)
    39 void SDL_MixAudio_MMX_S16(char* dst,char* src,unsigned int size,int volume)
    39 void SDL_MixAudio_MMX_S16(char* dst,char* src,unsigned int size,int volume)
    40 {
    40 {
    41     __asm__ __volatile__ (
    41     __asm__ __volatile__ (
    42 
    42 
    43 "	movl %3,%%eax\n"	// eax = volume
    43 "	movl %3,%%eax\n"	/* eax = volume */
    44 
    44 
    45 "	movl %2,%%edx\n"	// edx = size
    45 "	movl %2,%%edx\n"	/* edx = size */
    46 
    46 
    47 "	shrl $4,%%edx\n"	// process 16 bytes per iteration = 8 samples
    47 "	shrl $4,%%edx\n"	/* process 16 bytes per iteration = 8 samples */
    48 
    48 
    49 "	jz .endS16\n"
    49 "	jz .endS16\n"
    50 
    50 
    51 "	pxor %%mm0,%%mm0\n"
    51 "	pxor %%mm0,%%mm0\n"
    52 
    52 
    55 "	psllq $16,%%mm0\n"
    55 "	psllq $16,%%mm0\n"
    56 "	por %%mm1,%%mm0\n"
    56 "	por %%mm1,%%mm0\n"
    57 "	psllq $16,%%mm0\n"
    57 "	psllq $16,%%mm0\n"
    58 "	por %%mm1,%%mm0\n"
    58 "	por %%mm1,%%mm0\n"
    59 "	psllq $16,%%mm0\n"
    59 "	psllq $16,%%mm0\n"
    60 "	por %%mm1,%%mm0\n"		// mm0 = vol|vol|vol|vol
    60 "	por %%mm1,%%mm0\n"		/* mm0 = vol|vol|vol|vol */
    61 
    61 
    62 ".align 8\n"
    62 ".align 8\n"
    63 "	.mixloopS16:\n"
    63 "	.mixloopS16:\n"
    64 
    64 
    65 "	movq (%1),%%mm1\n" // mm1 = a|b|c|d
    65 "	movq (%1),%%mm1\n" /* mm1 = a|b|c|d */
    66 
    66 
    67 "	movq %%mm1,%%mm2\n" // mm2 = a|b|c|d
    67 "	movq %%mm1,%%mm2\n" /* mm2 = a|b|c|d */
    68 
    68 
    69 "	movq 8(%1),%%mm4\n" // mm4 = e|f|g|h
    69 "	movq 8(%1),%%mm4\n" /* mm4 = e|f|g|h */
    70 
    70 
    71 	// pré charger le buffer dst dans mm7
    71 	/* pré charger le buffer dst dans mm7 */
    72 "	movq (%0),%%mm7\n" // mm7 = dst[0]"
    72 "	movq (%0),%%mm7\n" /* mm7 = dst[0] */
    73 
    73 
    74 	// multiplier par le volume
    74 	/* multiplier par le volume */
    75 "	pmullw %%mm0,%%mm1\n" // mm1 = l(a*v)|l(b*v)|l(c*v)|l(d*v)
    75 "	pmullw %%mm0,%%mm1\n" /* mm1 = l(a*v)|l(b*v)|l(c*v)|l(d*v) */
    76 
    76 
    77 "	pmulhw %%mm0,%%mm2\n" // mm2 = h(a*v)|h(b*v)|h(c*v)|h(d*v)
    77 "	pmulhw %%mm0,%%mm2\n" /* mm2 = h(a*v)|h(b*v)|h(c*v)|h(d*v) */
    78 "	movq %%mm4,%%mm5\n" // mm5 = e|f|g|h
    78 "	movq %%mm4,%%mm5\n" /* mm5 = e|f|g|h */
    79 
    79 
    80 "	pmullw %%mm0,%%mm4\n" // mm4 = l(e*v)|l(f*v)|l(g*v)|l(h*v)
    80 "	pmullw %%mm0,%%mm4\n" /* mm4 = l(e*v)|l(f*v)|l(g*v)|l(h*v) */
    81 
    81 
    82 "	pmulhw %%mm0,%%mm5\n" // mm5 = h(e*v)|h(f*v)|h(g*v)|h(h*v)
    82 "	pmulhw %%mm0,%%mm5\n" /* mm5 = h(e*v)|h(f*v)|h(g*v)|h(h*v) */
    83 "	movq %%mm1,%%mm3\n" // mm3 = l(a*v)|l(b*v)|l(c*v)|l(d*v)
    83 "	movq %%mm1,%%mm3\n" /* mm3 = l(a*v)|l(b*v)|l(c*v)|l(d*v) */
    84 
    84 
    85 "	punpckhwd %%mm2,%%mm1\n" // mm1 = a*v|b*v
    85 "	punpckhwd %%mm2,%%mm1\n" /* mm1 = a*v|b*v */
    86 
    86 
    87 "	movq %%mm4,%%mm6\n" // mm6 = l(e*v)|l(f*v)|l(g*v)|l(h*v)
    87 "	movq %%mm4,%%mm6\n" /* mm6 = l(e*v)|l(f*v)|l(g*v)|l(h*v) */
    88 "	punpcklwd %%mm2,%%mm3\n" // mm3 = c*v|d*v
    88 "	punpcklwd %%mm2,%%mm3\n" /* mm3 = c*v|d*v */
    89 
    89 
    90 "	punpckhwd %%mm5,%%mm4\n" // mm4 = e*f|f*v
    90 "	punpckhwd %%mm5,%%mm4\n" /* mm4 = e*f|f*v */
    91 
    91 
    92 "	punpcklwd %%mm5,%%mm6\n" // mm6 = g*v|h*v
    92 "	punpcklwd %%mm5,%%mm6\n" /* mm6 = g*v|h*v */
    93 
    93 
    94 	// pré charger le buffer dst dans mm5
    94 	/* pré charger le buffer dst dans mm5 */
    95 "	movq 8(%0),%%mm5\n" // mm5 = dst[1]
    95 "	movq 8(%0),%%mm5\n" /* mm5 = dst[1] */
    96 
    96 
    97 	// diviser par 128
    97 	/* diviser par 128 */
    98 "	psrad $7,%%mm1\n" // mm1 = a*v/128|b*v/128 , 128 = SDL_MIX_MAXVOLUME
    98 "	psrad $7,%%mm1\n" /* mm1 = a*v/128|b*v/128 , 128 = SDL_MIX_MAXVOLUME */
    99 "	add $16,%1\n"
    99 "	add $16,%1\n"
   100 
   100 
   101 "	psrad $7,%%mm3\n" // mm3 = c*v/128|d*v/128
   101 "	psrad $7,%%mm3\n" /* mm3 = c*v/128|d*v/128 */
   102 
   102 
   103 "	psrad $7,%%mm4\n" // mm4 = e*v/128|f*v/128
   103 "	psrad $7,%%mm4\n" /* mm4 = e*v/128|f*v/128 */
   104 
   104 
   105 	// mm1 = le sample avec le volume modifié
   105 	/* mm1 = le sample avec le volume modifié */
   106 "	packssdw %%mm1,%%mm3\n" // mm3 = s(a*v|b*v|c*v|d*v)
   106 "	packssdw %%mm1,%%mm3\n" /* mm3 = s(a*v|b*v|c*v|d*v) */
   107 
   107 
   108 "	psrad $7,%%mm6\n" // mm6= g*v/128|h*v/128
   108 "	psrad $7,%%mm6\n" /* mm6= g*v/128|h*v/128 */
   109 "	paddsw %%mm7,%%mm3\n" // mm3 = adjust_volume(src)+dst
   109 "	paddsw %%mm7,%%mm3\n" /* mm3 = adjust_volume(src)+dst */
   110 
   110 
   111 	// mm4 = le sample avec le volume modifié
   111 	/* mm4 = le sample avec le volume modifié */
   112 "	packssdw %%mm4,%%mm6\n" // mm6 = s(e*v|f*v|g*v|h*v)
   112 "	packssdw %%mm4,%%mm6\n" /* mm6 = s(e*v|f*v|g*v|h*v) */
   113 "	movq %%mm3,(%0)\n"
   113 "	movq %%mm3,(%0)\n"
   114 
   114 
   115 "	paddsw %%mm5,%%mm6\n" // mm6 = adjust_volume(src)+dst
   115 "	paddsw %%mm5,%%mm6\n" /* mm6 = adjust_volume(src)+dst */
   116 
   116 
   117 "	movq %%mm6,8(%0)\n"
   117 "	movq %%mm6,8(%0)\n"
   118 
   118 
   119 "	add $16,%0\n"
   119 "	add $16,%0\n"
   120 
   120 
   132 	 );
   132 	 );
   133 }
   133 }
   134 
   134 
   135 
   135 
   136 
   136 
   137 ////////////////////////////////////////////////
   137 /*////////////////////////////////////////////// */
   138 // Mixing for 8 bit signed buffers
   138 /* Mixing for 8 bit signed buffers */
   139 ////////////////////////////////////////////////
   139 /*////////////////////////////////////////////// */
   140 
   140 
   141 void SDL_MixAudio_MMX_S8(char* dst,char* src,unsigned int size,int volume)
   141 void SDL_MixAudio_MMX_S8(char* dst,char* src,unsigned int size,int volume)
   142 {
   142 {
   143     __asm__ __volatile__ (
   143     __asm__ __volatile__ (
   144 
   144 
   145 "	movl %3,%%eax\n"	// eax = volume
   145 "	movl %3,%%eax\n"	/* eax = volume */
   146 
   146 
   147 "	movd %%eax,%%mm0\n"
   147 "	movd %%eax,%%mm0\n"
   148 "	movq %%mm0,%%mm1\n"
   148 "	movq %%mm0,%%mm1\n"
   149 "	psllq $16,%%mm0\n"
   149 "	psllq $16,%%mm0\n"
   150 "	por %%mm1,%%mm0\n"
   150 "	por %%mm1,%%mm0\n"
   151 "	psllq $16,%%mm0\n"
   151 "	psllq $16,%%mm0\n"
   152 "	por %%mm1,%%mm0\n"
   152 "	por %%mm1,%%mm0\n"
   153 "	psllq $16,%%mm0\n"
   153 "	psllq $16,%%mm0\n"
   154 "	por %%mm1,%%mm0\n"
   154 "	por %%mm1,%%mm0\n"
   155 
   155 
   156 "	movl %2,%%edx\n"	// edx = size
   156 "	movl %2,%%edx\n"	/* edx = size */
   157 "	shr $3,%%edx\n"	// process 8 bytes per iteration = 8 samples
   157 "	shr $3,%%edx\n"	/* process 8 bytes per iteration = 8 samples */
   158 
   158 
   159 "	cmp $0,%%edx\n"
   159 "	cmp $0,%%edx\n"
   160 "	je .endS8\n"
   160 "	je .endS8\n"
   161 
   161 
   162 ".align 8\n"
   162 ".align 8\n"
   163 "	.mixloopS8:\n"
   163 "	.mixloopS8:\n"
   164 
   164 
   165 "	pxor %%mm2,%%mm2\n"		// mm2 = 0
   165 "	pxor %%mm2,%%mm2\n"		/* mm2 = 0 */
   166 "	movq (%1),%%mm1\n"	// mm1 = a|b|c|d|e|f|g|h
   166 "	movq (%1),%%mm1\n"	/* mm1 = a|b|c|d|e|f|g|h */
   167 
   167 
   168 "	movq %%mm1,%%mm3\n" 	// mm3 = a|b|c|d|e|f|g|h
   168 "	movq %%mm1,%%mm3\n" 	/* mm3 = a|b|c|d|e|f|g|h */
   169 
   169 
   170 	// on va faire le "sign extension" en faisant un cmp avec 0 qui retourne 1 si <0, 0 si >0
   170 	/* on va faire le "sign extension" en faisant un cmp avec 0 qui retourne 1 si <0, 0 si >0 */
   171 "	pcmpgtb %%mm1,%%mm2\n"	// mm2 = 11111111|00000000|00000000....
   171 "	pcmpgtb %%mm1,%%mm2\n"	/* mm2 = 11111111|00000000|00000000.... */
   172 
   172 
   173 "	punpckhbw %%mm2,%%mm1\n"	// mm1 = 0|a|0|b|0|c|0|d
   173 "	punpckhbw %%mm2,%%mm1\n"	/* mm1 = 0|a|0|b|0|c|0|d */
   174 
   174 
   175 "	punpcklbw %%mm2,%%mm3\n"	// mm3 = 0|e|0|f|0|g|0|h
   175 "	punpcklbw %%mm2,%%mm3\n"	/* mm3 = 0|e|0|f|0|g|0|h */
   176 "	movq (%0),%%mm2\n"	// mm2 = destination
   176 "	movq (%0),%%mm2\n"	/* mm2 = destination */
   177 
   177 
   178 "	pmullw %%mm0,%%mm1\n"	// mm1 = v*a|v*b|v*c|v*d
   178 "	pmullw %%mm0,%%mm1\n"	/* mm1 = v*a|v*b|v*c|v*d */
   179 "	add $8,%1\n"
   179 "	add $8,%1\n"
   180 
   180 
   181 "	pmullw %%mm0,%%mm3\n"	// mm3 = v*e|v*f|v*g|v*h
   181 "	pmullw %%mm0,%%mm3\n"	/* mm3 = v*e|v*f|v*g|v*h */
   182 "	psraw $7,%%mm1\n"		// mm1 = v*a/128|v*b/128|v*c/128|v*d/128 
   182 "	psraw $7,%%mm1\n"		/* mm1 = v*a/128|v*b/128|v*c/128|v*d/128  */
   183 
   183 
   184 "	psraw $7,%%mm3\n"		// mm3 = v*e/128|v*f/128|v*g/128|v*h/128
   184 "	psraw $7,%%mm3\n"		/* mm3 = v*e/128|v*f/128|v*g/128|v*h/128 */
   185 
   185 
   186 "	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
   186 "	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 */
   187 
   187 
   188 "	paddsb %%mm2,%%mm3\n"	// add to destination buffer
   188 "	paddsb %%mm2,%%mm3\n"	/* add to destination buffer */
   189 
   189 
   190 "	movq %%mm3,(%0)\n"	// store back to ram
   190 "	movq %%mm3,(%0)\n"	/* store back to ram */
   191 "	add $8,%0\n"
   191 "	add $8,%0\n"
   192 
   192 
   193 "	dec %%edx\n"
   193 "	dec %%edx\n"
   194 
   194 
   195 "	jnz .mixloopS8\n"
   195 "	jnz .mixloopS8\n"