delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1993/07/31/20:57:30

To: DJGPP AT SUN DOT SOE DOT CLARKSON DOT EDU
From: A DOT APPLEYARD AT fs1 DOT mt DOT umist DOT ac DOT uk
Date: 31 Jul 93 15:51:05 GMT
Subject: Gnu C fast string comparing and copying

  If anyone is interested, here are faster versions of strcmp() and strcpy()
for Gnu C:-
/*-----*//* fast compare s[0:n-1]==t[0:n-1], treat chars as -128 to +127 */
char str_cmp(void*s,void*t,int n){
asm("pushl %esi"); asm("pushl %edi"); asm("cld");
asm("movl 8(%ebp),%esi"); asm("movl 12(%ebp),%edi"); asm("movl 16(%ebp),%ecx");
asm("repe"); asm("cmpsb"); asm("pushf"); asm("popw %ax"); asm("andl $192,%eax");
asm("xorl $64,%eax"); asm("popl %edi"); asm("popl %esi");}
/*-----*//* fast compare s[0:n-1]==t[0:n-1], treat chars as 0 to +255 */
char str__cmp(void*s,void*t,int n){
asm("pushl %esi"); asm("pushl %edi"); asm("cld");
asm("movl 8(%ebp),%esi"); asm("movl 12(%ebp),%edi"); asm("movl 16(%ebp),%ecx");
asm("repe"); asm("cmpsb"); asm("pushf"); asm("popw %ax"); asm("movl %ax,%bx");
asm("andw $1,%bx"); asm("salw $7,%bx"); asm("andw $64,%ax");asm("xorw $64,%ax");
asm("orw %bx,%ax"); asm("popl %edi"); asm("popl %esi");}
/*-----*//* fast move s[0:n-1]=t[0:n-1] */
void str_cpy(void*s,void*t,int n){
asm("pushl %esi"); asm("pushl %edi"); asm("cld");
asm("movl 8(%ebp),%edi"); asm("movl 12(%ebp),%esi"); asm("movl 16(%ebp),%ecx");
asm("rep"); asm("movsb"); asm("popl %edi"); asm("popl %esi");}
/*-----*/

- Raw text -


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