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
42 procedure strncmp (optimized assembler version for the 80960K Series)
44 result = strncmp (src1_addr, src2_addr, max_bytes)
46 compare the null terminated string pointed to by src1_addr to
47 the string pointed to by src2_addr. Return 0 iff the strings
48 are equal, -1 if src1_addr is lexicographically less than src2_addr,
49 and 1 if it is lexicographically greater. Do not compare more than
52 Undefined behavior will occur if the end of either source string
53 (i.e. the terminating null byte) is in the last two words of the
54 program's allocated memory space. This is so because strncmp
55 will fetch ahead. Disallowing the fetch ahead would impose
56 a severe performance penalty.
60 Fetch and compare the strings by words and go to a character
61 comparison loop as soon as a pair of words differ. If the
62 words are equal up through either the exhaustion of max_bytes
63 or the presence of the null byte, return 0 (equality). Otherwise,
64 the character comparator will return -1 or 1 for inequality, or
65 0 if the differing byte is after the null byte or after the
66 exhaustion of max_bytes.
70 1) Do NOT try to fetch the words in a word aligned manner because,
71 in my judgement, the performance degradation experienced due to
72 non-aligned accesses does NOT outweigh the time and complexity added
73 by the preamble and convoluted body that would be necessary to assure
79 .leafproc _strncmp,__strncmp
86 lda .Lrett-(.+8)(ip),g14
91 cmpibge 0,g2,Lequal_exit # Lexit early if max_bytes <= 0
94 cmpo g0,g2 # are max_bytes exhausted?
95 ld (g0), g5 # fetch word of source_1
96 bge Lequal_exit # Lexit (equality) if max_bytes exhausted
97 ld (g1), g3 # fetch word of source_2
98 addo 4,g0,g0 # post-increment source_1 ptr
99 scanbyte 0,g5 # is a null byte present?
100 addo 4,g1,g1 # post-increment source_1 ptr
101 be .Lcloop.a # perform char comparator if null byte found
102 cmpobe g5,g3,.Lwloop # perform char comparator if words are unequal
104 .Lcloop.a: subo 4,g0,g0 # adjust max_byte counter
105 ldconst 0xff,g4 # byte extraction mask
107 .Lcloop: and g4,g5,g7 # compare individual bytes
109 cmpobne g7,g6,.diff # if different, return -1 or 1
110 cmpo 0,g6 # they are equal. are they null?
111 shlo 8,g4,g4 # position mask to extract next byte
112 be Lequal_exit # if they are null, Lexit (equality)
113 addo 1,g0,g0 # is max_bytes exhausted?
114 cmpobl g0,g2,.Lcloop # if not, loop. if so, Lexit (equality)