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