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