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