Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [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_64.h" |
| 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 | 9cf3552 | 2014-06-09 18:40:10 +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 | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 24 | #include "mirror/object_reference.h" |
| 25 | #include "thread.h" |
| 26 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 27 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 28 | #include "utils/x86_64/assembler_x86_64.h" |
| 29 | #include "utils/x86_64/managed_register_x86_64.h" |
| 30 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 31 | namespace art { |
| 32 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 33 | namespace x86_64 { |
| 34 | |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 35 | static constexpr bool kExplicitStackOverflowCheck = false; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 36 | |
| 37 | // Some x86_64 instructions require a register to be available as temp. |
| 38 | static constexpr Register TMP = R11; |
| 39 | |
| 40 | static constexpr int kNumberOfPushedRegistersAtEntry = 1; |
| 41 | static constexpr int kCurrentMethodStackOffset = 0; |
| 42 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 43 | static constexpr Register kRuntimeParameterCoreRegisters[] = { RDI, RSI, RDX }; |
| 44 | static constexpr size_t kRuntimeParameterCoreRegistersLength = |
| 45 | arraysize(kRuntimeParameterCoreRegisters); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 46 | static constexpr FloatRegister kRuntimeParameterFpuRegisters[] = { }; |
| 47 | static constexpr size_t kRuntimeParameterFpuRegistersLength = 0; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 48 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 49 | class InvokeRuntimeCallingConvention : public CallingConvention<Register, FloatRegister> { |
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 | }; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 60 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 61 | #define __ reinterpret_cast<X86_64Assembler*>(codegen->GetAssembler())-> |
| 62 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 63 | class SlowPathCodeX86_64 : public SlowPathCode { |
| 64 | public: |
| 65 | SlowPathCodeX86_64() : 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_64); |
| 75 | }; |
| 76 | |
| 77 | class NullCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
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_64(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()); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 83 | __ gs()->call( |
| 84 | Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pThrowNullPointer), true)); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 85 | codegen->RecordPcInfo(instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 89 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 90 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86_64); |
| 91 | }; |
| 92 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 93 | class DivZeroCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
| 94 | public: |
| 95 | explicit DivZeroCheckSlowPathX86_64(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 96 | |
| 97 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 98 | __ Bind(GetEntryLabel()); |
| 99 | __ gs()->call( |
| 100 | Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pThrowDivZero), true)); |
| 101 | codegen->RecordPcInfo(instruction_, instruction_->GetDexPc()); |
| 102 | } |
| 103 | |
| 104 | private: |
| 105 | HDivZeroCheck* const instruction_; |
| 106 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86_64); |
| 107 | }; |
| 108 | |
| 109 | class DivMinusOneSlowPathX86_64 : public SlowPathCodeX86_64 { |
| 110 | public: |
| 111 | explicit DivMinusOneSlowPathX86_64(Register reg) : reg_(reg) {} |
| 112 | |
| 113 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 114 | __ Bind(GetEntryLabel()); |
| 115 | __ negl(CpuRegister(reg_)); |
| 116 | __ jmp(GetExitLabel()); |
| 117 | } |
| 118 | |
| 119 | private: |
| 120 | Register reg_; |
| 121 | DISALLOW_COPY_AND_ASSIGN(DivMinusOneSlowPathX86_64); |
| 122 | }; |
| 123 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 124 | class StackOverflowCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 125 | public: |
| 126 | StackOverflowCheckSlowPathX86_64() {} |
| 127 | |
| 128 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 129 | __ Bind(GetEntryLabel()); |
| 130 | __ addq(CpuRegister(RSP), |
| 131 | Immediate(codegen->GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86_64WordSize)); |
| 132 | __ gs()->jmp( |
| 133 | Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pThrowStackOverflow), true)); |
| 134 | } |
| 135 | |
| 136 | private: |
| 137 | DISALLOW_COPY_AND_ASSIGN(StackOverflowCheckSlowPathX86_64); |
| 138 | }; |
| 139 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 140 | class SuspendCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 141 | public: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 142 | explicit SuspendCheckSlowPathX86_64(HSuspendCheck* instruction, HBasicBlock* successor) |
| 143 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 144 | |
| 145 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 146 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 147 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 148 | codegen->SaveLiveRegisters(instruction_->GetLocations()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 149 | __ gs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pTestSuspend), true)); |
| 150 | codegen->RecordPcInfo(instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 151 | codegen->RestoreLiveRegisters(instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 152 | if (successor_ == nullptr) { |
| 153 | __ jmp(GetReturnLabel()); |
| 154 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 155 | __ jmp(x64_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 156 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 157 | } |
| 158 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 159 | Label* GetReturnLabel() { |
| 160 | DCHECK(successor_ == nullptr); |
| 161 | return &return_label_; |
| 162 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 163 | |
| 164 | private: |
| 165 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 166 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 167 | Label return_label_; |
| 168 | |
| 169 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64); |
| 170 | }; |
| 171 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 172 | class BoundsCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 173 | public: |
Roland Levillain | 5799fc0 | 2014-09-25 12:15:20 +0100 | [diff] [blame] | 174 | BoundsCheckSlowPathX86_64(HBoundsCheck* instruction, |
| 175 | Location index_location, |
| 176 | Location length_location) |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 177 | : instruction_(instruction), |
| 178 | index_location_(index_location), |
| 179 | length_location_(length_location) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 180 | |
| 181 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 182 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 183 | __ Bind(GetEntryLabel()); |
| 184 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 185 | x64_codegen->Move( |
| 186 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), index_location_); |
| 187 | x64_codegen->Move( |
| 188 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), length_location_); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 189 | __ gs()->call(Address::Absolute( |
| 190 | QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pThrowArrayBounds), true)); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 191 | codegen->RecordPcInfo(instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 195 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 196 | const Location index_location_; |
| 197 | const Location length_location_; |
| 198 | |
| 199 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 200 | }; |
| 201 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 202 | class LoadClassSlowPathX86_64 : public SlowPathCodeX86_64 { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 203 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 204 | LoadClassSlowPathX86_64(HLoadClass* cls, |
| 205 | HInstruction* at, |
| 206 | uint32_t dex_pc, |
| 207 | bool do_clinit) |
| 208 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 209 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 210 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 211 | |
| 212 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 213 | LocationSummary* locations = at_->GetLocations(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 214 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 215 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 216 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 217 | codegen->SaveLiveRegisters(locations); |
| 218 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 219 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 220 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(cls_->GetTypeIndex())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 221 | x64_codegen->LoadCurrentMethod(CpuRegister(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 222 | __ gs()->call(Address::Absolute((do_clinit_ |
| 223 | ? QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pInitializeStaticStorage) |
| 224 | : QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pInitializeType)) , true)); |
| 225 | codegen->RecordPcInfo(at_, dex_pc_); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 226 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 227 | Location out = locations->Out(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 228 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 229 | if (out.IsValid()) { |
| 230 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 231 | x64_codegen->Move(out, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | codegen->RestoreLiveRegisters(locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 235 | __ jmp(GetExitLabel()); |
| 236 | } |
| 237 | |
| 238 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 239 | // The class this slow path will load. |
| 240 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 241 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 242 | // The instruction where this slow path is happening. |
| 243 | // (Might be the load class or an initialization check). |
| 244 | HInstruction* const at_; |
| 245 | |
| 246 | // The dex PC of `at_`. |
| 247 | const uint32_t dex_pc_; |
| 248 | |
| 249 | // Whether to initialize the class. |
| 250 | const bool do_clinit_; |
| 251 | |
| 252 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86_64); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 253 | }; |
| 254 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 255 | class LoadStringSlowPathX86_64 : public SlowPathCodeX86_64 { |
| 256 | public: |
| 257 | explicit LoadStringSlowPathX86_64(HLoadString* instruction) : instruction_(instruction) {} |
| 258 | |
| 259 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 260 | LocationSummary* locations = instruction_->GetLocations(); |
| 261 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 262 | |
| 263 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 264 | __ Bind(GetEntryLabel()); |
| 265 | codegen->SaveLiveRegisters(locations); |
| 266 | |
| 267 | InvokeRuntimeCallingConvention calling_convention; |
| 268 | x64_codegen->LoadCurrentMethod(CpuRegister(calling_convention.GetRegisterAt(0))); |
| 269 | __ movl(CpuRegister(calling_convention.GetRegisterAt(1)), |
| 270 | Immediate(instruction_->GetStringIndex())); |
| 271 | __ gs()->call(Address::Absolute( |
| 272 | QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pResolveString), true)); |
| 273 | codegen->RecordPcInfo(instruction_, instruction_->GetDexPc()); |
| 274 | x64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
| 275 | codegen->RestoreLiveRegisters(locations); |
| 276 | __ jmp(GetExitLabel()); |
| 277 | } |
| 278 | |
| 279 | private: |
| 280 | HLoadString* const instruction_; |
| 281 | |
| 282 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86_64); |
| 283 | }; |
| 284 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 285 | class TypeCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
| 286 | public: |
| 287 | TypeCheckSlowPathX86_64(HTypeCheck* instruction, Location object_class) |
| 288 | : instruction_(instruction), |
| 289 | object_class_(object_class) {} |
| 290 | |
| 291 | virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 292 | LocationSummary* locations = instruction_->GetLocations(); |
| 293 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 294 | |
| 295 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 296 | __ Bind(GetEntryLabel()); |
| 297 | codegen->SaveLiveRegisters(locations); |
| 298 | |
| 299 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 300 | // move resolver. |
| 301 | InvokeRuntimeCallingConvention calling_convention; |
| 302 | MoveOperands move1(locations->InAt(1), |
| 303 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 304 | nullptr); |
| 305 | MoveOperands move2(object_class_, |
| 306 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 307 | nullptr); |
| 308 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 309 | parallel_move.AddMove(&move1); |
| 310 | parallel_move.AddMove(&move2); |
| 311 | x64_codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 312 | |
| 313 | __ gs()->call( |
| 314 | Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pInstanceofNonTrivial), true)); |
| 315 | codegen->RecordPcInfo(instruction_, instruction_->GetDexPc()); |
| 316 | x64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
| 317 | |
| 318 | codegen->RestoreLiveRegisters(locations); |
| 319 | __ jmp(GetExitLabel()); |
| 320 | } |
| 321 | |
| 322 | private: |
| 323 | HTypeCheck* const instruction_; |
| 324 | const Location object_class_; |
| 325 | |
| 326 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86_64); |
| 327 | }; |
| 328 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 329 | #undef __ |
| 330 | #define __ reinterpret_cast<X86_64Assembler*>(GetAssembler())-> |
| 331 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 332 | inline Condition X86_64Condition(IfCondition cond) { |
| 333 | switch (cond) { |
| 334 | case kCondEQ: return kEqual; |
| 335 | case kCondNE: return kNotEqual; |
| 336 | case kCondLT: return kLess; |
| 337 | case kCondLE: return kLessEqual; |
| 338 | case kCondGT: return kGreater; |
| 339 | case kCondGE: return kGreaterEqual; |
| 340 | default: |
| 341 | LOG(FATAL) << "Unknown if condition"; |
| 342 | } |
| 343 | return kEqual; |
| 344 | } |
| 345 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 346 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
| 347 | stream << X86_64ManagedRegister::FromCpuRegister(Register(reg)); |
| 348 | } |
| 349 | |
| 350 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| 351 | stream << X86_64ManagedRegister::FromXmmRegister(FloatRegister(reg)); |
| 352 | } |
| 353 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 354 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 355 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 356 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 357 | } |
| 358 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 359 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 360 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 361 | return kX86_64WordSize; |
| 362 | } |
| 363 | |
| 364 | size_t CodeGeneratorX86_64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 365 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 366 | return kX86_64WordSize; |
| 367 | } |
| 368 | |
| 369 | size_t CodeGeneratorX86_64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 370 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 371 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 372 | } |
| 373 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 374 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph) |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 375 | : CodeGenerator(graph, kNumberOfCpuRegisters, kNumberOfFloatRegisters, 0), |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 376 | block_labels_(graph->GetArena(), 0), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 377 | location_builder_(graph, this), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 378 | instruction_visitor_(graph, this), |
| 379 | move_resolver_(graph->GetArena(), this) {} |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 380 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 381 | size_t CodeGeneratorX86_64::FrameEntrySpillSize() const { |
| 382 | return kNumberOfPushedRegistersAtEntry * kX86_64WordSize; |
| 383 | } |
| 384 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 385 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 386 | CodeGeneratorX86_64* codegen) |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 387 | : HGraphVisitor(graph), |
| 388 | assembler_(codegen->GetAssembler()), |
| 389 | codegen_(codegen) {} |
| 390 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 391 | Location CodeGeneratorX86_64::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 392 | switch (type) { |
| 393 | case Primitive::kPrimLong: |
| 394 | case Primitive::kPrimByte: |
| 395 | case Primitive::kPrimBoolean: |
| 396 | case Primitive::kPrimChar: |
| 397 | case Primitive::kPrimShort: |
| 398 | case Primitive::kPrimInt: |
| 399 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 400 | size_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfCpuRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 401 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 405 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 406 | size_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfFloatRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 407 | return Location::FpuRegisterLocation(reg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 408 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 409 | |
| 410 | case Primitive::kPrimVoid: |
| 411 | LOG(FATAL) << "Unreachable type " << type; |
| 412 | } |
| 413 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 414 | return Location(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 415 | } |
| 416 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 417 | void CodeGeneratorX86_64::SetupBlockedRegisters() const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 418 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 419 | blocked_core_registers_[RSP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 420 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 421 | // Block the register used as TMP. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 422 | blocked_core_registers_[TMP] = true; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 423 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 424 | // TODO: We currently don't use Quick's callee saved registers. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 425 | blocked_core_registers_[RBX] = true; |
| 426 | blocked_core_registers_[RBP] = true; |
| 427 | blocked_core_registers_[R12] = true; |
| 428 | blocked_core_registers_[R13] = true; |
| 429 | blocked_core_registers_[R14] = true; |
| 430 | blocked_core_registers_[R15] = true; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 431 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 432 | blocked_fpu_registers_[XMM12] = true; |
| 433 | blocked_fpu_registers_[XMM13] = true; |
| 434 | blocked_fpu_registers_[XMM14] = true; |
| 435 | blocked_fpu_registers_[XMM15] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 436 | } |
| 437 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 438 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
| 439 | // Create a fake register to mimic Quick. |
| 440 | static const int kFakeReturnRegister = 16; |
| 441 | core_spill_mask_ |= (1 << kFakeReturnRegister); |
| 442 | |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 443 | bool skip_overflow_check = IsLeafMethod() |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 444 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 445 | |
| 446 | if (!skip_overflow_check && !kExplicitStackOverflowCheck) { |
| 447 | __ testq(CpuRegister(RAX), Address( |
| 448 | CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 449 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 450 | } |
| 451 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 452 | // The return PC has already been pushed on the stack. |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 453 | __ subq(CpuRegister(RSP), |
| 454 | Immediate(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86_64WordSize)); |
| 455 | |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 456 | if (!skip_overflow_check && kExplicitStackOverflowCheck) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 457 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathX86_64(); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 458 | AddSlowPath(slow_path); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 459 | |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 460 | __ gs()->cmpq(CpuRegister(RSP), |
| 461 | Address::Absolute(Thread::StackEndOffset<kX86_64WordSize>(), true)); |
| 462 | __ j(kLess, slow_path->GetEntryLabel()); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 463 | } |
| 464 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 465 | __ movl(Address(CpuRegister(RSP), kCurrentMethodStackOffset), CpuRegister(RDI)); |
| 466 | } |
| 467 | |
| 468 | void CodeGeneratorX86_64::GenerateFrameExit() { |
| 469 | __ addq(CpuRegister(RSP), |
| 470 | Immediate(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86_64WordSize)); |
| 471 | } |
| 472 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 473 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 474 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 475 | } |
| 476 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 477 | void CodeGeneratorX86_64::LoadCurrentMethod(CpuRegister reg) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 478 | __ movl(reg, Address(CpuRegister(RSP), kCurrentMethodStackOffset)); |
| 479 | } |
| 480 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 481 | Location CodeGeneratorX86_64::GetStackLocation(HLoadLocal* load) const { |
| 482 | switch (load->GetType()) { |
| 483 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 484 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 485 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
| 486 | break; |
| 487 | |
| 488 | case Primitive::kPrimInt: |
| 489 | case Primitive::kPrimNot: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 490 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 491 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 492 | |
| 493 | case Primitive::kPrimBoolean: |
| 494 | case Primitive::kPrimByte: |
| 495 | case Primitive::kPrimChar: |
| 496 | case Primitive::kPrimShort: |
| 497 | case Primitive::kPrimVoid: |
| 498 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
| 499 | } |
| 500 | |
| 501 | LOG(FATAL) << "Unreachable"; |
| 502 | return Location(); |
| 503 | } |
| 504 | |
| 505 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 506 | if (source.Equals(destination)) { |
| 507 | return; |
| 508 | } |
| 509 | if (destination.IsRegister()) { |
| 510 | if (source.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 511 | __ movq(destination.As<CpuRegister>(), source.As<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 512 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 513 | __ movd(destination.As<CpuRegister>(), source.As<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 514 | } else if (source.IsStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 515 | __ movl(destination.As<CpuRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 516 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 517 | } else { |
| 518 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 519 | __ movq(destination.As<CpuRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 520 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 521 | } |
| 522 | } else if (destination.IsFpuRegister()) { |
| 523 | if (source.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 524 | __ movd(destination.As<XmmRegister>(), source.As<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 525 | } else if (source.IsFpuRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 526 | __ movaps(destination.As<XmmRegister>(), source.As<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 527 | } else if (source.IsStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 528 | __ movss(destination.As<XmmRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 529 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 530 | } else { |
| 531 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 532 | __ movsd(destination.As<XmmRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 533 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 534 | } |
| 535 | } else if (destination.IsStackSlot()) { |
| 536 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 537 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 538 | source.As<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 539 | } else if (source.IsFpuRegister()) { |
| 540 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 541 | source.As<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 542 | } else { |
| 543 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 544 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 545 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 546 | } |
| 547 | } else { |
| 548 | DCHECK(destination.IsDoubleStackSlot()); |
| 549 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 550 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 551 | source.As<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 552 | } else if (source.IsFpuRegister()) { |
| 553 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 554 | source.As<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 555 | } else { |
| 556 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 557 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 558 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 559 | } |
| 560 | } |
| 561 | } |
| 562 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 563 | void CodeGeneratorX86_64::Move(HInstruction* instruction, |
| 564 | Location location, |
| 565 | HInstruction* move_for) { |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 566 | if (instruction->IsIntConstant()) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 567 | Immediate imm(instruction->AsIntConstant()->GetValue()); |
| 568 | if (location.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 569 | __ movl(location.As<CpuRegister>(), imm); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 570 | } else if (location.IsStackSlot()) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 571 | __ movl(Address(CpuRegister(RSP), location.GetStackIndex()), imm); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 572 | } else { |
| 573 | DCHECK(location.IsConstant()); |
| 574 | DCHECK_EQ(location.GetConstant(), instruction); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 575 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 576 | } else if (instruction->IsLongConstant()) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 577 | int64_t value = instruction->AsLongConstant()->GetValue(); |
| 578 | if (location.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 579 | __ movq(location.As<CpuRegister>(), Immediate(value)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 580 | } else if (location.IsDoubleStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 581 | __ movq(CpuRegister(TMP), Immediate(value)); |
| 582 | __ movq(Address(CpuRegister(RSP), location.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 583 | } else { |
| 584 | DCHECK(location.IsConstant()); |
| 585 | DCHECK_EQ(location.GetConstant(), instruction); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 586 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 587 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 588 | switch (instruction->GetType()) { |
| 589 | case Primitive::kPrimBoolean: |
| 590 | case Primitive::kPrimByte: |
| 591 | case Primitive::kPrimChar: |
| 592 | case Primitive::kPrimShort: |
| 593 | case Primitive::kPrimInt: |
| 594 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 595 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 596 | Move(location, Location::StackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
| 597 | break; |
| 598 | |
| 599 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 600 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 601 | Move(location, Location::DoubleStackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
| 602 | break; |
| 603 | |
| 604 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 605 | LOG(FATAL) << "Unexpected local type " << instruction->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 606 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 607 | } else if (instruction->IsTemporary()) { |
| 608 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
| 609 | Move(location, temp_location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 610 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 611 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 612 | switch (instruction->GetType()) { |
| 613 | case Primitive::kPrimBoolean: |
| 614 | case Primitive::kPrimByte: |
| 615 | case Primitive::kPrimChar: |
| 616 | case Primitive::kPrimShort: |
| 617 | case Primitive::kPrimInt: |
| 618 | case Primitive::kPrimNot: |
| 619 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 620 | case Primitive::kPrimFloat: |
| 621 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 622 | Move(location, instruction->GetLocations()->Out()); |
| 623 | break; |
| 624 | |
| 625 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 626 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 627 | } |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 632 | got->SetLocations(nullptr); |
| 633 | } |
| 634 | |
| 635 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 636 | HBasicBlock* successor = got->GetSuccessor(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 637 | DCHECK(!successor->IsExitBlock()); |
| 638 | |
| 639 | HBasicBlock* block = got->GetBlock(); |
| 640 | HInstruction* previous = got->GetPrevious(); |
| 641 | |
| 642 | HLoopInformation* info = block->GetLoopInformation(); |
| 643 | if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) { |
| 644 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck()); |
| 645 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 646 | return; |
| 647 | } |
| 648 | |
| 649 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 650 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 651 | } |
| 652 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 653 | __ jmp(codegen_->GetLabelOf(successor)); |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 658 | exit->SetLocations(nullptr); |
| 659 | } |
| 660 | |
| 661 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 662 | UNUSED(exit); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 663 | if (kIsDebugBuild) { |
| 664 | __ Comment("Unreachable"); |
| 665 | __ int3(); |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 670 | LocationSummary* locations = |
| 671 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 672 | HInstruction* cond = if_instr->InputAt(0); |
Nicolas Geoffray | 01ef345 | 2014-10-01 11:32:17 +0100 | [diff] [blame] | 673 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 674 | locations->SetInAt(0, Location::Any()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 675 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 679 | HInstruction* cond = if_instr->InputAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 680 | if (cond->IsIntConstant()) { |
| 681 | // Constant condition, statically compared against 1. |
| 682 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 683 | if (cond_value == 1) { |
| 684 | if (!codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 685 | if_instr->IfTrueSuccessor())) { |
| 686 | __ jmp(codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 687 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 688 | return; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 689 | } else { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 690 | DCHECK_EQ(cond_value, 0); |
| 691 | } |
| 692 | } else { |
| 693 | bool materialized = |
| 694 | !cond->IsCondition() || cond->AsCondition()->NeedsMaterialization(); |
| 695 | // Moves do not affect the eflags register, so if the condition is |
| 696 | // evaluated just before the if, we don't need to evaluate it |
| 697 | // again. |
| 698 | bool eflags_set = cond->IsCondition() |
| 699 | && cond->AsCondition()->IsBeforeWhenDisregardMoves(if_instr); |
| 700 | if (materialized) { |
| 701 | if (!eflags_set) { |
| 702 | // Materialized condition, compare against 0. |
| 703 | Location lhs = if_instr->GetLocations()->InAt(0); |
| 704 | if (lhs.IsRegister()) { |
| 705 | __ cmpl(lhs.As<CpuRegister>(), Immediate(0)); |
| 706 | } else { |
| 707 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), |
| 708 | Immediate(0)); |
| 709 | } |
| 710 | __ j(kNotEqual, codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
| 711 | } else { |
| 712 | __ j(X86_64Condition(cond->AsCondition()->GetCondition()), |
| 713 | codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
| 714 | } |
| 715 | } else { |
| 716 | Location lhs = cond->GetLocations()->InAt(0); |
| 717 | Location rhs = cond->GetLocations()->InAt(1); |
| 718 | if (rhs.IsRegister()) { |
| 719 | __ cmpl(lhs.As<CpuRegister>(), rhs.As<CpuRegister>()); |
| 720 | } else if (rhs.IsConstant()) { |
| 721 | __ cmpl(lhs.As<CpuRegister>(), |
| 722 | Immediate(rhs.GetConstant()->AsIntConstant()->GetValue())); |
| 723 | } else { |
| 724 | __ cmpl(lhs.As<CpuRegister>(), |
| 725 | Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 726 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 727 | __ j(X86_64Condition(cond->AsCondition()->GetCondition()), |
| 728 | codegen_->GetLabelOf(if_instr->IfTrueSuccessor())); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 729 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 730 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 731 | if (!codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 732 | if_instr->IfFalseSuccessor())) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 733 | __ jmp(codegen_->GetLabelOf(if_instr->IfFalseSuccessor())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 734 | } |
| 735 | } |
| 736 | |
| 737 | void LocationsBuilderX86_64::VisitLocal(HLocal* local) { |
| 738 | local->SetLocations(nullptr); |
| 739 | } |
| 740 | |
| 741 | void InstructionCodeGeneratorX86_64::VisitLocal(HLocal* local) { |
| 742 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
| 743 | } |
| 744 | |
| 745 | void LocationsBuilderX86_64::VisitLoadLocal(HLoadLocal* local) { |
| 746 | local->SetLocations(nullptr); |
| 747 | } |
| 748 | |
| 749 | void InstructionCodeGeneratorX86_64::VisitLoadLocal(HLoadLocal* load) { |
| 750 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 751 | UNUSED(load); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | void LocationsBuilderX86_64::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 755 | LocationSummary* locations = |
| 756 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 757 | switch (store->InputAt(1)->GetType()) { |
| 758 | case Primitive::kPrimBoolean: |
| 759 | case Primitive::kPrimByte: |
| 760 | case Primitive::kPrimChar: |
| 761 | case Primitive::kPrimShort: |
| 762 | case Primitive::kPrimInt: |
| 763 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 764 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 765 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 766 | break; |
| 767 | |
| 768 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 769 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 770 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 771 | break; |
| 772 | |
| 773 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 774 | LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 775 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | void InstructionCodeGeneratorX86_64::VisitStoreLocal(HStoreLocal* store) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 779 | UNUSED(store); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 780 | } |
| 781 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 782 | void LocationsBuilderX86_64::VisitCondition(HCondition* comp) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 783 | LocationSummary* locations = |
| 784 | new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 785 | locations->SetInAt(0, Location::RequiresRegister()); |
| 786 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 787 | if (comp->NeedsMaterialization()) { |
| 788 | locations->SetOut(Location::RequiresRegister()); |
| 789 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 790 | } |
| 791 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 792 | void InstructionCodeGeneratorX86_64::VisitCondition(HCondition* comp) { |
| 793 | if (comp->NeedsMaterialization()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 794 | LocationSummary* locations = comp->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 795 | CpuRegister reg = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 796 | // Clear register: setcc only sets the low byte. |
| 797 | __ xorq(reg, reg); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 798 | if (locations->InAt(1).IsRegister()) { |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 799 | __ cmpl(locations->InAt(0).As<CpuRegister>(), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 800 | locations->InAt(1).As<CpuRegister>()); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 801 | } else if (locations->InAt(1).IsConstant()) { |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 802 | __ cmpl(locations->InAt(0).As<CpuRegister>(), |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 803 | Immediate(locations->InAt(1).GetConstant()->AsIntConstant()->GetValue())); |
| 804 | } else { |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 805 | __ cmpl(locations->InAt(0).As<CpuRegister>(), |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 806 | Address(CpuRegister(RSP), locations->InAt(1).GetStackIndex())); |
| 807 | } |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 808 | __ setcc(X86_64Condition(comp->GetCondition()), reg); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 809 | } |
| 810 | } |
| 811 | |
| 812 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
| 813 | VisitCondition(comp); |
| 814 | } |
| 815 | |
| 816 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
| 817 | VisitCondition(comp); |
| 818 | } |
| 819 | |
| 820 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
| 821 | VisitCondition(comp); |
| 822 | } |
| 823 | |
| 824 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
| 825 | VisitCondition(comp); |
| 826 | } |
| 827 | |
| 828 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
| 829 | VisitCondition(comp); |
| 830 | } |
| 831 | |
| 832 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
| 833 | VisitCondition(comp); |
| 834 | } |
| 835 | |
| 836 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 837 | VisitCondition(comp); |
| 838 | } |
| 839 | |
| 840 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 841 | VisitCondition(comp); |
| 842 | } |
| 843 | |
| 844 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| 845 | VisitCondition(comp); |
| 846 | } |
| 847 | |
| 848 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| 849 | VisitCondition(comp); |
| 850 | } |
| 851 | |
| 852 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 853 | VisitCondition(comp); |
| 854 | } |
| 855 | |
| 856 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 857 | VisitCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 858 | } |
| 859 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 860 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 861 | LocationSummary* locations = |
| 862 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 863 | locations->SetInAt(0, Location::RequiresRegister()); |
| 864 | locations->SetInAt(1, Location::RequiresRegister()); |
| 865 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
| 869 | Label greater, done; |
| 870 | LocationSummary* locations = compare->GetLocations(); |
| 871 | switch (compare->InputAt(0)->GetType()) { |
| 872 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 873 | __ cmpq(locations->InAt(0).As<CpuRegister>(), |
| 874 | locations->InAt(1).As<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 875 | break; |
| 876 | default: |
| 877 | LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType(); |
| 878 | } |
| 879 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 880 | CpuRegister output = locations->Out().As<CpuRegister>(); |
| 881 | __ movl(output, Immediate(0)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 882 | __ j(kEqual, &done); |
| 883 | __ j(kGreater, &greater); |
| 884 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 885 | __ movl(output, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 886 | __ jmp(&done); |
| 887 | |
| 888 | __ Bind(&greater); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 889 | __ movl(output, Immediate(1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 890 | |
| 891 | __ Bind(&done); |
| 892 | } |
| 893 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 894 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 895 | LocationSummary* locations = |
| 896 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 897 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 901 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 902 | UNUSED(constant); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 906 | LocationSummary* locations = |
| 907 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 908 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 912 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 913 | UNUSED(constant); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 914 | } |
| 915 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 916 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 917 | LocationSummary* locations = |
| 918 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 919 | locations->SetOut(Location::ConstantLocation(constant)); |
| 920 | } |
| 921 | |
| 922 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 923 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 924 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 928 | LocationSummary* locations = |
| 929 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 930 | locations->SetOut(Location::ConstantLocation(constant)); |
| 931 | } |
| 932 | |
| 933 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 934 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 935 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 936 | } |
| 937 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 938 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 939 | ret->SetLocations(nullptr); |
| 940 | } |
| 941 | |
| 942 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 943 | UNUSED(ret); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 944 | codegen_->GenerateFrameExit(); |
| 945 | __ ret(); |
| 946 | } |
| 947 | |
| 948 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 949 | LocationSummary* locations = |
| 950 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 951 | switch (ret->InputAt(0)->GetType()) { |
| 952 | case Primitive::kPrimBoolean: |
| 953 | case Primitive::kPrimByte: |
| 954 | case Primitive::kPrimChar: |
| 955 | case Primitive::kPrimShort: |
| 956 | case Primitive::kPrimInt: |
| 957 | case Primitive::kPrimNot: |
| 958 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 959 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 960 | break; |
| 961 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 962 | case Primitive::kPrimFloat: |
| 963 | case Primitive::kPrimDouble: |
| 964 | locations->SetInAt(0, |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 965 | Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 966 | break; |
| 967 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 968 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 969 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 970 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 974 | if (kIsDebugBuild) { |
| 975 | switch (ret->InputAt(0)->GetType()) { |
| 976 | case Primitive::kPrimBoolean: |
| 977 | case Primitive::kPrimByte: |
| 978 | case Primitive::kPrimChar: |
| 979 | case Primitive::kPrimShort: |
| 980 | case Primitive::kPrimInt: |
| 981 | case Primitive::kPrimNot: |
| 982 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 983 | DCHECK_EQ(ret->GetLocations()->InAt(0).As<CpuRegister>().AsRegister(), RAX); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 984 | break; |
| 985 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 986 | case Primitive::kPrimFloat: |
| 987 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 988 | DCHECK_EQ(ret->GetLocations()->InAt(0).As<XmmRegister>().AsFloatRegister(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 989 | XMM0); |
| 990 | break; |
| 991 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 992 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 993 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 994 | } |
| 995 | } |
| 996 | codegen_->GenerateFrameExit(); |
| 997 | __ ret(); |
| 998 | } |
| 999 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1000 | Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) { |
| 1001 | switch (type) { |
| 1002 | case Primitive::kPrimBoolean: |
| 1003 | case Primitive::kPrimByte: |
| 1004 | case Primitive::kPrimChar: |
| 1005 | case Primitive::kPrimShort: |
| 1006 | case Primitive::kPrimInt: |
| 1007 | case Primitive::kPrimNot: { |
| 1008 | uint32_t index = gp_index_++; |
| 1009 | stack_index_++; |
| 1010 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1011 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1012 | } else { |
| 1013 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | case Primitive::kPrimLong: { |
| 1018 | uint32_t index = gp_index_; |
| 1019 | stack_index_ += 2; |
| 1020 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 1021 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1022 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1023 | } else { |
| 1024 | gp_index_ += 2; |
| 1025 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1026 | } |
| 1027 | } |
| 1028 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1029 | case Primitive::kPrimFloat: { |
| 1030 | uint32_t index = fp_index_++; |
| 1031 | stack_index_++; |
| 1032 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1033 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1034 | } else { |
| 1035 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1036 | } |
| 1037 | } |
| 1038 | |
| 1039 | case Primitive::kPrimDouble: { |
| 1040 | uint32_t index = fp_index_++; |
| 1041 | stack_index_ += 2; |
| 1042 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1043 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1044 | } else { |
| 1045 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1046 | } |
| 1047 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1048 | |
| 1049 | case Primitive::kPrimVoid: |
| 1050 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1051 | break; |
| 1052 | } |
| 1053 | return Location(); |
| 1054 | } |
| 1055 | |
| 1056 | void LocationsBuilderX86_64::VisitInvokeStatic(HInvokeStatic* invoke) { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1057 | HandleInvoke(invoke); |
| 1058 | } |
| 1059 | |
| 1060 | void InstructionCodeGeneratorX86_64::VisitInvokeStatic(HInvokeStatic* invoke) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1061 | CpuRegister temp = invoke->GetLocations()->GetTemp(0).As<CpuRegister>(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1062 | // TODO: Implement all kinds of calls: |
| 1063 | // 1) boot -> boot |
| 1064 | // 2) app -> boot |
| 1065 | // 3) app -> app |
| 1066 | // |
| 1067 | // Currently we implement the app -> app logic, which looks up in the resolve cache. |
| 1068 | |
| 1069 | // temp = method; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1070 | codegen_->LoadCurrentMethod(temp); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1071 | // temp = temp->dex_cache_resolved_methods_; |
| 1072 | __ movl(temp, Address(temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().SizeValue())); |
| 1073 | // temp = temp[index_in_cache] |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1074 | __ movl(temp, Address(temp, CodeGenerator::GetCacheOffset(invoke->GetIndexInDexCache()))); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1075 | // (temp + offset_of_quick_compiled_code)() |
| 1076 | __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().SizeValue())); |
| 1077 | |
| 1078 | DCHECK(!codegen_->IsLeafMethod()); |
| 1079 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1080 | } |
| 1081 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1082 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1083 | LocationSummary* locations = |
| 1084 | new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1085 | locations->AddTemp(Location::RegisterLocation(RDI)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1086 | |
| 1087 | InvokeDexCallingConventionVisitor calling_convention_visitor; |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1088 | for (size_t i = 0; i < invoke->InputCount(); i++) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1089 | HInstruction* input = invoke->InputAt(i); |
| 1090 | locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType())); |
| 1091 | } |
| 1092 | |
| 1093 | switch (invoke->GetType()) { |
| 1094 | case Primitive::kPrimBoolean: |
| 1095 | case Primitive::kPrimByte: |
| 1096 | case Primitive::kPrimChar: |
| 1097 | case Primitive::kPrimShort: |
| 1098 | case Primitive::kPrimInt: |
| 1099 | case Primitive::kPrimNot: |
| 1100 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1101 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1102 | break; |
| 1103 | |
| 1104 | case Primitive::kPrimVoid: |
| 1105 | break; |
| 1106 | |
| 1107 | case Primitive::kPrimDouble: |
| 1108 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1109 | locations->SetOut(Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1110 | break; |
| 1111 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1112 | } |
| 1113 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1114 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 1115 | HandleInvoke(invoke); |
| 1116 | } |
| 1117 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1118 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1119 | CpuRegister temp = invoke->GetLocations()->GetTemp(0).As<CpuRegister>(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1120 | size_t method_offset = mirror::Class::EmbeddedVTableOffset().SizeValue() + |
| 1121 | invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry); |
| 1122 | LocationSummary* locations = invoke->GetLocations(); |
| 1123 | Location receiver = locations->InAt(0); |
| 1124 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 1125 | // temp = object->GetClass(); |
| 1126 | if (receiver.IsStackSlot()) { |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1127 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
| 1128 | __ movl(temp, Address(temp, class_offset)); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1129 | } else { |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1130 | __ movl(temp, Address(receiver.As<CpuRegister>(), class_offset)); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1131 | } |
| 1132 | // temp = temp->GetMethodAt(method_offset); |
| 1133 | __ movl(temp, Address(temp, method_offset)); |
| 1134 | // call temp->GetEntryPoint(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1135 | __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().SizeValue())); |
| 1136 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1137 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1138 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1139 | } |
| 1140 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1141 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1142 | HandleInvoke(invoke); |
| 1143 | // Add the hidden argument. |
| 1144 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 1145 | } |
| 1146 | |
| 1147 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1148 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 1149 | CpuRegister temp = invoke->GetLocations()->GetTemp(0).As<CpuRegister>(); |
| 1150 | uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() + |
| 1151 | (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry); |
| 1152 | LocationSummary* locations = invoke->GetLocations(); |
| 1153 | Location receiver = locations->InAt(0); |
| 1154 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 1155 | |
| 1156 | // Set the hidden argument. |
| 1157 | __ movq(invoke->GetLocations()->GetTemp(1).As<CpuRegister>(), |
| 1158 | Immediate(invoke->GetDexMethodIndex())); |
| 1159 | |
| 1160 | // temp = object->GetClass(); |
| 1161 | if (receiver.IsStackSlot()) { |
| 1162 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
| 1163 | __ movl(temp, Address(temp, class_offset)); |
| 1164 | } else { |
| 1165 | __ movl(temp, Address(receiver.As<CpuRegister>(), class_offset)); |
| 1166 | } |
| 1167 | // temp = temp->GetImtEntryAt(method_offset); |
| 1168 | __ movl(temp, Address(temp, method_offset)); |
| 1169 | // call temp->GetEntryPoint(); |
| 1170 | __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().SizeValue())); |
| 1171 | |
| 1172 | DCHECK(!codegen_->IsLeafMethod()); |
| 1173 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1174 | } |
| 1175 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1176 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 1177 | LocationSummary* locations = |
| 1178 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1179 | switch (neg->GetResultType()) { |
| 1180 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1181 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1182 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1183 | locations->SetOut(Location::SameAsFirstInput()); |
| 1184 | break; |
| 1185 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1186 | case Primitive::kPrimFloat: |
| 1187 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1188 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1189 | // Output overlaps as we need a fresh (zero-initialized) |
| 1190 | // register to perform subtraction from zero. |
| 1191 | locations->SetOut(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1192 | break; |
| 1193 | |
| 1194 | default: |
| 1195 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1196 | } |
| 1197 | } |
| 1198 | |
| 1199 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 1200 | LocationSummary* locations = neg->GetLocations(); |
| 1201 | Location out = locations->Out(); |
| 1202 | Location in = locations->InAt(0); |
| 1203 | switch (neg->GetResultType()) { |
| 1204 | case Primitive::kPrimInt: |
| 1205 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1206 | DCHECK(in.Equals(out)); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1207 | __ negl(out.As<CpuRegister>()); |
| 1208 | break; |
| 1209 | |
| 1210 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1211 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1212 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1213 | __ negq(out.As<CpuRegister>()); |
| 1214 | break; |
| 1215 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1216 | case Primitive::kPrimFloat: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1217 | DCHECK(in.IsFpuRegister()); |
| 1218 | DCHECK(out.IsFpuRegister()); |
| 1219 | DCHECK(!in.Equals(out)); |
| 1220 | // TODO: Instead of computing negation as a subtraction from |
| 1221 | // zero, implement it with an exclusive or with value 0x80000000 |
| 1222 | // (mask for bit 31, representing the sign of a single-precision |
| 1223 | // floating-point number), fetched from a constant pool: |
| 1224 | // |
| 1225 | // xorps out, [RIP:...] // value at RIP is 0x80 00 00 00 |
| 1226 | |
| 1227 | // out = 0 |
| 1228 | __ xorps(out.As<XmmRegister>(), out.As<XmmRegister>()); |
| 1229 | // out = out - in |
| 1230 | __ subss(out.As<XmmRegister>(), in.As<XmmRegister>()); |
| 1231 | break; |
| 1232 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1233 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1234 | DCHECK(in.IsFpuRegister()); |
| 1235 | DCHECK(out.IsFpuRegister()); |
| 1236 | DCHECK(!in.Equals(out)); |
| 1237 | // TODO: Instead of computing negation as a subtraction from |
| 1238 | // zero, implement it with an exclusive or with value |
| 1239 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 1240 | // a double-precision floating-point number), fetched from a |
| 1241 | // constant pool: |
| 1242 | // |
| 1243 | // xorpd out, [RIP:...] // value at RIP is 0x80 00 00 00 00 00 00 00 |
| 1244 | |
| 1245 | // out = 0 |
| 1246 | __ xorpd(out.As<XmmRegister>(), out.As<XmmRegister>()); |
| 1247 | // out = out - in |
| 1248 | __ subsd(out.As<XmmRegister>(), in.As<XmmRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1249 | break; |
| 1250 | |
| 1251 | default: |
| 1252 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1253 | } |
| 1254 | } |
| 1255 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1256 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 1257 | LocationSummary* locations = |
| 1258 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 1259 | Primitive::Type result_type = conversion->GetResultType(); |
| 1260 | Primitive::Type input_type = conversion->GetInputType(); |
| 1261 | switch (result_type) { |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame^] | 1262 | case Primitive::kPrimInt: |
| 1263 | switch (input_type) { |
| 1264 | case Primitive::kPrimLong: |
| 1265 | // long-to-int conversion. |
| 1266 | locations->SetInAt(0, Location::Any()); |
| 1267 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1268 | break; |
| 1269 | |
| 1270 | case Primitive::kPrimFloat: |
| 1271 | case Primitive::kPrimDouble: |
| 1272 | LOG(FATAL) << "Type conversion from " << input_type |
| 1273 | << " to " << result_type << " not yet implemented"; |
| 1274 | break; |
| 1275 | |
| 1276 | default: |
| 1277 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1278 | << " to " << result_type; |
| 1279 | } |
| 1280 | break; |
| 1281 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1282 | case Primitive::kPrimLong: |
| 1283 | switch (input_type) { |
| 1284 | case Primitive::kPrimByte: |
| 1285 | case Primitive::kPrimShort: |
| 1286 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1287 | case Primitive::kPrimChar: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1288 | // int-to-long conversion. |
| 1289 | // TODO: We would benefit from a (to-be-implemented) |
| 1290 | // Location::RegisterOrStackSlot requirement for this input. |
| 1291 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1292 | locations->SetOut(Location::RequiresRegister()); |
| 1293 | break; |
| 1294 | |
| 1295 | case Primitive::kPrimFloat: |
| 1296 | case Primitive::kPrimDouble: |
| 1297 | LOG(FATAL) << "Type conversion from " << input_type << " to " |
| 1298 | << result_type << " not yet implemented"; |
| 1299 | break; |
| 1300 | |
| 1301 | default: |
| 1302 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1303 | << " to " << result_type; |
| 1304 | } |
| 1305 | break; |
| 1306 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1307 | case Primitive::kPrimFloat: |
| 1308 | case Primitive::kPrimDouble: |
| 1309 | LOG(FATAL) << "Type conversion from " << input_type |
| 1310 | << " to " << result_type << " not yet implemented"; |
| 1311 | break; |
| 1312 | |
| 1313 | default: |
| 1314 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1315 | << " to " << result_type; |
| 1316 | } |
| 1317 | } |
| 1318 | |
| 1319 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 1320 | LocationSummary* locations = conversion->GetLocations(); |
| 1321 | Location out = locations->Out(); |
| 1322 | Location in = locations->InAt(0); |
| 1323 | Primitive::Type result_type = conversion->GetResultType(); |
| 1324 | Primitive::Type input_type = conversion->GetInputType(); |
| 1325 | switch (result_type) { |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame^] | 1326 | case Primitive::kPrimInt: |
| 1327 | switch (input_type) { |
| 1328 | case Primitive::kPrimLong: |
| 1329 | // long-to-int conversion. |
| 1330 | if (in.IsRegister()) { |
| 1331 | __ movl(out.As<CpuRegister>(), in.As<CpuRegister>()); |
| 1332 | } else if (in.IsDoubleStackSlot()) { |
| 1333 | __ movl(out.As<CpuRegister>(), |
| 1334 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 1335 | } else { |
| 1336 | DCHECK(in.IsConstant()); |
| 1337 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 1338 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 1339 | __ movl(out.As<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 1340 | } |
| 1341 | break; |
| 1342 | |
| 1343 | case Primitive::kPrimFloat: |
| 1344 | case Primitive::kPrimDouble: |
| 1345 | LOG(FATAL) << "Type conversion from " << input_type |
| 1346 | << " to " << result_type << " not yet implemented"; |
| 1347 | break; |
| 1348 | |
| 1349 | default: |
| 1350 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1351 | << " to " << result_type; |
| 1352 | } |
| 1353 | break; |
| 1354 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1355 | case Primitive::kPrimLong: |
| 1356 | switch (input_type) { |
| 1357 | DCHECK(out.IsRegister()); |
| 1358 | case Primitive::kPrimByte: |
| 1359 | case Primitive::kPrimShort: |
| 1360 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1361 | case Primitive::kPrimChar: |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1362 | // int-to-long conversion. |
| 1363 | DCHECK(in.IsRegister()); |
| 1364 | __ movsxd(out.As<CpuRegister>(), in.As<CpuRegister>()); |
| 1365 | break; |
| 1366 | |
| 1367 | case Primitive::kPrimFloat: |
| 1368 | case Primitive::kPrimDouble: |
| 1369 | LOG(FATAL) << "Type conversion from " << input_type << " to " |
| 1370 | << result_type << " not yet implemented"; |
| 1371 | break; |
| 1372 | |
| 1373 | default: |
| 1374 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1375 | << " to " << result_type; |
| 1376 | } |
| 1377 | break; |
| 1378 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1379 | case Primitive::kPrimFloat: |
| 1380 | case Primitive::kPrimDouble: |
| 1381 | LOG(FATAL) << "Type conversion from " << input_type |
| 1382 | << " to " << result_type << " not yet implemented"; |
| 1383 | break; |
| 1384 | |
| 1385 | default: |
| 1386 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1387 | << " to " << result_type; |
| 1388 | } |
| 1389 | } |
| 1390 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1391 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1392 | LocationSummary* locations = |
| 1393 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1394 | switch (add->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1395 | case Primitive::kPrimInt: { |
| 1396 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1397 | locations->SetInAt(1, Location::Any()); |
| 1398 | locations->SetOut(Location::SameAsFirstInput()); |
| 1399 | break; |
| 1400 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1401 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1402 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1403 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1404 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1405 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1406 | break; |
| 1407 | } |
| 1408 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1409 | case Primitive::kPrimDouble: |
| 1410 | case Primitive::kPrimFloat: { |
| 1411 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1412 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1413 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1414 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1415 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1416 | |
| 1417 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1418 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1419 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 1423 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1424 | Location first = locations->InAt(0); |
| 1425 | Location second = locations->InAt(1); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1426 | DCHECK(first.Equals(locations->Out())); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1427 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1428 | switch (add->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1429 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1430 | if (second.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1431 | __ addl(first.As<CpuRegister>(), second.As<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1432 | } else if (second.IsConstant()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1433 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1434 | __ addl(first.As<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1435 | } else { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1436 | __ addl(first.As<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1437 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1438 | break; |
| 1439 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1440 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1441 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1442 | __ addq(first.As<CpuRegister>(), second.As<CpuRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1443 | break; |
| 1444 | } |
| 1445 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1446 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1447 | __ addss(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1448 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1449 | } |
| 1450 | |
| 1451 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1452 | __ addsd(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1453 | break; |
| 1454 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1455 | |
| 1456 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1457 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1458 | } |
| 1459 | } |
| 1460 | |
| 1461 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1462 | LocationSummary* locations = |
| 1463 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1464 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1465 | case Primitive::kPrimInt: { |
| 1466 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1467 | locations->SetInAt(1, Location::Any()); |
| 1468 | locations->SetOut(Location::SameAsFirstInput()); |
| 1469 | break; |
| 1470 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1471 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1472 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1473 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1474 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1475 | break; |
| 1476 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1477 | case Primitive::kPrimFloat: |
| 1478 | case Primitive::kPrimDouble: { |
| 1479 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1480 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1481 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1482 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1483 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1484 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1485 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1486 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 1490 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1491 | Location first = locations->InAt(0); |
| 1492 | Location second = locations->InAt(1); |
| 1493 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1494 | switch (sub->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1495 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1496 | if (second.IsRegister()) { |
| 1497 | __ subl(first.As<CpuRegister>(), second.As<CpuRegister>()); |
| 1498 | } else if (second.IsConstant()) { |
| 1499 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 1500 | __ subl(first.As<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1501 | } else { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1502 | __ subl(first.As<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1503 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1504 | break; |
| 1505 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1506 | case Primitive::kPrimLong: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1507 | __ subq(first.As<CpuRegister>(), second.As<CpuRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1508 | break; |
| 1509 | } |
| 1510 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1511 | case Primitive::kPrimFloat: { |
| 1512 | __ subss(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1513 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1514 | } |
| 1515 | |
| 1516 | case Primitive::kPrimDouble: { |
| 1517 | __ subsd(first.As<XmmRegister>(), second.As<XmmRegister>()); |
| 1518 | break; |
| 1519 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1520 | |
| 1521 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1522 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1523 | } |
| 1524 | } |
| 1525 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1526 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 1527 | LocationSummary* locations = |
| 1528 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 1529 | switch (mul->GetResultType()) { |
| 1530 | case Primitive::kPrimInt: { |
| 1531 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1532 | locations->SetInAt(1, Location::Any()); |
| 1533 | locations->SetOut(Location::SameAsFirstInput()); |
| 1534 | break; |
| 1535 | } |
| 1536 | case Primitive::kPrimLong: { |
| 1537 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1538 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1539 | locations->SetOut(Location::SameAsFirstInput()); |
| 1540 | break; |
| 1541 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1542 | case Primitive::kPrimFloat: |
| 1543 | case Primitive::kPrimDouble: { |
| 1544 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1545 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1546 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1547 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1548 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1549 | |
| 1550 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1551 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1552 | } |
| 1553 | } |
| 1554 | |
| 1555 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 1556 | LocationSummary* locations = mul->GetLocations(); |
| 1557 | Location first = locations->InAt(0); |
| 1558 | Location second = locations->InAt(1); |
| 1559 | DCHECK(first.Equals(locations->Out())); |
| 1560 | switch (mul->GetResultType()) { |
| 1561 | case Primitive::kPrimInt: { |
| 1562 | if (second.IsRegister()) { |
| 1563 | __ imull(first.As<CpuRegister>(), second.As<CpuRegister>()); |
| 1564 | } else if (second.IsConstant()) { |
| 1565 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 1566 | __ imull(first.As<CpuRegister>(), imm); |
| 1567 | } else { |
| 1568 | DCHECK(second.IsStackSlot()); |
| 1569 | __ imull(first.As<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
| 1570 | } |
| 1571 | break; |
| 1572 | } |
| 1573 | case Primitive::kPrimLong: { |
| 1574 | __ imulq(first.As<CpuRegister>(), second.As<CpuRegister>()); |
| 1575 | break; |
| 1576 | } |
| 1577 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1578 | case Primitive::kPrimFloat: { |
| 1579 | __ mulss(first.As<XmmRegister>(), second.As<XmmRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1580 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1581 | } |
| 1582 | |
| 1583 | case Primitive::kPrimDouble: { |
| 1584 | __ mulsd(first.As<XmmRegister>(), second.As<XmmRegister>()); |
| 1585 | break; |
| 1586 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1587 | |
| 1588 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 1589 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1590 | } |
| 1591 | } |
| 1592 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1593 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 1594 | LocationSummary* locations = |
| 1595 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 1596 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1597 | case Primitive::kPrimInt: { |
| 1598 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
| 1599 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1600 | locations->SetOut(Location::SameAsFirstInput()); |
| 1601 | // Intel uses edx:eax as the dividend. |
| 1602 | locations->AddTemp(Location::RegisterLocation(RDX)); |
| 1603 | break; |
| 1604 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1605 | case Primitive::kPrimLong: { |
| 1606 | LOG(FATAL) << "Not implemented div type" << div->GetResultType(); |
| 1607 | break; |
| 1608 | } |
| 1609 | case Primitive::kPrimFloat: |
| 1610 | case Primitive::kPrimDouble: { |
| 1611 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1612 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1613 | locations->SetOut(Location::SameAsFirstInput()); |
| 1614 | break; |
| 1615 | } |
| 1616 | |
| 1617 | default: |
| 1618 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 1619 | } |
| 1620 | } |
| 1621 | |
| 1622 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 1623 | LocationSummary* locations = div->GetLocations(); |
| 1624 | Location first = locations->InAt(0); |
| 1625 | Location second = locations->InAt(1); |
| 1626 | DCHECK(first.Equals(locations->Out())); |
| 1627 | |
| 1628 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1629 | case Primitive::kPrimInt: { |
| 1630 | CpuRegister first_reg = first.As<CpuRegister>(); |
| 1631 | CpuRegister second_reg = second.As<CpuRegister>(); |
| 1632 | DCHECK_EQ(RAX, first_reg.AsRegister()); |
| 1633 | DCHECK_EQ(RDX, locations->GetTemp(0).As<CpuRegister>().AsRegister()); |
| 1634 | |
| 1635 | SlowPathCodeX86_64* slow_path = |
| 1636 | new (GetGraph()->GetArena()) DivMinusOneSlowPathX86_64(first_reg.AsRegister()); |
| 1637 | codegen_->AddSlowPath(slow_path); |
| 1638 | |
| 1639 | // 0x80000000/-1 triggers an arithmetic exception! |
| 1640 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 1641 | // it's safe to just use negl instead of more complex comparisons. |
| 1642 | |
| 1643 | __ cmpl(second_reg, Immediate(-1)); |
| 1644 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 1645 | |
| 1646 | // edx:eax <- sign-extended of eax |
| 1647 | __ cdq(); |
| 1648 | // eax = quotient, edx = remainder |
| 1649 | __ idivl(second_reg); |
| 1650 | |
| 1651 | __ Bind(slow_path->GetExitLabel()); |
| 1652 | break; |
| 1653 | } |
| 1654 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1655 | case Primitive::kPrimLong: { |
| 1656 | LOG(FATAL) << "Not implemented div type" << div->GetResultType(); |
| 1657 | break; |
| 1658 | } |
| 1659 | |
| 1660 | case Primitive::kPrimFloat: { |
| 1661 | __ divss(first.As<XmmRegister>(), second.As<XmmRegister>()); |
| 1662 | break; |
| 1663 | } |
| 1664 | |
| 1665 | case Primitive::kPrimDouble: { |
| 1666 | __ divsd(first.As<XmmRegister>(), second.As<XmmRegister>()); |
| 1667 | break; |
| 1668 | } |
| 1669 | |
| 1670 | default: |
| 1671 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 1672 | } |
| 1673 | } |
| 1674 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1675 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 1676 | LocationSummary* locations = |
| 1677 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 1678 | locations->SetInAt(0, Location::Any()); |
| 1679 | if (instruction->HasUses()) { |
| 1680 | locations->SetOut(Location::SameAsFirstInput()); |
| 1681 | } |
| 1682 | } |
| 1683 | |
| 1684 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 1685 | SlowPathCodeX86_64* slow_path = |
| 1686 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction); |
| 1687 | codegen_->AddSlowPath(slow_path); |
| 1688 | |
| 1689 | LocationSummary* locations = instruction->GetLocations(); |
| 1690 | Location value = locations->InAt(0); |
| 1691 | |
| 1692 | if (value.IsRegister()) { |
| 1693 | __ testl(value.As<CpuRegister>(), value.As<CpuRegister>()); |
| 1694 | } else if (value.IsStackSlot()) { |
| 1695 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 1696 | } else { |
| 1697 | DCHECK(value.IsConstant()) << value; |
| 1698 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 1699 | __ jmp(slow_path->GetEntryLabel()); |
| 1700 | } |
| 1701 | return; |
| 1702 | } |
| 1703 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 1704 | } |
| 1705 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1706 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1707 | LocationSummary* locations = |
| 1708 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1709 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1710 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1711 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1712 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1713 | } |
| 1714 | |
| 1715 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
| 1716 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1717 | codegen_->LoadCurrentMethod(CpuRegister(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1718 | __ movq(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(instruction->GetTypeIndex())); |
| 1719 | |
| 1720 | __ gs()->call(Address::Absolute( |
| 1721 | QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pAllocObjectWithAccessCheck), true)); |
| 1722 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1723 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1724 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1725 | } |
| 1726 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1727 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 1728 | LocationSummary* locations = |
| 1729 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 1730 | InvokeRuntimeCallingConvention calling_convention; |
| 1731 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1732 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1733 | locations->SetOut(Location::RegisterLocation(RAX)); |
| 1734 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1735 | } |
| 1736 | |
| 1737 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| 1738 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1739 | codegen_->LoadCurrentMethod(CpuRegister(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1740 | __ movq(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(instruction->GetTypeIndex())); |
| 1741 | |
| 1742 | __ gs()->call(Address::Absolute( |
| 1743 | QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pAllocArrayWithAccessCheck), true)); |
| 1744 | |
| 1745 | DCHECK(!codegen_->IsLeafMethod()); |
| 1746 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 1747 | } |
| 1748 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1749 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1750 | LocationSummary* locations = |
| 1751 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1752 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 1753 | if (location.IsStackSlot()) { |
| 1754 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 1755 | } else if (location.IsDoubleStackSlot()) { |
| 1756 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 1757 | } |
| 1758 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1759 | } |
| 1760 | |
| 1761 | void InstructionCodeGeneratorX86_64::VisitParameterValue(HParameterValue* instruction) { |
| 1762 | // Nothing to do, the parameter is already at its location. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1763 | UNUSED(instruction); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1764 | } |
| 1765 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1766 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1767 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1768 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1769 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1770 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1771 | } |
| 1772 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1773 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 1774 | LocationSummary* locations = not_->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1775 | DCHECK_EQ(locations->InAt(0).As<CpuRegister>().AsRegister(), |
| 1776 | locations->Out().As<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1777 | Location out = locations->Out(); |
| 1778 | switch (not_->InputAt(0)->GetType()) { |
| 1779 | case Primitive::kPrimBoolean: |
| 1780 | __ xorq(out.As<CpuRegister>(), Immediate(1)); |
| 1781 | break; |
| 1782 | |
| 1783 | case Primitive::kPrimInt: |
| 1784 | __ notl(out.As<CpuRegister>()); |
| 1785 | break; |
| 1786 | |
| 1787 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 1788 | __ notq(out.As<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1789 | break; |
| 1790 | |
| 1791 | default: |
| 1792 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 1793 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1794 | } |
| 1795 | |
| 1796 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1797 | LocationSummary* locations = |
| 1798 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1799 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 1800 | locations->SetInAt(i, Location::Any()); |
| 1801 | } |
| 1802 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1803 | } |
| 1804 | |
| 1805 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1806 | UNUSED(instruction); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1807 | LOG(FATAL) << "Unimplemented"; |
| 1808 | } |
| 1809 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1810 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1811 | LocationSummary* locations = |
| 1812 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1813 | Primitive::Type field_type = instruction->GetFieldType(); |
| 1814 | bool is_object_type = field_type == Primitive::kPrimNot; |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1815 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1816 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1817 | if (is_object_type) { |
| 1818 | // Temporary registers for the write barrier. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 1819 | locations->AddTemp(Location::RequiresRegister()); |
| 1820 | locations->AddTemp(Location::RequiresRegister()); |
| 1821 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1822 | } |
| 1823 | |
| 1824 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 1825 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1826 | CpuRegister obj = locations->InAt(0).As<CpuRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1827 | size_t offset = instruction->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1828 | Primitive::Type field_type = instruction->GetFieldType(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1829 | |
| 1830 | switch (field_type) { |
| 1831 | case Primitive::kPrimBoolean: |
| 1832 | case Primitive::kPrimByte: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 1833 | CpuRegister value = locations->InAt(1).As<CpuRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1834 | __ movb(Address(obj, offset), value); |
| 1835 | break; |
| 1836 | } |
| 1837 | |
| 1838 | case Primitive::kPrimShort: |
| 1839 | case Primitive::kPrimChar: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 1840 | CpuRegister value = locations->InAt(1).As<CpuRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1841 | __ movw(Address(obj, offset), value); |
| 1842 | break; |
| 1843 | } |
| 1844 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1845 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1846 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 1847 | CpuRegister value = locations->InAt(1).As<CpuRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1848 | __ movl(Address(obj, offset), value); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1849 | if (field_type == Primitive::kPrimNot) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1850 | CpuRegister temp = locations->GetTemp(0).As<CpuRegister>(); |
| 1851 | CpuRegister card = locations->GetTemp(1).As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1852 | codegen_->MarkGCCard(temp, card, obj, value); |
| 1853 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1854 | break; |
| 1855 | } |
| 1856 | |
| 1857 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 1858 | CpuRegister value = locations->InAt(1).As<CpuRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1859 | __ movq(Address(obj, offset), value); |
| 1860 | break; |
| 1861 | } |
| 1862 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 1863 | case Primitive::kPrimFloat: { |
| 1864 | XmmRegister value = locations->InAt(1).As<XmmRegister>(); |
| 1865 | __ movss(Address(obj, offset), value); |
| 1866 | break; |
| 1867 | } |
| 1868 | |
| 1869 | case Primitive::kPrimDouble: { |
| 1870 | XmmRegister value = locations->InAt(1).As<XmmRegister>(); |
| 1871 | __ movsd(Address(obj, offset), value); |
| 1872 | break; |
| 1873 | } |
| 1874 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1875 | case Primitive::kPrimVoid: |
| 1876 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 1877 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1878 | } |
| 1879 | } |
| 1880 | |
| 1881 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1882 | LocationSummary* locations = |
| 1883 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1884 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1885 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1886 | } |
| 1887 | |
| 1888 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 1889 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1890 | CpuRegister obj = locations->InAt(0).As<CpuRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1891 | size_t offset = instruction->GetFieldOffset().SizeValue(); |
| 1892 | |
| 1893 | switch (instruction->GetType()) { |
| 1894 | case Primitive::kPrimBoolean: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 1895 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1896 | __ movzxb(out, Address(obj, offset)); |
| 1897 | break; |
| 1898 | } |
| 1899 | |
| 1900 | case Primitive::kPrimByte: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 1901 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1902 | __ movsxb(out, Address(obj, offset)); |
| 1903 | break; |
| 1904 | } |
| 1905 | |
| 1906 | case Primitive::kPrimShort: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 1907 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1908 | __ movsxw(out, Address(obj, offset)); |
| 1909 | break; |
| 1910 | } |
| 1911 | |
| 1912 | case Primitive::kPrimChar: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 1913 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1914 | __ movzxw(out, Address(obj, offset)); |
| 1915 | break; |
| 1916 | } |
| 1917 | |
| 1918 | case Primitive::kPrimInt: |
| 1919 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 1920 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1921 | __ movl(out, Address(obj, offset)); |
| 1922 | break; |
| 1923 | } |
| 1924 | |
| 1925 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 1926 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1927 | __ movq(out, Address(obj, offset)); |
| 1928 | break; |
| 1929 | } |
| 1930 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 1931 | case Primitive::kPrimFloat: { |
| 1932 | XmmRegister out = locations->Out().As<XmmRegister>(); |
| 1933 | __ movss(out, Address(obj, offset)); |
| 1934 | break; |
| 1935 | } |
| 1936 | |
| 1937 | case Primitive::kPrimDouble: { |
| 1938 | XmmRegister out = locations->Out().As<XmmRegister>(); |
| 1939 | __ movsd(out, Address(obj, offset)); |
| 1940 | break; |
| 1941 | } |
| 1942 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1943 | case Primitive::kPrimVoid: |
| 1944 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 1945 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1946 | } |
| 1947 | } |
| 1948 | |
| 1949 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1950 | LocationSummary* locations = |
| 1951 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1952 | locations->SetInAt(0, Location::Any()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1953 | if (instruction->HasUses()) { |
| 1954 | locations->SetOut(Location::SameAsFirstInput()); |
| 1955 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1959 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1960 | codegen_->AddSlowPath(slow_path); |
| 1961 | |
| 1962 | LocationSummary* locations = instruction->GetLocations(); |
| 1963 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1964 | |
| 1965 | if (obj.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1966 | __ cmpl(obj.As<CpuRegister>(), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1967 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1968 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 1969 | } else { |
| 1970 | DCHECK(obj.IsConstant()) << obj; |
| 1971 | DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0); |
| 1972 | __ jmp(slow_path->GetEntryLabel()); |
| 1973 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1974 | } |
| 1975 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 1976 | } |
| 1977 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1978 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1979 | LocationSummary* locations = |
| 1980 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1981 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 1982 | locations->SetInAt( |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 1983 | 1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 1984 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1985 | } |
| 1986 | |
| 1987 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 1988 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1989 | CpuRegister obj = locations->InAt(0).As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1990 | Location index = locations->InAt(1); |
| 1991 | |
| 1992 | switch (instruction->GetType()) { |
| 1993 | case Primitive::kPrimBoolean: { |
| 1994 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1995 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1996 | if (index.IsConstant()) { |
| 1997 | __ movzxb(out, Address(obj, |
| 1998 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 1999 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2000 | __ movzxb(out, Address(obj, index.As<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2001 | } |
| 2002 | break; |
| 2003 | } |
| 2004 | |
| 2005 | case Primitive::kPrimByte: { |
| 2006 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2007 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2008 | if (index.IsConstant()) { |
| 2009 | __ movsxb(out, Address(obj, |
| 2010 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 2011 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2012 | __ movsxb(out, Address(obj, index.As<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2013 | } |
| 2014 | break; |
| 2015 | } |
| 2016 | |
| 2017 | case Primitive::kPrimShort: { |
| 2018 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2019 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2020 | if (index.IsConstant()) { |
| 2021 | __ movsxw(out, Address(obj, |
| 2022 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 2023 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2024 | __ movsxw(out, Address(obj, index.As<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2025 | } |
| 2026 | break; |
| 2027 | } |
| 2028 | |
| 2029 | case Primitive::kPrimChar: { |
| 2030 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2031 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2032 | if (index.IsConstant()) { |
| 2033 | __ movzxw(out, Address(obj, |
| 2034 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 2035 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2036 | __ movzxw(out, Address(obj, index.As<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2037 | } |
| 2038 | break; |
| 2039 | } |
| 2040 | |
| 2041 | case Primitive::kPrimInt: |
| 2042 | case Primitive::kPrimNot: { |
| 2043 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
| 2044 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2045 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2046 | if (index.IsConstant()) { |
| 2047 | __ movl(out, Address(obj, |
| 2048 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 2049 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2050 | __ movl(out, Address(obj, index.As<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2051 | } |
| 2052 | break; |
| 2053 | } |
| 2054 | |
| 2055 | case Primitive::kPrimLong: { |
| 2056 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2057 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2058 | if (index.IsConstant()) { |
| 2059 | __ movq(out, Address(obj, |
| 2060 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 2061 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2062 | __ movq(out, Address(obj, index.As<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2063 | } |
| 2064 | break; |
| 2065 | } |
| 2066 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2067 | case Primitive::kPrimFloat: { |
| 2068 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 2069 | XmmRegister out = locations->Out().As<XmmRegister>(); |
| 2070 | if (index.IsConstant()) { |
| 2071 | __ movss(out, Address(obj, |
| 2072 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 2073 | } else { |
| 2074 | __ movss(out, Address(obj, index.As<CpuRegister>(), TIMES_4, data_offset)); |
| 2075 | } |
| 2076 | break; |
| 2077 | } |
| 2078 | |
| 2079 | case Primitive::kPrimDouble: { |
| 2080 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 2081 | XmmRegister out = locations->Out().As<XmmRegister>(); |
| 2082 | if (index.IsConstant()) { |
| 2083 | __ movsd(out, Address(obj, |
| 2084 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 2085 | } else { |
| 2086 | __ movsd(out, Address(obj, index.As<CpuRegister>(), TIMES_8, data_offset)); |
| 2087 | } |
| 2088 | break; |
| 2089 | } |
| 2090 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2091 | case Primitive::kPrimVoid: |
| 2092 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2093 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2094 | } |
| 2095 | } |
| 2096 | |
| 2097 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2098 | Primitive::Type value_type = instruction->GetComponentType(); |
| 2099 | bool is_object = value_type == Primitive::kPrimNot; |
| 2100 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 2101 | instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 2102 | if (is_object) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2103 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2104 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2105 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2106 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2107 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2108 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 2109 | locations->SetInAt( |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2110 | 1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2111 | locations->SetInAt(2, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2112 | if (value_type == Primitive::kPrimLong) { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2113 | locations->SetInAt(2, Location::RequiresRegister()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2114 | } else if (value_type == Primitive::kPrimFloat || value_type == Primitive::kPrimDouble) { |
| 2115 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2116 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2117 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2118 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2119 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2120 | } |
| 2121 | |
| 2122 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 2123 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2124 | CpuRegister obj = locations->InAt(0).As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2125 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2126 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2127 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2128 | |
| 2129 | switch (value_type) { |
| 2130 | case Primitive::kPrimBoolean: |
| 2131 | case Primitive::kPrimByte: { |
| 2132 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2133 | if (index.IsConstant()) { |
| 2134 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2135 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2136 | __ movb(Address(obj, offset), value.As<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2137 | } else { |
| 2138 | __ movb(Address(obj, offset), Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2139 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2140 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2141 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2142 | __ movb(Address(obj, index.As<CpuRegister>(), TIMES_1, data_offset), |
| 2143 | value.As<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2144 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2145 | __ movb(Address(obj, index.As<CpuRegister>(), TIMES_1, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2146 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2147 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2148 | } |
| 2149 | break; |
| 2150 | } |
| 2151 | |
| 2152 | case Primitive::kPrimShort: |
| 2153 | case Primitive::kPrimChar: { |
| 2154 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2155 | if (index.IsConstant()) { |
| 2156 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2157 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2158 | __ movw(Address(obj, offset), value.As<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2159 | } else { |
| 2160 | __ movw(Address(obj, offset), Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2161 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2162 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2163 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2164 | __ movw(Address(obj, index.As<CpuRegister>(), TIMES_2, data_offset), |
| 2165 | value.As<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2166 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2167 | __ movw(Address(obj, index.As<CpuRegister>(), TIMES_2, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2168 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2169 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2170 | } |
| 2171 | break; |
| 2172 | } |
| 2173 | |
| 2174 | case Primitive::kPrimInt: { |
| 2175 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2176 | if (index.IsConstant()) { |
| 2177 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2178 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2179 | __ movl(Address(obj, offset), value.As<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2180 | } else { |
| 2181 | __ movl(Address(obj, offset), Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2182 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2183 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2184 | if (value.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2185 | __ movl(Address(obj, index.As<CpuRegister>(), TIMES_4, data_offset), |
| 2186 | value.As<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2187 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2188 | DCHECK(value.IsConstant()) << value; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2189 | __ movl(Address(obj, index.As<CpuRegister>(), TIMES_4, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2190 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2191 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2192 | } |
| 2193 | break; |
| 2194 | } |
| 2195 | |
| 2196 | case Primitive::kPrimNot: { |
| 2197 | __ gs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pAputObject), true)); |
| 2198 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2199 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2200 | break; |
| 2201 | } |
| 2202 | |
| 2203 | case Primitive::kPrimLong: { |
| 2204 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2205 | if (index.IsConstant()) { |
| 2206 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2207 | DCHECK(value.IsRegister()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2208 | __ movq(Address(obj, offset), value.As<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2209 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2210 | DCHECK(value.IsRegister()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2211 | __ movq(Address(obj, index.As<CpuRegister>(), TIMES_8, data_offset), |
| 2212 | value.As<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2213 | } |
| 2214 | break; |
| 2215 | } |
| 2216 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2217 | case Primitive::kPrimFloat: { |
| 2218 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 2219 | if (index.IsConstant()) { |
| 2220 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 2221 | DCHECK(value.IsFpuRegister()); |
| 2222 | __ movss(Address(obj, offset), value.As<XmmRegister>()); |
| 2223 | } else { |
| 2224 | DCHECK(value.IsFpuRegister()); |
| 2225 | __ movss(Address(obj, index.As<CpuRegister>(), TIMES_4, data_offset), |
| 2226 | value.As<XmmRegister>()); |
| 2227 | } |
| 2228 | break; |
| 2229 | } |
| 2230 | |
| 2231 | case Primitive::kPrimDouble: { |
| 2232 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 2233 | if (index.IsConstant()) { |
| 2234 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 2235 | DCHECK(value.IsFpuRegister()); |
| 2236 | __ movsd(Address(obj, offset), value.As<XmmRegister>()); |
| 2237 | } else { |
| 2238 | DCHECK(value.IsFpuRegister()); |
| 2239 | __ movsd(Address(obj, index.As<CpuRegister>(), TIMES_8, data_offset), |
| 2240 | value.As<XmmRegister>()); |
| 2241 | } |
| 2242 | break; |
| 2243 | } |
| 2244 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2245 | case Primitive::kPrimVoid: |
| 2246 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2247 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2248 | } |
| 2249 | } |
| 2250 | |
| 2251 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2252 | LocationSummary* locations = |
| 2253 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2254 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2255 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2256 | } |
| 2257 | |
| 2258 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
| 2259 | LocationSummary* locations = instruction->GetLocations(); |
| 2260 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2261 | CpuRegister obj = locations->InAt(0).As<CpuRegister>(); |
| 2262 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2263 | __ movl(out, Address(obj, offset)); |
| 2264 | } |
| 2265 | |
| 2266 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2267 | LocationSummary* locations = |
| 2268 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2269 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2270 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2271 | if (instruction->HasUses()) { |
| 2272 | locations->SetOut(Location::SameAsFirstInput()); |
| 2273 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2274 | } |
| 2275 | |
| 2276 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 2277 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 2278 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64( |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2279 | instruction, locations->InAt(0), locations->InAt(1)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2280 | codegen_->AddSlowPath(slow_path); |
| 2281 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2282 | CpuRegister index = locations->InAt(0).As<CpuRegister>(); |
| 2283 | CpuRegister length = locations->InAt(1).As<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2284 | |
| 2285 | __ cmpl(index, length); |
| 2286 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
| 2287 | } |
| 2288 | |
| 2289 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 2290 | CpuRegister card, |
| 2291 | CpuRegister object, |
| 2292 | CpuRegister value) { |
| 2293 | Label is_null; |
| 2294 | __ testl(value, value); |
| 2295 | __ j(kEqual, &is_null); |
| 2296 | __ gs()->movq(card, Address::Absolute( |
| 2297 | Thread::CardTableOffset<kX86_64WordSize>().Int32Value(), true)); |
| 2298 | __ movq(temp, object); |
| 2299 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
| 2300 | __ movb(Address(temp, card, TIMES_1, 0), card); |
| 2301 | __ Bind(&is_null); |
| 2302 | } |
| 2303 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2304 | void LocationsBuilderX86_64::VisitTemporary(HTemporary* temp) { |
| 2305 | temp->SetLocations(nullptr); |
| 2306 | } |
| 2307 | |
| 2308 | void InstructionCodeGeneratorX86_64::VisitTemporary(HTemporary* temp) { |
| 2309 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2310 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2311 | } |
| 2312 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2313 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2314 | UNUSED(instruction); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2315 | LOG(FATAL) << "Unimplemented"; |
| 2316 | } |
| 2317 | |
| 2318 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2319 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 2320 | } |
| 2321 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2322 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 2323 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 2324 | } |
| 2325 | |
| 2326 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2327 | HBasicBlock* block = instruction->GetBlock(); |
| 2328 | if (block->GetLoopInformation() != nullptr) { |
| 2329 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 2330 | // The back edge will generate the suspend check. |
| 2331 | return; |
| 2332 | } |
| 2333 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 2334 | // The goto will generate the suspend check. |
| 2335 | return; |
| 2336 | } |
| 2337 | GenerateSuspendCheck(instruction, nullptr); |
| 2338 | } |
| 2339 | |
| 2340 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 2341 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2342 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2343 | new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2344 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2345 | __ gs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2346 | Thread::ThreadFlagsOffset<kX86_64WordSize>().Int32Value(), true), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 2347 | if (successor == nullptr) { |
| 2348 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 2349 | __ Bind(slow_path->GetReturnLabel()); |
| 2350 | } else { |
| 2351 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 2352 | __ jmp(slow_path->GetEntryLabel()); |
| 2353 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2354 | } |
| 2355 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2356 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 2357 | return codegen_->GetAssembler(); |
| 2358 | } |
| 2359 | |
| 2360 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
| 2361 | MoveOperands* move = moves_.Get(index); |
| 2362 | Location source = move->GetSource(); |
| 2363 | Location destination = move->GetDestination(); |
| 2364 | |
| 2365 | if (source.IsRegister()) { |
| 2366 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2367 | __ movq(destination.As<CpuRegister>(), source.As<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2368 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2369 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2370 | source.As<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2371 | } else { |
| 2372 | DCHECK(destination.IsDoubleStackSlot()); |
| 2373 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2374 | source.As<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2375 | } |
| 2376 | } else if (source.IsStackSlot()) { |
| 2377 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2378 | __ movl(destination.As<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2379 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2380 | } else if (destination.IsFpuRegister()) { |
| 2381 | __ movss(destination.As<XmmRegister>(), |
| 2382 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2383 | } else { |
| 2384 | DCHECK(destination.IsStackSlot()); |
| 2385 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 2386 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 2387 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2388 | } else if (source.IsDoubleStackSlot()) { |
| 2389 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2390 | __ movq(destination.As<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2391 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2392 | } else if (destination.IsFpuRegister()) { |
| 2393 | __ movsd(destination.As<XmmRegister>(), Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2394 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 2395 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2396 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 2397 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 2398 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2399 | } else if (source.IsConstant()) { |
| 2400 | HConstant* constant = source.GetConstant(); |
| 2401 | if (constant->IsIntConstant()) { |
| 2402 | Immediate imm(constant->AsIntConstant()->GetValue()); |
| 2403 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2404 | __ movl(destination.As<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2405 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2406 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2407 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 2408 | } |
| 2409 | } else if (constant->IsLongConstant()) { |
| 2410 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 2411 | if (destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2412 | __ movq(destination.As<CpuRegister>(), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2413 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2414 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2415 | __ movq(CpuRegister(TMP), Immediate(value)); |
| 2416 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 2417 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2418 | } else if (constant->IsFloatConstant()) { |
| 2419 | Immediate imm(bit_cast<float, int32_t>(constant->AsFloatConstant()->GetValue())); |
| 2420 | if (destination.IsFpuRegister()) { |
| 2421 | __ movl(CpuRegister(TMP), imm); |
| 2422 | __ movd(destination.As<XmmRegister>(), CpuRegister(TMP)); |
| 2423 | } else { |
| 2424 | DCHECK(destination.IsStackSlot()) << destination; |
| 2425 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 2426 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2427 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2428 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
| 2429 | Immediate imm(bit_cast<double, int64_t>(constant->AsDoubleConstant()->GetValue())); |
| 2430 | if (destination.IsFpuRegister()) { |
| 2431 | __ movq(CpuRegister(TMP), imm); |
| 2432 | __ movd(destination.As<XmmRegister>(), CpuRegister(TMP)); |
| 2433 | } else { |
| 2434 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 2435 | __ movq(CpuRegister(TMP), imm); |
| 2436 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 2437 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2438 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2439 | } else if (source.IsFpuRegister()) { |
| 2440 | if (destination.IsFpuRegister()) { |
| 2441 | __ movaps(destination.As<XmmRegister>(), source.As<XmmRegister>()); |
| 2442 | } else if (destination.IsStackSlot()) { |
| 2443 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| 2444 | source.As<XmmRegister>()); |
| 2445 | } else { |
| 2446 | DCHECK(destination.IsDoubleStackSlot()); |
| 2447 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
| 2448 | source.As<XmmRegister>()); |
| 2449 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2450 | } |
| 2451 | } |
| 2452 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2453 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2454 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2455 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 2456 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2457 | } |
| 2458 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2459 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2460 | ScratchRegisterScope ensure_scratch( |
| 2461 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 2462 | |
| 2463 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 2464 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 2465 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 2466 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 2467 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 2468 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 2469 | CpuRegister(ensure_scratch.GetRegister())); |
| 2470 | } |
| 2471 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2472 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 2473 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 2474 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 2475 | __ movq(reg, CpuRegister(TMP)); |
| 2476 | } |
| 2477 | |
| 2478 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 2479 | ScratchRegisterScope ensure_scratch( |
| 2480 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 2481 | |
| 2482 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 2483 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 2484 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 2485 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 2486 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 2487 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 2488 | CpuRegister(ensure_scratch.GetRegister())); |
| 2489 | } |
| 2490 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2491 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 2492 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 2493 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 2494 | __ movd(reg, CpuRegister(TMP)); |
| 2495 | } |
| 2496 | |
| 2497 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 2498 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 2499 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 2500 | __ movd(reg, CpuRegister(TMP)); |
| 2501 | } |
| 2502 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2503 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
| 2504 | MoveOperands* move = moves_.Get(index); |
| 2505 | Location source = move->GetSource(); |
| 2506 | Location destination = move->GetDestination(); |
| 2507 | |
| 2508 | if (source.IsRegister() && destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2509 | __ xchgq(destination.As<CpuRegister>(), source.As<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2510 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2511 | Exchange32(source.As<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2512 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2513 | Exchange32(destination.As<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2514 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2515 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 2516 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2517 | Exchange64(source.As<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2518 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2519 | Exchange64(destination.As<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2520 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 2521 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2522 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 2523 | __ movd(CpuRegister(TMP), source.As<XmmRegister>()); |
| 2524 | __ movaps(source.As<XmmRegister>(), destination.As<XmmRegister>()); |
| 2525 | __ movd(destination.As<XmmRegister>(), CpuRegister(TMP)); |
| 2526 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 2527 | Exchange32(source.As<XmmRegister>(), destination.GetStackIndex()); |
| 2528 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
| 2529 | Exchange32(destination.As<XmmRegister>(), source.GetStackIndex()); |
| 2530 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 2531 | Exchange64(source.As<XmmRegister>(), destination.GetStackIndex()); |
| 2532 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
| 2533 | Exchange64(destination.As<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2534 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2535 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2536 | } |
| 2537 | } |
| 2538 | |
| 2539 | |
| 2540 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 2541 | __ pushq(CpuRegister(reg)); |
| 2542 | } |
| 2543 | |
| 2544 | |
| 2545 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 2546 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2547 | } |
| 2548 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2549 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
| 2550 | SlowPathCodeX86_64* slow_path, CpuRegister class_reg) { |
| 2551 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 2552 | Immediate(mirror::Class::kStatusInitialized)); |
| 2553 | __ j(kLess, slow_path->GetEntryLabel()); |
| 2554 | __ Bind(slow_path->GetExitLabel()); |
| 2555 | // No need for memory fence, thanks to the X86_64 memory model. |
| 2556 | } |
| 2557 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2558 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2559 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() |
| 2560 | ? LocationSummary::kCallOnSlowPath |
| 2561 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2562 | LocationSummary* locations = |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2563 | new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2564 | locations->SetOut(Location::RequiresRegister()); |
| 2565 | } |
| 2566 | |
| 2567 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) { |
| 2568 | CpuRegister out = cls->GetLocations()->Out().As<CpuRegister>(); |
| 2569 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2570 | DCHECK(!cls->CanCallRuntime()); |
| 2571 | DCHECK(!cls->MustGenerateClinitCheck()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2572 | codegen_->LoadCurrentMethod(out); |
| 2573 | __ movl(out, Address(out, mirror::ArtMethod::DeclaringClassOffset().Int32Value())); |
| 2574 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2575 | DCHECK(cls->CanCallRuntime()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2576 | codegen_->LoadCurrentMethod(out); |
| 2577 | __ movl(out, Address(out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value())); |
| 2578 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2579 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 2580 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 2581 | codegen_->AddSlowPath(slow_path); |
| 2582 | __ testl(out, out); |
| 2583 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2584 | if (cls->MustGenerateClinitCheck()) { |
| 2585 | GenerateClassInitializationCheck(slow_path, out); |
| 2586 | } else { |
| 2587 | __ Bind(slow_path->GetExitLabel()); |
| 2588 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2589 | } |
| 2590 | } |
| 2591 | |
| 2592 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 2593 | LocationSummary* locations = |
| 2594 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 2595 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2596 | if (check->HasUses()) { |
| 2597 | locations->SetOut(Location::SameAsFirstInput()); |
| 2598 | } |
| 2599 | } |
| 2600 | |
| 2601 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2602 | // We assume the class to not be null. |
| 2603 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 2604 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2605 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2606 | GenerateClassInitializationCheck(slow_path, check->GetLocations()->InAt(0).As<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2607 | } |
| 2608 | |
| 2609 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 2610 | LocationSummary* locations = |
| 2611 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2612 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2613 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2614 | } |
| 2615 | |
| 2616 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 2617 | LocationSummary* locations = instruction->GetLocations(); |
| 2618 | CpuRegister cls = locations->InAt(0).As<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2619 | size_t offset = instruction->GetFieldOffset().SizeValue(); |
| 2620 | |
| 2621 | switch (instruction->GetType()) { |
| 2622 | case Primitive::kPrimBoolean: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2623 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2624 | __ movzxb(out, Address(cls, offset)); |
| 2625 | break; |
| 2626 | } |
| 2627 | |
| 2628 | case Primitive::kPrimByte: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2629 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2630 | __ movsxb(out, Address(cls, offset)); |
| 2631 | break; |
| 2632 | } |
| 2633 | |
| 2634 | case Primitive::kPrimShort: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2635 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2636 | __ movsxw(out, Address(cls, offset)); |
| 2637 | break; |
| 2638 | } |
| 2639 | |
| 2640 | case Primitive::kPrimChar: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2641 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2642 | __ movzxw(out, Address(cls, offset)); |
| 2643 | break; |
| 2644 | } |
| 2645 | |
| 2646 | case Primitive::kPrimInt: |
| 2647 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2648 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2649 | __ movl(out, Address(cls, offset)); |
| 2650 | break; |
| 2651 | } |
| 2652 | |
| 2653 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2654 | CpuRegister out = locations->Out().As<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2655 | __ movq(out, Address(cls, offset)); |
| 2656 | break; |
| 2657 | } |
| 2658 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2659 | case Primitive::kPrimFloat: { |
| 2660 | XmmRegister out = locations->Out().As<XmmRegister>(); |
| 2661 | __ movss(out, Address(cls, offset)); |
| 2662 | break; |
| 2663 | } |
| 2664 | |
| 2665 | case Primitive::kPrimDouble: { |
| 2666 | XmmRegister out = locations->Out().As<XmmRegister>(); |
| 2667 | __ movsd(out, Address(cls, offset)); |
| 2668 | break; |
| 2669 | } |
| 2670 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2671 | case Primitive::kPrimVoid: |
| 2672 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
| 2673 | UNREACHABLE(); |
| 2674 | } |
| 2675 | } |
| 2676 | |
| 2677 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 2678 | LocationSummary* locations = |
| 2679 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2680 | Primitive::Type field_type = instruction->GetFieldType(); |
| 2681 | bool is_object_type = field_type == Primitive::kPrimNot; |
| 2682 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2683 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2684 | if (is_object_type) { |
| 2685 | // Temporary registers for the write barrier. |
| 2686 | locations->AddTemp(Location::RequiresRegister()); |
| 2687 | locations->AddTemp(Location::RequiresRegister()); |
| 2688 | } |
| 2689 | } |
| 2690 | |
| 2691 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 2692 | LocationSummary* locations = instruction->GetLocations(); |
| 2693 | CpuRegister cls = locations->InAt(0).As<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2694 | size_t offset = instruction->GetFieldOffset().SizeValue(); |
| 2695 | Primitive::Type field_type = instruction->GetFieldType(); |
| 2696 | |
| 2697 | switch (field_type) { |
| 2698 | case Primitive::kPrimBoolean: |
| 2699 | case Primitive::kPrimByte: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2700 | CpuRegister value = locations->InAt(1).As<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2701 | __ movb(Address(cls, offset), value); |
| 2702 | break; |
| 2703 | } |
| 2704 | |
| 2705 | case Primitive::kPrimShort: |
| 2706 | case Primitive::kPrimChar: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2707 | CpuRegister value = locations->InAt(1).As<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2708 | __ movw(Address(cls, offset), value); |
| 2709 | break; |
| 2710 | } |
| 2711 | |
| 2712 | case Primitive::kPrimInt: |
| 2713 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2714 | CpuRegister value = locations->InAt(1).As<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2715 | __ movl(Address(cls, offset), value); |
| 2716 | if (field_type == Primitive::kPrimNot) { |
| 2717 | CpuRegister temp = locations->GetTemp(0).As<CpuRegister>(); |
| 2718 | CpuRegister card = locations->GetTemp(1).As<CpuRegister>(); |
| 2719 | codegen_->MarkGCCard(temp, card, cls, value); |
| 2720 | } |
| 2721 | break; |
| 2722 | } |
| 2723 | |
| 2724 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2725 | CpuRegister value = locations->InAt(1).As<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2726 | __ movq(Address(cls, offset), value); |
| 2727 | break; |
| 2728 | } |
| 2729 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2730 | case Primitive::kPrimFloat: { |
| 2731 | XmmRegister value = locations->InAt(1).As<XmmRegister>(); |
| 2732 | __ movss(Address(cls, offset), value); |
| 2733 | break; |
| 2734 | } |
| 2735 | |
| 2736 | case Primitive::kPrimDouble: { |
| 2737 | XmmRegister value = locations->InAt(1).As<XmmRegister>(); |
| 2738 | __ movsd(Address(cls, offset), value); |
| 2739 | break; |
| 2740 | } |
| 2741 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2742 | case Primitive::kPrimVoid: |
| 2743 | LOG(FATAL) << "Unreachable type " << field_type; |
| 2744 | UNREACHABLE(); |
| 2745 | } |
| 2746 | } |
| 2747 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 2748 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
| 2749 | LocationSummary* locations = |
| 2750 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
| 2751 | locations->SetOut(Location::RequiresRegister()); |
| 2752 | } |
| 2753 | |
| 2754 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) { |
| 2755 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86_64(load); |
| 2756 | codegen_->AddSlowPath(slow_path); |
| 2757 | |
| 2758 | CpuRegister out = load->GetLocations()->Out().As<CpuRegister>(); |
| 2759 | codegen_->LoadCurrentMethod(CpuRegister(out)); |
| 2760 | __ movl(out, Address(out, mirror::ArtMethod::DexCacheStringsOffset().Int32Value())); |
| 2761 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
| 2762 | __ testl(out, out); |
| 2763 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2764 | __ Bind(slow_path->GetExitLabel()); |
| 2765 | } |
| 2766 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2767 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 2768 | LocationSummary* locations = |
| 2769 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 2770 | locations->SetOut(Location::RequiresRegister()); |
| 2771 | } |
| 2772 | |
| 2773 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
| 2774 | Address address = Address::Absolute( |
| 2775 | Thread::ExceptionOffset<kX86_64WordSize>().Int32Value(), true); |
| 2776 | __ gs()->movl(load->GetLocations()->Out().As<CpuRegister>(), address); |
| 2777 | __ gs()->movl(address, Immediate(0)); |
| 2778 | } |
| 2779 | |
| 2780 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| 2781 | LocationSummary* locations = |
| 2782 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 2783 | InvokeRuntimeCallingConvention calling_convention; |
| 2784 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2785 | } |
| 2786 | |
| 2787 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
| 2788 | __ gs()->call( |
| 2789 | Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pDeliverException), true)); |
| 2790 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 2791 | } |
| 2792 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2793 | void LocationsBuilderX86_64::VisitTypeCheck(HTypeCheck* instruction) { |
| 2794 | LocationSummary::CallKind call_kind = instruction->IsClassFinal() |
| 2795 | ? LocationSummary::kNoCall |
| 2796 | : LocationSummary::kCallOnSlowPath; |
| 2797 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 2798 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2799 | locations->SetInAt(1, Location::Any()); |
| 2800 | locations->SetOut(Location::RequiresRegister()); |
| 2801 | } |
| 2802 | |
| 2803 | void InstructionCodeGeneratorX86_64::VisitTypeCheck(HTypeCheck* instruction) { |
| 2804 | LocationSummary* locations = instruction->GetLocations(); |
| 2805 | CpuRegister obj = locations->InAt(0).As<CpuRegister>(); |
| 2806 | Location cls = locations->InAt(1); |
| 2807 | CpuRegister out = locations->Out().As<CpuRegister>(); |
| 2808 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2809 | Label done, zero; |
| 2810 | SlowPathCodeX86_64* slow_path = nullptr; |
| 2811 | |
| 2812 | // Return 0 if `obj` is null. |
| 2813 | // TODO: avoid this check if we know obj is not null. |
| 2814 | __ testl(obj, obj); |
| 2815 | __ j(kEqual, &zero); |
| 2816 | // Compare the class of `obj` with `cls`. |
| 2817 | __ movl(out, Address(obj, class_offset)); |
| 2818 | if (cls.IsRegister()) { |
| 2819 | __ cmpl(out, cls.As<CpuRegister>()); |
| 2820 | } else { |
| 2821 | DCHECK(cls.IsStackSlot()) << cls; |
| 2822 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 2823 | } |
| 2824 | if (instruction->IsClassFinal()) { |
| 2825 | // Classes must be equal for the instanceof to succeed. |
| 2826 | __ j(kNotEqual, &zero); |
| 2827 | __ movl(out, Immediate(1)); |
| 2828 | __ jmp(&done); |
| 2829 | } else { |
| 2830 | // If the classes are not equal, we go into a slow path. |
| 2831 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 2832 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64( |
| 2833 | instruction, Location::RegisterLocation(out.AsRegister())); |
| 2834 | codegen_->AddSlowPath(slow_path); |
| 2835 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 2836 | __ movl(out, Immediate(1)); |
| 2837 | __ jmp(&done); |
| 2838 | } |
| 2839 | __ Bind(&zero); |
| 2840 | __ movl(out, Immediate(0)); |
| 2841 | if (slow_path != nullptr) { |
| 2842 | __ Bind(slow_path->GetExitLabel()); |
| 2843 | } |
| 2844 | __ Bind(&done); |
| 2845 | } |
| 2846 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2847 | } // namespace x86_64 |
| 2848 | } // namespace art |