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