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