1 /*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef ART_RUNTIME_ARCH_MEMCMP16_H_
18 #define ART_RUNTIME_ARCH_MEMCMP16_H_
19
20 #include <cstddef>
21 #include <cstdint>
22
23 // memcmp16 support.
24 //
25 // This can either be optimized assembly code, in which case we expect a function __memcmp16,
26 // or generic C support.
27 //
28 // In case of the generic support we declare two versions: one in this header file meant to be
29 // inlined, and a static version that assembly stubs can link against.
30 //
31 // In both cases, MemCmp16 is declared.
32
33 #if defined(__aarch64__) || defined(__arm__) || defined(__i386__) || defined(__x86_64__)
34
35 extern "C" uint32_t __memcmp16(const uint16_t* s0, const uint16_t* s1, size_t count);
36 #define MemCmp16 __memcmp16
37
38 #else
39
40 // This is the generic inlined version.
MemCmp16(const uint16_t * s0,const uint16_t * s1,size_t count)41 static inline int32_t MemCmp16(const uint16_t* s0, const uint16_t* s1, size_t count) {
42 for (size_t i = 0; i < count; i++) {
43 if (s0[i] != s1[i]) {
44 return static_cast<int32_t>(s0[i]) - static_cast<int32_t>(s1[i]);
45 }
46 }
47 return 0;
48 }
49
50 extern "C" int32_t memcmp16_generic_static(const uint16_t* s0, const uint16_t* s1, size_t count);
51 #endif
52
53 namespace art {
54
55 namespace testing {
56
57 // A version that is exposed and relatively "close to the metal," so that memcmp16_test can do
58 // some reasonable testing. Without this, as __memcmp16 is hidden, the test cannot access the
59 // implementation.
60 int32_t MemCmp16Testing(const uint16_t* s0, const uint16_t* s1, size_t count);
61
62 } // namespace testing
63
64 } // namespace art
65
66 #endif // ART_RUNTIME_ARCH_MEMCMP16_H_
67