comparison 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
comparison
equal deleted inserted replaced
688:c0522010bb6d 689:5bb080d35049
34 #include "SDL_sysvideo.h" 34 #include "SDL_sysvideo.h"
35 #include "SDL_blit.h" 35 #include "SDL_blit.h"
36 #include "SDL_RLEaccel_c.h" 36 #include "SDL_RLEaccel_c.h"
37 #include "SDL_pixels_c.h" 37 #include "SDL_pixels_c.h"
38 #include "SDL_memops.h" 38 #include "SDL_memops.h"
39
40 #if defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT)
41 #include "mmx.h"
42 /* Function to check the CPU flags */
43 #define MMX_CPU 0x800000
44 #define SSE_CPU 0x2000000
45 #define CPU_Flags() Hermes_X86_CPU()
46 #define X86_ASSEMBLER
47 #define HermesConverterInterface void
48 #define HermesClearInterface void
49 #define STACKCALL
50 #include "HeadX86.h"
51 #endif
39 52
40 /* The general purpose software blit routine */ 53 /* The general purpose software blit routine */
41 static int SDL_SoftBlit(SDL_Surface *src, SDL_Rect *srcrect, 54 static int SDL_SoftBlit(SDL_Surface *src, SDL_Rect *srcrect,
42 SDL_Surface *dst, SDL_Rect *dstrect) 55 SDL_Surface *dst, SDL_Rect *dstrect)
43 { 56 {
104 } 117 }
105 /* Blit is done! */ 118 /* Blit is done! */
106 return(okay ? 0 : -1); 119 return(okay ? 0 : -1);
107 } 120 }
108 121
122 #if defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT)
123 void SDL_memcpyMMX(char* to,char* from,int len)
124 {
125 int i;
126
127 for(i=0; i<len/8; i++) {
128 __asm__ __volatile__ (
129 " movq (%0), %%mm0\n"
130 " movq %%mm0, (%1)\n"
131 : : "r" (from), "r" (to) : "memory");
132 from+=8;
133 to+=8;
134 }
135 if (len&7)
136 SDL_memcpy(to, from, len&7);
137 }
138
139 void SDL_memcpySSE(char* to,char* from,int len)
140 {
141 int i;
142
143 __asm__ __volatile__ (
144 " prefetchnta (%0)\n"
145 " prefetchnta 64(%0)\n"
146 " prefetchnta 128(%0)\n"
147 " prefetchnta 192(%0)\n"
148 : : "r" (from) );
149
150 for(i=0; i<len/8; i++) {
151 __asm__ __volatile__ (
152 " prefetchnta 256(%0)\n"
153 " movq (%0), %%mm0\n"
154 " movntq %%mm0, (%1)\n"
155 : : "r" (from), "r" (to) : "memory");
156 from+=8;
157 to+=8;
158 }
159 if (len&7)
160 SDL_memcpy(to, from, len&7);
161 }
162 #endif
163
109 static void SDL_BlitCopy(SDL_BlitInfo *info) 164 static void SDL_BlitCopy(SDL_BlitInfo *info)
110 { 165 {
111 Uint8 *src, *dst; 166 Uint8 *src, *dst;
112 int w, h; 167 int w, h;
113 int srcskip, dstskip; 168 int srcskip, dstskip;
169 Uint32 f;
114 170
115 w = info->d_width*info->dst->BytesPerPixel; 171 w = info->d_width*info->dst->BytesPerPixel;
116 h = info->d_height; 172 h = info->d_height;
117 src = info->s_pixels; 173 src = info->s_pixels;
118 dst = info->d_pixels; 174 dst = info->d_pixels;
119 srcskip = w+info->s_skip; 175 srcskip = w+info->s_skip;
120 dstskip = w+info->d_skip; 176 dstskip = w+info->d_skip;
177 #if defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT)
178 f=CPU_Flags();
179 if((f&(MMX_CPU|SSE_CPU))==(MMX_CPU|SSE_CPU))
180 {
181 while ( h-- ) {
182 SDL_memcpySSE(dst, src, w);
183 src += srcskip;
184 dst += dstskip;
185 }
186 __asm__ __volatile__ (
187 " emms\n"
188 ::);
189 }
190 else
191 if((f&(MMX_CPU))!=0)
192 {
193 while ( h-- ) {
194 SDL_memcpyMMX(dst, src, w);
195 src += srcskip;
196 dst += dstskip;
197 }
198 __asm__ __volatile__ (
199 " emms\n"
200 ::);
201 }
202 else
203 #endif
121 while ( h-- ) { 204 while ( h-- ) {
122 SDL_memcpy(dst, src, w); 205 SDL_memcpy(dst, src, w);
123 src += srcskip; 206 src += srcskip;
124 dst += dstskip; 207 dst += dstskip;
125 } 208 }