blob: 268a88d9d32878983f39de6c2d049ccf80df216e [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
Ian Rogers57b86d42012-03-27 16:05:41 -070017#include "oat/runtime/oat_support_entrypoints.h"
buzbee1bc37c62012-11-20 13:35:41 -080018#include "mips_lir.h"
19#include "../codegen_util.h"
20#include "../ralloc_util.h"
Ian Rogers57b86d42012-03-27 16:05:41 -070021
buzbeee3acd072012-02-25 17:03:10 -080022namespace art {
23
buzbee408ad162012-06-06 16:45:18 -070024bool genArithOpFloat(CompilationUnit *cUnit, Instruction::Code opcode, RegLocation rlDest,
buzbee5de34942012-03-01 14:51:57 -080025 RegLocation rlSrc1, RegLocation rlSrc2)
buzbeee3acd072012-02-25 17:03:10 -080026{
27#ifdef __mips_hard_float
Bill Buzbeea114add2012-05-03 15:00:40 -070028 int op = kMipsNop;
29 RegLocation rlResult;
buzbeee3acd072012-02-25 17:03:10 -080030
Bill Buzbeea114add2012-05-03 15:00:40 -070031 /*
32 * Don't attempt to optimize register usage since these opcodes call out to
33 * the handlers.
34 */
buzbee408ad162012-06-06 16:45:18 -070035 switch (opcode) {
Bill Buzbeea114add2012-05-03 15:00:40 -070036 case Instruction::ADD_FLOAT_2ADDR:
37 case Instruction::ADD_FLOAT:
38 op = kMipsFadds;
39 break;
40 case Instruction::SUB_FLOAT_2ADDR:
41 case Instruction::SUB_FLOAT:
42 op = kMipsFsubs;
43 break;
44 case Instruction::DIV_FLOAT_2ADDR:
45 case Instruction::DIV_FLOAT:
46 op = kMipsFdivs;
47 break;
48 case Instruction::MUL_FLOAT_2ADDR:
49 case Instruction::MUL_FLOAT:
50 op = kMipsFmuls;
51 break;
52 case Instruction::REM_FLOAT_2ADDR:
53 case Instruction::REM_FLOAT:
54 case Instruction::NEG_FLOAT: {
buzbee408ad162012-06-06 16:45:18 -070055 return genArithOpFloatPortable(cUnit, opcode, rlDest, rlSrc1, rlSrc2);
buzbeee3acd072012-02-25 17:03:10 -080056 }
Bill Buzbeea114add2012-05-03 15:00:40 -070057 default:
58 return true;
59 }
60 rlSrc1 = loadValue(cUnit, rlSrc1, kFPReg);
61 rlSrc2 = loadValue(cUnit, rlSrc2, kFPReg);
62 rlResult = oatEvalLoc(cUnit, rlDest, kFPReg, true);
buzbeecbd6d442012-11-17 14:11:25 -080063 newLIR3(cUnit, op, rlResult.lowReg, rlSrc1.lowReg, rlSrc2.lowReg);
Bill Buzbeea114add2012-05-03 15:00:40 -070064 storeValue(cUnit, rlDest, rlResult);
buzbeee3acd072012-02-25 17:03:10 -080065
Bill Buzbeea114add2012-05-03 15:00:40 -070066 return false;
buzbeee3acd072012-02-25 17:03:10 -080067#else
buzbee408ad162012-06-06 16:45:18 -070068 return genArithOpFloatPortable(cUnit, opcode, rlDest, rlSrc1, rlSrc2);
buzbeee3acd072012-02-25 17:03:10 -080069#endif
70}
71
buzbeeeaf09bc2012-11-15 14:51:41 -080072bool genArithOpDouble(CompilationUnit *cUnit, Instruction::Code opcode,
73 RegLocation rlDest, RegLocation rlSrc1, RegLocation rlSrc2)
buzbeee3acd072012-02-25 17:03:10 -080074{
75#ifdef __mips_hard_float
Bill Buzbeea114add2012-05-03 15:00:40 -070076 int op = kMipsNop;
77 RegLocation rlResult;
buzbeee3acd072012-02-25 17:03:10 -080078
buzbee408ad162012-06-06 16:45:18 -070079 switch (opcode) {
Bill Buzbeea114add2012-05-03 15:00:40 -070080 case Instruction::ADD_DOUBLE_2ADDR:
81 case Instruction::ADD_DOUBLE:
82 op = kMipsFaddd;
83 break;
84 case Instruction::SUB_DOUBLE_2ADDR:
85 case Instruction::SUB_DOUBLE:
86 op = kMipsFsubd;
87 break;
88 case Instruction::DIV_DOUBLE_2ADDR:
89 case Instruction::DIV_DOUBLE:
90 op = kMipsFdivd;
91 break;
92 case Instruction::MUL_DOUBLE_2ADDR:
93 case Instruction::MUL_DOUBLE:
94 op = kMipsFmuld;
95 break;
96 case Instruction::REM_DOUBLE_2ADDR:
97 case Instruction::REM_DOUBLE:
98 case Instruction::NEG_DOUBLE: {
buzbee408ad162012-06-06 16:45:18 -070099 return genArithOpDoublePortable(cUnit, opcode, rlDest, rlSrc1, rlSrc2);
buzbeee3acd072012-02-25 17:03:10 -0800100 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700101 default:
102 return true;
103 }
104 rlSrc1 = loadValueWide(cUnit, rlSrc1, kFPReg);
105 DCHECK(rlSrc1.wide);
106 rlSrc2 = loadValueWide(cUnit, rlSrc2, kFPReg);
107 DCHECK(rlSrc2.wide);
108 rlResult = oatEvalLoc(cUnit, rlDest, kFPReg, true);
109 DCHECK(rlDest.wide);
110 DCHECK(rlResult.wide);
buzbeecbd6d442012-11-17 14:11:25 -0800111 newLIR3(cUnit, op, s2d(rlResult.lowReg, rlResult.highReg), s2d(rlSrc1.lowReg, rlSrc1.highReg),
buzbeef0504cd2012-11-13 16:31:10 -0800112 s2d(rlSrc2.lowReg, rlSrc2.highReg));
Bill Buzbeea114add2012-05-03 15:00:40 -0700113 storeValueWide(cUnit, rlDest, rlResult);
114 return false;
buzbeee3acd072012-02-25 17:03:10 -0800115#else
buzbee408ad162012-06-06 16:45:18 -0700116 return genArithOpDoublePortable(cUnit, opcode, rlDest, rlSrc1, rlSrc2);
buzbeee3acd072012-02-25 17:03:10 -0800117#endif
118}
119
buzbeeeaf09bc2012-11-15 14:51:41 -0800120bool genConversion(CompilationUnit *cUnit, Instruction::Code opcode, RegLocation rlDest,
121 RegLocation rlSrc)
buzbeee3acd072012-02-25 17:03:10 -0800122{
buzbee5de34942012-03-01 14:51:57 -0800123#ifdef __mips_hard_float
Bill Buzbeea114add2012-05-03 15:00:40 -0700124 int op = kMipsNop;
125 int srcReg;
126 RegLocation rlResult;
127 switch (opcode) {
128 case Instruction::INT_TO_FLOAT:
Bill Buzbeea114add2012-05-03 15:00:40 -0700129 op = kMipsFcvtsw;
130 break;
131 case Instruction::DOUBLE_TO_FLOAT:
Bill Buzbeea114add2012-05-03 15:00:40 -0700132 op = kMipsFcvtsd;
133 break;
134 case Instruction::FLOAT_TO_DOUBLE:
Bill Buzbeea114add2012-05-03 15:00:40 -0700135 op = kMipsFcvtds;
136 break;
137 case Instruction::INT_TO_DOUBLE:
Bill Buzbeea114add2012-05-03 15:00:40 -0700138 op = kMipsFcvtdw;
139 break;
140 case Instruction::FLOAT_TO_INT:
141 case Instruction::DOUBLE_TO_INT:
142 case Instruction::LONG_TO_DOUBLE:
143 case Instruction::FLOAT_TO_LONG:
144 case Instruction::LONG_TO_FLOAT:
145 case Instruction::DOUBLE_TO_LONG:
buzbee408ad162012-06-06 16:45:18 -0700146 return genConversionPortable(cUnit, opcode, rlDest, rlSrc);
Bill Buzbeea114add2012-05-03 15:00:40 -0700147 default:
148 return true;
149 }
buzbee408ad162012-06-06 16:45:18 -0700150 if (rlSrc.wide) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700151 rlSrc = loadValueWide(cUnit, rlSrc, kFPReg);
buzbeef0504cd2012-11-13 16:31:10 -0800152 srcReg = s2d(rlSrc.lowReg, rlSrc.highReg);
Bill Buzbeea114add2012-05-03 15:00:40 -0700153 } else {
Bill Buzbeea114add2012-05-03 15:00:40 -0700154 rlSrc = loadValue(cUnit, rlSrc, kFPReg);
155 srcReg = rlSrc.lowReg;
156 }
buzbee408ad162012-06-06 16:45:18 -0700157 if (rlDest.wide) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700158 rlResult = oatEvalLoc(cUnit, rlDest, kFPReg, true);
buzbeecbd6d442012-11-17 14:11:25 -0800159 newLIR2(cUnit, op, s2d(rlResult.lowReg, rlResult.highReg), srcReg);
Bill Buzbeea114add2012-05-03 15:00:40 -0700160 storeValueWide(cUnit, rlDest, rlResult);
161 } else {
Bill Buzbeea114add2012-05-03 15:00:40 -0700162 rlResult = oatEvalLoc(cUnit, rlDest, kFPReg, true);
buzbeecbd6d442012-11-17 14:11:25 -0800163 newLIR2(cUnit, op, rlResult.lowReg, srcReg);
Bill Buzbeea114add2012-05-03 15:00:40 -0700164 storeValue(cUnit, rlDest, rlResult);
165 }
166 return false;
buzbeee3acd072012-02-25 17:03:10 -0800167#else
buzbee408ad162012-06-06 16:45:18 -0700168 return genConversionPortable(cUnit, opcode, rlDest, rlSrc);
buzbeee3acd072012-02-25 17:03:10 -0800169#endif
170}
171
buzbeeeaf09bc2012-11-15 14:51:41 -0800172bool genCmpFP(CompilationUnit *cUnit, Instruction::Code opcode, RegLocation rlDest,
173 RegLocation rlSrc1, RegLocation rlSrc2)
buzbeee3acd072012-02-25 17:03:10 -0800174{
Bill Buzbeea114add2012-05-03 15:00:40 -0700175 bool wide = true;
176 int offset;
buzbeee3acd072012-02-25 17:03:10 -0800177
buzbee408ad162012-06-06 16:45:18 -0700178 switch (opcode) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700179 case Instruction::CMPL_FLOAT:
180 offset = ENTRYPOINT_OFFSET(pCmplFloat);
181 wide = false;
182 break;
183 case Instruction::CMPG_FLOAT:
184 offset = ENTRYPOINT_OFFSET(pCmpgFloat);
185 wide = false;
186 break;
187 case Instruction::CMPL_DOUBLE:
188 offset = ENTRYPOINT_OFFSET(pCmplDouble);
189 break;
190 case Instruction::CMPG_DOUBLE:
191 offset = ENTRYPOINT_OFFSET(pCmpgDouble);
192 break;
193 default:
194 return true;
195 }
196 oatFlushAllRegs(cUnit);
197 oatLockCallTemps(cUnit);
198 if (wide) {
buzbeef0504cd2012-11-13 16:31:10 -0800199 loadValueDirectWideFixed(cUnit, rlSrc1, rMIPS_FARG0, rMIPS_FARG1);
200 loadValueDirectWideFixed(cUnit, rlSrc2, rMIPS_FARG2, rMIPS_FARG3);
Bill Buzbeea114add2012-05-03 15:00:40 -0700201 } else {
buzbeef0504cd2012-11-13 16:31:10 -0800202 loadValueDirectFixed(cUnit, rlSrc1, rMIPS_FARG0);
203 loadValueDirectFixed(cUnit, rlSrc2, rMIPS_FARG2);
Bill Buzbeea114add2012-05-03 15:00:40 -0700204 }
205 int rTgt = loadHelper(cUnit, offset);
buzbee8320f382012-09-11 16:29:42 -0700206 // NOTE: not a safepoint
Bill Buzbeea114add2012-05-03 15:00:40 -0700207 opReg(cUnit, kOpBlx, rTgt);
208 RegLocation rlResult = oatGetReturn(cUnit, false);
209 storeValue(cUnit, rlDest, rlResult);
210 return false;
buzbeee3acd072012-02-25 17:03:10 -0800211}
212
jeffhao4b771a02012-07-25 15:07:21 -0700213void genFusedFPCmpBranch(CompilationUnit* cUnit, BasicBlock* bb, MIR* mir,
214 bool gtBias, bool isDouble)
215{
216 UNIMPLEMENTED(FATAL) << "Need codegen for fused fp cmp branch";
217}
218
buzbeeefc63692012-11-14 16:31:52 -0800219void genNegFloat(CompilationUnit *cUnit, RegLocation rlDest, RegLocation rlSrc)
220{
221 RegLocation rlResult;
222 rlSrc = loadValue(cUnit, rlSrc, kCoreReg);
223 rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
224 opRegRegImm(cUnit, kOpAdd, rlResult.lowReg, rlSrc.lowReg, 0x80000000);
225 storeValue(cUnit, rlDest, rlResult);
226}
227
228void genNegDouble(CompilationUnit *cUnit, RegLocation rlDest, RegLocation rlSrc)
229{
230 RegLocation rlResult;
231 rlSrc = loadValueWide(cUnit, rlSrc, kCoreReg);
232 rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
233 opRegRegImm(cUnit, kOpAdd, rlResult.highReg, rlSrc.highReg, 0x80000000);
234 opRegCopy(cUnit, rlResult.lowReg, rlSrc.lowReg);
235 storeValueWide(cUnit, rlDest, rlResult);
236}
237
238bool genInlinedMinMaxInt(CompilationUnit *cUnit, CallInfo* info, bool isMin)
239{
240 // TODO: need Mips implementation
241 return false;
242}
243
buzbeee3acd072012-02-25 17:03:10 -0800244} // namespace art