1/* strlen.S: Sparc optimized strlen code
2 * Hand optimized from GNU libc's strlen
3 * Copyright (C) 1991,1996 Free Software Foundation
4 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1996 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
6 */
7
8#include <asm/cprefix.h>
9
10#define LO_MAGIC 0x01010101
11#define HI_MAGIC 0x80808080
12
130:
14	ldub	[%o0], %o5
15	cmp	%o5, 0
16	be	1f
17	 add	%o0, 1, %o0
18	andcc	%o0, 3, %g0
19	be	4f
20	 or	%o4, %lo(HI_MAGIC), %o3
21	ldub	[%o0], %o5
22	cmp	%o5, 0
23	be	2f
24	 add	%o0, 1, %o0
25	andcc	%o0, 3, %g0
26	be	5f
27	 sethi	%hi(LO_MAGIC), %o4
28	ldub	[%o0], %o5
29	cmp	%o5, 0
30	be	3f
31	 add	%o0, 1, %o0
32	b	8f
33	 or	%o4, %lo(LO_MAGIC), %o2
341:
35	retl
36	 mov	0, %o0
372:
38	retl
39	 mov	1, %o0
403:
41	retl
42	 mov	2, %o0
43
44	.align 4
45	.global C_LABEL(strlen)
46C_LABEL(strlen):
47	mov	%o0, %o1
48	andcc	%o0, 3, %g0
49	bne	0b
50	 sethi	%hi(HI_MAGIC), %o4
51	or	%o4, %lo(HI_MAGIC), %o3
524:
53	sethi	%hi(LO_MAGIC), %o4
545:
55	or	%o4, %lo(LO_MAGIC), %o2
568:
57	ld	[%o0], %o5
582:
59	sub	%o5, %o2, %o4
60	andcc	%o4, %o3, %g0
61	be	8b
62	 add	%o0, 4, %o0
63
64	/* Check every byte. */
65	srl	%o5, 24, %g5
66	andcc	%g5, 0xff, %g0
67	be	1f
68	 add	%o0, -4, %o4
69	srl	%o5, 16, %g5
70	andcc	%g5, 0xff, %g0
71	be	1f
72	 add	%o4, 1, %o4
73	srl	%o5, 8, %g5
74	andcc	%g5, 0xff, %g0
75	be	1f
76	 add	%o4, 1, %o4
77	andcc	%o5, 0xff, %g0
78	bne,a	2b
79	 ld	[%o0], %o5
80	add	%o4, 1, %o4
811:
82	retl
83	 sub	%o4, %o1, %o0
84