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