src/audio/SDL_mixer_MMX_VC.c
author Ryan C. Gordon <icculus@icculus.org>
Thu, 31 Aug 2006 21:00:10 +0000
changeset 1994 6abc7e6f9817
parent 1895 c121d94672cb
child 2280 1863fa2050e8
permissions -rw-r--r--
Added int32 adn float32 support to SDL_LoadWAV_RW().
slouken@1402
     1
/*
slouken@1402
     2
    SDL - Simple DirectMedia Layer
slouken@1402
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@1402
     4
slouken@1402
     5
    This library is free software; you can redistribute it and/or
slouken@1402
     6
    modify it under the terms of the GNU Lesser General Public
slouken@1402
     7
    License as published by the Free Software Foundation; either
slouken@1402
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@1402
     9
slouken@1402
    10
    This library is distributed in the hope that it will be useful,
slouken@1402
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@1402
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1402
    13
    Lesser General Public License for more details.
slouken@1402
    14
slouken@1402
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1402
    16
    License along with this library; if not, write to the Free Software
slouken@1402
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@1402
    18
slouken@1402
    19
    Sam Lantinga
slouken@1402
    20
    slouken@libsdl.org
slouken@1402
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@1330
    23
slouken@1330
    24
#include "SDL_mixer_MMX_VC.h"
slouken@1330
    25
slouken@1442
    26
#if ((defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)) && defined(SDL_ASSEMBLY_ROUTINES)
slouken@574
    27
// MMX assembler version of SDL_MixAudio for signed little endian 16 bit samples and signed 8 bit samples
slouken@574
    28
// Copyright 2002 Stephane Marchesin (stephane.marchesin@wanadoo.fr)
slouken@574
    29
// Converted to Intel ASM notation by Cth
slouken@574
    30
// This code is licensed under the LGPL (see COPYING for details)
slouken@574
    31
// 
slouken@574
    32
// Assumes buffer size in bytes is a multiple of 16
slouken@574
    33
// Assumes SDL_MIX_MAXVOLUME = 128
slouken@574
    34
slouken@574
    35
slouken@574
    36
////////////////////////////////////////////////
slouken@574
    37
// Mixing for 16 bit signed buffers
slouken@574
    38
////////////////////////////////////////////////
slouken@574
    39
slouken@1895
    40
void
slouken@1895
    41
SDL_MixAudio_MMX_S16_VC(char *dst, char *src, unsigned int nSize, int volume)
slouken@574
    42
{
slouken@1895
    43
    /* *INDENT-OFF* */
slouken@574
    44
	__asm
