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