xref: /freebsd/lib/libc/amd64/string/strcmp.S (revision 3416500aef140042c64bc149cb1ec6620483bc44)
1/*
2 * Written by J.T. Conklin <jtc@acorntoolworks.com>
3 * Public domain.
4 */
5
6#include <machine/asm.h>
7__FBSDID("$FreeBSD$");
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 boundary.  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)
75
76	.section .note.GNU-stack,"",%progbits
77