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