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