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