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