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