src/audio/SDL_mixer_MMX_VC.c
author Ozkan Sezer <sezeroz@gmail.com>
Sat, 24 Mar 2018 22:41:17 +0300
branchSDL-1.2
changeset 11972 0b5ac2b90ab1
parent 6137 4720145f848b
permissions -rw-r--r--
backfort fix for bug #3739: handle %lu, %li and %ld in SDL_SetError.
slouken@1402
     1
/*
slouken@1402
     2
    SDL - Simple DirectMedia Layer
slouken@6137
     3
    Copyright (C) 1997-2012 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
icculus@4322
    26
#if defined(SDL_BUGGY_MMX_MIXERS) /* buggy, so we're disabling them. --ryan. */
slouken@1442
    27
#if ((defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)) && defined(SDL_ASSEMBLY_ROUTINES)
slouken@574
    28
// MMX assembler version of SDL_MixAudio for signed little endian 16 bit samples and signed 8 bit samples
slouken@574
    29
// Copyright 2002 Stephane Marchesin (stephane.marchesin@wanadoo.fr)
slouken@574
    30
// Converted to Intel ASM notation by Cth
slouken@574
    31
// This code is licensed under the LGPL (see COPYING for details)
slouken@574
    32
// 
slouken@574
    33
// Assumes buffer size in bytes is a multiple of 16
slouken@574
    34
// Assumes SDL_MIX_MAXVOLUME = 128
slouken@574
    35
slouken@574
    36
slouken@574
    37
////////////////////////////////////////////////
slouken@574
    38
// Mixing for 16 bit signed buffers
slouken@574
    39
////////////////////////////////////////////////
slouken@574
    40
slouken@574
    41
