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