Commit 3095e05e authored by Sam Lantinga's avatar Sam Lantinga

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).

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40690
parent d8ae01f1
......@@ -42,6 +42,7 @@ COMMON_SRCS = \
SDL_yuv_sw.c \
SDL_yuv_sw_c.h \
SDL_yuv_mmx.c \
mmx.h \
blank_cursor.h \
default_cursor.h
......
This diff is collapsed.
......@@ -37,6 +37,19 @@ static char rcsid =
#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 @@ static int SDL_SoftBlit(SDL_Surface *src, SDL_Rect *srcrect,
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 @@ static void SDL_BlitCopy(SDL_BlitInfo *info)
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;
......
......@@ -410,12 +410,86 @@ do { \
} \
}
/* 2 - times unrolled loop */
#define DUFFS_LOOP_DOUBLE2(pixel_copy_increment, \
double_pixel_copy_increment, width) \
{ int n, w = width; \
if( w & 1 ) { \
pixel_copy_increment; \
w--; \
} \
if ( w > 0 ) { \
n = ( w + 2) / 4; \
switch( w & 2 ) { \
case 0: do { double_pixel_copy_increment; \
case 2: double_pixel_copy_increment; \
} while ( --n > 0 ); \
} \
} \
}
/* 2 - times unrolled loop 4 pixels */
#define DUFFS_LOOP_QUATRO2(pixel_copy_increment, \
double_pixel_copy_increment, \
quatro_pixel_copy_increment, width) \
{ int n, w = width; \
if(w & 1) { \
pixel_copy_increment; \
w--; \
} \
if(w & 2) { \
double_pixel_copy_increment; \
w -= 2; \
} \
if ( w > 0 ) { \
n = ( w + 7 ) / 8; \
switch( w & 4 ) { \
case 0: do { quatro_pixel_copy_increment; \
case 4: quatro_pixel_copy_increment; \
} while ( --n > 0 ); \
} \
} \
}
/* Use the 8-times version of the loop by default */
#define DUFFS_LOOP(pixel_copy_increment, width) \
DUFFS_LOOP8(pixel_copy_increment, width)
#else
/* Don't use Duff's device to unroll loops */
#define DUFFS_LOOP_DOUBLE2(pixel_copy_increment, \
double_pixel_copy_increment, width) \
{ int n = width; \
if( n & 1 ) { \
pixel_copy_increment; \
n--; \
} \
n=n>>1; \
for(; n > 0; --n) { \
double_pixel_copy_increment; \
} \
}
/* Don't use Duff's device to unroll loops */
#define DUFFS_LOOP_QUATRO2(pixel_copy_increment, \
double_pixel_copy_increment, \
quatro_pixel_copy_increment, width) \
{ int n = width; \
if(n & 1) { \
pixel_copy_increment; \
n--; \
} \
if(n & 2) { \
double_pixel_copy_increment; \
n -= 2; \
} \
n=n>>2; \
for(; n > 0; --n) { \
quatro_pixel_copy_increment; \
} \
}
/* Don't use Duff's device to unroll loops */
#define DUFFS_LOOP(pixel_copy_increment, width) \
{ int n; \
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment