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 strcmp (optimized assembler version for the 80960K Series)
44 result = strcmp (src1_addr, src2_addr)
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.
51 Undefined behavior will occur if the end of either source string
52 (i.e. the terminating null byte) is in the last two words of the
53 program's allocated memory space. This is so because strcmp fetches
54 ahead. Disallowing the fetch ahead would impose a severe performance
59 Fetch the source strings by words and compare the words until either
60 differing words are found or the null byte is encountered. In either
61 case, move through the word until either the differing byte if found,
62 in which case return -1 or 1 appropriately; or the null byte is
63 encountered, in which case, return zero (equality).
67 1) Do NOT try to fetch the words in a word aligned manner because,
68 in my judgement, the performance degradation experienced due to
69 non-aligned accesses does NOT outweigh the time and complexity added
70 by the preamble and convoluted body that would be necessary to assure
71 alignment. This is supported by the intuition that many source
72 strings will be word aligned to begin with.
77 .leafproc _strcmp,__strcmp
84 lda .Lrett-(.+8)(ip),g14
87 ld (g0), g5 # fetch first word of source_1
88 mov g14,g7 # preserve return address
89 ldconst 0,g14 # conform to register conventions
90 ldconst 0xff,g4 # byte extraction mask
92 addo 4,g0,g0 # post-increment source_1 byte ptr
93 ld (g1), g3 # fetch word of source_2
94 scanbyte 0,g5 # does word have a null byte?
95 mov g5,g2 # save a copy of the source_1 word
96 be .Lcloop # branch if null byte encountered
97 cmpo g2,g3 # are the source words the same?
98 addo 4,g1,g1 # post-increment source_2 byte ptr
99 ld (g0), g5 # fetch ahead next word of source_1
100 be .Lwloop # fall thru if words are unequal
102 .Lcloop: and g4,g2,g5 # extract and compare individual bytes
104 cmpobne g5,g6,.diff # if they differ, go return 1 or -1
105 cmpo 0,g6 # they are the same. Are they null?
106 shlo 8,g4,g4 # position mask for next extraction
107 bne .Lcloop # loop if null not encountered
109 mov 0,g0 # return equality