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