-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFastcodeStrCompUnit.pas
261 lines (243 loc) · 5.83 KB
/
FastcodeStrCompUnit.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
unit FastcodeStrCompUnit;
(* ***** 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-2005
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Charalabos Michael <[email protected]>
* John O'Harrow <[email protected]>
* Aleksandr Sharahov
*
* BV Version: 2.70
* ***** END LICENSE BLOCK ***** *)
interface
{$I Fastcode.inc}
type
FastcodeStrCompFunction = function(const Str1, Str2: PChar): Integer;
{Functions shared between Targets}
function StrComp_Sha_IA32_7(const Str1, Str2: PChar): Integer;
function StrComp_JOH_IA32_6(const Str1, Str2: PChar): Integer;
function StrComp_JOH_IA32_5(const Str1, Str2: PChar): Integer;
{Functions not shared between Targets}
function StrComp_Sha_Pas_4(const str1, str2: pchar): integer;
function StrComp_Sha_Pas_5(const str1, str2: pchar): integer;
{Functions}
const
FastcodeStrCompP4R: FastcodeStrCompFunction = StrComp_JOH_IA32_6;
FastcodeStrCompP4N: FastcodeStrCompFunction = StrComp_Sha_IA32_7;
FastcodeStrCompPMY: FastcodeStrCompFunction = StrComp_Sha_IA32_7;
FastcodeStrCompPMD: FastcodeStrCompFunction = StrComp_Sha_IA32_7;
FastCodeStrCompIA32SizePenalty: FastCodeStrCompFunction = StrComp_JOH_IA32_5;
FastcodeStrCompIA32: FastcodeStrCompFunction = StrComp_Sha_IA32_7;
FastcodeStrCompMMX: FastcodeStrCompFunction = StrComp_Sha_IA32_7;
FastCodeStrCompSSESizePenalty: FastCodeStrCompFunction = StrComp_JOH_IA32_5;
FastcodeStrCompSSE: FastcodeStrCompFunction = StrComp_Sha_IA32_7;
FastcodeStrCompSSE2: FastcodeStrCompFunction = StrComp_Sha_IA32_7;
FastcodeStrCompAMD64: FastcodeStrCompFunction = StrComp_JOH_IA32_6;
FastcodeStrCompAMD64_SSE3: FastcodeStrCompFunction = StrComp_JOH_IA32_6;
FastCodeStrCompPascalSizePenalty: FastCodeStrCompFunction = StrComp_Sha_Pas_4;
FastCodeStrCompPascal: FastCodeStrCompFunction = StrComp_Sha_Pas_5;
procedure StrCompStub;
implementation
uses
SysUtils;
function StrComp_JOH_IA32_6(const Str1, Str2: PChar): Integer;
asm
sub eax, edx
mov ecx, eax
jz @@Exit
@@Loop:
movzx eax, [ecx+edx]
cmp al, [edx]
jne @@SetResult
test al, al
jz @@Exit
movzx eax, [ecx+edx+1]
cmp al, [edx+1]
jne @@SetResult
test al, al
jz @@Exit
movzx eax, [ecx+edx+2]
cmp al, [edx+2]
jne @@SetResult
test al, al
jz @@Exit
movzx eax, [ecx+edx+3]
cmp al, [edx+3]
jne @@SetResult
test al, al
jz @@Exit
movzx eax, [ecx+edx+4]
cmp al, [edx+4]
jne @@SetResult
test al, al
jz @@Exit
movzx eax, [ecx+edx+5]
cmp al, [edx+5]
jne @@SetResult
test al, al
jz @@Exit
movzx eax, [ecx+edx+6]
cmp al, [edx+6]
jne @@SetResult
test al, al
jz @@Exit
movzx eax, [ecx+edx+7]
cmp al, [edx+7]
jne @@SetResult
add edx, 8
test al, al
jnz @@Loop
ret
@@SetResult:
sbb eax, eax
or al, 1
@@Exit:
end;
function StrComp_Sha_IA32_7(const Str1, Str2: PChar): Integer;
asm
sub eax, edx
jz @ret
@loop:
movzx ecx, [eax+edx]
cmp cl, [edx]
jne @stop
test cl, cl
jz @eq
movzx ecx, [eax+edx+1]
cmp cl, [edx+1]
jne @stop1
test cl, cl
jz @eq
movzx ecx, [eax+edx+2]
cmp cl, [edx+2]
jne @stop2
test cl, cl
jz @eq
movzx ecx, [eax+edx+3]
cmp cl, [edx+3]
jne @stop3
add edx, 4
test cl, cl
jz @eq
movzx ecx, [eax+edx]
cmp cl, [edx]
jne @stop
test cl, cl
jz @eq
movzx ecx, [eax+edx+1]
cmp cl, [edx+1]
jne @stop1
test cl, cl
jz @eq
movzx ecx, [eax+edx+2]
cmp cl, [edx+2]
jne @stop2
test cl, cl
jz @eq
movzx ecx, [eax+edx+3]
cmp cl, [edx+3]
jne @stop3
add edx, 4
test cl, cl
jnz @loop
@eq:
xor eax, eax
@ret:
ret
@stop3:
add edx, 1
@stop2:
add edx, 1
@stop1:
add edx, 1
@stop:
mov eax, ecx
movzx edx, [edx]
sub eax, edx
end;
function StrComp_JOH_IA32_5(const Str1, Str2: PChar): Integer;
asm
sub eax, edx
jz @@Exit
@@Loop:
movzx ecx, [eax+edx]
cmp cl, [edx]
jne @@SetResult
inc edx
test cl, cl
jnz @@Loop
xor eax, eax
ret
@@SetResult:
sbb eax, eax
or al, 1
@@Exit:
end;
function StrComp_Sha_Pas_4(const str1, str2: pchar): integer;
var
dist: integer;
p: pchar;
label
make;
begin;
dist:=str1-str2;
p:=str2;
repeat;
Result:=shortint(p[dist]);
if (Result=0) or (chr(Result)<>p[0]) then goto make;
Result:=shortint(p[dist+1]);
inc(p,2);
until (Result=0) or (chr(Result)<>p[-1]);
dec(p);
make:
Result:=byte(Result)-byte(p[0]);
end;
function StrComp_Sha_Pas_5(const str1, str2: pchar): integer;
var
dist: integer;
p: pchar;
label
make, make1, make2;
begin;
dist:=str1-str2;
p:=str2;
repeat;
Result:=shortint(p[dist]);
if (Result=0) or (chr(Result)<>p[0]) then goto make;
Result:=shortint(p[dist+1]);
if (Result=0) or (chr(Result)<>p[1]) then goto make1;
Result:=shortint(p[dist+2]);
if (Result=0) or (chr(Result)<>p[2]) then goto make2;
Result:=shortint(p[dist+3]);
inc(p,4);
until (Result=0) or (chr(Result)<>p[-1]);
dec(p,3);
make2:
inc(p);
make1:
inc(p);
make:
Result:=byte(Result)-byte(p[0]);
end;
procedure StrCompStub;
asm
call SysUtils.StrComp;
end;
end.