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" |
| 19 | #include "../codegen_util.h" |
| 20 | #include "../ralloc_util.h" |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 21 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 22 | namespace art { |
| 23 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 24 | bool GenArithOpFloat(CompilationUnit *cu, Instruction::Code opcode, RegLocation rl_dest, |
| 25 | RegLocation rl_src1, RegLocation rl_src2) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 26 | { |
| 27 | #ifdef __mips_hard_float |
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 | #else |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 68 | return GenArithOpFloatPortable(cu, opcode, rl_dest, rl_src1, rl_src2); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 69 | #endif |
| 70 | } |
| 71 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 72 | bool 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 | { |
| 75 | #ifdef __mips_hard_float |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 76 | int op = kMipsNop; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 77 | RegLocation rl_result; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 78 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 79 | switch (opcode) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 80 | 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: { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 99 | return GenArithOpDoublePortable(cu, opcode, rl_dest, rl_src1, rl_src2); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 100 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 101 | default: |
| 102 | return true; |
| 103 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 104 | rl_src1 = LoadValueWide(cu, rl_src1, kFPReg); |
| 105 | DCHECK(rl_src1.wide); |
| 106 | rl_src2 = LoadValueWide(cu, rl_src2, kFPReg); |
| 107 | DCHECK(rl_src2.wide); |
| 108 | rl_result = EvalLoc(cu, rl_dest, kFPReg, true); |
| 109 | DCHECK(rl_dest.wide); |
| 110 | DCHECK(rl_result.wide); |
| 111 | NewLIR3(cu, op, S2d(rl_result.low_reg, rl_result.high_reg), S2d(rl_src1.low_reg, rl_src1.high_reg), |
| 112 | S2d(rl_src2.low_reg, rl_src2.high_reg)); |
| 113 | StoreValueWide(cu, rl_dest, rl_result); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 114 | return false; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 115 | #else |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 116 | return GenArithOpDoublePortable(cu, opcode, rl_dest, rl_src1, rl_src2); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 117 | #endif |
| 118 | } |
| 119 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 120 | bool GenConversion(CompilationUnit *cu, Instruction::Code opcode, RegLocation rl_dest, |
| 121 | RegLocation rl_src) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 122 | { |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 123 | #ifdef __mips_hard_float |
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: |
| 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: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 146 | return GenConversionPortable(cu, opcode, rl_dest, rl_src); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 147 | default: |
| 148 | return true; |
| 149 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 150 | if (rl_src.wide) { |
| 151 | rl_src = LoadValueWide(cu, rl_src, kFPReg); |
| 152 | src_reg = S2d(rl_src.low_reg, rl_src.high_reg); |
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_src = LoadValue(cu, rl_src, kFPReg); |
| 155 | src_reg = rl_src.low_reg; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 156 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 157 | if (rl_dest.wide) { |
| 158 | rl_result = EvalLoc(cu, rl_dest, kFPReg, true); |
| 159 | NewLIR2(cu, op, S2d(rl_result.low_reg, rl_result.high_reg), src_reg); |
| 160 | StoreValueWide(cu, rl_dest, rl_result); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 161 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 162 | rl_result = EvalLoc(cu, rl_dest, kFPReg, true); |
| 163 | NewLIR2(cu, op, rl_result.low_reg, src_reg); |
| 164 | StoreValue(cu, rl_dest, rl_result); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 165 | } |
| 166 | return false; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 167 | #else |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 168 | return GenConversionPortable(cu, opcode, rl_dest, rl_src); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 169 | #endif |
| 170 | } |
| 171 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 172 | bool GenCmpFP(CompilationUnit *cu, Instruction::Code opcode, RegLocation rl_dest, |
| 173 | RegLocation rl_src1, RegLocation rl_src2) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 174 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 175 | bool wide = true; |
| 176 | int offset; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 177 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 178 | switch (opcode) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 179 | 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 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 196 | FlushAllRegs(cu); |
| 197 | LockCallTemps(cu); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 198 | if (wide) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 199 | LoadValueDirectWideFixed(cu, rl_src1, rMIPS_FARG0, rMIPS_FARG1); |
| 200 | LoadValueDirectWideFixed(cu, rl_src2, rMIPS_FARG2, rMIPS_FARG3); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 201 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 202 | LoadValueDirectFixed(cu, rl_src1, rMIPS_FARG0); |
| 203 | LoadValueDirectFixed(cu, rl_src2, rMIPS_FARG2); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 204 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 205 | int r_tgt = LoadHelper(cu, offset); |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 206 | // NOTE: not a safepoint |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 207 | OpReg(cu, kOpBlx, r_tgt); |
| 208 | RegLocation rl_result = GetReturn(cu, false); |
| 209 | StoreValue(cu, rl_dest, rl_result); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 210 | return false; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 211 | } |
| 212 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 213 | void GenFusedFPCmpBranch(CompilationUnit* cu, BasicBlock* bb, MIR* mir, |
| 214 | bool gt_bias, bool is_double) |
jeffhao | 4b771a0 | 2012-07-25 15:07:21 -0700 | [diff] [blame] | 215 | { |
| 216 | UNIMPLEMENTED(FATAL) << "Need codegen for fused fp cmp branch"; |
| 217 | } |
| 218 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 219 | void GenNegFloat(CompilationUnit *cu, RegLocation rl_dest, RegLocation rl_src) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 220 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 221 | RegLocation rl_result; |
| 222 | rl_src = LoadValue(cu, rl_src, kCoreReg); |
| 223 | rl_result = EvalLoc(cu, rl_dest, kCoreReg, true); |
| 224 | OpRegRegImm(cu, kOpAdd, rl_result.low_reg, rl_src.low_reg, 0x80000000); |
| 225 | StoreValue(cu, rl_dest, rl_result); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 226 | } |
| 227 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 228 | void GenNegDouble(CompilationUnit *cu, RegLocation rl_dest, RegLocation rl_src) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 229 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 230 | RegLocation rl_result; |
| 231 | rl_src = LoadValueWide(cu, rl_src, kCoreReg); |
| 232 | rl_result = EvalLoc(cu, rl_dest, kCoreReg, true); |
| 233 | OpRegRegImm(cu, kOpAdd, rl_result.high_reg, rl_src.high_reg, 0x80000000); |
| 234 | OpRegCopy(cu, rl_result.low_reg, rl_src.low_reg); |
| 235 | StoreValueWide(cu, rl_dest, rl_result); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 236 | } |
| 237 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 238 | bool GenInlinedMinMaxInt(CompilationUnit *cu, CallInfo* info, bool is_min) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 239 | { |
| 240 | // TODO: need Mips implementation |
| 241 | return false; |
| 242 | } |
| 243 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 244 | } // namespace art |