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 #include "base/macros.h"
24
25 // memcmp16 support.
26 //
27 // This can either be optimized assembly code, in which case we expect a function __memcmp16,
28 // or generic C support.
29 //
30 // In case of the generic support we declare two versions: one in this header file meant to be
31 // inlined, and a static version that assembly stubs can link against.
32 //
33 // In both cases, MemCmp16 is declared.
34
35 #if defined(__aarch64__) || defined(__arm__) || defined(__i386__) || defined(__x86_64__)
36
37 extern "C" uint32_t __memcmp16(const uint16_t* s0, const uint16_t* s1, size_t count);
38 #define MemCmp16 __memcmp16
39
40 #else
41
42 // This is the generic inlined version.
MemCmp16(const uint16_t * s0,const uint16_t * s1,size_t count)43 static inline int32_t MemCmp16(const uint16_t* s0, const uint16_t* s1, size_t count) {
44 for (size_t i = 0; i < count; i++) {
45 if (s0[i] != s1[i]) {
46 return static_cast<int32_t>(s0[i]) - static_cast<int32_t>(s1[i]);
47 }
48 }
49 return 0;
50 }
51
52 // TODO(260881207): decide whether to hide this symbol.
53 extern "C" int32_t memcmp16_generic_static(const uint16_t* s0, const uint16_t* s1, size_t count);
54 #endif
55
56 namespace art HIDDEN {
57
58 namespace testing {
59
60 // A version that is exposed and relatively "close to the metal," so that memcmp16_test can do
61 // some reasonable testing. Without this, as __memcmp16 is hidden, the test cannot access the
62 // implementation.
63 int32_t MemCmp16Testing(const uint16_t* s0, const uint16_t* s1, size_t count);
64
65 } // namespace testing
66
67 } // namespace art
68
69 #endif // ART_RUNTIME_ARCH_MEMCMP16_H_
70