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