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