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