xref: /openbsd-src/sys/lib/libkern/arch/amd64/strcmp.S (revision a28daedfc357b214be5c701aa8ba8adb29a7f1c2)
1/*
2 * Written by J.T. Conklin <jtc@netbsd.org>.
3 * Public domain.
4 * Adapted for NetBSD/x86_64 by Frank van der Linden <fvdl@wasabisystems.com>
5 */
6
7#include <machine/asm.h>
8
9/*
10 * NOTE: I've unrolled the loop eight times: large enough to make a
11 * significant difference, and small enough not to totally trash the
12 * cache.
13 */
14
15ENTRY(strcmp)
16	jmp	L2			/* Jump into the loop. */
17
18L1:	incq	%rdi
19	incq	%rsi
20L2:	movb	(%rdi),%cl
21	testb	%cl,%cl			/* null terminator */
22	jz	L3
23	cmpb	%cl,(%rsi)		/* chars match */
24	jne	L3
25
26	incq	%rdi
27	incq	%rsi
28	movb	(%rdi),%cl
29	testb	%cl,%cl
30	jz	L3
31	cmpb	%cl,(%rsi)
32	jne	L3
33
34	incq	%rdi
35	incq	%rsi
36	movb	(%rdi),%cl
37	testb	%cl,%cl
38	jz	L3
39	cmpb	%cl,(%rsi)
40	jne	L3
41
42	incq	%rdi
43	incq	%rsi
44	movb	(%rdi),%cl
45	testb	%cl,%cl
46	jz	L3
47	cmpb	%cl,(%rsi)
48	jne	L3
49
50	incq	%rdi
51	incq	%rsi
52	movb	(%rdi),%cl
53	testb	%cl,%cl
54	jz	L3
55	cmpb	%cl,(%rsi)
56	jne	L3
57
58	incq	%rdi
59	incq	%rsi
60	movb	(%rdi),%cl
61	testb	%cl,%cl
62	jz	L3
63	cmpb	%cl,(%rsi)
64	jne	L3
65
66	incq	%rdi
67	incq	%rsi
68	movb	(%rdi),%cl
69	testb	%cl,%cl
70	jz	L3
71	cmpb	%cl,(%rsi)
72	jne	L3
73
74	incq	%rdi
75	incq	%rsi
76	movb	(%rdi),%cl
77	testb	%cl,%cl
78	jz	L3
79	cmpb	%cl,(%rsi)
80	je	L1
81L3:	movzbl	(%rdi),%eax		/* unsigned comparison */
82	movzbl	(%rsi),%edx
83	subl	%edx,%eax
84	ret
85