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