xref: /linux/arch/sparc/lib/strlen.S (revision ca55b2fef3a9373fcfc30f82fd26bc7fccbda732)
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,2008 David S. Miller (davem@davemloft.net)
5 * Copyright (C) 1996, 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
6 */
7
8#include <linux/linkage.h>
9#include <asm/asm.h>
10
11#define LO_MAGIC 0x01010101
12#define HI_MAGIC 0x80808080
13
14	.text
15ENTRY(strlen)
16	mov	%o0, %o1
17	andcc	%o0, 3, %g0
18	BRANCH32(be, pt, 9f)
19	 sethi	%hi(HI_MAGIC), %o4
20	ldub	[%o0], %o5
21	BRANCH_REG_ZERO(pn, %o5, 11f)
22	 add	%o0, 1, %o0
23	andcc	%o0, 3, %g0
24	BRANCH32(be, pn, 4f)
25	 or	%o4, %lo(HI_MAGIC), %o3
26	ldub	[%o0], %o5
27	BRANCH_REG_ZERO(pn, %o5, 12f)
28	 add	%o0, 1, %o0
29	andcc	%o0, 3, %g0
30	BRANCH32(be, pt, 5f)
31	 sethi	%hi(LO_MAGIC), %o4
32	ldub	[%o0], %o5
33	BRANCH_REG_ZERO(pn, %o5, 13f)
34	 add	%o0, 1, %o0
35	BRANCH32(ba, pt, 8f)
36	 or	%o4, %lo(LO_MAGIC), %o2
379:
38	or	%o4, %lo(HI_MAGIC), %o3
394:
40	sethi	%hi(LO_MAGIC), %o4
415:
42	or	%o4, %lo(LO_MAGIC), %o2
438:
44	ld	[%o0], %o5
452:
46	sub	%o5, %o2, %o4
47	andcc	%o4, %o3, %g0
48	BRANCH32(be, pt, 8b)
49	 add	%o0, 4, %o0
50
51	/* Check every byte. */
52	srl	%o5, 24, %g7
53	andcc	%g7, 0xff, %g0
54	BRANCH32(be, pn, 1f)
55	 add	%o0, -4, %o4
56	srl	%o5, 16, %g7
57	andcc	%g7, 0xff, %g0
58	BRANCH32(be, pn, 1f)
59	 add	%o4, 1, %o4
60	srl	%o5, 8, %g7
61	andcc	%g7, 0xff, %g0
62	BRANCH32(be, pn, 1f)
63	 add	%o4, 1, %o4
64	andcc	%o5, 0xff, %g0
65	BRANCH32_ANNUL(bne, pt, 2b)
66	 ld	[%o0], %o5
67	add	%o4, 1, %o4
681:
69	retl
70	 sub	%o4, %o1, %o0
7111:
72	retl
73	 mov	0, %o0
7412:
75	retl
76	 mov	1, %o0
7713:
78	retl
79	 mov	2, %o0
80ENDPROC(strlen)
81