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 #include <math.h>
18 #include <string.h>
19
20 #include "arch/mips64/asm_support_mips64.h"
21 #include "base/atomic.h"
22 #include "base/quasi_atomic.h"
23 #include "entrypoints/entrypoint_utils.h"
24 #include "entrypoints/jni/jni_entrypoints.h"
25 #include "entrypoints/math_entrypoints.h"
26 #include "entrypoints/quick/quick_alloc_entrypoints.h"
27 #include "entrypoints/quick/quick_default_externs.h"
28 #include "entrypoints/quick/quick_default_init_entrypoints.h"
29 #include "entrypoints/quick/quick_entrypoints.h"
30 #include "entrypoints/runtime_asm_entrypoints.h"
31 #include "interpreter/interpreter.h"
32
33 namespace art {
34
35 // Cast entrypoints.
36 extern "C" size_t artInstanceOfFromCode(mirror::Object* obj, mirror::Class* ref_class);
37
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
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
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
95 // No read barrier entrypoints for marking registers.
UpdateReadBarrierEntrypoints(QuickEntryPoints * qpoints,bool is_active)96 void UpdateReadBarrierEntrypoints(QuickEntryPoints* qpoints, bool is_active) {
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;
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;
132 }
133
InitEntryPoints(JniEntryPoints * jpoints,QuickEntryPoints * qpoints)134 void InitEntryPoints(JniEntryPoints* jpoints, QuickEntryPoints* qpoints) {
135 DefaultInitEntryPoints(jpoints, qpoints);
136
137 // Cast
138 qpoints->pInstanceofNonTrivial = artInstanceOfFromCode;
139 qpoints->pCheckInstanceOf = art_quick_check_instance_of;
140
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;
152 qpoints->pIdivmod = nullptr;
153 qpoints->pD2l = art_d2l;
154 qpoints->pF2l = art_f2l;
155 qpoints->pLdiv = artLdiv;
156 qpoints->pLmod = artLmod;
157 qpoints->pLmul = artLmul;
158 qpoints->pShlLong = nullptr;
159 qpoints->pShrLong = nullptr;
160 qpoints->pUshrLong = nullptr;
161
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;
169 qpoints->pPow = pow;
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
182 // Intrinsics
183 qpoints->pIndexOf = art_quick_indexof;
184 qpoints->pStringCompareTo = art_quick_string_compareto;
185 qpoints->pMemcpy = memcpy;
186
187 // TODO - use lld/scd instructions for Mips64
188 // Atomic 64-bit load/store
189 qpoints->pA64Load = QuasiAtomic::Read64;
190 qpoints->pA64Store = QuasiAtomic::Write64;
191
192 // Read barrier.
193 qpoints->pReadBarrierJni = ReadBarrierJni;
194 UpdateReadBarrierEntrypoints(qpoints, /*is_active=*/ false);
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).
198 qpoints->pReadBarrierMarkReg14 = nullptr;
199 qpoints->pReadBarrierMarkReg15 = nullptr;
200 qpoints->pReadBarrierMarkReg16 = nullptr;
201 qpoints->pReadBarrierMarkReg23 = nullptr;
202 qpoints->pReadBarrierMarkReg24 = nullptr;
203 qpoints->pReadBarrierMarkReg25 = nullptr;
204 qpoints->pReadBarrierMarkReg26 = nullptr;
205 qpoints->pReadBarrierMarkReg27 = nullptr;
206 qpoints->pReadBarrierMarkReg28 = nullptr;
207 qpoints->pReadBarrierSlow = artReadBarrierSlow;
208 qpoints->pReadBarrierForRootSlow = artReadBarrierForRootSlow;
209 }
210
211 } // namespace art
212