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)() |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1123 | __ call(Address( |
| 1124 | temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1125 | |
| 1126 | DCHECK(!codegen_->IsLeafMethod()); |
| 1127 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1128 | } |
| 1129 | |
| 1130 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 1131 | HandleInvoke(invoke); |
| 1132 | } |
| 1133 | |
| 1134 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1135 | LocationSummary* locations = |
| 1136 | new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1137 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1138 | |
| 1139 | InvokeDexCallingConventionVisitor calling_convention_visitor; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1140 | for (size_t i = 0; i < invoke->InputCount(); i++) { |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1141 | HInstruction* input = invoke->InputAt(i); |
| 1142 | locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType())); |
| 1143 | } |
| 1144 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1145 | switch (invoke->GetType()) { |
| 1146 | case Primitive::kPrimBoolean: |
| 1147 | case Primitive::kPrimByte: |
| 1148 | case Primitive::kPrimChar: |
| 1149 | case Primitive::kPrimShort: |
| 1150 | case Primitive::kPrimInt: |
| 1151 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1152 | locations->SetOut(Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1153 | break; |
| 1154 | |
| 1155 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1156 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1157 | break; |
| 1158 | |
| 1159 | case Primitive::kPrimVoid: |
| 1160 | break; |
| 1161 | |
| 1162 | case Primitive::kPrimDouble: |
| 1163 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1164 | locations->SetOut(Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1165 | break; |
| 1166 | } |
| 1167 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1168 | invoke->SetLocations(locations); |
| 1169 | } |
| 1170 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1171 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1172 | Register temp = invoke->GetLocations()->GetTemp(0).As<Register>(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1173 | uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() + |
| 1174 | invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry); |
| 1175 | LocationSummary* locations = invoke->GetLocations(); |
| 1176 | Location receiver = locations->InAt(0); |
| 1177 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1178 | // temp = object->GetClass(); |
| 1179 | if (receiver.IsStackSlot()) { |
| 1180 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
| 1181 | __ movl(temp, Address(temp, class_offset)); |
| 1182 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1183 | __ movl(temp, Address(receiver.As<Register>(), class_offset)); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1184 | } |
| 1185 | // temp = temp->GetMethodAt(method_offset); |
| 1186 | __ movl(temp, Address(temp, method_offset)); |
| 1187 | // call temp->GetEntryPoint(); |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1188 | __ call(Address( |
| 1189 | temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1190 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1191 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1192 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1193 | } |
| 1194 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1195 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1196 | HandleInvoke(invoke); |
| 1197 | // Add the hidden argument. |
| 1198 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM0)); |
| 1199 | } |
| 1200 | |
| 1201 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1202 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 1203 | Register temp = invoke->GetLocations()->GetTemp(0).As<Register>(); |
| 1204 | uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() + |
| 1205 | (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry); |
| 1206 | LocationSummary* locations = invoke->GetLocations(); |
| 1207 | Location receiver = locations->InAt(0); |
| 1208 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1209 | |
| 1210 | // Set the hidden argument. |
| 1211 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
| 1212 | __ movd(invoke->GetLocations()->GetTemp(1).As<XmmRegister>(), temp); |
| 1213 | |
| 1214 | // temp = object->GetClass(); |
| 1215 | if (receiver.IsStackSlot()) { |
| 1216 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
| 1217 | __ movl(temp, Address(temp, class_offset)); |
| 1218 | } else { |
| 1219 | __ movl(temp, Address(receiver.As<Register>(), class_offset)); |
| 1220 | } |
| 1221 | // temp = temp->GetImtEntryAt(method_offset); |
| 1222 | __ movl(temp, Address(temp, method_offset)); |
| 1223 | // call temp->GetEntryPoint(); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 1224 | __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1225 | kX86WordSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1226 | |
| 1227 | DCHECK(!codegen_->IsLeafMethod()); |
| 1228 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1229 | } |
| 1230 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1231 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 1232 | LocationSummary* locations = |
| 1233 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1234 | switch (neg->GetResultType()) { |
| 1235 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1236 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1237 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1238 | locations->SetOut(Location::SameAsFirstInput()); |
| 1239 | break; |
| 1240 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1241 | case Primitive::kPrimFloat: |
| 1242 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1243 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1244 | // Output overlaps as we need a fresh (zero-initialized) |
| 1245 | // register to perform subtraction from zero. |
| 1246 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1247 | break; |
| 1248 | |
| 1249 | default: |
| 1250 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1251 | } |
| 1252 | } |
| 1253 | |
| 1254 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 1255 | LocationSummary* locations = neg->GetLocations(); |
| 1256 | Location out = locations->Out(); |
| 1257 | Location in = locations->InAt(0); |
| 1258 | switch (neg->GetResultType()) { |
| 1259 | case Primitive::kPrimInt: |
| 1260 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1261 | DCHECK(in.Equals(out)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1262 | __ negl(out.As<Register>()); |
| 1263 | break; |
| 1264 | |
| 1265 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1266 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1267 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1268 | __ negl(out.AsRegisterPairLow<Register>()); |
| 1269 | // Negation is similar to subtraction from zero. The least |
| 1270 | // significant byte triggers a borrow when it is different from |
| 1271 | // zero; to take it into account, add 1 to the most significant |
| 1272 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 1273 | // operation. |
| 1274 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 1275 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 1276 | break; |
| 1277 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1278 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1279 | DCHECK(!in.Equals(out)); |
| 1280 | // out = 0 |
| 1281 | __ xorps(out.As<XmmRegister>(), out.As<XmmRegister>()); |
| 1282 | // out = out - in |
| 1283 | __ subss(out.As<XmmRegister>(), in.As<XmmRegister>()); |
| 1284 | break; |
| 1285 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1286 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1287 | DCHECK(!in.Equals(out)); |
| 1288 | // out = 0 |
| 1289 | __ xorpd(out.As<XmmRegister>(), out.As<XmmRegister>()); |
| 1290 | // out = out - in |
| 1291 | __ subsd(out.As<XmmRegister>(), in.As<XmmRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1292 | break; |
| 1293 | |
| 1294 | default: |
| 1295 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1296 | } |
| 1297 | } |
| 1298 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1299 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 1300 | LocationSummary* locations = |
| 1301 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 1302 | Primitive::Type result_type = conversion->GetResultType(); |
| 1303 | Primitive::Type input_type = conversion->GetInputType(); |
| 1304 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1305 | case Primitive::kPrimByte: |
| 1306 | switch (input_type) { |
| 1307 | case Primitive::kPrimShort: |
| 1308 | case Primitive::kPrimInt: |
| 1309 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1310 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1311 | locations->SetInAt(0, Location::Any()); |
| 1312 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1313 | break; |
| 1314 | |
| 1315 | default: |
| 1316 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1317 | << " to " << result_type; |
| 1318 | } |
| 1319 | break; |
| 1320 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1321 | case Primitive::kPrimShort: |
| 1322 | switch (input_type) { |
| 1323 | case Primitive::kPrimByte: |
| 1324 | case Primitive::kPrimInt: |
| 1325 | case Primitive::kPrimChar: |
| 1326 | // Processing a Dex `int-to-short' instruction. |
| 1327 | locations->SetInAt(0, Location::Any()); |
| 1328 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1329 | break; |
| 1330 | |
| 1331 | default: |
| 1332 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1333 | << " to " << result_type; |
| 1334 | } |
| 1335 | break; |
| 1336 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1337 | case Primitive::kPrimInt: |
| 1338 | switch (input_type) { |
| 1339 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1340 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1341 | locations->SetInAt(0, Location::Any()); |
| 1342 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1343 | break; |
| 1344 | |
| 1345 | case Primitive::kPrimFloat: |
| 1346 | case Primitive::kPrimDouble: |
| 1347 | LOG(FATAL) << "Type conversion from " << input_type |
| 1348 | << " to " << result_type << " not yet implemented"; |
| 1349 | break; |
| 1350 | |
| 1351 | default: |
| 1352 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1353 | << " to " << result_type; |
| 1354 | } |
| 1355 | break; |
| 1356 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1357 | case Primitive::kPrimLong: |
| 1358 | switch (input_type) { |
| 1359 | case Primitive::kPrimByte: |
| 1360 | case Primitive::kPrimShort: |
| 1361 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1362 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1363 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1364 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 1365 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 1366 | break; |
| 1367 | |
| 1368 | case Primitive::kPrimFloat: |
| 1369 | case Primitive::kPrimDouble: |
| 1370 | LOG(FATAL) << "Type conversion from " << input_type << " to " |
| 1371 | << result_type << " not yet implemented"; |
| 1372 | break; |
| 1373 | |
| 1374 | default: |
| 1375 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1376 | << " to " << result_type; |
| 1377 | } |
| 1378 | break; |
| 1379 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1380 | case Primitive::kPrimChar: |
| 1381 | switch (input_type) { |
| 1382 | case Primitive::kPrimByte: |
| 1383 | case Primitive::kPrimShort: |
| 1384 | case Primitive::kPrimInt: |
| 1385 | case Primitive::kPrimChar: |
| 1386 | // Processing a Dex `int-to-char' instruction. |
| 1387 | locations->SetInAt(0, Location::Any()); |
| 1388 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1389 | break; |
| 1390 | |
| 1391 | default: |
| 1392 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1393 | << " to " << result_type; |
| 1394 | } |
| 1395 | break; |
| 1396 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1397 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1398 | switch (input_type) { |
| 1399 | case Primitive::kPrimByte: |
| 1400 | case Primitive::kPrimShort: |
| 1401 | case Primitive::kPrimInt: |
| 1402 | case Primitive::kPrimChar: |
| 1403 | // Processing a Dex `int-to-float' instruction. |
| 1404 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1405 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1406 | break; |
| 1407 | |
| 1408 | case Primitive::kPrimLong: |
| 1409 | case Primitive::kPrimDouble: |
| 1410 | LOG(FATAL) << "Type conversion from " << input_type |
| 1411 | << " to " << result_type << " not yet implemented"; |
| 1412 | break; |
| 1413 | |
| 1414 | default: |
| 1415 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1416 | << " to " << result_type; |
| 1417 | }; |
| 1418 | break; |
| 1419 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1420 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1421 | switch (input_type) { |
| 1422 | case Primitive::kPrimByte: |
| 1423 | case Primitive::kPrimShort: |
| 1424 | case Primitive::kPrimInt: |
| 1425 | case Primitive::kPrimChar: |
| 1426 | // Processing a Dex `int-to-double' instruction. |
| 1427 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1428 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1429 | break; |
| 1430 | |
| 1431 | case Primitive::kPrimLong: |
| 1432 | case Primitive::kPrimFloat: |
| 1433 | LOG(FATAL) << "Type conversion from " << input_type |
| 1434 | << " to " << result_type << " not yet implemented"; |
| 1435 | break; |
| 1436 | |
| 1437 | default: |
| 1438 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1439 | << " to " << result_type; |
| 1440 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1441 | break; |
| 1442 | |
| 1443 | default: |
| 1444 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1445 | << " to " << result_type; |
| 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 1450 | LocationSummary* locations = conversion->GetLocations(); |
| 1451 | Location out = locations->Out(); |
| 1452 | Location in = locations->InAt(0); |
| 1453 | Primitive::Type result_type = conversion->GetResultType(); |
| 1454 | Primitive::Type input_type = conversion->GetInputType(); |
| 1455 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1456 | case Primitive::kPrimByte: |
| 1457 | switch (input_type) { |
| 1458 | case Primitive::kPrimShort: |
| 1459 | case Primitive::kPrimInt: |
| 1460 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1461 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1462 | if (in.IsRegister()) { |
| 1463 | __ movsxb(out.As<Register>(), in.As<ByteRegister>()); |
| 1464 | } else if (in.IsStackSlot()) { |
| 1465 | __ movsxb(out.As<Register>(), Address(ESP, in.GetStackIndex())); |
| 1466 | } else { |
| 1467 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 1468 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 1469 | __ movl(out.As<Register>(), Immediate(static_cast<int8_t>(value))); |
| 1470 | } |
| 1471 | break; |
| 1472 | |
| 1473 | default: |
| 1474 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1475 | << " to " << result_type; |
| 1476 | } |
| 1477 | break; |
| 1478 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1479 | case Primitive::kPrimShort: |
| 1480 | switch (input_type) { |
| 1481 | case Primitive::kPrimByte: |
| 1482 | case Primitive::kPrimInt: |
| 1483 | case Primitive::kPrimChar: |
| 1484 | // Processing a Dex `int-to-short' instruction. |
| 1485 | if (in.IsRegister()) { |
| 1486 | __ movsxw(out.As<Register>(), in.As<Register>()); |
| 1487 | } else if (in.IsStackSlot()) { |
| 1488 | __ movsxw(out.As<Register>(), Address(ESP, in.GetStackIndex())); |
| 1489 | } else { |
| 1490 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 1491 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 1492 | __ movl(out.As<Register>(), Immediate(static_cast<int16_t>(value))); |
| 1493 | } |
| 1494 | break; |
| 1495 | |
| 1496 | default: |
| 1497 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1498 | << " to " << result_type; |
| 1499 | } |
| 1500 | break; |
| 1501 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1502 | case Primitive::kPrimInt: |
| 1503 | switch (input_type) { |
| 1504 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1505 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1506 | if (in.IsRegisterPair()) { |
| 1507 | __ movl(out.As<Register>(), in.AsRegisterPairLow<Register>()); |
| 1508 | } else if (in.IsDoubleStackSlot()) { |
| 1509 | __ movl(out.As<Register>(), Address(ESP, in.GetStackIndex())); |
| 1510 | } else { |
| 1511 | DCHECK(in.IsConstant()); |
| 1512 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 1513 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 1514 | __ movl(out.As<Register>(), Immediate(static_cast<int32_t>(value))); |
| 1515 | } |
| 1516 | break; |
| 1517 | |
| 1518 | case Primitive::kPrimFloat: |
| 1519 | case Primitive::kPrimDouble: |
| 1520 | LOG(FATAL) << "Type conversion from " << input_type |
| 1521 | << " to " << result_type << " not yet implemented"; |
| 1522 | break; |
| 1523 | |
| 1524 | default: |
| 1525 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1526 | << " to " << result_type; |
| 1527 | } |
| 1528 | break; |
| 1529 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1530 | case Primitive::kPrimLong: |
| 1531 | switch (input_type) { |
| 1532 | case Primitive::kPrimByte: |
| 1533 | case Primitive::kPrimShort: |
| 1534 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1535 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1536 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1537 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 1538 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
| 1539 | DCHECK_EQ(in.As<Register>(), EAX); |
| 1540 | __ cdq(); |
| 1541 | break; |
| 1542 | |
| 1543 | case Primitive::kPrimFloat: |
| 1544 | case Primitive::kPrimDouble: |
| 1545 | LOG(FATAL) << "Type conversion from " << input_type << " to " |
| 1546 | << result_type << " not yet implemented"; |
| 1547 | break; |
| 1548 | |
| 1549 | default: |
| 1550 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1551 | << " to " << result_type; |
| 1552 | } |
| 1553 | break; |
| 1554 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1555 | case Primitive::kPrimChar: |
| 1556 | switch (input_type) { |
| 1557 | case Primitive::kPrimByte: |
| 1558 | case Primitive::kPrimShort: |
| 1559 | case Primitive::kPrimInt: |
| 1560 | case Primitive::kPrimChar: |
| 1561 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 1562 | if (in.IsRegister()) { |
| 1563 | __ movzxw(out.As<Register>(), in.As<Register>()); |
| 1564 | } else if (in.IsStackSlot()) { |
| 1565 | __ movzxw(out.As<Register>(), Address(ESP, in.GetStackIndex())); |
| 1566 | } else { |
| 1567 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 1568 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 1569 | __ movl(out.As<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 1570 | } |
| 1571 | break; |
| 1572 | |
| 1573 | default: |
| 1574 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1575 | << " to " << result_type; |
| 1576 | } |
| 1577 | break; |
| 1578 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1579 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1580 | switch (input_type) { |
| 1581 | // Processing a Dex `int-to-float' instruction. |
| 1582 | case Primitive::kPrimByte: |
| 1583 | case Primitive::kPrimShort: |
| 1584 | case Primitive::kPrimInt: |
| 1585 | case Primitive::kPrimChar: |
| 1586 | __ cvtsi2ss(out.As<XmmRegister>(), in.As<Register>()); |
| 1587 | break; |
| 1588 | |
| 1589 | case Primitive::kPrimLong: |
| 1590 | case Primitive::kPrimDouble: |
| 1591 | LOG(FATAL) << "Type conversion from " << input_type |
| 1592 | << " to " << result_type << " not yet implemented"; |
| 1593 | break; |
| 1594 | |
| 1595 | default: |
| 1596 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1597 | << " to " << result_type; |
| 1598 | }; |
| 1599 | break; |
| 1600 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1601 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1602 | switch (input_type) { |
| 1603 | // Processing a Dex `int-to-double' instruction. |
| 1604 | case Primitive::kPrimByte: |
| 1605 | case Primitive::kPrimShort: |
| 1606 | case Primitive::kPrimInt: |
| 1607 | case Primitive::kPrimChar: |
| 1608 | __ cvtsi2sd(out.As<XmmRegister>(), in.As<Register>()); |
| 1609 | break; |
| 1610 | |
| 1611 | case Primitive::kPrimLong: |
| 1612 | case Primitive::kPrimFloat: |
| 1613 | LOG(FATAL) << "Type conversion from " << input_type |
| 1614 | << " to " << result_type << " not yet implemented"; |
| 1615 | break; |
| 1616 | |
| 1617 | default: |
| 1618 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1619 | << " to " << result_type; |
| 1620 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1621 | break; |
| 1622 | |
| 1623 | default: |
| 1624 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1625 | << " to " << result_type; |
| 1626 | } |
| 1627 | } |
| 1628 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1629 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1630 | LocationSummary* locations = |
| 1631 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1632 | switch (add->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1633 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1634 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1635 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1636 | locations->SetInAt(1, Location::Any()); |
| 1637 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1638 | break; |
| 1639 | } |
| 1640 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1641 | case Primitive::kPrimFloat: |
| 1642 | case Primitive::kPrimDouble: { |
| 1643 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1644 | locations->SetInAt(1, Location::Any()); |
| 1645 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1646 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1647 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1648 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1649 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1650 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 1651 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1652 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1653 | } |
| 1654 | |
| 1655 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 1656 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1657 | Location first = locations->InAt(0); |
| 1658 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1659 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1660 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1661 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1662 | if (second.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1663 | __ addl(first.As<Register>(), second.As<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1664 | } else if (second.IsConstant()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1665 | __ addl(first.As<Register>(), Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1666 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1667 | __ addl(first.As<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1668 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1669 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1670 | } |
| 1671 | |
| 1672 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1673 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1674 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 1675 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1676 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1677 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 1678 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1679 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1680 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1681 | break; |
| 1682 | } |
| 1683 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1684 | case Primitive::kPrimFloat: { |
| 1685 | if (second.IsFpuRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1686 | __ addss(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1687 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1688 | __ addss(first.As<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1689 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1690 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | case Primitive::kPrimDouble: { |
| 1694 | if (second.IsFpuRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1695 | __ addsd(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1696 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1697 | __ addsd(first.As<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1698 | } |
| 1699 | break; |
| 1700 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1701 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1702 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1703 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1704 | } |
| 1705 | } |
| 1706 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1707 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1708 | LocationSummary* locations = |
| 1709 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1710 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1711 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1712 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1713 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1714 | locations->SetInAt(1, Location::Any()); |
| 1715 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1716 | break; |
| 1717 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1718 | case Primitive::kPrimFloat: |
| 1719 | case Primitive::kPrimDouble: { |
| 1720 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1721 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1722 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1723 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1724 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1725 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1726 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1727 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1728 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1729 | } |
| 1730 | |
| 1731 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 1732 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1733 | Location first = locations->InAt(0); |
| 1734 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1735 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1736 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1737 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1738 | if (second.IsRegister()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1739 | __ subl(first.As<Register>(), second.As<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1740 | } else if (second.IsConstant()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1741 | __ subl(first.As<Register>(), Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1742 | } else { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1743 | __ subl(first.As<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1744 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1745 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1746 | } |
| 1747 | |
| 1748 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1749 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1750 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 1751 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1752 | } else { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1753 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1754 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 1755 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1756 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1757 | break; |
| 1758 | } |
| 1759 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1760 | case Primitive::kPrimFloat: { |
| 1761 | __ subss(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1762 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | case Primitive::kPrimDouble: { |
| 1766 | __ subsd(first.As<XmmRegister>(), second.As<XmmRegister>()); |
| 1767 | break; |
| 1768 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1769 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1770 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1771 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1772 | } |
| 1773 | } |
| 1774 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1775 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 1776 | LocationSummary* locations = |
| 1777 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 1778 | switch (mul->GetResultType()) { |
| 1779 | case Primitive::kPrimInt: |
| 1780 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1781 | locations->SetInAt(1, Location::Any()); |
| 1782 | locations->SetOut(Location::SameAsFirstInput()); |
| 1783 | break; |
| 1784 | case Primitive::kPrimLong: { |
| 1785 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1786 | // TODO: Currently this handles only stack operands: |
| 1787 | // - we don't have enough registers because we currently use Quick ABI. |
| 1788 | // - by the time we have a working register allocator we will probably change the ABI |
| 1789 | // and fix the above. |
| 1790 | // - we don't have a way yet to request operands on stack but the base line compiler |
| 1791 | // will leave the operands on the stack with Any(). |
| 1792 | locations->SetInAt(1, Location::Any()); |
| 1793 | locations->SetOut(Location::SameAsFirstInput()); |
| 1794 | // Needed for imul on 32bits with 64bits output. |
| 1795 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 1796 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 1797 | break; |
| 1798 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1799 | case Primitive::kPrimFloat: |
| 1800 | case Primitive::kPrimDouble: { |
| 1801 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1802 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1803 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1804 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1805 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1806 | |
| 1807 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1808 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1809 | } |
| 1810 | } |
| 1811 | |
| 1812 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 1813 | LocationSummary* locations = mul->GetLocations(); |
| 1814 | Location first = locations->InAt(0); |
| 1815 | Location second = locations->InAt(1); |
| 1816 | DCHECK(first.Equals(locations->Out())); |
| 1817 | |
| 1818 | switch (mul->GetResultType()) { |
| 1819 | case Primitive::kPrimInt: { |
| 1820 | if (second.IsRegister()) { |
| 1821 | __ imull(first.As<Register>(), second.As<Register>()); |
| 1822 | } else if (second.IsConstant()) { |
| 1823 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 1824 | __ imull(first.As<Register>(), imm); |
| 1825 | } else { |
| 1826 | DCHECK(second.IsStackSlot()); |
| 1827 | __ imull(first.As<Register>(), Address(ESP, second.GetStackIndex())); |
| 1828 | } |
| 1829 | break; |
| 1830 | } |
| 1831 | |
| 1832 | case Primitive::kPrimLong: { |
| 1833 | DCHECK(second.IsDoubleStackSlot()); |
| 1834 | |
| 1835 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 1836 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
| 1837 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 1838 | Address in2_lo(ESP, second.GetStackIndex()); |
| 1839 | Register eax = locations->GetTemp(0).As<Register>(); |
| 1840 | Register edx = locations->GetTemp(1).As<Register>(); |
| 1841 | |
| 1842 | DCHECK_EQ(EAX, eax); |
| 1843 | DCHECK_EQ(EDX, edx); |
| 1844 | |
| 1845 | // input: in1 - 64 bits, in2 - 64 bits |
| 1846 | // output: in1 |
| 1847 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 1848 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 1849 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
| 1850 | |
| 1851 | __ movl(eax, in2_hi); |
| 1852 | // eax <- in1.lo * in2.hi |
| 1853 | __ imull(eax, in1_lo); |
| 1854 | // in1.hi <- in1.hi * in2.lo |
| 1855 | __ imull(in1_hi, in2_lo); |
| 1856 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 1857 | __ addl(in1_hi, eax); |
| 1858 | // move in1_lo to eax to prepare for double precision |
| 1859 | __ movl(eax, in1_lo); |
| 1860 | // edx:eax <- in1.lo * in2.lo |
| 1861 | __ mull(in2_lo); |
| 1862 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 1863 | __ addl(in1_hi, edx); |
| 1864 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 1865 | __ movl(in1_lo, eax); |
| 1866 | |
| 1867 | break; |
| 1868 | } |
| 1869 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1870 | case Primitive::kPrimFloat: { |
| 1871 | __ mulss(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1872 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1873 | } |
| 1874 | |
| 1875 | case Primitive::kPrimDouble: { |
| 1876 | __ mulsd(first.As<XmmRegister>(), second.As<XmmRegister>()); |
| 1877 | break; |
| 1878 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1879 | |
| 1880 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1881 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1882 | } |
| 1883 | } |
| 1884 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1885 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 1886 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 1887 | |
| 1888 | LocationSummary* locations = instruction->GetLocations(); |
| 1889 | Location out = locations->Out(); |
| 1890 | Location first = locations->InAt(0); |
| 1891 | Location second = locations->InAt(1); |
| 1892 | bool is_div = instruction->IsDiv(); |
| 1893 | |
| 1894 | switch (instruction->GetResultType()) { |
| 1895 | case Primitive::kPrimInt: { |
| 1896 | Register second_reg = second.As<Register>(); |
| 1897 | DCHECK_EQ(EAX, first.As<Register>()); |
| 1898 | DCHECK_EQ(is_div ? EAX : EDX, out.As<Register>()); |
| 1899 | |
| 1900 | SlowPathCodeX86* slow_path = |
| 1901 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86(out.As<Register>(), is_div); |
| 1902 | codegen_->AddSlowPath(slow_path); |
| 1903 | |
| 1904 | // 0x80000000/-1 triggers an arithmetic exception! |
| 1905 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 1906 | // it's safe to just use negl instead of more complex comparisons. |
| 1907 | |
| 1908 | __ cmpl(second_reg, Immediate(-1)); |
| 1909 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 1910 | |
| 1911 | // edx:eax <- sign-extended of eax |
| 1912 | __ cdq(); |
| 1913 | // eax = quotient, edx = remainder |
| 1914 | __ idivl(second_reg); |
| 1915 | |
| 1916 | __ Bind(slow_path->GetExitLabel()); |
| 1917 | break; |
| 1918 | } |
| 1919 | |
| 1920 | case Primitive::kPrimLong: { |
| 1921 | InvokeRuntimeCallingConvention calling_convention; |
| 1922 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 1923 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 1924 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 1925 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 1926 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 1927 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 1928 | |
| 1929 | if (is_div) { |
| 1930 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pLdiv))); |
| 1931 | } else { |
| 1932 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pLmod))); |
| 1933 | } |
| 1934 | uint32_t dex_pc = is_div |
| 1935 | ? instruction->AsDiv()->GetDexPc() |
| 1936 | : instruction->AsRem()->GetDexPc(); |
| 1937 | codegen_->RecordPcInfo(instruction, dex_pc); |
| 1938 | |
| 1939 | break; |
| 1940 | } |
| 1941 | |
| 1942 | default: |
| 1943 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 1944 | } |
| 1945 | } |
| 1946 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1947 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1948 | LocationSummary::CallKind call_kind = div->GetResultType() == Primitive::kPrimLong |
| 1949 | ? LocationSummary::kCall |
| 1950 | : LocationSummary::kNoCall; |
| 1951 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 1952 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1953 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1954 | case Primitive::kPrimInt: { |
| 1955 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 1956 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1957 | locations->SetOut(Location::SameAsFirstInput()); |
| 1958 | // Intel uses edx:eax as the dividend. |
| 1959 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 1960 | break; |
| 1961 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1962 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1963 | InvokeRuntimeCallingConvention calling_convention; |
| 1964 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 1965 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 1966 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 1967 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 1968 | // Runtime helper puts the result in EAX, EDX. |
| 1969 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1970 | break; |
| 1971 | } |
| 1972 | case Primitive::kPrimFloat: |
| 1973 | case Primitive::kPrimDouble: { |
| 1974 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1975 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1976 | locations->SetOut(Location::SameAsFirstInput()); |
| 1977 | break; |
| 1978 | } |
| 1979 | |
| 1980 | default: |
| 1981 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 1982 | } |
| 1983 | } |
| 1984 | |
| 1985 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 1986 | LocationSummary* locations = div->GetLocations(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1987 | Location out = locations->Out(); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1988 | Location first = locations->InAt(0); |
| 1989 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1990 | |
| 1991 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1992 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1993 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1994 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1995 | break; |
| 1996 | } |
| 1997 | |
| 1998 | case Primitive::kPrimFloat: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1999 | DCHECK(first.Equals(out)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2000 | __ divss(first.As<XmmRegister>(), second.As<XmmRegister>()); |
| 2001 | break; |
| 2002 | } |
| 2003 | |
| 2004 | case Primitive::kPrimDouble: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2005 | DCHECK(first.Equals(out)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2006 | __ divsd(first.As<XmmRegister>(), second.As<XmmRegister>()); |
| 2007 | break; |
| 2008 | } |
| 2009 | |
| 2010 | default: |
| 2011 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2012 | } |
| 2013 | } |
| 2014 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2015 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
| 2016 | LocationSummary::CallKind call_kind = rem->GetResultType() == Primitive::kPrimLong |
| 2017 | ? LocationSummary::kCall |
| 2018 | : LocationSummary::kNoCall; |
| 2019 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
| 2020 | |
| 2021 | switch (rem->GetResultType()) { |
| 2022 | case Primitive::kPrimInt: { |
| 2023 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2024 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2025 | locations->SetOut(Location::RegisterLocation(EDX)); |
| 2026 | break; |
| 2027 | } |
| 2028 | case Primitive::kPrimLong: { |
| 2029 | InvokeRuntimeCallingConvention calling_convention; |
| 2030 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2031 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2032 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2033 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 2034 | // Runtime helper puts the result in EAX, EDX. |
| 2035 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2036 | break; |
| 2037 | } |
| 2038 | case Primitive::kPrimFloat: |
| 2039 | case Primitive::kPrimDouble: { |
| 2040 | LOG(FATAL) << "Unimplemented rem type " << rem->GetResultType(); |
| 2041 | break; |
| 2042 | } |
| 2043 | |
| 2044 | default: |
| 2045 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 2046 | } |
| 2047 | } |
| 2048 | |
| 2049 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 2050 | Primitive::Type type = rem->GetResultType(); |
| 2051 | switch (type) { |
| 2052 | case Primitive::kPrimInt: |
| 2053 | case Primitive::kPrimLong: { |
| 2054 | GenerateDivRemIntegral(rem); |
| 2055 | break; |
| 2056 | } |
| 2057 | case Primitive::kPrimFloat: |
| 2058 | case Primitive::kPrimDouble: { |
| 2059 | LOG(FATAL) << "Unimplemented rem type " << type; |
| 2060 | break; |
| 2061 | } |
| 2062 | default: |
| 2063 | LOG(FATAL) << "Unexpected rem type " << type; |
| 2064 | } |
| 2065 | } |
| 2066 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2067 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2068 | LocationSummary* locations = |
| 2069 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2070 | switch (instruction->GetType()) { |
| 2071 | case Primitive::kPrimInt: { |
| 2072 | locations->SetInAt(0, Location::Any()); |
| 2073 | break; |
| 2074 | } |
| 2075 | case Primitive::kPrimLong: { |
| 2076 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 2077 | if (!instruction->IsConstant()) { |
| 2078 | locations->AddTemp(Location::RequiresRegister()); |
| 2079 | } |
| 2080 | break; |
| 2081 | } |
| 2082 | default: |
| 2083 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 2084 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2085 | if (instruction->HasUses()) { |
| 2086 | locations->SetOut(Location::SameAsFirstInput()); |
| 2087 | } |
| 2088 | } |
| 2089 | |
| 2090 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2091 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
| 2092 | codegen_->AddSlowPath(slow_path); |
| 2093 | |
| 2094 | LocationSummary* locations = instruction->GetLocations(); |
| 2095 | Location value = locations->InAt(0); |
| 2096 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2097 | switch (instruction->GetType()) { |
| 2098 | case Primitive::kPrimInt: { |
| 2099 | if (value.IsRegister()) { |
| 2100 | __ testl(value.As<Register>(), value.As<Register>()); |
| 2101 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2102 | } else if (value.IsStackSlot()) { |
| 2103 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 2104 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2105 | } else { |
| 2106 | DCHECK(value.IsConstant()) << value; |
| 2107 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 2108 | __ jmp(slow_path->GetEntryLabel()); |
| 2109 | } |
| 2110 | } |
| 2111 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2112 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2113 | case Primitive::kPrimLong: { |
| 2114 | if (value.IsRegisterPair()) { |
| 2115 | Register temp = locations->GetTemp(0).As<Register>(); |
| 2116 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 2117 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 2118 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2119 | } else { |
| 2120 | DCHECK(value.IsConstant()) << value; |
| 2121 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 2122 | __ jmp(slow_path->GetEntryLabel()); |
| 2123 | } |
| 2124 | } |
| 2125 | break; |
| 2126 | } |
| 2127 | default: |
| 2128 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2129 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2130 | } |
| 2131 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2132 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 2133 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 2134 | |
| 2135 | LocationSummary* locations = |
| 2136 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 2137 | |
| 2138 | switch (op->GetResultType()) { |
| 2139 | case Primitive::kPrimInt: { |
| 2140 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2141 | // The shift count needs to be in CL. |
| 2142 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
| 2143 | locations->SetOut(Location::SameAsFirstInput()); |
| 2144 | break; |
| 2145 | } |
| 2146 | case Primitive::kPrimLong: { |
| 2147 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2148 | // The shift count needs to be in CL. |
| 2149 | locations->SetInAt(1, Location::RegisterLocation(ECX)); |
| 2150 | locations->SetOut(Location::SameAsFirstInput()); |
| 2151 | break; |
| 2152 | } |
| 2153 | default: |
| 2154 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 2155 | } |
| 2156 | } |
| 2157 | |
| 2158 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 2159 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 2160 | |
| 2161 | LocationSummary* locations = op->GetLocations(); |
| 2162 | Location first = locations->InAt(0); |
| 2163 | Location second = locations->InAt(1); |
| 2164 | DCHECK(first.Equals(locations->Out())); |
| 2165 | |
| 2166 | switch (op->GetResultType()) { |
| 2167 | case Primitive::kPrimInt: { |
| 2168 | Register first_reg = first.As<Register>(); |
| 2169 | if (second.IsRegister()) { |
| 2170 | Register second_reg = second.As<Register>(); |
| 2171 | DCHECK_EQ(ECX, second_reg); |
| 2172 | if (op->IsShl()) { |
| 2173 | __ shll(first_reg, second_reg); |
| 2174 | } else if (op->IsShr()) { |
| 2175 | __ sarl(first_reg, second_reg); |
| 2176 | } else { |
| 2177 | __ shrl(first_reg, second_reg); |
| 2178 | } |
| 2179 | } else { |
| 2180 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 2181 | if (op->IsShl()) { |
| 2182 | __ shll(first_reg, imm); |
| 2183 | } else if (op->IsShr()) { |
| 2184 | __ sarl(first_reg, imm); |
| 2185 | } else { |
| 2186 | __ shrl(first_reg, imm); |
| 2187 | } |
| 2188 | } |
| 2189 | break; |
| 2190 | } |
| 2191 | case Primitive::kPrimLong: { |
| 2192 | Register second_reg = second.As<Register>(); |
| 2193 | DCHECK_EQ(ECX, second_reg); |
| 2194 | if (op->IsShl()) { |
| 2195 | GenerateShlLong(first, second_reg); |
| 2196 | } else if (op->IsShr()) { |
| 2197 | GenerateShrLong(first, second_reg); |
| 2198 | } else { |
| 2199 | GenerateUShrLong(first, second_reg); |
| 2200 | } |
| 2201 | break; |
| 2202 | } |
| 2203 | default: |
| 2204 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 2205 | } |
| 2206 | } |
| 2207 | |
| 2208 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
| 2209 | Label done; |
| 2210 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 2211 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 2212 | __ testl(shifter, Immediate(32)); |
| 2213 | __ j(kEqual, &done); |
| 2214 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 2215 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 2216 | __ Bind(&done); |
| 2217 | } |
| 2218 | |
| 2219 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
| 2220 | Label done; |
| 2221 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 2222 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 2223 | __ testl(shifter, Immediate(32)); |
| 2224 | __ j(kEqual, &done); |
| 2225 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 2226 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 2227 | __ Bind(&done); |
| 2228 | } |
| 2229 | |
| 2230 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
| 2231 | Label done; |
| 2232 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 2233 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 2234 | __ testl(shifter, Immediate(32)); |
| 2235 | __ j(kEqual, &done); |
| 2236 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 2237 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2238 | __ Bind(&done); |
| 2239 | } |
| 2240 | |
| 2241 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 2242 | HandleShift(shl); |
| 2243 | } |
| 2244 | |
| 2245 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 2246 | HandleShift(shl); |
| 2247 | } |
| 2248 | |
| 2249 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 2250 | HandleShift(shr); |
| 2251 | } |
| 2252 | |
| 2253 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 2254 | HandleShift(shr); |
| 2255 | } |
| 2256 | |
| 2257 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 2258 | HandleShift(ushr); |
| 2259 | } |
| 2260 | |
| 2261 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 2262 | HandleShift(ushr); |
| 2263 | } |
| 2264 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2265 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2266 | LocationSummary* locations = |
| 2267 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2268 | locations->SetOut(Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2269 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2270 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2271 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2272 | } |
| 2273 | |
| 2274 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
| 2275 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2276 | codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2277 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2278 | |
Nicolas Geoffray | 707c809 | 2014-04-04 10:50:14 +0100 | [diff] [blame] | 2279 | __ fs()->call( |
| 2280 | Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pAllocObjectWithAccessCheck))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2281 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2282 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2283 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 2284 | } |
| 2285 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2286 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 2287 | LocationSummary* locations = |
| 2288 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 2289 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 2290 | InvokeRuntimeCallingConvention calling_convention; |
| 2291 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2292 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2293 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 2294 | } |
| 2295 | |
| 2296 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 2297 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2298 | codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2299 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
| 2300 | |
| 2301 | __ fs()->call( |
| 2302 | Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pAllocArrayWithAccessCheck))); |
| 2303 | |
| 2304 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 2305 | DCHECK(!codegen_->IsLeafMethod()); |
| 2306 | } |
| 2307 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2308 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2309 | LocationSummary* locations = |
| 2310 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2311 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 2312 | if (location.IsStackSlot()) { |
| 2313 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 2314 | } else if (location.IsDoubleStackSlot()) { |
| 2315 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2316 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 2317 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2318 | } |
| 2319 | |
| 2320 | void InstructionCodeGeneratorX86::VisitParameterValue(HParameterValue* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2321 | UNUSED(instruction); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2322 | } |
| 2323 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2324 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2325 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2326 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2327 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2328 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 2329 | } |
| 2330 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2331 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 2332 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 2333 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2334 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 2335 | DCHECK(in.Equals(out)); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2336 | switch (not_->InputAt(0)->GetType()) { |
| 2337 | case Primitive::kPrimBoolean: |
| 2338 | __ xorl(out.As<Register>(), Immediate(1)); |
| 2339 | break; |
| 2340 | |
| 2341 | case Primitive::kPrimInt: |
| 2342 | __ notl(out.As<Register>()); |
| 2343 | break; |
| 2344 | |
| 2345 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 2346 | __ notl(out.AsRegisterPairLow<Register>()); |
| 2347 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2348 | break; |
| 2349 | |
| 2350 | default: |
| 2351 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 2352 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 2353 | } |
| 2354 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2355 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2356 | LocationSummary* locations = |
| 2357 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2358 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2359 | locations->SetInAt(1, Location::Any()); |
| 2360 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2361 | } |
| 2362 | |
| 2363 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2364 | LocationSummary* locations = compare->GetLocations(); |
| 2365 | switch (compare->InputAt(0)->GetType()) { |
| 2366 | case Primitive::kPrimLong: { |
| 2367 | Label less, greater, done; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2368 | Register output = locations->Out().As<Register>(); |
| 2369 | Location left = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2370 | Location right = locations->InAt(1); |
| 2371 | if (right.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2372 | __ cmpl(left.AsRegisterPairHigh<Register>(), right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2373 | } else { |
| 2374 | DCHECK(right.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2375 | __ cmpl(left.AsRegisterPairHigh<Register>(), |
| 2376 | Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2377 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2378 | __ j(kLess, &less); // Signed compare. |
| 2379 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2380 | if (right.IsRegisterPair()) { |
| 2381 | __ cmpl(left.AsRegisterPairLow<Register>(), right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2382 | } else { |
| 2383 | DCHECK(right.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2384 | __ cmpl(left.AsRegisterPairLow<Register>(), Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2385 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2386 | __ movl(output, Immediate(0)); |
| 2387 | __ j(kEqual, &done); |
| 2388 | __ j(kBelow, &less); // Unsigned compare. |
| 2389 | |
| 2390 | __ Bind(&greater); |
| 2391 | __ movl(output, Immediate(1)); |
| 2392 | __ jmp(&done); |
| 2393 | |
| 2394 | __ Bind(&less); |
| 2395 | __ movl(output, Immediate(-1)); |
| 2396 | |
| 2397 | __ Bind(&done); |
| 2398 | break; |
| 2399 | } |
| 2400 | default: |
| 2401 | LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType(); |
| 2402 | } |
| 2403 | } |
| 2404 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2405 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2406 | LocationSummary* locations = |
| 2407 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 2408 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 2409 | locations->SetInAt(i, Location::Any()); |
| 2410 | } |
| 2411 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2412 | } |
| 2413 | |
| 2414 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2415 | UNUSED(instruction); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2416 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2417 | } |
| 2418 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2419 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2420 | LocationSummary* locations = |
| 2421 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2422 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2423 | Primitive::Type field_type = instruction->GetFieldType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2424 | bool needs_write_barrier = |
| 2425 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 2426 | |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 2427 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 2428 | || (field_type == Primitive::kPrimByte); |
| 2429 | // The register allocator does not support multiple |
| 2430 | // inputs that die at entry with one in a specific register. |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 2431 | if (is_byte_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2432 | // Ensure the value is in a byte register. |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2433 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2434 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2435 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2436 | } |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 2437 | // Temporary registers for the write barrier. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2438 | if (needs_write_barrier) { |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 2439 | locations->AddTemp(Location::RequiresRegister()); |
| 2440 | // Ensure the card is in a byte register. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2441 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 2442 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2443 | } |
| 2444 | |
| 2445 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 2446 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2447 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2448 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2449 | Primitive::Type field_type = instruction->GetFieldType(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2450 | |
| 2451 | switch (field_type) { |
| 2452 | case Primitive::kPrimBoolean: |
| 2453 | case Primitive::kPrimByte: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2454 | ByteRegister value = locations->InAt(1).As<ByteRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2455 | __ movb(Address(obj, offset), value); |
| 2456 | break; |
| 2457 | } |
| 2458 | |
| 2459 | case Primitive::kPrimShort: |
| 2460 | case Primitive::kPrimChar: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2461 | Register value = locations->InAt(1).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2462 | __ movw(Address(obj, offset), value); |
| 2463 | break; |
| 2464 | } |
| 2465 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2466 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2467 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2468 | Register value = locations->InAt(1).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2469 | __ movl(Address(obj, offset), value); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2470 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2471 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2472 | Register temp = locations->GetTemp(0).As<Register>(); |
| 2473 | Register card = locations->GetTemp(1).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2474 | codegen_->MarkGCCard(temp, card, obj, value); |
| 2475 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2476 | break; |
| 2477 | } |
| 2478 | |
| 2479 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2480 | Location value = locations->InAt(1); |
| 2481 | __ movl(Address(obj, offset), value.AsRegisterPairLow<Register>()); |
| 2482 | __ movl(Address(obj, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2483 | break; |
| 2484 | } |
| 2485 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2486 | case Primitive::kPrimFloat: { |
| 2487 | XmmRegister value = locations->InAt(1).As<XmmRegister>(); |
| 2488 | __ movss(Address(obj, offset), value); |
| 2489 | break; |
| 2490 | } |
| 2491 | |
| 2492 | case Primitive::kPrimDouble: { |
| 2493 | XmmRegister value = locations->InAt(1).As<XmmRegister>(); |
| 2494 | __ movsd(Address(obj, offset), value); |
| 2495 | break; |
| 2496 | } |
| 2497 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2498 | case Primitive::kPrimVoid: |
| 2499 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2500 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2501 | } |
| 2502 | } |
| 2503 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2504 | void CodeGeneratorX86::MarkGCCard(Register temp, Register card, Register object, Register value) { |
| 2505 | Label is_null; |
| 2506 | __ testl(value, value); |
| 2507 | __ j(kEqual, &is_null); |
| 2508 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 2509 | __ movl(temp, object); |
| 2510 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
| 2511 | __ movb(Address(temp, card, TIMES_1, 0), |
| 2512 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
| 2513 | __ Bind(&is_null); |
| 2514 | } |
| 2515 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2516 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2517 | LocationSummary* locations = |
| 2518 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2519 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2520 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2521 | } |
| 2522 | |
| 2523 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 2524 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2525 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2526 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
| 2527 | |
| 2528 | switch (instruction->GetType()) { |
| 2529 | case Primitive::kPrimBoolean: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2530 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2531 | __ movzxb(out, Address(obj, offset)); |
| 2532 | break; |
| 2533 | } |
| 2534 | |
| 2535 | case Primitive::kPrimByte: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2536 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2537 | __ movsxb(out, Address(obj, offset)); |
| 2538 | break; |
| 2539 | } |
| 2540 | |
| 2541 | case Primitive::kPrimShort: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2542 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2543 | __ movsxw(out, Address(obj, offset)); |
| 2544 | break; |
| 2545 | } |
| 2546 | |
| 2547 | case Primitive::kPrimChar: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2548 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2549 | __ movzxw(out, Address(obj, offset)); |
| 2550 | break; |
| 2551 | } |
| 2552 | |
| 2553 | case Primitive::kPrimInt: |
| 2554 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2555 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2556 | __ movl(out, Address(obj, offset)); |
| 2557 | break; |
| 2558 | } |
| 2559 | |
| 2560 | case Primitive::kPrimLong: { |
| 2561 | // TODO: support volatile. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2562 | __ movl(locations->Out().AsRegisterPairLow<Register>(), Address(obj, offset)); |
| 2563 | __ movl(locations->Out().AsRegisterPairHigh<Register>(), Address(obj, kX86WordSize + offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2564 | break; |
| 2565 | } |
| 2566 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2567 | case Primitive::kPrimFloat: { |
| 2568 | XmmRegister out = locations->Out().As<XmmRegister>(); |
| 2569 | __ movss(out, Address(obj, offset)); |
| 2570 | break; |
| 2571 | } |
| 2572 | |
| 2573 | case Primitive::kPrimDouble: { |
| 2574 | XmmRegister out = locations->Out().As<XmmRegister>(); |
| 2575 | __ movsd(out, Address(obj, offset)); |
| 2576 | break; |
| 2577 | } |
| 2578 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2579 | case Primitive::kPrimVoid: |
| 2580 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2581 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2582 | } |
| 2583 | } |
| 2584 | |
| 2585 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2586 | LocationSummary* locations = |
| 2587 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2588 | locations->SetInAt(0, Location::Any()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2589 | if (instruction->HasUses()) { |
| 2590 | locations->SetOut(Location::SameAsFirstInput()); |
| 2591 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2592 | } |
| 2593 | |
| 2594 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 2595 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2596 | codegen_->AddSlowPath(slow_path); |
| 2597 | |
| 2598 | LocationSummary* locations = instruction->GetLocations(); |
| 2599 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2600 | |
| 2601 | if (obj.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2602 | __ cmpl(obj.As<Register>(), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2603 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2604 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2605 | } else { |
| 2606 | DCHECK(obj.IsConstant()) << obj; |
| 2607 | DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0); |
| 2608 | __ jmp(slow_path->GetEntryLabel()); |
| 2609 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2610 | } |
| 2611 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2612 | } |
| 2613 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2614 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2615 | LocationSummary* locations = |
| 2616 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2617 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2618 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2619 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2620 | } |
| 2621 | |
| 2622 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* 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); |
| 2626 | |
| 2627 | switch (instruction->GetType()) { |
| 2628 | case Primitive::kPrimBoolean: { |
| 2629 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2630 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2631 | if (index.IsConstant()) { |
| 2632 | __ movzxb(out, Address(obj, |
| 2633 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 2634 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2635 | __ movzxb(out, Address(obj, index.As<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2636 | } |
| 2637 | break; |
| 2638 | } |
| 2639 | |
| 2640 | case Primitive::kPrimByte: { |
| 2641 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2642 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2643 | if (index.IsConstant()) { |
| 2644 | __ movsxb(out, Address(obj, |
| 2645 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 2646 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2647 | __ movsxb(out, Address(obj, index.As<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2648 | } |
| 2649 | break; |
| 2650 | } |
| 2651 | |
| 2652 | case Primitive::kPrimShort: { |
| 2653 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2654 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2655 | if (index.IsConstant()) { |
| 2656 | __ movsxw(out, Address(obj, |
| 2657 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 2658 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2659 | __ movsxw(out, Address(obj, index.As<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2660 | } |
| 2661 | break; |
| 2662 | } |
| 2663 | |
| 2664 | case Primitive::kPrimChar: { |
| 2665 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2666 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2667 | if (index.IsConstant()) { |
| 2668 | __ movzxw(out, Address(obj, |
| 2669 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 2670 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2671 | __ movzxw(out, Address(obj, index.As<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2672 | } |
| 2673 | break; |
| 2674 | } |
| 2675 | |
| 2676 | case Primitive::kPrimInt: |
| 2677 | case Primitive::kPrimNot: { |
| 2678 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2679 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2680 | if (index.IsConstant()) { |
| 2681 | __ movl(out, Address(obj, |
| 2682 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 2683 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2684 | __ movl(out, Address(obj, index.As<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2685 | } |
| 2686 | break; |
| 2687 | } |
| 2688 | |
| 2689 | case Primitive::kPrimLong: { |
| 2690 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2691 | Location out = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2692 | if (index.IsConstant()) { |
| 2693 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2694 | __ movl(out.AsRegisterPairLow<Register>(), Address(obj, offset)); |
| 2695 | __ movl(out.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2696 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2697 | __ movl(out.AsRegisterPairLow<Register>(), |
| 2698 | Address(obj, index.As<Register>(), TIMES_8, data_offset)); |
| 2699 | __ movl(out.AsRegisterPairHigh<Register>(), |
| 2700 | Address(obj, index.As<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2701 | } |
| 2702 | break; |
| 2703 | } |
| 2704 | |
| 2705 | case Primitive::kPrimFloat: |
| 2706 | case Primitive::kPrimDouble: |
| 2707 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2708 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2709 | case Primitive::kPrimVoid: |
| 2710 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2711 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2712 | } |
| 2713 | } |
| 2714 | |
| 2715 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2716 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2717 | bool needs_write_barrier = |
| 2718 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 2719 | |
| 2720 | DCHECK(kFollowsQuickABI); |
| 2721 | bool not_enough_registers = needs_write_barrier |
| 2722 | && !instruction->GetValue()->IsConstant() |
| 2723 | && !instruction->GetIndex()->IsConstant(); |
| 2724 | bool needs_runtime_call = instruction->NeedsTypeCheck() || not_enough_registers; |
| 2725 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2726 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2727 | instruction, |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2728 | needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2729 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2730 | if (needs_runtime_call) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2731 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2732 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2733 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2734 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2735 | } else { |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 2736 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 2737 | || (value_type == Primitive::kPrimByte); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 2738 | // 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] | 2739 | // In case of a byte operation, the register allocator does not support multiple |
| 2740 | // inputs that die at entry with one in a specific register. |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2741 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2742 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 2743 | if (is_byte_type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2744 | // Ensure the value is in a byte register. |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2745 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2746 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2747 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2748 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2749 | // Temporary registers for the write barrier. |
| 2750 | if (needs_write_barrier) { |
| 2751 | locations->AddTemp(Location::RequiresRegister()); |
| 2752 | // Ensure the card is in a byte register. |
| 2753 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 2754 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2755 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2756 | } |
| 2757 | |
| 2758 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 2759 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2760 | Register obj = locations->InAt(0).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2761 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2762 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2763 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2764 | bool needs_runtime_call = locations->WillCall(); |
| 2765 | bool needs_write_barrier = |
| 2766 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2767 | |
| 2768 | switch (value_type) { |
| 2769 | case Primitive::kPrimBoolean: |
| 2770 | case Primitive::kPrimByte: { |
| 2771 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2772 | if (index.IsConstant()) { |
| 2773 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2774 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2775 | __ movb(Address(obj, offset), value.As<ByteRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2776 | } else { |
| 2777 | __ movb(Address(obj, offset), |
| 2778 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2779 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2780 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2781 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2782 | __ movb(Address(obj, index.As<Register>(), TIMES_1, data_offset), |
| 2783 | value.As<ByteRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2784 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2785 | __ movb(Address(obj, index.As<Register>(), TIMES_1, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2786 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2787 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2788 | } |
| 2789 | break; |
| 2790 | } |
| 2791 | |
| 2792 | case Primitive::kPrimShort: |
| 2793 | case Primitive::kPrimChar: { |
| 2794 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2795 | if (index.IsConstant()) { |
| 2796 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2797 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2798 | __ movw(Address(obj, offset), value.As<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2799 | } else { |
| 2800 | __ movw(Address(obj, offset), |
| 2801 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2802 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2803 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2804 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2805 | __ movw(Address(obj, index.As<Register>(), TIMES_2, data_offset), |
| 2806 | value.As<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2807 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2808 | __ movw(Address(obj, index.As<Register>(), TIMES_2, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2809 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2810 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2811 | } |
| 2812 | break; |
| 2813 | } |
| 2814 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2815 | case Primitive::kPrimInt: |
| 2816 | case Primitive::kPrimNot: { |
| 2817 | if (!needs_runtime_call) { |
| 2818 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 2819 | if (index.IsConstant()) { |
| 2820 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2821 | if (value.IsRegister()) { |
| 2822 | __ movl(Address(obj, offset), value.As<Register>()); |
| 2823 | } else { |
| 2824 | DCHECK(value.IsConstant()) << value; |
| 2825 | __ movl(Address(obj, offset), |
| 2826 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2827 | } |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2828 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2829 | DCHECK(index.IsRegister()) << index; |
| 2830 | if (value.IsRegister()) { |
| 2831 | __ movl(Address(obj, index.As<Register>(), TIMES_4, data_offset), |
| 2832 | value.As<Register>()); |
| 2833 | } else { |
| 2834 | DCHECK(value.IsConstant()) << value; |
| 2835 | __ movl(Address(obj, index.As<Register>(), TIMES_4, data_offset), |
| 2836 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2837 | } |
| 2838 | } |
| 2839 | |
| 2840 | if (needs_write_barrier) { |
| 2841 | Register temp = locations->GetTemp(0).As<Register>(); |
| 2842 | Register card = locations->GetTemp(1).As<Register>(); |
| 2843 | codegen_->MarkGCCard(temp, card, obj, value.As<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2844 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2845 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2846 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 2847 | DCHECK(!codegen_->IsLeafMethod()); |
| 2848 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pAputObject))); |
| 2849 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2850 | } |
| 2851 | break; |
| 2852 | } |
| 2853 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2854 | case Primitive::kPrimLong: { |
| 2855 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2856 | if (index.IsConstant()) { |
| 2857 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2858 | if (value.IsRegisterPair()) { |
| 2859 | __ movl(Address(obj, offset), value.AsRegisterPairLow<Register>()); |
| 2860 | __ movl(Address(obj, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2861 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2862 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2863 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 2864 | __ movl(Address(obj, offset), Immediate(Low32Bits(val))); |
| 2865 | __ movl(Address(obj, offset + kX86WordSize), Immediate(High32Bits(val))); |
| 2866 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2867 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2868 | if (value.IsRegisterPair()) { |
| 2869 | __ movl(Address(obj, index.As<Register>(), TIMES_8, data_offset), |
| 2870 | value.AsRegisterPairLow<Register>()); |
| 2871 | __ movl(Address(obj, index.As<Register>(), TIMES_8, data_offset + kX86WordSize), |
| 2872 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2873 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2874 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2875 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2876 | __ movl(Address(obj, index.As<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2877 | Immediate(Low32Bits(val))); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2878 | __ movl(Address(obj, index.As<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2879 | Immediate(High32Bits(val))); |
| 2880 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2881 | } |
| 2882 | break; |
| 2883 | } |
| 2884 | |
| 2885 | case Primitive::kPrimFloat: |
| 2886 | case Primitive::kPrimDouble: |
| 2887 | LOG(FATAL) << "Unimplemented register type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2888 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2889 | case Primitive::kPrimVoid: |
| 2890 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2891 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2892 | } |
| 2893 | } |
| 2894 | |
| 2895 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 2896 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2897 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2898 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2899 | instruction->SetLocations(locations); |
| 2900 | } |
| 2901 | |
| 2902 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 2903 | LocationSummary* locations = instruction->GetLocations(); |
| 2904 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2905 | Register obj = locations->InAt(0).As<Register>(); |
| 2906 | Register out = locations->Out().As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2907 | __ movl(out, Address(obj, offset)); |
| 2908 | } |
| 2909 | |
| 2910 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2911 | LocationSummary* locations = |
| 2912 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2913 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2914 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2915 | if (instruction->HasUses()) { |
| 2916 | locations->SetOut(Location::SameAsFirstInput()); |
| 2917 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2918 | } |
| 2919 | |
| 2920 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 2921 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 2922 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathX86( |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2923 | instruction, locations->InAt(0), locations->InAt(1)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2924 | codegen_->AddSlowPath(slow_path); |
| 2925 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2926 | Register index = locations->InAt(0).As<Register>(); |
| 2927 | Register length = locations->InAt(1).As<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2928 | |
| 2929 | __ cmpl(index, length); |
| 2930 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
| 2931 | } |
| 2932 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2933 | void LocationsBuilderX86::VisitTemporary(HTemporary* temp) { |
| 2934 | temp->SetLocations(nullptr); |
| 2935 | } |
| 2936 | |
| 2937 | void InstructionCodeGeneratorX86::VisitTemporary(HTemporary* temp) { |
| 2938 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2939 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2940 | } |
| 2941 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 2942 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2943 | UNUSED(instruction); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2944 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 2945 | } |
| 2946 | |
| 2947 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2948 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 2949 | } |
| 2950 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2951 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 2952 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 2953 | } |
| 2954 | |
| 2955 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2956 | HBasicBlock* block = instruction->GetBlock(); |
| 2957 | if (block->GetLoopInformation() != nullptr) { |
| 2958 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 2959 | // The back edge will generate the suspend check. |
| 2960 | return; |
| 2961 | } |
| 2962 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 2963 | // The goto will generate the suspend check. |
| 2964 | return; |
| 2965 | } |
| 2966 | GenerateSuspendCheck(instruction, nullptr); |
| 2967 | } |
| 2968 | |
| 2969 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 2970 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2971 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2972 | new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2973 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2974 | __ fs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2975 | Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2976 | if (successor == nullptr) { |
| 2977 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 2978 | __ Bind(slow_path->GetReturnLabel()); |
| 2979 | } else { |
| 2980 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 2981 | __ jmp(slow_path->GetEntryLabel()); |
| 2982 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2983 | } |
| 2984 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2985 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 2986 | return codegen_->GetAssembler(); |
| 2987 | } |
| 2988 | |
| 2989 | void ParallelMoveResolverX86::MoveMemoryToMemory(int dst, int src) { |
| 2990 | ScratchRegisterScope ensure_scratch( |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 2991 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 2992 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 2993 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, src + stack_offset)); |
| 2994 | __ movl(Address(ESP, dst + stack_offset), static_cast<Register>(ensure_scratch.GetRegister())); |
| 2995 | } |
| 2996 | |
| 2997 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
| 2998 | MoveOperands* move = moves_.Get(index); |
| 2999 | Location source = move->GetSource(); |
| 3000 | Location destination = move->GetDestination(); |
| 3001 | |
| 3002 | if (source.IsRegister()) { |
| 3003 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3004 | __ movl(destination.As<Register>(), source.As<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 3005 | } else { |
| 3006 | DCHECK(destination.IsStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3007 | __ movl(Address(ESP, destination.GetStackIndex()), source.As<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 3008 | } |
| 3009 | } else if (source.IsStackSlot()) { |
| 3010 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3011 | __ movl(destination.As<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 3012 | } else { |
| 3013 | DCHECK(destination.IsStackSlot()); |
| 3014 | MoveMemoryToMemory(destination.GetStackIndex(), |
| 3015 | source.GetStackIndex()); |
| 3016 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3017 | } else if (source.IsConstant()) { |
| 3018 | HIntConstant* instruction = source.GetConstant()->AsIntConstant(); |
| 3019 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
| 3020 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3021 | __ movl(destination.As<Register>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3022 | } else { |
| 3023 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 3024 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 3025 | } else { |
| 3026 | LOG(FATAL) << "Unimplemented"; |
| 3027 | } |
| 3028 | } |
| 3029 | |
| 3030 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3031 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 3032 | ScratchRegisterScope ensure_scratch( |
| 3033 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 3034 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 3035 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 3036 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 3037 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 3038 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
| 3039 | } |
| 3040 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 3041 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
| 3042 | ScratchRegisterScope ensure_scratch1( |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3043 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 3044 | |
| 3045 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 3046 | ScratchRegisterScope ensure_scratch2( |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 3047 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 3048 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 3049 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 3050 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 3051 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 3052 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 3053 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 3054 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
| 3055 | } |
| 3056 | |
| 3057 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
| 3058 | MoveOperands* move = moves_.Get(index); |
| 3059 | Location source = move->GetSource(); |
| 3060 | Location destination = move->GetDestination(); |
| 3061 | |
| 3062 | if (source.IsRegister() && destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3063 | __ xchgl(destination.As<Register>(), source.As<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 3064 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3065 | Exchange(source.As<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 3066 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3067 | Exchange(destination.As<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 3068 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 3069 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 3070 | } else { |
| 3071 | LOG(FATAL) << "Unimplemented"; |
| 3072 | } |
| 3073 | } |
| 3074 | |
| 3075 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 3076 | __ pushl(static_cast<Register>(reg)); |
| 3077 | } |
| 3078 | |
| 3079 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 3080 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 3081 | } |
| 3082 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3083 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3084 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() |
| 3085 | ? LocationSummary::kCallOnSlowPath |
| 3086 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3087 | LocationSummary* locations = |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3088 | new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3089 | locations->SetOut(Location::RequiresRegister()); |
| 3090 | } |
| 3091 | |
| 3092 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
| 3093 | Register out = cls->GetLocations()->Out().As<Register>(); |
| 3094 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3095 | DCHECK(!cls->CanCallRuntime()); |
| 3096 | DCHECK(!cls->MustGenerateClinitCheck()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3097 | codegen_->LoadCurrentMethod(out); |
| 3098 | __ movl(out, Address(out, mirror::ArtMethod::DeclaringClassOffset().Int32Value())); |
| 3099 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3100 | DCHECK(cls->CanCallRuntime()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3101 | codegen_->LoadCurrentMethod(out); |
| 3102 | __ movl(out, Address(out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value())); |
| 3103 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3104 | |
| 3105 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 3106 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 3107 | codegen_->AddSlowPath(slow_path); |
| 3108 | __ testl(out, out); |
| 3109 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3110 | if (cls->MustGenerateClinitCheck()) { |
| 3111 | GenerateClassInitializationCheck(slow_path, out); |
| 3112 | } else { |
| 3113 | __ Bind(slow_path->GetExitLabel()); |
| 3114 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3115 | } |
| 3116 | } |
| 3117 | |
| 3118 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 3119 | LocationSummary* locations = |
| 3120 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 3121 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3122 | if (check->HasUses()) { |
| 3123 | locations->SetOut(Location::SameAsFirstInput()); |
| 3124 | } |
| 3125 | } |
| 3126 | |
| 3127 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3128 | // We assume the class to not be null. |
| 3129 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 3130 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3131 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3132 | GenerateClassInitializationCheck(slow_path, check->GetLocations()->InAt(0).As<Register>()); |
| 3133 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3134 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3135 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
| 3136 | SlowPathCodeX86* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3137 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 3138 | Immediate(mirror::Class::kStatusInitialized)); |
| 3139 | __ j(kLess, slow_path->GetEntryLabel()); |
| 3140 | __ Bind(slow_path->GetExitLabel()); |
| 3141 | // No need for memory fence, thanks to the X86 memory model. |
| 3142 | } |
| 3143 | |
| 3144 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3145 | LocationSummary* locations = |
| 3146 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3147 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3148 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3149 | } |
| 3150 | |
| 3151 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3152 | LocationSummary* locations = instruction->GetLocations(); |
| 3153 | Register cls = locations->InAt(0).As<Register>(); |
| 3154 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
| 3155 | |
| 3156 | switch (instruction->GetType()) { |
| 3157 | case Primitive::kPrimBoolean: { |
| 3158 | Register out = locations->Out().As<Register>(); |
| 3159 | __ movzxb(out, Address(cls, offset)); |
| 3160 | break; |
| 3161 | } |
| 3162 | |
| 3163 | case Primitive::kPrimByte: { |
| 3164 | Register out = locations->Out().As<Register>(); |
| 3165 | __ movsxb(out, Address(cls, offset)); |
| 3166 | break; |
| 3167 | } |
| 3168 | |
| 3169 | case Primitive::kPrimShort: { |
| 3170 | Register out = locations->Out().As<Register>(); |
| 3171 | __ movsxw(out, Address(cls, offset)); |
| 3172 | break; |
| 3173 | } |
| 3174 | |
| 3175 | case Primitive::kPrimChar: { |
| 3176 | Register out = locations->Out().As<Register>(); |
| 3177 | __ movzxw(out, Address(cls, offset)); |
| 3178 | break; |
| 3179 | } |
| 3180 | |
| 3181 | case Primitive::kPrimInt: |
| 3182 | case Primitive::kPrimNot: { |
| 3183 | Register out = locations->Out().As<Register>(); |
| 3184 | __ movl(out, Address(cls, offset)); |
| 3185 | break; |
| 3186 | } |
| 3187 | |
| 3188 | case Primitive::kPrimLong: { |
| 3189 | // TODO: support volatile. |
| 3190 | __ movl(locations->Out().AsRegisterPairLow<Register>(), Address(cls, offset)); |
| 3191 | __ movl(locations->Out().AsRegisterPairHigh<Register>(), Address(cls, kX86WordSize + offset)); |
| 3192 | break; |
| 3193 | } |
| 3194 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3195 | case Primitive::kPrimFloat: { |
| 3196 | XmmRegister out = locations->Out().As<XmmRegister>(); |
| 3197 | __ movss(out, Address(cls, offset)); |
| 3198 | break; |
| 3199 | } |
| 3200 | |
| 3201 | case Primitive::kPrimDouble: { |
| 3202 | XmmRegister out = locations->Out().As<XmmRegister>(); |
| 3203 | __ movsd(out, Address(cls, offset)); |
| 3204 | break; |
| 3205 | } |
| 3206 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3207 | case Primitive::kPrimVoid: |
| 3208 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 3209 | UNREACHABLE(); |
| 3210 | } |
| 3211 | } |
| 3212 | |
| 3213 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3214 | LocationSummary* locations = |
| 3215 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3216 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3217 | Primitive::Type field_type = instruction->GetFieldType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3218 | bool needs_write_barrier = |
| 3219 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3220 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 3221 | || (field_type == Primitive::kPrimByte); |
| 3222 | // The register allocator does not support multiple |
| 3223 | // inputs that die at entry with one in a specific register. |
| 3224 | if (is_byte_type) { |
| 3225 | // Ensure the value is in a byte register. |
| 3226 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
| 3227 | } else { |
| 3228 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3229 | } |
| 3230 | // Temporary registers for the write barrier. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3231 | if (needs_write_barrier) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3232 | locations->AddTemp(Location::RequiresRegister()); |
| 3233 | // Ensure the card is in a byte register. |
| 3234 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 3235 | } |
| 3236 | } |
| 3237 | |
| 3238 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3239 | LocationSummary* locations = instruction->GetLocations(); |
| 3240 | Register cls = locations->InAt(0).As<Register>(); |
| 3241 | uint32_t offset = instruction->GetFieldOffset().Uint32Value(); |
| 3242 | Primitive::Type field_type = instruction->GetFieldType(); |
| 3243 | |
| 3244 | switch (field_type) { |
| 3245 | case Primitive::kPrimBoolean: |
| 3246 | case Primitive::kPrimByte: { |
| 3247 | ByteRegister value = locations->InAt(1).As<ByteRegister>(); |
| 3248 | __ movb(Address(cls, offset), value); |
| 3249 | break; |
| 3250 | } |
| 3251 | |
| 3252 | case Primitive::kPrimShort: |
| 3253 | case Primitive::kPrimChar: { |
| 3254 | Register value = locations->InAt(1).As<Register>(); |
| 3255 | __ movw(Address(cls, offset), value); |
| 3256 | break; |
| 3257 | } |
| 3258 | |
| 3259 | case Primitive::kPrimInt: |
| 3260 | case Primitive::kPrimNot: { |
| 3261 | Register value = locations->InAt(1).As<Register>(); |
| 3262 | __ movl(Address(cls, offset), value); |
| 3263 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3264 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3265 | Register temp = locations->GetTemp(0).As<Register>(); |
| 3266 | Register card = locations->GetTemp(1).As<Register>(); |
| 3267 | codegen_->MarkGCCard(temp, card, cls, value); |
| 3268 | } |
| 3269 | break; |
| 3270 | } |
| 3271 | |
| 3272 | case Primitive::kPrimLong: { |
| 3273 | Location value = locations->InAt(1); |
| 3274 | __ movl(Address(cls, offset), value.AsRegisterPairLow<Register>()); |
| 3275 | __ movl(Address(cls, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 3276 | break; |
| 3277 | } |
| 3278 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3279 | case Primitive::kPrimFloat: { |
| 3280 | XmmRegister value = locations->InAt(1).As<XmmRegister>(); |
| 3281 | __ movss(Address(cls, offset), value); |
| 3282 | break; |
| 3283 | } |
| 3284 | |
| 3285 | case Primitive::kPrimDouble: { |
| 3286 | XmmRegister value = locations->InAt(1).As<XmmRegister>(); |
| 3287 | __ movsd(Address(cls, offset), value); |
| 3288 | break; |
| 3289 | } |
| 3290 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3291 | case Primitive::kPrimVoid: |
| 3292 | LOG(FATAL) << "Unreachable type " << field_type; |
| 3293 | UNREACHABLE(); |
| 3294 | } |
| 3295 | } |
| 3296 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 3297 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
| 3298 | LocationSummary* locations = |
| 3299 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
| 3300 | locations->SetOut(Location::RequiresRegister()); |
| 3301 | } |
| 3302 | |
| 3303 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
| 3304 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 3305 | codegen_->AddSlowPath(slow_path); |
| 3306 | |
| 3307 | Register out = load->GetLocations()->Out().As<Register>(); |
| 3308 | codegen_->LoadCurrentMethod(out); |
| 3309 | __ movl(out, Address(out, mirror::ArtMethod::DexCacheStringsOffset().Int32Value())); |
| 3310 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
| 3311 | __ testl(out, out); |
| 3312 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3313 | __ Bind(slow_path->GetExitLabel()); |
| 3314 | } |
| 3315 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 3316 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 3317 | LocationSummary* locations = |
| 3318 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 3319 | locations->SetOut(Location::RequiresRegister()); |
| 3320 | } |
| 3321 | |
| 3322 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
| 3323 | Address address = Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); |
| 3324 | __ fs()->movl(load->GetLocations()->Out().As<Register>(), address); |
| 3325 | __ fs()->movl(address, Immediate(0)); |
| 3326 | } |
| 3327 | |
| 3328 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 3329 | LocationSummary* locations = |
| 3330 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3331 | InvokeRuntimeCallingConvention calling_convention; |
| 3332 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3333 | } |
| 3334 | |
| 3335 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
| 3336 | __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pDeliverException))); |
| 3337 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3338 | } |
| 3339 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3340 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 3341 | LocationSummary::CallKind call_kind = instruction->IsClassFinal() |
| 3342 | ? LocationSummary::kNoCall |
| 3343 | : LocationSummary::kCallOnSlowPath; |
| 3344 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 3345 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3346 | locations->SetInAt(1, Location::Any()); |
| 3347 | locations->SetOut(Location::RequiresRegister()); |
| 3348 | } |
| 3349 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3350 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 3351 | LocationSummary* locations = instruction->GetLocations(); |
| 3352 | Register obj = locations->InAt(0).As<Register>(); |
| 3353 | Location cls = locations->InAt(1); |
| 3354 | Register out = locations->Out().As<Register>(); |
| 3355 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3356 | Label done, zero; |
| 3357 | SlowPathCodeX86* slow_path = nullptr; |
| 3358 | |
| 3359 | // Return 0 if `obj` is null. |
| 3360 | // TODO: avoid this check if we know obj is not null. |
| 3361 | __ testl(obj, obj); |
| 3362 | __ j(kEqual, &zero); |
| 3363 | __ movl(out, Address(obj, class_offset)); |
| 3364 | // Compare the class of `obj` with `cls`. |
| 3365 | if (cls.IsRegister()) { |
| 3366 | __ cmpl(out, cls.As<Register>()); |
| 3367 | } else { |
| 3368 | DCHECK(cls.IsStackSlot()) << cls; |
| 3369 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 3370 | } |
| 3371 | |
| 3372 | if (instruction->IsClassFinal()) { |
| 3373 | // Classes must be equal for the instanceof to succeed. |
| 3374 | __ j(kNotEqual, &zero); |
| 3375 | __ movl(out, Immediate(1)); |
| 3376 | __ jmp(&done); |
| 3377 | } else { |
| 3378 | // If the classes are not equal, we go into a slow path. |
| 3379 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 3380 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86( |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3381 | instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 3382 | codegen_->AddSlowPath(slow_path); |
| 3383 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 3384 | __ movl(out, Immediate(1)); |
| 3385 | __ jmp(&done); |
| 3386 | } |
| 3387 | __ Bind(&zero); |
| 3388 | __ movl(out, Immediate(0)); |
| 3389 | if (slow_path != nullptr) { |
| 3390 | __ Bind(slow_path->GetExitLabel()); |
| 3391 | } |
| 3392 | __ Bind(&done); |
| 3393 | } |
| 3394 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3395 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
| 3396 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 3397 | instruction, LocationSummary::kCallOnSlowPath); |
| 3398 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3399 | locations->SetInAt(1, Location::Any()); |
| 3400 | locations->AddTemp(Location::RequiresRegister()); |
| 3401 | } |
| 3402 | |
| 3403 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
| 3404 | LocationSummary* locations = instruction->GetLocations(); |
| 3405 | Register obj = locations->InAt(0).As<Register>(); |
| 3406 | Location cls = locations->InAt(1); |
| 3407 | Register temp = locations->GetTemp(0).As<Register>(); |
| 3408 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3409 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86( |
| 3410 | instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc()); |
| 3411 | codegen_->AddSlowPath(slow_path); |
| 3412 | |
| 3413 | // TODO: avoid this check if we know obj is not null. |
| 3414 | __ testl(obj, obj); |
| 3415 | __ j(kEqual, slow_path->GetExitLabel()); |
| 3416 | __ movl(temp, Address(obj, class_offset)); |
| 3417 | |
| 3418 | // Compare the class of `obj` with `cls`. |
| 3419 | if (cls.IsRegister()) { |
| 3420 | __ cmpl(temp, cls.As<Register>()); |
| 3421 | } else { |
| 3422 | DCHECK(cls.IsStackSlot()) << cls; |
| 3423 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 3424 | } |
| 3425 | |
| 3426 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 3427 | __ Bind(slow_path->GetExitLabel()); |
| 3428 | } |
| 3429 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 3430 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 3431 | LocationSummary* locations = |
| 3432 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3433 | InvokeRuntimeCallingConvention calling_convention; |
| 3434 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3435 | } |
| 3436 | |
| 3437 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 3438 | __ fs()->call(Address::Absolute(instruction->IsEnter() |
| 3439 | ? QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pLockObject) |
| 3440 | : QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pUnlockObject))); |
| 3441 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3442 | } |
| 3443 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3444 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 3445 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 3446 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 3447 | |
| 3448 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 3449 | LocationSummary* locations = |
| 3450 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3451 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 3452 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 3453 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3454 | locations->SetInAt(1, Location::Any()); |
| 3455 | locations->SetOut(Location::SameAsFirstInput()); |
| 3456 | } |
| 3457 | |
| 3458 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 3459 | HandleBitwiseOperation(instruction); |
| 3460 | } |
| 3461 | |
| 3462 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 3463 | HandleBitwiseOperation(instruction); |
| 3464 | } |
| 3465 | |
| 3466 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 3467 | HandleBitwiseOperation(instruction); |
| 3468 | } |
| 3469 | |
| 3470 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 3471 | LocationSummary* locations = instruction->GetLocations(); |
| 3472 | Location first = locations->InAt(0); |
| 3473 | Location second = locations->InAt(1); |
| 3474 | DCHECK(first.Equals(locations->Out())); |
| 3475 | |
| 3476 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 3477 | if (second.IsRegister()) { |
| 3478 | if (instruction->IsAnd()) { |
| 3479 | __ andl(first.As<Register>(), second.As<Register>()); |
| 3480 | } else if (instruction->IsOr()) { |
| 3481 | __ orl(first.As<Register>(), second.As<Register>()); |
| 3482 | } else { |
| 3483 | DCHECK(instruction->IsXor()); |
| 3484 | __ xorl(first.As<Register>(), second.As<Register>()); |
| 3485 | } |
| 3486 | } else if (second.IsConstant()) { |
| 3487 | if (instruction->IsAnd()) { |
| 3488 | __ andl(first.As<Register>(), Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 3489 | } else if (instruction->IsOr()) { |
| 3490 | __ orl(first.As<Register>(), Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 3491 | } else { |
| 3492 | DCHECK(instruction->IsXor()); |
| 3493 | __ xorl(first.As<Register>(), Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 3494 | } |
| 3495 | } else { |
| 3496 | if (instruction->IsAnd()) { |
| 3497 | __ andl(first.As<Register>(), Address(ESP, second.GetStackIndex())); |
| 3498 | } else if (instruction->IsOr()) { |
| 3499 | __ orl(first.As<Register>(), Address(ESP, second.GetStackIndex())); |
| 3500 | } else { |
| 3501 | DCHECK(instruction->IsXor()); |
| 3502 | __ xorl(first.As<Register>(), Address(ESP, second.GetStackIndex())); |
| 3503 | } |
| 3504 | } |
| 3505 | } else { |
| 3506 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3507 | if (second.IsRegisterPair()) { |
| 3508 | if (instruction->IsAnd()) { |
| 3509 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3510 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 3511 | } else if (instruction->IsOr()) { |
| 3512 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3513 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 3514 | } else { |
| 3515 | DCHECK(instruction->IsXor()); |
| 3516 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 3517 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 3518 | } |
| 3519 | } else { |
| 3520 | if (instruction->IsAnd()) { |
| 3521 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 3522 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 3523 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 3524 | } else if (instruction->IsOr()) { |
| 3525 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 3526 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 3527 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 3528 | } else { |
| 3529 | DCHECK(instruction->IsXor()); |
| 3530 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 3531 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 3532 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 3533 | } |
| 3534 | } |
| 3535 | } |
| 3536 | } |
| 3537 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 3538 | } // namespace x86 |
| 3539 | } // namespace art |