1/*
2 * ====================================================
3 * Copyright (C) 1998, 2002, 2008 by Red Hat Inc. All rights reserved.
4 *
5 * Permission to use, copy, modify, and distribute this
6 * software is freely granted, provided that this notice
7 * is preserved.
8 * ====================================================
9 */
10
11	#include "i386mach.h"
12
13	.global SYM (strlen)
14       SOTYPE_FUNCTION(strlen)
15
16SYM (strlen):
17
18	pushl ebp
19	movl esp,ebp
20	pushl edi
21#ifdef __iamcu__
22	movl eax,edx
23#else
24	movl 8(ebp),edx
25#endif
26
27#if defined __OPTIMIZE_SIZE__ || defined __iamcu__
28	cld
29	movl edx,edi
30	movl $4294967295,ecx
31	xor eax,eax
32	repnz
33	scasb
34#else
35/* Modern x86 hardware is much faster at double-word
36   manipulation than with bytewise repnz scasb.  */
37
38/* Do byte-wise checks until string is aligned.  */
39	movl edx,edi
40	test $3,edi
41	je L5
42	movb (edi),cl
43	incl edi
44	testb cl,cl
45	je L15
46
47	test $3,edi
48	je L5
49	movb (edi),cl
50	incl edi
51	testb cl,cl
52	je L15
53
54	test $3,edi
55	je L5
56	movb (edi),cl
57	incl edi
58	testb cl,cl
59	je L15
60
61L5:
62	subl $4,edi
63
64/* loop performing 4 byte mask checking for desired 0 byte */
65	.p2align 4,,7
66L10:
67	addl $4,edi
68	movl (edi),ecx
69	leal -16843009(ecx),eax
70	notl ecx
71	andl ecx,eax
72	testl $-2139062144,eax
73	je L10
74
75/* Find which of four bytes is 0.  */
76	notl ecx
77	incl edi
78
79	testb cl,cl
80	je L15
81	incl edi
82	shrl $8,ecx
83
84	testb cl,cl
85	je L15
86	incl edi
87	shrl $8,ecx
88
89	testb cl,cl
90	je L15
91	incl edi
92
93#endif
94
95L15:
96	subl edx,edi
97	leal -1(edi),eax
98
99	leal -4(ebp),esp
100	popl edi
101	leave
102	ret
103
104#if defined(__linux__) && defined(__ELF__)
105.section .note.GNU-stack,"",%progbits
106#endif
107