I had an idea for a way to search strings that *might* be faster. I don't know for sure. I would like to know what you all think of this checksum method. I have tested the algo and it works as expected, but I haven't profiled it. I want to hear more ideas first.
Thanks. ;)
Thanks. ;)
[size=12]InString2 proc uses ebx edi esi, lpSource:DWORD, lpPattern:DWORD[/size]
[size=9]
;-------------------------------------------------------------
; by Iblis
;
; InString2 searches for the first occurance of the string
; pointed to by lpPattern in the string pointed to by lpSource
; and returns the (1) based index into the character array.
;
; This version of InString does not use a starting position,
; so calculating the position is the responsibility of the
; user, although adding this functionality wouldn't be too
; difficult. The main purpose of this is to play with an idea
; I had about string searching. Instead of doing a straight
; byte scan, the routine creates a simple checksum for the
; pattern string and compares it with the source string. If
; the checksums match, one last check is made to see if the
; strings match byte for byte. The idea is that perhaps this
; might speed the search up a bit.
;
; Return value:
; On success, the (1) based index of the search string is
; returned. If there is no match, the routine returns (0).
; Returns -1 on error. Possible causes for error include:
; -If the pattern string is longer than the source.
; -If the pattern string has zero length.
;-------------------------------------------------------------[/size]
[size=12]
mov esi, lpSource
mov edi, lpPattern
xor eax, eax
xor edx, edx
@chksm: movzx ebx, byte ptr [esi]
inc esi
movzx ecx, byte ptr [edi]
inc edi
lea eax, [eax + ecx]
lea edx, [edx + ebx]
dec bl
sub bl, 0FFh
not ecx
inc ecx
ja @error
jnz @chksm
sub edx, ebx
lea ecx, [edi - 1]
sub ecx, lpPattern
jz @error
sub esi, ecx
dec esi
@findm: cmp eax, edx
je @match
@findn: movzx ebx, byte ptr [esi]
sub edx, ebx
movzx ebx, byte ptr [esi + ecx]
lea edx, [edx + ebx]
inc esi
or ebx, ebx
jnz @findm
xor eax, eax
jmp @done
@match: mov edi, lpPattern
mov ebx, ecx
repe cmpsb
sub esi, ebx
add esi, ecx
or ecx, ecx
mov ecx, ebx
jnz @findn
lea eax, [esi + 1]
sub eax, lpSource
jmp @done
@error: mov eax, -1
@done: ret
InString2 endp[/size]
Here is test.
But I used a little bit different InString then in m32lib.
Yet it still just modification of Steve's original proc.
But I used a little bit different InString then in m32lib.
Yet it still just modification of Steve's original proc.
Svin, thanks! :)
I see that my algo is horribly slow. :(
I am not much of an optimizer.
My point in posting that was to get a discussion going about the method used. It doesn't behave like normal byte scanners. Basically I want to know if the checksum method has the potential to be fast.
Ahh well, I try. ;)
I see that my algo is horribly slow. :(
I am not much of an optimizer.
My point in posting that was to get a discussion going about the method used. It doesn't behave like normal byte scanners. Basically I want to know if the checksum method has the potential to be fast.
Ahh well, I try. ;)
the svin .
can your version vs my version?
but notice it uses strlen .
so maybe add to parameters to both algo . and remove the strlen for the test ?
bye
thanks
eko
EDIT:
iblis . how does your method work ?
i mean you created checksum for the pattern. but what about the all string ?
can your version vs my version?
but notice it uses strlen .
so maybe add to parameters to both algo . and remove the strlen for the test ?
bye
thanks
eko
EDIT:
iblis . how does your method work ?
i mean you created checksum for the pattern. but what about the all string ?
eko,
Yours in most cases ~ 0,5% faster.
Good work!
iblis, it's very good that you got ideas and try it.
It's much harder to create ideas and check them then
critisize others.
Some people recently tought me that critisize others ideas is more profitable - you gave nothing exept for OTHER people code and almost always win, 'cause it's not so easy to improve some hardly inspected algos and creators mostly lost in their attempts (to win at the end if they are tough enogh).
So try your ideas, give them to other - they beat them most of the time :)
But at the end you may get lucky and find something better then exist to give it out for free :)
Good luck to you.
I stopped doing it.
Yours in most cases ~ 0,5% faster.
Good work!
iblis, it's very good that you got ideas and try it.
It's much harder to create ideas and check them then
critisize others.
Some people recently tought me that critisize others ideas is more profitable - you gave nothing exept for OTHER people code and almost always win, 'cause it's not so easy to improve some hardly inspected algos and creators mostly lost in their attempts (to win at the end if they are tough enogh).
So try your ideas, give them to other - they beat them most of the time :)
But at the end you may get lucky and find something better then exist to give it out for free :)
Good luck to you.
I stopped doing it.
I forgot testing prog :)
iblis your idea can be good . maybe we can optimize the code alittle
few questions
1.why do you do lea edx, and not add edx,ebx?
2. doesnt sub bl,-1 is the same as inc bl , so dec bl sub bl,0ffh cancel each other
i think the order of the command make a diffrent
like you can do
dec bl
not ecx
sub bl,-1
inc ecx ; should be faster than the orginal order because there is no dependantcy(spelling! ...how to write this word ) this way
bye
eko
EDIT:
the svin . - can you post your version of instring
and why did you "stop doing it "?
chksm: movzx ebx, byte ptr [esi]
inc esi
movzx ecx, byte ptr [edi]
inc edi
lea eax, [eax + ecx]
lea edx, [edx + ebx]
dec bl
sub bl, 0FFh
not ecx
inc ecx
ja @error
jnz @chksm
few questions
1.why do you do lea edx, and not add edx,ebx?
2. doesnt sub bl,-1 is the same as inc bl , so dec bl sub bl,0ffh cancel each other
i think the order of the command make a diffrent
like you can do
dec bl
not ecx
sub bl,-1
inc ecx ; should be faster than the orginal order because there is no dependantcy(spelling! ...how to write this word ) this way
bye
eko
EDIT:
the svin . - can you post your version of instring
and why did you "stop doing it "?
Svin,
Don't give up! Most people here appreciate what you have to offer to the community. I for one enjoy reading your informational posts. ;)
Eko, thanks for your interest. ;)
1.why do you do lea edx, and not add edx,ebx?
Don't give up! Most people here appreciate what you have to offer to the community. I for one enjoy reading your informational posts. ;)
Eko, thanks for your interest. ;)
1.why do you do lea edx, and not add edx,ebx?
I don't know... like I said before, I'm not a very experienced optimizer. For some reason I thought that LEA is generally faster than ADD. Feel free to let me know the truth on this.
2. doesnt sub bl,-1 is the same as inc bl , so dec bl sub bl,0ffh cancel each other
Yes, but my reasons for this was to set the flags for my two branches. (Sorry if it seems convoluted) I will comment the code here so it makes more sense:
i think the order of the command make a diffrent [...] should be faster
Interesting... why is this?
dependantcy(spelling! ...how to write this word )
"Dependency"
Thanks!
-ib