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