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