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