1 /*******************************************************************************
3 * Copyright (c) 1993 Intel Corporation
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.
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.
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.
29 ******************************************************************************/
39 * (c) copyright 1988,1993 Intel Corp., all rights reserved
43 procedure strchr (optimized assembler version for the 80960K series)
45 src_addr = strchr (src_addr, char)
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.
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.
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,
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.
75 .leafproc _strchr, __strchr
81 lda Lrett-(.+8)(ip),g14
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
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
96 Lsearch_for_word_with_char_or_null:
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
106 mov 0,g0 # char not found. Return null
108 bx (g13) # g0 = addr of char in src (or null); g14 = 0
113 subo 5,g0,g0 # back up the byte pointer
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
120 cmpobne 0,g6,Lsearch_for_char.a # quit if null comes before char