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