[retroforth] Speed up of 'find' word

  • From: "Ron Aaron" <ron@xxxxxxxxxxx>
  • To: retroforth@xxxxxxxxxxxxx
  • Date: Tue, 25 Jan 2005 09:03:20 -0800 (PST)

'find' currently only does a full check of the word if it's the same length as
the word sought.  This is good; but it can be further sped up by only doing
the rep cmpsb if the first char is the same.  This prevents a lot of push/pop
and the cmpsb:


; trashes EDX
code 'find', find               ;
        push ebx                ;
        mov ebx, flast          ;
.o:     push ecx                ;
        upop ecx                ;
        ; get first char to do quick compare:
        mov dl,  byte [eax]
.a:     mov ebx,[ebx]           ;
        or ebx,ebx              ;
        jz .end                 ;
        cmp cl,[ebx+8]          ;
        jne .a                  ;
        ; same length; compare first char
        cmp dl, [ebx+9]
        jne .a
.len:   push esi                ; same length
        push edi                ;
        push ecx                ;
        mov esi,eax             ;
        lea edi,[ebx+9]         ;
        rep cmpsb               ;
        pop ecx                 ;
        pop edi                 ;
        pop esi                 ;
        jne .a                  ;
        mov eax,[ebx+4]         ; exact match
        clc                     ;
        jmp .ret                ;
.end:   upsh ecx                ; no matches
        stc                     ;
.ret:   pop ecx                 ;
        pop ebx                 ;
next




-- 
My GPG public key is at http://ronware.org/
fingerprint: 8130 734C 69A3 6542 0853  CB42 3ECF 9259 AD29 415D




Other related posts: