Mail Archives: djgpp/1993/07/31/20:57:30
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 -