yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame^] | 1 | /* vi: set sw=8 ts=8: */ |
| 2 | /* |
| 3 | * libc/string/sh64/strlen.S |
| 4 | * |
| 5 | * Simplistic strlen() implementation for SHmedia. |
| 6 | * |
| 7 | * Copyright (C) 2003 Paul Mundt <lethal@linux-sh.org> |
| 8 | * |
| 9 | * All rights reserved. |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or without |
| 12 | * modification, are permitted provided that the following conditions |
| 13 | * are met: |
| 14 | * 1. Redistributions of source code must retain the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer. |
| 16 | * 2. The name of the above contributors may not be |
| 17 | * used to endorse or promote products derived from this software |
| 18 | * without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND |
| 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE |
| 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 30 | * SUCH DAMAGE. |
| 31 | */ |
| 32 | |
| 33 | #include <features.h> |
| 34 | |
| 35 | .section .text..SHmedia32,"ax" |
| 36 | .globl strlen |
| 37 | .type strlen,@function |
| 38 | |
| 39 | .balign 16 |
| 40 | strlen: |
| 41 | ptabs r18, tr4 |
| 42 | |
| 43 | /* |
| 44 | * Note: We could easily deal with the NULL case here with a simple |
| 45 | * sanity check, though it seems that the behavior we want is to fault |
| 46 | * in the event that r2 == NULL, so we don't bother. |
| 47 | */ |
| 48 | /* beqi r2, 0, tr4 */ ! Sanity check |
| 49 | |
| 50 | movi -1, r0 |
| 51 | pta/l loop, tr0 |
| 52 | loop: |
| 53 | ld.b r2, 0, r1 |
| 54 | addi r2, 1, r2 |
| 55 | addi r0, 1, r0 |
| 56 | bnei/l r1, 0, tr0 |
| 57 | |
| 58 | or r0, r63, r2 |
| 59 | blink tr4, r63 |
| 60 | |
| 61 | .size strlen,.-strlen |
| 62 | |
| 63 | libc_hidden_def(strlen) |