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