All pastes #338569 Raw Edit

Untitled

public cpp v1 · immutable
·published 2007-02-03 15:34 UTC
rendered paste body
void * my_memset_mmx(void *vpAddress, char cFill, unsigned int uiLength){    /* ALIGN ME OMG *    http://<b style="color:black;background-color:#ffff66">72.14.253.104</b>/search?q=cache:adDii5O4mWcJ:www.johnfindlay.plus.com/lcc-win32/asm/memset.htm+mmx+memset&hl=en&gl=us&ct=clnk&cd=8    */	_asm {		push eax		push ebx		push ecx		push edx		push esi		push edi		push esp		emms				xor edx, edx		movsx ebx, byte ptr [cFill] ; load the char into ebx, bl has the actual byte		mov edi, dword ptr [vpAddress] ; load the start address		mov eax, dword ptr [uiLength] ; get the length of bytes to copy				mov ecx, 8h ; we want to divide by 8		div ecx ; do the division, eax has the quotient, edx has the remainder				; this is where we make ebx hold repeat copies of the byte		test eax, eax		jz mainend				mov esi, ebx		shl esi, 8		or ebx, esi		mov esi, ebx		shl esi, 16		or ebx, esi				pxor mm0, mm0				movd mm0, ebx		movq mm1, mm0		psllq mm0, 20h		por mm1, mm0        xor ecx, ecx		mainstart:		movq dword ptr [edi+ecx*8], mm1        movq dword ptr [edi+ecx*8+8], mm1        movq dword ptr [edi+ecx*8+16], mm1        movq dword ptr [edi+ecx*8+24], mm1        movq dword ptr [edi+ecx*8+32], mm1        movq dword ptr [edi+ecx*8+40], mm1        movq dword ptr [edi+ecx*8+48], mm1        movq dword ptr [edi+ecx*8+56], mm1                lea ecx, [ecx+8]		cmp ecx, eax		jl mainstart                shl ecx, 3        add edi, ecx        		mainend:                test edx, edx		jz remend                xor ecx, ecx				remstart:		mov byte ptr [edi+ecx], bl				inc ecx		cmp ecx, edx		jl remstart		remend:		emms				pop esp		pop edi		pop esi		pop edx		pop ecx		pop ebx		pop eax	}	return vpAddress;}void * my_memset_mmx_a(void *vpAddress, char cFill, unsigned int uiLength){	_asm {		push eax		push ebx		push ecx		push edx		push esi		push edi		push esp		emms				movsx ebx, byte ptr [cFill] ; load the char into ebx, bl has the actual byte		mov edi, dword ptr [vpAddress] ; load the start address		mov eax, dword ptr [uiLength] ; get the length of bytes to copy				; are we aligned on an 8-boundary?		mov ecx, edi		and ecx, 7h		jpo init		mov edx, 8		sub edx, ecx		mov ecx, edx		sub eax, ecx				; do the actual alignment		alignment:		mov byte ptr [edi], bl		inc edi		loop alignment				init:				; decrease the total number of bytes by the number of 64 byte blocks				mov ecx, eax		shr ecx, 7		mov edx, ecx		shl edx, 7		sub eax, edx				; make the value repeat a lot		mov esi, ebx		shl esi, 8		or ebx, esi		mov esi, ebx		shl esi, 16		or ebx, esi				; make it repeat even more		pxor mm0, mm0				movd mm0, ebx		movq mm1, mm0		psllq mm0, 20h		por mm1, mm0		mainstart:		jecxz mainend		dec ecx		movq dword ptr [edi], mm1        movq dword ptr [edi+8], mm1        movq dword ptr [edi+16], mm1        movq dword ptr [edi+24], mm1        movq dword ptr [edi+32], mm1        movq dword ptr [edi+40], mm1        movq dword ptr [edi+48], mm1        movq dword ptr [edi+56], mm1        movq dword ptr [edi+64], mm1        movq dword ptr [edi+72], mm1        movq dword ptr [edi+80], mm1        movq dword ptr [edi+88], mm1        movq dword ptr [edi+96], mm1        movq dword ptr [edi+104], mm1        movq dword ptr [edi+112], mm1        movq dword ptr [edi+120], mm1        add edi, 128		jmp mainstart        		mainend:                test edx, edx		jz remend				mov ecx, eax				remstart:		mov byte ptr [edi], bl		inc edi		loop remstart		remend:		emms				pop esp		pop edi		pop esi		pop edx		pop ecx		pop ebx		pop eax	}	return vpAddress;}void * my_memset_sse2(void *vpAddress, char cFill, unsigned int uiLength){	_asm {		push eax		push ebx		push ecx		push edx		push esi		push edi		push esp				movsx ebx, byte ptr [cFill] ; load the char into ebx, bl has the actual byte		mov edi, dword ptr [vpAddress] ; load the start address		mov eax, dword ptr [uiLength] ; get the length of bytes to copy				; are we aligned on an 8-boundary?		mov ecx, edi		and ecx, 15		jpo init		mov edx, 16		sub edx, ecx		mov ecx, edx		sub eax, ecx				; do the actual alignment		alignment:		mov byte ptr [edi], bl		inc edi		loop alignment				init:				; decrease the total number of bytes by the number of 64 byte blocks				mov ecx, eax		shr ecx, 8		mov edx, ecx		shl edx, 8		sub eax, edx				; make the value repeat a lot		mov esi, ebx		shl esi, 8		or ebx, esi		mov esi, ebx		shl esi, 16		or ebx, esi				; make it repeat even more		pxor mm0, mm0				movd mm0, ebx		movq mm1, mm0		psllq mm0, 20h		por mm1, mm0				movq2dq xmm0, mm1		movaps xmm1, xmm0		pslldq xmm1, 8		orps xmm1, xmm0		mainstart:		jecxz mainend		dec ecx		movaps qword ptr [edi], xmm1        movaps qword ptr [edi+16], xmm1        movaps qword ptr [edi+32], xmm1        movaps qword ptr [edi+48], xmm1        movaps qword ptr [edi+64], xmm1        movaps qword ptr [edi+80], xmm1        movaps qword ptr [edi+96], xmm1        movaps qword ptr [edi+112], xmm1        movaps qword ptr [edi+128], xmm1        movaps qword ptr [edi+144], xmm1        movaps qword ptr [edi+160], xmm1        movaps qword ptr [edi+176], xmm1        movaps qword ptr [edi+192], xmm1        movaps qword ptr [edi+208], xmm1        movaps qword ptr [edi+224], xmm1        movaps qword ptr [edi+240], xmm1        add edi, 256		jmp mainstart        		mainend:				mov ecx, eax		test ecx, ecx		jz remend				remstart:		mov byte ptr [edi], bl		inc edi		loop remstart		remend:		emms				pop esp		pop edi		pop esi		pop edx		pop ecx		pop ebx		pop eax	}	return vpAddress;}