I wrote another version to test out an idea and it has ended up a fair bit faster than the last one. It uses an unrolled main loop and multibranching to access the subloop. The subloop does the character scans forward as it allowed the use of memory operands that did not require stack preservation of ESI. Testing it has been interesting, I have Jeremy Collake's Boyer Moore variation to test against and with 5 or less characters it is faster than the Boyer Moore. 6 and over the Boyer Moore start to improve on it in speed terms. I bother with these types of algorithms as they are a lot more general purpose than the Boyer Moore and don't require a shift table to be constructed. Regards, hutch@pbq.com.au

; ########################################################################

tSearch proc StartPos:DWORD,lpString:DWORD,lnStrng:DWORD,
                            lpSubStr:DWORD,lnSubSt:DWORD

    push ebx
    push esi
    push edi

    mov eax, lpSubStr
    mov ecx, lnStrng
    mov bl,        ; 1st byte to search for
    mov esi, lpString
    mov edx, lnSubSt
    add ecx, esi        ; set exit condition

    add esi, StartPos

; ----------- main loop ----------------
;   Unroll by 4
; --------------------------------------
  tsStart:
    cmp , bl       ; cmp 1st byte
    je tp1
    cmp , bl     ; cmp 2nd byte
    je tp2
    cmp , bl     ; cmp 3rd byte
    je tp3
    cmp , bl     ; cmp 4th byte
    je tp4
    lea esi,     ; add 4 to esi
    cmp esi, ecx
    jle tsStart
; --------------------------------------
    mov eax, -1         ; set no match at -1
    jmp tQuit

  tp4:
    add esi, 3
    jmp tp1
  tp3:
    add esi, 2
    jmp tp1
  tp2:
    inc esi
  tp1:
    mov eax, 0          ; zero eax & use as counter
    mov edi, lpSubStr
  ; ----------- sub loop --------------
  tSubLoop:
    mov bh, 
    cmp bh, 
    jne teBack
    inc eax
    cmp eax, edx
    jne tSubLoop
  ; -----------------------------------
  tMatch:
    sub esi, lpString
    mov eax, esi
    jmp tQuit

  teBack:
    inc esi
    jmp tsStart

  tQuit:
    pop edi
    pop esi
    pop ebx

    ret

tSearch endp

; ########################################################################

Posted on 2001-04-29 11:50:00 by hutch--
hutch: Where can I get that Boyer-Moore algo? Thanks =)
Posted on 2001-04-29 23:27:00 by GogetaSSJ4
GogetaSSJ4, http://www.collakesoftware.com/ This is Jeremy Collake's site and it has a full boyer moore download available, I am testing a variation of his BMBinBin which is apparently a horsepool variation of ther algorithm. Regards, hutch@pbq.com.au
Posted on 2001-04-30 04:39:00 by hutch--