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