[SDL] [PATCH] Re: SDL_memcpy variants used in SDL_BlitCopy

Ricardo Cruz rpmcruz at clix.pt
Tue Sep 13 09:45:29 PDT 2005

 Perdon me, but may I ask why does SDL try to roll its own version of 
 I mean, wouldn't you think the authors of your's system C library would do 
all possible optmizations possible? If some systems don't, maybe you should 
send 'em a patch or, in last case, make your own memcpy(), if they are closed 


Em Terça, 13 de Setembro de 2005 15:29, o Stephane Marchesin escreveu:
> > > Actually, for the kind of memcpy that SDL does (small blocks on
> > > average), the rolled version is faster than the unrolled one. Same goes
> > > for the "heavily optimized" memcpy that you can find on the net, these
> > > are aimed at large blocks.
> > >
> > > Stephane
> >
> >   As I can see in SDL sources SDL_memcpy is used in SDL_BlitCopy.
> >   Then
> >         /* Check for special "identity" case -- copy blit */
> >         if ( surface->map->identity && blit_index == 0 ) {
> >                 surface->map->sw_data->blit = SDL_BlitCopy;
> >
> >   So in most cases blocks will be huge - backgrounds, sprites and so on.
> >   Please give more detail on the point - "the rolled version is faster
> > than the unrolled one".
> Long story : when I wrote that memcpy code, I Initially had an unrolled
> version, and I benchmarked it versus a rolled version versus the plain libc
> version. To my surprise, the rolled version was faster. The reason is that
> these highly optimized versions are made for page-sized (4096 bytes)
> chunks, while the SDL_BlitCopy function copies one line at a time, so the
> average block size we're interested in is the average size of a line (for
> 100 pixels, that's between 100 bytes and 400 bytes depending on the pixel
> format). So, for our SDL purposes, the rolled memcpy is the right
> compromise.
> Heh, people suspect this code to be slow from time to time (slower than the
> unrolled version, slower than the libc version...) but I have yet to be
> proven wrong :)
> Stephane
Freedom is what you do with what's been done to you.
		-- Jean-Paul Sartre

More information about the SDL mailing list