1{
2    This file is part of the Free Pascal run time library.
3    Copyright (c) 2003 by Florian Klaempfl, member of the
4    Free Pascal development team
5
6    Processor dependent part of strings.pp, that can be shared with
7    sysutils unit.
8
9    See the file COPYING.FPC, included in this distribution,
10    for details about the copyright.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
16 **********************************************************************}
17
18{$ASMMODE GAS}
19
20{$ifndef FPC_UNIT_HAS_STRCOMP}
21{$define FPC_UNIT_HAS_STRCOMP}
22function StrComp(Str1, Str2: PChar): SizeInt;assembler;nostackframe;
23asm
24{$ifndef win64}
25        movq   %rsi,%rdx
26        movq   %rdi,%rcx
27{$endif win64}
28        subq   %rcx,%rdx
29.balign 16
30.Lloop:                          { unrolled 4 times }
31        movb   (%rcx),%al
32        cmpb   (%rdx,%rcx),%al
33        jne    .Ldiff
34        testb  %al,%al
35        jz    .Leq
36        movb   1(%rcx),%al
37        cmpb   1(%rdx,%rcx),%al
38        jne    .Ldiff
39        testb  %al,%al
40        jz     .Leq
41        movb   2(%rcx),%al
42        cmpb   2(%rdx,%rcx),%al
43        jne    .Ldiff
44        testb  %al,%al
45        jz     .Leq
46        movb   3(%rcx),%al
47        add    $4,%rcx
48        cmpb   -1(%rdx,%rcx),%al
49        jne    .Ldiff
50        testb  %al,%al
51        jnz    .Lloop
52.Leq:
53        xorq   %rax,%rax
54        jmp    .Lexit
55
56.Ldiff:
57        sbbq   %rax,%rax        { -1 if CF was set, 0 otherwise }
58        orb    $1,%al           { 0 becomes 1, -1 remains unchanged }
59.Lexit:
60end;
61{$endif FPC_UNIT_HAS_STRCOMP}
62