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