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 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame^] | 39 | static constexpr Register kRuntimeParameterCoreRegisters[] = { EAX, ECX, EDX, EBX }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 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 { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame^] | 578 | DCHECK(destination.IsStackSlot()) << destination; |
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 { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame^] | 639 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
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(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame^] | 677 | if (location.IsRegisterPair()) { |
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()); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 689 | if (temp_location.IsStackSlot()) { |
| 690 | Move32(location, temp_location); |
| 691 | } else { |
| 692 | DCHECK(temp_location.IsDoubleStackSlot()); |
| 693 | Move64(location, temp_location); |
| 694 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 695 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 696 | int slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 697 | switch (instruction->GetType()) { |
| 698 | case Primitive::kPrimBoolean: |
| 699 | case Primitive::kPrimByte: |
| 700 | case Primitive::kPrimChar: |
| 701 | case Primitive::kPrimShort: |
| 702 | case Primitive::kPrimInt: |
| 703 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 704 | case Primitive::kPrimFloat: |
| 705 | Move32(location, Location::StackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 706 | break; |
| 707 | |
| 708 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 709 | case Primitive::kPrimDouble: |
| 710 | Move64(location, Location::DoubleStackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 711 | break; |
| 712 | |
| 713 | default: |
| 714 | LOG(FATAL) << "Unimplemented local type " << instruction->GetType(); |
| 715 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 716 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 717 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 718 | switch (instruction->GetType()) { |
| 719 | case Primitive::kPrimBoolean: |
| 720 | case Primitive::kPrimByte: |
| 721 | case Primitive::kPrimChar: |
| 722 | case Primitive::kPrimShort: |
| 723 | case Primitive::kPrimInt: |
| 724 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 725 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 726 | Move32(location, instruction->GetLocations()->Out()); |
| 727 | break; |
| 728 | |
| 729 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 730 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 731 | Move64(location, instruction->GetLocations()->Out()); |
| 732 | break; |
| 733 | |
| 734 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 735 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 736 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 737 | } |
| 738 | } |
| 739 | |
| 740 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 741 | got->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 742 | } |
| 743 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 744 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 745 | HBasicBlock* successor = got->GetSuccessor(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 746 | DCHECK(!successor->IsExitBlock()); |
| 747 | |
| 748 | HBasicBlock* block = got->GetBlock(); |
| 749 | HInstruction* previous = got->GetPrevious(); |
| 750 | |
| 751 | HLoopInformation* info = block->GetLoopInformation(); |
| 752 | if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) { |
| 753 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 754 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 755 | return; |
| 756 | } |
| 757 | |
| 758 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 759 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 760 | } |
| 761 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 762 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 763 | } |
| 764 | } |
| 765 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 766 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 767 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 768 | } |
| 769 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 770 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 771 | UNUSED(exit); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 772 | if (kIsDebugBuild) { |
| 773 | __ Comment("Unreachable"); |
| 774 | __ int3(); |
| 775 | } |
| 776 | } |
| 777 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 778 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 779 | LocationSummary* locations = |
| 780 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 781 | HInstruction* cond = if_instr->InputAt(0); |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 782 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 783 | locations->SetInAt(0, Location::Any()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 784 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 785 | } |
| 786 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 787 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 788 | HInstruction* cond = if_instr->InputAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 789 | if (cond->IsIntConstant()) { |
| 790 | // Constant condition, statically compared against 1. |
| 791 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 792 | if (cond_value == 1) { |
| 793 | if (!codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 794 | if_instr->IfTrueSuccessor())) { |
| 795 | __ jmp(codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 796 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 797 | return; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 798 | } else { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 799 | DCHECK_EQ(cond_value, 0); |
| 800 | } |
| 801 | } else { |
| 802 | bool materialized = |
| 803 | !cond->IsCondition() || cond->AsCondition()->NeedsMaterialization(); |
| 804 | // Moves do not affect the eflags register, so if the condition is |
| 805 | // evaluated just before the if, we don't need to evaluate it |
| 806 | // again. |
| 807 | bool eflags_set = cond->IsCondition() |
| 808 | && cond->AsCondition()->IsBeforeWhenDisregardMoves(if_instr); |
| 809 | if (materialized) { |
| 810 | if (!eflags_set) { |
| 811 | // Materialized condition, compare against 0. |
| 812 | Location lhs = if_instr->GetLocations()->InAt(0); |
| 813 | if (lhs.IsRegister()) { |
| 814 | __ cmpl(lhs.As<Register>(), Immediate(0)); |
| 815 | } else { |
| 816 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 817 | } |
| 818 | __ j(kNotEqual, codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
| 819 | } else { |
| 820 | __ j(X86Condition(cond->AsCondition()->GetCondition()), |
| 821 | codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
| 822 | } |
| 823 | } else { |
| 824 | Location lhs = cond->GetLocations()->InAt(0); |
| 825 | Location rhs = cond->GetLocations()->InAt(1); |
| 826 | // LHS is guaranteed to be in a register (see |
| 827 | // LocationsBuilderX86::VisitCondition). |
| 828 | if (rhs.IsRegister()) { |
| 829 | __ cmpl(lhs.As<Register>(), rhs.As<Register>()); |
| 830 | } else if (rhs.IsConstant()) { |
| 831 | HIntConstant* instruction = rhs.GetConstant()->AsIntConstant(); |
| 832 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
| 833 | __ cmpl(lhs.As<Register>(), imm); |
| 834 | } else { |
| 835 | __ cmpl(lhs.As<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 836 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 837 | __ j(X86Condition(cond->AsCondition()->GetCondition()), |
| 838 | codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 839 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 840 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 841 | if (!codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 842 | if_instr->IfFalseSuccessor())) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 843 | __ jmp(codegen_->GetLabelOf(if_instr->IfFalseSuccessor())); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 844 | } |
| 845 | } |
| 846 | |
| 847 | void LocationsBuilderX86::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 848 | local->SetLocations(nullptr); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 849 | } |
| 850 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 851 | void InstructionCodeGeneratorX86::VisitLocal(HLocal* local) { |
| 852 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 853 | } |
| 854 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 855 | void LocationsBuilderX86::VisitLoadLocal(HLoadLocal* local) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 856 | local->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 857 | } |
| 858 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 859 | void InstructionCodeGeneratorX86::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 860 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 861 | UNUSED(load); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 862 | } |
| 863 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 864 | void LocationsBuilderX86::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 865 | LocationSummary* locations = |
| 866 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 867 | switch (store->InputAt(1)->GetType()) { |
| 868 | case Primitive::kPrimBoolean: |
| 869 | case Primitive::kPrimByte: |
| 870 | case Primitive::kPrimChar: |
| 871 | case Primitive::kPrimShort: |
| 872 | case Primitive::kPrimInt: |
| 873 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 874 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 875 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 876 | break; |
| 877 | |
| 878 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 879 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 880 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 881 | break; |
| 882 | |
| 883 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 884 | LOG(FATAL) << "Unknown local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 885 | } |
| 886 | store->SetLocations(locations); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 887 | } |
| 888 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 889 | void InstructionCodeGeneratorX86::VisitStoreLocal(HStoreLocal* store) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 890 | UNUSED(store); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 891 | } |
| 892 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 893 | void LocationsBuilderX86::VisitCondition(HCondition* comp) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 894 | LocationSummary* locations = |
| 895 | new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 896 | locations->SetInAt(0, Location::RequiresRegister()); |
| 897 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 898 | if (comp->NeedsMaterialization()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 899 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 900 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 901 | } |
| 902 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 903 | void InstructionCodeGeneratorX86::VisitCondition(HCondition* comp) { |
| 904 | if (comp->NeedsMaterialization()) { |
| 905 | LocationSummary* locations = comp->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 906 | Register reg = locations->Out().As<Register>(); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 907 | // Clear register: setcc only sets the low byte. |
| 908 | __ xorl(reg, reg); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 909 | if (locations->InAt(1).IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 910 | __ cmpl(locations->InAt(0).As<Register>(), |
| 911 | locations->InAt(1).As<Register>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 912 | } else if (locations->InAt(1).IsConstant()) { |
| 913 | HConstant* instruction = locations->InAt(1).GetConstant(); |
| 914 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 915 | __ cmpl(locations->InAt(0).As<Register>(), imm); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 916 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 917 | __ cmpl(locations->InAt(0).As<Register>(), |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 918 | Address(ESP, locations->InAt(1).GetStackIndex())); |
| 919 | } |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 920 | __ setb(X86Condition(comp->GetCondition()), reg); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 921 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
| 925 | VisitCondition(comp); |
| 926 | } |
| 927 | |
| 928 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
| 929 | VisitCondition(comp); |
| 930 | } |
| 931 | |
| 932 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
| 933 | VisitCondition(comp); |
| 934 | } |
| 935 | |
| 936 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
| 937 | VisitCondition(comp); |
| 938 | } |
| 939 | |
| 940 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
| 941 | VisitCondition(comp); |
| 942 | } |
| 943 | |
| 944 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
| 945 | VisitCondition(comp); |
| 946 | } |
| 947 | |
| 948 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 949 | VisitCondition(comp); |
| 950 | } |
| 951 | |
| 952 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 953 | VisitCondition(comp); |
| 954 | } |
| 955 | |
| 956 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
| 957 | VisitCondition(comp); |
| 958 | } |
| 959 | |
| 960 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
| 961 | VisitCondition(comp); |
| 962 | } |
| 963 | |
| 964 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 965 | VisitCondition(comp); |
| 966 | } |
| 967 | |
| 968 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 969 | VisitCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 973 | LocationSummary* locations = |
| 974 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 975 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 976 | } |
| 977 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 978 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 979 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 980 | UNUSED(constant); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 981 | } |
| 982 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 983 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 984 | LocationSummary* locations = |
| 985 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 986 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant) { |
| 990 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 991 | UNUSED(constant); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 992 | } |
| 993 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 994 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 995 | LocationSummary* locations = |
| 996 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 997 | locations->SetOut(Location::ConstantLocation(constant)); |
| 998 | } |
| 999 | |
| 1000 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1001 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1002 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1006 | LocationSummary* locations = |
| 1007 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1008 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1009 | } |
| 1010 | |
| 1011 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1012 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1013 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1014 | } |
| 1015 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1016 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1017 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1020 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1021 | UNUSED(ret); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1022 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1023 | __ ret(); |
| 1024 | } |
| 1025 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1026 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1027 | LocationSummary* locations = |
| 1028 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1029 | switch (ret->InputAt(0)->GetType()) { |
| 1030 | case Primitive::kPrimBoolean: |
| 1031 | case Primitive::kPrimByte: |
| 1032 | case Primitive::kPrimChar: |
| 1033 | case Primitive::kPrimShort: |
| 1034 | case Primitive::kPrimInt: |
| 1035 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1036 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1037 | break; |
| 1038 | |
| 1039 | case Primitive::kPrimLong: |
| 1040 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1041 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1042 | break; |
| 1043 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1044 | case Primitive::kPrimFloat: |
| 1045 | case Primitive::kPrimDouble: |
| 1046 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1047 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1048 | break; |
| 1049 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1050 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1051 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1052 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1055 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1056 | if (kIsDebugBuild) { |
| 1057 | switch (ret->InputAt(0)->GetType()) { |
| 1058 | case Primitive::kPrimBoolean: |
| 1059 | case Primitive::kPrimByte: |
| 1060 | case Primitive::kPrimChar: |
| 1061 | case Primitive::kPrimShort: |
| 1062 | case Primitive::kPrimInt: |
| 1063 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1064 | DCHECK_EQ(ret->GetLocations()->InAt(0).As<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1065 | break; |
| 1066 | |
| 1067 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1068 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1069 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1070 | break; |
| 1071 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1072 | case Primitive::kPrimFloat: |
| 1073 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1074 | DCHECK_EQ(ret->GetLocations()->InAt(0).As<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1075 | break; |
| 1076 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1077 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1078 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1079 | } |
| 1080 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1081 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1082 | __ ret(); |
| 1083 | } |
| 1084 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1085 | void LocationsBuilderX86::VisitInvokeStatic(HInvokeStatic* invoke) { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1086 | HandleInvoke(invoke); |
| 1087 | } |
| 1088 | |
| 1089 | void InstructionCodeGeneratorX86::VisitInvokeStatic(HInvokeStatic* invoke) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1090 | Register temp = invoke->GetLocations()->GetTemp(0).As<Register>(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1091 | |
| 1092 | // TODO: Implement all kinds of calls: |
| 1093 | // 1) boot -> boot |
| 1094 | // 2) app -> boot |
| 1095 | // 3) app -> app |
| 1096 | // |
| 1097 | // Currently we implement the app -> app logic, which looks up in the resolve cache. |
| 1098 | |
| 1099 | // temp = method; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1100 | codegen_->LoadCurrentMethod(temp); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1101 | // temp = temp->dex_cache_resolved_methods_; |
| 1102 | __ movl(temp, Address(temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value())); |
| 1103 | // temp = temp[index_in_cache] |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1104 | __ movl(temp, Address(temp, CodeGenerator::GetCacheOffset(invoke->GetIndexInDexCache()))); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1105 | // (temp + offset_of_quick_compiled_code)() |
| 1106 | __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value())); |
| 1107 | |
| 1108 | DCHECK(!codegen_->IsLeafMethod()); |
| 1109 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1110 | } |
| 1111 | |
| 1112 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 1113 | HandleInvoke(invoke); |
| 1114 | } |
| 1115 | |
| 1116 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1117 | LocationSummary* locations = |
| 1118 | new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1119 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1120 | |
| 1121 | InvokeDexCallingConventionVisitor calling_convention_visitor; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1122 | for (size_t i = 0; i < invoke->InputCount(); i++) { |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1123 | HInstruction* input = invoke->InputAt(i); |
| 1124 | locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType())); |
| 1125 | } |
| 1126 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1127 | switch (invoke->GetType()) { |
| 1128 | case Primitive::kPrimBoolean: |
| 1129 | case Primitive::kPrimByte: |
| 1130 | case Primitive::kPrimChar: |
| 1131 | case Primitive::kPrimShort: |
| 1132 | case Primitive::kPrimInt: |
| 1133 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1134 | locations->SetOut(Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1135 | break; |
| 1136 | |
| 1137 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1138 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1139 | break; |
| 1140 | |
| 1141 | case Primitive::kPrimVoid: |
| 1142 | break; |
| 1143 | |
| 1144 | case Primitive::kPrimDouble: |
| 1145 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1146 | locations->SetOut(Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1147 | break; |
| 1148 | } |
| 1149 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1150 | invoke->SetLocations(locations); |
| 1151 | } |
| 1152 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1153 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1154 | Register temp = invoke->GetLocations()->GetTemp(0).As<Register>(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1155 | uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() + |
| 1156 | invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry); |
| 1157 | LocationSummary* locations = invoke->GetLocations(); |
| 1158 | Location receiver = locations->InAt(0); |
| 1159 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1160 | // temp = object->GetClass(); |
| 1161 | if (receiver.IsStackSlot()) { |
| 1162 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
| 1163 | __ movl(temp, Address(temp, class_offset)); |
| 1164 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1165 | __ movl(temp, Address(receiver.As<Register>(), class_offset)); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1166 | } |
| 1167 | // temp = temp->GetMethodAt(method_offset); |
| 1168 | __ movl(temp, Address(temp, method_offset)); |
| 1169 | // call temp->GetEntryPoint(); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1170 | __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value())); |
| 1171 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1172 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1173 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1174 | } |
| 1175 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1176 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1177 | HandleInvoke(invoke); |
| 1178 | // Add the hidden argument. |
| 1179 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM0)); |
| 1180 | } |
| 1181 | |
| 1182 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1183 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 1184 | Register temp = invoke->GetLocations()->GetTemp(0).As<Register>(); |
| 1185 | uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() + |
| 1186 | (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry); |
| 1187 | LocationSummary* locations = invoke->GetLocations(); |
| 1188 | Location receiver = locations->InAt(0); |
| 1189 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1190 | |
| 1191 | // Set the hidden argument. |
| 1192 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
| 1193 | __ movd(invoke->GetLocations()->GetTemp(1).As<XmmRegister>(), temp); |
| 1194 | |
| 1195 | // temp = object->GetClass(); |
| 1196 | if (receiver.IsStackSlot()) { |
| 1197 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
| 1198 | __ movl(temp, Address(temp, class_offset)); |
| 1199 | } else { |
| 1200 | __ movl(temp, Address(receiver.As<Register>(), class_offset)); |
| 1201 | } |
| 1202 | // temp = temp->GetImtEntryAt(method_offset); |
| 1203 | __ movl(temp, Address(temp, method_offset)); |
| 1204 | // call temp->GetEntryPoint(); |
| 1205 | __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value())); |
| 1206 | |
| 1207 | DCHECK(!codegen_->IsLeafMethod()); |
| 1208 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1209 | } |
| 1210 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1211 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 1212 | LocationSummary* locations = |
| 1213 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1214 | switch (neg->GetResultType()) { |
| 1215 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1216 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1217 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1218 | locations->SetOut(Location::SameAsFirstInput()); |
| 1219 | break; |
| 1220 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1221 | case Primitive::kPrimFloat: |
| 1222 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1223 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1224 | // Output overlaps as we need a fresh (zero-initialized) |
| 1225 | // register to perform subtraction from zero. |
| 1226 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1227 | break; |
| 1228 | |
| 1229 | default: |
| 1230 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1231 | } |
| 1232 | } |
| 1233 | |
| 1234 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 1235 | LocationSummary* locations = neg->GetLocations(); |
| 1236 | Location out = locations->Out(); |
| 1237 | Location in = locations->InAt(0); |
| 1238 | switch (neg->GetResultType()) { |
| 1239 | case Primitive::kPrimInt: |
| 1240 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1241 | DCHECK(in.Equals(out)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1242 | __ negl(out.As<Register>()); |
| 1243 | break; |
| 1244 | |
| 1245 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1246 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1247 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1248 | __ negl(out.AsRegisterPairLow<Register>()); |
| 1249 | // Negation is similar to subtraction from zero. The least |
| 1250 | // significant byte triggers a borrow when it is different from |
| 1251 | // zero; to take it into account, add 1 to the most significant |
| 1252 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 1253 | // operation. |
| 1254 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 1255 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 1256 | break; |
| 1257 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1258 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1259 | DCHECK(!in.Equals(out)); |
| 1260 | // out = 0 |
| 1261 | __ xorps(out.As<XmmRegister>(), out.As<XmmRegister>()); |
| 1262 | // out = out - in |
| 1263 | __ subss(out.As<XmmRegister>(), in.As<XmmRegister>()); |
| 1264 | break; |
| 1265 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1266 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1267 | DCHECK(!in.Equals(out)); |
| 1268 | // out = 0 |
| 1269 | __ xorpd(out.As<XmmRegister>(), out.As<XmmRegister>()); |
| 1270 | // out = out - in |
| 1271 | __ subsd(out.As<XmmRegister>(), in.As<XmmRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1272 | break; |
| 1273 | |
| 1274 | default: |
| 1275 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1276 | } |
| 1277 | } |
| 1278 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1279 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 1280 | LocationSummary* locations = |
| 1281 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 1282 | Primitive::Type result_type = conversion->GetResultType(); |
| 1283 | Primitive::Type input_type = conversion->GetInputType(); |
| 1284 | switch (result_type) { |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1285 | case Primitive::kPrimInt: |
| 1286 | switch (input_type) { |
| 1287 | case Primitive::kPrimLong: |
| 1288 | // long-to-int conversion. |
| 1289 | locations->SetInAt(0, Location::Any()); |
| 1290 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1291 | break; |
| 1292 | |
| 1293 | case Primitive::kPrimFloat: |
| 1294 | case Primitive::kPrimDouble: |
| 1295 | LOG(FATAL) << "Type conversion from " << input_type |
| 1296 | << " to " << result_type << " not yet implemented"; |
| 1297 | break; |
| 1298 | |
| 1299 | default: |
| 1300 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1301 | << " to " << result_type; |
| 1302 | } |
| 1303 | break; |
| 1304 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1305 | case Primitive::kPrimLong: |
| 1306 | switch (input_type) { |
| 1307 | case Primitive::kPrimByte: |
| 1308 | case Primitive::kPrimShort: |
| 1309 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1310 | case Primitive::kPrimChar: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1311 | // int-to-long conversion. |
| 1312 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 1313 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 1314 | break; |
| 1315 | |
| 1316 | case Primitive::kPrimFloat: |
| 1317 | case Primitive::kPrimDouble: |
| 1318 | LOG(FATAL) << "Type conversion from " << input_type << " to " |
| 1319 | << result_type << " not yet implemented"; |
| 1320 | break; |
| 1321 | |
| 1322 | default: |
| 1323 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1324 | << " to " << result_type; |
| 1325 | } |
| 1326 | break; |
| 1327 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1328 | case Primitive::kPrimFloat: |
| 1329 | case Primitive::kPrimDouble: |
| 1330 | LOG(FATAL) << "Type conversion from " << input_type |
| 1331 | << " to " << result_type << " not yet implemented"; |
| 1332 | break; |
| 1333 | |
| 1334 | default: |
| 1335 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1336 | << " to " << result_type; |
| 1337 | } |
| 1338 | } |
| 1339 | |
| 1340 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 1341 | LocationSummary* locations = conversion->GetLocations(); |
| 1342 | Location out = locations->Out(); |
| 1343 | Location in = locations->InAt(0); |
| 1344 | Primitive::Type result_type = conversion->GetResultType(); |
| 1345 | Primitive::Type input_type = conversion->GetInputType(); |
| 1346 | switch (result_type) { |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1347 | case Primitive::kPrimInt: |
| 1348 | switch (input_type) { |
| 1349 | case Primitive::kPrimLong: |
| 1350 | // long-to-int conversion. |
| 1351 | if (in.IsRegisterPair()) { |
| 1352 | __ movl(out.As<Register>(), in.AsRegisterPairLow<Register>()); |
| 1353 | } else if (in.IsDoubleStackSlot()) { |
| 1354 | __ movl(out.As<Register>(), Address(ESP, in.GetStackIndex())); |
| 1355 | } else { |
| 1356 | DCHECK(in.IsConstant()); |
| 1357 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 1358 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 1359 | __ movl(out.As<Register>(), Immediate(static_cast<int32_t>(value))); |
| 1360 | } |
| 1361 | break; |
| 1362 | |
| 1363 | case Primitive::kPrimFloat: |
| 1364 | case Primitive::kPrimDouble: |
| 1365 | LOG(FATAL) << "Type conversion from " << input_type |
| 1366 | << " to " << result_type << " not yet implemented"; |
| 1367 | break; |
| 1368 | |
| 1369 | default: |
| 1370 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1371 | << " to " << result_type; |
| 1372 | } |
| 1373 | break; |
| 1374 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1375 | case Primitive::kPrimLong: |
| 1376 | switch (input_type) { |
| 1377 | case Primitive::kPrimByte: |
| 1378 | case Primitive::kPrimShort: |
| 1379 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1380 | case Primitive::kPrimChar: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1381 | // int-to-long conversion. |
| 1382 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 1383 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
| 1384 | DCHECK_EQ(in.As<Register>(), EAX); |
| 1385 | __ cdq(); |
| 1386 | break; |
| 1387 | |
| 1388 | case Primitive::kPrimFloat: |
| 1389 | case Primitive::kPrimDouble: |
| 1390 | LOG(FATAL) << "Type conversion from " << input_type << " to " |
| 1391 | << result_type << " not yet implemented"; |
| 1392 | break; |
| 1393 | |
| 1394 | default: |
| 1395 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1396 | << " to " << result_type; |
| 1397 | } |
| 1398 | break; |
| 1399 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1400 | case Primitive::kPrimFloat: |
| 1401 | case Primitive::kPrimDouble: |
| 1402 | LOG(FATAL) << "Type conversion from " << input_type |
| 1403 | << " to " << result_type << " not yet implemented"; |
| 1404 | break; |
| 1405 | |
| 1406 | default: |
| 1407 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1408 | << " to " << result_type; |
| 1409 | } |
| 1410 | } |
| 1411 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1412 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1413 | LocationSummary* locations = |
| 1414 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1415 | switch (add->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1416 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1417 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1418 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1419 | locations->SetInAt(1, Location::Any()); |
| 1420 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1421 | break; |
| 1422 | } |
| 1423 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1424 | case Primitive::kPrimFloat: |
| 1425 | case Primitive::kPrimDouble: { |
| 1426 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1427 | locations->SetInAt(1, Location::Any()); |
| 1428 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1429 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1430 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1431 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1432 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1433 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 1434 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1435 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1436 | } |
| 1437 | |
| 1438 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 1439 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1440 | Location first = locations->InAt(0); |
| 1441 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1442 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1443 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1444 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1445 | if (second.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1446 | __ addl(first.As<Register>(), second.As<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1447 | } else if (second.IsConstant()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1448 | __ addl(first.As<Register>(), Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1449 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1450 | __ addl(first.As<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1451 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1452 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1456 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1457 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 1458 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1459 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1460 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 1461 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1462 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1463 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1464 | break; |
| 1465 | } |
| 1466 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1467 | case Primitive::kPrimFloat: { |
| 1468 | if (second.IsFpuRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1469 | __ addss(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1470 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1471 | __ addss(first.As<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1472 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1473 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | case Primitive::kPrimDouble: { |
| 1477 | if (second.IsFpuRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1478 | __ addsd(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1479 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1480 | __ addsd(first.As<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1481 | } |
| 1482 | break; |
| 1483 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1484 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1485 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1486 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1487 | } |
| 1488 | } |
| 1489 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1490 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1491 | LocationSummary* locations = |
| 1492 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1493 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1494 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1495 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1496 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1497 | locations->SetInAt(1, Location::Any()); |
| 1498 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1499 | break; |
| 1500 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1501 | case Primitive::kPrimFloat: |
| 1502 | case Primitive::kPrimDouble: { |
| 1503 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1504 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1505 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1506 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1507 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1508 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1509 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1510 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1511 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 1515 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1516 | Location first = locations->InAt(0); |
| 1517 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1518 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1519 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1520 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1521 | if (second.IsRegister()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1522 | __ subl(first.As<Register>(), second.As<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1523 | } else if (second.IsConstant()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1524 | __ subl(first.As<Register>(), Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1525 | } else { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1526 | __ subl(first.As<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1527 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1528 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1532 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1533 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 1534 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1535 | } else { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1536 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1537 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 1538 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1539 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1540 | break; |
| 1541 | } |
| 1542 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1543 | case Primitive::kPrimFloat: { |
| 1544 | __ subss(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1545 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | case Primitive::kPrimDouble: { |
| 1549 | __ subsd(first.As<XmmRegister>(), second.As<XmmRegister>()); |
| 1550 | break; |
| 1551 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1552 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1553 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1554 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1555 | } |
| 1556 | } |
| 1557 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1558 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 1559 | LocationSummary* locations = |
| 1560 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 1561 | switch (mul->GetResultType()) { |
| 1562 | case Primitive::kPrimInt: |
| 1563 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1564 | locations->SetInAt(1, Location::Any()); |
| 1565 | locations->SetOut(Location::SameAsFirstInput()); |
| 1566 | break; |
| 1567 | case Primitive::kPrimLong: { |
| 1568 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1569 | // TODO: Currently this handles only stack operands: |
| 1570 | // - we don't have enough registers because we currently use Quick ABI. |
| 1571 | // - by the time we have a working register allocator we will probably change the ABI |
| 1572 | // and fix the above. |
| 1573 | // - we don't have a way yet to request operands on stack but the base line compiler |
| 1574 | // will leave the operands on the stack with Any(). |
| 1575 | locations->SetInAt(1, Location::Any()); |
| 1576 | locations->SetOut(Location::SameAsFirstInput()); |
| 1577 | // Needed for imul on 32bits with 64bits output. |
| 1578 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 1579 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 1580 | break; |
| 1581 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1582 | case Primitive::kPrimFloat: |
| 1583 | case Primitive::kPrimDouble: { |
| 1584 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1585 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1586 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1587 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1588 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1589 | |
| 1590 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1591 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1592 | } |
| 1593 | } |
| 1594 | |
| 1595 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 1596 | LocationSummary* locations = mul->GetLocations(); |
| 1597 | Location first = locations->InAt(0); |
| 1598 | Location second = locations->InAt(1); |
| 1599 | DCHECK(first.Equals(locations->Out())); |
| 1600 | |
| 1601 | switch (mul->GetResultType()) { |
| 1602 | case Primitive::kPrimInt: { |
| 1603 | if (second.IsRegister()) { |
| 1604 | __ imull(first.As<Register>(), second.As<Register>()); |
| 1605 | } else if (second.IsConstant()) { |
| 1606 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 1607 | __ imull(first.As<Register>(), imm); |
| 1608 | } else { |
| 1609 | DCHECK(second.IsStackSlot()); |
| 1610 | __ imull(first.As<Register>(), Address(ESP, second.GetStackIndex())); |
| 1611 | } |
| 1612 | break; |
| 1613 | } |
| 1614 | |
| 1615 | case Primitive::kPrimLong: { |
| 1616 | DCHECK(second.IsDoubleStackSlot()); |
| 1617 | |
| 1618 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 1619 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 1620 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 1621 | Address in2_lo(ESP, second.GetStackIndex()); |
| 1622 | Register eax = locations->GetTemp(0).As<Register>(); |
| 1623 | Register edx = locations->GetTemp(1).As<Register>(); |
| 1624 | |
| 1625 | DCHECK_EQ(EAX, eax); |
| 1626 | DCHECK_EQ(EDX, edx); |
| 1627 | |
| 1628 | // input: in1 - 64 bits, in2 - 64 bits |
| 1629 | // output: in1 |
| 1630 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 1631 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 1632 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
| 1633 | |
| 1634 | __ movl(eax, in2_hi); |
| 1635 | // eax <- in1.lo * in2.hi |
| 1636 | __ imull(eax, in1_lo); |
| 1637 | // in1.hi <- in1.hi * in2.lo |
| 1638 | __ imull(in1_hi, in2_lo); |
| 1639 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 1640 | __ addl(in1_hi, eax); |
| 1641 | // move in1_lo to eax to prepare for double precision |
| 1642 | __ movl(eax, in1_lo); |
| 1643 | // edx:eax <- in1.lo * in2.lo |
| 1644 | __ mull(in2_lo); |
| 1645 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 1646 | __ addl(in1_hi, edx); |
| 1647 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 1648 | __ movl(in1_lo, eax); |
| 1649 | |
| 1650 | break; |
| 1651 | } |
| 1652 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1653 | case Primitive::kPrimFloat: { |
| 1654 | __ mulss(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1655 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1656 | } |
| 1657 | |
| 1658 | case Primitive::kPrimDouble: { |
| 1659 | __ mulsd(first.As<XmmRegister>(), second.As<XmmRegister>()); |
| 1660 | break; |
| 1661 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1662 | |
| 1663 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1664 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1665 | } |
| 1666 | } |
| 1667 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1668 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame^] | 1669 | LocationSummary::CallKind call_kind = div->GetResultType() == Primitive::kPrimLong |
| 1670 | ? LocationSummary::kCall |
| 1671 | : LocationSummary::kNoCall; |
| 1672 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 1673 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1674 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1675 | case Primitive::kPrimInt: { |
| 1676 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 1677 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1678 | locations->SetOut(Location::SameAsFirstInput()); |
| 1679 | // Intel uses edx:eax as the dividend. |
| 1680 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 1681 | break; |
| 1682 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1683 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame^] | 1684 | InvokeRuntimeCallingConvention calling_convention; |
| 1685 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 1686 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 1687 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 1688 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 1689 | // Runtime helper puts the result in EAX, EDX. |
| 1690 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1691 | break; |
| 1692 | } |
| 1693 | case Primitive::kPrimFloat: |
| 1694 | case Primitive::kPrimDouble: { |
| 1695 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1696 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1697 | locations->SetOut(Location::SameAsFirstInput()); |
| 1698 | break; |
| 1699 | } |
| 1700 | |
| 1701 | default: |
| 1702 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 1703 | } |
| 1704 | } |
| 1705 | |
| 1706 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 1707 | LocationSummary* locations = div->GetLocations(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame^] | 1708 | Location out = locations->Out(); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1709 | Location first = locations->InAt(0); |
| 1710 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1711 | |
| 1712 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1713 | case Primitive::kPrimInt: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame^] | 1714 | DCHECK(first.Equals(out)); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1715 | Register first_reg = first.As<Register>(); |
| 1716 | Register second_reg = second.As<Register>(); |
| 1717 | DCHECK_EQ(EAX, first_reg); |
| 1718 | DCHECK_EQ(EDX, locations->GetTemp(0).As<Register>()); |
| 1719 | |
| 1720 | SlowPathCodeX86* slow_path = |
| 1721 | new (GetGraph()->GetArena()) DivMinusOneSlowPathX86(first_reg); |
| 1722 | codegen_->AddSlowPath(slow_path); |
| 1723 | |
| 1724 | // 0x80000000/-1 triggers an arithmetic exception! |
| 1725 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 1726 | // it's safe to just use negl instead of more complex comparisons. |
| 1727 | |
| 1728 | __ cmpl(second_reg, Immediate(-1)); |
| 1729 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 1730 | |
| 1731 | // edx:eax <- sign-extended of eax |
| 1732 | __ cdq(); |
| 1733 | // eax = quotient, edx = remainder |
| 1734 | __ idivl(second_reg); |
| 1735 | |
| 1736 | __ Bind(slow_path->GetExitLabel()); |
| 1737 | break; |
| 1738 | } |
| 1739 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1740 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame^] | 1741 | InvokeRuntimeCallingConvention calling_convention; |
| 1742 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 1743 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 1744 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 1745 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 1746 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 1747 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 1748 | |
| 1749 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pLdiv))); |
| 1750 | codegen_->RecordPcInfo(div, div->GetDexPc()); |
| 1751 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1752 | break; |
| 1753 | } |
| 1754 | |
| 1755 | case Primitive::kPrimFloat: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame^] | 1756 | DCHECK(first.Equals(out)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1757 | __ divss(first.As<XmmRegister>(), second.As<XmmRegister>()); |
| 1758 | break; |
| 1759 | } |
| 1760 | |
| 1761 | case Primitive::kPrimDouble: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame^] | 1762 | DCHECK(first.Equals(out)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1763 | __ divsd(first.As<XmmRegister>(), second.As<XmmRegister>()); |
| 1764 | break; |
| 1765 | } |
| 1766 | |
| 1767 | default: |
| 1768 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 1769 | } |
| 1770 | } |
| 1771 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1772 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 1773 | LocationSummary* locations = |
| 1774 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame^] | 1775 | switch (instruction->GetType()) { |
| 1776 | case Primitive::kPrimInt: { |
| 1777 | locations->SetInAt(0, Location::Any()); |
| 1778 | break; |
| 1779 | } |
| 1780 | case Primitive::kPrimLong: { |
| 1781 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 1782 | if (!instruction->IsConstant()) { |
| 1783 | locations->AddTemp(Location::RequiresRegister()); |
| 1784 | } |
| 1785 | break; |
| 1786 | } |
| 1787 | default: |
| 1788 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 1789 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1790 | if (instruction->HasUses()) { |
| 1791 | locations->SetOut(Location::SameAsFirstInput()); |
| 1792 | } |
| 1793 | } |
| 1794 | |
| 1795 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 1796 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
| 1797 | codegen_->AddSlowPath(slow_path); |
| 1798 | |
| 1799 | LocationSummary* locations = instruction->GetLocations(); |
| 1800 | Location value = locations->InAt(0); |
| 1801 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame^] | 1802 | switch (instruction->GetType()) { |
| 1803 | case Primitive::kPrimInt: { |
| 1804 | if (value.IsRegister()) { |
| 1805 | __ testl(value.As<Register>(), value.As<Register>()); |
| 1806 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 1807 | } else if (value.IsStackSlot()) { |
| 1808 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 1809 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 1810 | } else { |
| 1811 | DCHECK(value.IsConstant()) << value; |
| 1812 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 1813 | __ jmp(slow_path->GetEntryLabel()); |
| 1814 | } |
| 1815 | } |
| 1816 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1817 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame^] | 1818 | case Primitive::kPrimLong: { |
| 1819 | if (value.IsRegisterPair()) { |
| 1820 | Register temp = locations->GetTemp(0).As<Register>(); |
| 1821 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 1822 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 1823 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 1824 | } else { |
| 1825 | DCHECK(value.IsConstant()) << value; |
| 1826 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 1827 | __ jmp(slow_path->GetEntryLabel()); |
| 1828 | } |
| 1829 | } |
| 1830 | break; |
| 1831 | } |
| 1832 | default: |
| 1833 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1834 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1835 | } |
| 1836 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1837 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1838 | LocationSummary* locations = |
| 1839 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1840 | locations->SetOut(Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1841 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1842 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1843 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1844 | } |
| 1845 | |
| 1846 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
| 1847 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1848 | codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1849 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1850 | |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 1851 | __ fs()->call( |
| 1852 | Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pAllocObjectWithAccessCheck))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1853 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1854 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1855 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1856 | } |
| 1857 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1858 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 1859 | LocationSummary* locations = |
| 1860 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 1861 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 1862 | InvokeRuntimeCallingConvention calling_convention; |
| 1863 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1864 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1865 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1866 | } |
| 1867 | |
| 1868 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 1869 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1870 | codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1871 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
| 1872 | |
| 1873 | __ fs()->call( |
| 1874 | Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pAllocArrayWithAccessCheck))); |
| 1875 | |
| 1876 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 1877 | DCHECK(!codegen_->IsLeafMethod()); |
| 1878 | } |
| 1879 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1880 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1881 | LocationSummary* locations = |
| 1882 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1883 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 1884 | if (location.IsStackSlot()) { |
| 1885 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 1886 | } else if (location.IsDoubleStackSlot()) { |
| 1887 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1888 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1889 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1890 | } |
| 1891 | |
| 1892 | void InstructionCodeGeneratorX86::VisitParameterValue(HParameterValue* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1893 | UNUSED(instruction); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1894 | } |
| 1895 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1896 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1897 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1898 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1899 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1900 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1901 | } |
| 1902 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1903 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 1904 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 1905 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1906 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 1907 | DCHECK(in.Equals(out)); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1908 | switch (not_->InputAt(0)->GetType()) { |
| 1909 | case Primitive::kPrimBoolean: |
| 1910 | __ xorl(out.As<Register>(), Immediate(1)); |
| 1911 | break; |
| 1912 | |
| 1913 | case Primitive::kPrimInt: |
| 1914 | __ notl(out.As<Register>()); |
| 1915 | break; |
| 1916 | |
| 1917 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 1918 | __ notl(out.AsRegisterPairLow<Register>()); |
| 1919 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1920 | break; |
| 1921 | |
| 1922 | default: |
| 1923 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 1924 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1925 | } |
| 1926 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1927 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1928 | LocationSummary* locations = |
| 1929 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1930 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1931 | locations->SetInAt(1, Location::Any()); |
| 1932 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1933 | } |
| 1934 | |
| 1935 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1936 | LocationSummary* locations = compare->GetLocations(); |
| 1937 | switch (compare->InputAt(0)->GetType()) { |
| 1938 | case Primitive::kPrimLong: { |
| 1939 | Label less, greater, done; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1940 | Register output = locations->Out().As<Register>(); |
| 1941 | Location left = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1942 | Location right = locations->InAt(1); |
| 1943 | if (right.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1944 | __ cmpl(left.AsRegisterPairHigh<Register>(), right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1945 | } else { |
| 1946 | DCHECK(right.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1947 | __ cmpl(left.AsRegisterPairHigh<Register>(), |
| 1948 | Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1949 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1950 | __ j(kLess, &less); // Signed compare. |
| 1951 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1952 | if (right.IsRegisterPair()) { |
| 1953 | __ cmpl(left.AsRegisterPairLow<Register>(), right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1954 | } else { |
| 1955 | DCHECK(right.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1956 | __ cmpl(left.AsRegisterPairLow<Register>(), Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1957 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1958 | __ movl(output, Immediate(0)); |
| 1959 | __ j(kEqual, &done); |
| 1960 | __ j(kBelow, &less); // Unsigned compare. |
| 1961 | |
| 1962 | __ Bind(&greater); |
| 1963 | __ movl(output, Immediate(1)); |
| 1964 | __ jmp(&done); |
| 1965 | |
| 1966 | __ Bind(&less); |
| 1967 | __ movl(output, Immediate(-1)); |
| 1968 | |
| 1969 | __ Bind(&done); |
| 1970 | break; |
| 1971 | } |
| 1972 | default: |
| 1973 | LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType(); |
| 1974 | } |
| 1975 | } |
| 1976 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1977 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1978 | LocationSummary* locations = |
| 1979 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 1980 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 1981 | locations->SetInAt(i, Location::Any()); |
| 1982 | } |
| 1983 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1987 | UNUSED(instruction); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1988 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1989 | } |
| 1990 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1991 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1992 | LocationSummary* locations = |
| 1993 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1994 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1995 | Primitive::Type field_type = instruction->GetFieldType(); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1996 | bool is_object_type = field_type == Primitive::kPrimNot; |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 1997 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 1998 | || (field_type == Primitive::kPrimByte); |
| 1999 | // The register allocator does not support multiple |
| 2000 | // inputs that die at entry with one in a specific register. |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 2001 | if (is_byte_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2002 | // Ensure the value is in a byte register. |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2003 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2004 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2005 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2006 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 2007 | // Temporary registers for the write barrier. |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 2008 | if (is_object_type) { |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 2009 | locations->AddTemp(Location::RequiresRegister()); |
| 2010 | // Ensure the card is in a byte register. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2011 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 2012 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 2016 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2017 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2018 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2019 | Primitive::Type field_type = instruction->GetFieldType(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2020 | |
| 2021 | switch (field_type) { |
| 2022 | case Primitive::kPrimBoolean: |
| 2023 | case Primitive::kPrimByte: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2024 | ByteRegister value = locations->InAt(1).As<ByteRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2025 | __ movb(Address(obj, offset), value); |
| 2026 | break; |
| 2027 | } |
| 2028 | |
| 2029 | case Primitive::kPrimShort: |
| 2030 | case Primitive::kPrimChar: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2031 | Register value = locations->InAt(1).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2032 | __ movw(Address(obj, offset), value); |
| 2033 | break; |
| 2034 | } |
| 2035 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2036 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2037 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2038 | Register value = locations->InAt(1).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2039 | __ movl(Address(obj, offset), value); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2040 | |
| 2041 | if (field_type == Primitive::kPrimNot) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2042 | Register temp = locations->GetTemp(0).As<Register>(); |
| 2043 | Register card = locations->GetTemp(1).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2044 | codegen_->MarkGCCard(temp, card, obj, value); |
| 2045 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2046 | break; |
| 2047 | } |
| 2048 | |
| 2049 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2050 | Location value = locations->InAt(1); |
| 2051 | __ movl(Address(obj, offset), value.AsRegisterPairLow<Register>()); |
| 2052 | __ movl(Address(obj, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2053 | break; |
| 2054 | } |
| 2055 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2056 | case Primitive::kPrimFloat: { |
| 2057 | XmmRegister value = locations->InAt(1).As<XmmRegister>(); |
| 2058 | __ movss(Address(obj, offset), value); |
| 2059 | break; |
| 2060 | } |
| 2061 | |
| 2062 | case Primitive::kPrimDouble: { |
| 2063 | XmmRegister value = locations->InAt(1).As<XmmRegister>(); |
| 2064 | __ movsd(Address(obj, offset), value); |
| 2065 | break; |
| 2066 | } |
| 2067 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2068 | case Primitive::kPrimVoid: |
| 2069 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2070 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2071 | } |
| 2072 | } |
| 2073 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2074 | void CodeGeneratorX86::MarkGCCard(Register temp, Register card, Register object, Register value) { |
| 2075 | Label is_null; |
| 2076 | __ testl(value, value); |
| 2077 | __ j(kEqual, &is_null); |
| 2078 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 2079 | __ movl(temp, object); |
| 2080 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
| 2081 | __ movb(Address(temp, card, TIMES_1, 0), |
| 2082 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
| 2083 | __ Bind(&is_null); |
| 2084 | } |
| 2085 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2086 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2087 | LocationSummary* locations = |
| 2088 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2089 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2090 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2091 | } |
| 2092 | |
| 2093 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 2094 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2095 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2096 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
| 2097 | |
| 2098 | switch (instruction->GetType()) { |
| 2099 | case Primitive::kPrimBoolean: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2100 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2101 | __ movzxb(out, Address(obj, offset)); |
| 2102 | break; |
| 2103 | } |
| 2104 | |
| 2105 | case Primitive::kPrimByte: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2106 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2107 | __ movsxb(out, Address(obj, offset)); |
| 2108 | break; |
| 2109 | } |
| 2110 | |
| 2111 | case Primitive::kPrimShort: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2112 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2113 | __ movsxw(out, Address(obj, offset)); |
| 2114 | break; |
| 2115 | } |
| 2116 | |
| 2117 | case Primitive::kPrimChar: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2118 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2119 | __ movzxw(out, Address(obj, offset)); |
| 2120 | break; |
| 2121 | } |
| 2122 | |
| 2123 | case Primitive::kPrimInt: |
| 2124 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2125 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2126 | __ movl(out, Address(obj, offset)); |
| 2127 | break; |
| 2128 | } |
| 2129 | |
| 2130 | case Primitive::kPrimLong: { |
| 2131 | // TODO: support volatile. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2132 | __ movl(locations->Out().AsRegisterPairLow<Register>(), Address(obj, offset)); |
| 2133 | __ movl(locations->Out().AsRegisterPairHigh<Register>(), Address(obj, kX86WordSize + offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2134 | break; |
| 2135 | } |
| 2136 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2137 | case Primitive::kPrimFloat: { |
| 2138 | XmmRegister out = locations->Out().As<XmmRegister>(); |
| 2139 | __ movss(out, Address(obj, offset)); |
| 2140 | break; |
| 2141 | } |
| 2142 | |
| 2143 | case Primitive::kPrimDouble: { |
| 2144 | XmmRegister out = locations->Out().As<XmmRegister>(); |
| 2145 | __ movsd(out, Address(obj, offset)); |
| 2146 | break; |
| 2147 | } |
| 2148 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2149 | case Primitive::kPrimVoid: |
| 2150 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2151 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2152 | } |
| 2153 | } |
| 2154 | |
| 2155 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2156 | LocationSummary* locations = |
| 2157 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2158 | locations->SetInAt(0, Location::Any()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2159 | if (instruction->HasUses()) { |
| 2160 | locations->SetOut(Location::SameAsFirstInput()); |
| 2161 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 2165 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2166 | codegen_->AddSlowPath(slow_path); |
| 2167 | |
| 2168 | LocationSummary* locations = instruction->GetLocations(); |
| 2169 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2170 | |
| 2171 | if (obj.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2172 | __ cmpl(obj.As<Register>(), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2173 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2174 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2175 | } else { |
| 2176 | DCHECK(obj.IsConstant()) << obj; |
| 2177 | DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0); |
| 2178 | __ jmp(slow_path->GetEntryLabel()); |
| 2179 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2180 | } |
| 2181 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2182 | } |
| 2183 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2184 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2185 | LocationSummary* locations = |
| 2186 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2187 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2188 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2189 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2190 | } |
| 2191 | |
| 2192 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 2193 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2194 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2195 | Location index = locations->InAt(1); |
| 2196 | |
| 2197 | switch (instruction->GetType()) { |
| 2198 | case Primitive::kPrimBoolean: { |
| 2199 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2200 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2201 | if (index.IsConstant()) { |
| 2202 | __ movzxb(out, Address(obj, |
| 2203 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 2204 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2205 | __ movzxb(out, Address(obj, index.As<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2206 | } |
| 2207 | break; |
| 2208 | } |
| 2209 | |
| 2210 | case Primitive::kPrimByte: { |
| 2211 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2212 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2213 | if (index.IsConstant()) { |
| 2214 | __ movsxb(out, Address(obj, |
| 2215 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 2216 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2217 | __ movsxb(out, Address(obj, index.As<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2218 | } |
| 2219 | break; |
| 2220 | } |
| 2221 | |
| 2222 | case Primitive::kPrimShort: { |
| 2223 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2224 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2225 | if (index.IsConstant()) { |
| 2226 | __ movsxw(out, Address(obj, |
| 2227 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 2228 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2229 | __ movsxw(out, Address(obj, index.As<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2230 | } |
| 2231 | break; |
| 2232 | } |
| 2233 | |
| 2234 | case Primitive::kPrimChar: { |
| 2235 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2236 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2237 | if (index.IsConstant()) { |
| 2238 | __ movzxw(out, Address(obj, |
| 2239 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 2240 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2241 | __ movzxw(out, Address(obj, index.As<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2242 | } |
| 2243 | break; |
| 2244 | } |
| 2245 | |
| 2246 | case Primitive::kPrimInt: |
| 2247 | case Primitive::kPrimNot: { |
| 2248 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2249 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2250 | if (index.IsConstant()) { |
| 2251 | __ movl(out, Address(obj, |
| 2252 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 2253 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2254 | __ movl(out, Address(obj, index.As<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2255 | } |
| 2256 | break; |
| 2257 | } |
| 2258 | |
| 2259 | case Primitive::kPrimLong: { |
| 2260 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2261 | Location out = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2262 | if (index.IsConstant()) { |
| 2263 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2264 | __ movl(out.AsRegisterPairLow<Register>(), Address(obj, offset)); |
| 2265 | __ movl(out.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2266 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2267 | __ movl(out.AsRegisterPairLow<Register>(), |
| 2268 | Address(obj, index.As<Register>(), TIMES_8, data_offset)); |
| 2269 | __ movl(out.AsRegisterPairHigh<Register>(), |
| 2270 | Address(obj, index.As<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2271 | } |
| 2272 | break; |
| 2273 | } |
| 2274 | |
| 2275 | case Primitive::kPrimFloat: |
| 2276 | case Primitive::kPrimDouble: |
| 2277 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2278 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2279 | case Primitive::kPrimVoid: |
| 2280 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2281 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2282 | } |
| 2283 | } |
| 2284 | |
| 2285 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2286 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2287 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2288 | instruction, |
| 2289 | value_type == Primitive::kPrimNot ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 2290 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2291 | if (value_type == Primitive::kPrimNot) { |
| 2292 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2293 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2294 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2295 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2296 | } else { |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 2297 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 2298 | || (value_type == Primitive::kPrimByte); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 2299 | // 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] | 2300 | // In case of a byte operation, the register allocator does not support multiple |
| 2301 | // inputs that die at entry with one in a specific register. |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2302 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2303 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 2304 | if (is_byte_type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2305 | // Ensure the value is in a byte register. |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2306 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2307 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2308 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2309 | } |
| 2310 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2311 | } |
| 2312 | |
| 2313 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 2314 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2315 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2316 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2317 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2318 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2319 | |
| 2320 | switch (value_type) { |
| 2321 | case Primitive::kPrimBoolean: |
| 2322 | case Primitive::kPrimByte: { |
| 2323 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2324 | if (index.IsConstant()) { |
| 2325 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2326 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2327 | __ movb(Address(obj, offset), value.As<ByteRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2328 | } else { |
| 2329 | __ movb(Address(obj, offset), |
| 2330 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2331 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2332 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2333 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2334 | __ movb(Address(obj, index.As<Register>(), TIMES_1, data_offset), |
| 2335 | value.As<ByteRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2336 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2337 | __ movb(Address(obj, index.As<Register>(), TIMES_1, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2338 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2339 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2340 | } |
| 2341 | break; |
| 2342 | } |
| 2343 | |
| 2344 | case Primitive::kPrimShort: |
| 2345 | case Primitive::kPrimChar: { |
| 2346 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2347 | if (index.IsConstant()) { |
| 2348 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2349 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2350 | __ movw(Address(obj, offset), value.As<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2351 | } else { |
| 2352 | __ movw(Address(obj, offset), |
| 2353 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2354 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2355 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2356 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2357 | __ movw(Address(obj, index.As<Register>(), TIMES_2, data_offset), |
| 2358 | value.As<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2359 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2360 | __ movw(Address(obj, index.As<Register>(), TIMES_2, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2361 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2362 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2363 | } |
| 2364 | break; |
| 2365 | } |
| 2366 | |
| 2367 | case Primitive::kPrimInt: { |
| 2368 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2369 | if (index.IsConstant()) { |
| 2370 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2371 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2372 | __ movl(Address(obj, offset), value.As<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2373 | } else { |
| 2374 | __ movl(Address(obj, offset), Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2375 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2376 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2377 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2378 | __ movl(Address(obj, index.As<Register>(), TIMES_4, data_offset), |
| 2379 | value.As<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2380 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2381 | __ movl(Address(obj, index.As<Register>(), TIMES_4, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2382 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2383 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2384 | } |
| 2385 | break; |
| 2386 | } |
| 2387 | |
| 2388 | case Primitive::kPrimNot: { |
| 2389 | DCHECK(!codegen_->IsLeafMethod()); |
| 2390 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pAputObject))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2391 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2392 | break; |
| 2393 | } |
| 2394 | |
| 2395 | case Primitive::kPrimLong: { |
| 2396 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2397 | if (index.IsConstant()) { |
| 2398 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2399 | if (value.IsRegisterPair()) { |
| 2400 | __ movl(Address(obj, offset), value.AsRegisterPairLow<Register>()); |
| 2401 | __ movl(Address(obj, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2402 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2403 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2404 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 2405 | __ movl(Address(obj, offset), Immediate(Low32Bits(val))); |
| 2406 | __ movl(Address(obj, offset + kX86WordSize), Immediate(High32Bits(val))); |
| 2407 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2408 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2409 | if (value.IsRegisterPair()) { |
| 2410 | __ movl(Address(obj, index.As<Register>(), TIMES_8, data_offset), |
| 2411 | value.AsRegisterPairLow<Register>()); |
| 2412 | __ movl(Address(obj, index.As<Register>(), TIMES_8, data_offset + kX86WordSize), |
| 2413 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2414 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2415 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2416 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2417 | __ movl(Address(obj, index.As<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2418 | Immediate(Low32Bits(val))); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2419 | __ movl(Address(obj, index.As<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2420 | Immediate(High32Bits(val))); |
| 2421 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2422 | } |
| 2423 | break; |
| 2424 | } |
| 2425 | |
| 2426 | case Primitive::kPrimFloat: |
| 2427 | case Primitive::kPrimDouble: |
| 2428 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2429 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2430 | case Primitive::kPrimVoid: |
| 2431 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2432 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2433 | } |
| 2434 | } |
| 2435 | |
| 2436 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 2437 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2438 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2439 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2440 | instruction->SetLocations(locations); |
| 2441 | } |
| 2442 | |
| 2443 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 2444 | LocationSummary* locations = instruction->GetLocations(); |
| 2445 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2446 | Register obj = locations->InAt(0).As<Register>(); |
| 2447 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2448 | __ movl(out, Address(obj, offset)); |
| 2449 | } |
| 2450 | |
| 2451 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2452 | LocationSummary* locations = |
| 2453 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2454 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2455 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2456 | if (instruction->HasUses()) { |
| 2457 | locations->SetOut(Location::SameAsFirstInput()); |
| 2458 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2459 | } |
| 2460 | |
| 2461 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 2462 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 2463 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathX86( |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2464 | instruction, locations->InAt(0), locations->InAt(1)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2465 | codegen_->AddSlowPath(slow_path); |
| 2466 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2467 | Register index = locations->InAt(0).As<Register>(); |
| 2468 | Register length = locations->InAt(1).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2469 | |
| 2470 | __ cmpl(index, length); |
| 2471 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
| 2472 | } |
| 2473 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2474 | void LocationsBuilderX86::VisitTemporary(HTemporary* temp) { |
| 2475 | temp->SetLocations(nullptr); |
| 2476 | } |
| 2477 | |
| 2478 | void InstructionCodeGeneratorX86::VisitTemporary(HTemporary* temp) { |
| 2479 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2480 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2481 | } |
| 2482 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 2483 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2484 | UNUSED(instruction); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2485 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 2486 | } |
| 2487 | |
| 2488 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2489 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 2490 | } |
| 2491 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2492 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 2493 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 2494 | } |
| 2495 | |
| 2496 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2497 | HBasicBlock* block = instruction->GetBlock(); |
| 2498 | if (block->GetLoopInformation() != nullptr) { |
| 2499 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 2500 | // The back edge will generate the suspend check. |
| 2501 | return; |
| 2502 | } |
| 2503 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 2504 | // The goto will generate the suspend check. |
| 2505 | return; |
| 2506 | } |
| 2507 | GenerateSuspendCheck(instruction, nullptr); |
| 2508 | } |
| 2509 | |
| 2510 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 2511 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2512 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2513 | new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2514 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2515 | __ fs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2516 | Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2517 | if (successor == nullptr) { |
| 2518 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 2519 | __ Bind(slow_path->GetReturnLabel()); |
| 2520 | } else { |
| 2521 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 2522 | __ jmp(slow_path->GetEntryLabel()); |
| 2523 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2524 | } |
| 2525 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2526 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 2527 | return codegen_->GetAssembler(); |
| 2528 | } |
| 2529 | |
| 2530 | void ParallelMoveResolverX86::MoveMemoryToMemory(int dst, int src) { |
| 2531 | ScratchRegisterScope ensure_scratch( |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2532 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2533 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 2534 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, src + stack_offset)); |
| 2535 | __ movl(Address(ESP, dst + stack_offset), static_cast<Register>(ensure_scratch.GetRegister())); |
| 2536 | } |
| 2537 | |
| 2538 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
| 2539 | MoveOperands* move = moves_.Get(index); |
| 2540 | Location source = move->GetSource(); |
| 2541 | Location destination = move->GetDestination(); |
| 2542 | |
| 2543 | if (source.IsRegister()) { |
| 2544 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2545 | __ movl(destination.As<Register>(), source.As<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2546 | } else { |
| 2547 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2548 | __ movl(Address(ESP, destination.GetStackIndex()), source.As<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2549 | } |
| 2550 | } else if (source.IsStackSlot()) { |
| 2551 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2552 | __ movl(destination.As<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2553 | } else { |
| 2554 | DCHECK(destination.IsStackSlot()); |
| 2555 | MoveMemoryToMemory(destination.GetStackIndex(), |
| 2556 | source.GetStackIndex()); |
| 2557 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2558 | } else if (source.IsConstant()) { |
| 2559 | HIntConstant* instruction = source.GetConstant()->AsIntConstant(); |
| 2560 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
| 2561 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2562 | __ movl(destination.As<Register>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2563 | } else { |
| 2564 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 2565 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2566 | } else { |
| 2567 | LOG(FATAL) << "Unimplemented"; |
| 2568 | } |
| 2569 | } |
| 2570 | |
| 2571 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2572 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 2573 | ScratchRegisterScope ensure_scratch( |
| 2574 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 2575 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2576 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 2577 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 2578 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 2579 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
| 2580 | } |
| 2581 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2582 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
| 2583 | ScratchRegisterScope ensure_scratch1( |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2584 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 2585 | |
| 2586 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2587 | ScratchRegisterScope ensure_scratch2( |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2588 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 2589 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2590 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 2591 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 2592 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 2593 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 2594 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 2595 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
| 2596 | } |
| 2597 | |
| 2598 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
| 2599 | MoveOperands* move = moves_.Get(index); |
| 2600 | Location source = move->GetSource(); |
| 2601 | Location destination = move->GetDestination(); |
| 2602 | |
| 2603 | if (source.IsRegister() && destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2604 | __ xchgl(destination.As<Register>(), source.As<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2605 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2606 | Exchange(source.As<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2607 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2608 | Exchange(destination.As<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2609 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 2610 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 2611 | } else { |
| 2612 | LOG(FATAL) << "Unimplemented"; |
| 2613 | } |
| 2614 | } |
| 2615 | |
| 2616 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 2617 | __ pushl(static_cast<Register>(reg)); |
| 2618 | } |
| 2619 | |
| 2620 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 2621 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 2622 | } |
| 2623 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2624 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2625 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() |
| 2626 | ? LocationSummary::kCallOnSlowPath |
| 2627 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2628 | LocationSummary* locations = |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2629 | new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2630 | locations->SetOut(Location::RequiresRegister()); |
| 2631 | } |
| 2632 | |
| 2633 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
| 2634 | Register out = cls->GetLocations()->Out().As<Register>(); |
| 2635 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2636 | DCHECK(!cls->CanCallRuntime()); |
| 2637 | DCHECK(!cls->MustGenerateClinitCheck()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2638 | codegen_->LoadCurrentMethod(out); |
| 2639 | __ movl(out, Address(out, mirror::ArtMethod::DeclaringClassOffset().Int32Value())); |
| 2640 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2641 | DCHECK(cls->CanCallRuntime()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2642 | codegen_->LoadCurrentMethod(out); |
| 2643 | __ movl(out, Address(out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value())); |
| 2644 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2645 | |
| 2646 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 2647 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 2648 | codegen_->AddSlowPath(slow_path); |
| 2649 | __ testl(out, out); |
| 2650 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2651 | if (cls->MustGenerateClinitCheck()) { |
| 2652 | GenerateClassInitializationCheck(slow_path, out); |
| 2653 | } else { |
| 2654 | __ Bind(slow_path->GetExitLabel()); |
| 2655 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2656 | } |
| 2657 | } |
| 2658 | |
| 2659 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 2660 | LocationSummary* locations = |
| 2661 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 2662 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2663 | if (check->HasUses()) { |
| 2664 | locations->SetOut(Location::SameAsFirstInput()); |
| 2665 | } |
| 2666 | } |
| 2667 | |
| 2668 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2669 | // We assume the class to not be null. |
| 2670 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 2671 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2672 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2673 | GenerateClassInitializationCheck(slow_path, check->GetLocations()->InAt(0).As<Register>()); |
| 2674 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2675 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2676 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
| 2677 | SlowPathCodeX86* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2678 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 2679 | Immediate(mirror::Class::kStatusInitialized)); |
| 2680 | __ j(kLess, slow_path->GetEntryLabel()); |
| 2681 | __ Bind(slow_path->GetExitLabel()); |
| 2682 | // No need for memory fence, thanks to the X86 memory model. |
| 2683 | } |
| 2684 | |
| 2685 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 2686 | LocationSummary* locations = |
| 2687 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2688 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2689 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2690 | } |
| 2691 | |
| 2692 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 2693 | LocationSummary* locations = instruction->GetLocations(); |
| 2694 | Register cls = locations->InAt(0).As<Register>(); |
| 2695 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
| 2696 | |
| 2697 | switch (instruction->GetType()) { |
| 2698 | case Primitive::kPrimBoolean: { |
| 2699 | Register out = locations->Out().As<Register>(); |
| 2700 | __ movzxb(out, Address(cls, offset)); |
| 2701 | break; |
| 2702 | } |
| 2703 | |
| 2704 | case Primitive::kPrimByte: { |
| 2705 | Register out = locations->Out().As<Register>(); |
| 2706 | __ movsxb(out, Address(cls, offset)); |
| 2707 | break; |
| 2708 | } |
| 2709 | |
| 2710 | case Primitive::kPrimShort: { |
| 2711 | Register out = locations->Out().As<Register>(); |
| 2712 | __ movsxw(out, Address(cls, offset)); |
| 2713 | break; |
| 2714 | } |
| 2715 | |
| 2716 | case Primitive::kPrimChar: { |
| 2717 | Register out = locations->Out().As<Register>(); |
| 2718 | __ movzxw(out, Address(cls, offset)); |
| 2719 | break; |
| 2720 | } |
| 2721 | |
| 2722 | case Primitive::kPrimInt: |
| 2723 | case Primitive::kPrimNot: { |
| 2724 | Register out = locations->Out().As<Register>(); |
| 2725 | __ movl(out, Address(cls, offset)); |
| 2726 | break; |
| 2727 | } |
| 2728 | |
| 2729 | case Primitive::kPrimLong: { |
| 2730 | // TODO: support volatile. |
| 2731 | __ movl(locations->Out().AsRegisterPairLow<Register>(), Address(cls, offset)); |
| 2732 | __ movl(locations->Out().AsRegisterPairHigh<Register>(), Address(cls, kX86WordSize + offset)); |
| 2733 | break; |
| 2734 | } |
| 2735 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2736 | case Primitive::kPrimFloat: { |
| 2737 | XmmRegister out = locations->Out().As<XmmRegister>(); |
| 2738 | __ movss(out, Address(cls, offset)); |
| 2739 | break; |
| 2740 | } |
| 2741 | |
| 2742 | case Primitive::kPrimDouble: { |
| 2743 | XmmRegister out = locations->Out().As<XmmRegister>(); |
| 2744 | __ movsd(out, Address(cls, offset)); |
| 2745 | break; |
| 2746 | } |
| 2747 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2748 | case Primitive::kPrimVoid: |
| 2749 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2750 | UNREACHABLE(); |
| 2751 | } |
| 2752 | } |
| 2753 | |
| 2754 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 2755 | LocationSummary* locations = |
| 2756 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2757 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2758 | Primitive::Type field_type = instruction->GetFieldType(); |
| 2759 | bool is_object_type = field_type == Primitive::kPrimNot; |
| 2760 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 2761 | || (field_type == Primitive::kPrimByte); |
| 2762 | // The register allocator does not support multiple |
| 2763 | // inputs that die at entry with one in a specific register. |
| 2764 | if (is_byte_type) { |
| 2765 | // Ensure the value is in a byte register. |
| 2766 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
| 2767 | } else { |
| 2768 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2769 | } |
| 2770 | // Temporary registers for the write barrier. |
| 2771 | if (is_object_type) { |
| 2772 | locations->AddTemp(Location::RequiresRegister()); |
| 2773 | // Ensure the card is in a byte register. |
| 2774 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 2775 | } |
| 2776 | } |
| 2777 | |
| 2778 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 2779 | LocationSummary* locations = instruction->GetLocations(); |
| 2780 | Register cls = locations->InAt(0).As<Register>(); |
| 2781 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
| 2782 | Primitive::Type field_type = instruction->GetFieldType(); |
| 2783 | |
| 2784 | switch (field_type) { |
| 2785 | case Primitive::kPrimBoolean: |
| 2786 | case Primitive::kPrimByte: { |
| 2787 | ByteRegister value = locations->InAt(1).As<ByteRegister>(); |
| 2788 | __ movb(Address(cls, offset), value); |
| 2789 | break; |
| 2790 | } |
| 2791 | |
| 2792 | case Primitive::kPrimShort: |
| 2793 | case Primitive::kPrimChar: { |
| 2794 | Register value = locations->InAt(1).As<Register>(); |
| 2795 | __ movw(Address(cls, offset), value); |
| 2796 | break; |
| 2797 | } |
| 2798 | |
| 2799 | case Primitive::kPrimInt: |
| 2800 | case Primitive::kPrimNot: { |
| 2801 | Register value = locations->InAt(1).As<Register>(); |
| 2802 | __ movl(Address(cls, offset), value); |
| 2803 | |
| 2804 | if (field_type == Primitive::kPrimNot) { |
| 2805 | Register temp = locations->GetTemp(0).As<Register>(); |
| 2806 | Register card = locations->GetTemp(1).As<Register>(); |
| 2807 | codegen_->MarkGCCard(temp, card, cls, value); |
| 2808 | } |
| 2809 | break; |
| 2810 | } |
| 2811 | |
| 2812 | case Primitive::kPrimLong: { |
| 2813 | Location value = locations->InAt(1); |
| 2814 | __ movl(Address(cls, offset), value.AsRegisterPairLow<Register>()); |
| 2815 | __ movl(Address(cls, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 2816 | break; |
| 2817 | } |
| 2818 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2819 | case Primitive::kPrimFloat: { |
| 2820 | XmmRegister value = locations->InAt(1).As<XmmRegister>(); |
| 2821 | __ movss(Address(cls, offset), value); |
| 2822 | break; |
| 2823 | } |
| 2824 | |
| 2825 | case Primitive::kPrimDouble: { |
| 2826 | XmmRegister value = locations->InAt(1).As<XmmRegister>(); |
| 2827 | __ movsd(Address(cls, offset), value); |
| 2828 | break; |
| 2829 | } |
| 2830 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2831 | case Primitive::kPrimVoid: |
| 2832 | LOG(FATAL) << "Unreachable type " << field_type; |
| 2833 | UNREACHABLE(); |
| 2834 | } |
| 2835 | } |
| 2836 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 2837 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
| 2838 | LocationSummary* locations = |
| 2839 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
| 2840 | locations->SetOut(Location::RequiresRegister()); |
| 2841 | } |
| 2842 | |
| 2843 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
| 2844 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 2845 | codegen_->AddSlowPath(slow_path); |
| 2846 | |
| 2847 | Register out = load->GetLocations()->Out().As<Register>(); |
| 2848 | codegen_->LoadCurrentMethod(out); |
| 2849 | __ movl(out, Address(out, mirror::ArtMethod::DexCacheStringsOffset().Int32Value())); |
| 2850 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
| 2851 | __ testl(out, out); |
| 2852 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2853 | __ Bind(slow_path->GetExitLabel()); |
| 2854 | } |
| 2855 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2856 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 2857 | LocationSummary* locations = |
| 2858 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 2859 | locations->SetOut(Location::RequiresRegister()); |
| 2860 | } |
| 2861 | |
| 2862 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
| 2863 | Address address = Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); |
| 2864 | __ fs()->movl(load->GetLocations()->Out().As<Register>(), address); |
| 2865 | __ fs()->movl(address, Immediate(0)); |
| 2866 | } |
| 2867 | |
| 2868 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 2869 | LocationSummary* locations = |
| 2870 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 2871 | InvokeRuntimeCallingConvention calling_convention; |
| 2872 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2873 | } |
| 2874 | |
| 2875 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
| 2876 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pDeliverException))); |
| 2877 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 2878 | } |
| 2879 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 2880 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2881 | LocationSummary::CallKind call_kind = instruction->IsClassFinal() |
| 2882 | ? LocationSummary::kNoCall |
| 2883 | : LocationSummary::kCallOnSlowPath; |
| 2884 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 2885 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2886 | locations->SetInAt(1, Location::Any()); |
| 2887 | locations->SetOut(Location::RequiresRegister()); |
| 2888 | } |
| 2889 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 2890 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2891 | LocationSummary* locations = instruction->GetLocations(); |
| 2892 | Register obj = locations->InAt(0).As<Register>(); |
| 2893 | Location cls = locations->InAt(1); |
| 2894 | Register out = locations->Out().As<Register>(); |
| 2895 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2896 | Label done, zero; |
| 2897 | SlowPathCodeX86* slow_path = nullptr; |
| 2898 | |
| 2899 | // Return 0 if `obj` is null. |
| 2900 | // TODO: avoid this check if we know obj is not null. |
| 2901 | __ testl(obj, obj); |
| 2902 | __ j(kEqual, &zero); |
| 2903 | __ movl(out, Address(obj, class_offset)); |
| 2904 | // Compare the class of `obj` with `cls`. |
| 2905 | if (cls.IsRegister()) { |
| 2906 | __ cmpl(out, cls.As<Register>()); |
| 2907 | } else { |
| 2908 | DCHECK(cls.IsStackSlot()) << cls; |
| 2909 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 2910 | } |
| 2911 | |
| 2912 | if (instruction->IsClassFinal()) { |
| 2913 | // Classes must be equal for the instanceof to succeed. |
| 2914 | __ j(kNotEqual, &zero); |
| 2915 | __ movl(out, Immediate(1)); |
| 2916 | __ jmp(&done); |
| 2917 | } else { |
| 2918 | // If the classes are not equal, we go into a slow path. |
| 2919 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 2920 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86( |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 2921 | instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2922 | codegen_->AddSlowPath(slow_path); |
| 2923 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 2924 | __ movl(out, Immediate(1)); |
| 2925 | __ jmp(&done); |
| 2926 | } |
| 2927 | __ Bind(&zero); |
| 2928 | __ movl(out, Immediate(0)); |
| 2929 | if (slow_path != nullptr) { |
| 2930 | __ Bind(slow_path->GetExitLabel()); |
| 2931 | } |
| 2932 | __ Bind(&done); |
| 2933 | } |
| 2934 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 2935 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
| 2936 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2937 | instruction, LocationSummary::kCallOnSlowPath); |
| 2938 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2939 | locations->SetInAt(1, Location::Any()); |
| 2940 | locations->AddTemp(Location::RequiresRegister()); |
| 2941 | } |
| 2942 | |
| 2943 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
| 2944 | LocationSummary* locations = instruction->GetLocations(); |
| 2945 | Register obj = locations->InAt(0).As<Register>(); |
| 2946 | Location cls = locations->InAt(1); |
| 2947 | Register temp = locations->GetTemp(0).As<Register>(); |
| 2948 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2949 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86( |
| 2950 | instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc()); |
| 2951 | codegen_->AddSlowPath(slow_path); |
| 2952 | |
| 2953 | // TODO: avoid this check if we know obj is not null. |
| 2954 | __ testl(obj, obj); |
| 2955 | __ j(kEqual, slow_path->GetExitLabel()); |
| 2956 | __ movl(temp, Address(obj, class_offset)); |
| 2957 | |
| 2958 | // Compare the class of `obj` with `cls`. |
| 2959 | if (cls.IsRegister()) { |
| 2960 | __ cmpl(temp, cls.As<Register>()); |
| 2961 | } else { |
| 2962 | DCHECK(cls.IsStackSlot()) << cls; |
| 2963 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 2964 | } |
| 2965 | |
| 2966 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 2967 | __ Bind(slow_path->GetExitLabel()); |
| 2968 | } |
| 2969 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 2970 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 2971 | LocationSummary* locations = |
| 2972 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 2973 | InvokeRuntimeCallingConvention calling_convention; |
| 2974 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2975 | } |
| 2976 | |
| 2977 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 2978 | __ fs()->call(Address::Absolute(instruction->IsEnter() |
| 2979 | ? QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pLockObject) |
| 2980 | : QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pUnlockObject))); |
| 2981 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 2982 | } |
| 2983 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2984 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 2985 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 2986 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 2987 | |
| 2988 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 2989 | LocationSummary* locations = |
| 2990 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2991 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 2992 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 2993 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2994 | locations->SetInAt(1, Location::Any()); |
| 2995 | locations->SetOut(Location::SameAsFirstInput()); |
| 2996 | } |
| 2997 | |
| 2998 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 2999 | HandleBitwiseOperation(instruction); |
| 3000 | } |
| 3001 | |
| 3002 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 3003 | HandleBitwiseOperation(instruction); |
| 3004 | } |
| 3005 | |
| 3006 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 3007 | HandleBitwiseOperation(instruction); |
| 3008 | } |
| 3009 | |
| 3010 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 3011 | LocationSummary* locations = instruction->GetLocations(); |
| 3012 | Location first = locations->InAt(0); |
| 3013 | Location second = locations->InAt(1); |
| 3014 | DCHECK(first.Equals(locations->Out())); |
| 3015 | |
| 3016 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 3017 | if (second.IsRegister()) { |
| 3018 | if (instruction->IsAnd()) { |
| 3019 | __ andl(first.As<Register>(), second.As<Register>()); |
| 3020 | } else if (instruction->IsOr()) { |
| 3021 | __ orl(first.As<Register>(), second.As<Register>()); |
| 3022 | } else { |
| 3023 | DCHECK(instruction->IsXor()); |
| 3024 | __ xorl(first.As<Register>(), second.As<Register>()); |
| 3025 | } |
| 3026 | } else if (second.IsConstant()) { |
| 3027 | if (instruction->IsAnd()) { |
| 3028 | __ andl(first.As<Register>(), Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 3029 | } else if (instruction->IsOr()) { |
| 3030 | __ orl(first.As<Register>(), Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 3031 | } else { |
| 3032 | DCHECK(instruction->IsXor()); |
| 3033 | __ xorl(first.As<Register>(), Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 3034 | } |
| 3035 | } else { |
| 3036 | if (instruction->IsAnd()) { |
| 3037 | __ andl(first.As<Register>(), Address(ESP, second.GetStackIndex())); |
| 3038 | } else if (instruction->IsOr()) { |
| 3039 | __ orl(first.As<Register>(), Address(ESP, second.GetStackIndex())); |
| 3040 | } else { |
| 3041 | DCHECK(instruction->IsXor()); |
| 3042 | __ xorl(first.As<Register>(), Address(ESP, second.GetStackIndex())); |
| 3043 | } |
| 3044 | } |
| 3045 | } else { |
| 3046 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3047 | if (second.IsRegisterPair()) { |
| 3048 | if (instruction->IsAnd()) { |
| 3049 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3050 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 3051 | } else if (instruction->IsOr()) { |
| 3052 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3053 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 3054 | } else { |
| 3055 | DCHECK(instruction->IsXor()); |
| 3056 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3057 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 3058 | } |
| 3059 | } else { |
| 3060 | if (instruction->IsAnd()) { |
| 3061 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 3062 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 3063 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 3064 | } else if (instruction->IsOr()) { |
| 3065 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 3066 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 3067 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 3068 | } else { |
| 3069 | DCHECK(instruction->IsXor()); |
| 3070 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 3071 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 3072 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 3073 | } |
| 3074 | } |
| 3075 | } |
| 3076 | } |
| 3077 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 3078 | } // namespace x86 |
| 3079 | } // namespace art |