xref: /freebsd/lib/libc/amd64/string/bcmp.S (revision b9f654b163bce26de79705e77b872427c9f2afa1)
1/*-
2 * Copyright (c) 2018 The FreeBSD Foundation
3 *
4 * This software was developed by Mateusz Guzik <mjg@FreeBSD.org>
5 * under sponsorship from the FreeBSD Foundation.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
28 * $FreeBSD$
29 */
30
31#include <machine/asm.h>
32__FBSDID("$FreeBSD$");
33
34ENTRY(bcmp)
35	cmpq	$16,%rdx
36	jae	5f
371:
38	testq	%rdx,%rdx
39	je	3f
40	xorl	%ecx,%ecx
412:
42	movzbl	(%rdi,%rcx,1),%eax
43	movzbl	(%rsi,%rcx,1),%r8d
44	cmpb	%r8b,%al
45	jne	4f
46	addq	$1,%rcx
47	cmpq	%rcx,%rdx
48	jz	3f
49	movzbl	(%rdi,%rcx,1),%eax
50	movzbl	(%rsi,%rcx,1),%r8d
51	cmpb	%r8b,%al
52	jne	4f
53	addq	$1,%rcx
54	cmpq	%rcx,%rdx
55	jz	3f
56	movzbl	(%rdi,%rcx,1),%eax
57	movzbl	(%rsi,%rcx,1),%r8d
58	cmpb	%r8b,%al
59	jne	4f
60	addq	$1,%rcx
61	cmpq	%rcx,%rdx
62	jz	3f
63	movzbl	(%rdi,%rcx,1),%eax
64	movzbl	(%rsi,%rcx,1),%r8d
65	cmpb	%r8b,%al
66	jne	4f
67	addq	$1,%rcx
68	cmpq	%rcx,%rdx
69	jne	2b
703:
71	xorl	%eax,%eax
72	ret
734:
74	movl	$1,%eax
75	ret
765:
77	cmpq	$32,%rdx
78	jae	7f
796:
80	/*
81	 * 8 bytes
82	 */
83	movq	(%rdi),%r8
84	movq	(%rsi),%r9
85	cmpq	%r8,%r9
86	jne	4b
87	leaq	8(%rdi),%rdi
88	leaq	8(%rsi),%rsi
89	subq	$8,%rdx
90	cmpq	$8,%rdx
91	jae	6b
92	jl	1b
93	jmp	3b
947:
95	/*
96	 * 32 bytes
97	 */
98	movq	(%rsi),%r8
99	movq	8(%rsi),%r9
100	subq	(%rdi),%r8
101	subq	8(%rdi),%r9
102	or	%r8,%r9
103	jnz	4b
104
105	movq	16(%rsi),%r8
106	movq	24(%rsi),%r9
107	subq	16(%rdi),%r8
108	subq	24(%rdi),%r9
109	or	%r8,%r9
110	jnz	4b
111
112	leaq	32(%rdi),%rdi
113	leaq	32(%rsi),%rsi
114	subq	$32,%rdx
115	cmpq	$32,%rdx
116	jae	7b
117	jnz	1b
118	jmp	3b
119END(bcmp)
120
121	.section .note.GNU-stack,"",%progbits
122