source: trunk/libs/newlib/src/newlib/libc/machine/i960/strchr.S @ 444

Last change on this file since 444 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 4.3 KB
Line 
1/*******************************************************************************
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 "strchr.s"
32#ifdef  __PIC
33        .pic
34#endif
35#ifdef  __PID
36        .pid
37#endif
38/*
39 * (c) copyright 1988,1993 Intel Corp., all rights reserved
40 */
41
42/*
43        procedure strchr  (optimized assembler version for the 80960K series)
44
45        src_addr = strchr (src_addr, char)
46
47        return a pointer to the first byte that contains the indicated
48        byte in the source string.  Return null if the byte is not found.
49
50        Undefined behavior will occur if the end of the source string (i.e.
51        the terminating null byte) is in the last two words of the program's
52        allocated memory space.  This is so because strchr fetches ahead. 
53        Disallowing the fetch ahead would impose a severe performance penalty.
54
55        Strategy:
56
57        Fetch the source string by words and scanbyte the words for the
58        char until either a word with the byte is found or the null byte is
59        encountered.  In the former case, move through the word to find the
60        matching byte and return its memory address.  In the latter case,
61        return zero (null).
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 most source arrays (even more
70        true of most big source arrays) will be word aligned to begin with.
71*/
72
73        .globl  _strchr
74        .globl  __strchr
75        .leafproc       _strchr, __strchr
76        .align  2
77_strchr:
78#ifndef __PIC
79        lda     Lrett,g14
80#else
81        lda     Lrett-(.+8)(ip),g14
82#endif
83__strchr:
84
85        ld      (g0),g4         # fetch first word
86        lda     0xff,g7         # byte extraction mask
87        and     g1,g7,g1        # make char an 8-bit ordinal
88        shlo    8,g1,g2         # broadcast the char to four bytes
89        or      g1,g2,g2
90        shlo    16,g2,g5
91        or      g2,g5,g3
92        mov     g14,g13         # preserve return address
93        addo    4,g0,g0         # post-increment src pointer
94        mov     0,g14           # conform to register linkage standard
95
96Lsearch_for_word_with_char_or_null:
97        mov     g4,g5           # copy word
98        scanbyte g3,g5          # check for byte with char
99        ld      (g0),g4         # fetch next word of src
100        bo      Lsearch_for_char        # branch if char found
101        scanbyte 0,g5           # check for null byte
102        addo    4,g0,g0         # post-increment src pointer
103        bno     Lsearch_for_word_with_char_or_null      # branch if not null
104
105Lnot_found:
106        mov     0,g0            # char not found.  Return null
107Lexit_code:
108        bx      (g13)           # g0 = addr of char in src (or null);  g14 = 0
109Lrett:
110        ret
111
112Lsearch_for_char:
113        subo    5,g0,g0         # back up the byte pointer
114Lsearch_for_char.a:
115        and     g5,g7,g6        # extract byte
116        cmpo    g1,g6           # is it char?
117        addo    1,g0,g0         # bump src byte ptr
118        shro    8,g5,g5         # shift word to position next byte
119        be      Lexit_code
120        cmpobne 0,g6,Lsearch_for_char.a # quit if null comes before char
121        b       Lnot_found
122
123/* end of strchr */
Note: See TracBrowser for help on using the repository browser.