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