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