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 memcmp (optimized assembler version for the 80960K series)
44 result = memcmp (src1_addr, src2_addr, max_bytes)
46 compare the byte array pointed to by src1_addr to the byte array
47 pointed to by src2_addr. Return 0 iff the arrays are equal, -1 iff
48 src1_addr is lexicographically less than src2_addr, and 1 iff it is
49 lexicographically greater. Do not compare more than max_bytes bytes.
51 Undefined behavior will occur if the end of either source array
52 is in the last two words of the program's allocated memory space.
53 This is so because memcmp fetches ahead. Disallowing the fetch ahead
54 would impose a severe performance penalty.
58 Fetch the source strings by words and compare the words until either
59 a differing word is found or max_bytes is exhausted. In the former
60 case, move through the words to find the differing byte and return
61 plus or minus one, appropriately. In the latter case, return zero
66 1) Do NOT try to fetch the words in a word aligned manner because,
67 in my judgement, the performance degradation experienced due to
68 non-aligned accesses does NOT outweigh the time and complexity added
69 by the preamble that would be necessary to assure alignment. This
70 is supported by the intuition that most source arrays (even more
71 true of most big source arrays) will be word aligned to begin with.
73 2) Rather than decrementing max_bytes to zero, I calculate the
74 address of the byte after the last byte of the source_1 array, and
75 quit when the source byte pointer passes that.
80 .leafproc _memcmp,__memcmp
87 lda .Lrett-(.+8)(ip),g14
90 mov g14,g13 # preserve return address
91 ldconst 0,g14 # conform to register conventions
92 cmpibge 0,g2,Lequal_exit # quit if max_bytes <= 0
93 addo g0,g2,g2 # calculate byte addr of byte after last in src1
97 ld (g0), g5 # fetch word of source_1
98 bge Lequal_exit # quit (equal) if max_bytes exhausted
99 ld (g1), g3 # fetch word of source_2
100 addo 4,g0,g0 # post-increment source_1 byte ptr
101 addo 4,g1,g1 # post-increment source_2 byte ptr
102 cmpobe g5,g3,.Lwloop # branch if source words are equal
104 ldconst 0xff,g4 # byte extraction mask
105 subo 4,g0,g0 # back up src1 pointer
107 .Lcloop: and g4,g5,g7 # extract and compare individual bytes
109 cmpobne g7,g6,.diff # branch if they are different
110 shlo 8,g4,g4 # position mask for next extraction
112 cmpobl g0,g2,.Lcloop # quit if max_bytes is exhausted
120 .diff: bl .neg # arrays differ at current byte.
121 /* return 1 or -1 appropriately */