OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libc/] [machine/] [i960/] [strlen.S] - Blame information for rev 816

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
/*******************************************************************************
2
 *
3
 * Copyright (c) 1993 Intel Corporation
4
 *
5
 * Intel hereby grants you permission to copy, modify, and distribute this
6
 * software and its documentation.  Intel grants this permission provided
7
 * that the above copyright notice appears in all copies and that both the
8
 * copyright notice and this permission notice appear in supporting
9
 * documentation.  In addition, Intel grants this permission provided that
10
 * you prominently mark as "not part of the original" any modifications
11
 * made to this software or documentation, and that the name of Intel
12
 * Corporation not be used in advertising or publicity pertaining to
13
 * distribution of the software or the documentation without specific,
14
 * written prior permission.
15
 *
16
 * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR
17
 * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY
18
 * OR FITNESS FOR A PARTICULAR PURPOSE.  Intel makes no guarantee or
19
 * representations regarding the use of, or the results of the use of,
20
 * the software and documentation in terms of correctness, accuracy,
21
 * reliability, currentness, or otherwise; and you rely on the software,
22
 * documentation and results solely at your own risk.
23
 *
24
 * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS,
25
 * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES
26
 * OF ANY KIND.  IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM
27
 * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER.
28
 *
29
 ******************************************************************************/
30
 
31
        .file "strlen.s"
32
#ifdef  __PIC
33
        .pic
34
#endif
35
#ifdef  __PID
36
        .pid
37
#endif
38
 
39
/*
40
 * (c) copyright 1988,1993 Intel Corp., all rights reserved
41
 */
42
 
43
/*
44
        procedure strlen  (optimized assembler version for the 80960K series)
45
 
46
        src_addr = strlen (src_addr)
47
 
48
        return the number of bytes that precede the null byte in the
49
        string pointed to by src_addr.
50
 
51
        Undefined behavior will occur if the end of the source string (i.e.
52
        the terminating null byte) is in the last four words of the program's
53
        allocated memory space.  This is so because strlen fetches ahead
54
        several words.  Disallowing the fetch ahead would impose a severe
55
        performance penalty.
56
 
57
        Strategy:
58
 
59
        Fetch the source array by long-words and scanbyte the words for the
60
        null byte until found.  Examine the word in which the null byte is
61
        found, to determine its actual position, and return the length.
62
 
63
        Tactics:
64
 
65
        1) Do NOT try to fetch the words in a word aligned manner because,
66
        in my judgement, the performance degradation experienced due to
67
        non-aligned accesses does NOT outweigh the time and complexity added
68
        by the preamble that would be necessary to assure alignment.  This
69
        is supported by the intuition that many source strings will be word
70
        aligned to begin with.
71
*/
72
 
73
        .globl  _strlen
74
        .globl  __strlen
75
        .leafproc       _strlen, __strlen
76
        .align  2
77
_strlen:
78
#ifndef __PIC
79
        lda     Lrett,g14
80
#else
81
        lda     Lrett-(.+8)(ip),g14
82
#endif
83
__strlen:
84
 
85
        mov     g14,g13         # preserve return address
86
        ldl     (g0),g4         # fetch first two words
87
        addo    8,g0,g2         # post-increment src word pointer
88
        lda     0xff,g3         # byte extraction mask
89
 
90
 
91
Lsearch_for_word_with_null_byte:
92
        scanbyte 0,g4           # check for null byte
93
        mov     g5,g7           # copy second word
94
        bo.f    Lsearch_for_null        # branch if null found
95
        scanbyte 0,g7           # check for null byte
96
        ldl     (g2),g4         # fetch next pair of word of src
97
        addo    8,g2,g2         # post-increment src word pointer
98
        bno     Lsearch_for_word_with_null_byte # branch if null not found yet
99
 
100
        subo    4,g2,g2         # back up the byte pointer
101
        mov     g7,g4           # move word with null to search word
102
Lsearch_for_null:
103
        subo    9,g2,g2         # back up the byte pointer
104
Lsearch_for_null.a:
105
        and     g4,g3,g14       # extract byte
106
        cmpo    0,g14           # is it null?
107
        addo    1,g2,g2         # bump src byte ptr
108
        shro    8,g4,g4         # shift word to position next byte
109
        bne     Lsearch_for_null.a
110
 
111
Lexit_code:
112
        subo    g0,g2,g0        # calculate string length
113
        bx      (g13)           # g0 = addr of src;  g14 = 0
114
Lrett:
115
        ret
116
 
117
/* end of strlen */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.