blob: 536f83507fbff1dc669f998f5e6b7336812225a5 [file] [log] [blame]
David S. Millerae984d72008-12-09 01:07:09 -08001/* strlen.S: Sparc optimized strlen code
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Hand optimized from GNU libc's strlen
3 * Copyright (C) 1991,1996 Free Software Foundation
David S. Millerae984d72008-12-09 01:07:09 -08004 * Copyright (C) 1996,2008 David S. Miller (davem@davemloft.net)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Copyright (C) 1996, 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
6 */
7
David S. Millerae984d72008-12-09 01:07:09 -08008#include <linux/linkage.h>
9#include <asm/asm.h>
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#define LO_MAGIC 0x01010101
12#define HI_MAGIC 0x80808080
13
David S. Millerae984d72008-12-09 01:07:09 -080014 .text
15ENTRY(strlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 mov %o0, %o1
17 andcc %o0, 3, %g0
David S. Millerae984d72008-12-09 01:07:09 -080018 BRANCH32(be, pt, 9f)
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 sethi %hi(HI_MAGIC), %o4
20 ldub [%o0], %o5
David S. Millerae984d72008-12-09 01:07:09 -080021 BRANCH_REG_ZERO(pn, %o5, 11f)
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 add %o0, 1, %o0
23 andcc %o0, 3, %g0
David S. Millerae984d72008-12-09 01:07:09 -080024 BRANCH32(be, pn, 4f)
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 or %o4, %lo(HI_MAGIC), %o3
26 ldub [%o0], %o5
David S. Millerae984d72008-12-09 01:07:09 -080027 BRANCH_REG_ZERO(pn, %o5, 12f)
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 add %o0, 1, %o0
29 andcc %o0, 3, %g0
David S. Millerae984d72008-12-09 01:07:09 -080030 BRANCH32(be, pt, 5f)
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 sethi %hi(LO_MAGIC), %o4
32 ldub [%o0], %o5
David S. Millerae984d72008-12-09 01:07:09 -080033 BRANCH_REG_ZERO(pn, %o5, 13f)
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 add %o0, 1, %o0
David S. Millerae984d72008-12-09 01:07:09 -080035 BRANCH32(ba, pt, 8f)
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 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
David S. Millerae984d72008-12-09 01:07:09 -080048 BRANCH32(be, pt, 8b)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 add %o0, 4, %o0
50
51 /* Check every byte. */
52 srl %o5, 24, %g7
53 andcc %g7, 0xff, %g0
David S. Millerae984d72008-12-09 01:07:09 -080054 BRANCH32(be, pn, 1f)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 add %o0, -4, %o4
56 srl %o5, 16, %g7
57 andcc %g7, 0xff, %g0
David S. Millerae984d72008-12-09 01:07:09 -080058 BRANCH32(be, pn, 1f)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 add %o4, 1, %o4
60 srl %o5, 8, %g7
61 andcc %g7, 0xff, %g0
David S. Millerae984d72008-12-09 01:07:09 -080062 BRANCH32(be, pn, 1f)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 add %o4, 1, %o4
64 andcc %o5, 0xff, %g0
David S. Millerae984d72008-12-09 01:07:09 -080065 BRANCH32_ANNUL(bne, pt, 2b)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 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
David S. Millerae984d72008-12-09 01:07:09 -080080ENDPROC(strlen)