slouken@574
    45
	{
slouken@574
    46
slouken@574
    47
		push	edi
slouken@574
    48
		push	esi
slouken@574
    49
		push	ebx
slouken@574
    50
		
slouken@574
    51
		mov		edi, dst		// edi = dst
slouken@574
    52
		mov		esi, src		// esi = src
slouken@574
    53
		mov		eax, volume		// eax = volume
slouken@574
    54
		mov		ebx, nSize		// ebx = size
slouken@574
    55
		shr		ebx, 4			// process 16 bytes per iteration = 8 samples
slouken@574
    56
		jz		endS16
slouken@574
    57
		
slouken@574
    58
		pxor	mm0, mm0
slouken@574
    59
		movd	mm0, eax		//%%eax,%%mm0
slouken@574
    60
		movq	mm1, mm0		//%%mm0,%%mm1
slouken@574
    61
		psllq	mm0, 16			//$16,%%mm0
slouken@574
    62
		por		mm0, mm1		//%%mm1,%%mm0
slouken@574
    63
		psllq	mm0, 16			//$16,%%mm0
slouken@574
    64
		por		mm0, mm1		//%%mm1,%%mm0
slouken@574
    65
		psllq	mm0, 16			//$16,%%mm0
slouken@574
    66
		por		mm0, mm1		//%%mm1,%%mm0			// mm0 = vol|vol|vol|vol
slouken@574
    67
icculus@1190
    68
		#ifndef __WATCOMC__
icculus@1049
    69
		align	16
icculus@1190
    70
		#endif
slouken@574
    71
mixloopS16:
slouken@574
    72
		movq	mm1, [esi]		//(%%esi),%%mm1\n" // mm1 = a|b|c|d
slouken@574
    73
		movq	mm2, mm1		//%%mm1,%%mm2\n" // mm2 = a|b|c|d
slouken@574
    74
		movq	mm4, [esi + 8]	//8(%%esi),%%mm4\n" // mm4 = e|f|g|h
slouken@574
    75
		// pre charger le buffer dst dans mm7
slouken@574
    76
		movq	mm7, [edi]		//(%%edi),%%mm7\n" // mm7 = dst[0]"
slouken@574
    77
		// multiplier par le volume
slouken@574
    78
		pmullw	mm1, mm0		//%%mm0,%%mm1\n" // mm1 = l(a*v)|l(b*v)|l(c*v)|l(d*v)
slouken@574
    79
		pmulhw	mm2, mm0		//%%mm0,%%mm2\n" // mm2 = h(a*v)|h(b*v)|h(c*v)|h(d*v)
slouken@574
    80
		movq	mm5, mm4		//%%mm4,%%mm5\n" // mm5 = e|f|g|h
slouken@574
    81
		pmullw	mm4, mm0		//%%mm0,%%mm4\n" // mm4 = l(e*v)|l(f*v)|l(g*v)|l(h*v)
slouken@574
    82
		pmulhw	mm5, mm0		//%%mm0,%%mm5\n" // mm5 = h(e*v)|h(f*v)|h(g*v)|h(h*v)
slouken@574
    83
		movq	mm3, mm1		//%%mm1,%%mm3\n" // mm3 = l(a*v)|l(b*v)|l(c*v)|l(d*v)
slouken@574
    84
		punpckhwd	mm1, mm2	//%%mm2,%%mm1\n" // mm1 = a*v|b*v
slouken@574
    85
		movq		mm6, mm4	//%%mm4,%%mm6\n" // mm6 = l(e*v)|l(f*v)|l(g*v)|l(h*v)
slouken@574
    86
		punpcklwd	mm3, mm2	//%%mm2,%%mm3\n" // mm3 = c*v|d*v
slouken@574
    87
		punpckhwd	mm4, mm5	//%%mm5,%%mm4\n" // mm4 = e*f|f*v
slouken@574
    88
		punpcklwd	mm6, mm5	//%%mm5,%%mm6\n" // mm6 = g*v|h*v
slouken@574
    89
		// pre charger le buffer dst dans mm5
slouken@574
    90
		movq	mm5, [edi + 8]	//8(%%edi),%%mm5\n" // mm5 = dst[1]
slouken@574
    91
		// diviser par 128
slouken@574
    92
		psrad	mm1, 7			//$7,%%mm1\n" // mm1 = a*v/128|b*v/128 , 128 = SDL_MIX_MAXVOLUME
slouken@574
    93
		add		esi, 16			//$16,%%esi\n"
slouken@574
    94
		psrad	mm3, 7			//$7,%%mm3\n" // mm3 = c*v/128|d*v/128
slouken@574
    95
		psrad	mm4, 7			//$7,%%mm4\n" // mm4 = e*v/128|f*v/128
slouken@574
    96
		// mm1 = le sample avec le volume modifie
slouken@574
    97
		packssdw	mm3, mm1	//%%mm1,%%mm3\n" // mm3 = s(a*v|b*v|c*v|d*v)
slouken@574
    98
		psrad	mm6, 7			//$7,%%mm6\n" // mm6= g*v/128|h*v/128
slouken@574
    99
		paddsw	mm3, mm7		//%%mm7,%%mm3\n" // mm3 = adjust_volume(src)+dst
slouken@574
   100
		// mm4 = le sample avec le volume modifie
slouken@574
   101
		packssdw	mm6, mm4	//%%mm4,%%mm6\n" // mm6 = s(e*v|f*v|g*v|h*v)
slouken@574
   102
		movq	[edi], mm3		//%%mm3,(%%edi)\n"
slouken@574
   103
		paddsw	mm6, mm5		//%%mm5,%%mm6\n" // mm6 = adjust_volume(src)+dst
slouken@574
   104
		movq	[edi + 8], mm6	//%%mm6,8(%%edi)\n"
slouken@574
   105
		add		edi, 16			//$16,%%edi\n"
slouken@574
   106
		dec		ebx				//%%ebx\n"
slouken@574
   107
		jnz mixloopS16
slouken@574
   108
slouken@574
   109
ends16:
slouken@574
   110
		emms
slouken@574
   111
		
slouken@574
   112
		pop		ebx
slouken@574
   113
		pop		esi
slouken@574
   114
		pop		edi
slouken@574
   115
	}
slouken@1895
   116
    /* *INDENT-ON* */
slouken@574
   117
}
slouken@574
   118
slouken@574
   119
////////////////////////////////////////////////
slouken@574
   120
// Mixing for 8 bit signed buffers
slouken@574
   121
////////////////////////////////////////////////
slouken@574
   122
slouken@1895
   123
void
slouken@1895
   124
