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