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