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