blob: b1164d653d3263dbbd3cf21103805ee3538095c1 [file] [log] [blame]
Chris Larsen3039e382015-08-26 07:54:08 -07001/*
2 * Copyright (C) 2015 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 "intrinsics_mips64.h"
18
19#include "arch/mips64/instruction_set_features_mips64.h"
20#include "art_method.h"
21#include "code_generator_mips64.h"
22#include "entrypoints/quick/quick_entrypoints.h"
23#include "intrinsics.h"
24#include "mirror/array-inl.h"
25#include "mirror/string.h"
26#include "thread.h"
27#include "utils/mips64/assembler_mips64.h"
28#include "utils/mips64/constants_mips64.h"
29
30namespace art {
31
32namespace mips64 {
33
34IntrinsicLocationsBuilderMIPS64::IntrinsicLocationsBuilderMIPS64(CodeGeneratorMIPS64* codegen)
35 : arena_(codegen->GetGraph()->GetArena()) {
36}
37
38Mips64Assembler* IntrinsicCodeGeneratorMIPS64::GetAssembler() {
39 return reinterpret_cast<Mips64Assembler*>(codegen_->GetAssembler());
40}
41
42ArenaAllocator* IntrinsicCodeGeneratorMIPS64::GetAllocator() {
43 return codegen_->GetGraph()->GetArena();
44}
45
46bool IntrinsicLocationsBuilderMIPS64::TryDispatch(HInvoke* invoke) {
47 Dispatch(invoke);
48 LocationSummary* res = invoke->GetLocations();
49 return res != nullptr && res->Intrinsified();
50}
51
52#define __ assembler->
53
54static void CreateFPToIntLocations(ArenaAllocator* arena, HInvoke* invoke) {
55 LocationSummary* locations = new (arena) LocationSummary(invoke,
56 LocationSummary::kNoCall,
57 kIntrinsified);
58 locations->SetInAt(0, Location::RequiresFpuRegister());
59 locations->SetOut(Location::RequiresRegister());
60}
61
62static void MoveFPToInt(LocationSummary* locations, bool is64bit, Mips64Assembler* assembler) {
63 FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>();
64 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
65
66 if (is64bit) {
67 __ Dmfc1(out, in);
68 } else {
69 __ Mfc1(out, in);
70 }
71}
72
73// long java.lang.Double.doubleToRawLongBits(double)
74void IntrinsicLocationsBuilderMIPS64::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) {
75 CreateFPToIntLocations(arena_, invoke);
76}
77
78void IntrinsicCodeGeneratorMIPS64::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) {
79 MoveFPToInt(invoke->GetLocations(), true, GetAssembler());
80}
81
82// int java.lang.Float.floatToRawIntBits(float)
83void IntrinsicLocationsBuilderMIPS64::VisitFloatFloatToRawIntBits(HInvoke* invoke) {
84 CreateFPToIntLocations(arena_, invoke);
85}
86
87void IntrinsicCodeGeneratorMIPS64::VisitFloatFloatToRawIntBits(HInvoke* invoke) {
88 MoveFPToInt(invoke->GetLocations(), false, GetAssembler());
89}
90
91static void CreateIntToFPLocations(ArenaAllocator* arena, HInvoke* invoke) {
92 LocationSummary* locations = new (arena) LocationSummary(invoke,
93 LocationSummary::kNoCall,
94 kIntrinsified);
95 locations->SetInAt(0, Location::RequiresRegister());
96 locations->SetOut(Location::RequiresFpuRegister());
97}
98
99static void MoveIntToFP(LocationSummary* locations, bool is64bit, Mips64Assembler* assembler) {
100 GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>();
101 FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>();
102
103 if (is64bit) {
104 __ Dmtc1(in, out);
105 } else {
106 __ Mtc1(in, out);
107 }
108}
109
110// double java.lang.Double.longBitsToDouble(long)
111void IntrinsicLocationsBuilderMIPS64::VisitDoubleLongBitsToDouble(HInvoke* invoke) {
112 CreateIntToFPLocations(arena_, invoke);
113}
114
115void IntrinsicCodeGeneratorMIPS64::VisitDoubleLongBitsToDouble(HInvoke* invoke) {
116 MoveIntToFP(invoke->GetLocations(), true, GetAssembler());
117}
118
119// float java.lang.Float.intBitsToFloat(int)
120void IntrinsicLocationsBuilderMIPS64::VisitFloatIntBitsToFloat(HInvoke* invoke) {
121 CreateIntToFPLocations(arena_, invoke);
122}
123
124void IntrinsicCodeGeneratorMIPS64::VisitFloatIntBitsToFloat(HInvoke* invoke) {
125 MoveIntToFP(invoke->GetLocations(), false, GetAssembler());
126}
127
128static void CreateIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) {
129 LocationSummary* locations = new (arena) LocationSummary(invoke,
130 LocationSummary::kNoCall,
131 kIntrinsified);
132 locations->SetInAt(0, Location::RequiresRegister());
133 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
134}
135
136static void GenReverseBytes(LocationSummary* locations,
137 Primitive::Type type,
138 Mips64Assembler* assembler) {
139 GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>();
140 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
141
142 switch (type) {
143 case Primitive::kPrimShort:
144 __ Dsbh(out, in);
145 __ Seh(out, out);
146 break;
147 case Primitive::kPrimInt:
148 __ Rotr(out, in, 16);
149 __ Wsbh(out, out);
150 break;
151 case Primitive::kPrimLong:
152 __ Dsbh(out, in);
153 __ Dshd(out, out);
154 break;
155 default:
156 LOG(FATAL) << "Unexpected size for reverse-bytes: " << type;
157 UNREACHABLE();
158 }
159}
160
161// int java.lang.Integer.reverseBytes(int)
162void IntrinsicLocationsBuilderMIPS64::VisitIntegerReverseBytes(HInvoke* invoke) {
163 CreateIntToIntLocations(arena_, invoke);
164}
165
166void IntrinsicCodeGeneratorMIPS64::VisitIntegerReverseBytes(HInvoke* invoke) {
167 GenReverseBytes(invoke->GetLocations(), Primitive::kPrimInt, GetAssembler());
168}
169
170// long java.lang.Long.reverseBytes(long)
171void IntrinsicLocationsBuilderMIPS64::VisitLongReverseBytes(HInvoke* invoke) {
172 CreateIntToIntLocations(arena_, invoke);
173}
174
175void IntrinsicCodeGeneratorMIPS64::VisitLongReverseBytes(HInvoke* invoke) {
176 GenReverseBytes(invoke->GetLocations(), Primitive::kPrimLong, GetAssembler());
177}
178
179// short java.lang.Short.reverseBytes(short)
180void IntrinsicLocationsBuilderMIPS64::VisitShortReverseBytes(HInvoke* invoke) {
181 CreateIntToIntLocations(arena_, invoke);
182}
183
184void IntrinsicCodeGeneratorMIPS64::VisitShortReverseBytes(HInvoke* invoke) {
185 GenReverseBytes(invoke->GetLocations(), Primitive::kPrimShort, GetAssembler());
186}
187
188static void GenCountZeroes(LocationSummary* locations, bool is64bit, Mips64Assembler* assembler) {
189 GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>();
190 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
191
192 if (is64bit) {
193 __ Dclz(out, in);
194 } else {
195 __ Clz(out, in);
196 }
197}
198
199// int java.lang.Integer.numberOfLeadingZeros(int i)
200void IntrinsicLocationsBuilderMIPS64::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) {
201 CreateIntToIntLocations(arena_, invoke);
202}
203
204void IntrinsicCodeGeneratorMIPS64::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) {
205 GenCountZeroes(invoke->GetLocations(), false, GetAssembler());
206}
207
208// int java.lang.Long.numberOfLeadingZeros(long i)
209void IntrinsicLocationsBuilderMIPS64::VisitLongNumberOfLeadingZeros(HInvoke* invoke) {
210 CreateIntToIntLocations(arena_, invoke);
211}
212
213void IntrinsicCodeGeneratorMIPS64::VisitLongNumberOfLeadingZeros(HInvoke* invoke) {
214 GenCountZeroes(invoke->GetLocations(), true, GetAssembler());
215}
216
217static void GenReverse(LocationSummary* locations,
218 Primitive::Type type,
219 Mips64Assembler* assembler) {
220 DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong);
221
222 GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>();
223 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
224
225 if (type == Primitive::kPrimInt) {
226 __ Rotr(out, in, 16);
227 __ Wsbh(out, out);
228 __ Bitswap(out, out);
229 } else {
230 __ Dsbh(out, in);
231 __ Dshd(out, out);
232 __ Dbitswap(out, out);
233 }
234}
235
236// int java.lang.Integer.reverse(int)
237void IntrinsicLocationsBuilderMIPS64::VisitIntegerReverse(HInvoke* invoke) {
238 CreateIntToIntLocations(arena_, invoke);
239}
240
241void IntrinsicCodeGeneratorMIPS64::VisitIntegerReverse(HInvoke* invoke) {
242 GenReverse(invoke->GetLocations(), Primitive::kPrimInt, GetAssembler());
243}
244
245// long java.lang.Long.reverse(long)
246void IntrinsicLocationsBuilderMIPS64::VisitLongReverse(HInvoke* invoke) {
247 CreateIntToIntLocations(arena_, invoke);
248}
249
250void IntrinsicCodeGeneratorMIPS64::VisitLongReverse(HInvoke* invoke) {
251 GenReverse(invoke->GetLocations(), Primitive::kPrimLong, GetAssembler());
252}
253
254// Unimplemented intrinsics.
255
256#define UNIMPLEMENTED_INTRINSIC(Name) \
257void IntrinsicLocationsBuilderMIPS64::Visit ## Name(HInvoke* invoke ATTRIBUTE_UNUSED) { \
258} \
259void IntrinsicCodeGeneratorMIPS64::Visit ## Name(HInvoke* invoke ATTRIBUTE_UNUSED) { \
260}
261
262UNIMPLEMENTED_INTRINSIC(MathAbsDouble)
263UNIMPLEMENTED_INTRINSIC(MathAbsFloat)
264UNIMPLEMENTED_INTRINSIC(MathAbsInt)
265UNIMPLEMENTED_INTRINSIC(MathAbsLong)
266UNIMPLEMENTED_INTRINSIC(MathMinDoubleDouble)
267UNIMPLEMENTED_INTRINSIC(MathMinFloatFloat)
268UNIMPLEMENTED_INTRINSIC(MathMaxDoubleDouble)
269UNIMPLEMENTED_INTRINSIC(MathMaxFloatFloat)
270UNIMPLEMENTED_INTRINSIC(MathMinIntInt)
271UNIMPLEMENTED_INTRINSIC(MathMinLongLong)
272UNIMPLEMENTED_INTRINSIC(MathMaxIntInt)
273UNIMPLEMENTED_INTRINSIC(MathMaxLongLong)
274UNIMPLEMENTED_INTRINSIC(MathSqrt)
275UNIMPLEMENTED_INTRINSIC(MathCeil)
276UNIMPLEMENTED_INTRINSIC(MathFloor)
277UNIMPLEMENTED_INTRINSIC(MathRint)
278UNIMPLEMENTED_INTRINSIC(MathRoundDouble)
279UNIMPLEMENTED_INTRINSIC(MathRoundFloat)
280UNIMPLEMENTED_INTRINSIC(MemoryPeekByte)
281UNIMPLEMENTED_INTRINSIC(MemoryPeekIntNative)
282UNIMPLEMENTED_INTRINSIC(MemoryPeekLongNative)
283UNIMPLEMENTED_INTRINSIC(MemoryPeekShortNative)
284UNIMPLEMENTED_INTRINSIC(MemoryPokeByte)
285UNIMPLEMENTED_INTRINSIC(MemoryPokeIntNative)
286UNIMPLEMENTED_INTRINSIC(MemoryPokeLongNative)
287UNIMPLEMENTED_INTRINSIC(MemoryPokeShortNative)
288UNIMPLEMENTED_INTRINSIC(ThreadCurrentThread)
289UNIMPLEMENTED_INTRINSIC(UnsafeGet)
290UNIMPLEMENTED_INTRINSIC(UnsafeGetVolatile)
291UNIMPLEMENTED_INTRINSIC(UnsafeGetLong)
292UNIMPLEMENTED_INTRINSIC(UnsafeGetLongVolatile)
293UNIMPLEMENTED_INTRINSIC(UnsafeGetObject)
294UNIMPLEMENTED_INTRINSIC(UnsafeGetObjectVolatile)
295UNIMPLEMENTED_INTRINSIC(UnsafePut)
296UNIMPLEMENTED_INTRINSIC(UnsafePutOrdered)
297UNIMPLEMENTED_INTRINSIC(UnsafePutVolatile)
298UNIMPLEMENTED_INTRINSIC(UnsafePutObject)
299UNIMPLEMENTED_INTRINSIC(UnsafePutObjectOrdered)
300UNIMPLEMENTED_INTRINSIC(UnsafePutObjectVolatile)
301UNIMPLEMENTED_INTRINSIC(UnsafePutLong)
302UNIMPLEMENTED_INTRINSIC(UnsafePutLongOrdered)
303UNIMPLEMENTED_INTRINSIC(UnsafePutLongVolatile)
304UNIMPLEMENTED_INTRINSIC(UnsafeCASInt)
305UNIMPLEMENTED_INTRINSIC(UnsafeCASLong)
306UNIMPLEMENTED_INTRINSIC(UnsafeCASObject)
307UNIMPLEMENTED_INTRINSIC(StringCharAt)
308UNIMPLEMENTED_INTRINSIC(StringCompareTo)
309UNIMPLEMENTED_INTRINSIC(StringEquals)
310UNIMPLEMENTED_INTRINSIC(StringIndexOf)
311UNIMPLEMENTED_INTRINSIC(StringIndexOfAfter)
312UNIMPLEMENTED_INTRINSIC(StringNewStringFromBytes)
313UNIMPLEMENTED_INTRINSIC(StringNewStringFromChars)
314UNIMPLEMENTED_INTRINSIC(StringNewStringFromString)
315UNIMPLEMENTED_INTRINSIC(LongRotateLeft)
316UNIMPLEMENTED_INTRINSIC(LongRotateRight)
317UNIMPLEMENTED_INTRINSIC(LongNumberOfTrailingZeros)
318UNIMPLEMENTED_INTRINSIC(IntegerRotateLeft)
319UNIMPLEMENTED_INTRINSIC(IntegerRotateRight)
320UNIMPLEMENTED_INTRINSIC(IntegerNumberOfTrailingZeros)
321
322UNIMPLEMENTED_INTRINSIC(ReferenceGetReferent)
323UNIMPLEMENTED_INTRINSIC(StringGetCharsNoCheck)
324UNIMPLEMENTED_INTRINSIC(SystemArrayCopyChar)
325
326#undef UNIMPLEMENTED_INTRINSIC
327
328#undef __
329
330} // namespace mips64
331} // namespace art