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