diff src/video/SDL_blit.c @ 689:5bb080d35049

Date: Tue, 19 Aug 2003 17:57:00 +0200 From: Stephane Marchesin Subject: Re: [SDL] [patch] MMX alpha blit patches with MMX detection I think everything is correct now. I've done as much testing as I could, but some real-world testing wouldn't hurt, I think. The patch is here : http://icps.u-strasbg.fr/~marchesin/sdl_mmxblit.patch If you do byte-by-byte comparison of the output between C and MMX functions, you'll notice that the results for 555 and 565 RGB alpha blits aren't exactly the same. This is because MMX functions for 555 and 565 RGB have an higher accuracy. If you want the exact same behaviour that's possible by masking the three lower alpha bits in the MMX functions. Just ask ! I removed one MMX function because after I fixed it to match its C equivalent, it revealed to be slower than the C version on a PIII (although a bit faster on an Athlon XP). I've also added MMX and PIII replacements for SDL_memcpy. Those provide some speed up in testvidinfo -benchmark (at least for me, under linux & X11).
author Sam Lantinga <slouken@libsdl.org>
date Fri, 22 Aug 2003 05:51:19 +0000
parents 4314a501d7be
children 8468fc0504f3
line wrap: on
line diff
--- a/src/video/SDL_blit.c	Tue Aug 12 15:17:20 2003 +0000
+++ b/src/video/SDL_blit.c	Fri Aug 22 05:51:19 2003 +0000
@@ -37,6 +37,19 @@
 #include "SDL_pixels_c.h"
 #include "SDL_memops.h"
 
+#if defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT)
+#include "mmx.h"
+/* Function to check the CPU flags */
+#define MMX_CPU		0x800000
+#define SSE_CPU		0x2000000
+#define CPU_Flags()	Hermes_X86_CPU()
+#define X86_ASSEMBLER
+#define HermesConverterInterface	void
+#define HermesClearInterface		void
+#define STACKCALL
+#include "HeadX86.h"
+#endif
+
 /* The general purpose software blit routine */
 static int SDL_SoftBlit(SDL_Surface *src, SDL_Rect *srcrect,
 			SDL_Surface *dst, SDL_Rect *dstrect)
@@ -106,11 +119,54 @@
 	return(okay ? 0 : -1);
 }
 
+#if defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT)
+void SDL_memcpyMMX(char* to,char* from,int len)
+{
+	int i;
+
+	for(i=0; i<len/8; i++) {
+		__asm__ __volatile__ (
+		"	movq (%0), %%mm0\n"
+		"	movq %%mm0, (%1)\n"
+		: : "r" (from), "r" (to) : "memory");
+		from+=8;
+		to+=8;
+	}
+	if (len&7)
+		SDL_memcpy(to, from, len&7);
+}
+
+void SDL_memcpySSE(char* to,char* from,int len)
+{
+	int i;
+
+	__asm__ __volatile__ (
+	"	prefetchnta (%0)\n"
+	"	prefetchnta 64(%0)\n"
+	"	prefetchnta 128(%0)\n"
+	"	prefetchnta 192(%0)\n"
+	: : "r" (from) );
+
+	for(i=0; i<len/8; i++) {
+		__asm__ __volatile__ (
+		"	prefetchnta 256(%0)\n"
+		"	movq (%0), %%mm0\n"
+		"	movntq %%mm0, (%1)\n"
+		: : "r" (from), "r" (to) : "memory");
+		from+=8;
+		to+=8;
+	}
+	if (len&7)
+		SDL_memcpy(to, from, len&7);
+}
+#endif
+
 static void SDL_BlitCopy(SDL_BlitInfo *info)
 {
 	Uint8 *src, *dst;
 	int w, h;
 	int srcskip, dstskip;
+	Uint32 f;
 
 	w = info->d_width*info->dst->BytesPerPixel;
 	h = info->d_height;
@@ -118,6 +174,33 @@
 	dst = info->d_pixels;
 	srcskip = w+info->s_skip;
 	dstskip = w+info->d_skip;
+#if defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT)
+	f=CPU_Flags();
+	if((f&(MMX_CPU|SSE_CPU))==(MMX_CPU|SSE_CPU))
+	{
+		while ( h-- ) {
+			SDL_memcpySSE(dst, src, w);
+			src += srcskip;
+			dst += dstskip;
+		}
+		__asm__ __volatile__ (
+		"	emms\n"
+		::);
+	}
+	else
+	if((f&(MMX_CPU))!=0)
+	{
+		while ( h-- ) {
+			SDL_memcpyMMX(dst, src, w);
+			src += srcskip;
+			dst += dstskip;
+		}
+		__asm__ __volatile__ (
+		"	emms\n"
+		::);
+	}
+	else
+#endif
 	while ( h-- ) {
 		SDL_memcpy(dst, src, w);
 		src += srcskip;