Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | #include "code_generator_x86.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 18 | |
| 19 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 20 | #include "gc/accounting/card_table.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 21 | #include "mirror/array-inl.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 22 | #include "mirror/art_method.h" |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 23 | #include "mirror/class.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 24 | #include "thread.h" |
Roland Levillain | 647b96f | 2014-11-11 12:26:26 +0000 | [diff] [blame] | 25 | #include "utils.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 26 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 27 | #include "utils/stack_checks.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 28 | #include "utils/x86/assembler_x86.h" |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 29 | #include "utils/x86/managed_register_x86.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 30 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 31 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 32 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 33 | namespace x86 { |
| 34 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 35 | static constexpr bool kExplicitStackOverflowCheck = false; |
| 36 | |
| 37 | static constexpr int kNumberOfPushedRegistersAtEntry = 1; |
| 38 | static constexpr int kCurrentMethodStackOffset = 0; |
| 39 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 40 | static constexpr Register kRuntimeParameterCoreRegisters[] = { EAX, ECX, EDX }; |
| 41 | static constexpr size_t kRuntimeParameterCoreRegistersLength = |
| 42 | arraysize(kRuntimeParameterCoreRegisters); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 43 | static constexpr XmmRegister kRuntimeParameterFpuRegisters[] = { }; |
| 44 | static constexpr size_t kRuntimeParameterFpuRegistersLength = 0; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 45 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 46 | class InvokeRuntimeCallingConvention : public CallingConvention<Register, XmmRegister> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 47 | public: |
| 48 | InvokeRuntimeCallingConvention() |
| 49 | : CallingConvention(kRuntimeParameterCoreRegisters, |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 50 | kRuntimeParameterCoreRegistersLength, |
| 51 | kRuntimeParameterFpuRegisters, |
| 52 | kRuntimeParameterFpuRegistersLength) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 53 | |
| 54 | private: |
| 55 | DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention); |
| 56 | }; |
| 57 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 58 | #define __ reinterpret_cast<X86Assembler*>(codegen->GetAssembler())-> |
| 59 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 60 | class SlowPathCodeX86 : public SlowPathCode { |
| 61 | public: |
| 62 | SlowPathCodeX86() : entry_label_(), exit_label_() {} |
| 63 | |
| 64 | Label* GetEntryLabel() { return &entry_label_; } |
| 65 | Label* GetExitLabel() { return &exit_label_; } |
| 66 | |
| 67 | private: |
| 68 | Label entry_label_; |
| 69 | Label exit_label_; |
| 70 | |
| 71 | DISALLOW_COPY_AND_ASSIGN(SlowPathCodeX86); |
| 72 | }; |
| 73 | |
| 74 | class NullCheckSlowPathX86 : public SlowPathCodeX86 { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 75 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 76 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 77 | |
| 78 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 79 | __ Bind(GetEntryLabel()); |
| 80 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pThrowNullPointer))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 81 | codegen->RecordPcInfo(instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 85 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 86 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 87 | }; |
| 88 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 89 | class DivZeroCheckSlowPathX86 : public SlowPathCodeX86 { |
| 90 | public: |
| 91 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 92 | |
| 93 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 94 | __ Bind(GetEntryLabel()); |
| 95 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pThrowDivZero))); |
| 96 | codegen->RecordPcInfo(instruction_, instruction_->GetDexPc()); |
| 97 | } |
| 98 | |
| 99 | private: |
| 100 | HDivZeroCheck* const instruction_; |
| 101 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 102 | }; |
| 103 | |
| 104 | class DivMinusOneSlowPathX86 : public SlowPathCodeX86 { |
| 105 | public: |
| 106 | explicit DivMinusOneSlowPathX86(Register reg) : reg_(reg) {} |
| 107 | |
| 108 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 109 | __ Bind(GetEntryLabel()); |
| 110 | __ negl(reg_); |
| 111 | __ jmp(GetExitLabel()); |
| 112 | } |
| 113 | |
| 114 | private: |
| 115 | Register reg_; |
| 116 | DISALLOW_COPY_AND_ASSIGN(DivMinusOneSlowPathX86); |
| 117 | }; |
| 118 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 119 | class StackOverflowCheckSlowPathX86 : public SlowPathCodeX86 { |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 120 | public: |
| 121 | StackOverflowCheckSlowPathX86() {} |
| 122 | |
| 123 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 124 | __ Bind(GetEntryLabel()); |
| 125 | __ addl(ESP, |
| 126 | Immediate(codegen->GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86WordSize)); |
| 127 | __ fs()->jmp(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pThrowStackOverflow))); |
| 128 | } |
| 129 | |
| 130 | private: |
| 131 | DISALLOW_COPY_AND_ASSIGN(StackOverflowCheckSlowPathX86); |
| 132 | }; |
| 133 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 134 | class BoundsCheckSlowPathX86 : public SlowPathCodeX86 { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 135 | public: |
Roland Levillain | 5799fc0 | 2014-09-25 12:15:20 +0100 | [diff] [blame] | 136 | BoundsCheckSlowPathX86(HBoundsCheck* instruction, |
| 137 | Location index_location, |
| 138 | Location length_location) |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 139 | : instruction_(instruction), index_location_(index_location), length_location_(length_location) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 140 | |
| 141 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 142 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 143 | __ Bind(GetEntryLabel()); |
| 144 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 145 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), index_location_); |
| 146 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(1)), length_location_); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 147 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pThrowArrayBounds))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 148 | codegen->RecordPcInfo(instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 152 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 153 | const Location index_location_; |
| 154 | const Location length_location_; |
| 155 | |
| 156 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 157 | }; |
| 158 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 159 | class SuspendCheckSlowPathX86 : public SlowPathCodeX86 { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 160 | public: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 161 | explicit SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
| 162 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 163 | |
| 164 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 165 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 166 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 167 | codegen->SaveLiveRegisters(instruction_->GetLocations()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 168 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pTestSuspend))); |
| 169 | codegen->RecordPcInfo(instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 170 | codegen->RestoreLiveRegisters(instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 171 | if (successor_ == nullptr) { |
| 172 | __ jmp(GetReturnLabel()); |
| 173 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 174 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 175 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 176 | } |
| 177 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 178 | Label* GetReturnLabel() { |
| 179 | DCHECK(successor_ == nullptr); |
| 180 | return &return_label_; |
| 181 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 182 | |
| 183 | private: |
| 184 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 185 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 186 | Label return_label_; |
| 187 | |
| 188 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 189 | }; |
| 190 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 191 | class LoadStringSlowPathX86 : public SlowPathCodeX86 { |
| 192 | public: |
| 193 | explicit LoadStringSlowPathX86(HLoadString* instruction) : instruction_(instruction) {} |
| 194 | |
| 195 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 196 | LocationSummary* locations = instruction_->GetLocations(); |
| 197 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 198 | |
| 199 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 200 | __ Bind(GetEntryLabel()); |
| 201 | codegen->SaveLiveRegisters(locations); |
| 202 | |
| 203 | InvokeRuntimeCallingConvention calling_convention; |
| 204 | x86_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(0)); |
| 205 | __ movl(calling_convention.GetRegisterAt(1), Immediate(instruction_->GetStringIndex())); |
| 206 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pResolveString))); |
| 207 | codegen->RecordPcInfo(instruction_, instruction_->GetDexPc()); |
| 208 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 209 | codegen->RestoreLiveRegisters(locations); |
| 210 | |
| 211 | __ jmp(GetExitLabel()); |
| 212 | } |
| 213 | |
| 214 | private: |
| 215 | HLoadString* const instruction_; |
| 216 | |
| 217 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 218 | }; |
| 219 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 220 | class LoadClassSlowPathX86 : public SlowPathCodeX86 { |
| 221 | public: |
| 222 | LoadClassSlowPathX86(HLoadClass* cls, |
| 223 | HInstruction* at, |
| 224 | uint32_t dex_pc, |
| 225 | bool do_clinit) |
| 226 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 227 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 228 | } |
| 229 | |
| 230 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 231 | LocationSummary* locations = at_->GetLocations(); |
| 232 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 233 | __ Bind(GetEntryLabel()); |
| 234 | codegen->SaveLiveRegisters(locations); |
| 235 | |
| 236 | InvokeRuntimeCallingConvention calling_convention; |
| 237 | __ movl(calling_convention.GetRegisterAt(0), Immediate(cls_->GetTypeIndex())); |
| 238 | x86_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
| 239 | __ fs()->call(Address::Absolute(do_clinit_ |
| 240 | ? QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pInitializeStaticStorage) |
| 241 | : QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pInitializeType))); |
| 242 | codegen->RecordPcInfo(at_, dex_pc_); |
| 243 | |
| 244 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 245 | Location out = locations->Out(); |
| 246 | if (out.IsValid()) { |
| 247 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 248 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 249 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 250 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 251 | codegen->RestoreLiveRegisters(locations); |
| 252 | __ jmp(GetExitLabel()); |
| 253 | } |
| 254 | |
| 255 | private: |
| 256 | // The class this slow path will load. |
| 257 | HLoadClass* const cls_; |
| 258 | |
| 259 | // The instruction where this slow path is happening. |
| 260 | // (Might be the load class or an initialization check). |
| 261 | HInstruction* const at_; |
| 262 | |
| 263 | // The dex PC of `at_`. |
| 264 | const uint32_t dex_pc_; |
| 265 | |
| 266 | // Whether to initialize the class. |
| 267 | const bool do_clinit_; |
| 268 | |
| 269 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 270 | }; |
| 271 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 272 | class TypeCheckSlowPathX86 : public SlowPathCodeX86 { |
| 273 | public: |
| 274 | TypeCheckSlowPathX86(HTypeCheck* instruction, Location object_class) |
| 275 | : instruction_(instruction), |
| 276 | object_class_(object_class) {} |
| 277 | |
| 278 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 279 | LocationSummary* locations = instruction_->GetLocations(); |
| 280 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 281 | |
| 282 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 283 | __ Bind(GetEntryLabel()); |
| 284 | codegen->SaveLiveRegisters(locations); |
| 285 | |
| 286 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 287 | // move resolver. |
| 288 | InvokeRuntimeCallingConvention calling_convention; |
| 289 | MoveOperands move1(locations->InAt(1), |
| 290 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 291 | nullptr); |
| 292 | MoveOperands move2(object_class_, |
| 293 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 294 | nullptr); |
| 295 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 296 | parallel_move.AddMove(&move1); |
| 297 | parallel_move.AddMove(&move2); |
| 298 | x86_codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 299 | |
| 300 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pInstanceofNonTrivial))); |
| 301 | codegen->RecordPcInfo(instruction_, instruction_->GetDexPc()); |
| 302 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 303 | codegen->RestoreLiveRegisters(locations); |
| 304 | |
| 305 | __ jmp(GetExitLabel()); |
| 306 | } |
| 307 | |
| 308 | private: |
| 309 | HTypeCheck* const instruction_; |
| 310 | const Location object_class_; |
| 311 | |
| 312 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 313 | }; |
| 314 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 315 | #undef __ |
| 316 | #define __ reinterpret_cast<X86Assembler*>(GetAssembler())-> |
| 317 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 318 | inline Condition X86Condition(IfCondition cond) { |
| 319 | switch (cond) { |
| 320 | case kCondEQ: return kEqual; |
| 321 | case kCondNE: return kNotEqual; |
| 322 | case kCondLT: return kLess; |
| 323 | case kCondLE: return kLessEqual; |
| 324 | case kCondGT: return kGreater; |
| 325 | case kCondGE: return kGreaterEqual; |
| 326 | default: |
| 327 | LOG(FATAL) << "Unknown if condition"; |
| 328 | } |
| 329 | return kEqual; |
| 330 | } |
| 331 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 332 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
| 333 | stream << X86ManagedRegister::FromCpuRegister(Register(reg)); |
| 334 | } |
| 335 | |
| 336 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| 337 | stream << X86ManagedRegister::FromXmmRegister(XmmRegister(reg)); |
| 338 | } |
| 339 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 340 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 341 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 342 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 343 | } |
| 344 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 345 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 346 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 347 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 348 | } |
| 349 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 350 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph) |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 351 | : CodeGenerator(graph, kNumberOfCpuRegisters, kNumberOfXmmRegisters, kNumberOfRegisterPairs), |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 352 | block_labels_(graph->GetArena(), 0), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 353 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 354 | instruction_visitor_(graph, this), |
| 355 | move_resolver_(graph->GetArena(), this) {} |
| 356 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 357 | size_t CodeGeneratorX86::FrameEntrySpillSize() const { |
| 358 | return kNumberOfPushedRegistersAtEntry * kX86WordSize; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 359 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 360 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 361 | Location CodeGeneratorX86::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 362 | switch (type) { |
| 363 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 364 | size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 365 | X86ManagedRegister pair = |
| 366 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 367 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]); |
| 368 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]); |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 369 | blocked_core_registers_[pair.AsRegisterPairLow()] = true; |
| 370 | blocked_core_registers_[pair.AsRegisterPairHigh()] = true; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 371 | UpdateBlockedPairRegisters(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 372 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | case Primitive::kPrimByte: |
| 376 | case Primitive::kPrimBoolean: |
| 377 | case Primitive::kPrimChar: |
| 378 | case Primitive::kPrimShort: |
| 379 | case Primitive::kPrimInt: |
| 380 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 381 | Register reg = static_cast<Register>( |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 382 | FindFreeEntry(blocked_core_registers_, kNumberOfCpuRegisters)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 383 | // Block all register pairs that contain `reg`. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 384 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 385 | X86ManagedRegister current = |
| 386 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 387 | if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 388 | blocked_register_pairs_[i] = true; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 389 | } |
| 390 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 391 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 395 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 396 | return Location::FpuRegisterLocation( |
| 397 | FindFreeEntry(blocked_fpu_registers_, kNumberOfXmmRegisters)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 398 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 399 | |
| 400 | case Primitive::kPrimVoid: |
| 401 | LOG(FATAL) << "Unreachable type " << type; |
| 402 | } |
| 403 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 404 | return Location(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 405 | } |
| 406 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 407 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 408 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 409 | blocked_register_pairs_[ECX_EDX] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 410 | |
| 411 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 412 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 413 | |
| 414 | // TODO: We currently don't use Quick's callee saved registers. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 415 | blocked_core_registers_[EBP] = true; |
| 416 | blocked_core_registers_[ESI] = true; |
| 417 | blocked_core_registers_[EDI] = true; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 418 | |
| 419 | UpdateBlockedPairRegisters(); |
| 420 | } |
| 421 | |
| 422 | void CodeGeneratorX86::UpdateBlockedPairRegisters() const { |
| 423 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 424 | X86ManagedRegister current = |
| 425 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 426 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 427 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 428 | blocked_register_pairs_[i] = true; |
| 429 | } |
| 430 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 431 | } |
| 432 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 433 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
| 434 | : HGraphVisitor(graph), |
| 435 | assembler_(codegen->GetAssembler()), |
| 436 | codegen_(codegen) {} |
| 437 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 438 | void CodeGeneratorX86::GenerateFrameEntry() { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 439 | // Create a fake register to mimic Quick. |
| 440 | static const int kFakeReturnRegister = 8; |
| 441 | core_spill_mask_ |= (1 << kFakeReturnRegister); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 442 | |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 443 | bool skip_overflow_check = IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 444 | if (!skip_overflow_check && !kExplicitStackOverflowCheck) { |
| 445 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 446 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 447 | } |
| 448 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 449 | // The return PC has already been pushed on the stack. |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 450 | __ subl(ESP, Immediate(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86WordSize)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 451 | |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 452 | if (!skip_overflow_check && kExplicitStackOverflowCheck) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 453 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathX86(); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 454 | AddSlowPath(slow_path); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 455 | |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 456 | __ fs()->cmpl(ESP, Address::Absolute(Thread::StackEndOffset<kX86WordSize>())); |
| 457 | __ j(kLess, slow_path->GetEntryLabel()); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 458 | } |
| 459 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 460 | __ movl(Address(ESP, kCurrentMethodStackOffset), EAX); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | void CodeGeneratorX86::GenerateFrameExit() { |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 464 | __ addl(ESP, Immediate(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86WordSize)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 465 | } |
| 466 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 467 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 468 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 469 | } |
| 470 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 471 | void CodeGeneratorX86::LoadCurrentMethod(Register reg) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 472 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 473 | } |
| 474 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 475 | Location CodeGeneratorX86::GetStackLocation(HLoadLocal* load) const { |
| 476 | switch (load->GetType()) { |
| 477 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 478 | case Primitive::kPrimDouble: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 479 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
| 480 | break; |
| 481 | |
| 482 | case Primitive::kPrimInt: |
| 483 | case Primitive::kPrimNot: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 484 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 485 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 486 | |
| 487 | case Primitive::kPrimBoolean: |
| 488 | case Primitive::kPrimByte: |
| 489 | case Primitive::kPrimChar: |
| 490 | case Primitive::kPrimShort: |
| 491 | case Primitive::kPrimVoid: |
| 492 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
| 493 | } |
| 494 | |
| 495 | LOG(FATAL) << "Unreachable"; |
| 496 | return Location(); |
| 497 | } |
| 498 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 499 | Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) { |
| 500 | switch (type) { |
| 501 | case Primitive::kPrimBoolean: |
| 502 | case Primitive::kPrimByte: |
| 503 | case Primitive::kPrimChar: |
| 504 | case Primitive::kPrimShort: |
| 505 | case Primitive::kPrimInt: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 506 | case Primitive::kPrimFloat: |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 507 | case Primitive::kPrimNot: { |
| 508 | uint32_t index = gp_index_++; |
| 509 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 510 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 511 | } else { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 512 | return Location::StackSlot(calling_convention.GetStackOffsetOf(index)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 513 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 514 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 515 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 516 | case Primitive::kPrimLong: |
| 517 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 518 | uint32_t index = gp_index_; |
| 519 | gp_index_ += 2; |
| 520 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 521 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 522 | calling_convention.GetRegisterPairAt(index)); |
| 523 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 524 | } else if (index + 1 == calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 525 | // On X86, the register index and stack index of a quick parameter is the same, since |
| 526 | // we are passing floating pointer values in core registers. |
| 527 | return Location::QuickParameter(index, index); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 528 | } else { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 529 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 530 | } |
| 531 | } |
| 532 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 533 | case Primitive::kPrimVoid: |
| 534 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 535 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 536 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 537 | return Location(); |
| 538 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 539 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 540 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 541 | if (source.Equals(destination)) { |
| 542 | return; |
| 543 | } |
| 544 | if (destination.IsRegister()) { |
| 545 | if (source.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 546 | __ movl(destination.As<Register>(), source.As<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 547 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 548 | __ movd(destination.As<Register>(), source.As<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 549 | } else { |
| 550 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 551 | __ movl(destination.As<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 552 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 553 | } else if (destination.IsFpuRegister()) { |
| 554 | if (source.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 555 | __ movd(destination.As<XmmRegister>(), source.As<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 556 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 557 | __ movaps(destination.As<XmmRegister>(), source.As<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 558 | } else { |
| 559 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 560 | __ movss(destination.As<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 561 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 562 | } else { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 563 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 564 | if (source.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 565 | __ movl(Address(ESP, destination.GetStackIndex()), source.As<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 566 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 567 | __ movss(Address(ESP, destination.GetStackIndex()), source.As<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 568 | } else { |
| 569 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 570 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 571 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 572 | } |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 577 | if (source.Equals(destination)) { |
| 578 | return; |
| 579 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 580 | if (destination.IsRegisterPair()) { |
| 581 | if (source.IsRegisterPair()) { |
| 582 | __ movl(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>()); |
| 583 | __ movl(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 584 | } else if (source.IsFpuRegister()) { |
| 585 | LOG(FATAL) << "Unimplemented"; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 586 | } else if (source.IsQuickParameter()) { |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 587 | uint16_t register_index = source.GetQuickParameterRegisterIndex(); |
| 588 | uint16_t stack_index = source.GetQuickParameterStackIndex(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 589 | InvokeDexCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 590 | __ movl(destination.AsRegisterPairLow<Register>(), |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 591 | calling_convention.GetRegisterAt(register_index)); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 592 | __ movl(destination.AsRegisterPairHigh<Register>(), Address(ESP, |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 593 | calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 594 | } else { |
| 595 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 596 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 597 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 598 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 599 | } |
| 600 | } else if (destination.IsQuickParameter()) { |
| 601 | InvokeDexCallingConvention calling_convention; |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 602 | uint16_t register_index = destination.GetQuickParameterRegisterIndex(); |
| 603 | uint16_t stack_index = destination.GetQuickParameterStackIndex(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 604 | if (source.IsRegister()) { |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 605 | __ movl(calling_convention.GetRegisterAt(register_index), source.AsRegisterPairLow<Register>()); |
| 606 | __ movl(Address(ESP, calling_convention.GetStackOffsetOf(stack_index + 1)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 607 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 608 | } else if (source.IsFpuRegister()) { |
| 609 | LOG(FATAL) << "Unimplemented"; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 610 | } else { |
| 611 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 612 | __ movl(calling_convention.GetRegisterAt(register_index), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 613 | Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 614 | __ pushl(Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 615 | __ popl(Address(ESP, calling_convention.GetStackOffsetOf(stack_index + 1))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 616 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 617 | } else if (destination.IsFpuRegister()) { |
| 618 | if (source.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 619 | __ movsd(destination.As<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 620 | } else { |
| 621 | LOG(FATAL) << "Unimplemented"; |
| 622 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 623 | } else { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 624 | DCHECK(destination.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 625 | if (source.IsRegisterPair()) { |
| 626 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 627 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 628 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 629 | } else if (source.IsQuickParameter()) { |
| 630 | InvokeDexCallingConvention calling_convention; |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 631 | uint16_t register_index = source.GetQuickParameterRegisterIndex(); |
| 632 | uint16_t stack_index = source.GetQuickParameterStackIndex(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 633 | __ movl(Address(ESP, destination.GetStackIndex()), |
Nicolas Geoffray | 0a6c459 | 2014-10-30 16:37:57 +0000 | [diff] [blame] | 634 | calling_convention.GetRegisterAt(register_index)); |
| 635 | DCHECK_EQ(calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 636 | static_cast<size_t>(destination.GetHighStackIndex(kX86WordSize))); |
| 637 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 638 | __ movsd(Address(ESP, destination.GetStackIndex()), source.As<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 639 | } else { |
| 640 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 641 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 642 | __ popl(Address(ESP, destination.GetStackIndex())); |
| 643 | __ pushl(Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 644 | __ popl(Address(ESP, destination.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 645 | } |
| 646 | } |
| 647 | } |
| 648 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 649 | void CodeGeneratorX86::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 650 | if (instruction->IsIntConstant()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 651 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
| 652 | if (location.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 653 | __ movl(location.As<Register>(), imm); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 654 | } else if (location.IsStackSlot()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 655 | __ movl(Address(ESP, location.GetStackIndex()), imm); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 656 | } else { |
| 657 | DCHECK(location.IsConstant()); |
| 658 | DCHECK_EQ(location.GetConstant(), instruction); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 659 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 660 | } else if (instruction->IsLongConstant()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 661 | int64_t value = instruction->AsLongConstant()->GetValue(); |
| 662 | if (location.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 663 | __ movl(location.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 664 | __ movl(location.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 665 | } else if (location.IsDoubleStackSlot()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 666 | __ movl(Address(ESP, location.GetStackIndex()), Immediate(Low32Bits(value))); |
| 667 | __ movl(Address(ESP, location.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 668 | } else { |
| 669 | DCHECK(location.IsConstant()); |
| 670 | DCHECK_EQ(location.GetConstant(), instruction); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 671 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 672 | } else if (instruction->IsTemporary()) { |
| 673 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
| 674 | Move32(location, temp_location); |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 675 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 676 | int slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 677 | switch (instruction->GetType()) { |
| 678 | case Primitive::kPrimBoolean: |
| 679 | case Primitive::kPrimByte: |
| 680 | case Primitive::kPrimChar: |
| 681 | case Primitive::kPrimShort: |
| 682 | case Primitive::kPrimInt: |
| 683 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 684 | case Primitive::kPrimFloat: |
| 685 | Move32(location, Location::StackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 686 | break; |
| 687 | |
| 688 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 689 | case Primitive::kPrimDouble: |
| 690 | Move64(location, Location::DoubleStackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 691 | break; |
| 692 | |
| 693 | default: |
| 694 | LOG(FATAL) << "Unimplemented local type " << instruction->GetType(); |
| 695 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 696 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 697 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 698 | switch (instruction->GetType()) { |
| 699 | case Primitive::kPrimBoolean: |
| 700 | case Primitive::kPrimByte: |
| 701 | case Primitive::kPrimChar: |
| 702 | case Primitive::kPrimShort: |
| 703 | case Primitive::kPrimInt: |
| 704 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 705 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 706 | Move32(location, instruction->GetLocations()->Out()); |
| 707 | break; |
| 708 | |
| 709 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 710 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 711 | Move64(location, instruction->GetLocations()->Out()); |
| 712 | break; |
| 713 | |
| 714 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 715 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 716 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 717 | } |
| 718 | } |
| 719 | |
| 720 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 721 | got->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 722 | } |
| 723 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 724 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 725 | HBasicBlock* successor = got->GetSuccessor(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 726 | DCHECK(!successor->IsExitBlock()); |
| 727 | |
| 728 | HBasicBlock* block = got->GetBlock(); |
| 729 | HInstruction* previous = got->GetPrevious(); |
| 730 | |
| 731 | HLoopInformation* info = block->GetLoopInformation(); |
| 732 | if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) { |
| 733 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 734 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 735 | return; |
| 736 | } |
| 737 | |
| 738 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 739 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 740 | } |
| 741 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 742 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 743 | } |
| 744 | } |
| 745 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 746 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 747 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 748 | } |
| 749 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 750 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 751 | UNUSED(exit); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 752 | if (kIsDebugBuild) { |
| 753 | __ Comment("Unreachable"); |
| 754 | __ int3(); |
| 755 | } |
| 756 | } |
| 757 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 758 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 759 | LocationSummary* locations = |
| 760 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 761 | HInstruction* cond = if_instr->InputAt(0); |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 762 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 763 | locations->SetInAt(0, Location::Any()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 764 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 765 | } |
| 766 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 767 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 768 | HInstruction* cond = if_instr->InputAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 769 | if (cond->IsIntConstant()) { |
| 770 | // Constant condition, statically compared against 1. |
| 771 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 772 | if (cond_value == 1) { |
| 773 | if (!codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 774 | if_instr->IfTrueSuccessor())) { |
| 775 | __ jmp(codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 776 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 777 | return; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 778 | } else { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 779 | DCHECK_EQ(cond_value, 0); |
| 780 | } |
| 781 | } else { |
| 782 | bool materialized = |
| 783 | !cond->IsCondition() || cond->AsCondition()->NeedsMaterialization(); |
| 784 | // Moves do not affect the eflags register, so if the condition is |
| 785 | // evaluated just before the if, we don't need to evaluate it |
| 786 | // again. |
| 787 | bool eflags_set = cond->IsCondition() |
| 788 | && cond->AsCondition()->IsBeforeWhenDisregardMoves(if_instr); |
| 789 | if (materialized) { |
| 790 | if (!eflags_set) { |
| 791 | // Materialized condition, compare against 0. |
| 792 | Location lhs = if_instr->GetLocations()->InAt(0); |
| 793 | if (lhs.IsRegister()) { |
| 794 | __ cmpl(lhs.As<Register>(), Immediate(0)); |
| 795 | } else { |
| 796 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 797 | } |
| 798 | __ j(kNotEqual, codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
| 799 | } else { |
| 800 | __ j(X86Condition(cond->AsCondition()->GetCondition()), |
| 801 | codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
| 802 | } |
| 803 | } else { |
| 804 | Location lhs = cond->GetLocations()->InAt(0); |
| 805 | Location rhs = cond->GetLocations()->InAt(1); |
| 806 | // LHS is guaranteed to be in a register (see |
| 807 | // LocationsBuilderX86::VisitCondition). |
| 808 | if (rhs.IsRegister()) { |
| 809 | __ cmpl(lhs.As<Register>(), rhs.As<Register>()); |
| 810 | } else if (rhs.IsConstant()) { |
| 811 | HIntConstant* instruction = rhs.GetConstant()->AsIntConstant(); |
| 812 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
| 813 | __ cmpl(lhs.As<Register>(), imm); |
| 814 | } else { |
| 815 | __ cmpl(lhs.As<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 816 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 817 | __ j(X86Condition(cond->AsCondition()->GetCondition()), |
| 818 | codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 819 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 820 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 821 | if (!codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 822 | if_instr->IfFalseSuccessor())) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 823 | __ jmp(codegen_->GetLabelOf(if_instr->IfFalseSuccessor())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 824 | } |
| 825 | } |
| 826 | |
| 827 | void LocationsBuilderX86::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 828 | local->SetLocations(nullptr); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 829 | } |
| 830 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 831 | void InstructionCodeGeneratorX86::VisitLocal(HLocal* local) { |
| 832 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 833 | } |
| 834 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 835 | void LocationsBuilderX86::VisitLoadLocal(HLoadLocal* local) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 836 | local->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 837 | } |
| 838 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 839 | void InstructionCodeGeneratorX86::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 840 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 841 | UNUSED(load); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 842 | } |
| 843 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 844 | void LocationsBuilderX86::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 845 | LocationSummary* locations = |
| 846 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 847 | switch (store->InputAt(1)->GetType()) { |
| 848 | case Primitive::kPrimBoolean: |
| 849 | case Primitive::kPrimByte: |
| 850 | case Primitive::kPrimChar: |
| 851 | case Primitive::kPrimShort: |
| 852 | case Primitive::kPrimInt: |
| 853 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 854 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 855 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 856 | break; |
| 857 | |
| 858 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 859 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 860 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 861 | break; |
| 862 | |
| 863 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 864 | LOG(FATAL) << "Unknown local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 865 | } |
| 866 | store->SetLocations(locations); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 867 | } |
| 868 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 869 | void InstructionCodeGeneratorX86::VisitStoreLocal(HStoreLocal* store) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 870 | UNUSED(store); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 871 | } |
| 872 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 873 | void LocationsBuilderX86::VisitCondition(HCondition* comp) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 874 | LocationSummary* locations = |
| 875 | new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 876 | locations->SetInAt(0, Location::RequiresRegister()); |
| 877 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 878 | if (comp->NeedsMaterialization()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 879 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 880 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 881 | } |
| 882 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 883 | void InstructionCodeGeneratorX86::VisitCondition(HCondition* comp) { |
| 884 | if (comp->NeedsMaterialization()) { |
| 885 | LocationSummary* locations = comp->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 886 | Register reg = locations->Out().As<Register>(); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 887 | // Clear register: setcc only sets the low byte. |
| 888 | __ xorl(reg, reg); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 889 | if (locations->InAt(1).IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 890 | __ cmpl(locations->InAt(0).As<Register>(), |
| 891 | locations->InAt(1).As<Register>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 892 | } else if (locations->InAt(1).IsConstant()) { |
| 893 | HConstant* instruction = locations->InAt(1).GetConstant(); |
| 894 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 895 | __ cmpl(locations->InAt(0).As<Register>(), imm); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 896 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 897 | __ cmpl(locations->InAt(0).As<Register>(), |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 898 | Address(ESP, locations->InAt(1).GetStackIndex())); |
| 899 | } |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 900 | __ setb(X86Condition(comp->GetCondition()), reg); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 901 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
| 905 | VisitCondition(comp); |
| 906 | } |
| 907 | |
| 908 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
| 909 | VisitCondition(comp); |
| 910 | } |
| 911 | |
| 912 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
| 913 | VisitCondition(comp); |
| 914 | } |
| 915 | |
| 916 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
| 917 | VisitCondition(comp); |
| 918 | } |
| 919 | |
| 920 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
| 921 | VisitCondition(comp); |
| 922 | } |
| 923 | |
| 924 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
| 925 | VisitCondition(comp); |
| 926 | } |
| 927 | |
| 928 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 929 | VisitCondition(comp); |
| 930 | } |
| 931 | |
| 932 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 933 | VisitCondition(comp); |
| 934 | } |
| 935 | |
| 936 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
| 937 | VisitCondition(comp); |
| 938 | } |
| 939 | |
| 940 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
| 941 | VisitCondition(comp); |
| 942 | } |
| 943 | |
| 944 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 945 | VisitCondition(comp); |
| 946 | } |
| 947 | |
| 948 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 949 | VisitCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 953 | LocationSummary* locations = |
| 954 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 955 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 956 | } |
| 957 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 958 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 959 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 960 | UNUSED(constant); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 961 | } |
| 962 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 963 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 964 | LocationSummary* locations = |
| 965 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 966 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant) { |
| 970 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 971 | UNUSED(constant); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 972 | } |
| 973 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 974 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 975 | LocationSummary* locations = |
| 976 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 977 | locations->SetOut(Location::ConstantLocation(constant)); |
| 978 | } |
| 979 | |
| 980 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant) { |
| 981 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 982 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 986 | LocationSummary* locations = |
| 987 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 988 | locations->SetOut(Location::ConstantLocation(constant)); |
| 989 | } |
| 990 | |
| 991 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 992 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 993 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 994 | } |
| 995 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 996 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 997 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 998 | } |
| 999 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1000 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1001 | UNUSED(ret); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1002 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1003 | __ ret(); |
| 1004 | } |
| 1005 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1006 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1007 | LocationSummary* locations = |
| 1008 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1009 | switch (ret->InputAt(0)->GetType()) { |
| 1010 | case Primitive::kPrimBoolean: |
| 1011 | case Primitive::kPrimByte: |
| 1012 | case Primitive::kPrimChar: |
| 1013 | case Primitive::kPrimShort: |
| 1014 | case Primitive::kPrimInt: |
| 1015 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1016 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1017 | break; |
| 1018 | |
| 1019 | case Primitive::kPrimLong: |
| 1020 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1021 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1022 | break; |
| 1023 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1024 | case Primitive::kPrimFloat: |
| 1025 | case Primitive::kPrimDouble: |
| 1026 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1027 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1028 | break; |
| 1029 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1030 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1031 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1032 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1033 | } |
| 1034 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1035 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1036 | if (kIsDebugBuild) { |
| 1037 | switch (ret->InputAt(0)->GetType()) { |
| 1038 | case Primitive::kPrimBoolean: |
| 1039 | case Primitive::kPrimByte: |
| 1040 | case Primitive::kPrimChar: |
| 1041 | case Primitive::kPrimShort: |
| 1042 | case Primitive::kPrimInt: |
| 1043 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1044 | DCHECK_EQ(ret->GetLocations()->InAt(0).As<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1045 | break; |
| 1046 | |
| 1047 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1048 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1049 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1050 | break; |
| 1051 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1052 | case Primitive::kPrimFloat: |
| 1053 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1054 | DCHECK_EQ(ret->GetLocations()->InAt(0).As<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1055 | break; |
| 1056 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1057 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1058 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1059 | } |
| 1060 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1061 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1062 | __ ret(); |
| 1063 | } |
| 1064 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1065 | void LocationsBuilderX86::VisitInvokeStatic(HInvokeStatic* invoke) { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1066 | HandleInvoke(invoke); |
| 1067 | } |
| 1068 | |
| 1069 | void InstructionCodeGeneratorX86::VisitInvokeStatic(HInvokeStatic* invoke) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1070 | Register temp = invoke->GetLocations()->GetTemp(0).As<Register>(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1071 | |
| 1072 | // TODO: Implement all kinds of calls: |
| 1073 | // 1) boot -> boot |
| 1074 | // 2) app -> boot |
| 1075 | // 3) app -> app |
| 1076 | // |
| 1077 | // Currently we implement the app -> app logic, which looks up in the resolve cache. |
| 1078 | |
| 1079 | // temp = method; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1080 | codegen_->LoadCurrentMethod(temp); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1081 | // temp = temp->dex_cache_resolved_methods_; |
| 1082 | __ movl(temp, Address(temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value())); |
| 1083 | // temp = temp[index_in_cache] |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1084 | __ movl(temp, Address(temp, CodeGenerator::GetCacheOffset(invoke->GetIndexInDexCache()))); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1085 | // (temp + offset_of_quick_compiled_code)() |
| 1086 | __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value())); |
| 1087 | |
| 1088 | DCHECK(!codegen_->IsLeafMethod()); |
| 1089 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1090 | } |
| 1091 | |
| 1092 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 1093 | HandleInvoke(invoke); |
| 1094 | } |
| 1095 | |
| 1096 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1097 | LocationSummary* locations = |
| 1098 | new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1099 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1100 | |
| 1101 | InvokeDexCallingConventionVisitor calling_convention_visitor; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1102 | for (size_t i = 0; i < invoke->InputCount(); i++) { |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1103 | HInstruction* input = invoke->InputAt(i); |
| 1104 | locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType())); |
| 1105 | } |
| 1106 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1107 | switch (invoke->GetType()) { |
| 1108 | case Primitive::kPrimBoolean: |
| 1109 | case Primitive::kPrimByte: |
| 1110 | case Primitive::kPrimChar: |
| 1111 | case Primitive::kPrimShort: |
| 1112 | case Primitive::kPrimInt: |
| 1113 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1114 | locations->SetOut(Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1115 | break; |
| 1116 | |
| 1117 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1118 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1119 | break; |
| 1120 | |
| 1121 | case Primitive::kPrimVoid: |
| 1122 | break; |
| 1123 | |
| 1124 | case Primitive::kPrimDouble: |
| 1125 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1126 | locations->SetOut(Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1127 | break; |
| 1128 | } |
| 1129 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1130 | invoke->SetLocations(locations); |
| 1131 | } |
| 1132 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1133 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1134 | Register temp = invoke->GetLocations()->GetTemp(0).As<Register>(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1135 | uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() + |
| 1136 | invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry); |
| 1137 | LocationSummary* locations = invoke->GetLocations(); |
| 1138 | Location receiver = locations->InAt(0); |
| 1139 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1140 | // temp = object->GetClass(); |
| 1141 | if (receiver.IsStackSlot()) { |
| 1142 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
| 1143 | __ movl(temp, Address(temp, class_offset)); |
| 1144 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1145 | __ movl(temp, Address(receiver.As<Register>(), class_offset)); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1146 | } |
| 1147 | // temp = temp->GetMethodAt(method_offset); |
| 1148 | __ movl(temp, Address(temp, method_offset)); |
| 1149 | // call temp->GetEntryPoint(); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1150 | __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value())); |
| 1151 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1152 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1153 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1154 | } |
| 1155 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1156 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1157 | HandleInvoke(invoke); |
| 1158 | // Add the hidden argument. |
| 1159 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM0)); |
| 1160 | } |
| 1161 | |
| 1162 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1163 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 1164 | Register temp = invoke->GetLocations()->GetTemp(0).As<Register>(); |
| 1165 | uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() + |
| 1166 | (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry); |
| 1167 | LocationSummary* locations = invoke->GetLocations(); |
| 1168 | Location receiver = locations->InAt(0); |
| 1169 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1170 | |
| 1171 | // Set the hidden argument. |
| 1172 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
| 1173 | __ movd(invoke->GetLocations()->GetTemp(1).As<XmmRegister>(), temp); |
| 1174 | |
| 1175 | // temp = object->GetClass(); |
| 1176 | if (receiver.IsStackSlot()) { |
| 1177 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
| 1178 | __ movl(temp, Address(temp, class_offset)); |
| 1179 | } else { |
| 1180 | __ movl(temp, Address(receiver.As<Register>(), class_offset)); |
| 1181 | } |
| 1182 | // temp = temp->GetImtEntryAt(method_offset); |
| 1183 | __ movl(temp, Address(temp, method_offset)); |
| 1184 | // call temp->GetEntryPoint(); |
| 1185 | __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value())); |
| 1186 | |
| 1187 | DCHECK(!codegen_->IsLeafMethod()); |
| 1188 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1189 | } |
| 1190 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1191 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 1192 | LocationSummary* locations = |
| 1193 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1194 | switch (neg->GetResultType()) { |
| 1195 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1196 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1197 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1198 | locations->SetOut(Location::SameAsFirstInput()); |
| 1199 | break; |
| 1200 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1201 | case Primitive::kPrimFloat: |
| 1202 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1203 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1204 | // Output overlaps as we need a fresh (zero-initialized) |
| 1205 | // register to perform subtraction from zero. |
| 1206 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1207 | break; |
| 1208 | |
| 1209 | default: |
| 1210 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1211 | } |
| 1212 | } |
| 1213 | |
| 1214 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 1215 | LocationSummary* locations = neg->GetLocations(); |
| 1216 | Location out = locations->Out(); |
| 1217 | Location in = locations->InAt(0); |
| 1218 | switch (neg->GetResultType()) { |
| 1219 | case Primitive::kPrimInt: |
| 1220 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1221 | DCHECK(in.Equals(out)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1222 | __ negl(out.As<Register>()); |
| 1223 | break; |
| 1224 | |
| 1225 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1226 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1227 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1228 | __ negl(out.AsRegisterPairLow<Register>()); |
| 1229 | // Negation is similar to subtraction from zero. The least |
| 1230 | // significant byte triggers a borrow when it is different from |
| 1231 | // zero; to take it into account, add 1 to the most significant |
| 1232 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 1233 | // operation. |
| 1234 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 1235 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 1236 | break; |
| 1237 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1238 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1239 | DCHECK(!in.Equals(out)); |
| 1240 | // out = 0 |
| 1241 | __ xorps(out.As<XmmRegister>(), out.As<XmmRegister>()); |
| 1242 | // out = out - in |
| 1243 | __ subss(out.As<XmmRegister>(), in.As<XmmRegister>()); |
| 1244 | break; |
| 1245 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1246 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1247 | DCHECK(!in.Equals(out)); |
| 1248 | // out = 0 |
| 1249 | __ xorpd(out.As<XmmRegister>(), out.As<XmmRegister>()); |
| 1250 | // out = out - in |
| 1251 | __ subsd(out.As<XmmRegister>(), in.As<XmmRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1252 | break; |
| 1253 | |
| 1254 | default: |
| 1255 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1256 | } |
| 1257 | } |
| 1258 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1259 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 1260 | LocationSummary* locations = |
| 1261 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 1262 | Primitive::Type result_type = conversion->GetResultType(); |
| 1263 | Primitive::Type input_type = conversion->GetInputType(); |
| 1264 | switch (result_type) { |
Roland Levillain | 647b96f | 2014-11-11 12:26:26 +0000 | [diff] [blame] | 1265 | case Primitive::kPrimInt: |
| 1266 | switch (input_type) { |
| 1267 | case Primitive::kPrimLong: |
| 1268 | // long-to-int conversion. |
| 1269 | locations->SetInAt(0, Location::Any()); |
| 1270 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1271 | break; |
| 1272 | |
| 1273 | case Primitive::kPrimFloat: |
| 1274 | case Primitive::kPrimDouble: |
| 1275 | LOG(FATAL) << "Type conversion from " << input_type |
| 1276 | << " to " << result_type << " not yet implemented"; |
| 1277 | break; |
| 1278 | |
| 1279 | default: |
| 1280 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1281 | << " to " << result_type; |
| 1282 | } |
| 1283 | break; |
| 1284 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1285 | case Primitive::kPrimLong: |
| 1286 | switch (input_type) { |
| 1287 | case Primitive::kPrimByte: |
| 1288 | case Primitive::kPrimShort: |
| 1289 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1290 | case Primitive::kPrimChar: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1291 | // int-to-long conversion. |
| 1292 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 1293 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 1294 | break; |
| 1295 | |
| 1296 | case Primitive::kPrimFloat: |
| 1297 | case Primitive::kPrimDouble: |
| 1298 | LOG(FATAL) << "Type conversion from " << input_type << " to " |
| 1299 | << result_type << " not yet implemented"; |
| 1300 | break; |
| 1301 | |
| 1302 | default: |
| 1303 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1304 | << " to " << result_type; |
| 1305 | } |
| 1306 | break; |
| 1307 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1308 | case Primitive::kPrimFloat: |
| 1309 | case Primitive::kPrimDouble: |
| 1310 | LOG(FATAL) << "Type conversion from " << input_type |
| 1311 | << " to " << result_type << " not yet implemented"; |
| 1312 | break; |
| 1313 | |
| 1314 | default: |
| 1315 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1316 | << " to " << result_type; |
| 1317 | } |
| 1318 | } |
| 1319 | |
| 1320 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 1321 | LocationSummary* locations = conversion->GetLocations(); |
| 1322 | Location out = locations->Out(); |
| 1323 | Location in = locations->InAt(0); |
| 1324 | Primitive::Type result_type = conversion->GetResultType(); |
| 1325 | Primitive::Type input_type = conversion->GetInputType(); |
| 1326 | switch (result_type) { |
Roland Levillain | 647b96f | 2014-11-11 12:26:26 +0000 | [diff] [blame] | 1327 | case Primitive::kPrimInt: |
| 1328 | switch (input_type) { |
| 1329 | case Primitive::kPrimLong: |
| 1330 | // long-to-int conversion. |
| 1331 | if (in.IsRegisterPair()) { |
| 1332 | __ movl(out.As<Register>(), in.AsRegisterPairLow<Register>()); |
| 1333 | } else if (in.IsDoubleStackSlot()) { |
| 1334 | __ movl(out.As<Register>(), Address(ESP, in.GetStackIndex())); |
| 1335 | } else { |
| 1336 | DCHECK(in.IsConstant()); |
| 1337 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 1338 | __ movl(out.As<Register>(), |
| 1339 | Immediate(Low32Bits(in.GetConstant()->AsLongConstant()->GetValue()))); |
| 1340 | } |
| 1341 | break; |
| 1342 | |
| 1343 | case Primitive::kPrimFloat: |
| 1344 | case Primitive::kPrimDouble: |
| 1345 | LOG(FATAL) << "Type conversion from " << input_type |
| 1346 | << " to " << result_type << " not yet implemented"; |
| 1347 | break; |
| 1348 | |
| 1349 | default: |
| 1350 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1351 | << " to " << result_type; |
| 1352 | } |
| 1353 | break; |
| 1354 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1355 | case Primitive::kPrimLong: |
| 1356 | switch (input_type) { |
| 1357 | case Primitive::kPrimByte: |
| 1358 | case Primitive::kPrimShort: |
| 1359 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1360 | case Primitive::kPrimChar: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1361 | // int-to-long conversion. |
| 1362 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 1363 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
| 1364 | DCHECK_EQ(in.As<Register>(), EAX); |
| 1365 | __ cdq(); |
| 1366 | break; |
| 1367 | |
| 1368 | case Primitive::kPrimFloat: |
| 1369 | case Primitive::kPrimDouble: |
| 1370 | LOG(FATAL) << "Type conversion from " << input_type << " to " |
| 1371 | << result_type << " not yet implemented"; |
| 1372 | break; |
| 1373 | |
| 1374 | default: |
| 1375 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1376 | << " to " << result_type; |
| 1377 | } |
| 1378 | break; |
| 1379 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1380 | case Primitive::kPrimFloat: |
| 1381 | case Primitive::kPrimDouble: |
| 1382 | LOG(FATAL) << "Type conversion from " << input_type |
| 1383 | << " to " << result_type << " not yet implemented"; |
| 1384 | break; |
| 1385 | |
| 1386 | default: |
| 1387 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1388 | << " to " << result_type; |
| 1389 | } |
| 1390 | } |
| 1391 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1392 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1393 | LocationSummary* locations = |
| 1394 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1395 | switch (add->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1396 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1397 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1398 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1399 | locations->SetInAt(1, Location::Any()); |
| 1400 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1401 | break; |
| 1402 | } |
| 1403 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1404 | case Primitive::kPrimFloat: |
| 1405 | case Primitive::kPrimDouble: { |
| 1406 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1407 | locations->SetInAt(1, Location::Any()); |
| 1408 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1409 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1410 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1411 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1412 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1413 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 1414 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1415 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 1419 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1420 | Location first = locations->InAt(0); |
| 1421 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1422 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1423 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1424 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1425 | if (second.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1426 | __ addl(first.As<Register>(), second.As<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1427 | } else if (second.IsConstant()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1428 | __ addl(first.As<Register>(), Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1429 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1430 | __ addl(first.As<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1431 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1432 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1433 | } |
| 1434 | |
| 1435 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1436 | if (second.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1437 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 1438 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1439 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1440 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 1441 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1442 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1443 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1444 | break; |
| 1445 | } |
| 1446 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1447 | case Primitive::kPrimFloat: { |
| 1448 | if (second.IsFpuRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1449 | __ addss(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1450 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1451 | __ addss(first.As<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1452 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1453 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1454 | } |
| 1455 | |
| 1456 | case Primitive::kPrimDouble: { |
| 1457 | if (second.IsFpuRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1458 | __ addsd(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1459 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1460 | __ addsd(first.As<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1461 | } |
| 1462 | break; |
| 1463 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1464 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1465 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1466 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1467 | } |
| 1468 | } |
| 1469 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1470 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1471 | LocationSummary* locations = |
| 1472 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1473 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1474 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1475 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1476 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1477 | locations->SetInAt(1, Location::Any()); |
| 1478 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1479 | break; |
| 1480 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1481 | case Primitive::kPrimFloat: |
| 1482 | case Primitive::kPrimDouble: { |
| 1483 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1484 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1485 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1486 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1487 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1488 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1489 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1490 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1491 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 1495 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1496 | Location first = locations->InAt(0); |
| 1497 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1498 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1499 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1500 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1501 | if (second.IsRegister()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1502 | __ subl(first.As<Register>(), second.As<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1503 | } else if (second.IsConstant()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1504 | __ subl(first.As<Register>(), Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1505 | } else { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1506 | __ subl(first.As<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1507 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1508 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1509 | } |
| 1510 | |
| 1511 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1512 | if (second.IsRegister()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1513 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 1514 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1515 | } else { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1516 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1517 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 1518 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1519 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1520 | break; |
| 1521 | } |
| 1522 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1523 | case Primitive::kPrimFloat: { |
| 1524 | __ subss(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1525 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1526 | } |
| 1527 | |
| 1528 | case Primitive::kPrimDouble: { |
| 1529 | __ subsd(first.As<XmmRegister>(), second.As<XmmRegister>()); |
| 1530 | break; |
| 1531 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1532 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1533 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1534 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1535 | } |
| 1536 | } |
| 1537 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1538 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 1539 | LocationSummary* locations = |
| 1540 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 1541 | switch (mul->GetResultType()) { |
| 1542 | case Primitive::kPrimInt: |
| 1543 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1544 | locations->SetInAt(1, Location::Any()); |
| 1545 | locations->SetOut(Location::SameAsFirstInput()); |
| 1546 | break; |
| 1547 | case Primitive::kPrimLong: { |
| 1548 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1549 | // TODO: Currently this handles only stack operands: |
| 1550 | // - we don't have enough registers because we currently use Quick ABI. |
| 1551 | // - by the time we have a working register allocator we will probably change the ABI |
| 1552 | // and fix the above. |
| 1553 | // - we don't have a way yet to request operands on stack but the base line compiler |
| 1554 | // will leave the operands on the stack with Any(). |
| 1555 | locations->SetInAt(1, Location::Any()); |
| 1556 | locations->SetOut(Location::SameAsFirstInput()); |
| 1557 | // Needed for imul on 32bits with 64bits output. |
| 1558 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 1559 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 1560 | break; |
| 1561 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1562 | case Primitive::kPrimFloat: |
| 1563 | case Primitive::kPrimDouble: { |
| 1564 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1565 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1566 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1567 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1568 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1569 | |
| 1570 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1571 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1572 | } |
| 1573 | } |
| 1574 | |
| 1575 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 1576 | LocationSummary* locations = mul->GetLocations(); |
| 1577 | Location first = locations->InAt(0); |
| 1578 | Location second = locations->InAt(1); |
| 1579 | DCHECK(first.Equals(locations->Out())); |
| 1580 | |
| 1581 | switch (mul->GetResultType()) { |
| 1582 | case Primitive::kPrimInt: { |
| 1583 | if (second.IsRegister()) { |
| 1584 | __ imull(first.As<Register>(), second.As<Register>()); |
| 1585 | } else if (second.IsConstant()) { |
| 1586 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 1587 | __ imull(first.As<Register>(), imm); |
| 1588 | } else { |
| 1589 | DCHECK(second.IsStackSlot()); |
| 1590 | __ imull(first.As<Register>(), Address(ESP, second.GetStackIndex())); |
| 1591 | } |
| 1592 | break; |
| 1593 | } |
| 1594 | |
| 1595 | case Primitive::kPrimLong: { |
| 1596 | DCHECK(second.IsDoubleStackSlot()); |
| 1597 | |
| 1598 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 1599 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 1600 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 1601 | Address in2_lo(ESP, second.GetStackIndex()); |
| 1602 | Register eax = locations->GetTemp(0).As<Register>(); |
| 1603 | Register edx = locations->GetTemp(1).As<Register>(); |
| 1604 | |
| 1605 | DCHECK_EQ(EAX, eax); |
| 1606 | DCHECK_EQ(EDX, edx); |
| 1607 | |
| 1608 | // input: in1 - 64 bits, in2 - 64 bits |
| 1609 | // output: in1 |
| 1610 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 1611 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 1612 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
| 1613 | |
| 1614 | __ movl(eax, in2_hi); |
| 1615 | // eax <- in1.lo * in2.hi |
| 1616 | __ imull(eax, in1_lo); |
| 1617 | // in1.hi <- in1.hi * in2.lo |
| 1618 | __ imull(in1_hi, in2_lo); |
| 1619 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 1620 | __ addl(in1_hi, eax); |
| 1621 | // move in1_lo to eax to prepare for double precision |
| 1622 | __ movl(eax, in1_lo); |
| 1623 | // edx:eax <- in1.lo * in2.lo |
| 1624 | __ mull(in2_lo); |
| 1625 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 1626 | __ addl(in1_hi, edx); |
| 1627 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 1628 | __ movl(in1_lo, eax); |
| 1629 | |
| 1630 | break; |
| 1631 | } |
| 1632 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1633 | case Primitive::kPrimFloat: { |
| 1634 | __ mulss(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1635 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | case Primitive::kPrimDouble: { |
| 1639 | __ mulsd(first.As<XmmRegister>(), second.As<XmmRegister>()); |
| 1640 | break; |
| 1641 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1642 | |
| 1643 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1644 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1645 | } |
| 1646 | } |
| 1647 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1648 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
| 1649 | LocationSummary* locations = |
| 1650 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 1651 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1652 | case Primitive::kPrimInt: { |
| 1653 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 1654 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1655 | locations->SetOut(Location::SameAsFirstInput()); |
| 1656 | // Intel uses edx:eax as the dividend. |
| 1657 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 1658 | break; |
| 1659 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1660 | case Primitive::kPrimLong: { |
| 1661 | LOG(FATAL) << "Not implemented div type" << div->GetResultType(); |
| 1662 | break; |
| 1663 | } |
| 1664 | case Primitive::kPrimFloat: |
| 1665 | case Primitive::kPrimDouble: { |
| 1666 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1667 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1668 | locations->SetOut(Location::SameAsFirstInput()); |
| 1669 | break; |
| 1670 | } |
| 1671 | |
| 1672 | default: |
| 1673 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 1674 | } |
| 1675 | } |
| 1676 | |
| 1677 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 1678 | LocationSummary* locations = div->GetLocations(); |
| 1679 | Location first = locations->InAt(0); |
| 1680 | Location second = locations->InAt(1); |
| 1681 | DCHECK(first.Equals(locations->Out())); |
| 1682 | |
| 1683 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1684 | case Primitive::kPrimInt: { |
| 1685 | Register first_reg = first.As<Register>(); |
| 1686 | Register second_reg = second.As<Register>(); |
| 1687 | DCHECK_EQ(EAX, first_reg); |
| 1688 | DCHECK_EQ(EDX, locations->GetTemp(0).As<Register>()); |
| 1689 | |
| 1690 | SlowPathCodeX86* slow_path = |
| 1691 | new (GetGraph()->GetArena()) DivMinusOneSlowPathX86(first_reg); |
| 1692 | codegen_->AddSlowPath(slow_path); |
| 1693 | |
| 1694 | // 0x80000000/-1 triggers an arithmetic exception! |
| 1695 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 1696 | // it's safe to just use negl instead of more complex comparisons. |
| 1697 | |
| 1698 | __ cmpl(second_reg, Immediate(-1)); |
| 1699 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 1700 | |
| 1701 | // edx:eax <- sign-extended of eax |
| 1702 | __ cdq(); |
| 1703 | // eax = quotient, edx = remainder |
| 1704 | __ idivl(second_reg); |
| 1705 | |
| 1706 | __ Bind(slow_path->GetExitLabel()); |
| 1707 | break; |
| 1708 | } |
| 1709 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1710 | case Primitive::kPrimLong: { |
| 1711 | LOG(FATAL) << "Not implemented div type" << div->GetResultType(); |
| 1712 | break; |
| 1713 | } |
| 1714 | |
| 1715 | case Primitive::kPrimFloat: { |
| 1716 | __ divss(first.As<XmmRegister>(), second.As<XmmRegister>()); |
| 1717 | break; |
| 1718 | } |
| 1719 | |
| 1720 | case Primitive::kPrimDouble: { |
| 1721 | __ divsd(first.As<XmmRegister>(), second.As<XmmRegister>()); |
| 1722 | break; |
| 1723 | } |
| 1724 | |
| 1725 | default: |
| 1726 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 1727 | } |
| 1728 | } |
| 1729 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1730 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 1731 | LocationSummary* locations = |
| 1732 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1733 | locations->SetInAt(0, Location::Any()); |
| 1734 | if (instruction->HasUses()) { |
| 1735 | locations->SetOut(Location::SameAsFirstInput()); |
| 1736 | } |
| 1737 | } |
| 1738 | |
| 1739 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 1740 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
| 1741 | codegen_->AddSlowPath(slow_path); |
| 1742 | |
| 1743 | LocationSummary* locations = instruction->GetLocations(); |
| 1744 | Location value = locations->InAt(0); |
| 1745 | |
| 1746 | if (value.IsRegister()) { |
| 1747 | __ testl(value.As<Register>(), value.As<Register>()); |
| 1748 | } else if (value.IsStackSlot()) { |
| 1749 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 1750 | } else { |
| 1751 | DCHECK(value.IsConstant()) << value; |
| 1752 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 1753 | __ jmp(slow_path->GetEntryLabel()); |
| 1754 | } |
| 1755 | return; |
| 1756 | } |
| 1757 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 1758 | } |
| 1759 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1760 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1761 | LocationSummary* locations = |
| 1762 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1763 | locations->SetOut(Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1764 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1765 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1766 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
| 1770 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1771 | codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1772 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1773 | |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 1774 | __ fs()->call( |
| 1775 | Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pAllocObjectWithAccessCheck))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1776 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1777 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1778 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1779 | } |
| 1780 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1781 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 1782 | LocationSummary* locations = |
| 1783 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 1784 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 1785 | InvokeRuntimeCallingConvention calling_convention; |
| 1786 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1787 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1788 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1789 | } |
| 1790 | |
| 1791 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 1792 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1793 | codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1794 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
| 1795 | |
| 1796 | __ fs()->call( |
| 1797 | Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pAllocArrayWithAccessCheck))); |
| 1798 | |
| 1799 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 1800 | DCHECK(!codegen_->IsLeafMethod()); |
| 1801 | } |
| 1802 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1803 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1804 | LocationSummary* locations = |
| 1805 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1806 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 1807 | if (location.IsStackSlot()) { |
| 1808 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 1809 | } else if (location.IsDoubleStackSlot()) { |
| 1810 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1811 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1812 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1813 | } |
| 1814 | |
| 1815 | void InstructionCodeGeneratorX86::VisitParameterValue(HParameterValue* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1816 | UNUSED(instruction); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1817 | } |
| 1818 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1819 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1820 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1821 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1822 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1823 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1824 | } |
| 1825 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1826 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 1827 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 1828 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1829 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 1830 | DCHECK(in.Equals(out)); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1831 | switch (not_->InputAt(0)->GetType()) { |
| 1832 | case Primitive::kPrimBoolean: |
| 1833 | __ xorl(out.As<Register>(), Immediate(1)); |
| 1834 | break; |
| 1835 | |
| 1836 | case Primitive::kPrimInt: |
| 1837 | __ notl(out.As<Register>()); |
| 1838 | break; |
| 1839 | |
| 1840 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 1841 | __ notl(out.AsRegisterPairLow<Register>()); |
| 1842 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1843 | break; |
| 1844 | |
| 1845 | default: |
| 1846 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 1847 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1848 | } |
| 1849 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1850 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1851 | LocationSummary* locations = |
| 1852 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1853 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1854 | locations->SetInAt(1, Location::Any()); |
| 1855 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1856 | } |
| 1857 | |
| 1858 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1859 | LocationSummary* locations = compare->GetLocations(); |
| 1860 | switch (compare->InputAt(0)->GetType()) { |
| 1861 | case Primitive::kPrimLong: { |
| 1862 | Label less, greater, done; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1863 | Register output = locations->Out().As<Register>(); |
| 1864 | Location left = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1865 | Location right = locations->InAt(1); |
| 1866 | if (right.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1867 | __ cmpl(left.AsRegisterPairHigh<Register>(), right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1868 | } else { |
| 1869 | DCHECK(right.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1870 | __ cmpl(left.AsRegisterPairHigh<Register>(), |
| 1871 | Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1872 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1873 | __ j(kLess, &less); // Signed compare. |
| 1874 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1875 | if (right.IsRegisterPair()) { |
| 1876 | __ cmpl(left.AsRegisterPairLow<Register>(), right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1877 | } else { |
| 1878 | DCHECK(right.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1879 | __ cmpl(left.AsRegisterPairLow<Register>(), Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1880 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1881 | __ movl(output, Immediate(0)); |
| 1882 | __ j(kEqual, &done); |
| 1883 | __ j(kBelow, &less); // Unsigned compare. |
| 1884 | |
| 1885 | __ Bind(&greater); |
| 1886 | __ movl(output, Immediate(1)); |
| 1887 | __ jmp(&done); |
| 1888 | |
| 1889 | __ Bind(&less); |
| 1890 | __ movl(output, Immediate(-1)); |
| 1891 | |
| 1892 | __ Bind(&done); |
| 1893 | break; |
| 1894 | } |
| 1895 | default: |
| 1896 | LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType(); |
| 1897 | } |
| 1898 | } |
| 1899 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1900 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1901 | LocationSummary* locations = |
| 1902 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 1903 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 1904 | locations->SetInAt(i, Location::Any()); |
| 1905 | } |
| 1906 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1907 | } |
| 1908 | |
| 1909 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1910 | UNUSED(instruction); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1911 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1912 | } |
| 1913 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1914 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1915 | LocationSummary* locations = |
| 1916 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1917 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1918 | Primitive::Type field_type = instruction->GetFieldType(); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1919 | bool is_object_type = field_type == Primitive::kPrimNot; |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 1920 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 1921 | || (field_type == Primitive::kPrimByte); |
| 1922 | // The register allocator does not support multiple |
| 1923 | // inputs that die at entry with one in a specific register. |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 1924 | if (is_byte_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1925 | // Ensure the value is in a byte register. |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1926 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1927 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1928 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1929 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 1930 | // Temporary registers for the write barrier. |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1931 | if (is_object_type) { |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 1932 | locations->AddTemp(Location::RequiresRegister()); |
| 1933 | // Ensure the card is in a byte register. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1934 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 1935 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1936 | } |
| 1937 | |
| 1938 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 1939 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1940 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1941 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1942 | Primitive::Type field_type = instruction->GetFieldType(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1943 | |
| 1944 | switch (field_type) { |
| 1945 | case Primitive::kPrimBoolean: |
| 1946 | case Primitive::kPrimByte: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1947 | ByteRegister value = locations->InAt(1).As<ByteRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1948 | __ movb(Address(obj, offset), value); |
| 1949 | break; |
| 1950 | } |
| 1951 | |
| 1952 | case Primitive::kPrimShort: |
| 1953 | case Primitive::kPrimChar: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1954 | Register value = locations->InAt(1).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1955 | __ movw(Address(obj, offset), value); |
| 1956 | break; |
| 1957 | } |
| 1958 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1959 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1960 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1961 | Register value = locations->InAt(1).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1962 | __ movl(Address(obj, offset), value); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1963 | |
| 1964 | if (field_type == Primitive::kPrimNot) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1965 | Register temp = locations->GetTemp(0).As<Register>(); |
| 1966 | Register card = locations->GetTemp(1).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1967 | codegen_->MarkGCCard(temp, card, obj, value); |
| 1968 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1969 | break; |
| 1970 | } |
| 1971 | |
| 1972 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1973 | Location value = locations->InAt(1); |
| 1974 | __ movl(Address(obj, offset), value.AsRegisterPairLow<Register>()); |
| 1975 | __ movl(Address(obj, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1976 | break; |
| 1977 | } |
| 1978 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 1979 | case Primitive::kPrimFloat: { |
| 1980 | XmmRegister value = locations->InAt(1).As<XmmRegister>(); |
| 1981 | __ movss(Address(obj, offset), value); |
| 1982 | break; |
| 1983 | } |
| 1984 | |
| 1985 | case Primitive::kPrimDouble: { |
| 1986 | XmmRegister value = locations->InAt(1).As<XmmRegister>(); |
| 1987 | __ movsd(Address(obj, offset), value); |
| 1988 | break; |
| 1989 | } |
| 1990 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1991 | case Primitive::kPrimVoid: |
| 1992 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 1993 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1994 | } |
| 1995 | } |
| 1996 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1997 | void CodeGeneratorX86::MarkGCCard(Register temp, Register card, Register object, Register value) { |
| 1998 | Label is_null; |
| 1999 | __ testl(value, value); |
| 2000 | __ j(kEqual, &is_null); |
| 2001 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 2002 | __ movl(temp, object); |
| 2003 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
| 2004 | __ movb(Address(temp, card, TIMES_1, 0), |
| 2005 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
| 2006 | __ Bind(&is_null); |
| 2007 | } |
| 2008 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2009 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2010 | LocationSummary* locations = |
| 2011 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2012 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2013 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2014 | } |
| 2015 | |
| 2016 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 2017 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2018 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2019 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
| 2020 | |
| 2021 | switch (instruction->GetType()) { |
| 2022 | case Primitive::kPrimBoolean: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2023 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2024 | __ movzxb(out, Address(obj, offset)); |
| 2025 | break; |
| 2026 | } |
| 2027 | |
| 2028 | case Primitive::kPrimByte: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2029 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2030 | __ movsxb(out, Address(obj, offset)); |
| 2031 | break; |
| 2032 | } |
| 2033 | |
| 2034 | case Primitive::kPrimShort: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2035 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2036 | __ movsxw(out, Address(obj, offset)); |
| 2037 | break; |
| 2038 | } |
| 2039 | |
| 2040 | case Primitive::kPrimChar: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2041 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2042 | __ movzxw(out, Address(obj, offset)); |
| 2043 | break; |
| 2044 | } |
| 2045 | |
| 2046 | case Primitive::kPrimInt: |
| 2047 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2048 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2049 | __ movl(out, Address(obj, offset)); |
| 2050 | break; |
| 2051 | } |
| 2052 | |
| 2053 | case Primitive::kPrimLong: { |
| 2054 | // TODO: support volatile. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2055 | __ movl(locations->Out().AsRegisterPairLow<Register>(), Address(obj, offset)); |
| 2056 | __ movl(locations->Out().AsRegisterPairHigh<Register>(), Address(obj, kX86WordSize + offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2057 | break; |
| 2058 | } |
| 2059 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2060 | case Primitive::kPrimFloat: { |
| 2061 | XmmRegister out = locations->Out().As<XmmRegister>(); |
| 2062 | __ movss(out, Address(obj, offset)); |
| 2063 | break; |
| 2064 | } |
| 2065 | |
| 2066 | case Primitive::kPrimDouble: { |
| 2067 | XmmRegister out = locations->Out().As<XmmRegister>(); |
| 2068 | __ movsd(out, Address(obj, offset)); |
| 2069 | break; |
| 2070 | } |
| 2071 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2072 | case Primitive::kPrimVoid: |
| 2073 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2074 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2075 | } |
| 2076 | } |
| 2077 | |
| 2078 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2079 | LocationSummary* locations = |
| 2080 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2081 | locations->SetInAt(0, Location::Any()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2082 | if (instruction->HasUses()) { |
| 2083 | locations->SetOut(Location::SameAsFirstInput()); |
| 2084 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2085 | } |
| 2086 | |
| 2087 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 2088 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2089 | codegen_->AddSlowPath(slow_path); |
| 2090 | |
| 2091 | LocationSummary* locations = instruction->GetLocations(); |
| 2092 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2093 | |
| 2094 | if (obj.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2095 | __ cmpl(obj.As<Register>(), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2096 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2097 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2098 | } else { |
| 2099 | DCHECK(obj.IsConstant()) << obj; |
| 2100 | DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0); |
| 2101 | __ jmp(slow_path->GetEntryLabel()); |
| 2102 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2103 | } |
| 2104 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2105 | } |
| 2106 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2107 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2108 | LocationSummary* locations = |
| 2109 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2110 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2111 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2112 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2113 | } |
| 2114 | |
| 2115 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 2116 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2117 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2118 | Location index = locations->InAt(1); |
| 2119 | |
| 2120 | switch (instruction->GetType()) { |
| 2121 | case Primitive::kPrimBoolean: { |
| 2122 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2123 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2124 | if (index.IsConstant()) { |
| 2125 | __ movzxb(out, Address(obj, |
| 2126 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 2127 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2128 | __ movzxb(out, Address(obj, index.As<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2129 | } |
| 2130 | break; |
| 2131 | } |
| 2132 | |
| 2133 | case Primitive::kPrimByte: { |
| 2134 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2135 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2136 | if (index.IsConstant()) { |
| 2137 | __ movsxb(out, Address(obj, |
| 2138 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 2139 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2140 | __ movsxb(out, Address(obj, index.As<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2141 | } |
| 2142 | break; |
| 2143 | } |
| 2144 | |
| 2145 | case Primitive::kPrimShort: { |
| 2146 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2147 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2148 | if (index.IsConstant()) { |
| 2149 | __ movsxw(out, Address(obj, |
| 2150 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 2151 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2152 | __ movsxw(out, Address(obj, index.As<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2153 | } |
| 2154 | break; |
| 2155 | } |
| 2156 | |
| 2157 | case Primitive::kPrimChar: { |
| 2158 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2159 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2160 | if (index.IsConstant()) { |
| 2161 | __ movzxw(out, Address(obj, |
| 2162 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 2163 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2164 | __ movzxw(out, Address(obj, index.As<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2165 | } |
| 2166 | break; |
| 2167 | } |
| 2168 | |
| 2169 | case Primitive::kPrimInt: |
| 2170 | case Primitive::kPrimNot: { |
| 2171 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2172 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2173 | if (index.IsConstant()) { |
| 2174 | __ movl(out, Address(obj, |
| 2175 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 2176 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2177 | __ movl(out, Address(obj, index.As<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2178 | } |
| 2179 | break; |
| 2180 | } |
| 2181 | |
| 2182 | case Primitive::kPrimLong: { |
| 2183 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2184 | Location out = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2185 | if (index.IsConstant()) { |
| 2186 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2187 | __ movl(out.AsRegisterPairLow<Register>(), Address(obj, offset)); |
| 2188 | __ movl(out.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2189 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2190 | __ movl(out.AsRegisterPairLow<Register>(), |
| 2191 | Address(obj, index.As<Register>(), TIMES_8, data_offset)); |
| 2192 | __ movl(out.AsRegisterPairHigh<Register>(), |
| 2193 | Address(obj, index.As<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2194 | } |
| 2195 | break; |
| 2196 | } |
| 2197 | |
| 2198 | case Primitive::kPrimFloat: |
| 2199 | case Primitive::kPrimDouble: |
| 2200 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2201 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2202 | case Primitive::kPrimVoid: |
| 2203 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2204 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2205 | } |
| 2206 | } |
| 2207 | |
| 2208 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2209 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2210 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2211 | instruction, |
| 2212 | value_type == Primitive::kPrimNot ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 2213 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2214 | if (value_type == Primitive::kPrimNot) { |
| 2215 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2216 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2217 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2218 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2219 | } else { |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 2220 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 2221 | || (value_type == Primitive::kPrimByte); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 2222 | // We need the inputs to be different than the output in case of long operation. |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 2223 | // In case of a byte operation, the register allocator does not support multiple |
| 2224 | // inputs that die at entry with one in a specific register. |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2225 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2226 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 2227 | if (is_byte_type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2228 | // Ensure the value is in a byte register. |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2229 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2230 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2231 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2232 | } |
| 2233 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2234 | } |
| 2235 | |
| 2236 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 2237 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2238 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2239 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2240 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2241 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2242 | |
| 2243 | switch (value_type) { |
| 2244 | case Primitive::kPrimBoolean: |
| 2245 | case Primitive::kPrimByte: { |
| 2246 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2247 | if (index.IsConstant()) { |
| 2248 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2249 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2250 | __ movb(Address(obj, offset), value.As<ByteRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2251 | } else { |
| 2252 | __ movb(Address(obj, offset), |
| 2253 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2254 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2255 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2256 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2257 | __ movb(Address(obj, index.As<Register>(), TIMES_1, data_offset), |
| 2258 | value.As<ByteRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2259 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2260 | __ movb(Address(obj, index.As<Register>(), TIMES_1, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2261 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2262 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2263 | } |
| 2264 | break; |
| 2265 | } |
| 2266 | |
| 2267 | case Primitive::kPrimShort: |
| 2268 | case Primitive::kPrimChar: { |
| 2269 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2270 | if (index.IsConstant()) { |
| 2271 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2272 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2273 | __ movw(Address(obj, offset), value.As<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2274 | } else { |
| 2275 | __ movw(Address(obj, offset), |
| 2276 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2277 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2278 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2279 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2280 | __ movw(Address(obj, index.As<Register>(), TIMES_2, data_offset), |
| 2281 | value.As<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2282 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2283 | __ movw(Address(obj, index.As<Register>(), TIMES_2, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2284 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2285 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2286 | } |
| 2287 | break; |
| 2288 | } |
| 2289 | |
| 2290 | case Primitive::kPrimInt: { |
| 2291 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2292 | if (index.IsConstant()) { |
| 2293 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2294 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2295 | __ movl(Address(obj, offset), value.As<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2296 | } else { |
| 2297 | __ movl(Address(obj, offset), Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2298 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2299 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2300 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2301 | __ movl(Address(obj, index.As<Register>(), TIMES_4, data_offset), |
| 2302 | value.As<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2303 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2304 | __ movl(Address(obj, index.As<Register>(), TIMES_4, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2305 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2306 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2307 | } |
| 2308 | break; |
| 2309 | } |
| 2310 | |
| 2311 | case Primitive::kPrimNot: { |
| 2312 | DCHECK(!codegen_->IsLeafMethod()); |
| 2313 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pAputObject))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2314 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2315 | break; |
| 2316 | } |
| 2317 | |
| 2318 | case Primitive::kPrimLong: { |
| 2319 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2320 | if (index.IsConstant()) { |
| 2321 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2322 | if (value.IsRegisterPair()) { |
| 2323 | __ movl(Address(obj, offset), value.AsRegisterPairLow<Register>()); |
| 2324 | __ movl(Address(obj, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2325 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2326 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2327 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 2328 | __ movl(Address(obj, offset), Immediate(Low32Bits(val))); |
| 2329 | __ movl(Address(obj, offset + kX86WordSize), Immediate(High32Bits(val))); |
| 2330 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2331 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2332 | if (value.IsRegisterPair()) { |
| 2333 | __ movl(Address(obj, index.As<Register>(), TIMES_8, data_offset), |
| 2334 | value.AsRegisterPairLow<Register>()); |
| 2335 | __ movl(Address(obj, index.As<Register>(), TIMES_8, data_offset + kX86WordSize), |
| 2336 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2337 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2338 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2339 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2340 | __ movl(Address(obj, index.As<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2341 | Immediate(Low32Bits(val))); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2342 | __ movl(Address(obj, index.As<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2343 | Immediate(High32Bits(val))); |
| 2344 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2345 | } |
| 2346 | break; |
| 2347 | } |
| 2348 | |
| 2349 | case Primitive::kPrimFloat: |
| 2350 | case Primitive::kPrimDouble: |
| 2351 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2352 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2353 | case Primitive::kPrimVoid: |
| 2354 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2355 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2356 | } |
| 2357 | } |
| 2358 | |
| 2359 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 2360 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2361 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2362 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2363 | instruction->SetLocations(locations); |
| 2364 | } |
| 2365 | |
| 2366 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 2367 | LocationSummary* locations = instruction->GetLocations(); |
| 2368 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2369 | Register obj = locations->InAt(0).As<Register>(); |
| 2370 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2371 | __ movl(out, Address(obj, offset)); |
| 2372 | } |
| 2373 | |
| 2374 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2375 | LocationSummary* locations = |
| 2376 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2377 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2378 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2379 | if (instruction->HasUses()) { |
| 2380 | locations->SetOut(Location::SameAsFirstInput()); |
| 2381 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2382 | } |
| 2383 | |
| 2384 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 2385 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 2386 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathX86( |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2387 | instruction, locations->InAt(0), locations->InAt(1)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2388 | codegen_->AddSlowPath(slow_path); |
| 2389 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2390 | Register index = locations->InAt(0).As<Register>(); |
| 2391 | Register length = locations->InAt(1).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2392 | |
| 2393 | __ cmpl(index, length); |
| 2394 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
| 2395 | } |
| 2396 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2397 | void LocationsBuilderX86::VisitTemporary(HTemporary* temp) { |
| 2398 | temp->SetLocations(nullptr); |
| 2399 | } |
| 2400 | |
| 2401 | void InstructionCodeGeneratorX86::VisitTemporary(HTemporary* temp) { |
| 2402 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2403 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2404 | } |
| 2405 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 2406 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2407 | UNUSED(instruction); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2408 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 2409 | } |
| 2410 | |
| 2411 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2412 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 2413 | } |
| 2414 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2415 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 2416 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 2417 | } |
| 2418 | |
| 2419 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2420 | HBasicBlock* block = instruction->GetBlock(); |
| 2421 | if (block->GetLoopInformation() != nullptr) { |
| 2422 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 2423 | // The back edge will generate the suspend check. |
| 2424 | return; |
| 2425 | } |
| 2426 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 2427 | // The goto will generate the suspend check. |
| 2428 | return; |
| 2429 | } |
| 2430 | GenerateSuspendCheck(instruction, nullptr); |
| 2431 | } |
| 2432 | |
| 2433 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 2434 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2435 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2436 | new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2437 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2438 | __ fs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2439 | Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2440 | if (successor == nullptr) { |
| 2441 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 2442 | __ Bind(slow_path->GetReturnLabel()); |
| 2443 | } else { |
| 2444 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 2445 | __ jmp(slow_path->GetEntryLabel()); |
| 2446 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2447 | } |
| 2448 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2449 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 2450 | return codegen_->GetAssembler(); |
| 2451 | } |
| 2452 | |
| 2453 | void ParallelMoveResolverX86::MoveMemoryToMemory(int dst, int src) { |
| 2454 | ScratchRegisterScope ensure_scratch( |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2455 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2456 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 2457 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, src + stack_offset)); |
| 2458 | __ movl(Address(ESP, dst + stack_offset), static_cast<Register>(ensure_scratch.GetRegister())); |
| 2459 | } |
| 2460 | |
| 2461 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
| 2462 | MoveOperands* move = moves_.Get(index); |
| 2463 | Location source = move->GetSource(); |
| 2464 | Location destination = move->GetDestination(); |
| 2465 | |
| 2466 | if (source.IsRegister()) { |
| 2467 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2468 | __ movl(destination.As<Register>(), source.As<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2469 | } else { |
| 2470 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2471 | __ movl(Address(ESP, destination.GetStackIndex()), source.As<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2472 | } |
| 2473 | } else if (source.IsStackSlot()) { |
| 2474 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2475 | __ movl(destination.As<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2476 | } else { |
| 2477 | DCHECK(destination.IsStackSlot()); |
| 2478 | MoveMemoryToMemory(destination.GetStackIndex(), |
| 2479 | source.GetStackIndex()); |
| 2480 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2481 | } else if (source.IsConstant()) { |
| 2482 | HIntConstant* instruction = source.GetConstant()->AsIntConstant(); |
| 2483 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
| 2484 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2485 | __ movl(destination.As<Register>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2486 | } else { |
| 2487 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 2488 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2489 | } else { |
| 2490 | LOG(FATAL) << "Unimplemented"; |
| 2491 | } |
| 2492 | } |
| 2493 | |
| 2494 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2495 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 2496 | ScratchRegisterScope ensure_scratch( |
| 2497 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 2498 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2499 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 2500 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 2501 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 2502 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
| 2503 | } |
| 2504 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2505 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
| 2506 | ScratchRegisterScope ensure_scratch1( |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2507 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 2508 | |
| 2509 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2510 | ScratchRegisterScope ensure_scratch2( |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2511 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 2512 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2513 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 2514 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 2515 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 2516 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 2517 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 2518 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
| 2519 | } |
| 2520 | |
| 2521 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
| 2522 | MoveOperands* move = moves_.Get(index); |
| 2523 | Location source = move->GetSource(); |
| 2524 | Location destination = move->GetDestination(); |
| 2525 | |
| 2526 | if (source.IsRegister() && destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2527 | __ xchgl(destination.As<Register>(), source.As<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2528 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2529 | Exchange(source.As<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2530 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2531 | Exchange(destination.As<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2532 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 2533 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 2534 | } else { |
| 2535 | LOG(FATAL) << "Unimplemented"; |
| 2536 | } |
| 2537 | } |
| 2538 | |
| 2539 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 2540 | __ pushl(static_cast<Register>(reg)); |
| 2541 | } |
| 2542 | |
| 2543 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 2544 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 2545 | } |
| 2546 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2547 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2548 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() |
| 2549 | ? LocationSummary::kCallOnSlowPath |
| 2550 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2551 | LocationSummary* locations = |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2552 | new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2553 | locations->SetOut(Location::RequiresRegister()); |
| 2554 | } |
| 2555 | |
| 2556 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
| 2557 | Register out = cls->GetLocations()->Out().As<Register>(); |
| 2558 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2559 | DCHECK(!cls->CanCallRuntime()); |
| 2560 | DCHECK(!cls->MustGenerateClinitCheck()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2561 | codegen_->LoadCurrentMethod(out); |
| 2562 | __ movl(out, Address(out, mirror::ArtMethod::DeclaringClassOffset().Int32Value())); |
| 2563 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2564 | DCHECK(cls->CanCallRuntime()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2565 | codegen_->LoadCurrentMethod(out); |
| 2566 | __ movl(out, Address(out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value())); |
| 2567 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2568 | |
| 2569 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 2570 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 2571 | codegen_->AddSlowPath(slow_path); |
| 2572 | __ testl(out, out); |
| 2573 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2574 | if (cls->MustGenerateClinitCheck()) { |
| 2575 | GenerateClassInitializationCheck(slow_path, out); |
| 2576 | } else { |
| 2577 | __ Bind(slow_path->GetExitLabel()); |
| 2578 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2579 | } |
| 2580 | } |
| 2581 | |
| 2582 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 2583 | LocationSummary* locations = |
| 2584 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 2585 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2586 | if (check->HasUses()) { |
| 2587 | locations->SetOut(Location::SameAsFirstInput()); |
| 2588 | } |
| 2589 | } |
| 2590 | |
| 2591 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2592 | // We assume the class to not be null. |
| 2593 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 2594 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2595 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2596 | GenerateClassInitializationCheck(slow_path, check->GetLocations()->InAt(0).As<Register>()); |
| 2597 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2598 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2599 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
| 2600 | SlowPathCodeX86* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2601 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 2602 | Immediate(mirror::Class::kStatusInitialized)); |
| 2603 | __ j(kLess, slow_path->GetEntryLabel()); |
| 2604 | __ Bind(slow_path->GetExitLabel()); |
| 2605 | // No need for memory fence, thanks to the X86 memory model. |
| 2606 | } |
| 2607 | |
| 2608 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 2609 | LocationSummary* locations = |
| 2610 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2611 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2612 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2613 | } |
| 2614 | |
| 2615 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 2616 | LocationSummary* locations = instruction->GetLocations(); |
| 2617 | Register cls = locations->InAt(0).As<Register>(); |
| 2618 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
| 2619 | |
| 2620 | switch (instruction->GetType()) { |
| 2621 | case Primitive::kPrimBoolean: { |
| 2622 | Register out = locations->Out().As<Register>(); |
| 2623 | __ movzxb(out, Address(cls, offset)); |
| 2624 | break; |
| 2625 | } |
| 2626 | |
| 2627 | case Primitive::kPrimByte: { |
| 2628 | Register out = locations->Out().As<Register>(); |
| 2629 | __ movsxb(out, Address(cls, offset)); |
| 2630 | break; |
| 2631 | } |
| 2632 | |
| 2633 | case Primitive::kPrimShort: { |
| 2634 | Register out = locations->Out().As<Register>(); |
| 2635 | __ movsxw(out, Address(cls, offset)); |
| 2636 | break; |
| 2637 | } |
| 2638 | |
| 2639 | case Primitive::kPrimChar: { |
| 2640 | Register out = locations->Out().As<Register>(); |
| 2641 | __ movzxw(out, Address(cls, offset)); |
| 2642 | break; |
| 2643 | } |
| 2644 | |
| 2645 | case Primitive::kPrimInt: |
| 2646 | case Primitive::kPrimNot: { |
| 2647 | Register out = locations->Out().As<Register>(); |
| 2648 | __ movl(out, Address(cls, offset)); |
| 2649 | break; |
| 2650 | } |
| 2651 | |
| 2652 | case Primitive::kPrimLong: { |
| 2653 | // TODO: support volatile. |
| 2654 | __ movl(locations->Out().AsRegisterPairLow<Register>(), Address(cls, offset)); |
| 2655 | __ movl(locations->Out().AsRegisterPairHigh<Register>(), Address(cls, kX86WordSize + offset)); |
| 2656 | break; |
| 2657 | } |
| 2658 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2659 | case Primitive::kPrimFloat: { |
| 2660 | XmmRegister out = locations->Out().As<XmmRegister>(); |
| 2661 | __ movss(out, Address(cls, offset)); |
| 2662 | break; |
| 2663 | } |
| 2664 | |
| 2665 | case Primitive::kPrimDouble: { |
| 2666 | XmmRegister out = locations->Out().As<XmmRegister>(); |
| 2667 | __ movsd(out, Address(cls, offset)); |
| 2668 | break; |
| 2669 | } |
| 2670 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2671 | case Primitive::kPrimVoid: |
| 2672 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2673 | UNREACHABLE(); |
| 2674 | } |
| 2675 | } |
| 2676 | |
| 2677 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 2678 | LocationSummary* locations = |
| 2679 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2680 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2681 | Primitive::Type field_type = instruction->GetFieldType(); |
| 2682 | bool is_object_type = field_type == Primitive::kPrimNot; |
| 2683 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 2684 | || (field_type == Primitive::kPrimByte); |
| 2685 | // The register allocator does not support multiple |
| 2686 | // inputs that die at entry with one in a specific register. |
| 2687 | if (is_byte_type) { |
| 2688 | // Ensure the value is in a byte register. |
| 2689 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
| 2690 | } else { |
| 2691 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2692 | } |
| 2693 | // Temporary registers for the write barrier. |
| 2694 | if (is_object_type) { |
| 2695 | locations->AddTemp(Location::RequiresRegister()); |
| 2696 | // Ensure the card is in a byte register. |
| 2697 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 2698 | } |
| 2699 | } |
| 2700 | |
| 2701 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 2702 | LocationSummary* locations = instruction->GetLocations(); |
| 2703 | Register cls = locations->InAt(0).As<Register>(); |
| 2704 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
| 2705 | Primitive::Type field_type = instruction->GetFieldType(); |
| 2706 | |
| 2707 | switch (field_type) { |
| 2708 | case Primitive::kPrimBoolean: |
| 2709 | case Primitive::kPrimByte: { |
| 2710 | ByteRegister value = locations->InAt(1).As<ByteRegister>(); |
| 2711 | __ movb(Address(cls, offset), value); |
| 2712 | break; |
| 2713 | } |
| 2714 | |
| 2715 | case Primitive::kPrimShort: |
| 2716 | case Primitive::kPrimChar: { |
| 2717 | Register value = locations->InAt(1).As<Register>(); |
| 2718 | __ movw(Address(cls, offset), value); |
| 2719 | break; |
| 2720 | } |
| 2721 | |
| 2722 | case Primitive::kPrimInt: |
| 2723 | case Primitive::kPrimNot: { |
| 2724 | Register value = locations->InAt(1).As<Register>(); |
| 2725 | __ movl(Address(cls, offset), value); |
| 2726 | |
| 2727 | if (field_type == Primitive::kPrimNot) { |
| 2728 | Register temp = locations->GetTemp(0).As<Register>(); |
| 2729 | Register card = locations->GetTemp(1).As<Register>(); |
| 2730 | codegen_->MarkGCCard(temp, card, cls, value); |
| 2731 | } |
| 2732 | break; |
| 2733 | } |
| 2734 | |
| 2735 | case Primitive::kPrimLong: { |
| 2736 | Location value = locations->InAt(1); |
| 2737 | __ movl(Address(cls, offset), value.AsRegisterPairLow<Register>()); |
| 2738 | __ movl(Address(cls, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 2739 | break; |
| 2740 | } |
| 2741 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2742 | case Primitive::kPrimFloat: { |
| 2743 | XmmRegister value = locations->InAt(1).As<XmmRegister>(); |
| 2744 | __ movss(Address(cls, offset), value); |
| 2745 | break; |
| 2746 | } |
| 2747 | |
| 2748 | case Primitive::kPrimDouble: { |
| 2749 | XmmRegister value = locations->InAt(1).As<XmmRegister>(); |
| 2750 | __ movsd(Address(cls, offset), value); |
| 2751 | break; |
| 2752 | } |
| 2753 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2754 | case Primitive::kPrimVoid: |
| 2755 | LOG(FATAL) << "Unreachable type " << field_type; |
| 2756 | UNREACHABLE(); |
| 2757 | } |
| 2758 | } |
| 2759 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 2760 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
| 2761 | LocationSummary* locations = |
| 2762 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
| 2763 | locations->SetOut(Location::RequiresRegister()); |
| 2764 | } |
| 2765 | |
| 2766 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
| 2767 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 2768 | codegen_->AddSlowPath(slow_path); |
| 2769 | |
| 2770 | Register out = load->GetLocations()->Out().As<Register>(); |
| 2771 | codegen_->LoadCurrentMethod(out); |
| 2772 | __ movl(out, Address(out, mirror::ArtMethod::DexCacheStringsOffset().Int32Value())); |
| 2773 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
| 2774 | __ testl(out, out); |
| 2775 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2776 | __ Bind(slow_path->GetExitLabel()); |
| 2777 | } |
| 2778 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2779 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 2780 | LocationSummary* locations = |
| 2781 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 2782 | locations->SetOut(Location::RequiresRegister()); |
| 2783 | } |
| 2784 | |
| 2785 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
| 2786 | Address address = Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); |
| 2787 | __ fs()->movl(load->GetLocations()->Out().As<Register>(), address); |
| 2788 | __ fs()->movl(address, Immediate(0)); |
| 2789 | } |
| 2790 | |
| 2791 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 2792 | LocationSummary* locations = |
| 2793 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 2794 | InvokeRuntimeCallingConvention calling_convention; |
| 2795 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2796 | } |
| 2797 | |
| 2798 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
| 2799 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pDeliverException))); |
| 2800 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 2801 | } |
| 2802 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2803 | void LocationsBuilderX86::VisitTypeCheck(HTypeCheck* instruction) { |
| 2804 | LocationSummary::CallKind call_kind = instruction->IsClassFinal() |
| 2805 | ? LocationSummary::kNoCall |
| 2806 | : LocationSummary::kCallOnSlowPath; |
| 2807 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 2808 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2809 | locations->SetInAt(1, Location::Any()); |
| 2810 | locations->SetOut(Location::RequiresRegister()); |
| 2811 | } |
| 2812 | |
| 2813 | void InstructionCodeGeneratorX86::VisitTypeCheck(HTypeCheck* instruction) { |
| 2814 | LocationSummary* locations = instruction->GetLocations(); |
| 2815 | Register obj = locations->InAt(0).As<Register>(); |
| 2816 | Location cls = locations->InAt(1); |
| 2817 | Register out = locations->Out().As<Register>(); |
| 2818 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2819 | Label done, zero; |
| 2820 | SlowPathCodeX86* slow_path = nullptr; |
| 2821 | |
| 2822 | // Return 0 if `obj` is null. |
| 2823 | // TODO: avoid this check if we know obj is not null. |
| 2824 | __ testl(obj, obj); |
| 2825 | __ j(kEqual, &zero); |
| 2826 | __ movl(out, Address(obj, class_offset)); |
| 2827 | // Compare the class of `obj` with `cls`. |
| 2828 | if (cls.IsRegister()) { |
| 2829 | __ cmpl(out, cls.As<Register>()); |
| 2830 | } else { |
| 2831 | DCHECK(cls.IsStackSlot()) << cls; |
| 2832 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 2833 | } |
| 2834 | |
| 2835 | if (instruction->IsClassFinal()) { |
| 2836 | // Classes must be equal for the instanceof to succeed. |
| 2837 | __ j(kNotEqual, &zero); |
| 2838 | __ movl(out, Immediate(1)); |
| 2839 | __ jmp(&done); |
| 2840 | } else { |
| 2841 | // If the classes are not equal, we go into a slow path. |
| 2842 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 2843 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86( |
| 2844 | instruction, Location::RegisterLocation(out)); |
| 2845 | codegen_->AddSlowPath(slow_path); |
| 2846 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 2847 | __ movl(out, Immediate(1)); |
| 2848 | __ jmp(&done); |
| 2849 | } |
| 2850 | __ Bind(&zero); |
| 2851 | __ movl(out, Immediate(0)); |
| 2852 | if (slow_path != nullptr) { |
| 2853 | __ Bind(slow_path->GetExitLabel()); |
| 2854 | } |
| 2855 | __ Bind(&done); |
| 2856 | } |
| 2857 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2858 | } // namespace x86 |
| 2859 | } // namespace art |