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