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