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