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