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()); |
| 1871 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1872 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1873 | break; |
| 1874 | } |
| 1875 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1876 | case Primitive::kPrimDouble: |
| 1877 | case Primitive::kPrimFloat: { |
| 1878 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1879 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1880 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1881 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1882 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1883 | |
| 1884 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1885 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1886 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1887 | } |
| 1888 | |
| 1889 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 1890 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1891 | Location first = locations->InAt(0); |
| 1892 | Location second = locations->InAt(1); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 1893 | Location out = locations->Out(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1894 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1895 | switch (add->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1896 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1897 | if (second.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 1898 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 1899 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 1900 | } else { |
| 1901 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 1902 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 1903 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1904 | } else if (second.IsConstant()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 1905 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 1906 | __ addl(out.AsRegister<CpuRegister>(), |
| 1907 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 1908 | } else { |
| 1909 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 1910 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 1911 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1912 | } else { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 1913 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1914 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1915 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1916 | break; |
| 1917 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1918 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1919 | case Primitive::kPrimLong: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1920 | __ addq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1921 | break; |
| 1922 | } |
| 1923 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1924 | case Primitive::kPrimFloat: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1925 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1926 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1927 | } |
| 1928 | |
| 1929 | case Primitive::kPrimDouble: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1930 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1931 | break; |
| 1932 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1933 | |
| 1934 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1935 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1936 | } |
| 1937 | } |
| 1938 | |
| 1939 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1940 | LocationSummary* locations = |
| 1941 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1942 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1943 | case Primitive::kPrimInt: { |
| 1944 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1945 | locations->SetInAt(1, Location::Any()); |
| 1946 | locations->SetOut(Location::SameAsFirstInput()); |
| 1947 | break; |
| 1948 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1949 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1950 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1951 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1952 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1953 | break; |
| 1954 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1955 | case Primitive::kPrimFloat: |
| 1956 | case Primitive::kPrimDouble: { |
| 1957 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1958 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1959 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1960 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1961 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1962 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1963 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1964 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 1968 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1969 | Location first = locations->InAt(0); |
| 1970 | Location second = locations->InAt(1); |
| 1971 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1972 | switch (sub->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1973 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1974 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1975 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1976 | } else if (second.IsConstant()) { |
| 1977 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1978 | __ subl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1979 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1980 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1981 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1982 | break; |
| 1983 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1984 | case Primitive::kPrimLong: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1985 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1986 | break; |
| 1987 | } |
| 1988 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1989 | case Primitive::kPrimFloat: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1990 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1991 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1992 | } |
| 1993 | |
| 1994 | case Primitive::kPrimDouble: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1995 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 1996 | break; |
| 1997 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1998 | |
| 1999 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2000 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2001 | } |
| 2002 | } |
| 2003 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2004 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 2005 | LocationSummary* locations = |
| 2006 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2007 | switch (mul->GetResultType()) { |
| 2008 | case Primitive::kPrimInt: { |
| 2009 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2010 | locations->SetInAt(1, Location::Any()); |
| 2011 | locations->SetOut(Location::SameAsFirstInput()); |
| 2012 | break; |
| 2013 | } |
| 2014 | case Primitive::kPrimLong: { |
| 2015 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2016 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2017 | locations->SetOut(Location::SameAsFirstInput()); |
| 2018 | break; |
| 2019 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2020 | case Primitive::kPrimFloat: |
| 2021 | case Primitive::kPrimDouble: { |
| 2022 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2023 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2024 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2025 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2026 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2027 | |
| 2028 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2029 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2030 | } |
| 2031 | } |
| 2032 | |
| 2033 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 2034 | LocationSummary* locations = mul->GetLocations(); |
| 2035 | Location first = locations->InAt(0); |
| 2036 | Location second = locations->InAt(1); |
| 2037 | DCHECK(first.Equals(locations->Out())); |
| 2038 | switch (mul->GetResultType()) { |
| 2039 | case Primitive::kPrimInt: { |
| 2040 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2041 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2042 | } else if (second.IsConstant()) { |
| 2043 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2044 | __ imull(first.AsRegister<CpuRegister>(), imm); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2045 | } else { |
| 2046 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2047 | __ imull(first.AsRegister<CpuRegister>(), |
| 2048 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2049 | } |
| 2050 | break; |
| 2051 | } |
| 2052 | case Primitive::kPrimLong: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2053 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2054 | break; |
| 2055 | } |
| 2056 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2057 | case Primitive::kPrimFloat: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2058 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2059 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | case Primitive::kPrimDouble: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2063 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2064 | break; |
| 2065 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2066 | |
| 2067 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2068 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2069 | } |
| 2070 | } |
| 2071 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2072 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 2073 | uint32_t stack_adjustment, bool is_float) { |
| 2074 | if (source.IsStackSlot()) { |
| 2075 | DCHECK(is_float); |
| 2076 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 2077 | } else if (source.IsDoubleStackSlot()) { |
| 2078 | DCHECK(!is_float); |
| 2079 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 2080 | } else { |
| 2081 | // Write the value to the temporary location on the stack and load to FP stack. |
| 2082 | if (is_float) { |
| 2083 | Location stack_temp = Location::StackSlot(temp_offset); |
| 2084 | codegen_->Move(stack_temp, source); |
| 2085 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 2086 | } else { |
| 2087 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 2088 | codegen_->Move(stack_temp, source); |
| 2089 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 2090 | } |
| 2091 | } |
| 2092 | } |
| 2093 | |
| 2094 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| 2095 | Primitive::Type type = rem->GetResultType(); |
| 2096 | bool is_float = type == Primitive::kPrimFloat; |
| 2097 | size_t elem_size = Primitive::ComponentSize(type); |
| 2098 | LocationSummary* locations = rem->GetLocations(); |
| 2099 | Location first = locations->InAt(0); |
| 2100 | Location second = locations->InAt(1); |
| 2101 | Location out = locations->Out(); |
| 2102 | |
| 2103 | // Create stack space for 2 elements. |
| 2104 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2105 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 2106 | |
| 2107 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 2108 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 2109 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 2110 | |
| 2111 | // Loop doing FPREM until we stabilize. |
| 2112 | Label retry; |
| 2113 | __ Bind(&retry); |
| 2114 | __ fprem(); |
| 2115 | |
| 2116 | // Move FP status to AX. |
| 2117 | __ fstsw(); |
| 2118 | |
| 2119 | // And see if the argument reduction is complete. This is signaled by the |
| 2120 | // C2 FPU flag bit set to 0. |
| 2121 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 2122 | __ j(kNotEqual, &retry); |
| 2123 | |
| 2124 | // We have settled on the final value. Retrieve it into an XMM register. |
| 2125 | // Store FP top of stack to real stack. |
| 2126 | if (is_float) { |
| 2127 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 2128 | } else { |
| 2129 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 2130 | } |
| 2131 | |
| 2132 | // Pop the 2 items from the FP stack. |
| 2133 | __ fucompp(); |
| 2134 | |
| 2135 | // Load the value from the stack into an XMM register. |
| 2136 | DCHECK(out.IsFpuRegister()) << out; |
| 2137 | if (is_float) { |
| 2138 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 2139 | } else { |
| 2140 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 2141 | } |
| 2142 | |
| 2143 | // And remove the temporary stack space we allocated. |
| 2144 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 2145 | } |
| 2146 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2147 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 2148 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2149 | Primitive::Type type = instruction->GetResultType(); |
| 2150 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 2151 | |
| 2152 | bool is_div = instruction->IsDiv(); |
| 2153 | LocationSummary* locations = instruction->GetLocations(); |
| 2154 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2155 | CpuRegister out_reg = locations->Out().AsRegister<CpuRegister>(); |
| 2156 | CpuRegister second_reg = locations->InAt(1).AsRegister<CpuRegister>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2157 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2158 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2159 | DCHECK_EQ(is_div ? RAX : RDX, out_reg.AsRegister()); |
| 2160 | |
| 2161 | SlowPathCodeX86_64* slow_path = |
| 2162 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86_64( |
| 2163 | out_reg.AsRegister(), type, is_div); |
| 2164 | codegen_->AddSlowPath(slow_path); |
| 2165 | |
| 2166 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 2167 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 2168 | // 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] | 2169 | if (type == Primitive::kPrimInt) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2170 | __ cmpl(second_reg, Immediate(-1)); |
| 2171 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2172 | // edx:eax <- sign-extended of eax |
| 2173 | __ cdq(); |
| 2174 | // eax = quotient, edx = remainder |
| 2175 | __ idivl(second_reg); |
| 2176 | } else { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2177 | __ cmpq(second_reg, Immediate(-1)); |
| 2178 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2179 | // rdx:rax <- sign-extended of rax |
| 2180 | __ cqo(); |
| 2181 | // rax = quotient, rdx = remainder |
| 2182 | __ idivq(second_reg); |
| 2183 | } |
| 2184 | |
| 2185 | __ Bind(slow_path->GetExitLabel()); |
| 2186 | } |
| 2187 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2188 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 2189 | LocationSummary* locations = |
| 2190 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 2191 | switch (div->GetResultType()) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2192 | case Primitive::kPrimInt: |
| 2193 | case Primitive::kPrimLong: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2194 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
| 2195 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2196 | locations->SetOut(Location::SameAsFirstInput()); |
| 2197 | // Intel uses edx:eax as the dividend. |
| 2198 | locations->AddTemp(Location::RegisterLocation(RDX)); |
| 2199 | break; |
| 2200 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2201 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2202 | case Primitive::kPrimFloat: |
| 2203 | case Primitive::kPrimDouble: { |
| 2204 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2205 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2206 | locations->SetOut(Location::SameAsFirstInput()); |
| 2207 | break; |
| 2208 | } |
| 2209 | |
| 2210 | default: |
| 2211 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2212 | } |
| 2213 | } |
| 2214 | |
| 2215 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 2216 | LocationSummary* locations = div->GetLocations(); |
| 2217 | Location first = locations->InAt(0); |
| 2218 | Location second = locations->InAt(1); |
| 2219 | DCHECK(first.Equals(locations->Out())); |
| 2220 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2221 | Primitive::Type type = div->GetResultType(); |
| 2222 | switch (type) { |
| 2223 | case Primitive::kPrimInt: |
| 2224 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2225 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2226 | break; |
| 2227 | } |
| 2228 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2229 | case Primitive::kPrimFloat: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2230 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2231 | break; |
| 2232 | } |
| 2233 | |
| 2234 | case Primitive::kPrimDouble: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2235 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2236 | break; |
| 2237 | } |
| 2238 | |
| 2239 | default: |
| 2240 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2241 | } |
| 2242 | } |
| 2243 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2244 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2245 | Primitive::Type type = rem->GetResultType(); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2246 | LocationSummary* locations = |
| 2247 | new (GetGraph()->GetArena()) LocationSummary(rem, LocationSummary::kNoCall); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2248 | |
| 2249 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2250 | case Primitive::kPrimInt: |
| 2251 | case Primitive::kPrimLong: { |
| 2252 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
| 2253 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2254 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 2255 | locations->SetOut(Location::RegisterLocation(RDX)); |
| 2256 | break; |
| 2257 | } |
| 2258 | |
| 2259 | case Primitive::kPrimFloat: |
| 2260 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2261 | locations->SetInAt(0, Location::Any()); |
| 2262 | locations->SetInAt(1, Location::Any()); |
| 2263 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2264 | locations->AddTemp(Location::RegisterLocation(RAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2265 | break; |
| 2266 | } |
| 2267 | |
| 2268 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2269 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2270 | } |
| 2271 | } |
| 2272 | |
| 2273 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| 2274 | Primitive::Type type = rem->GetResultType(); |
| 2275 | switch (type) { |
| 2276 | case Primitive::kPrimInt: |
| 2277 | case Primitive::kPrimLong: { |
| 2278 | GenerateDivRemIntegral(rem); |
| 2279 | break; |
| 2280 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2281 | case Primitive::kPrimFloat: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2282 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2283 | GenerateRemFP(rem); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2284 | break; |
| 2285 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2286 | default: |
| 2287 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 2288 | } |
| 2289 | } |
| 2290 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2291 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2292 | LocationSummary* locations = |
| 2293 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 2294 | locations->SetInAt(0, Location::Any()); |
| 2295 | if (instruction->HasUses()) { |
| 2296 | locations->SetOut(Location::SameAsFirstInput()); |
| 2297 | } |
| 2298 | } |
| 2299 | |
| 2300 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 2301 | SlowPathCodeX86_64* slow_path = |
| 2302 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction); |
| 2303 | codegen_->AddSlowPath(slow_path); |
| 2304 | |
| 2305 | LocationSummary* locations = instruction->GetLocations(); |
| 2306 | Location value = locations->InAt(0); |
| 2307 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2308 | switch (instruction->GetType()) { |
| 2309 | case Primitive::kPrimInt: { |
| 2310 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2311 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2312 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2313 | } else if (value.IsStackSlot()) { |
| 2314 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 2315 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2316 | } else { |
| 2317 | DCHECK(value.IsConstant()) << value; |
| 2318 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 2319 | __ jmp(slow_path->GetEntryLabel()); |
| 2320 | } |
| 2321 | } |
| 2322 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2323 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2324 | case Primitive::kPrimLong: { |
| 2325 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2326 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2327 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2328 | } else if (value.IsDoubleStackSlot()) { |
| 2329 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 2330 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2331 | } else { |
| 2332 | DCHECK(value.IsConstant()) << value; |
| 2333 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 2334 | __ jmp(slow_path->GetEntryLabel()); |
| 2335 | } |
| 2336 | } |
| 2337 | break; |
| 2338 | } |
| 2339 | default: |
| 2340 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2341 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2342 | } |
| 2343 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2344 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 2345 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 2346 | |
| 2347 | LocationSummary* locations = |
| 2348 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 2349 | |
| 2350 | switch (op->GetResultType()) { |
| 2351 | case Primitive::kPrimInt: |
| 2352 | case Primitive::kPrimLong: { |
| 2353 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2354 | // The shift count needs to be in CL. |
| 2355 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 2356 | locations->SetOut(Location::SameAsFirstInput()); |
| 2357 | break; |
| 2358 | } |
| 2359 | default: |
| 2360 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 2361 | } |
| 2362 | } |
| 2363 | |
| 2364 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 2365 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 2366 | |
| 2367 | LocationSummary* locations = op->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2368 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2369 | Location second = locations->InAt(1); |
| 2370 | |
| 2371 | switch (op->GetResultType()) { |
| 2372 | case Primitive::kPrimInt: { |
| 2373 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2374 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2375 | if (op->IsShl()) { |
| 2376 | __ shll(first_reg, second_reg); |
| 2377 | } else if (op->IsShr()) { |
| 2378 | __ sarl(first_reg, second_reg); |
| 2379 | } else { |
| 2380 | __ shrl(first_reg, second_reg); |
| 2381 | } |
| 2382 | } else { |
Nicolas Geoffray | 486cc19 | 2014-12-08 18:00:55 +0000 | [diff] [blame] | 2383 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2384 | if (op->IsShl()) { |
| 2385 | __ shll(first_reg, imm); |
| 2386 | } else if (op->IsShr()) { |
| 2387 | __ sarl(first_reg, imm); |
| 2388 | } else { |
| 2389 | __ shrl(first_reg, imm); |
| 2390 | } |
| 2391 | } |
| 2392 | break; |
| 2393 | } |
| 2394 | case Primitive::kPrimLong: { |
| 2395 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2396 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2397 | if (op->IsShl()) { |
| 2398 | __ shlq(first_reg, second_reg); |
| 2399 | } else if (op->IsShr()) { |
| 2400 | __ sarq(first_reg, second_reg); |
| 2401 | } else { |
| 2402 | __ shrq(first_reg, second_reg); |
| 2403 | } |
| 2404 | } else { |
Nicolas Geoffray | 486cc19 | 2014-12-08 18:00:55 +0000 | [diff] [blame] | 2405 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 2406 | if (op->IsShl()) { |
| 2407 | __ shlq(first_reg, imm); |
| 2408 | } else if (op->IsShr()) { |
| 2409 | __ sarq(first_reg, imm); |
| 2410 | } else { |
| 2411 | __ shrq(first_reg, imm); |
| 2412 | } |
| 2413 | } |
| 2414 | break; |
| 2415 | } |
| 2416 | default: |
| 2417 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 2418 | } |
| 2419 | } |
| 2420 | |
| 2421 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 2422 | HandleShift(shl); |
| 2423 | } |
| 2424 | |
| 2425 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 2426 | HandleShift(shl); |
| 2427 | } |
| 2428 | |
| 2429 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 2430 | HandleShift(shr); |
| 2431 | } |
| 2432 | |
| 2433 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 2434 | HandleShift(shr); |
| 2435 | } |
| 2436 | |
| 2437 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 2438 | HandleShift(ushr); |
| 2439 | } |
| 2440 | |
| 2441 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 2442 | HandleShift(ushr); |
| 2443 | } |
| 2444 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2445 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2446 | LocationSummary* locations = |
| 2447 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 2448 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2449 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2450 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2451 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2452 | } |
| 2453 | |
| 2454 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
| 2455 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2456 | codegen_->LoadCurrentMethod(CpuRegister(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2457 | __ movq(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(instruction->GetTypeIndex())); |
| 2458 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 2459 | __ gs()->call( |
| 2460 | Address::Absolute(GetThreadOffset<kX86_64WordSize>(instruction->GetEntrypoint()), true)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2461 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2462 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2463 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2464 | } |
| 2465 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2466 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 2467 | LocationSummary* locations = |
| 2468 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 2469 | InvokeRuntimeCallingConvention calling_convention; |
| 2470 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 2471 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2472 | locations->SetOut(Location::RegisterLocation(RAX)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 2473 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2474 | } |
| 2475 | |
| 2476 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| 2477 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 2478 | codegen_->LoadCurrentMethod(CpuRegister(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2479 | __ movq(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(instruction->GetTypeIndex())); |
| 2480 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 2481 | __ gs()->call( |
| 2482 | Address::Absolute(GetThreadOffset<kX86_64WordSize>(instruction->GetEntrypoint()), true)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 2483 | |
| 2484 | DCHECK(!codegen_->IsLeafMethod()); |
| 2485 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 2486 | } |
| 2487 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2488 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2489 | LocationSummary* locations = |
| 2490 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2491 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 2492 | if (location.IsStackSlot()) { |
| 2493 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 2494 | } else if (location.IsDoubleStackSlot()) { |
| 2495 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 2496 | } |
| 2497 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2498 | } |
| 2499 | |
| 2500 | void InstructionCodeGeneratorX86_64::VisitParameterValue(HParameterValue* instruction) { |
| 2501 | // Nothing to do, the parameter is already at its location. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2502 | UNUSED(instruction); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2503 | } |
| 2504 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2505 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2506 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2507 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2508 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2509 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2510 | } |
| 2511 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2512 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 2513 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2514 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 2515 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2516 | Location out = locations->Out(); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame^] | 2517 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2518 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2519 | __ notl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2520 | break; |
| 2521 | |
| 2522 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2523 | __ notq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 2524 | break; |
| 2525 | |
| 2526 | default: |
| 2527 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 2528 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2529 | } |
| 2530 | |
| 2531 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2532 | LocationSummary* locations = |
| 2533 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2534 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 2535 | locations->SetInAt(i, Location::Any()); |
| 2536 | } |
| 2537 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2538 | } |
| 2539 | |
| 2540 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2541 | UNUSED(instruction); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2542 | LOG(FATAL) << "Unimplemented"; |
| 2543 | } |
| 2544 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2545 | void InstructionCodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 2546 | /* |
| 2547 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 2548 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 2549 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 2550 | */ |
| 2551 | switch (kind) { |
| 2552 | case MemBarrierKind::kAnyAny: { |
| 2553 | __ mfence(); |
| 2554 | break; |
| 2555 | } |
| 2556 | case MemBarrierKind::kAnyStore: |
| 2557 | case MemBarrierKind::kLoadAny: |
| 2558 | case MemBarrierKind::kStoreStore: { |
| 2559 | // nop |
| 2560 | break; |
| 2561 | } |
| 2562 | default: |
| 2563 | LOG(FATAL) << "Unexpected memory barier " << kind; |
| 2564 | } |
| 2565 | } |
| 2566 | |
| 2567 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 2568 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 2569 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2570 | LocationSummary* locations = |
| 2571 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2572 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2573 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2574 | } |
| 2575 | |
| 2576 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 2577 | const FieldInfo& field_info) { |
| 2578 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 2579 | |
| 2580 | LocationSummary* locations = instruction->GetLocations(); |
| 2581 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 2582 | Location out = locations->Out(); |
| 2583 | bool is_volatile = field_info.IsVolatile(); |
| 2584 | Primitive::Type field_type = field_info.GetFieldType(); |
| 2585 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 2586 | |
| 2587 | switch (field_type) { |
| 2588 | case Primitive::kPrimBoolean: { |
| 2589 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 2590 | break; |
| 2591 | } |
| 2592 | |
| 2593 | case Primitive::kPrimByte: { |
| 2594 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 2595 | break; |
| 2596 | } |
| 2597 | |
| 2598 | case Primitive::kPrimShort: { |
| 2599 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 2600 | break; |
| 2601 | } |
| 2602 | |
| 2603 | case Primitive::kPrimChar: { |
| 2604 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 2605 | break; |
| 2606 | } |
| 2607 | |
| 2608 | case Primitive::kPrimInt: |
| 2609 | case Primitive::kPrimNot: { |
| 2610 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 2611 | break; |
| 2612 | } |
| 2613 | |
| 2614 | case Primitive::kPrimLong: { |
| 2615 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 2616 | break; |
| 2617 | } |
| 2618 | |
| 2619 | case Primitive::kPrimFloat: { |
| 2620 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 2621 | break; |
| 2622 | } |
| 2623 | |
| 2624 | case Primitive::kPrimDouble: { |
| 2625 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 2626 | break; |
| 2627 | } |
| 2628 | |
| 2629 | case Primitive::kPrimVoid: |
| 2630 | LOG(FATAL) << "Unreachable type " << field_type; |
| 2631 | UNREACHABLE(); |
| 2632 | } |
| 2633 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2634 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2635 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2636 | if (is_volatile) { |
| 2637 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 2638 | } |
| 2639 | } |
| 2640 | |
| 2641 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 2642 | const FieldInfo& field_info) { |
| 2643 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 2644 | |
| 2645 | LocationSummary* locations = |
| 2646 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2647 | bool needs_write_barrier = |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2648 | CodeGenerator::StoreNeedsWriteBarrier(field_info.GetFieldType(), instruction->InputAt(1)); |
| 2649 | |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2650 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2651 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2652 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 2653 | // Temporary registers for the write barrier. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 2654 | locations->AddTemp(Location::RequiresRegister()); |
| 2655 | locations->AddTemp(Location::RequiresRegister()); |
| 2656 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2657 | } |
| 2658 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2659 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
| 2660 | const FieldInfo& field_info) { |
| 2661 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 2662 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2663 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2664 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 2665 | Location value = locations->InAt(1); |
| 2666 | bool is_volatile = field_info.IsVolatile(); |
| 2667 | Primitive::Type field_type = field_info.GetFieldType(); |
| 2668 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 2669 | |
| 2670 | if (is_volatile) { |
| 2671 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 2672 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2673 | |
| 2674 | switch (field_type) { |
| 2675 | case Primitive::kPrimBoolean: |
| 2676 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2677 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2678 | break; |
| 2679 | } |
| 2680 | |
| 2681 | case Primitive::kPrimShort: |
| 2682 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2683 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2684 | break; |
| 2685 | } |
| 2686 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2687 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2688 | case Primitive::kPrimNot: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2689 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2690 | break; |
| 2691 | } |
| 2692 | |
| 2693 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2694 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2695 | break; |
| 2696 | } |
| 2697 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2698 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2699 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2700 | break; |
| 2701 | } |
| 2702 | |
| 2703 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2704 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 2705 | break; |
| 2706 | } |
| 2707 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2708 | case Primitive::kPrimVoid: |
| 2709 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2710 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2711 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2712 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2713 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 2714 | |
| 2715 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 2716 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2717 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 2718 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>()); |
| 2719 | } |
| 2720 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2721 | if (is_volatile) { |
| 2722 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 2723 | } |
| 2724 | } |
| 2725 | |
| 2726 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 2727 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 2728 | } |
| 2729 | |
| 2730 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 2731 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2732 | } |
| 2733 | |
| 2734 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2735 | HandleFieldGet(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2736 | } |
| 2737 | |
| 2738 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2739 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 2740 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2741 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2742 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 2743 | HandleFieldGet(instruction); |
| 2744 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2745 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2746 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 2747 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 2748 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2749 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2750 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 2751 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 2752 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2753 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 2754 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 2755 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2756 | } |
| 2757 | |
| 2758 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2759 | LocationSummary* locations = |
| 2760 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 2761 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 2762 | ? Location::RequiresRegister() |
| 2763 | : Location::Any(); |
| 2764 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2765 | if (instruction->HasUses()) { |
| 2766 | locations->SetOut(Location::SameAsFirstInput()); |
| 2767 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2768 | } |
| 2769 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 2770 | void InstructionCodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2771 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 2772 | return; |
| 2773 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 2774 | LocationSummary* locations = instruction->GetLocations(); |
| 2775 | Location obj = locations->InAt(0); |
| 2776 | |
| 2777 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
| 2778 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 2779 | } |
| 2780 | |
| 2781 | void InstructionCodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 2782 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2783 | codegen_->AddSlowPath(slow_path); |
| 2784 | |
| 2785 | LocationSummary* locations = instruction->GetLocations(); |
| 2786 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2787 | |
| 2788 | if (obj.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2789 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2790 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2791 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2792 | } else { |
| 2793 | DCHECK(obj.IsConstant()) << obj; |
| 2794 | DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0); |
| 2795 | __ jmp(slow_path->GetEntryLabel()); |
| 2796 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2797 | } |
| 2798 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2799 | } |
| 2800 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 2801 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
| 2802 | if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) { |
| 2803 | GenerateImplicitNullCheck(instruction); |
| 2804 | } else { |
| 2805 | GenerateExplicitNullCheck(instruction); |
| 2806 | } |
| 2807 | } |
| 2808 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2809 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2810 | LocationSummary* locations = |
| 2811 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2812 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 2813 | locations->SetInAt( |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2814 | 1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2815 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2816 | } |
| 2817 | |
| 2818 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 2819 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2820 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2821 | Location index = locations->InAt(1); |
| 2822 | |
| 2823 | switch (instruction->GetType()) { |
| 2824 | case Primitive::kPrimBoolean: { |
| 2825 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2826 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2827 | if (index.IsConstant()) { |
| 2828 | __ movzxb(out, Address(obj, |
| 2829 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 2830 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2831 | __ movzxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2832 | } |
| 2833 | break; |
| 2834 | } |
| 2835 | |
| 2836 | case Primitive::kPrimByte: { |
| 2837 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2838 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2839 | if (index.IsConstant()) { |
| 2840 | __ movsxb(out, Address(obj, |
| 2841 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 2842 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2843 | __ movsxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2844 | } |
| 2845 | break; |
| 2846 | } |
| 2847 | |
| 2848 | case Primitive::kPrimShort: { |
| 2849 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2850 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2851 | if (index.IsConstant()) { |
| 2852 | __ movsxw(out, Address(obj, |
| 2853 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 2854 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2855 | __ movsxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2856 | } |
| 2857 | break; |
| 2858 | } |
| 2859 | |
| 2860 | case Primitive::kPrimChar: { |
| 2861 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2862 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2863 | if (index.IsConstant()) { |
| 2864 | __ movzxw(out, Address(obj, |
| 2865 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 2866 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2867 | __ movzxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2868 | } |
| 2869 | break; |
| 2870 | } |
| 2871 | |
| 2872 | case Primitive::kPrimInt: |
| 2873 | case Primitive::kPrimNot: { |
| 2874 | DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t)); |
| 2875 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2876 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2877 | if (index.IsConstant()) { |
| 2878 | __ movl(out, Address(obj, |
| 2879 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 2880 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2881 | __ movl(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2882 | } |
| 2883 | break; |
| 2884 | } |
| 2885 | |
| 2886 | case Primitive::kPrimLong: { |
| 2887 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2888 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2889 | if (index.IsConstant()) { |
| 2890 | __ movq(out, Address(obj, |
| 2891 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 2892 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2893 | __ movq(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2894 | } |
| 2895 | break; |
| 2896 | } |
| 2897 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2898 | case Primitive::kPrimFloat: { |
| 2899 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2900 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2901 | if (index.IsConstant()) { |
| 2902 | __ movss(out, Address(obj, |
| 2903 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 2904 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2905 | __ movss(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2906 | } |
| 2907 | break; |
| 2908 | } |
| 2909 | |
| 2910 | case Primitive::kPrimDouble: { |
| 2911 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2912 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2913 | if (index.IsConstant()) { |
| 2914 | __ movsd(out, Address(obj, |
| 2915 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 2916 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2917 | __ movsd(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2918 | } |
| 2919 | break; |
| 2920 | } |
| 2921 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2922 | case Primitive::kPrimVoid: |
| 2923 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 2924 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2925 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2926 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2927 | } |
| 2928 | |
| 2929 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2930 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2931 | |
| 2932 | bool needs_write_barrier = |
| 2933 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 2934 | bool needs_runtime_call = instruction->NeedsTypeCheck(); |
| 2935 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2936 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2937 | instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 2938 | if (needs_runtime_call) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2939 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2940 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2941 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2942 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2943 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2944 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 2945 | locations->SetInAt( |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2946 | 1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 2947 | locations->SetInAt(2, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2948 | if (value_type == Primitive::kPrimLong) { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2949 | locations->SetInAt(2, Location::RequiresRegister()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2950 | } else if (value_type == Primitive::kPrimFloat || value_type == Primitive::kPrimDouble) { |
| 2951 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2952 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 2953 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2954 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2955 | |
| 2956 | if (needs_write_barrier) { |
| 2957 | // Temporary registers for the write barrier. |
| 2958 | locations->AddTemp(Location::RequiresRegister()); |
| 2959 | locations->AddTemp(Location::RequiresRegister()); |
| 2960 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2961 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2962 | } |
| 2963 | |
| 2964 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 2965 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2966 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2967 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2968 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2969 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2970 | bool needs_runtime_call = locations->WillCall(); |
| 2971 | bool needs_write_barrier = |
| 2972 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2973 | |
| 2974 | switch (value_type) { |
| 2975 | case Primitive::kPrimBoolean: |
| 2976 | case Primitive::kPrimByte: { |
| 2977 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2978 | if (index.IsConstant()) { |
| 2979 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2980 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2981 | __ movb(Address(obj, offset), value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2982 | } else { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2983 | __ movb(Address(obj, offset), |
| 2984 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2985 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2986 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2987 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2988 | __ movb(Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset), |
| 2989 | value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2990 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2991 | __ movb(Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 2992 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 2993 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2994 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2995 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2996 | break; |
| 2997 | } |
| 2998 | |
| 2999 | case Primitive::kPrimShort: |
| 3000 | case Primitive::kPrimChar: { |
| 3001 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3002 | if (index.IsConstant()) { |
| 3003 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3004 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3005 | __ movw(Address(obj, offset), value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3006 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3007 | DCHECK(value.IsConstant()) << value; |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3008 | __ movw(Address(obj, offset), |
| 3009 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3010 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3011 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3012 | DCHECK(index.IsRegister()) << index; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3013 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3014 | __ movw(Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset), |
| 3015 | value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3016 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3017 | DCHECK(value.IsConstant()) << value; |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3018 | __ movw(Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3019 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 3020 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3021 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3022 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3023 | break; |
| 3024 | } |
| 3025 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3026 | case Primitive::kPrimInt: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3027 | case Primitive::kPrimNot: { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3028 | if (!needs_runtime_call) { |
| 3029 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 3030 | if (index.IsConstant()) { |
| 3031 | size_t offset = |
| 3032 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 3033 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3034 | __ movl(Address(obj, offset), value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3035 | } else { |
| 3036 | DCHECK(value.IsConstant()) << value; |
| 3037 | __ movl(Address(obj, offset), |
| 3038 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 3039 | } |
| 3040 | } else { |
| 3041 | DCHECK(index.IsRegister()) << index; |
| 3042 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3043 | __ movl(Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset), |
| 3044 | value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3045 | } else { |
| 3046 | DCHECK(value.IsConstant()) << value; |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3047 | __ movl(Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset), |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3048 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 3049 | } |
| 3050 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3051 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3052 | if (needs_write_barrier) { |
| 3053 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3054 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3055 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 3056 | codegen_->MarkGCCard(temp, card, obj, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3057 | } |
| 3058 | } else { |
| 3059 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3060 | __ gs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pAputObject), |
| 3061 | true)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3062 | DCHECK(!codegen_->IsLeafMethod()); |
| 3063 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3064 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3065 | break; |
| 3066 | } |
| 3067 | |
| 3068 | case Primitive::kPrimLong: { |
| 3069 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3070 | if (index.IsConstant()) { |
| 3071 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3072 | DCHECK(value.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3073 | __ movq(Address(obj, offset), value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3074 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3075 | DCHECK(value.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3076 | __ movq(Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset), |
| 3077 | value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3078 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3079 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3080 | break; |
| 3081 | } |
| 3082 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3083 | case Primitive::kPrimFloat: { |
| 3084 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 3085 | if (index.IsConstant()) { |
| 3086 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 3087 | DCHECK(value.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3088 | __ movss(Address(obj, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3089 | } else { |
| 3090 | DCHECK(value.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3091 | __ movss(Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset), |
| 3092 | value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3093 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3094 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3095 | break; |
| 3096 | } |
| 3097 | |
| 3098 | case Primitive::kPrimDouble: { |
| 3099 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 3100 | if (index.IsConstant()) { |
| 3101 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 3102 | DCHECK(value.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3103 | __ movsd(Address(obj, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3104 | } else { |
| 3105 | DCHECK(value.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3106 | __ movsd(Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset), |
| 3107 | value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3108 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3109 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3110 | break; |
| 3111 | } |
| 3112 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3113 | case Primitive::kPrimVoid: |
| 3114 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3115 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3116 | } |
| 3117 | } |
| 3118 | |
| 3119 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3120 | LocationSummary* locations = |
| 3121 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3122 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3123 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3124 | } |
| 3125 | |
| 3126 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
| 3127 | LocationSummary* locations = instruction->GetLocations(); |
| 3128 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3129 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3130 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3131 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3132 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3133 | } |
| 3134 | |
| 3135 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3136 | LocationSummary* locations = |
| 3137 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3138 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3139 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3140 | if (instruction->HasUses()) { |
| 3141 | locations->SetOut(Location::SameAsFirstInput()); |
| 3142 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3143 | } |
| 3144 | |
| 3145 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 3146 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 3147 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64( |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3148 | instruction, locations->InAt(0), locations->InAt(1)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3149 | codegen_->AddSlowPath(slow_path); |
| 3150 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3151 | CpuRegister index = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3152 | CpuRegister length = locations->InAt(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3153 | |
| 3154 | __ cmpl(index, length); |
| 3155 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
| 3156 | } |
| 3157 | |
| 3158 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 3159 | CpuRegister card, |
| 3160 | CpuRegister object, |
| 3161 | CpuRegister value) { |
| 3162 | Label is_null; |
| 3163 | __ testl(value, value); |
| 3164 | __ j(kEqual, &is_null); |
| 3165 | __ gs()->movq(card, Address::Absolute( |
| 3166 | Thread::CardTableOffset<kX86_64WordSize>().Int32Value(), true)); |
| 3167 | __ movq(temp, object); |
| 3168 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
| 3169 | __ movb(Address(temp, card, TIMES_1, 0), card); |
| 3170 | __ Bind(&is_null); |
| 3171 | } |
| 3172 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3173 | void LocationsBuilderX86_64::VisitTemporary(HTemporary* temp) { |
| 3174 | temp->SetLocations(nullptr); |
| 3175 | } |
| 3176 | |
| 3177 | void InstructionCodeGeneratorX86_64::VisitTemporary(HTemporary* temp) { |
| 3178 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3179 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3180 | } |
| 3181 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3182 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3183 | UNUSED(instruction); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3184 | LOG(FATAL) << "Unimplemented"; |
| 3185 | } |
| 3186 | |
| 3187 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3188 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 3189 | } |
| 3190 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 3191 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 3192 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 3193 | } |
| 3194 | |
| 3195 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 3196 | HBasicBlock* block = instruction->GetBlock(); |
| 3197 | if (block->GetLoopInformation() != nullptr) { |
| 3198 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 3199 | // The back edge will generate the suspend check. |
| 3200 | return; |
| 3201 | } |
| 3202 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 3203 | // The goto will generate the suspend check. |
| 3204 | return; |
| 3205 | } |
| 3206 | GenerateSuspendCheck(instruction, nullptr); |
| 3207 | } |
| 3208 | |
| 3209 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 3210 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 3211 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 3212 | new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 3213 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 3214 | __ gs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 3215 | Thread::ThreadFlagsOffset<kX86_64WordSize>().Int32Value(), true), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 3216 | if (successor == nullptr) { |
| 3217 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 3218 | __ Bind(slow_path->GetReturnLabel()); |
| 3219 | } else { |
| 3220 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 3221 | __ jmp(slow_path->GetEntryLabel()); |
| 3222 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 3223 | } |
| 3224 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3225 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 3226 | return codegen_->GetAssembler(); |
| 3227 | } |
| 3228 | |
| 3229 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
| 3230 | MoveOperands* move = moves_.Get(index); |
| 3231 | Location source = move->GetSource(); |
| 3232 | Location destination = move->GetDestination(); |
| 3233 | |
| 3234 | if (source.IsRegister()) { |
| 3235 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3236 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3237 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3238 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3239 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3240 | } else { |
| 3241 | DCHECK(destination.IsDoubleStackSlot()); |
| 3242 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3243 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3244 | } |
| 3245 | } else if (source.IsStackSlot()) { |
| 3246 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3247 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3248 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3249 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3250 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3251 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3252 | } else { |
| 3253 | DCHECK(destination.IsStackSlot()); |
| 3254 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 3255 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 3256 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3257 | } else if (source.IsDoubleStackSlot()) { |
| 3258 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3259 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3260 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3261 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3262 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 3263 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3264 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 3265 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3266 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 3267 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 3268 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3269 | } else if (source.IsConstant()) { |
| 3270 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 3271 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 3272 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3273 | if (destination.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3274 | if (value == 0) { |
| 3275 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 3276 | } else { |
| 3277 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 3278 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3279 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3280 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3281 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3282 | } |
| 3283 | } else if (constant->IsLongConstant()) { |
| 3284 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 3285 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3286 | __ movq(destination.AsRegister<CpuRegister>(), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3287 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3288 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3289 | __ movq(CpuRegister(TMP), Immediate(value)); |
| 3290 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 3291 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3292 | } else if (constant->IsFloatConstant()) { |
| 3293 | Immediate imm(bit_cast<float, int32_t>(constant->AsFloatConstant()->GetValue())); |
| 3294 | if (destination.IsFpuRegister()) { |
| 3295 | __ movl(CpuRegister(TMP), imm); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3296 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3297 | } else { |
| 3298 | DCHECK(destination.IsStackSlot()) << destination; |
| 3299 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 3300 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3301 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3302 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
| 3303 | Immediate imm(bit_cast<double, int64_t>(constant->AsDoubleConstant()->GetValue())); |
| 3304 | if (destination.IsFpuRegister()) { |
| 3305 | __ movq(CpuRegister(TMP), imm); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3306 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3307 | } else { |
| 3308 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 3309 | __ movq(CpuRegister(TMP), imm); |
| 3310 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 3311 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3312 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3313 | } else if (source.IsFpuRegister()) { |
| 3314 | if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3315 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3316 | } else if (destination.IsStackSlot()) { |
| 3317 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3318 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3319 | } else { |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 3320 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3321 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3322 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3323 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3324 | } |
| 3325 | } |
| 3326 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3327 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3328 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3329 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 3330 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3331 | } |
| 3332 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3333 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3334 | ScratchRegisterScope ensure_scratch( |
| 3335 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 3336 | |
| 3337 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 3338 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 3339 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 3340 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 3341 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 3342 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 3343 | CpuRegister(ensure_scratch.GetRegister())); |
| 3344 | } |
| 3345 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3346 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 3347 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 3348 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 3349 | __ movq(reg, CpuRegister(TMP)); |
| 3350 | } |
| 3351 | |
| 3352 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 3353 | ScratchRegisterScope ensure_scratch( |
| 3354 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 3355 | |
| 3356 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 3357 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 3358 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 3359 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 3360 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 3361 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 3362 | CpuRegister(ensure_scratch.GetRegister())); |
| 3363 | } |
| 3364 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3365 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 3366 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 3367 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 3368 | __ movd(reg, CpuRegister(TMP)); |
| 3369 | } |
| 3370 | |
| 3371 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 3372 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 3373 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 3374 | __ movd(reg, CpuRegister(TMP)); |
| 3375 | } |
| 3376 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3377 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
| 3378 | MoveOperands* move = moves_.Get(index); |
| 3379 | Location source = move->GetSource(); |
| 3380 | Location destination = move->GetDestination(); |
| 3381 | |
| 3382 | if (source.IsRegister() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3383 | __ xchgq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3384 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3385 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3386 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3387 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3388 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3389 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 3390 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3391 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3392 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3393 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3394 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 3395 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3396 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3397 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 3398 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 3399 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3400 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3401 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3402 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3403 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3404 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3405 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3406 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3407 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3408 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3409 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3410 | } |
| 3411 | } |
| 3412 | |
| 3413 | |
| 3414 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 3415 | __ pushq(CpuRegister(reg)); |
| 3416 | } |
| 3417 | |
| 3418 | |
| 3419 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 3420 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3421 | } |
| 3422 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3423 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
| 3424 | SlowPathCodeX86_64* slow_path, CpuRegister class_reg) { |
| 3425 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 3426 | Immediate(mirror::Class::kStatusInitialized)); |
| 3427 | __ j(kLess, slow_path->GetEntryLabel()); |
| 3428 | __ Bind(slow_path->GetExitLabel()); |
| 3429 | // No need for memory fence, thanks to the X86_64 memory model. |
| 3430 | } |
| 3431 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3432 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3433 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() |
| 3434 | ? LocationSummary::kCallOnSlowPath |
| 3435 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3436 | LocationSummary* locations = |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3437 | new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3438 | locations->SetOut(Location::RequiresRegister()); |
| 3439 | } |
| 3440 | |
| 3441 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3442 | CpuRegister out = cls->GetLocations()->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3443 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3444 | DCHECK(!cls->CanCallRuntime()); |
| 3445 | DCHECK(!cls->MustGenerateClinitCheck()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3446 | codegen_->LoadCurrentMethod(out); |
| 3447 | __ movl(out, Address(out, mirror::ArtMethod::DeclaringClassOffset().Int32Value())); |
| 3448 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3449 | DCHECK(cls->CanCallRuntime()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3450 | codegen_->LoadCurrentMethod(out); |
| 3451 | __ movl(out, Address(out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value())); |
| 3452 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3453 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 3454 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 3455 | codegen_->AddSlowPath(slow_path); |
| 3456 | __ testl(out, out); |
| 3457 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3458 | if (cls->MustGenerateClinitCheck()) { |
| 3459 | GenerateClassInitializationCheck(slow_path, out); |
| 3460 | } else { |
| 3461 | __ Bind(slow_path->GetExitLabel()); |
| 3462 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3463 | } |
| 3464 | } |
| 3465 | |
| 3466 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 3467 | LocationSummary* locations = |
| 3468 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 3469 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3470 | if (check->HasUses()) { |
| 3471 | locations->SetOut(Location::SameAsFirstInput()); |
| 3472 | } |
| 3473 | } |
| 3474 | |
| 3475 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 3476 | // We assume the class to not be null. |
| 3477 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 3478 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3479 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3480 | GenerateClassInitializationCheck(slow_path, |
| 3481 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 3482 | } |
| 3483 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 3484 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
| 3485 | LocationSummary* locations = |
| 3486 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
| 3487 | locations->SetOut(Location::RequiresRegister()); |
| 3488 | } |
| 3489 | |
| 3490 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) { |
| 3491 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86_64(load); |
| 3492 | codegen_->AddSlowPath(slow_path); |
| 3493 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3494 | CpuRegister out = load->GetLocations()->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 3495 | codegen_->LoadCurrentMethod(CpuRegister(out)); |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 3496 | __ movl(out, Address(out, mirror::ArtMethod::DeclaringClassOffset().Int32Value())); |
| 3497 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 3498 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
| 3499 | __ testl(out, out); |
| 3500 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3501 | __ Bind(slow_path->GetExitLabel()); |
| 3502 | } |
| 3503 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 3504 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 3505 | LocationSummary* locations = |
| 3506 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 3507 | locations->SetOut(Location::RequiresRegister()); |
| 3508 | } |
| 3509 | |
| 3510 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
| 3511 | Address address = Address::Absolute( |
| 3512 | Thread::ExceptionOffset<kX86_64WordSize>().Int32Value(), true); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3513 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 3514 | __ gs()->movl(address, Immediate(0)); |
| 3515 | } |
| 3516 | |
| 3517 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| 3518 | LocationSummary* locations = |
| 3519 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3520 | InvokeRuntimeCallingConvention calling_convention; |
| 3521 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3522 | } |
| 3523 | |
| 3524 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
| 3525 | __ gs()->call( |
| 3526 | Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pDeliverException), true)); |
| 3527 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3528 | } |
| 3529 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3530 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 3531 | LocationSummary::CallKind call_kind = instruction->IsClassFinal() |
| 3532 | ? LocationSummary::kNoCall |
| 3533 | : LocationSummary::kCallOnSlowPath; |
| 3534 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 3535 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3536 | locations->SetInAt(1, Location::Any()); |
| 3537 | locations->SetOut(Location::RequiresRegister()); |
| 3538 | } |
| 3539 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3540 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 3541 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3542 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 3543 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3544 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 3545 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3546 | Label done, zero; |
| 3547 | SlowPathCodeX86_64* slow_path = nullptr; |
| 3548 | |
| 3549 | // Return 0 if `obj` is null. |
| 3550 | // TODO: avoid this check if we know obj is not null. |
| 3551 | __ testl(obj, obj); |
| 3552 | __ j(kEqual, &zero); |
| 3553 | // Compare the class of `obj` with `cls`. |
| 3554 | __ movl(out, Address(obj, class_offset)); |
| 3555 | if (cls.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3556 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 3557 | } else { |
| 3558 | DCHECK(cls.IsStackSlot()) << cls; |
| 3559 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 3560 | } |
| 3561 | if (instruction->IsClassFinal()) { |
| 3562 | // Classes must be equal for the instanceof to succeed. |
| 3563 | __ j(kNotEqual, &zero); |
| 3564 | __ movl(out, Immediate(1)); |
| 3565 | __ jmp(&done); |
| 3566 | } else { |
| 3567 | // If the classes are not equal, we go into a slow path. |
| 3568 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 3569 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64( |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3570 | instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 3571 | codegen_->AddSlowPath(slow_path); |
| 3572 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 3573 | __ movl(out, Immediate(1)); |
| 3574 | __ jmp(&done); |
| 3575 | } |
| 3576 | __ Bind(&zero); |
| 3577 | __ movl(out, Immediate(0)); |
| 3578 | if (slow_path != nullptr) { |
| 3579 | __ Bind(slow_path->GetExitLabel()); |
| 3580 | } |
| 3581 | __ Bind(&done); |
| 3582 | } |
| 3583 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3584 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
| 3585 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 3586 | instruction, LocationSummary::kCallOnSlowPath); |
| 3587 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3588 | locations->SetInAt(1, Location::Any()); |
| 3589 | locations->AddTemp(Location::RequiresRegister()); |
| 3590 | } |
| 3591 | |
| 3592 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
| 3593 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3594 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3595 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3596 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3597 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3598 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64( |
| 3599 | instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc()); |
| 3600 | codegen_->AddSlowPath(slow_path); |
| 3601 | |
| 3602 | // TODO: avoid this check if we know obj is not null. |
| 3603 | __ testl(obj, obj); |
| 3604 | __ j(kEqual, slow_path->GetExitLabel()); |
| 3605 | // Compare the class of `obj` with `cls`. |
| 3606 | __ movl(temp, Address(obj, class_offset)); |
| 3607 | if (cls.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3608 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 3609 | } else { |
| 3610 | DCHECK(cls.IsStackSlot()) << cls; |
| 3611 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 3612 | } |
| 3613 | // Classes must be equal for the checkcast to succeed. |
| 3614 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 3615 | __ Bind(slow_path->GetExitLabel()); |
| 3616 | } |
| 3617 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 3618 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 3619 | LocationSummary* locations = |
| 3620 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3621 | InvokeRuntimeCallingConvention calling_convention; |
| 3622 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3623 | } |
| 3624 | |
| 3625 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 3626 | __ gs()->call(Address::Absolute(instruction->IsEnter() |
| 3627 | ? QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pLockObject) |
| 3628 | : QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pUnlockObject), |
| 3629 | true)); |
| 3630 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3631 | } |
| 3632 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3633 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 3634 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 3635 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 3636 | |
| 3637 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 3638 | LocationSummary* locations = |
| 3639 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3640 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 3641 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 3642 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3643 | if (instruction->GetType() == Primitive::kPrimInt) { |
| 3644 | locations->SetInAt(1, Location::Any()); |
| 3645 | } else { |
| 3646 | // Request a register to avoid loading a 64bits constant. |
| 3647 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3648 | } |
| 3649 | locations->SetOut(Location::SameAsFirstInput()); |
| 3650 | } |
| 3651 | |
| 3652 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 3653 | HandleBitwiseOperation(instruction); |
| 3654 | } |
| 3655 | |
| 3656 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 3657 | HandleBitwiseOperation(instruction); |
| 3658 | } |
| 3659 | |
| 3660 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 3661 | HandleBitwiseOperation(instruction); |
| 3662 | } |
| 3663 | |
| 3664 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 3665 | LocationSummary* locations = instruction->GetLocations(); |
| 3666 | Location first = locations->InAt(0); |
| 3667 | Location second = locations->InAt(1); |
| 3668 | DCHECK(first.Equals(locations->Out())); |
| 3669 | |
| 3670 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 3671 | if (second.IsRegister()) { |
| 3672 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3673 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3674 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3675 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3676 | } else { |
| 3677 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3678 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3679 | } |
| 3680 | } else if (second.IsConstant()) { |
| 3681 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 3682 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3683 | __ andl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3684 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3685 | __ orl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3686 | } else { |
| 3687 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3688 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3689 | } |
| 3690 | } else { |
| 3691 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 3692 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3693 | __ andl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3694 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3695 | __ orl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3696 | } else { |
| 3697 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3698 | __ xorl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3699 | } |
| 3700 | } |
| 3701 | } else { |
| 3702 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3703 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3704 | __ andq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3705 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3706 | __ orq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3707 | } else { |
| 3708 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3709 | __ xorq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3710 | } |
| 3711 | } |
| 3712 | } |
| 3713 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 3714 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction) { |
| 3715 | // Nothing to do, this should be removed during prepare for register allocator. |
| 3716 | UNUSED(instruction); |
| 3717 | LOG(FATAL) << "Unreachable"; |
| 3718 | } |
| 3719 | |
| 3720 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction) { |
| 3721 | // Nothing to do, this should be removed during prepare for register allocator. |
| 3722 | UNUSED(instruction); |
| 3723 | LOG(FATAL) << "Unreachable"; |
| 3724 | } |
| 3725 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3726 | } // namespace x86_64 |
| 3727 | } // namespace art |