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" |
| 18 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 19 | namespace art { |
| 20 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 21 | bool genArithOpFloat(CompilationUnit *cUnit, Instruction::Code opcode, RegLocation rlDest, |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 22 | RegLocation rlSrc1, RegLocation rlSrc2) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 23 | { |
| 24 | #ifdef __mips_hard_float |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 25 | int op = kMipsNop; |
| 26 | RegLocation rlResult; |
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 | /* |
| 29 | * Don't attempt to optimize register usage since these opcodes call out to |
| 30 | * the handlers. |
| 31 | */ |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 32 | switch (opcode) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 33 | case Instruction::ADD_FLOAT_2ADDR: |
| 34 | case Instruction::ADD_FLOAT: |
| 35 | op = kMipsFadds; |
| 36 | break; |
| 37 | case Instruction::SUB_FLOAT_2ADDR: |
| 38 | case Instruction::SUB_FLOAT: |
| 39 | op = kMipsFsubs; |
| 40 | break; |
| 41 | case Instruction::DIV_FLOAT_2ADDR: |
| 42 | case Instruction::DIV_FLOAT: |
| 43 | op = kMipsFdivs; |
| 44 | break; |
| 45 | case Instruction::MUL_FLOAT_2ADDR: |
| 46 | case Instruction::MUL_FLOAT: |
| 47 | op = kMipsFmuls; |
| 48 | break; |
| 49 | case Instruction::REM_FLOAT_2ADDR: |
| 50 | case Instruction::REM_FLOAT: |
| 51 | case Instruction::NEG_FLOAT: { |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 52 | return genArithOpFloatPortable(cUnit, opcode, rlDest, rlSrc1, rlSrc2); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 53 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 54 | default: |
| 55 | return true; |
| 56 | } |
| 57 | rlSrc1 = loadValue(cUnit, rlSrc1, kFPReg); |
| 58 | rlSrc2 = loadValue(cUnit, rlSrc2, kFPReg); |
| 59 | rlResult = oatEvalLoc(cUnit, rlDest, kFPReg, true); |
| 60 | newLIR3(cUnit, (MipsOpCode)op, rlResult.lowReg, rlSrc1.lowReg, |
| 61 | rlSrc2.lowReg); |
| 62 | storeValue(cUnit, rlDest, rlResult); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 63 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 64 | return false; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 65 | #else |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 66 | return genArithOpFloatPortable(cUnit, opcode, rlDest, rlSrc1, rlSrc2); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 67 | #endif |
| 68 | } |
| 69 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 70 | static bool genArithOpDouble(CompilationUnit *cUnit, Instruction::Code opcode, |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 71 | RegLocation rlDest, RegLocation rlSrc1, |
| 72 | RegLocation rlSrc2) |
| 73 | { |
| 74 | #ifdef __mips_hard_float |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 75 | int op = kMipsNop; |
| 76 | RegLocation rlResult; |
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: |
| 97 | case Instruction::NEG_DOUBLE: { |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 98 | return genArithOpDoublePortable(cUnit, opcode, rlDest, rlSrc1, rlSrc2); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 99 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 100 | default: |
| 101 | return true; |
| 102 | } |
| 103 | rlSrc1 = loadValueWide(cUnit, rlSrc1, kFPReg); |
| 104 | DCHECK(rlSrc1.wide); |
| 105 | rlSrc2 = loadValueWide(cUnit, rlSrc2, kFPReg); |
| 106 | DCHECK(rlSrc2.wide); |
| 107 | rlResult = oatEvalLoc(cUnit, rlDest, kFPReg, true); |
| 108 | DCHECK(rlDest.wide); |
| 109 | DCHECK(rlResult.wide); |
buzbee | f0504cd | 2012-11-13 16:31:10 -0800 | [diff] [blame] | 110 | newLIR3(cUnit, (MipsOpCode)op, s2d(rlResult.lowReg, rlResult.highReg), |
| 111 | s2d(rlSrc1.lowReg, rlSrc1.highReg), |
| 112 | s2d(rlSrc2.lowReg, rlSrc2.highReg)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 113 | storeValueWide(cUnit, rlDest, rlResult); |
| 114 | return false; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 115 | #else |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 116 | return genArithOpDoublePortable(cUnit, opcode, rlDest, rlSrc1, rlSrc2); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 117 | #endif |
| 118 | } |
| 119 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 120 | static bool genConversion(CompilationUnit *cUnit, Instruction::Code opcode, |
| 121 | RegLocation rlDest, RegLocation rlSrc) |
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; |
| 125 | int srcReg; |
| 126 | RegLocation rlResult; |
| 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 | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 146 | return genConversionPortable(cUnit, opcode, rlDest, rlSrc); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 147 | default: |
| 148 | return true; |
| 149 | } |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 150 | if (rlSrc.wide) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 151 | rlSrc = loadValueWide(cUnit, rlSrc, kFPReg); |
buzbee | f0504cd | 2012-11-13 16:31:10 -0800 | [diff] [blame] | 152 | srcReg = s2d(rlSrc.lowReg, rlSrc.highReg); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 153 | } else { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 154 | rlSrc = loadValue(cUnit, rlSrc, kFPReg); |
| 155 | srcReg = rlSrc.lowReg; |
| 156 | } |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 157 | if (rlDest.wide) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 158 | rlResult = oatEvalLoc(cUnit, rlDest, kFPReg, true); |
buzbee | f0504cd | 2012-11-13 16:31:10 -0800 | [diff] [blame] | 159 | newLIR2(cUnit, (MipsOpCode)op, s2d(rlResult.lowReg, rlResult.highReg), |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 160 | srcReg); |
| 161 | storeValueWide(cUnit, rlDest, rlResult); |
| 162 | } else { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 163 | rlResult = oatEvalLoc(cUnit, rlDest, kFPReg, true); |
| 164 | newLIR2(cUnit, (MipsOpCode)op, rlResult.lowReg, srcReg); |
| 165 | storeValue(cUnit, rlDest, rlResult); |
| 166 | } |
| 167 | return false; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 168 | #else |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 169 | return genConversionPortable(cUnit, opcode, rlDest, rlSrc); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 170 | #endif |
| 171 | } |
| 172 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 173 | static bool genCmpFP(CompilationUnit *cUnit, Instruction::Code opcode, RegLocation rlDest, |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 174 | RegLocation rlSrc1, RegLocation rlSrc2) |
| 175 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 176 | bool wide = true; |
| 177 | int offset; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 178 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 179 | switch (opcode) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 180 | case Instruction::CMPL_FLOAT: |
| 181 | offset = ENTRYPOINT_OFFSET(pCmplFloat); |
| 182 | wide = false; |
| 183 | break; |
| 184 | case Instruction::CMPG_FLOAT: |
| 185 | offset = ENTRYPOINT_OFFSET(pCmpgFloat); |
| 186 | wide = false; |
| 187 | break; |
| 188 | case Instruction::CMPL_DOUBLE: |
| 189 | offset = ENTRYPOINT_OFFSET(pCmplDouble); |
| 190 | break; |
| 191 | case Instruction::CMPG_DOUBLE: |
| 192 | offset = ENTRYPOINT_OFFSET(pCmpgDouble); |
| 193 | break; |
| 194 | default: |
| 195 | return true; |
| 196 | } |
| 197 | oatFlushAllRegs(cUnit); |
| 198 | oatLockCallTemps(cUnit); |
| 199 | if (wide) { |
buzbee | f0504cd | 2012-11-13 16:31:10 -0800 | [diff] [blame] | 200 | loadValueDirectWideFixed(cUnit, rlSrc1, rMIPS_FARG0, rMIPS_FARG1); |
| 201 | loadValueDirectWideFixed(cUnit, rlSrc2, rMIPS_FARG2, rMIPS_FARG3); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 202 | } else { |
buzbee | f0504cd | 2012-11-13 16:31:10 -0800 | [diff] [blame] | 203 | loadValueDirectFixed(cUnit, rlSrc1, rMIPS_FARG0); |
| 204 | loadValueDirectFixed(cUnit, rlSrc2, rMIPS_FARG2); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 205 | } |
| 206 | int rTgt = loadHelper(cUnit, offset); |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 207 | // NOTE: not a safepoint |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 208 | opReg(cUnit, kOpBlx, rTgt); |
| 209 | RegLocation rlResult = oatGetReturn(cUnit, false); |
| 210 | storeValue(cUnit, rlDest, rlResult); |
| 211 | return false; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 212 | } |
| 213 | |
jeffhao | 4b771a0 | 2012-07-25 15:07:21 -0700 | [diff] [blame] | 214 | void genFusedFPCmpBranch(CompilationUnit* cUnit, BasicBlock* bb, MIR* mir, |
| 215 | bool gtBias, bool isDouble) |
| 216 | { |
| 217 | UNIMPLEMENTED(FATAL) << "Need codegen for fused fp cmp branch"; |
| 218 | } |
| 219 | |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame^] | 220 | void genNegFloat(CompilationUnit *cUnit, RegLocation rlDest, RegLocation rlSrc) |
| 221 | { |
| 222 | RegLocation rlResult; |
| 223 | rlSrc = loadValue(cUnit, rlSrc, kCoreReg); |
| 224 | rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 225 | opRegRegImm(cUnit, kOpAdd, rlResult.lowReg, rlSrc.lowReg, 0x80000000); |
| 226 | storeValue(cUnit, rlDest, rlResult); |
| 227 | } |
| 228 | |
| 229 | void genNegDouble(CompilationUnit *cUnit, RegLocation rlDest, RegLocation rlSrc) |
| 230 | { |
| 231 | RegLocation rlResult; |
| 232 | rlSrc = loadValueWide(cUnit, rlSrc, kCoreReg); |
| 233 | rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 234 | opRegRegImm(cUnit, kOpAdd, rlResult.highReg, rlSrc.highReg, 0x80000000); |
| 235 | opRegCopy(cUnit, rlResult.lowReg, rlSrc.lowReg); |
| 236 | storeValueWide(cUnit, rlDest, rlResult); |
| 237 | } |
| 238 | |
| 239 | bool genInlinedMinMaxInt(CompilationUnit *cUnit, CallInfo* info, bool isMin) |
| 240 | { |
| 241 | // TODO: need Mips implementation |
| 242 | return false; |
| 243 | } |
| 244 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 245 | } // namespace art |