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