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