unit FastcodePosExUnit; (* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is Fastcode * * The Initial Developer of the Original Code is Fastcode * * Portions created by the Initial Developer are Copyright (C) 2002-2004 * the Initial Developer. All Rights Reserved. * * Contributor(s): Aleksandr Sharahov * * ***** END LICENSE BLOCK ***** *) //Version : 0.1 //Only plain function calls supported //Last update 24/5 2005 interface function PosExFastcodeP4P(const SubStr, S: string; Offset: Integer = 1): Integer; function PosExFastcodeP4N(const SubStr, S: string; Offset: Integer = 1): Integer; function PosExFastcodePMD(const SubStr, S: string; Offset: Integer = 1): Integer; function PosExFastcodePMB(const SubStr, S: string; Offset: Integer = 1): Integer; function PosExFastcodeAMD64(const SubStr, S: string; Offset: Integer = 1): Integer; function PosExFastcodeXP(const SubStr, S: string; Offset: Integer = 1): Integer; function PosExFastcodeBlended(const SubStr, S: string; Offset: Integer = 1): Integer; function PosExFastcodeRTL(const SubStr, S: string; Offset: Integer = 1): Integer; function PosExFastcodePascal(const SubStr, S: string; Offset: Integer = 1): Integer; implementation //Author: Aleksandr Sharahov //Date: 25/5 2004 //Optimized for: Intel P4 Prescott //Instructionset(s): IA32 //Original name: PosEx_Sha_IA32_3 function PosExFastcodeP4P(const SubStr, S: string; Offset: Integer = 1): Integer; asm test eax, eax jz @Nil test edx, edx jz @Nil dec ecx jl @Nil push esi push ebx mov esi, [edx-4] //Length(Str) mov ebx, [eax-4] //Length(Substr) sub esi, ecx //effective length of Str add edx, ecx //addr of the first char at starting position cmp esi, ebx jl @Past //jump if EffectiveLength(Str)0 then repeat; if (psub[len]<>p[len+1]) or (psub[len+1]<>p[len+2]) then goto AfterTestT; len:=len+2; until len>=0; p:=p+2; if p<=pStop then goto Ret; Result:=0; goto Exit; Test4: p:=p-2; Test2: p:=p-2; Test0: len:=lenSub; if lenSub<>0 then repeat; if (psub[len]<>p[len]) or (psub[len+1]<>p[len+1]) then goto AfterTest0; len:=len+2; until len>=0; inc(p); Ret: Result:=p-pStart; Exit: end; end.