void SDL_MixAudio_MMX_S16_VC(char* dst,char* src,unsigned int nSize,int volume)
slouken@574
    42
{
slouken@574
    43
	__asm
slouken@574
    44
	{
slouken@574
    45
slouken@574
    46
		push	edi
slouken@574
    47
		push	esi
slouken@574
    48
		push	ebx
slouken@574
    49
		
slouken@574
    50
		mov		edi, dst		// edi = dst
slouken@574
    51
		mov		esi, src		// esi = src
slouken@574
    52
		mov		eax, volume		// eax = volume
slouken@574
    53
		mov		ebx, nSize		// ebx = size
slouken@574
    54
		shr		ebx, 4			// process 16 bytes per iteration = 8 samples
slouken@574
    55
		jz		endS16
slouken@574
    56
		
slouken@574
    57
		pxor	mm0, mm0
slouken@574
    58
		movd	mm0, eax		//%%eax,%%mm0
slouken@574
    59
		movq	mm1, mm0		//%%mm0,%%mm1
slouken@574
    60
		psllq	mm0, 16			//$16,%%mm0
slouken@574
    61
		por		mm0, mm1		//%%mm1,%%mm0
slouken@574
    62
		psllq	mm0, 16			//$16,%%mm0
slouken@574
    63
		por		mm0, mm1		//%%mm1,%%mm0
slouken@574
    64
		psllq	mm0, 16			//$16,%%mm0
slouken@574
    65
		por		mm0, mm1		//%%mm1,%%mm0			// mm0 = vol|vol|vol|vol
slouken@574
    66
icculus@1190
    67
		#ifndef __WATCOMC__
icculus@1049
    68
		align	16
icculus@1190
    69
		#endif
slouken@574
    70
mixloopS16:
slouken@574
    71
		movq	mm1, [esi]		//(%%esi),%%mm1\n" // mm1 = a|b|c|d
slouken@574
    72
		movq	mm2, mm1		//%%mm1,%%mm2\n" // mm2 = a|b|c|d
slouken@574
    73
		movq	mm4, [esi + 8]	//8(%%esi),%%mm4\n" // mm4 = e|f|g|h
slouken@574
    74
		// pre charger le buffer dst dans mm7
slouken@574
    75
		movq	mm7, [edi]		//(%%edi),%%mm7\n" // mm7 = dst[0]"
slouken@574
    76
		// multiplier par le volume
slouken@574
    77
		pmullw	mm1, mm0		//%%mm0,%%mm1\n" // mm1 = l(a*v)|l(b*v)|l(c*v)|l(d*v)
slouken@574
    78
		pmulhw	mm2, mm0		//%%mm0,%%mm2\n" // mm2 = h(a*v)|h(b*v)|h(c*v)|h(d*v)
slouken@574
    79
		movq	mm5, mm4		//%%mm4,%%mm5\n" // mm5 = e|f|g|h
slouken@574
    80
		pmullw	mm4, mm0		//%%mm0,%%mm4\n" // mm4 = l(e*v)|l(f*v)|l(g*v)|l(h*v)
slouken@574
    81
		pmulhw	mm5, mm0		//%%mm0,%%mm5\n" // mm5 = h(e*v)|h(f*v)|h(g*v)|h(h*v)
slouken@574
    82
		movq	mm3, mm1		//%%mm1,%%mm3\n" // mm3 = l(a*v)|l(b*v)|l(c*v)|l(d*v)
slouken@574
    83
		punpckhwd	mm1, mm2	//%%mm2,%%mm1\n" // mm1 = a*v|b*v
slouken@574
    84
		movq		mm6, mm4	//%%mm4,%%mm6\n" // mm6 = l(e*v)|l(f*v)|l(g*v)|l(h*v)
slouken@574
    85
		punpcklwd	mm3, mm2	//%%mm2,%%mm3\n" // mm3 = c*v|d*v
slouken@574
    86
		punpckhwd	mm4, mm5	//%%mm5,%%mm4\n" // mm4 = e*f|f*v
slouken@574
    87
		punpcklwd	mm6, mm5	//%%mm5,%%mm6\n" // mm6 = g*v|h*v
slouken@574
    88
		// pre charger le buffer dst dans mm5
slouken@574
    89
		movq	mm5, [edi + 8]	//8(%%edi),%%mm5\n" // mm5 = dst[1]
slouken@574
    90
		// diviser par 128
slouken@574
    91
		psrad	mm1, 7			//$7,%%mm1\n" // mm1 = a*v/128|b*v/128 , 128 = SDL_MIX_MAXVOLUME
slouken@574
    92
		add		esi, 16			//$16,%%esi\n"
slouken@574
    93
		psrad	mm3, 7			//$7,%%mm3\n" // mm3 = c*v/128|d*v/128
slouken@574
    94
		psrad	mm4, 7			//$7,%%mm4\n" // mm4 = e*v/128|f*v/128
slouken@574
    95
		// mm1 = le sample avec le volume modifie
slouken@574
    96
		packssdw	mm3, mm1	//%%mm1,%%mm3\n" // mm3 = s(a*v|b*v|c*v|d*v)
slouken@574
    97
		psrad	mm6, 7			//$7,%%mm6\n" // mm6= g*v/128|h*v/128
slouken@574
    98
		paddsw	mm3, mm7		//%%mm7,%%mm3\n" // mm3 = adjust_volume(src)+dst
slouken@574
    99
		// mm4 = le sample avec le volume modifie
slouken@574
   100
		packssdw	mm6, mm4	//%%mm4,%%mm6\n" // mm6 = s(e*v|f*v|g*v|h*v)
slouken@574
   101
		movq	[edi], mm3		//%%mm3,(%%edi)\n"
slouken@574
   102
		paddsw	mm6, mm5		//%%mm5,%%mm6\n" // mm6 = adjust_volume(src)+dst
slouken@574
   103
		movq	[edi + 8], mm6	//%%mm6,8(%%edi)\n"
slouken@574
   104
		add		edi, 16			//$16,%%edi\n"
slouken@574
   105
		dec		ebx				//%%ebx\n"
slouken@574
   106
		jnz mixloopS16
slouken@574
   107
slouken@4102
   108
endS16:
slouken@574
   109
		emms
slouken@574
   110
		
slouken@574
   111
		pop		ebx
slouken@574
   112
		pop		esi
slouken@574
   113
		pop		edi
slouken@574
   114
	}
slouken@574
   115
slouken@574
   116
}
slouken@574
   117
slouken@574
   118
////////////////////////////////////////////////
slouken@574
   119
// Mixing for 8 bit signed buffers
slouken@574
   120
////////////////////////////////////////////////
slouken@574
   121
slouken@574
   122