SDL_MixAudio_MMX_S8_VC(char *dst, char *src, unsigned int nSize, int volume)
slouken@574
   125
{
slouken@1895
   126
    /* *INDENT-OFF* */
slouken@574
   127
	_asm
slouken@574
   128
	{
slouken@574
   129
slouken@574
   130
		push	edi
slouken@574
   131
		push	esi
slouken@574
   132
		push	ebx
slouken@574
   133
		
slouken@574
   134
		mov		edi, dst	//movl	%0,%%edi	// edi = dst
slouken@574
   135
		mov		esi, src	//%1,%%esi	// esi = src
slouken@574
   136
		mov		eax, volume	//%3,%%eax	// eax = volume
slouken@574
   137
icculus@1149
   138
		movd	mm0, eax	//%%eax,%%mm0
slouken@574
   139
		movq	mm1, mm0	//%%mm0,%%mm1
slouken@574
   140
		psllq	mm0, 16		//$16,%%mm0
slouken@574
   141
		por		mm0, mm1	//%%mm1,%%mm0
slouken@574
   142
		psllq	mm0, 16		//$16,%%mm0
slouken@574
   143
		por		mm0, mm1	//%%mm1,%%mm0
slouken@574
   144
		psllq	mm0, 16		//$16,%%mm0
slouken@574
   145
		por		mm0, mm1	//%%mm1,%%mm0
slouken@574
   146
		
slouken@574
   147
		mov		ebx, nSize	//%2,%%ebx	// ebx = size
slouken@574
   148
		shr		ebx, 3		//$3,%%ebx	// process 8 bytes per iteration = 8 samples
slouken@574
   149
		cmp		ebx, 0		//$0,%%ebx
slouken@574
   150
		je		endS8
slouken@574
   151
icculus@1190
   152
		#ifndef __WATCOMC__
icculus@1049
   153
		align 16
icculus@1190
   154
		#endif
slouken@574
   155
mixloopS8:
slouken@574
   156
		pxor	mm2, mm2	//%%mm2,%%mm2		// mm2 = 0
slouken@574
   157
		movq	mm1, [esi]	//(%%esi),%%mm1	// mm1 = a|b|c|d|e|f|g|h
slouken@574
   158
		movq	mm3, mm1	//%%mm1,%%mm3 	// mm3 = a|b|c|d|e|f|g|h
slouken@574
   159
		// on va faire le "sign extension" en faisant un cmp avec 0 qui retourne 1 si <0, 0 si >0
slouken@574
   160
		pcmpgtb		mm2, mm1	//%%mm1,%%mm2	// mm2 = 11111111|00000000|00000000....
slouken@574
   161
		punpckhbw	mm1, mm2	//%%mm2,%%mm1	// mm1 = 0|a|0|b|0|c|0|d
slouken@574
   162
		punpcklbw	mm3, mm2	//%%mm2,%%mm3	// mm3 = 0|e|0|f|0|g|0|h
slouken@574
   163
		movq	mm2, [edi]	//(%%edi),%%mm2	// mm2 = destination
slouken@574
   164
		pmullw	mm1, mm0	//%%mm0,%%mm1	// mm1 = v*a|v*b|v*c|v*d
slouken@574
   165
		add		esi, 8		//$8,%%esi
slouken@574
   166
		pmullw	mm3, mm0	//%%mm0,%%mm3	// mm3 = v*e|v*f|v*g|v*h
slouken@574
   167
		psraw	mm1, 7		//$7,%%mm1		// mm1 = v*a/128|v*b/128|v*c/128|v*d/128 
slouken@574
   168
		psraw	mm3, 7		//$7,%%mm3		// mm3 = v*e/128|v*f/128|v*g/128|v*h/128
slouken@574
   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
slouken@574
   170
		paddsb	mm3, mm2	//%%mm2,%%mm3	// add to destination buffer
slouken@574
   171
		movq	[edi], mm3	//%%mm3,(%%edi)	// store back to ram
slouken@574
   172
		add		edi, 8		//$8,%%edi
slouken@574
   173
		dec		ebx			//%%ebx
slouken@574
   174
		jnz		mixloopS8
slouken@574
   175
		
slouken@574
   176
endS8:
slouken@574
   177
		emms
slouken@574
   178
		
slouken@574
   179
		pop		ebx
slouken@574
   180
		pop		esi
slouken@574
   181
		pop		edi
slouken@574
   182
	}
slouken@1895
   183
    /* *INDENT-ON* */
slouken@574
   184
}
slouken@574
   185
slouken@1402
   186
#endif /* SDL_ASSEMBLY_ROUTINES */
slouken@1895
   187
slouken@1895
   188
/* vi: set ts=4 sw=4 expandtab: */