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