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