| xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 1 | /* Copyright (C) 1999-2016 Free Software Foundation, Inc. | 
|  | 2 | This file is part of the GNU C Library. | 
|  | 3 | Contributed by Kazumoto Kojima <kkojima@rr.iij4u.or.jp> | 
|  | 4 |  | 
|  | 5 | The GNU C Library is free software; you can redistribute it and/or | 
|  | 6 | modify it under the terms of the GNU Lesser General Public | 
|  | 7 | License as published by the Free Software Foundation; either | 
|  | 8 | version 2.1 of the License, or (at your option) any later version. | 
|  | 9 |  | 
|  | 10 | The GNU C Library is distributed in the hope that it will be useful, | 
|  | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
|  | 13 | Lesser General Public License for more details. | 
|  | 14 |  | 
|  | 15 | You should have received a copy of the GNU Lesser General Public | 
|  | 16 | License along with the GNU C Library; if not, see | 
|  | 17 | <http://www.gnu.org/licenses/>.  */ | 
|  | 18 |  | 
|  | 19 | #include <sysdep.h> | 
|  | 20 |  | 
|  | 21 | /* size_t strlen (const char *s)  */ | 
|  | 22 |  | 
|  | 23 | ENTRY(strlen) | 
|  | 24 | mov	r4, r0 | 
|  | 25 | and	#3, r0 | 
|  | 26 | tst	r0, r0 | 
|  | 27 | bt/s	1f | 
|  | 28 | mov	#0, r2 | 
|  | 29 |  | 
|  | 30 | add	#-1, r0 | 
|  | 31 | shll2	r0 | 
|  | 32 | shll	r0 | 
|  | 33 | braf	r0 | 
|  | 34 | nop | 
|  | 35 |  | 
|  | 36 | mov.b	@r4+, r1 | 
|  | 37 | tst	r1, r1 | 
|  | 38 | bt	8f | 
|  | 39 | add	#1, r2 | 
|  | 40 |  | 
|  | 41 | mov.b	@r4+, r1 | 
|  | 42 | tst	r1, r1 | 
|  | 43 | bt	8f | 
|  | 44 | add	#1, r2 | 
|  | 45 |  | 
|  | 46 | mov.b	@r4+, r1 | 
|  | 47 | tst	r1, r1 | 
|  | 48 | bt	8f | 
|  | 49 | add	#1, r2 | 
|  | 50 |  | 
|  | 51 | 1: | 
|  | 52 | mov	#0, r3 | 
|  | 53 | 2: | 
|  | 54 | mov.l	@r4+, r1 | 
|  | 55 | cmp/str	r3, r1 | 
|  | 56 | bf/s	2b | 
|  | 57 | add	#4, r2 | 
|  | 58 |  | 
|  | 59 | add	#-4, r2 | 
|  | 60 | #ifdef __BIG_ENDIAN__ | 
|  | 61 | swap.b	r1, r1 | 
|  | 62 | swap.w	r1, r1 | 
|  | 63 | swap.b	r1, r1 | 
|  | 64 | #endif | 
|  | 65 | extu.b	r1, r0 | 
|  | 66 | tst	r0, r0 | 
|  | 67 | bt/s	8f | 
|  | 68 | shlr8	r1 | 
|  | 69 | add	#1, r2 | 
|  | 70 | extu.b	r1, r0 | 
|  | 71 | tst	r0, r0 | 
|  | 72 | bt/s	8f | 
|  | 73 | shlr8	r1 | 
|  | 74 | add	#1, r2 | 
|  | 75 | extu.b	r1, r0 | 
|  | 76 | tst	r0, r0 | 
|  | 77 | bt	8f | 
|  | 78 | add	#1, r2 | 
|  | 79 | 8: | 
|  | 80 | rts | 
|  | 81 | mov	r2, r0 | 
|  | 82 | END(strlen) | 
|  | 83 | libc_hidden_builtin_def (strlen) |