www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/12/22/05:39:07

From: Elliott Oti <e DOT oti AT stud DOT warande DOT ruu DOT nl>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: memcpy(); is there something faster?
Date: Sat, 21 Dec 1996 23:59:16 -0800
Organization: Academic Computer Centre Utrecht, (ACCU)
Lines: 40
Message-ID: <32BCEA54.763F@stud.warande.ruu.nl>
References: <59g08k$758_001 AT cpe DOT Maroochydore DOT aone DOT net DOT au>
NNTP-Posting-Host: warande1078.warande.ruu.nl
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Daniel Everton wrote:
> 
> Hi all,
> 
> In a program I'm currently writing I need to copy some biggish (64k)
> shunks of memory around. I'm using memcpy() at the moment but it's not
> quite fast enough. Is there some other function that any one can
> suggest? The memory has all been allocated with malloc() and I'm not
> copying between conventional memory or something like that. Any help
> appreciated.

 
Here's some code I originally got from Mihai Moise's port of GL,  it
copies lng bytes from buffer src to buffer dst using movsl, with a movsb/movsw
attached at the beginning & the end to even things out. For variable
buffer sizes it should be faster than memcpy().

void CopyBuffer(void * dst, const void * src, int lng)
{
    asm("cld                 \n\t"
        "movl %%edi,%%ecx    \n\t"
	"andl $1,%%ecx       \n\t"
	"subl %%ecx,%%edx    \n\t"
	"rep ; movsb         \n\t" 
	"movl %%edx,%%ecx    \n\t"
	"shrl $2,%%ecx       \n\t"
	"rep ; movsl         \n\t"
	"testb $1,%%dl       \n\t"
	"je 1f               \n\t"
	"movsb               \n"
	"1:\ttestb $2,%%dl   \n\t"
	"je 2f               \n\t"
	"movsw               \n"
	"2:                  \n"
	::"d" (lng),"D" ((long) dst),"S" ((long) src)
	: "cx","dx","di","si");
}


Elliott

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019