blob: eb3a08b804272f7cf9d8b819fbf52673823ceb5b [file] [log] [blame]
Alexander Ivchenkobaa91f42013-06-27 12:55:46 +04001/*
2Copyright (c) 2013 Intel Corporation
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7
8 * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10
11 * Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14
15 * Neither the name of Intel Corporation nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18
19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*/
30
31#include <stddef.h>
32
Elliott Hughes53e43292014-02-24 18:00:43 -080033// Unoptimized version of __memcmp16.
Elliott Hughesb6208832014-02-25 15:12:29 -080034extern "C" int __memcmp16(const unsigned short* lhs, const unsigned short* rhs, size_t n) {
Elliott Hughes53e43292014-02-24 18:00:43 -080035 for (size_t i = 0; i < n; i++) {
Elliott Hughesb6208832014-02-25 15:12:29 -080036 if (*lhs != *rhs) {
37 return *lhs - *rhs;
Elliott Hughes53e43292014-02-24 18:00:43 -080038 }
Elliott Hughesb6208832014-02-25 15:12:29 -080039 lhs++;
40 rhs++;
Alexander Ivchenkobaa91f42013-06-27 12:55:46 +040041 }
42 return 0;
43}