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