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