buzbee | efc6369 | 2012-11-14 16:31:52 -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 | /* This file contains codegen for the X86 ISA */ |
| 18 | |
buzbee | 1bc37c6 | 2012-11-20 13:35:41 -0800 | [diff] [blame] | 19 | #include "x86_lir.h" |
| 20 | #include "../codegen_util.h" |
| 21 | #include "../ralloc_util.h" |
| 22 | |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 23 | namespace art { |
| 24 | |
| 25 | /* |
| 26 | * Perform register memory operation. |
| 27 | */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 28 | LIR* GenRegMemCheck(CompilationUnit* cUnit, ConditionCode cCode, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 29 | int reg1, int base, int offset, ThrowKind kind) |
| 30 | { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 31 | LIR* tgt = RawLIR(cUnit, 0, kPseudoThrowTarget, kind, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 32 | cUnit->currentDalvikOffset, reg1, base, offset); |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 33 | OpRegMem(cUnit, kOpCmp, reg1, base, offset); |
| 34 | LIR* branch = OpCondBranch(cUnit, cCode, tgt); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 35 | // Remember branch target - will process later |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 36 | InsertGrowableList(cUnit, &cUnit->throwLaunchpads, reinterpret_cast<uintptr_t>(tgt)); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 37 | return branch; |
| 38 | } |
| 39 | |
| 40 | /* |
| 41 | * Compare two 64-bit values |
| 42 | * x = y return 0 |
| 43 | * x < y return -1 |
| 44 | * x > y return 1 |
| 45 | * |
| 46 | * slt t0, x.hi, y.hi; # (x.hi < y.hi) ? 1:0 |
| 47 | * sgt t1, x.hi, y.hi; # (y.hi > x.hi) ? 1:0 |
| 48 | * subu res, t0, t1 # res = -1:1:0 for [ < > = ] |
| 49 | * bnez res, finish |
| 50 | * sltu t0, x.lo, y.lo |
| 51 | * sgtu r1, x.lo, y.lo |
| 52 | * subu res, t0, t1 |
| 53 | * finish: |
| 54 | * |
| 55 | */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 56 | void GenCmpLong(CompilationUnit* cUnit, RegLocation rlDest, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 57 | RegLocation rlSrc1, RegLocation rlSrc2) |
| 58 | { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 59 | FlushAllRegs(cUnit); |
| 60 | LockCallTemps(cUnit); // Prepare for explicit register usage |
| 61 | LoadValueDirectWideFixed(cUnit, rlSrc1, r0, r1); |
| 62 | LoadValueDirectWideFixed(cUnit, rlSrc2, r2, r3); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 63 | // Compute (r1:r0) = (r1:r0) - (r3:r2) |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 64 | OpRegReg(cUnit, kOpSub, r0, r2); // r0 = r0 - r2 |
| 65 | OpRegReg(cUnit, kOpSbc, r1, r3); // r1 = r1 - r3 - CF |
| 66 | NewLIR2(cUnit, kX86Set8R, r2, kX86CondL); // r2 = (r1:r0) < (r3:r2) ? 1 : 0 |
| 67 | NewLIR2(cUnit, kX86Movzx8RR, r2, r2); |
| 68 | OpReg(cUnit, kOpNeg, r2); // r2 = -r2 |
| 69 | OpRegReg(cUnit, kOpOr, r0, r1); // r0 = high | low - sets ZF |
| 70 | NewLIR2(cUnit, kX86Set8R, r0, kX86CondNz); // r0 = (r1:r0) != (r3:r2) ? 1 : 0 |
| 71 | NewLIR2(cUnit, kX86Movzx8RR, r0, r0); |
| 72 | OpRegReg(cUnit, kOpOr, r0, r2); // r0 = r0 | r2 |
| 73 | RegLocation rlResult = LocCReturn(); |
| 74 | StoreValue(cUnit, rlDest, rlResult); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 75 | } |
| 76 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 77 | X86ConditionCode X86ConditionEncoding(ConditionCode cond) { |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 78 | switch (cond) { |
| 79 | case kCondEq: return kX86CondEq; |
| 80 | case kCondNe: return kX86CondNe; |
| 81 | case kCondCs: return kX86CondC; |
| 82 | case kCondCc: return kX86CondNc; |
| 83 | case kCondMi: return kX86CondS; |
| 84 | case kCondPl: return kX86CondNs; |
| 85 | case kCondVs: return kX86CondO; |
| 86 | case kCondVc: return kX86CondNo; |
| 87 | case kCondHi: return kX86CondA; |
| 88 | case kCondLs: return kX86CondBe; |
| 89 | case kCondGe: return kX86CondGe; |
| 90 | case kCondLt: return kX86CondL; |
| 91 | case kCondGt: return kX86CondG; |
| 92 | case kCondLe: return kX86CondLe; |
| 93 | case kCondAl: |
| 94 | case kCondNv: LOG(FATAL) << "Should not reach here"; |
| 95 | } |
| 96 | return kX86CondO; |
| 97 | } |
| 98 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 99 | LIR* OpCmpBranch(CompilationUnit* cUnit, ConditionCode cond, int src1, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 100 | int src2, LIR* target) |
| 101 | { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 102 | NewLIR2(cUnit, kX86Cmp32RR, src1, src2); |
| 103 | X86ConditionCode cc = X86ConditionEncoding(cond); |
| 104 | LIR* branch = NewLIR2(cUnit, kX86Jcc8, 0 /* lir operand for Jcc offset */ , |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 105 | cc); |
| 106 | branch->target = target; |
| 107 | return branch; |
| 108 | } |
| 109 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 110 | LIR* OpCmpImmBranch(CompilationUnit* cUnit, ConditionCode cond, int reg, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 111 | int checkValue, LIR* target) |
| 112 | { |
| 113 | if ((checkValue == 0) && (cond == kCondEq || cond == kCondNe)) { |
| 114 | // TODO: when checkValue == 0 and reg is rCX, use the jcxz/nz opcode |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 115 | NewLIR2(cUnit, kX86Test32RR, reg, reg); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 116 | } else { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 117 | NewLIR2(cUnit, IS_SIMM8(checkValue) ? kX86Cmp32RI8 : kX86Cmp32RI, reg, checkValue); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 118 | } |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 119 | X86ConditionCode cc = X86ConditionEncoding(cond); |
| 120 | LIR* branch = NewLIR2(cUnit, kX86Jcc8, 0 /* lir operand for Jcc offset */ , cc); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 121 | branch->target = target; |
| 122 | return branch; |
| 123 | } |
| 124 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 125 | LIR* OpRegCopyNoInsert(CompilationUnit *cUnit, int rDest, int rSrc) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 126 | { |
| 127 | if (X86_FPREG(rDest) || X86_FPREG(rSrc)) |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 128 | return FpRegCopy(cUnit, rDest, rSrc); |
| 129 | LIR* res = RawLIR(cUnit, cUnit->currentDalvikOffset, kX86Mov32RR, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 130 | rDest, rSrc); |
| 131 | if (rDest == rSrc) { |
| 132 | res->flags.isNop = true; |
| 133 | } |
| 134 | return res; |
| 135 | } |
| 136 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 137 | LIR* OpRegCopy(CompilationUnit *cUnit, int rDest, int rSrc) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 138 | { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 139 | LIR *res = OpRegCopyNoInsert(cUnit, rDest, rSrc); |
| 140 | AppendLIR(cUnit, res); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 141 | return res; |
| 142 | } |
| 143 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 144 | void OpRegCopyWide(CompilationUnit *cUnit, int destLo, int destHi, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 145 | int srcLo, int srcHi) |
| 146 | { |
| 147 | bool destFP = X86_FPREG(destLo) && X86_FPREG(destHi); |
| 148 | bool srcFP = X86_FPREG(srcLo) && X86_FPREG(srcHi); |
| 149 | assert(X86_FPREG(srcLo) == X86_FPREG(srcHi)); |
| 150 | assert(X86_FPREG(destLo) == X86_FPREG(destHi)); |
| 151 | if (destFP) { |
| 152 | if (srcFP) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 153 | OpRegCopy(cUnit, S2d(destLo, destHi), S2d(srcLo, srcHi)); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 154 | } else { |
| 155 | // TODO: Prevent this from happening in the code. The result is often |
| 156 | // unused or could have been loaded more easily from memory. |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 157 | NewLIR2(cUnit, kX86MovdxrRR, destLo, srcLo); |
| 158 | NewLIR2(cUnit, kX86MovdxrRR, destHi, srcHi); |
| 159 | NewLIR2(cUnit, kX86PsllqRI, destHi, 32); |
| 160 | NewLIR2(cUnit, kX86OrpsRR, destLo, destHi); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 161 | } |
| 162 | } else { |
| 163 | if (srcFP) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 164 | NewLIR2(cUnit, kX86MovdrxRR, destLo, srcLo); |
| 165 | NewLIR2(cUnit, kX86PsrlqRI, srcLo, 32); |
| 166 | NewLIR2(cUnit, kX86MovdrxRR, destHi, srcLo); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 167 | } else { |
| 168 | // Handle overlap |
| 169 | if (srcHi == destLo) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 170 | OpRegCopy(cUnit, destHi, srcHi); |
| 171 | OpRegCopy(cUnit, destLo, srcLo); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 172 | } else { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 173 | OpRegCopy(cUnit, destLo, srcLo); |
| 174 | OpRegCopy(cUnit, destHi, srcHi); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 175 | } |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 180 | void GenFusedLongCmpBranch(CompilationUnit* cUnit, BasicBlock* bb, MIR* mir) { |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 181 | LIR* labelList = cUnit->blockLabelList; |
| 182 | LIR* taken = &labelList[bb->taken->id]; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 183 | RegLocation rlSrc1 = GetSrcWide(cUnit, mir, 0); |
| 184 | RegLocation rlSrc2 = GetSrcWide(cUnit, mir, 2); |
| 185 | FlushAllRegs(cUnit); |
| 186 | LockCallTemps(cUnit); // Prepare for explicit register usage |
| 187 | LoadValueDirectWideFixed(cUnit, rlSrc1, r0, r1); |
| 188 | LoadValueDirectWideFixed(cUnit, rlSrc2, r2, r3); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 189 | ConditionCode ccode = static_cast<ConditionCode>(mir->dalvikInsn.arg[0]); |
| 190 | // Swap operands and condition code to prevent use of zero flag. |
| 191 | if (ccode == kCondLe || ccode == kCondGt) { |
| 192 | // Compute (r3:r2) = (r3:r2) - (r1:r0) |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 193 | OpRegReg(cUnit, kOpSub, r2, r0); // r2 = r2 - r0 |
| 194 | OpRegReg(cUnit, kOpSbc, r3, r1); // r3 = r3 - r1 - CF |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 195 | } else { |
| 196 | // Compute (r1:r0) = (r1:r0) - (r3:r2) |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 197 | OpRegReg(cUnit, kOpSub, r0, r2); // r0 = r0 - r2 |
| 198 | OpRegReg(cUnit, kOpSbc, r1, r3); // r1 = r1 - r3 - CF |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 199 | } |
| 200 | switch (ccode) { |
| 201 | case kCondEq: |
| 202 | case kCondNe: |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 203 | OpRegReg(cUnit, kOpOr, r0, r1); // r0 = r0 | r1 |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 204 | break; |
| 205 | case kCondLe: |
| 206 | ccode = kCondGe; |
| 207 | break; |
| 208 | case kCondGt: |
| 209 | ccode = kCondLt; |
| 210 | break; |
| 211 | case kCondLt: |
| 212 | case kCondGe: |
| 213 | break; |
| 214 | default: |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 215 | LOG(FATAL) << "Unexpected ccode: " << ccode; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 216 | } |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 217 | OpCondBranch(cUnit, ccode, taken); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 218 | } |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 219 | RegLocation GenDivRemLit(CompilationUnit* cUnit, RegLocation rlDest, int regLo, int lit, bool isDiv) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 220 | { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 221 | LOG(FATAL) << "Unexpected use of GenDivRemLit for x86"; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 222 | return rlDest; |
| 223 | } |
| 224 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 225 | RegLocation GenDivRem(CompilationUnit* cUnit, RegLocation rlDest, int regLo, int regHi, bool isDiv) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 226 | { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 227 | LOG(FATAL) << "Unexpected use of GenDivRem for x86"; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 228 | return rlDest; |
| 229 | } |
| 230 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 231 | bool GenInlinedMinMaxInt(CompilationUnit *cUnit, CallInfo* info, bool isMin) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 232 | { |
| 233 | DCHECK_EQ(cUnit->instructionSet, kX86); |
| 234 | RegLocation rlSrc1 = info->args[0]; |
| 235 | RegLocation rlSrc2 = info->args[1]; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 236 | rlSrc1 = LoadValue(cUnit, rlSrc1, kCoreReg); |
| 237 | rlSrc2 = LoadValue(cUnit, rlSrc2, kCoreReg); |
| 238 | RegLocation rlDest = InlineTarget(cUnit, info); |
| 239 | RegLocation rlResult = EvalLoc(cUnit, rlDest, kCoreReg, true); |
| 240 | OpRegReg(cUnit, kOpCmp, rlSrc1.lowReg, rlSrc2.lowReg); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 241 | DCHECK_EQ(cUnit->instructionSet, kX86); |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 242 | LIR* branch = NewLIR2(cUnit, kX86Jcc8, 0, isMin ? kX86CondG : kX86CondL); |
| 243 | OpRegReg(cUnit, kOpMov, rlResult.lowReg, rlSrc1.lowReg); |
| 244 | LIR* branch2 = NewLIR1(cUnit, kX86Jmp8, 0); |
| 245 | branch->target = NewLIR0(cUnit, kPseudoTargetLabel); |
| 246 | OpRegReg(cUnit, kOpMov, rlResult.lowReg, rlSrc2.lowReg); |
| 247 | branch2->target = NewLIR0(cUnit, kPseudoTargetLabel); |
| 248 | StoreValue(cUnit, rlDest, rlResult); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 249 | return true; |
| 250 | } |
| 251 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 252 | void OpLea(CompilationUnit* cUnit, int rBase, int reg1, int reg2, int scale, int offset) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 253 | { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 254 | NewLIR5(cUnit, kX86Lea32RA, rBase, reg1, reg2, scale, offset); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 255 | } |
| 256 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 257 | void OpTlsCmp(CompilationUnit* cUnit, int offset, int val) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 258 | { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 259 | NewLIR2(cUnit, kX86Cmp16TI8, offset, val); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 260 | } |
| 261 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 262 | bool GenInlinedCas32(CompilationUnit* cUnit, CallInfo* info, bool need_write_barrier) { |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 263 | DCHECK_NE(cUnit->instructionSet, kThumb2); |
| 264 | return false; |
| 265 | } |
| 266 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 267 | LIR* OpPcRelLoad(CompilationUnit* cUnit, int reg, LIR* target) { |
| 268 | LOG(FATAL) << "Unexpected use of OpPcRelLoad for x86"; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 269 | return NULL; |
| 270 | } |
| 271 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 272 | LIR* OpVldm(CompilationUnit* cUnit, int rBase, int count) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 273 | { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 274 | LOG(FATAL) << "Unexpected use of OpVldm for x86"; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 275 | return NULL; |
| 276 | } |
| 277 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 278 | LIR* OpVstm(CompilationUnit* cUnit, int rBase, int count) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 279 | { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 280 | LOG(FATAL) << "Unexpected use of OpVstm for x86"; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 281 | return NULL; |
| 282 | } |
| 283 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 284 | void GenMultiplyByTwoBitMultiplier(CompilationUnit* cUnit, RegLocation rlSrc, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 285 | RegLocation rlResult, int lit, |
| 286 | int firstBit, int secondBit) |
| 287 | { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 288 | int tReg = AllocTemp(cUnit); |
| 289 | OpRegRegImm(cUnit, kOpLsl, tReg, rlSrc.lowReg, secondBit - firstBit); |
| 290 | OpRegRegReg(cUnit, kOpAdd, rlResult.lowReg, rlSrc.lowReg, tReg); |
| 291 | FreeTemp(cUnit, tReg); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 292 | if (firstBit != 0) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 293 | OpRegRegImm(cUnit, kOpLsl, rlResult.lowReg, rlResult.lowReg, firstBit); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 294 | } |
| 295 | } |
| 296 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 297 | void GenDivZeroCheck(CompilationUnit* cUnit, int regLo, int regHi) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 298 | { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 299 | int tReg = AllocTemp(cUnit); |
| 300 | OpRegRegReg(cUnit, kOpOr, tReg, regLo, regHi); |
| 301 | GenImmedCheck(cUnit, kCondEq, tReg, 0, kThrowDivZero); |
| 302 | FreeTemp(cUnit, tReg); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | // Test suspend flag, return target of taken suspend branch |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 306 | LIR* OpTestSuspend(CompilationUnit* cUnit, LIR* target) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 307 | { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 308 | OpTlsCmp(cUnit, Thread::ThreadFlagsOffset().Int32Value(), 0); |
| 309 | return OpCondBranch(cUnit, (target == NULL) ? kCondNe : kCondEq, target); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | // Decrement register and branch on condition |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 313 | LIR* OpDecAndBranch(CompilationUnit* cUnit, ConditionCode cCode, int reg, LIR* target) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 314 | { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 315 | OpRegImm(cUnit, kOpSub, reg, 1); |
| 316 | return OpCmpImmBranch(cUnit, cCode, reg, 0, target); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 317 | } |
| 318 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 319 | bool SmallLiteralDivide(CompilationUnit* cUnit, Instruction::Code dalvikOpcode, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 320 | RegLocation rlSrc, RegLocation rlDest, int lit) |
| 321 | { |
| 322 | LOG(FATAL) << "Unexpected use of smallLiteralDive in x86"; |
| 323 | return false; |
| 324 | } |
| 325 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 326 | LIR* OpIT(CompilationUnit* cUnit, ArmConditionCode cond, const char* guide) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 327 | { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 328 | LOG(FATAL) << "Unexpected use of OpIT in x86"; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 329 | return NULL; |
| 330 | } |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 331 | bool GenAddLong(CompilationUnit* cUnit, RegLocation rlDest, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 332 | RegLocation rlSrc1, RegLocation rlSrc2) |
| 333 | { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 334 | FlushAllRegs(cUnit); |
| 335 | LockCallTemps(cUnit); // Prepare for explicit register usage |
| 336 | LoadValueDirectWideFixed(cUnit, rlSrc1, r0, r1); |
| 337 | LoadValueDirectWideFixed(cUnit, rlSrc2, r2, r3); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 338 | // Compute (r1:r0) = (r1:r0) + (r2:r3) |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 339 | OpRegReg(cUnit, kOpAdd, r0, r2); // r0 = r0 + r2 |
| 340 | OpRegReg(cUnit, kOpAdc, r1, r3); // r1 = r1 + r3 + CF |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 341 | RegLocation rlResult = {kLocPhysReg, 1, 0, 0, 0, 0, 0, 0, 1, r0, r1, |
| 342 | INVALID_SREG, INVALID_SREG}; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 343 | StoreValueWide(cUnit, rlDest, rlResult); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 344 | return false; |
| 345 | } |
| 346 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 347 | bool GenSubLong(CompilationUnit* cUnit, RegLocation rlDest, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 348 | RegLocation rlSrc1, RegLocation rlSrc2) |
| 349 | { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 350 | FlushAllRegs(cUnit); |
| 351 | LockCallTemps(cUnit); // Prepare for explicit register usage |
| 352 | LoadValueDirectWideFixed(cUnit, rlSrc1, r0, r1); |
| 353 | LoadValueDirectWideFixed(cUnit, rlSrc2, r2, r3); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 354 | // Compute (r1:r0) = (r1:r0) + (r2:r3) |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 355 | OpRegReg(cUnit, kOpSub, r0, r2); // r0 = r0 - r2 |
| 356 | OpRegReg(cUnit, kOpSbc, r1, r3); // r1 = r1 - r3 - CF |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 357 | RegLocation rlResult = {kLocPhysReg, 1, 0, 0, 0, 0, 0, 0, 1, r0, r1, |
| 358 | INVALID_SREG, INVALID_SREG}; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 359 | StoreValueWide(cUnit, rlDest, rlResult); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 360 | return false; |
| 361 | } |
| 362 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 363 | bool GenAndLong(CompilationUnit* cUnit, RegLocation rlDest, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 364 | RegLocation rlSrc1, RegLocation rlSrc2) |
| 365 | { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 366 | FlushAllRegs(cUnit); |
| 367 | LockCallTemps(cUnit); // Prepare for explicit register usage |
| 368 | LoadValueDirectWideFixed(cUnit, rlSrc1, r0, r1); |
| 369 | LoadValueDirectWideFixed(cUnit, rlSrc2, r2, r3); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 370 | // Compute (r1:r0) = (r1:r0) + (r2:r3) |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 371 | OpRegReg(cUnit, kOpAnd, r0, r2); // r0 = r0 - r2 |
| 372 | OpRegReg(cUnit, kOpAnd, r1, r3); // r1 = r1 - r3 - CF |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 373 | RegLocation rlResult = {kLocPhysReg, 1, 0, 0, 0, 0, 0, 0, 1, r0, r1, |
| 374 | INVALID_SREG, INVALID_SREG}; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 375 | StoreValueWide(cUnit, rlDest, rlResult); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 376 | return false; |
| 377 | } |
| 378 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 379 | bool GenOrLong(CompilationUnit* cUnit, RegLocation rlDest, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 380 | RegLocation rlSrc1, RegLocation rlSrc2) |
| 381 | { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 382 | FlushAllRegs(cUnit); |
| 383 | LockCallTemps(cUnit); // Prepare for explicit register usage |
| 384 | LoadValueDirectWideFixed(cUnit, rlSrc1, r0, r1); |
| 385 | LoadValueDirectWideFixed(cUnit, rlSrc2, r2, r3); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 386 | // Compute (r1:r0) = (r1:r0) + (r2:r3) |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 387 | OpRegReg(cUnit, kOpOr, r0, r2); // r0 = r0 - r2 |
| 388 | OpRegReg(cUnit, kOpOr, r1, r3); // r1 = r1 - r3 - CF |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 389 | RegLocation rlResult = {kLocPhysReg, 1, 0, 0, 0, 0, 0, 0, 1, r0, r1, |
| 390 | INVALID_SREG, INVALID_SREG}; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 391 | StoreValueWide(cUnit, rlDest, rlResult); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 392 | return false; |
| 393 | } |
| 394 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 395 | bool GenXorLong(CompilationUnit* cUnit, RegLocation rlDest, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 396 | RegLocation rlSrc1, RegLocation rlSrc2) |
| 397 | { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 398 | FlushAllRegs(cUnit); |
| 399 | LockCallTemps(cUnit); // Prepare for explicit register usage |
| 400 | LoadValueDirectWideFixed(cUnit, rlSrc1, r0, r1); |
| 401 | LoadValueDirectWideFixed(cUnit, rlSrc2, r2, r3); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 402 | // Compute (r1:r0) = (r1:r0) + (r2:r3) |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 403 | OpRegReg(cUnit, kOpXor, r0, r2); // r0 = r0 - r2 |
| 404 | OpRegReg(cUnit, kOpXor, r1, r3); // r1 = r1 - r3 - CF |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 405 | RegLocation rlResult = {kLocPhysReg, 1, 0, 0, 0, 0, 0, 0, 1, r0, r1, |
| 406 | INVALID_SREG, INVALID_SREG}; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 407 | StoreValueWide(cUnit, rlDest, rlResult); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 408 | return false; |
| 409 | } |
| 410 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 411 | bool GenNegLong(CompilationUnit* cUnit, RegLocation rlDest, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 412 | RegLocation rlSrc) |
| 413 | { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 414 | FlushAllRegs(cUnit); |
| 415 | LockCallTemps(cUnit); // Prepare for explicit register usage |
| 416 | LoadValueDirectWideFixed(cUnit, rlSrc, r0, r1); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 417 | // Compute (r1:r0) = -(r1:r0) |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 418 | OpRegReg(cUnit, kOpNeg, r0, r0); // r0 = -r0 |
| 419 | OpRegImm(cUnit, kOpAdc, r1, 0); // r1 = r1 + CF |
| 420 | OpRegReg(cUnit, kOpNeg, r1, r1); // r1 = -r1 |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 421 | RegLocation rlResult = {kLocPhysReg, 1, 0, 0, 0, 0, 0, 0, 1, r0, r1, |
| 422 | INVALID_SREG, INVALID_SREG}; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 423 | StoreValueWide(cUnit, rlDest, rlResult); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 424 | return false; |
| 425 | } |
| 426 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 427 | void OpRegThreadMem(CompilationUnit* cUnit, OpKind op, int rDest, int threadOffset) { |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 428 | X86OpCode opcode = kX86Bkpt; |
| 429 | switch (op) { |
| 430 | case kOpCmp: opcode = kX86Cmp32RT; break; |
| 431 | default: |
| 432 | LOG(FATAL) << "Bad opcode: " << op; |
| 433 | break; |
| 434 | } |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 435 | NewLIR2(cUnit, opcode, rDest, threadOffset); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | } // namespace art |