Mercurial > ecos
annotate packages/language/c/libc/current/src/string/memcmp.cxx @ 66:bf00f99aec69 ecos-sw-2000-02-02
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
| author | jlarmour |
|---|---|
| date | Wed, 02 Feb 2000 19:57:02 +0000 |
| parents | c38311975d4f |
| children |
| rev | line source |
|---|---|
| 0 | 1 //=========================================================================== |
| 2 // | |
| 3 // memcmp.cxx | |
| 4 // | |
| 5 // ANSI standard memcmp() routine | |
| 6 // | |
| 7 //=========================================================================== | |
| 8 //####COPYRIGHTBEGIN#### | |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
9 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
10 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
11 // The contents of this file are subject to the Red Hat eCos Public License |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
12 // Version 1.1 (the "License"); you may not use this file except in |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
13 // compliance with the License. You may obtain a copy of the License at |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
14 // http://www.redhat.com/ |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
15 // |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
18 // License for the specific language governing rights and limitations under |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
19 // the License. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
20 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
21 // The Original Code is eCos - Embedded Configurable Operating System, |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
22 // released September 30, 1998. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
23 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
24 // The Initial Developer of the Original Code is Red Hat. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
25 // Portions created by Red Hat are |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
26 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
27 // All Rights Reserved. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
28 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
29 // |
| 0 | 30 //####COPYRIGHTEND#### |
| 31 //=========================================================================== | |
| 32 //#####DESCRIPTIONBEGIN#### | |
| 33 // | |
| 34 // Author(s): jlarmour | |
| 2 | 35 // Contributors: jlarmour |
| 0 | 36 // Date: 1998-02-13 |
| 37 // Purpose: | |
| 38 // Description: | |
| 39 // Usage: | |
| 40 // | |
| 41 //####DESCRIPTIONEND#### | |
| 42 // | |
| 43 //=========================================================================== | |
| 44 | |
| 45 // CONFIGURATION | |
| 46 | |
| 47 #include <pkgconf/libc.h> // Configuration header | |
| 48 | |
| 49 // Include the C library? | |
| 50 #ifdef CYGPKG_LIBC | |
| 51 | |
| 52 // INCLUDES | |
| 53 | |
| 54 #include <cyg/infra/cyg_type.h> // Common type definitions | |
| 55 #include <cyg/infra/cyg_trac.h> // Tracing support | |
| 56 #include <cyg/infra/cyg_ass.h> // Assertion support | |
| 57 #include <string.h> // Header for this file | |
| 58 #include <stddef.h> // Compiler definitions such as size_t, NULL etc. | |
| 59 #include "clibincl/stringsupp.hxx" // Useful string function support and | |
| 60 // prototypes | |
| 61 | |
| 62 | |
| 63 // EXPORTED SYMBOLS | |
| 64 | |
| 65 externC int | |
| 66 memcmp( const void *s1, const void *s2, size_t n ) \ | |
| 67 CYGPRI_LIBC_WEAK_ALIAS("_memcmp"); | |
| 68 | |
| 69 // FUNCTIONS | |
| 70 | |
| 71 int | |
| 72 _memcmp( const void *s1, const void *s2, size_t n ) | |
| 73 { | |
| 74 int retval; | |
| 75 | |
| 76 CYG_REPORT_FUNCNAMETYPE( "_memcmp", "returning %d" ); | |
| 77 CYG_REPORT_FUNCARG3( "s1=%08x, s2=%08x, n=%d", s1, s2, n ); | |
| 78 | |
| 79 CYG_CHECK_DATA_PTR( s1, "s1 is not a valid pointer!" ); | |
| 80 CYG_CHECK_DATA_PTR( s2, "s2 is not a valid pointer!" ); | |
| 81 | |
| 82 #if defined(CYGIMP_LIBC_STRING_PREFER_SMALL_TO_FAST) || defined(__OPTIMIZE_SIZE__) | |
| 83 const unsigned char *m1 = (const unsigned char *) s1; | |
| 84 const unsigned char *m2 = (const unsigned char *) s2; | |
| 85 | |
| 86 while (n--) | |
| 87 { | |
| 88 if (*m1 != *m2) | |
| 89 { | |
| 90 retval = *m1 - *m2; | |
| 91 CYG_REPORT_RETVAL( retval ); | |
| 92 return retval; | |
| 93 } | |
| 94 m1++; | |
| 95 m2++; | |
| 96 } | |
| 97 CYG_REPORT_RETVAL( 0 ); | |
| 98 return 0; | |
| 99 #else | |
| 100 const unsigned char *m1 = (const unsigned char *) s1; | |
| 101 const unsigned char *m2 = (const unsigned char *) s2; | |
| 102 const CYG_WORD *aligned_m1; | |
| 103 const CYG_WORD *aligned_m2; | |
| 104 | |
| 105 // If the size is too small, or either pointer is unaligned, | |
| 106 // then we punt to the byte compare loop. Hopefully this will | |
| 107 // not turn up in inner loops. | |
| 108 if (CYG_LIBC_STR_OPT_TOO_SMALL(n) || CYG_LIBC_STR_UNALIGNED2(m1,m2)) | |
| 109 { | |
| 110 while (n--) | |
| 111 { | |
| 112 if (*m1 != *m2) | |
| 113 { | |
| 114 retval = *m1 - *m2; | |
| 115 CYG_REPORT_RETVAL( retval ); | |
| 116 return retval; | |
| 117 } | |
| 118 m1++; | |
| 119 m2++; | |
| 120 } | |
| 121 CYG_REPORT_RETVAL( 0 ); | |
| 122 return 0; | |
| 123 } | |
| 124 | |
| 125 // Otherwise, load and compare the blocks of memory one | |
| 126 // word at a time. | |
| 127 aligned_m1 = (const CYG_WORD *) m1; | |
| 128 aligned_m2 = (const CYG_WORD *) m2; | |
| 129 while (n > CYG_LIBC_STR_OPT_LITTLEBLOCKSIZE) | |
| 130 { | |
| 131 if (*aligned_m1 != *aligned_m2) | |
| 132 { | |
| 133 // This block of characters has a mismatch, somewhere. | |
| 134 // xoring them together and then testing for null would | |
| 135 // be fastest, but this is clearer code. | |
| 136 m1 = (const unsigned char *)aligned_m1; | |
| 137 m2 = (const unsigned char *)aligned_m2; | |
| 138 while (n--) | |
| 139 { | |
| 140 if (*m1 != *m2) | |
| 141 { | |
| 142 retval = *m1 - *m2; | |
| 143 CYG_REPORT_RETVAL( retval ); | |
| 144 return retval; | |
| 145 } | |
| 146 m1++; | |
| 147 m2++; | |
| 148 } | |
| 149 // NOT REACHED | |
| 150 } | |
| 151 aligned_m1++; | |
| 152 aligned_m2++; | |
| 153 n -= CYG_LIBC_STR_OPT_LITTLEBLOCKSIZE; | |
| 154 } | |
| 155 | |
| 156 // checking the last few characters | |
| 157 | |
| 158 m1 = (const unsigned char *)aligned_m1; | |
| 159 m2 = (const unsigned char *)aligned_m2; | |
| 160 | |
| 161 while (n--) | |
| 162 { | |
| 163 if (*m1 != *m2) | |
| 164 { | |
| 165 retval = *m1 - *m2; | |
| 166 CYG_REPORT_RETVAL( retval ); | |
| 167 return retval; | |
| 168 } | |
| 169 m1++; | |
| 170 m2++; | |
| 171 } | |
| 172 | |
| 173 CYG_REPORT_RETVAL( 0 ); | |
| 174 return 0; | |
| 175 #endif // not defined(CYGIMP_LIBC_STRING_PREFER_SMALL_TO_FAST) || | |
| 176 // defined(__OPTIMIZE_SIZE__) | |
| 177 } // _memcmp() | |
| 178 | |
| 179 #endif // CYGPKG_LIBC | |
| 180 | |
| 181 // EOF memcmp.cxx |
