blob: 1ccecc17b94f7f54ed442daa68f7d862254202ff [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/* $Id: strlen.S,v 1.2 2001/06/29 14:07:15 gniibe Exp $
2 *
3 * "strlen" implementation of SuperH
4 *
5 * Copyright (C) 1999 Kaz Kojima
6 *
7 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
8 */
9
10/* size_t strlen (const char *s) */
11
12#include <sysdep.h>
13#include <endian.h>
14
15ENTRY(strlen)
16 mov r4,r0
17 and #3,r0
18 tst r0,r0
19 bt/s 1f
20 mov #0,r2
21
22 add #-1,r0
23 shll2 r0
24 shll r0
25 braf r0
26 nop
27
28 mov.b @r4+,r1
29 tst r1,r1
30 bt 8f
31 add #1,r2
32
33 mov.b @r4+,r1
34 tst r1,r1
35 bt 8f
36 add #1,r2
37
38 mov.b @r4+,r1
39 tst r1,r1
40 bt 8f
41 add #1,r2
42
431:
44 mov #0,r3
452:
46 mov.l @r4+,r1
47 cmp/str r3,r1
48 bf/s 2b
49 add #4,r2
50
51 add #-4,r2
52#ifndef __LITTLE_ENDIAN__
53 swap.b r1,r1
54 swap.w r1,r1
55 swap.b r1,r1
56#endif
57 extu.b r1,r0
58 tst r0,r0
59 bt/s 8f
60 shlr8 r1
61 add #1,r2
62 extu.b r1,r0
63 tst r0,r0
64 bt/s 8f
65 shlr8 r1
66 add #1,r2
67 extu.b r1,r0
68 tst r0,r0
69 bt 8f
70 add #1,r2
718:
72 rts
73 mov r2,r0
74END(strlen)
75libc_hidden_def (strlen)