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