blob: 46c90f89ac309d81e9e39ccdb8081515452fb76a [file] [log] [blame]
buzbeee3acd072012-02-25 17:03:10 -08001/*
2 * Copyright (C) 2012 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/*
18 * This file contains codegen for the Mips ISA and is intended to be
19 * includes by:
20 *
21 * Codegen-$(TARGET_ARCH_VARIANT).c
22 *
23 */
24
Ian Rogers57b86d42012-03-27 16:05:41 -070025#include "oat/runtime/oat_support_entrypoints.h"
26
buzbeee3acd072012-02-25 17:03:10 -080027namespace art {
28
buzbee16da88c2012-03-20 10:38:17 -070029void genSpecialCase(CompilationUnit* cUnit, BasicBlock* bb, MIR* mir,
30 SpecialCaseHandler specialCase)
31{
32 // TODO
33}
34
buzbeee3acd072012-02-25 17:03:10 -080035/*
buzbeec5159d52012-03-03 11:48:39 -080036 * The lack of pc-relative loads on Mips presents somewhat of a challenge
37 * for our PIC switch table strategy. To materialize the current location
38 * we'll do a dummy JAL and reference our tables using r_RA as the
39 * base register. Note that r_RA will be used both as the base to
40 * locate the switch table data and as the reference base for the switch
41 * target offsets stored in the table. We'll use a special pseudo-instruction
42 * to represent the jal and trigger the construction of the
43 * switch table offsets (which will happen after final assembly and all
44 * labels are fixed).
buzbeee3acd072012-02-25 17:03:10 -080045 *
46 * The test loop will look something like:
47 *
buzbeec5159d52012-03-03 11:48:39 -080048 * ori rEnd, r_ZERO, #tableSize ; size in bytes
49 * jal BaseLabel ; stores "return address" (BaseLabel) in r_RA
50 * nop ; opportunistically fill
51 * BaseLabel:
52 * addiu rBase, r_RA, <table> - <BaseLabel> ; table relative to BaseLabel
53 addu rEnd, rEnd, rBase ; end of table
54 * lw rVal, [rSP, vRegOff] ; Test Value
55 * loop:
56 * beq rBase, rEnd, done
57 * lw rKey, 0(rBase)
58 * addu rBase, 8
59 * bne rVal, rKey, loop
60 * lw rDisp, -4(rBase)
61 * addu r_RA, rDisp
62 * jr r_RA
63 * done:
64 *
buzbeee3acd072012-02-25 17:03:10 -080065 */
Ian Rogers55bd45f2012-04-04 17:31:20 -070066void genSparseSwitch(CompilationUnit* cUnit, MIR* mir, RegLocation rlSrc,
Bill Buzbeea114add2012-05-03 15:00:40 -070067 LIR* labelList)
buzbeee3acd072012-02-25 17:03:10 -080068{
Bill Buzbeea114add2012-05-03 15:00:40 -070069 const u2* table = cUnit->insns + mir->offset + mir->dalvikInsn.vB;
70 if (cUnit->printMe) {
71 dumpSparseSwitchTable(table);
72 }
73 // Add the table to the list - we'll process it later
74 SwitchTable *tabRec = (SwitchTable *)oatNew(cUnit, sizeof(SwitchTable),
75 true, kAllocData);
76 tabRec->table = table;
77 tabRec->vaddr = mir->offset;
78 int elements = table[1];
79 tabRec->targets = (LIR* *)oatNew(cUnit, elements * sizeof(LIR*), true,
80 kAllocLIR);
81 oatInsertGrowableList(cUnit, &cUnit->switchTables, (intptr_t)tabRec);
buzbeee3acd072012-02-25 17:03:10 -080082
Bill Buzbeea114add2012-05-03 15:00:40 -070083 // The table is composed of 8-byte key/disp pairs
84 int byteSize = elements * 8;
buzbeec5159d52012-03-03 11:48:39 -080085
Bill Buzbeea114add2012-05-03 15:00:40 -070086 int sizeHi = byteSize >> 16;
87 int sizeLo = byteSize & 0xffff;
buzbeec5159d52012-03-03 11:48:39 -080088
Bill Buzbeea114add2012-05-03 15:00:40 -070089 int rEnd = oatAllocTemp(cUnit);
90 if (sizeHi) {
91 newLIR2(cUnit, kMipsLui, rEnd, sizeHi);
92 }
93 // Must prevent code motion for the curr pc pair
94 genBarrier(cUnit); // Scheduling barrier
95 newLIR0(cUnit, kMipsCurrPC); // Really a jal to .+8
96 // Now, fill the branch delay slot
97 if (sizeHi) {
98 newLIR3(cUnit, kMipsOri, rEnd, rEnd, sizeLo);
99 } else {
100 newLIR3(cUnit, kMipsOri, rEnd, r_ZERO, sizeLo);
101 }
102 genBarrier(cUnit); // Scheduling barrier
buzbeec5159d52012-03-03 11:48:39 -0800103
Bill Buzbeea114add2012-05-03 15:00:40 -0700104 // Construct BaseLabel and set up table base register
105 LIR* baseLabel = newLIR0(cUnit, kPseudoTargetLabel);
106 // Remember base label so offsets can be computed later
107 tabRec->anchor = baseLabel;
108 int rBase = oatAllocTemp(cUnit);
109 newLIR4(cUnit, kMipsDelta, rBase, 0, (intptr_t)baseLabel, (intptr_t)tabRec);
110 opRegRegReg(cUnit, kOpAdd, rEnd, rEnd, rBase);
buzbeec5159d52012-03-03 11:48:39 -0800111
Bill Buzbeea114add2012-05-03 15:00:40 -0700112 // Grab switch test value
113 rlSrc = loadValue(cUnit, rlSrc, kCoreReg);
buzbeec5159d52012-03-03 11:48:39 -0800114
Bill Buzbeea114add2012-05-03 15:00:40 -0700115 // Test loop
116 int rKey = oatAllocTemp(cUnit);
117 LIR* loopLabel = newLIR0(cUnit, kPseudoTargetLabel);
118 LIR* exitBranch = opCmpBranch(cUnit , kCondEq, rBase, rEnd, NULL);
119 loadWordDisp(cUnit, rBase, 0, rKey);
120 opRegImm(cUnit, kOpAdd, rBase, 8);
121 opCmpBranch(cUnit, kCondNe, rlSrc.lowReg, rKey, loopLabel);
122 int rDisp = oatAllocTemp(cUnit);
123 loadWordDisp(cUnit, rBase, -4, rDisp);
124 opRegRegReg(cUnit, kOpAdd, r_RA, r_RA, rDisp);
125 opReg(cUnit, kOpBx, r_RA);
buzbeec5159d52012-03-03 11:48:39 -0800126
Bill Buzbeea114add2012-05-03 15:00:40 -0700127 // Loop exit
128 LIR* exitLabel = newLIR0(cUnit, kPseudoTargetLabel);
129 exitBranch->target = exitLabel;
buzbeee3acd072012-02-25 17:03:10 -0800130}
131
buzbeec5159d52012-03-03 11:48:39 -0800132/*
133 * Code pattern will look something like:
134 *
135 * lw rVal
136 * jal BaseLabel ; stores "return address" (BaseLabel) in r_RA
137 * nop ; opportunistically fill
138 * [subiu rVal, bias] ; Remove bias if lowVal != 0
139 * bound check -> done
140 * lw rDisp, [r_RA, rVal]
141 * addu r_RA, rDisp
142 * jr r_RA
143 * done:
144 */
buzbee5de34942012-03-01 14:51:57 -0800145void genPackedSwitch(CompilationUnit* cUnit, MIR* mir, RegLocation rlSrc)
buzbeee3acd072012-02-25 17:03:10 -0800146{
Bill Buzbeea114add2012-05-03 15:00:40 -0700147 const u2* table = cUnit->insns + mir->offset + mir->dalvikInsn.vB;
148 if (cUnit->printMe) {
149 dumpPackedSwitchTable(table);
150 }
151 // Add the table to the list - we'll process it later
152 SwitchTable *tabRec = (SwitchTable *)oatNew(cUnit, sizeof(SwitchTable),
153 true, kAllocData);
154 tabRec->table = table;
155 tabRec->vaddr = mir->offset;
156 int size = table[1];
157 tabRec->targets = (LIR* *)oatNew(cUnit, size * sizeof(LIR*), true,
158 kAllocLIR);
159 oatInsertGrowableList(cUnit, &cUnit->switchTables, (intptr_t)tabRec);
buzbeee3acd072012-02-25 17:03:10 -0800160
Bill Buzbeea114add2012-05-03 15:00:40 -0700161 // Get the switch value
162 rlSrc = loadValue(cUnit, rlSrc, kCoreReg);
buzbeec5159d52012-03-03 11:48:39 -0800163
Bill Buzbeea114add2012-05-03 15:00:40 -0700164 // Prepare the bias. If too big, handle 1st stage here
165 int lowKey = s4FromSwitchData(&table[2]);
166 bool largeBias = false;
167 int rKey;
168 if (lowKey == 0) {
169 rKey = rlSrc.lowReg;
170 } else if ((lowKey & 0xffff) != lowKey) {
171 rKey = oatAllocTemp(cUnit);
172 loadConstant(cUnit, rKey, lowKey);
173 largeBias = true;
174 } else {
175 rKey = oatAllocTemp(cUnit);
176 }
177
178 // Must prevent code motion for the curr pc pair
179 genBarrier(cUnit);
180 newLIR0(cUnit, kMipsCurrPC); // Really a jal to .+8
181 // Now, fill the branch delay slot with bias strip
182 if (lowKey == 0) {
183 newLIR0(cUnit, kMipsNop);
184 } else {
185 if (largeBias) {
186 opRegRegReg(cUnit, kOpSub, rKey, rlSrc.lowReg, rKey);
buzbeee3acd072012-02-25 17:03:10 -0800187 } else {
Bill Buzbeea114add2012-05-03 15:00:40 -0700188 opRegRegImm(cUnit, kOpSub, rKey, rlSrc.lowReg, lowKey);
buzbeee3acd072012-02-25 17:03:10 -0800189 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700190 }
191 genBarrier(cUnit); // Scheduling barrier
buzbeec5159d52012-03-03 11:48:39 -0800192
Bill Buzbeea114add2012-05-03 15:00:40 -0700193 // Construct BaseLabel and set up table base register
194 LIR* baseLabel = newLIR0(cUnit, kPseudoTargetLabel);
195 // Remember base label so offsets can be computed later
196 tabRec->anchor = baseLabel;
buzbeec5159d52012-03-03 11:48:39 -0800197
Bill Buzbeea114add2012-05-03 15:00:40 -0700198 // Bounds check - if < 0 or >= size continue following switch
199 LIR* branchOver = opCmpImmBranch(cUnit, kCondHi, rKey, size-1, NULL);
buzbeec5159d52012-03-03 11:48:39 -0800200
Bill Buzbeea114add2012-05-03 15:00:40 -0700201 // Materialize the table base pointer
202 int rBase = oatAllocTemp(cUnit);
203 newLIR4(cUnit, kMipsDelta, rBase, 0, (intptr_t)baseLabel, (intptr_t)tabRec);
buzbeec5159d52012-03-03 11:48:39 -0800204
Bill Buzbeea114add2012-05-03 15:00:40 -0700205 // Load the displacement from the switch table
206 int rDisp = oatAllocTemp(cUnit);
207 loadBaseIndexed(cUnit, rBase, rKey, rDisp, 2, kWord);
buzbeee3acd072012-02-25 17:03:10 -0800208
Bill Buzbeea114add2012-05-03 15:00:40 -0700209 // Add to r_AP and go
210 opRegRegReg(cUnit, kOpAdd, r_RA, r_RA, rDisp);
211 opReg(cUnit, kOpBx, r_RA);
buzbeee3acd072012-02-25 17:03:10 -0800212
Bill Buzbeea114add2012-05-03 15:00:40 -0700213 /* branchOver target here */
214 LIR* target = newLIR0(cUnit, kPseudoTargetLabel);
215 branchOver->target = (LIR*)target;
buzbeee3acd072012-02-25 17:03:10 -0800216}
217
218/*
219 * Array data table format:
220 * ushort ident = 0x0300 magic value
221 * ushort width width of each element in the table
222 * uint size number of elements in the table
223 * ubyte data[size*width] table of data values (may contain a single-byte
224 * padding at the end)
225 *
226 * Total size is 4+(width * size + 1)/2 16-bit code units.
227 */
buzbee5de34942012-03-01 14:51:57 -0800228void genFillArrayData(CompilationUnit* cUnit, MIR* mir, RegLocation rlSrc)
buzbeee3acd072012-02-25 17:03:10 -0800229{
Bill Buzbeea114add2012-05-03 15:00:40 -0700230 const u2* table = cUnit->insns + mir->offset + mir->dalvikInsn.vB;
231 // Add the table to the list - we'll process it later
232 FillArrayData *tabRec = (FillArrayData *)
233 oatNew(cUnit, sizeof(FillArrayData), true, kAllocData);
234 tabRec->table = table;
235 tabRec->vaddr = mir->offset;
236 u2 width = tabRec->table[1];
237 u4 size = tabRec->table[2] | (((u4)tabRec->table[3]) << 16);
238 tabRec->size = (size * width) + 8;
buzbeee3acd072012-02-25 17:03:10 -0800239
Bill Buzbeea114add2012-05-03 15:00:40 -0700240 oatInsertGrowableList(cUnit, &cUnit->fillArrayData, (intptr_t)tabRec);
buzbeee3acd072012-02-25 17:03:10 -0800241
Bill Buzbeea114add2012-05-03 15:00:40 -0700242 // Making a call - use explicit registers
243 oatFlushAllRegs(cUnit); /* Everything to home location */
244 oatLockCallTemps(cUnit);
245 loadValueDirectFixed(cUnit, rlSrc, rARG0);
buzbeec5159d52012-03-03 11:48:39 -0800246
Bill Buzbeea114add2012-05-03 15:00:40 -0700247 // Must prevent code motion for the curr pc pair
248 genBarrier(cUnit);
249 newLIR0(cUnit, kMipsCurrPC); // Really a jal to .+8
250 // Now, fill the branch delay slot with the helper load
251 int rTgt = loadHelper(cUnit, ENTRYPOINT_OFFSET(pHandleFillArrayDataFromCode));
252 genBarrier(cUnit); // Scheduling barrier
buzbeec5159d52012-03-03 11:48:39 -0800253
Bill Buzbeea114add2012-05-03 15:00:40 -0700254 // Construct BaseLabel and set up table base register
255 LIR* baseLabel = newLIR0(cUnit, kPseudoTargetLabel);
buzbeec5159d52012-03-03 11:48:39 -0800256
Bill Buzbeea114add2012-05-03 15:00:40 -0700257 // Materialize a pointer to the fill data image
258 newLIR4(cUnit, kMipsDelta, rARG1, 0, (intptr_t)baseLabel, (intptr_t)tabRec);
buzbeec5159d52012-03-03 11:48:39 -0800259
Bill Buzbeea114add2012-05-03 15:00:40 -0700260 // And go...
261 oatClobberCalleeSave(cUnit);
262 opReg(cUnit, kOpBlx, rTgt); // ( array*, fill_data* )
buzbeee3acd072012-02-25 17:03:10 -0800263}
264
buzbee71ac9942012-03-01 17:23:10 -0800265void genNegFloat(CompilationUnit *cUnit, RegLocation rlDest, RegLocation rlSrc)
266{
Bill Buzbeea114add2012-05-03 15:00:40 -0700267 RegLocation rlResult;
268 rlSrc = loadValue(cUnit, rlSrc, kCoreReg);
269 rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
270 opRegRegImm(cUnit, kOpAdd, rlResult.lowReg, rlSrc.lowReg, 0x80000000);
271 storeValue(cUnit, rlDest, rlResult);
buzbee71ac9942012-03-01 17:23:10 -0800272}
273
274void genNegDouble(CompilationUnit *cUnit, RegLocation rlDest, RegLocation rlSrc)
275{
Bill Buzbeea114add2012-05-03 15:00:40 -0700276 RegLocation rlResult;
277 rlSrc = loadValueWide(cUnit, rlSrc, kCoreReg);
278 rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
279 opRegRegImm(cUnit, kOpAdd, rlResult.highReg, rlSrc.highReg, 0x80000000);
280 opRegCopy(cUnit, rlResult.lowReg, rlSrc.lowReg);
281 storeValueWide(cUnit, rlDest, rlResult);
buzbee71ac9942012-03-01 17:23:10 -0800282}
283
buzbee5de34942012-03-01 14:51:57 -0800284/*
285 * TODO: implement fast path to short-circuit thin-lock case
286 */
287void genMonitorEnter(CompilationUnit* cUnit, MIR* mir, RegLocation rlSrc)
buzbeee3acd072012-02-25 17:03:10 -0800288{
Bill Buzbeea114add2012-05-03 15:00:40 -0700289 oatFlushAllRegs(cUnit);
290 loadValueDirectFixed(cUnit, rlSrc, rARG0); // Get obj
291 oatLockCallTemps(cUnit); // Prepare for explicit register usage
292 genNullCheck(cUnit, rlSrc.sRegLow, rARG0, mir);
293 // Go expensive route - artLockObjectFromCode(self, obj);
294 int rTgt = loadHelper(cUnit, ENTRYPOINT_OFFSET(pLockObjectFromCode));
295 oatClobberCalleeSave(cUnit);
296 opReg(cUnit, kOpBlx, rTgt);
buzbeee3acd072012-02-25 17:03:10 -0800297}
298
299/*
buzbee5de34942012-03-01 14:51:57 -0800300 * TODO: implement fast path to short-circuit thin-lock case
buzbeee3acd072012-02-25 17:03:10 -0800301 */
buzbee5de34942012-03-01 14:51:57 -0800302void genMonitorExit(CompilationUnit* cUnit, MIR* mir, RegLocation rlSrc)
buzbeee3acd072012-02-25 17:03:10 -0800303{
Bill Buzbeea114add2012-05-03 15:00:40 -0700304 oatFlushAllRegs(cUnit);
305 loadValueDirectFixed(cUnit, rlSrc, rARG0); // Get obj
306 oatLockCallTemps(cUnit); // Prepare for explicit register usage
307 genNullCheck(cUnit, rlSrc.sRegLow, rARG0, mir);
308 // Go expensive route - UnlockObjectFromCode(obj);
309 int rTgt = loadHelper(cUnit, ENTRYPOINT_OFFSET(pUnlockObjectFromCode));
310 oatClobberCalleeSave(cUnit);
311 opReg(cUnit, kOpBlx, rTgt);
buzbee5de34942012-03-01 14:51:57 -0800312}
313
314/*
315 * Compare two 64-bit values
316 * x = y return 0
317 * x < y return -1
318 * x > y return 1
319 *
320 * slt t0, x.hi, y.hi; # (x.hi < y.hi) ? 1:0
321 * sgt t1, x.hi, y.hi; # (y.hi > x.hi) ? 1:0
322 * subu res, t0, t1 # res = -1:1:0 for [ < > = ]
323 * bnez res, finish
324 * sltu t0, x.lo, y.lo
325 * sgtu r1, x.lo, y.lo
326 * subu res, t0, t1
327 * finish:
328 *
329 */
330void genCmpLong(CompilationUnit* cUnit, MIR* mir, RegLocation rlDest,
Bill Buzbeea114add2012-05-03 15:00:40 -0700331 RegLocation rlSrc1, RegLocation rlSrc2)
buzbee5de34942012-03-01 14:51:57 -0800332{
Bill Buzbeea114add2012-05-03 15:00:40 -0700333 rlSrc1 = loadValueWide(cUnit, rlSrc1, kCoreReg);
334 rlSrc2 = loadValueWide(cUnit, rlSrc2, kCoreReg);
335 int t0 = oatAllocTemp(cUnit);
336 int t1 = oatAllocTemp(cUnit);
337 RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
338 newLIR3(cUnit, kMipsSlt, t0, rlSrc1.highReg, rlSrc2.highReg);
339 newLIR3(cUnit, kMipsSlt, t1, rlSrc2.highReg, rlSrc1.highReg);
340 newLIR3(cUnit, kMipsSubu, rlResult.lowReg, t1, t0);
341 LIR* branch = opCmpImmBranch(cUnit, kCondNe, rlResult.lowReg, 0, NULL);
342 newLIR3(cUnit, kMipsSltu, t0, rlSrc1.lowReg, rlSrc2.lowReg);
343 newLIR3(cUnit, kMipsSltu, t1, rlSrc2.lowReg, rlSrc1.lowReg);
344 newLIR3(cUnit, kMipsSubu, rlResult.lowReg, t1, t0);
345 oatFreeTemp(cUnit, t0);
346 oatFreeTemp(cUnit, t1);
347 LIR* target = newLIR0(cUnit, kPseudoTargetLabel);
348 branch->target = (LIR*)target;
349 storeValue(cUnit, rlDest, rlResult);
buzbeee3acd072012-02-25 17:03:10 -0800350}
351
buzbee82488f52012-03-02 08:20:26 -0800352LIR* opCmpBranch(CompilationUnit* cUnit, ConditionCode cond, int src1,
Bill Buzbeea114add2012-05-03 15:00:40 -0700353 int src2, LIR* target)
buzbeee3acd072012-02-25 17:03:10 -0800354{
Bill Buzbeea114add2012-05-03 15:00:40 -0700355 LIR* branch;
356 MipsOpCode sltOp;
357 MipsOpCode brOp;
358 bool cmpZero = false;
359 bool swapped = false;
360 switch (cond) {
361 case kCondEq:
362 brOp = kMipsBeq;
363 cmpZero = true;
364 break;
365 case kCondNe:
366 brOp = kMipsBne;
367 cmpZero = true;
368 break;
369 case kCondCc:
370 sltOp = kMipsSltu;
371 brOp = kMipsBnez;
372 break;
373 case kCondCs:
374 sltOp = kMipsSltu;
375 brOp = kMipsBeqz;
376 break;
377 case kCondGe:
378 sltOp = kMipsSlt;
379 brOp = kMipsBeqz;
380 break;
381 case kCondGt:
382 sltOp = kMipsSlt;
383 brOp = kMipsBnez;
384 swapped = true;
385 break;
386 case kCondLe:
387 sltOp = kMipsSlt;
388 brOp = kMipsBeqz;
389 swapped = true;
390 break;
391 case kCondLt:
392 sltOp = kMipsSlt;
393 brOp = kMipsBnez;
394 break;
395 case kCondHi: // Gtu
396 sltOp = kMipsSltu;
397 brOp = kMipsBnez;
398 swapped = true;
399 break;
400 default:
401 LOG(FATAL) << "No support for ConditionCode: " << (int) cond;
402 return NULL;
403 }
404 if (cmpZero) {
405 branch = newLIR2(cUnit, brOp, src1, src2);
406 } else {
407 int tReg = oatAllocTemp(cUnit);
408 if (swapped) {
409 newLIR3(cUnit, sltOp, tReg, src2, src1);
buzbee82488f52012-03-02 08:20:26 -0800410 } else {
Bill Buzbeea114add2012-05-03 15:00:40 -0700411 newLIR3(cUnit, sltOp, tReg, src1, src2);
buzbee5de34942012-03-01 14:51:57 -0800412 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700413 branch = newLIR1(cUnit, brOp, tReg);
414 oatFreeTemp(cUnit, tReg);
415 }
416 branch->target = target;
417 return branch;
buzbeee3acd072012-02-25 17:03:10 -0800418}
419
buzbee82488f52012-03-02 08:20:26 -0800420LIR* opCmpImmBranch(CompilationUnit* cUnit, ConditionCode cond, int reg,
Bill Buzbeea114add2012-05-03 15:00:40 -0700421 int checkValue, LIR* target)
buzbeee3acd072012-02-25 17:03:10 -0800422{
Bill Buzbeea114add2012-05-03 15:00:40 -0700423 LIR* branch;
424 if (checkValue != 0) {
425 // TUNING: handle s16 & kCondLt/Mi case using slti
426 int tReg = oatAllocTemp(cUnit);
427 loadConstant(cUnit, tReg, checkValue);
428 branch = opCmpBranch(cUnit, cond, reg, tReg, target);
429 oatFreeTemp(cUnit, tReg);
buzbee82488f52012-03-02 08:20:26 -0800430 return branch;
Bill Buzbeea114add2012-05-03 15:00:40 -0700431 }
432 MipsOpCode opc;
433 switch (cond) {
434 case kCondEq: opc = kMipsBeqz; break;
435 case kCondGe: opc = kMipsBgez; break;
436 case kCondGt: opc = kMipsBgtz; break;
437 case kCondLe: opc = kMipsBlez; break;
438 //case KCondMi:
439 case kCondLt: opc = kMipsBltz; break;
440 case kCondNe: opc = kMipsBnez; break;
441 default:
442 // Tuning: use slti when applicable
443 int tReg = oatAllocTemp(cUnit);
444 loadConstant(cUnit, tReg, checkValue);
445 branch = opCmpBranch(cUnit, cond, reg, tReg, target);
446 oatFreeTemp(cUnit, tReg);
447 return branch;
448 }
449 branch = newLIR1(cUnit, opc, reg);
450 branch->target = target;
451 return branch;
buzbeee3acd072012-02-25 17:03:10 -0800452}
453
buzbee82488f52012-03-02 08:20:26 -0800454LIR* opRegCopyNoInsert(CompilationUnit *cUnit, int rDest, int rSrc)
buzbeee3acd072012-02-25 17:03:10 -0800455{
buzbeee3acd072012-02-25 17:03:10 -0800456#ifdef __mips_hard_float
Bill Buzbeea114add2012-05-03 15:00:40 -0700457 if (FPREG(rDest) || FPREG(rSrc))
458 return fpRegCopy(cUnit, rDest, rSrc);
buzbee5de34942012-03-01 14:51:57 -0800459#endif
Bill Buzbeea114add2012-05-03 15:00:40 -0700460 LIR* res = rawLIR(cUnit, cUnit->currentDalvikOffset, kMipsMove,
461 rDest, rSrc);
462 if (!(cUnit->disableOpt & (1 << kSafeOptimizations)) && rDest == rSrc) {
463 res->flags.isNop = true;
464 }
465 return res;
buzbee5de34942012-03-01 14:51:57 -0800466}
467
buzbee82488f52012-03-02 08:20:26 -0800468LIR* opRegCopy(CompilationUnit *cUnit, int rDest, int rSrc)
buzbee5de34942012-03-01 14:51:57 -0800469{
Bill Buzbeea114add2012-05-03 15:00:40 -0700470 LIR *res = opRegCopyNoInsert(cUnit, rDest, rSrc);
471 oatAppendLIR(cUnit, (LIR*)res);
472 return res;
buzbee5de34942012-03-01 14:51:57 -0800473}
474
buzbee82488f52012-03-02 08:20:26 -0800475void opRegCopyWide(CompilationUnit *cUnit, int destLo, int destHi,
Bill Buzbeea114add2012-05-03 15:00:40 -0700476 int srcLo, int srcHi)
buzbee5de34942012-03-01 14:51:57 -0800477{
478#ifdef __mips_hard_float
Bill Buzbeea114add2012-05-03 15:00:40 -0700479 bool destFP = FPREG(destLo) && FPREG(destHi);
480 bool srcFP = FPREG(srcLo) && FPREG(srcHi);
481 assert(FPREG(srcLo) == FPREG(srcHi));
482 assert(FPREG(destLo) == FPREG(destHi));
483 if (destFP) {
484 if (srcFP) {
485 opRegCopy(cUnit, S2D(destLo, destHi), S2D(srcLo, srcHi));
buzbee5de34942012-03-01 14:51:57 -0800486 } else {
Bill Buzbeea114add2012-05-03 15:00:40 -0700487 /* note the operands are swapped for the mtc1 instr */
488 newLIR2(cUnit, kMipsMtc1, srcLo, destLo);
489 newLIR2(cUnit, kMipsMtc1, srcHi, destHi);
buzbee5de34942012-03-01 14:51:57 -0800490 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700491 } else {
492 if (srcFP) {
493 newLIR2(cUnit, kMipsMfc1, destLo, srcLo);
494 newLIR2(cUnit, kMipsMfc1, destHi, srcHi);
495 } else {
496 // Handle overlap
497 if (srcHi == destLo) {
498 opRegCopy(cUnit, destHi, srcHi);
499 opRegCopy(cUnit, destLo, srcLo);
500 } else {
501 opRegCopy(cUnit, destLo, srcLo);
502 opRegCopy(cUnit, destHi, srcHi);
503 }
504 }
505 }
buzbeee3acd072012-02-25 17:03:10 -0800506#else
Bill Buzbeea114add2012-05-03 15:00:40 -0700507 // Handle overlap
508 if (srcHi == destLo) {
509 opRegCopy(cUnit, destHi, srcHi);
510 opRegCopy(cUnit, destLo, srcLo);
511 } else {
512 opRegCopy(cUnit, destLo, srcLo);
513 opRegCopy(cUnit, destHi, srcHi);
514 }
buzbeee3acd072012-02-25 17:03:10 -0800515#endif
buzbeee3acd072012-02-25 17:03:10 -0800516}
517
518} // namespace art