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 | |
| 17 | namespace art { |
| 18 | |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 19 | bool genArithOpFloat(CompilationUnit *cUnit, MIR *mir, RegLocation rlDest, |
| 20 | RegLocation rlSrc1, RegLocation rlSrc2) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 21 | { |
| 22 | #ifdef __mips_hard_float |
| 23 | int op = kMipsNop; |
| 24 | RegLocation rlResult; |
| 25 | |
| 26 | /* |
| 27 | * Don't attempt to optimize register usage since these opcodes call out to |
| 28 | * the handlers. |
| 29 | */ |
| 30 | switch (mir->dalvikInsn.opcode) { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 31 | case Instruction::ADD_FLOAT_2ADDR: |
| 32 | case Instruction::ADD_FLOAT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 33 | op = kMipsFadds; |
| 34 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 35 | case Instruction::SUB_FLOAT_2ADDR: |
| 36 | case Instruction::SUB_FLOAT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 37 | op = kMipsFsubs; |
| 38 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 39 | case Instruction::DIV_FLOAT_2ADDR: |
| 40 | case Instruction::DIV_FLOAT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 41 | op = kMipsFdivs; |
| 42 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 43 | case Instruction::MUL_FLOAT_2ADDR: |
| 44 | case Instruction::MUL_FLOAT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 45 | op = kMipsFmuls; |
| 46 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 47 | case Instruction::REM_FLOAT_2ADDR: |
| 48 | case Instruction::REM_FLOAT: |
| 49 | case Instruction::NEG_FLOAT: { |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 50 | return genArithOpFloatPortable(cUnit, mir, rlDest, rlSrc1, rlSrc2); |
| 51 | } |
| 52 | default: |
| 53 | return true; |
| 54 | } |
| 55 | rlSrc1 = loadValue(cUnit, rlSrc1, kFPReg); |
| 56 | rlSrc2 = loadValue(cUnit, rlSrc2, kFPReg); |
| 57 | rlResult = oatEvalLoc(cUnit, rlDest, kFPReg, true); |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 58 | newLIR3(cUnit, (MipsOpCode)op, rlResult.lowReg, rlSrc1.lowReg, |
| 59 | rlSrc2.lowReg); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 60 | storeValue(cUnit, rlDest, rlResult); |
| 61 | |
| 62 | return false; |
| 63 | #else |
Bill Buzbee | 11f9d21 | 2012-03-03 20:03:18 -0800 | [diff] [blame] | 64 | return genArithOpFloatPortable(cUnit, mir, rlDest, rlSrc1, rlSrc2); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 65 | #endif |
| 66 | } |
| 67 | |
| 68 | static bool genArithOpDouble(CompilationUnit *cUnit, MIR *mir, |
| 69 | RegLocation rlDest, RegLocation rlSrc1, |
| 70 | RegLocation rlSrc2) |
| 71 | { |
| 72 | #ifdef __mips_hard_float |
| 73 | int op = kMipsNop; |
| 74 | RegLocation rlResult; |
| 75 | |
| 76 | switch (mir->dalvikInsn.opcode) { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 77 | case Instruction::ADD_DOUBLE_2ADDR: |
| 78 | case Instruction::ADD_DOUBLE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 79 | op = kMipsFaddd; |
| 80 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 81 | case Instruction::SUB_DOUBLE_2ADDR: |
| 82 | case Instruction::SUB_DOUBLE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 83 | op = kMipsFsubd; |
| 84 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 85 | case Instruction::DIV_DOUBLE_2ADDR: |
| 86 | case Instruction::DIV_DOUBLE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 87 | op = kMipsFdivd; |
| 88 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 89 | case Instruction::MUL_DOUBLE_2ADDR: |
| 90 | case Instruction::MUL_DOUBLE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 91 | op = kMipsFmuld; |
| 92 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 93 | case Instruction::REM_DOUBLE_2ADDR: |
| 94 | case Instruction::REM_DOUBLE: |
| 95 | case Instruction::NEG_DOUBLE: { |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 96 | return genArithOpDoublePortable(cUnit, mir, rlDest, rlSrc1, rlSrc2); |
| 97 | } |
| 98 | default: |
| 99 | return true; |
| 100 | } |
| 101 | rlSrc1 = loadValueWide(cUnit, rlSrc1, kFPReg); |
| 102 | DCHECK(rlSrc1.wide); |
| 103 | rlSrc2 = loadValueWide(cUnit, rlSrc2, kFPReg); |
| 104 | DCHECK(rlSrc2.wide); |
| 105 | rlResult = oatEvalLoc(cUnit, rlDest, kFPReg, true); |
| 106 | DCHECK(rlDest.wide); |
| 107 | DCHECK(rlResult.wide); |
| 108 | newLIR3(cUnit, (MipsOpCode)op, S2D(rlResult.lowReg, rlResult.highReg), |
| 109 | S2D(rlSrc1.lowReg, rlSrc1.highReg), |
| 110 | S2D(rlSrc2.lowReg, rlSrc2.highReg)); |
| 111 | storeValueWide(cUnit, rlDest, rlResult); |
| 112 | return false; |
| 113 | #else |
Bill Buzbee | 11f9d21 | 2012-03-03 20:03:18 -0800 | [diff] [blame] | 114 | return genArithOpDoublePortable(cUnit, mir, rlDest, rlSrc1, rlSrc2); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 115 | #endif |
| 116 | } |
| 117 | |
| 118 | static bool genConversion(CompilationUnit *cUnit, MIR *mir) |
| 119 | { |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 120 | #ifdef __mips_hard_float |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 121 | Instruction::Code opcode = mir->dalvikInsn.opcode; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 122 | bool longSrc = false; |
| 123 | bool longDest = false; |
| 124 | RegLocation rlSrc; |
| 125 | RegLocation rlDest; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 126 | int op = kMipsNop; |
| 127 | int srcReg; |
| 128 | RegLocation rlResult; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 129 | switch (opcode) { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 130 | case Instruction::INT_TO_FLOAT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 131 | longSrc = false; |
| 132 | longDest = false; |
| 133 | op = kMipsFcvtsw; |
| 134 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 135 | case Instruction::DOUBLE_TO_FLOAT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 136 | longSrc = true; |
| 137 | longDest = false; |
| 138 | op = kMipsFcvtsd; |
| 139 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 140 | case Instruction::FLOAT_TO_DOUBLE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 141 | longSrc = false; |
| 142 | longDest = true; |
| 143 | op = kMipsFcvtds; |
| 144 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 145 | case Instruction::INT_TO_DOUBLE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 146 | longSrc = false; |
| 147 | longDest = true; |
| 148 | op = kMipsFcvtdw; |
| 149 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 150 | case Instruction::FLOAT_TO_INT: |
| 151 | case Instruction::DOUBLE_TO_INT: |
| 152 | case Instruction::LONG_TO_DOUBLE: |
| 153 | case Instruction::FLOAT_TO_LONG: |
| 154 | case Instruction::LONG_TO_FLOAT: |
| 155 | case Instruction::DOUBLE_TO_LONG: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 156 | return genConversionPortable(cUnit, mir); |
| 157 | default: |
| 158 | return true; |
| 159 | } |
| 160 | if (longSrc) { |
| 161 | rlSrc = oatGetSrcWide(cUnit, mir, 0, 1); |
| 162 | rlSrc = loadValueWide(cUnit, rlSrc, kFPReg); |
| 163 | srcReg = S2D(rlSrc.lowReg, rlSrc.highReg); |
| 164 | } else { |
| 165 | rlSrc = oatGetSrc(cUnit, mir, 0); |
| 166 | rlSrc = loadValue(cUnit, rlSrc, kFPReg); |
| 167 | srcReg = rlSrc.lowReg; |
| 168 | } |
| 169 | if (longDest) { |
| 170 | rlDest = oatGetDestWide(cUnit, mir, 0, 1); |
| 171 | rlResult = oatEvalLoc(cUnit, rlDest, kFPReg, true); |
| 172 | newLIR2(cUnit, (MipsOpCode)op, S2D(rlResult.lowReg, rlResult.highReg), srcReg); |
| 173 | storeValueWide(cUnit, rlDest, rlResult); |
| 174 | } else { |
| 175 | rlDest = oatGetDest(cUnit, mir, 0); |
| 176 | rlResult = oatEvalLoc(cUnit, rlDest, kFPReg, true); |
| 177 | newLIR2(cUnit, (MipsOpCode)op, rlResult.lowReg, srcReg); |
| 178 | storeValue(cUnit, rlDest, rlResult); |
| 179 | } |
| 180 | return false; |
| 181 | #else |
Bill Buzbee | 11f9d21 | 2012-03-03 20:03:18 -0800 | [diff] [blame] | 182 | return genConversionPortable(cUnit, mir); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 183 | #endif |
| 184 | } |
| 185 | |
| 186 | static bool genCmpFP(CompilationUnit *cUnit, MIR *mir, RegLocation rlDest, |
| 187 | RegLocation rlSrc1, RegLocation rlSrc2) |
| 188 | { |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 189 | bool wide = true; |
Bill Buzbee | 11f9d21 | 2012-03-03 20:03:18 -0800 | [diff] [blame] | 190 | int offset; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 191 | |
| 192 | switch(mir->dalvikInsn.opcode) { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 193 | case Instruction::CMPL_FLOAT: |
Bill Buzbee | 11f9d21 | 2012-03-03 20:03:18 -0800 | [diff] [blame] | 194 | offset = OFFSETOF_MEMBER(Thread, pCmplFloat); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 195 | wide = false; |
| 196 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 197 | case Instruction::CMPG_FLOAT: |
Bill Buzbee | 11f9d21 | 2012-03-03 20:03:18 -0800 | [diff] [blame] | 198 | offset = OFFSETOF_MEMBER(Thread, pCmpgFloat); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 199 | wide = false; |
| 200 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 201 | case Instruction::CMPL_DOUBLE: |
Bill Buzbee | 11f9d21 | 2012-03-03 20:03:18 -0800 | [diff] [blame] | 202 | offset = OFFSETOF_MEMBER(Thread, pCmplDouble); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 203 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 204 | case Instruction::CMPG_DOUBLE: |
Bill Buzbee | 11f9d21 | 2012-03-03 20:03:18 -0800 | [diff] [blame] | 205 | offset = OFFSETOF_MEMBER(Thread, pCmpgDouble); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 206 | break; |
| 207 | default: |
| 208 | return true; |
| 209 | } |
Bill Buzbee | 11f9d21 | 2012-03-03 20:03:18 -0800 | [diff] [blame] | 210 | oatFlushAllRegs(cUnit); |
| 211 | oatLockCallTemps(cUnit); |
| 212 | if (wide) { |
| 213 | loadValueDirectWideFixed(cUnit, rlSrc1, rARG0, rARG1); |
| 214 | loadValueDirectWideFixed(cUnit, rlSrc2, rARG2, rARG3); |
| 215 | } else { |
| 216 | loadValueDirectFixed(cUnit, rlSrc1, rARG0); |
| 217 | loadValueDirectFixed(cUnit, rlSrc2, rARG1); |
| 218 | } |
| 219 | int rTgt = loadHelper(cUnit, offset); |
| 220 | opReg(cUnit, kOpBlx, rTgt); |
Ian Rogers | f7d9ad3 | 2012-03-13 18:45:39 -0700 | [diff] [blame] | 221 | RegLocation rlResult = oatGetReturn(cUnit, false); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 222 | storeValue(cUnit, rlDest, rlResult); |
| 223 | return false; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | } // namespace art |