Deleted Added
full compact
strcmp.S (144847) strcmp.S (184547)
1/*
2 * Written by J.T. Conklin <jtc@acorntoolworks.com>
3 * Public domain.
4 */
5
6#include <machine/asm.h>
1/*
2 * Written by J.T. Conklin <jtc@acorntoolworks.com>
3 * Public domain.
4 */
5
6#include <machine/asm.h>
7__FBSDID("$FreeBSD: head/lib/libc/amd64/string/strcmp.S 144847 2005-04-09 20:47:08Z alc $");
7__FBSDID("$FreeBSD: head/lib/libc/amd64/string/strcmp.S 184547 2008-11-02 01:10:54Z peter $");
8
9#if 0
10 RCSID("$NetBSD: strcmp.S,v 1.3 2004/07/19 20:04:41 drochner Exp $")
11#endif
12
13ENTRY(strcmp)
14 /*
15 * Align s1 to word boundary.
16 * Consider unrolling loop?
17 */
18.Ls1align:
19 testb $7,%dil
20 je .Ls1aligned
21 movb (%rdi),%al
22 incq %rdi
23 movb (%rsi),%dl
24 incq %rsi
25 testb %al,%al
26 je .Ldone
27 cmpb %al,%dl
28 je .Ls1align
29 jmp .Ldone
30
31 /*
32 * Check whether s2 is aligned to a word boundry. If it is, we
33 * can compare by words. Otherwise we have to compare by bytes.
34 */
35.Ls1aligned:
36 testb $7,%sil
37 jne .Lbyte_loop
38
39 movabsq $0x0101010101010101,%r8
40 subq $8,%rdi
41 movabsq $0x8080808080808080,%r9
42 subq $8,%rsi
43
44 .align 4
45.Lword_loop:
46 movq 8(%rdi),%rax
47 addq $8,%rdi
48 movq 8(%rsi),%rdx
49 addq $8,%rsi
50 cmpq %rax,%rdx
51 jne .Lbyte_loop
52 subq %r8,%rdx
53 notq %rax
54 andq %rax,%rdx
55 testq %r9,%rdx
56 je .Lword_loop
57
58 .align 4
59.Lbyte_loop:
60 movb (%rdi),%al
61 incq %rdi
62 movb (%rsi),%dl
63 incq %rsi
64 testb %al,%al
65 je .Ldone
66 cmpb %al,%dl
67 je .Lbyte_loop
68
69.Ldone:
70 movzbq %al,%rax
71 movzbq %dl,%rdx
72 subq %rdx,%rax
73 ret
8
9#if 0
10 RCSID("$NetBSD: strcmp.S,v 1.3 2004/07/19 20:04:41 drochner Exp $")
11#endif
12
13ENTRY(strcmp)
14 /*
15 * Align s1 to word boundary.
16 * Consider unrolling loop?
17 */
18.Ls1align:
19 testb $7,%dil
20 je .Ls1aligned
21 movb (%rdi),%al
22 incq %rdi
23 movb (%rsi),%dl
24 incq %rsi
25 testb %al,%al
26 je .Ldone
27 cmpb %al,%dl
28 je .Ls1align
29 jmp .Ldone
30
31 /*
32 * Check whether s2 is aligned to a word boundry. If it is, we
33 * can compare by words. Otherwise we have to compare by bytes.
34 */
35.Ls1aligned:
36 testb $7,%sil
37 jne .Lbyte_loop
38
39 movabsq $0x0101010101010101,%r8
40 subq $8,%rdi
41 movabsq $0x8080808080808080,%r9
42 subq $8,%rsi
43
44 .align 4
45.Lword_loop:
46 movq 8(%rdi),%rax
47 addq $8,%rdi
48 movq 8(%rsi),%rdx
49 addq $8,%rsi
50 cmpq %rax,%rdx
51 jne .Lbyte_loop
52 subq %r8,%rdx
53 notq %rax
54 andq %rax,%rdx
55 testq %r9,%rdx
56 je .Lword_loop
57
58 .align 4
59.Lbyte_loop:
60 movb (%rdi),%al
61 incq %rdi
62 movb (%rsi),%dl
63 incq %rsi
64 testb %al,%al
65 je .Ldone
66 cmpb %al,%dl
67 je .Lbyte_loop
68
69.Ldone:
70 movzbq %al,%rax
71 movzbq %dl,%rdx
72 subq %rdx,%rax
73 ret
74END(strcmp)