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