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