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