void SDL_MixAudio_MMX_S8_VC(char* dst,char* src,unsigned int nSize,int volume)
slouken@574
   123
{
slouken@574
   124
	_asm
slouken@574
   125
	{
slouken@574
   126
slouken@574
   127
		push	edi
slouken@574
   128
		push	esi
slouken@574
   129
		push	ebx
slouken@574
   130
		
slouken@574
   131
		mov		edi, dst	//movl	%0,%%edi	// edi = dst
slouken@574
   132
		mov		esi, src	//%1,%%esi	// esi = src
slouken@574
   133
		mov		eax, volume	//%3,%%eax	// eax = volume
slouken@574
   134
icculus@1149
   135
		movd	mm0, eax	//%%eax,%%mm0
slouken@574
   136
		movq	mm1, mm0	//%%mm0,%%mm1
slouken@574
   137
		psllq	mm0, 16		//$16,%%mm0
slouken@574
   138
		por		mm0, mm1	//%%mm1,%%mm0
slouken@574
   139
		psllq	mm0, 16		//$16,%%mm0
slouken@574
   140
		por		mm0, mm1	//%%mm1,%%mm0
slouken@574
   141
		psllq	mm0, 16		//$16,%%mm0
slouken@574
   142
		por		mm0, mm1	//%%mm1,%%mm0
slouken@574
   143
		
slouken@574
   144
		mov		ebx, nSize	//%2,%%ebx	// ebx = size
slouken@574
   145
		shr		ebx, 3		//$3,%%ebx	// process 8 bytes per iteration = 8 samples
slouken@574
   146
		cmp		ebx, 0		//$0,%%ebx
slouken@574
   147
		je		endS8
slouken@574
   148
icculus@1190
   149
		#ifndef __WATCOMC__
icculus@1049
   150
		align 16
icculus@1190
   151
		#endif
slouken@574
   152
mixloopS8:
slouken@574
   153
		pxor	mm2, mm2	//%%mm2,%%mm2		// mm2 = 0
slouken@574
   154
		movq	mm1, [esi]	//(%%esi),%%mm1	// mm1 = a|b|c|d|e|f|g|h
slouken@574
   155
		movq	mm3, mm1	//%%mm1,%%mm3 	// mm3 = a|b|c|d|e|f|g|h
slouken@574
   156
		// on va faire le "sign extension" en faisant un cmp avec 0 qui retourne 1 si <0, 0 si >0
slouken@574
   157
		pcmpgtb		mm2, mm1	//%%mm1,%%mm2	// mm2 = 11111111|00000000|00000000....
slouken@574
   158
		punpckhbw	mm1, mm2	//%%mm2,%%mm1	// mm1 = 0|a|0|b|0|c|0|d
slouken@574
   159
		punpcklbw	mm3, mm2	//%%mm2,%%mm3	// mm3 = 0|e|0|f|0|g|0|h
slouken@574
   160
		movq	mm2, [edi]	//(%%edi),%%mm2	// mm2 = destination
slouken@574
   161
		pmullw	mm1, mm0	//%%mm0,%%mm1	// mm1 = v*a|v*b|v*c|v*d
slouken@574
   162
		add		esi, 8		//$8,%%esi
slouken@574
   163
		pmullw	mm3, mm0	//%%mm0,%%mm3	// mm3 = v*e|v*f|v*g|v*h
slouken@574
   164
		psraw	mm1, 7		//$7,%%mm1		// mm1 = v*a/128|v*b/128|v*c/128|v*d/128 
slouken@574
   165
		psraw	mm3, 7		//$7,%%mm3		// mm3 = v*e/128|v*f/128|v*g/128|v*h/128
slouken@574
   166
		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
   167
		paddsb	mm3, mm2	//%%mm2,%%mm3	// add to destination buffer
slouken@574
   168
		movq	[edi], mm3	//%%mm3,(%%edi)	// store back to ram
slouken@574
   169
		add		edi, 8		//$8,%%edi
slouken@574
   170
		dec		ebx			//%%ebx
slouken@574
   171
		jnz		mixloopS8
slouken@574
   172
		
slouken@574
   173
endS8:
slouken@574
   174
		emms
slouken@574
   175
		
slouken@574
   176
		pop		ebx
slouken@574
   177
		pop		esi
slouken@574
   178
		pop		edi
slouken@574
   179
	}
slouken@574
   180
}
slouken@574
   181
slouken@1402
   182
#endif /* SDL_ASSEMBLY_ROUTINES */
icculus@4322
   183
#endif /* SDL_BUGGY_MMX_MIXERS */