BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Some assembly required again :) --Wide PosEx

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Language BASM
View previous topic :: View next topic  
Author Message
Adem
Guest





PostPosted: Thu Apr 26, 2007 7:56 am    Post subject: Some assembly required again :) --Wide PosEx Reply with quote



This is from fastCode project. It's fast.

Could it also be turned into using WideStrings, please.

function PosEx_EWC_IA32_2_b(const ASearchString, AText: String; AOffset:
Integer = 1): Integer;
//Pattern = edi
//Source = esi
//SourceOffset/LoopVar = ecx
//PatternLength = edx
//Result = eax
asm
test eax, eax
jz @NotFound

test edx, edx
jz @NotFound

cmp ecx, 0
jle @NotFound

push esi
push edi
mov edi,eax

sub ecx, 1 //Make AOffset relative to zero
lea esi,[edx+ecx] //Load esi with starting addr of source String

mov eax,[edx-$04] //Get String Source Length
push eax
mov edx,[edi-$04] //Get String Pattern Length

test eax, eax
jz @NotFoundPop
test edx, edx
jz @NotFoundPop

//Calculate Number of Loops to execute
sub eax,ecx // Subtract the AOffset from the Length of the String
sub eax,edx // Backoff the Length of the Pattern
lea ecx,[eax+1] // Add 1 and move the result to the LoopVar

test ecx,ecx //If Pattern is longer than the remaining Source
jle @NotFoundPop // Pattern was not found.

mov al,[edi] //Get Pattern Character
jmp @BeginLoop

@NextSourceChar:
lea esi, [esi+1] //Advance to next Source character

@BeginLoop:
cmp al,[esi] //Compare to Source Character
jnz @NextSource //If no match, Break loop

@BeginPattern:
push edx //Save Pattern Length

@PatternLoop:
sub edx, 1 //Make Pattern Count an AOffset/Dec Loop Counter
jle @Found //If end of Pattern then must be found
mov ah, [edi+edx] //Get Pattern TNanoXMLChar
cmp ah, [esi+edx] //Compare to Source TNanoXMLChar
je @PatternLoop //if Pattern TNanoXMLChar Matches

pop edx //Restore Pattern Count if not found

@NextSource:
sub ecx, 1
jnz @NextSourceChar

@NotFoundPop:
pop eax
pop edi
pop esi
@NotFound:
xor eax, eax
jmp @Done

@Found:
pop edx
pop eax //Length of Source String
pop edi
pop esi

sub eax, ecx //Subtract Number of Iterations Left
sub eax, edx //Add the Length of the Pattern
lea eax,[eax+2]

@Done:
end;
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Language BASM All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.