1144847Salc/*
2144847Salc * Written by J.T. Conklin <jtc@acorntoolworks.com>
3144847Salc * Public domain.
4144847Salc */
5144847Salc
6144847Salc#include <machine/asm.h>
7144847Salc__FBSDID("$FreeBSD$");
8144847Salc
9144847Salc#if 0
10144847Salc	RCSID("$NetBSD: strcmp.S,v 1.3 2004/07/19 20:04:41 drochner Exp $")
11144847Salc#endif
12144847Salc
13144847SalcENTRY(strcmp)
14144847Salc	/*
15144847Salc	 * Align s1 to word boundary.
16144847Salc	 * Consider unrolling loop?
17144847Salc	 */
18144847Salc.Ls1align:
19144847Salc	testb	$7,%dil
20144847Salc	je	.Ls1aligned
21144847Salc	movb	(%rdi),%al
22144847Salc	incq	%rdi
23144847Salc	movb	(%rsi),%dl
24144847Salc	incq	%rsi
25144847Salc	testb	%al,%al
26144847Salc	je	.Ldone
27144847Salc	cmpb	%al,%dl
28144847Salc	je	.Ls1align
29144847Salc	jmp	.Ldone
30144847Salc
31144847Salc	/*
32144847Salc	 * Check whether s2 is aligned to a word boundry.  If it is, we
33144847Salc	 * can compare by words.  Otherwise we have to compare by bytes.
34144847Salc	 */
35144847Salc.Ls1aligned:
36144847Salc	testb	$7,%sil
37144847Salc	jne	.Lbyte_loop
38144847Salc
39144847Salc	movabsq	$0x0101010101010101,%r8
40144847Salc	subq	$8,%rdi
41144847Salc	movabsq	$0x8080808080808080,%r9
42144847Salc	subq	$8,%rsi
43144847Salc
44144847Salc	.align	4
45144847Salc.Lword_loop:
46144847Salc	movq	8(%rdi),%rax
47144847Salc	addq	$8,%rdi
48144847Salc	movq	8(%rsi),%rdx
49144847Salc	addq	$8,%rsi
50144847Salc	cmpq	%rax,%rdx
51144847Salc	jne	.Lbyte_loop
52144847Salc	subq	%r8,%rdx
53144847Salc	notq	%rax
54144847Salc	andq	%rax,%rdx
55144847Salc	testq	%r9,%rdx
56144847Salc	je	.Lword_loop
57144847Salc
58144847Salc	.align	4
59144847Salc.Lbyte_loop:
60144847Salc	movb	(%rdi),%al
61144847Salc	incq	%rdi
62144847Salc	movb	(%rsi),%dl
63144847Salc	incq	%rsi
64144847Salc	testb	%al,%al
65144847Salc	je	.Ldone
66144847Salc	cmpb	%al,%dl
67144847Salc	je	.Lbyte_loop
68144847Salc
69144847Salc.Ldone:
70144847Salc	movzbq	%al,%rax
71144847Salc	movzbq	%dl,%rdx
72144847Salc	subq	%rdx,%rax
73144847Salc	ret
74184547SpeterEND(strcmp)
75217106Skib
76217106Skib	.section .note.GNU-stack,"",%progbits
77