buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 17 | #include "codegen_mips.h" |
Brian Carlstrom | 641ce03 | 2013-01-31 15:21:37 -0800 | [diff] [blame] | 18 | #include "compiler/codegen/codegen_util.h" |
| 19 | #include "compiler/codegen/ralloc_util.h" |
| 20 | #include "mips_lir.h" |
| 21 | #include "oat/runtime/oat_support_entrypoints.h" |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 22 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 23 | namespace art { |
| 24 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 25 | bool MipsCodegen::GenArithOpFloat(CompilationUnit *cu, Instruction::Code opcode, |
| 26 | RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 27 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 28 | int op = kMipsNop; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 29 | RegLocation rl_result; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 30 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 31 | /* |
| 32 | * Don't attempt to optimize register usage since these opcodes call out to |
| 33 | * the handlers. |
| 34 | */ |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 35 | switch (opcode) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 36 | 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; |
Ian Rogers | a6f3aaf | 2013-01-16 15:17:58 -0800 | [diff] [blame] | 52 | case Instruction::REM_FLOAT_2ADDR: |
| 53 | case Instruction::REM_FLOAT: |
buzbee | a3a82b2 | 2012-11-27 16:09:55 -0800 | [diff] [blame] | 54 | FlushAllRegs(cu); // Send everything to home location |
| 55 | CallRuntimeHelperRegLocationRegLocation(cu, ENTRYPOINT_OFFSET(pFmodf), rl_src1, rl_src2, false); |
| 56 | rl_result = GetReturn(cu, true); |
| 57 | StoreValue(cu, rl_dest, rl_result); |
| 58 | return false; |
| 59 | case Instruction::NEG_FLOAT: |
| 60 | GenNegFloat(cu, rl_dest, rl_src1); |
| 61 | return false; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 62 | default: |
| 63 | return true; |
| 64 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 65 | rl_src1 = LoadValue(cu, rl_src1, kFPReg); |
| 66 | rl_src2 = LoadValue(cu, rl_src2, kFPReg); |
| 67 | rl_result = EvalLoc(cu, rl_dest, kFPReg, true); |
| 68 | NewLIR3(cu, op, rl_result.low_reg, rl_src1.low_reg, rl_src2.low_reg); |
| 69 | StoreValue(cu, rl_dest, rl_result); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 70 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 71 | return false; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 72 | } |
| 73 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 74 | bool MipsCodegen::GenArithOpDouble(CompilationUnit *cu, Instruction::Code opcode, |
| 75 | RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 76 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 77 | int op = kMipsNop; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 78 | RegLocation rl_result; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 79 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 80 | switch (opcode) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 81 | case Instruction::ADD_DOUBLE_2ADDR: |
| 82 | case Instruction::ADD_DOUBLE: |
| 83 | op = kMipsFaddd; |
| 84 | break; |
| 85 | case Instruction::SUB_DOUBLE_2ADDR: |
| 86 | case Instruction::SUB_DOUBLE: |
| 87 | op = kMipsFsubd; |
| 88 | break; |
| 89 | case Instruction::DIV_DOUBLE_2ADDR: |
| 90 | case Instruction::DIV_DOUBLE: |
| 91 | op = kMipsFdivd; |
| 92 | break; |
| 93 | case Instruction::MUL_DOUBLE_2ADDR: |
| 94 | case Instruction::MUL_DOUBLE: |
| 95 | op = kMipsFmuld; |
| 96 | break; |
| 97 | case Instruction::REM_DOUBLE_2ADDR: |
| 98 | case Instruction::REM_DOUBLE: |
buzbee | a3a82b2 | 2012-11-27 16:09:55 -0800 | [diff] [blame] | 99 | FlushAllRegs(cu); // Send everything to home location |
| 100 | CallRuntimeHelperRegLocationRegLocation(cu, ENTRYPOINT_OFFSET(pFmod), rl_src1, rl_src2, false); |
| 101 | rl_result = GetReturnWide(cu, true); |
| 102 | StoreValueWide(cu, rl_dest, rl_result); |
| 103 | return false; |
| 104 | case Instruction::NEG_DOUBLE: |
| 105 | GenNegDouble(cu, rl_dest, rl_src1); |
| 106 | return false; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 107 | default: |
| 108 | return true; |
| 109 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 110 | rl_src1 = LoadValueWide(cu, rl_src1, kFPReg); |
| 111 | DCHECK(rl_src1.wide); |
| 112 | rl_src2 = LoadValueWide(cu, rl_src2, kFPReg); |
| 113 | DCHECK(rl_src2.wide); |
| 114 | rl_result = EvalLoc(cu, rl_dest, kFPReg, true); |
| 115 | DCHECK(rl_dest.wide); |
| 116 | DCHECK(rl_result.wide); |
| 117 | NewLIR3(cu, op, S2d(rl_result.low_reg, rl_result.high_reg), S2d(rl_src1.low_reg, rl_src1.high_reg), |
| 118 | S2d(rl_src2.low_reg, rl_src2.high_reg)); |
| 119 | StoreValueWide(cu, rl_dest, rl_result); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 120 | return false; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 121 | } |
| 122 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 123 | bool MipsCodegen::GenConversion(CompilationUnit *cu, Instruction::Code opcode, RegLocation rl_dest, |
| 124 | RegLocation rl_src) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 125 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 126 | int op = kMipsNop; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 127 | int src_reg; |
| 128 | RegLocation rl_result; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 129 | switch (opcode) { |
| 130 | case Instruction::INT_TO_FLOAT: |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 131 | op = kMipsFcvtsw; |
| 132 | break; |
| 133 | case Instruction::DOUBLE_TO_FLOAT: |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 134 | op = kMipsFcvtsd; |
| 135 | break; |
| 136 | case Instruction::FLOAT_TO_DOUBLE: |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 137 | op = kMipsFcvtds; |
| 138 | break; |
| 139 | case Instruction::INT_TO_DOUBLE: |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 140 | op = kMipsFcvtdw; |
| 141 | break; |
| 142 | case Instruction::FLOAT_TO_INT: |
buzbee | a3a82b2 | 2012-11-27 16:09:55 -0800 | [diff] [blame] | 143 | return GenConversionCall(cu, ENTRYPOINT_OFFSET(pF2iz), rl_dest, rl_src); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 144 | case Instruction::DOUBLE_TO_INT: |
buzbee | a3a82b2 | 2012-11-27 16:09:55 -0800 | [diff] [blame] | 145 | return GenConversionCall(cu, ENTRYPOINT_OFFSET(pD2iz), rl_dest, rl_src); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 146 | case Instruction::LONG_TO_DOUBLE: |
buzbee | a3a82b2 | 2012-11-27 16:09:55 -0800 | [diff] [blame] | 147 | return GenConversionCall(cu, ENTRYPOINT_OFFSET(pL2d), rl_dest, rl_src); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 148 | case Instruction::FLOAT_TO_LONG: |
buzbee | a3a82b2 | 2012-11-27 16:09:55 -0800 | [diff] [blame] | 149 | return GenConversionCall(cu, ENTRYPOINT_OFFSET(pF2l), rl_dest, rl_src); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 150 | case Instruction::LONG_TO_FLOAT: |
buzbee | a3a82b2 | 2012-11-27 16:09:55 -0800 | [diff] [blame] | 151 | return GenConversionCall(cu, ENTRYPOINT_OFFSET(pL2f), rl_dest, rl_src); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 152 | case Instruction::DOUBLE_TO_LONG: |
buzbee | a3a82b2 | 2012-11-27 16:09:55 -0800 | [diff] [blame] | 153 | return GenConversionCall(cu, ENTRYPOINT_OFFSET(pD2l), rl_dest, rl_src); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 154 | default: |
| 155 | return true; |
| 156 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 157 | if (rl_src.wide) { |
| 158 | rl_src = LoadValueWide(cu, rl_src, kFPReg); |
| 159 | src_reg = S2d(rl_src.low_reg, rl_src.high_reg); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 160 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 161 | rl_src = LoadValue(cu, rl_src, kFPReg); |
| 162 | src_reg = rl_src.low_reg; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 163 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 164 | if (rl_dest.wide) { |
| 165 | rl_result = EvalLoc(cu, rl_dest, kFPReg, true); |
| 166 | NewLIR2(cu, op, S2d(rl_result.low_reg, rl_result.high_reg), src_reg); |
| 167 | StoreValueWide(cu, rl_dest, rl_result); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 168 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 169 | rl_result = EvalLoc(cu, rl_dest, kFPReg, true); |
| 170 | NewLIR2(cu, op, rl_result.low_reg, src_reg); |
| 171 | StoreValue(cu, rl_dest, rl_result); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 172 | } |
| 173 | return false; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 174 | } |
| 175 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 176 | bool MipsCodegen::GenCmpFP(CompilationUnit *cu, Instruction::Code opcode, RegLocation rl_dest, |
| 177 | RegLocation rl_src1, RegLocation rl_src2) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 178 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 179 | bool wide = true; |
| 180 | int offset; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 181 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 182 | switch (opcode) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 183 | case Instruction::CMPL_FLOAT: |
| 184 | offset = ENTRYPOINT_OFFSET(pCmplFloat); |
| 185 | wide = false; |
| 186 | break; |
| 187 | case Instruction::CMPG_FLOAT: |
| 188 | offset = ENTRYPOINT_OFFSET(pCmpgFloat); |
| 189 | wide = false; |
| 190 | break; |
| 191 | case Instruction::CMPL_DOUBLE: |
| 192 | offset = ENTRYPOINT_OFFSET(pCmplDouble); |
| 193 | break; |
| 194 | case Instruction::CMPG_DOUBLE: |
| 195 | offset = ENTRYPOINT_OFFSET(pCmpgDouble); |
| 196 | break; |
| 197 | default: |
| 198 | return true; |
| 199 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 200 | FlushAllRegs(cu); |
| 201 | LockCallTemps(cu); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 202 | if (wide) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 203 | LoadValueDirectWideFixed(cu, rl_src1, rMIPS_FARG0, rMIPS_FARG1); |
| 204 | LoadValueDirectWideFixed(cu, rl_src2, rMIPS_FARG2, rMIPS_FARG3); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 205 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 206 | LoadValueDirectFixed(cu, rl_src1, rMIPS_FARG0); |
| 207 | LoadValueDirectFixed(cu, rl_src2, rMIPS_FARG2); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 208 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 209 | int r_tgt = LoadHelper(cu, offset); |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 210 | // NOTE: not a safepoint |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 211 | OpReg(cu, kOpBlx, r_tgt); |
| 212 | RegLocation rl_result = GetReturn(cu, false); |
| 213 | StoreValue(cu, rl_dest, rl_result); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 214 | return false; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 215 | } |
| 216 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 217 | void MipsCodegen::GenFusedFPCmpBranch(CompilationUnit* cu, BasicBlock* bb, MIR* mir, |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 218 | bool gt_bias, bool is_double) |
jeffhao | 4b771a0 | 2012-07-25 15:07:21 -0700 | [diff] [blame] | 219 | { |
| 220 | UNIMPLEMENTED(FATAL) << "Need codegen for fused fp cmp branch"; |
| 221 | } |
| 222 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 223 | void MipsCodegen::GenNegFloat(CompilationUnit *cu, RegLocation rl_dest, RegLocation rl_src) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 224 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 225 | RegLocation rl_result; |
| 226 | rl_src = LoadValue(cu, rl_src, kCoreReg); |
| 227 | rl_result = EvalLoc(cu, rl_dest, kCoreReg, true); |
| 228 | OpRegRegImm(cu, kOpAdd, rl_result.low_reg, rl_src.low_reg, 0x80000000); |
| 229 | StoreValue(cu, rl_dest, rl_result); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 230 | } |
| 231 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 232 | void MipsCodegen::GenNegDouble(CompilationUnit *cu, RegLocation rl_dest, RegLocation rl_src) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 233 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 234 | RegLocation rl_result; |
| 235 | rl_src = LoadValueWide(cu, rl_src, kCoreReg); |
| 236 | rl_result = EvalLoc(cu, rl_dest, kCoreReg, true); |
| 237 | OpRegRegImm(cu, kOpAdd, rl_result.high_reg, rl_src.high_reg, 0x80000000); |
| 238 | OpRegCopy(cu, rl_result.low_reg, rl_src.low_reg); |
| 239 | StoreValueWide(cu, rl_dest, rl_result); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 240 | } |
| 241 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 242 | bool MipsCodegen::GenInlinedMinMaxInt(CompilationUnit *cu, CallInfo* info, bool is_min) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 243 | { |
| 244 | // TODO: need Mips implementation |
| 245 | return false; |
| 246 | } |
| 247 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 248 | } // namespace art |