| Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 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 | |
| Goran Jakovljevic | c5dd99f | 2017-06-12 13:46:18 +0200 | [diff] [blame] | 17 | #include <math.h> |
| Vladimir Marko | 3a21e38 | 2016-09-02 12:38:38 +0100 | [diff] [blame] | 18 | #include <string.h> |
| 19 | |
| Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 20 | #include "arch/mips64/asm_support_mips64.h" |
| David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 21 | #include "base/atomic.h" |
| 22 | #include "base/quasi_atomic.h" |
| Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 23 | #include "entrypoints/entrypoint_utils.h" |
| Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 24 | #include "entrypoints/jni/jni_entrypoints.h" |
| Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 25 | #include "entrypoints/math_entrypoints.h" |
| Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 26 | #include "entrypoints/quick/quick_alloc_entrypoints.h" |
| 27 | #include "entrypoints/quick/quick_default_externs.h" |
| Andreas Gampe | c7ed09b | 2016-04-25 20:08:55 -0700 | [diff] [blame] | 28 | #include "entrypoints/quick/quick_default_init_entrypoints.h" |
| Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 29 | #include "entrypoints/quick/quick_entrypoints.h" |
| Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 30 | #include "entrypoints/runtime_asm_entrypoints.h" |
| 31 | #include "interpreter/interpreter.h" |
| 32 | |
| 33 | namespace art { |
| 34 | |
| 35 | // Cast entrypoints. |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 36 | extern "C" size_t artInstanceOfFromCode(mirror::Object* obj, mirror::Class* ref_class); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 37 | |
| Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 38 | // Read barrier entrypoints. |
| 39 | // art_quick_read_barrier_mark_regXX uses a non-standard calling |
| 40 | // convention: it expects its input in register XX+1 and returns its |
| 41 | // result in that same register, and saves and restores all |
| 42 | // caller-save registers. |
| 43 | extern "C" mirror::Object* art_quick_read_barrier_mark_reg01(mirror::Object*); |
| 44 | extern "C" mirror::Object* art_quick_read_barrier_mark_reg02(mirror::Object*); |
| 45 | extern "C" mirror::Object* art_quick_read_barrier_mark_reg03(mirror::Object*); |
| 46 | extern "C" mirror::Object* art_quick_read_barrier_mark_reg04(mirror::Object*); |
| 47 | extern "C" mirror::Object* art_quick_read_barrier_mark_reg05(mirror::Object*); |
| 48 | extern "C" mirror::Object* art_quick_read_barrier_mark_reg06(mirror::Object*); |
| 49 | extern "C" mirror::Object* art_quick_read_barrier_mark_reg07(mirror::Object*); |
| 50 | extern "C" mirror::Object* art_quick_read_barrier_mark_reg08(mirror::Object*); |
| 51 | extern "C" mirror::Object* art_quick_read_barrier_mark_reg09(mirror::Object*); |
| 52 | extern "C" mirror::Object* art_quick_read_barrier_mark_reg10(mirror::Object*); |
| 53 | extern "C" mirror::Object* art_quick_read_barrier_mark_reg11(mirror::Object*); |
| 54 | extern "C" mirror::Object* art_quick_read_barrier_mark_reg12(mirror::Object*); |
| 55 | extern "C" mirror::Object* art_quick_read_barrier_mark_reg13(mirror::Object*); |
| 56 | extern "C" mirror::Object* art_quick_read_barrier_mark_reg17(mirror::Object*); |
| 57 | extern "C" mirror::Object* art_quick_read_barrier_mark_reg18(mirror::Object*); |
| 58 | extern "C" mirror::Object* art_quick_read_barrier_mark_reg19(mirror::Object*); |
| 59 | extern "C" mirror::Object* art_quick_read_barrier_mark_reg20(mirror::Object*); |
| 60 | extern "C" mirror::Object* art_quick_read_barrier_mark_reg21(mirror::Object*); |
| 61 | extern "C" mirror::Object* art_quick_read_barrier_mark_reg22(mirror::Object*); |
| 62 | extern "C" mirror::Object* art_quick_read_barrier_mark_reg29(mirror::Object*); |
| 63 | |
| Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 64 | extern "C" mirror::Object* art_quick_read_barrier_mark_introspection(mirror::Object*); |
| 65 | extern "C" mirror::Object* art_quick_read_barrier_mark_introspection_gc_roots(mirror::Object*); |
| 66 | extern "C" void art_quick_read_barrier_mark_introspection_end_of_entries(void); |
| 67 | |
| Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 68 | // Math entrypoints. |
| 69 | extern int32_t CmpgDouble(double a, double b); |
| 70 | extern int32_t CmplDouble(double a, double b); |
| 71 | extern int32_t CmpgFloat(float a, float b); |
| 72 | extern int32_t CmplFloat(float a, float b); |
| 73 | extern "C" int64_t artLmul(int64_t a, int64_t b); |
| 74 | extern "C" int64_t artLdiv(int64_t a, int64_t b); |
| 75 | extern "C" int64_t artLmod(int64_t a, int64_t b); |
| 76 | |
| 77 | // Math conversions. |
| 78 | extern "C" int32_t __fixsfsi(float op1); // FLOAT_TO_INT |
| 79 | extern "C" int32_t __fixdfsi(double op1); // DOUBLE_TO_INT |
| 80 | extern "C" float __floatdisf(int64_t op1); // LONG_TO_FLOAT |
| 81 | extern "C" double __floatdidf(int64_t op1); // LONG_TO_DOUBLE |
| 82 | extern "C" int64_t __fixsfdi(float op1); // FLOAT_TO_LONG |
| 83 | extern "C" int64_t __fixdfdi(double op1); // DOUBLE_TO_LONG |
| 84 | |
| 85 | // Single-precision FP arithmetics. |
| 86 | extern "C" float fmodf(float a, float b); // REM_FLOAT[_2ADDR] |
| 87 | |
| 88 | // Double-precision FP arithmetics. |
| 89 | extern "C" double fmod(double a, double b); // REM_DOUBLE[_2ADDR] |
| 90 | |
| 91 | // Long long arithmetics - REM_LONG[_2ADDR] and DIV_LONG[_2ADDR] |
| 92 | extern "C" int64_t __divdi3(int64_t, int64_t); |
| 93 | extern "C" int64_t __moddi3(int64_t, int64_t); |
| 94 | |
| Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 95 | // No read barrier entrypoints for marking registers. |
| Mathieu Chartier | 3768ade | 2017-05-02 14:04:39 -0700 | [diff] [blame] | 96 | void UpdateReadBarrierEntrypoints(QuickEntryPoints* qpoints, bool is_active) { |
| Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 97 | intptr_t introspection_field_array_entries_size = |
| 98 | reinterpret_cast<intptr_t>(&art_quick_read_barrier_mark_introspection_gc_roots) - |
| 99 | reinterpret_cast<intptr_t>(&art_quick_read_barrier_mark_introspection); |
| 100 | static_assert( |
| 101 | BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRIES_OFFSET == 2 * |
| 102 | BAKER_MARK_INTROSPECTION_REGISTER_COUNT * BAKER_MARK_INTROSPECTION_FIELD_ARRAY_ENTRY_SIZE, |
| 103 | "Expecting equal"); |
| 104 | DCHECK_EQ(introspection_field_array_entries_size, |
| 105 | BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRIES_OFFSET); |
| 106 | intptr_t introspection_gc_root_entries_size = |
| 107 | reinterpret_cast<intptr_t>(&art_quick_read_barrier_mark_introspection_end_of_entries) - |
| 108 | reinterpret_cast<intptr_t>(&art_quick_read_barrier_mark_introspection_gc_roots); |
| 109 | DCHECK_EQ(introspection_gc_root_entries_size, |
| 110 | BAKER_MARK_INTROSPECTION_REGISTER_COUNT * BAKER_MARK_INTROSPECTION_GC_ROOT_ENTRY_SIZE); |
| 111 | qpoints->pReadBarrierMarkReg00 = is_active ? art_quick_read_barrier_mark_introspection : nullptr; |
| Mathieu Chartier | 3768ade | 2017-05-02 14:04:39 -0700 | [diff] [blame] | 112 | qpoints->pReadBarrierMarkReg01 = is_active ? art_quick_read_barrier_mark_reg01 : nullptr; |
| 113 | qpoints->pReadBarrierMarkReg02 = is_active ? art_quick_read_barrier_mark_reg02 : nullptr; |
| 114 | qpoints->pReadBarrierMarkReg03 = is_active ? art_quick_read_barrier_mark_reg03 : nullptr; |
| 115 | qpoints->pReadBarrierMarkReg04 = is_active ? art_quick_read_barrier_mark_reg04 : nullptr; |
| 116 | qpoints->pReadBarrierMarkReg05 = is_active ? art_quick_read_barrier_mark_reg05 : nullptr; |
| 117 | qpoints->pReadBarrierMarkReg06 = is_active ? art_quick_read_barrier_mark_reg06 : nullptr; |
| 118 | qpoints->pReadBarrierMarkReg07 = is_active ? art_quick_read_barrier_mark_reg07 : nullptr; |
| 119 | qpoints->pReadBarrierMarkReg08 = is_active ? art_quick_read_barrier_mark_reg08 : nullptr; |
| 120 | qpoints->pReadBarrierMarkReg09 = is_active ? art_quick_read_barrier_mark_reg09 : nullptr; |
| 121 | qpoints->pReadBarrierMarkReg10 = is_active ? art_quick_read_barrier_mark_reg10 : nullptr; |
| 122 | qpoints->pReadBarrierMarkReg11 = is_active ? art_quick_read_barrier_mark_reg11 : nullptr; |
| 123 | qpoints->pReadBarrierMarkReg12 = is_active ? art_quick_read_barrier_mark_reg12 : nullptr; |
| 124 | qpoints->pReadBarrierMarkReg13 = is_active ? art_quick_read_barrier_mark_reg13 : nullptr; |
| 125 | qpoints->pReadBarrierMarkReg17 = is_active ? art_quick_read_barrier_mark_reg17 : nullptr; |
| 126 | qpoints->pReadBarrierMarkReg18 = is_active ? art_quick_read_barrier_mark_reg18 : nullptr; |
| 127 | qpoints->pReadBarrierMarkReg19 = is_active ? art_quick_read_barrier_mark_reg19 : nullptr; |
| 128 | qpoints->pReadBarrierMarkReg20 = is_active ? art_quick_read_barrier_mark_reg20 : nullptr; |
| 129 | qpoints->pReadBarrierMarkReg21 = is_active ? art_quick_read_barrier_mark_reg21 : nullptr; |
| 130 | qpoints->pReadBarrierMarkReg22 = is_active ? art_quick_read_barrier_mark_reg22 : nullptr; |
| 131 | qpoints->pReadBarrierMarkReg29 = is_active ? art_quick_read_barrier_mark_reg29 : nullptr; |
| Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 132 | } |
| Mathieu Chartier | fe814e8 | 2016-11-09 14:32:49 -0800 | [diff] [blame] | 133 | |
| Andreas Gampe | 3cfa4d0 | 2015-10-06 17:04:01 -0700 | [diff] [blame] | 134 | void InitEntryPoints(JniEntryPoints* jpoints, QuickEntryPoints* qpoints) { |
| Andreas Gampe | c7ed09b | 2016-04-25 20:08:55 -0700 | [diff] [blame] | 135 | DefaultInitEntryPoints(jpoints, qpoints); |
| Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 136 | |
| 137 | // Cast |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 138 | qpoints->pInstanceofNonTrivial = artInstanceOfFromCode; |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 139 | qpoints->pCheckInstanceOf = art_quick_check_instance_of; |
| Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 140 | |
| Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 141 | // Math |
| 142 | qpoints->pCmpgDouble = CmpgDouble; |
| 143 | qpoints->pCmpgFloat = CmpgFloat; |
| 144 | qpoints->pCmplDouble = CmplDouble; |
| 145 | qpoints->pCmplFloat = CmplFloat; |
| 146 | qpoints->pFmod = fmod; |
| 147 | qpoints->pL2d = art_l2d; |
| 148 | qpoints->pFmodf = fmodf; |
| 149 | qpoints->pL2f = art_l2f; |
| 150 | qpoints->pD2iz = art_d2i; |
| 151 | qpoints->pF2iz = art_f2i; |
| Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 152 | qpoints->pIdivmod = nullptr; |
| Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 153 | qpoints->pD2l = art_d2l; |
| 154 | qpoints->pF2l = art_f2l; |
| 155 | qpoints->pLdiv = artLdiv; |
| 156 | qpoints->pLmod = artLmod; |
| 157 | qpoints->pLmul = artLmul; |
| Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 158 | qpoints->pShlLong = nullptr; |
| 159 | qpoints->pShrLong = nullptr; |
| 160 | qpoints->pUshrLong = nullptr; |
| Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 161 | |
| Chris Larsen | 74c2058 | 2017-03-28 22:17:35 -0700 | [diff] [blame] | 162 | // More math. |
| 163 | qpoints->pCos = cos; |
| 164 | qpoints->pSin = sin; |
| 165 | qpoints->pAcos = acos; |
| 166 | qpoints->pAsin = asin; |
| 167 | qpoints->pAtan = atan; |
| 168 | qpoints->pAtan2 = atan2; |
| Vladimir Marko | 4d17987 | 2018-01-19 14:50:10 +0000 | [diff] [blame] | 169 | qpoints->pPow = pow; |
| Chris Larsen | 74c2058 | 2017-03-28 22:17:35 -0700 | [diff] [blame] | 170 | qpoints->pCbrt = cbrt; |
| 171 | qpoints->pCosh = cosh; |
| 172 | qpoints->pExp = exp; |
| 173 | qpoints->pExpm1 = expm1; |
| 174 | qpoints->pHypot = hypot; |
| 175 | qpoints->pLog = log; |
| 176 | qpoints->pLog10 = log10; |
| 177 | qpoints->pNextAfter = nextafter; |
| 178 | qpoints->pSinh = sinh; |
| 179 | qpoints->pTan = tan; |
| 180 | qpoints->pTanh = tanh; |
| 181 | |
| Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 182 | // Intrinsics |
| 183 | qpoints->pIndexOf = art_quick_indexof; |
| 184 | qpoints->pStringCompareTo = art_quick_string_compareto; |
| 185 | qpoints->pMemcpy = memcpy; |
| 186 | |
| Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 187 | // TODO - use lld/scd instructions for Mips64 |
| 188 | // Atomic 64-bit load/store |
| 189 | qpoints->pA64Load = QuasiAtomic::Read64; |
| 190 | qpoints->pA64Store = QuasiAtomic::Write64; |
| Hiroshi Yamauchi | 1cc71eb | 2015-05-07 10:47:27 -0700 | [diff] [blame] | 191 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 192 | // Read barrier. |
| Hiroshi Yamauchi | 1cc71eb | 2015-05-07 10:47:27 -0700 | [diff] [blame] | 193 | qpoints->pReadBarrierJni = ReadBarrierJni; |
| Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame^] | 194 | UpdateReadBarrierEntrypoints(qpoints, /*is_active=*/ false); |
| Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 195 | // Cannot use the following registers to pass arguments: |
| 196 | // 0(ZERO), 1(AT), 15(T3), 16(S0), 17(S1), 24(T8), 25(T9), 26(K0), 27(K1), 28(GP), 29(SP), 31(RA). |
| 197 | // Note that there are 30 entry points only: 00 for register 1(AT), ..., 29 for register 30(S8). |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 198 | qpoints->pReadBarrierMarkReg14 = nullptr; |
| 199 | qpoints->pReadBarrierMarkReg15 = nullptr; |
| 200 | qpoints->pReadBarrierMarkReg16 = nullptr; |
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 201 | qpoints->pReadBarrierMarkReg23 = nullptr; |
| 202 | qpoints->pReadBarrierMarkReg24 = nullptr; |
| 203 | qpoints->pReadBarrierMarkReg25 = nullptr; |
| 204 | qpoints->pReadBarrierMarkReg26 = nullptr; |
| 205 | qpoints->pReadBarrierMarkReg27 = nullptr; |
| 206 | qpoints->pReadBarrierMarkReg28 = nullptr; |
| Man Cao | 1aee900 | 2015-07-14 22:31:42 -0700 | [diff] [blame] | 207 | qpoints->pReadBarrierSlow = artReadBarrierSlow; |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 208 | qpoints->pReadBarrierForRootSlow = artReadBarrierForRootSlow; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 209 | } |
| Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 210 | |
| 211 | } // namespace art |