Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_x86_64.h" |
| 18 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 19 | #include "art_method.h" |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 20 | #include "code_generator_utils.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 21 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 22 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 23 | #include "intrinsics.h" |
| 24 | #include "intrinsics_x86_64.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 25 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 26 | #include "mirror/class-inl.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 27 | #include "mirror/object_reference.h" |
| 28 | #include "thread.h" |
| 29 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 30 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 31 | #include "utils/x86_64/assembler_x86_64.h" |
| 32 | #include "utils/x86_64/managed_register_x86_64.h" |
| 33 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 34 | namespace art { |
| 35 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 36 | namespace x86_64 { |
| 37 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 38 | // Some x86_64 instructions require a register to be available as temp. |
| 39 | static constexpr Register TMP = R11; |
| 40 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 41 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 42 | static constexpr Register kMethodRegisterArgument = RDI; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 43 | |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 44 | static constexpr Register kCoreCalleeSaves[] = { RBX, RBP, R12, R13, R14, R15 }; |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 45 | static constexpr FloatRegister kFpuCalleeSaves[] = { XMM12, XMM13, XMM14, XMM15 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 46 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 47 | static constexpr int kC2ConditionMask = 0x400; |
| 48 | |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 49 | #define __ down_cast<X86_64Assembler*>(codegen->GetAssembler())-> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 50 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 51 | class NullCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 52 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 53 | explicit NullCheckSlowPathX86_64(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 54 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 55 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 56 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 57 | __ gs()->call( |
| 58 | Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pThrowNullPointer), true)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 59 | RecordPcInfo(codegen, instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 60 | } |
| 61 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 62 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86_64"; } |
| 63 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 64 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 65 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 66 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86_64); |
| 67 | }; |
| 68 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 69 | class DivZeroCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
| 70 | public: |
| 71 | explicit DivZeroCheckSlowPathX86_64(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 72 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 73 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 74 | __ Bind(GetEntryLabel()); |
| 75 | __ gs()->call( |
| 76 | Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pThrowDivZero), true)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 77 | RecordPcInfo(codegen, instruction_, instruction_->GetDexPc()); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 80 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86_64"; } |
| 81 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 82 | private: |
| 83 | HDivZeroCheck* const instruction_; |
| 84 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86_64); |
| 85 | }; |
| 86 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 87 | class DivRemMinusOneSlowPathX86_64 : public SlowPathCodeX86_64 { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 88 | public: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 89 | explicit DivRemMinusOneSlowPathX86_64(Register reg, Primitive::Type type, bool is_div) |
| 90 | : cpu_reg_(CpuRegister(reg)), type_(type), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 91 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 92 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 93 | __ Bind(GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 94 | if (type_ == Primitive::kPrimInt) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 95 | if (is_div_) { |
| 96 | __ negl(cpu_reg_); |
| 97 | } else { |
| 98 | __ movl(cpu_reg_, Immediate(0)); |
| 99 | } |
| 100 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 101 | } else { |
| 102 | DCHECK_EQ(Primitive::kPrimLong, type_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 103 | if (is_div_) { |
| 104 | __ negq(cpu_reg_); |
| 105 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 106 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 107 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 108 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 109 | __ jmp(GetExitLabel()); |
| 110 | } |
| 111 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 112 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86_64"; } |
| 113 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 114 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 115 | const CpuRegister cpu_reg_; |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 116 | const Primitive::Type type_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 117 | const bool is_div_; |
| 118 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86_64); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 119 | }; |
| 120 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 121 | class SuspendCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 122 | public: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 123 | explicit SuspendCheckSlowPathX86_64(HSuspendCheck* instruction, HBasicBlock* successor) |
| 124 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 125 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 126 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 127 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 128 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 129 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 130 | __ gs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pTestSuspend), true)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 131 | RecordPcInfo(codegen, instruction_, instruction_->GetDexPc()); |
| 132 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 133 | if (successor_ == nullptr) { |
| 134 | __ jmp(GetReturnLabel()); |
| 135 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 136 | __ jmp(x64_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 137 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 138 | } |
| 139 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 140 | Label* GetReturnLabel() { |
| 141 | DCHECK(successor_ == nullptr); |
| 142 | return &return_label_; |
| 143 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 144 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 145 | HBasicBlock* GetSuccessor() const { |
| 146 | return successor_; |
| 147 | } |
| 148 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 149 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86_64"; } |
| 150 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 151 | private: |
| 152 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 153 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 154 | Label return_label_; |
| 155 | |
| 156 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64); |
| 157 | }; |
| 158 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 159 | class BoundsCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 160 | public: |
Roland Levillain | 5799fc0 | 2014-09-25 12:15:20 +0100 | [diff] [blame] | 161 | BoundsCheckSlowPathX86_64(HBoundsCheck* instruction, |
| 162 | Location index_location, |
| 163 | Location length_location) |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 164 | : instruction_(instruction), |
| 165 | index_location_(index_location), |
| 166 | length_location_(length_location) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 167 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 168 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 169 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 170 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 171 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 172 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 173 | codegen->EmitParallelMoves( |
| 174 | index_location_, |
| 175 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 176 | Primitive::kPrimInt, |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 177 | length_location_, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 178 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 179 | Primitive::kPrimInt); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 180 | __ gs()->call(Address::Absolute( |
| 181 | QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pThrowArrayBounds), true)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 182 | RecordPcInfo(codegen, instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 183 | } |
| 184 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 185 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86_64"; } |
| 186 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 187 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 188 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 189 | const Location index_location_; |
| 190 | const Location length_location_; |
| 191 | |
| 192 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 193 | }; |
| 194 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 195 | class LoadClassSlowPathX86_64 : public SlowPathCodeX86_64 { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 196 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 197 | LoadClassSlowPathX86_64(HLoadClass* cls, |
| 198 | HInstruction* at, |
| 199 | uint32_t dex_pc, |
| 200 | bool do_clinit) |
| 201 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 202 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 203 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 204 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 205 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 206 | LocationSummary* locations = at_->GetLocations(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 207 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 208 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 209 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 210 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 211 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 212 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 213 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(cls_->GetTypeIndex())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 214 | __ gs()->call(Address::Absolute((do_clinit_ |
| 215 | ? QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pInitializeStaticStorage) |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 216 | : QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pInitializeType)), true)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 217 | RecordPcInfo(codegen, at_, dex_pc_); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 218 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 219 | Location out = locations->Out(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 220 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 221 | if (out.IsValid()) { |
| 222 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 223 | x64_codegen->Move(out, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 226 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 227 | __ jmp(GetExitLabel()); |
| 228 | } |
| 229 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 230 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86_64"; } |
| 231 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 232 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 233 | // The class this slow path will load. |
| 234 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 235 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 236 | // The instruction where this slow path is happening. |
| 237 | // (Might be the load class or an initialization check). |
| 238 | HInstruction* const at_; |
| 239 | |
| 240 | // The dex PC of `at_`. |
| 241 | const uint32_t dex_pc_; |
| 242 | |
| 243 | // Whether to initialize the class. |
| 244 | const bool do_clinit_; |
| 245 | |
| 246 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86_64); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 247 | }; |
| 248 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 249 | class LoadStringSlowPathX86_64 : public SlowPathCodeX86_64 { |
| 250 | public: |
| 251 | explicit LoadStringSlowPathX86_64(HLoadString* instruction) : instruction_(instruction) {} |
| 252 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 253 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 254 | LocationSummary* locations = instruction_->GetLocations(); |
| 255 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 256 | |
| 257 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 258 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 259 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 260 | |
| 261 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 262 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 263 | Immediate(instruction_->GetStringIndex())); |
| 264 | __ gs()->call(Address::Absolute( |
| 265 | QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pResolveString), true)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 266 | RecordPcInfo(codegen, instruction_, instruction_->GetDexPc()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 267 | x64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 268 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 269 | __ jmp(GetExitLabel()); |
| 270 | } |
| 271 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 272 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86_64"; } |
| 273 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 274 | private: |
| 275 | HLoadString* const instruction_; |
| 276 | |
| 277 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86_64); |
| 278 | }; |
| 279 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 280 | class TypeCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
| 281 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 282 | TypeCheckSlowPathX86_64(HInstruction* instruction, |
| 283 | Location class_to_check, |
| 284 | Location object_class, |
| 285 | uint32_t dex_pc) |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 286 | : instruction_(instruction), |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 287 | class_to_check_(class_to_check), |
| 288 | object_class_(object_class), |
| 289 | dex_pc_(dex_pc) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 290 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 291 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 292 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 293 | DCHECK(instruction_->IsCheckCast() |
| 294 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 295 | |
| 296 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 297 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 298 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 299 | |
| 300 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 301 | // move resolver. |
| 302 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 303 | codegen->EmitParallelMoves( |
| 304 | class_to_check_, |
| 305 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 306 | Primitive::kPrimNot, |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 307 | object_class_, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 308 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 309 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 310 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 311 | if (instruction_->IsInstanceOf()) { |
| 312 | __ gs()->call( |
| 313 | Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pInstanceofNonTrivial), true)); |
| 314 | } else { |
| 315 | DCHECK(instruction_->IsCheckCast()); |
| 316 | __ gs()->call( |
| 317 | Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pCheckCast), true)); |
| 318 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 319 | RecordPcInfo(codegen, instruction_, dex_pc_); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 320 | |
| 321 | if (instruction_->IsInstanceOf()) { |
| 322 | x64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
| 323 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 324 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 325 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 326 | __ jmp(GetExitLabel()); |
| 327 | } |
| 328 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 329 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86_64"; } |
| 330 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 331 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 332 | HInstruction* const instruction_; |
| 333 | const Location class_to_check_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 334 | const Location object_class_; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 335 | const uint32_t dex_pc_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 336 | |
| 337 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86_64); |
| 338 | }; |
| 339 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 340 | class DeoptimizationSlowPathX86_64 : public SlowPathCodeX86_64 { |
| 341 | public: |
| 342 | explicit DeoptimizationSlowPathX86_64(HInstruction* instruction) |
| 343 | : instruction_(instruction) {} |
| 344 | |
| 345 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 346 | __ Bind(GetEntryLabel()); |
| 347 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 348 | __ gs()->call( |
| 349 | Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pDeoptimize), true)); |
| 350 | DCHECK(instruction_->IsDeoptimize()); |
| 351 | HDeoptimize* deoptimize = instruction_->AsDeoptimize(); |
| 352 | uint32_t dex_pc = deoptimize->GetDexPc(); |
| 353 | codegen->RecordPcInfo(instruction_, dex_pc, this); |
| 354 | } |
| 355 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 356 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86_64"; } |
| 357 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 358 | private: |
| 359 | HInstruction* const instruction_; |
| 360 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86_64); |
| 361 | }; |
| 362 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 363 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 364 | #define __ down_cast<X86_64Assembler*>(GetAssembler())-> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 365 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 366 | inline Condition X86_64IntegerCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 367 | switch (cond) { |
| 368 | case kCondEQ: return kEqual; |
| 369 | case kCondNE: return kNotEqual; |
| 370 | case kCondLT: return kLess; |
| 371 | case kCondLE: return kLessEqual; |
| 372 | case kCondGT: return kGreater; |
| 373 | case kCondGE: return kGreaterEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 374 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 375 | LOG(FATAL) << "Unreachable"; |
| 376 | UNREACHABLE(); |
| 377 | } |
| 378 | |
| 379 | inline Condition X86_64FPCondition(IfCondition cond) { |
| 380 | switch (cond) { |
| 381 | case kCondEQ: return kEqual; |
| 382 | case kCondNE: return kNotEqual; |
| 383 | case kCondLT: return kBelow; |
| 384 | case kCondLE: return kBelowEqual; |
| 385 | case kCondGT: return kAbove; |
| 386 | case kCondGE: return kAboveEqual; |
| 387 | }; |
| 388 | LOG(FATAL) << "Unreachable"; |
| 389 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 392 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 393 | Location temp) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 394 | // All registers are assumed to be correctly set up. |
| 395 | |
| 396 | // TODO: Implement all kinds of calls: |
| 397 | // 1) boot -> boot |
| 398 | // 2) app -> boot |
| 399 | // 3) app -> app |
| 400 | // |
| 401 | // Currently we implement the app -> app logic, which looks up in the resolve cache. |
| 402 | |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 403 | if (invoke->IsStringInit()) { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 404 | CpuRegister reg = temp.AsRegister<CpuRegister>(); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 405 | // temp = thread->string_init_entrypoint |
Jeff Hao | cad6542 | 2015-06-18 21:16:08 -0700 | [diff] [blame] | 406 | __ gs()->movq(reg, Address::Absolute(invoke->GetStringInitOffset(), true)); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 407 | // (temp + offset_of_quick_compiled_code)() |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 408 | __ call(Address(reg, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 409 | kX86_64WordSize).SizeValue())); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 410 | } else if (invoke->IsRecursive()) { |
| 411 | __ call(&frame_entry_label_); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 412 | } else { |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 413 | CpuRegister reg = temp.AsRegister<CpuRegister>(); |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 414 | Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 415 | Register method_reg; |
| 416 | if (current_method.IsRegister()) { |
| 417 | method_reg = current_method.AsRegister<Register>(); |
| 418 | } else { |
| 419 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 420 | DCHECK(!current_method.IsValid()); |
| 421 | method_reg = reg.AsRegister(); |
| 422 | __ movq(reg, Address(CpuRegister(RSP), kCurrentMethodStackOffset)); |
| 423 | } |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 424 | // temp = temp->dex_cache_resolved_methods_; |
Nicolas Geoffray | ae71a05 | 2015-06-09 14:12:28 +0100 | [diff] [blame] | 425 | __ movl(reg, Address(CpuRegister(method_reg), |
| 426 | ArtMethod::DexCacheResolvedMethodsOffset().SizeValue())); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 427 | // temp = temp[index_in_cache] |
| 428 | __ movq(reg, Address( |
| 429 | reg, CodeGenerator::GetCachePointerOffset(invoke->GetDexMethodIndex()))); |
| 430 | // (temp + offset_of_quick_compiled_code)() |
| 431 | __ call(Address(reg, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 432 | kX86_64WordSize).SizeValue())); |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 433 | } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 434 | |
| 435 | DCHECK(!IsLeafMethod()); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 436 | } |
| 437 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 438 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 439 | stream << Register(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 443 | stream << FloatRegister(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 444 | } |
| 445 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 446 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 447 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 448 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 449 | } |
| 450 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 451 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 452 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 453 | return kX86_64WordSize; |
| 454 | } |
| 455 | |
| 456 | size_t CodeGeneratorX86_64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 457 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 458 | return kX86_64WordSize; |
| 459 | } |
| 460 | |
| 461 | size_t CodeGeneratorX86_64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 462 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 463 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 464 | } |
| 465 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 466 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 467 | // Use a fake return address register to mimic Quick. |
| 468 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 469 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
| 470 | const X86_64InstructionSetFeatures& isa_features, |
| 471 | const CompilerOptions& compiler_options) |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 472 | : CodeGenerator(graph, |
| 473 | kNumberOfCpuRegisters, |
| 474 | kNumberOfFloatRegisters, |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 475 | kNumberOfCpuRegisterPairs, |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 476 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 477 | arraysize(kCoreCalleeSaves)) |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 478 | | (1 << kFakeReturnRegister), |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 479 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 480 | arraysize(kFpuCalleeSaves)), |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 481 | compiler_options), |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 482 | block_labels_(graph->GetArena(), 0), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 483 | location_builder_(graph, this), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 484 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 485 | move_resolver_(graph->GetArena(), this), |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 486 | isa_features_(isa_features), |
| 487 | constant_area_start_(0) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 488 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 489 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 490 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 491 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 492 | CodeGeneratorX86_64* codegen) |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 493 | : HGraphVisitor(graph), |
| 494 | assembler_(codegen->GetAssembler()), |
| 495 | codegen_(codegen) {} |
| 496 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 497 | Location CodeGeneratorX86_64::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 498 | switch (type) { |
| 499 | case Primitive::kPrimLong: |
| 500 | case Primitive::kPrimByte: |
| 501 | case Primitive::kPrimBoolean: |
| 502 | case Primitive::kPrimChar: |
| 503 | case Primitive::kPrimShort: |
| 504 | case Primitive::kPrimInt: |
| 505 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 506 | size_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfCpuRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 507 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 511 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 512 | size_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfFloatRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 513 | return Location::FpuRegisterLocation(reg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 514 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 515 | |
| 516 | case Primitive::kPrimVoid: |
| 517 | LOG(FATAL) << "Unreachable type " << type; |
| 518 | } |
| 519 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 520 | return Location(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 521 | } |
| 522 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 523 | void CodeGeneratorX86_64::SetupBlockedRegisters(bool is_baseline) const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 524 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 525 | blocked_core_registers_[RSP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 526 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 527 | // Block the register used as TMP. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 528 | blocked_core_registers_[TMP] = true; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 529 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 530 | if (is_baseline) { |
| 531 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 532 | blocked_core_registers_[kCoreCalleeSaves[i]] = true; |
| 533 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 534 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 535 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 536 | } |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 537 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 538 | } |
| 539 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 540 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 541 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 542 | } |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 543 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 544 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 545 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 546 | } |
| 547 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 548 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 549 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 550 | __ Bind(&frame_entry_label_); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 551 | bool skip_overflow_check = IsLeafMethod() |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 552 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 553 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 554 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 555 | if (!skip_overflow_check) { |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 556 | __ testq(CpuRegister(RAX), Address( |
| 557 | CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 558 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 559 | } |
Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 560 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 561 | if (HasEmptyFrame()) { |
| 562 | return; |
| 563 | } |
| 564 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 565 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 566 | Register reg = kCoreCalleeSaves[i]; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 567 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 568 | __ pushq(CpuRegister(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 569 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 570 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 571 | } |
| 572 | } |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 573 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 574 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 575 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 576 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 577 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 578 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 579 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 580 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 581 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 582 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 583 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 584 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 585 | } |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 586 | } |
| 587 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 588 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 589 | CpuRegister(kMethodRegisterArgument)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | void CodeGeneratorX86_64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 593 | __ cfi().RememberState(); |
| 594 | if (!HasEmptyFrame()) { |
| 595 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 596 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| 597 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 598 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 599 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 600 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 601 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 606 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 607 | __ cfi().AdjustCFAOffset(-adjust); |
| 608 | |
| 609 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 610 | Register reg = kCoreCalleeSaves[i]; |
| 611 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 612 | __ popq(CpuRegister(reg)); |
| 613 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 614 | __ cfi().Restore(DWARFReg(reg)); |
| 615 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 616 | } |
| 617 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 618 | __ ret(); |
| 619 | __ cfi().RestoreState(); |
| 620 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 621 | } |
| 622 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 623 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 624 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 625 | } |
| 626 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 627 | Location CodeGeneratorX86_64::GetStackLocation(HLoadLocal* load) const { |
| 628 | switch (load->GetType()) { |
| 629 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 630 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 631 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 632 | |
| 633 | case Primitive::kPrimInt: |
| 634 | case Primitive::kPrimNot: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 635 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 636 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 637 | |
| 638 | case Primitive::kPrimBoolean: |
| 639 | case Primitive::kPrimByte: |
| 640 | case Primitive::kPrimChar: |
| 641 | case Primitive::kPrimShort: |
| 642 | case Primitive::kPrimVoid: |
| 643 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 644 | UNREACHABLE(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 648 | UNREACHABLE(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 652 | if (source.Equals(destination)) { |
| 653 | return; |
| 654 | } |
| 655 | if (destination.IsRegister()) { |
| 656 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 657 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 658 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 659 | __ movd(destination.AsRegister<CpuRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 660 | } else if (source.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 661 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 662 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 663 | } else { |
| 664 | DCHECK(source.IsDoubleStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 665 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 666 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 667 | } |
| 668 | } else if (destination.IsFpuRegister()) { |
| 669 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 670 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 671 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 672 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 673 | } else if (source.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 674 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 675 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 676 | } else { |
| 677 | DCHECK(source.IsDoubleStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 678 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 679 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 680 | } |
| 681 | } else if (destination.IsStackSlot()) { |
| 682 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 683 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 684 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 685 | } else if (source.IsFpuRegister()) { |
| 686 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 687 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 688 | } else if (source.IsConstant()) { |
| 689 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 690 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 691 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 692 | } else { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 693 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 694 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 695 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 696 | } |
| 697 | } else { |
| 698 | DCHECK(destination.IsDoubleStackSlot()); |
| 699 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 700 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 701 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 702 | } else if (source.IsFpuRegister()) { |
| 703 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 704 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 705 | } else if (source.IsConstant()) { |
| 706 | HConstant* constant = source.GetConstant(); |
Zheng Xu | 12bca97 | 2015-03-30 19:35:50 +0800 | [diff] [blame] | 707 | int64_t value; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 708 | if (constant->IsDoubleConstant()) { |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 709 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 710 | } else { |
| 711 | DCHECK(constant->IsLongConstant()); |
| 712 | value = constant->AsLongConstant()->GetValue(); |
| 713 | } |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 714 | Load64BitValue(CpuRegister(TMP), value); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 715 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 716 | } else { |
| 717 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 718 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 719 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 720 | } |
| 721 | } |
| 722 | } |
| 723 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 724 | void CodeGeneratorX86_64::Move(HInstruction* instruction, |
| 725 | Location location, |
| 726 | HInstruction* move_for) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 727 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 728 | if (instruction->IsCurrentMethod()) { |
Mathieu Chartier | e3b034a | 2015-05-31 14:29:23 -0700 | [diff] [blame] | 729 | Move(location, Location::DoubleStackSlot(kCurrentMethodStackOffset)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 730 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 731 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 732 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 733 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 734 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 735 | Immediate imm(GetInt32ValueOf(const_to_move)); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 736 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 737 | __ movl(location.AsRegister<CpuRegister>(), imm); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 738 | } else if (location.IsStackSlot()) { |
| 739 | __ movl(Address(CpuRegister(RSP), location.GetStackIndex()), imm); |
| 740 | } else { |
| 741 | DCHECK(location.IsConstant()); |
| 742 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 743 | } |
| 744 | } else if (const_to_move->IsLongConstant()) { |
| 745 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 746 | if (location.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 747 | Load64BitValue(location.AsRegister<CpuRegister>(), value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 748 | } else if (location.IsDoubleStackSlot()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 749 | Load64BitValue(CpuRegister(TMP), value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 750 | __ movq(Address(CpuRegister(RSP), location.GetStackIndex()), CpuRegister(TMP)); |
| 751 | } else { |
| 752 | DCHECK(location.IsConstant()); |
| 753 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 754 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 755 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 756 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 757 | switch (instruction->GetType()) { |
| 758 | case Primitive::kPrimBoolean: |
| 759 | case Primitive::kPrimByte: |
| 760 | case Primitive::kPrimChar: |
| 761 | case Primitive::kPrimShort: |
| 762 | case Primitive::kPrimInt: |
| 763 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 764 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 765 | Move(location, Location::StackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
| 766 | break; |
| 767 | |
| 768 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 769 | case Primitive::kPrimDouble: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 770 | Move(location, |
| 771 | Location::DoubleStackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 772 | break; |
| 773 | |
| 774 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 775 | LOG(FATAL) << "Unexpected local type " << instruction->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 776 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 777 | } else if (instruction->IsTemporary()) { |
| 778 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
| 779 | Move(location, temp_location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 780 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 781 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 782 | switch (instruction->GetType()) { |
| 783 | case Primitive::kPrimBoolean: |
| 784 | case Primitive::kPrimByte: |
| 785 | case Primitive::kPrimChar: |
| 786 | case Primitive::kPrimShort: |
| 787 | case Primitive::kPrimInt: |
| 788 | case Primitive::kPrimNot: |
| 789 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 790 | case Primitive::kPrimFloat: |
| 791 | case Primitive::kPrimDouble: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 792 | Move(location, locations->Out()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 793 | break; |
| 794 | |
| 795 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 796 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 797 | } |
| 798 | } |
| 799 | } |
| 800 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 801 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 802 | DCHECK(!successor->IsExitBlock()); |
| 803 | |
| 804 | HBasicBlock* block = got->GetBlock(); |
| 805 | HInstruction* previous = got->GetPrevious(); |
| 806 | |
| 807 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 808 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 809 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 810 | return; |
| 811 | } |
| 812 | |
| 813 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 814 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 815 | } |
| 816 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 817 | __ jmp(codegen_->GetLabelOf(successor)); |
| 818 | } |
| 819 | } |
| 820 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 821 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 822 | got->SetLocations(nullptr); |
| 823 | } |
| 824 | |
| 825 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 826 | HandleGoto(got, got->GetSuccessor()); |
| 827 | } |
| 828 | |
| 829 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 830 | try_boundary->SetLocations(nullptr); |
| 831 | } |
| 832 | |
| 833 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 834 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 835 | if (!successor->IsExitBlock()) { |
| 836 | HandleGoto(try_boundary, successor); |
| 837 | } |
| 838 | } |
| 839 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 840 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 841 | exit->SetLocations(nullptr); |
| 842 | } |
| 843 | |
| 844 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 845 | UNUSED(exit); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 846 | } |
| 847 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 848 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
| 849 | Label* true_label, |
| 850 | Label* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 851 | if (cond->IsFPConditionTrueIfNaN()) { |
| 852 | __ j(kUnordered, true_label); |
| 853 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 854 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 855 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 856 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HIf* if_instr, |
| 860 | HCondition* condition, |
| 861 | Label* true_target, |
| 862 | Label* false_target, |
| 863 | Label* always_true_target) { |
| 864 | LocationSummary* locations = condition->GetLocations(); |
| 865 | Location left = locations->InAt(0); |
| 866 | Location right = locations->InAt(1); |
| 867 | |
| 868 | // We don't want true_target as a nullptr. |
| 869 | if (true_target == nullptr) { |
| 870 | true_target = always_true_target; |
| 871 | } |
| 872 | bool falls_through = (false_target == nullptr); |
| 873 | |
| 874 | // FP compares don't like null false_targets. |
| 875 | if (false_target == nullptr) { |
| 876 | false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 877 | } |
| 878 | |
| 879 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 880 | switch (type) { |
| 881 | case Primitive::kPrimLong: { |
| 882 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 883 | if (right.IsConstant()) { |
| 884 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 885 | if (IsInt<32>(value)) { |
| 886 | if (value == 0) { |
| 887 | __ testq(left_reg, left_reg); |
| 888 | } else { |
| 889 | __ cmpq(left_reg, Immediate(static_cast<int32_t>(value))); |
| 890 | } |
| 891 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 892 | // Value won't fit in a 32-bit integer. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 893 | __ cmpq(left_reg, codegen_->LiteralInt64Address(value)); |
| 894 | } |
| 895 | } else if (right.IsDoubleStackSlot()) { |
| 896 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 897 | } else { |
| 898 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 899 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 900 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 901 | break; |
| 902 | } |
| 903 | case Primitive::kPrimFloat: { |
| 904 | if (right.IsFpuRegister()) { |
| 905 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 906 | } else if (right.IsConstant()) { |
| 907 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 908 | codegen_->LiteralFloatAddress( |
| 909 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 910 | } else { |
| 911 | DCHECK(right.IsStackSlot()); |
| 912 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 913 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 914 | } |
| 915 | GenerateFPJumps(condition, true_target, false_target); |
| 916 | break; |
| 917 | } |
| 918 | case Primitive::kPrimDouble: { |
| 919 | if (right.IsFpuRegister()) { |
| 920 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 921 | } else if (right.IsConstant()) { |
| 922 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 923 | codegen_->LiteralDoubleAddress( |
| 924 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 925 | } else { |
| 926 | DCHECK(right.IsDoubleStackSlot()); |
| 927 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 928 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 929 | } |
| 930 | GenerateFPJumps(condition, true_target, false_target); |
| 931 | break; |
| 932 | } |
| 933 | default: |
| 934 | LOG(FATAL) << "Unexpected condition type " << type; |
| 935 | } |
| 936 | |
| 937 | if (!falls_through) { |
| 938 | __ jmp(false_target); |
| 939 | } |
| 940 | } |
| 941 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 942 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
| 943 | Label* true_target, |
| 944 | Label* false_target, |
| 945 | Label* always_true_target) { |
| 946 | HInstruction* cond = instruction->InputAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 947 | if (cond->IsIntConstant()) { |
| 948 | // Constant condition, statically compared against 1. |
| 949 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 950 | if (cond_value == 1) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 951 | if (always_true_target != nullptr) { |
| 952 | __ jmp(always_true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 953 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 954 | return; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 955 | } else { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 956 | DCHECK_EQ(cond_value, 0); |
| 957 | } |
| 958 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 959 | bool is_materialized = |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 960 | !cond->IsCondition() || cond->AsCondition()->NeedsMaterialization(); |
| 961 | // Moves do not affect the eflags register, so if the condition is |
| 962 | // evaluated just before the if, we don't need to evaluate it |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 963 | // again. We can't use the eflags on FP conditions if they are |
| 964 | // materialized due to the complex branching. |
| 965 | Primitive::Type type = cond->IsCondition() ? cond->InputAt(0)->GetType() : Primitive::kPrimInt; |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 966 | bool eflags_set = cond->IsCondition() |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 967 | && cond->AsCondition()->IsBeforeWhenDisregardMoves(instruction) |
| 968 | && !Primitive::IsFloatingPointType(type); |
| 969 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 970 | if (is_materialized) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 971 | if (!eflags_set) { |
| 972 | // Materialized condition, compare against 0. |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 973 | Location lhs = instruction->GetLocations()->InAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 974 | if (lhs.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 975 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 976 | } else { |
| 977 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), |
| 978 | Immediate(0)); |
| 979 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 980 | __ j(kNotEqual, true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 981 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 982 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 983 | } |
| 984 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 985 | // Condition has not been materialized, use its inputs as the |
| 986 | // comparison and its condition as the branch condition. |
| 987 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 988 | // Is this a long or FP comparison that has been folded into the HCondition? |
| 989 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 990 | // Generate the comparison directly. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 991 | GenerateCompareTestAndBranch(instruction->AsIf(), cond->AsCondition(), |
| 992 | true_target, false_target, always_true_target); |
| 993 | return; |
| 994 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 995 | |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 996 | Location lhs = cond->GetLocations()->InAt(0); |
| 997 | Location rhs = cond->GetLocations()->InAt(1); |
| 998 | if (rhs.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 999 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1000 | } else if (rhs.IsConstant()) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1001 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 1002 | if (constant == 0) { |
| 1003 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1004 | } else { |
| 1005 | __ cmpl(lhs.AsRegister<CpuRegister>(), Immediate(constant)); |
| 1006 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1007 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1008 | __ cmpl(lhs.AsRegister<CpuRegister>(), |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1009 | Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1010 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1011 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1012 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1013 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1014 | if (false_target != nullptr) { |
| 1015 | __ jmp(false_target); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1016 | } |
| 1017 | } |
| 1018 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1019 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
| 1020 | LocationSummary* locations = |
| 1021 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
| 1022 | HInstruction* cond = if_instr->InputAt(0); |
| 1023 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 1024 | locations->SetInAt(0, Location::Any()); |
| 1025 | } |
| 1026 | } |
| 1027 | |
| 1028 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
| 1029 | Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor()); |
| 1030 | Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1031 | Label* always_true_target = true_target; |
| 1032 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1033 | if_instr->IfTrueSuccessor())) { |
| 1034 | always_true_target = nullptr; |
| 1035 | } |
| 1036 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1037 | if_instr->IfFalseSuccessor())) { |
| 1038 | false_target = nullptr; |
| 1039 | } |
| 1040 | GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target); |
| 1041 | } |
| 1042 | |
| 1043 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1044 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1045 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| 1046 | HInstruction* cond = deoptimize->InputAt(0); |
| 1047 | DCHECK(cond->IsCondition()); |
| 1048 | if (cond->AsCondition()->NeedsMaterialization()) { |
| 1049 | locations->SetInAt(0, Location::Any()); |
| 1050 | } |
| 1051 | } |
| 1052 | |
| 1053 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1054 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) |
| 1055 | DeoptimizationSlowPathX86_64(deoptimize); |
| 1056 | codegen_->AddSlowPath(slow_path); |
| 1057 | Label* slow_path_entry = slow_path->GetEntryLabel(); |
| 1058 | GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry); |
| 1059 | } |
| 1060 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1061 | void LocationsBuilderX86_64::VisitLocal(HLocal* local) { |
| 1062 | local->SetLocations(nullptr); |
| 1063 | } |
| 1064 | |
| 1065 | void InstructionCodeGeneratorX86_64::VisitLocal(HLocal* local) { |
| 1066 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
| 1067 | } |
| 1068 | |
| 1069 | void LocationsBuilderX86_64::VisitLoadLocal(HLoadLocal* local) { |
| 1070 | local->SetLocations(nullptr); |
| 1071 | } |
| 1072 | |
| 1073 | void InstructionCodeGeneratorX86_64::VisitLoadLocal(HLoadLocal* load) { |
| 1074 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1075 | UNUSED(load); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | void LocationsBuilderX86_64::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1079 | LocationSummary* locations = |
| 1080 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1081 | switch (store->InputAt(1)->GetType()) { |
| 1082 | case Primitive::kPrimBoolean: |
| 1083 | case Primitive::kPrimByte: |
| 1084 | case Primitive::kPrimChar: |
| 1085 | case Primitive::kPrimShort: |
| 1086 | case Primitive::kPrimInt: |
| 1087 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1088 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1089 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1090 | break; |
| 1091 | |
| 1092 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1093 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1094 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1095 | break; |
| 1096 | |
| 1097 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1098 | LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1099 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | void InstructionCodeGeneratorX86_64::VisitStoreLocal(HStoreLocal* store) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1103 | UNUSED(store); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1104 | } |
| 1105 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1106 | void LocationsBuilderX86_64::VisitCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1107 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1108 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1109 | // Handle the long/FP comparisons made in instruction simplification. |
| 1110 | switch (cond->InputAt(0)->GetType()) { |
| 1111 | case Primitive::kPrimLong: |
| 1112 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1113 | locations->SetInAt(1, Location::Any()); |
| 1114 | break; |
| 1115 | case Primitive::kPrimFloat: |
| 1116 | case Primitive::kPrimDouble: |
| 1117 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1118 | locations->SetInAt(1, Location::Any()); |
| 1119 | break; |
| 1120 | default: |
| 1121 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1122 | locations->SetInAt(1, Location::Any()); |
| 1123 | break; |
| 1124 | } |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1125 | if (cond->NeedsMaterialization()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1126 | locations->SetOut(Location::RequiresRegister()); |
| 1127 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1128 | } |
| 1129 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1130 | void InstructionCodeGeneratorX86_64::VisitCondition(HCondition* cond) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1131 | if (!cond->NeedsMaterialization()) { |
| 1132 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1133 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1134 | |
| 1135 | LocationSummary* locations = cond->GetLocations(); |
| 1136 | Location lhs = locations->InAt(0); |
| 1137 | Location rhs = locations->InAt(1); |
| 1138 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
| 1139 | Label true_label, false_label; |
| 1140 | |
| 1141 | switch (cond->InputAt(0)->GetType()) { |
| 1142 | default: |
| 1143 | // Integer case. |
| 1144 | |
| 1145 | // Clear output register: setcc only sets the low byte. |
| 1146 | __ xorl(reg, reg); |
| 1147 | |
| 1148 | if (rhs.IsRegister()) { |
| 1149 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1150 | } else if (rhs.IsConstant()) { |
| 1151 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1152 | if (constant == 0) { |
| 1153 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1154 | } else { |
| 1155 | __ cmpl(lhs.AsRegister<CpuRegister>(), Immediate(constant)); |
| 1156 | } |
| 1157 | } else { |
| 1158 | __ cmpl(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1159 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1160 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1161 | return; |
| 1162 | case Primitive::kPrimLong: |
| 1163 | // Clear output register: setcc only sets the low byte. |
| 1164 | __ xorl(reg, reg); |
| 1165 | |
| 1166 | if (rhs.IsRegister()) { |
| 1167 | __ cmpq(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1168 | } else if (rhs.IsConstant()) { |
| 1169 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
| 1170 | if (IsInt<32>(value)) { |
| 1171 | if (value == 0) { |
| 1172 | __ testq(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1173 | } else { |
| 1174 | __ cmpq(lhs.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 1175 | } |
| 1176 | } else { |
| 1177 | // Value won't fit in an int. |
| 1178 | __ cmpq(lhs.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 1179 | } |
| 1180 | } else { |
| 1181 | __ cmpq(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1182 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1183 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1184 | return; |
| 1185 | case Primitive::kPrimFloat: { |
| 1186 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1187 | if (rhs.IsConstant()) { |
| 1188 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 1189 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 1190 | } else if (rhs.IsStackSlot()) { |
| 1191 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1192 | } else { |
| 1193 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1194 | } |
| 1195 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1196 | break; |
| 1197 | } |
| 1198 | case Primitive::kPrimDouble: { |
| 1199 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1200 | if (rhs.IsConstant()) { |
| 1201 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1202 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 1203 | } else if (rhs.IsDoubleStackSlot()) { |
| 1204 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1205 | } else { |
| 1206 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1207 | } |
| 1208 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1209 | break; |
| 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | // Convert the jumps into the result. |
| 1214 | Label done_label; |
| 1215 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1216 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1217 | __ Bind(&false_label); |
| 1218 | __ xorl(reg, reg); |
| 1219 | __ jmp(&done_label); |
| 1220 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1221 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1222 | __ Bind(&true_label); |
| 1223 | __ movl(reg, Immediate(1)); |
| 1224 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1225 | } |
| 1226 | |
| 1227 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
| 1228 | VisitCondition(comp); |
| 1229 | } |
| 1230 | |
| 1231 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
| 1232 | VisitCondition(comp); |
| 1233 | } |
| 1234 | |
| 1235 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
| 1236 | VisitCondition(comp); |
| 1237 | } |
| 1238 | |
| 1239 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
| 1240 | VisitCondition(comp); |
| 1241 | } |
| 1242 | |
| 1243 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
| 1244 | VisitCondition(comp); |
| 1245 | } |
| 1246 | |
| 1247 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
| 1248 | VisitCondition(comp); |
| 1249 | } |
| 1250 | |
| 1251 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1252 | VisitCondition(comp); |
| 1253 | } |
| 1254 | |
| 1255 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1256 | VisitCondition(comp); |
| 1257 | } |
| 1258 | |
| 1259 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| 1260 | VisitCondition(comp); |
| 1261 | } |
| 1262 | |
| 1263 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| 1264 | VisitCondition(comp); |
| 1265 | } |
| 1266 | |
| 1267 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1268 | VisitCondition(comp); |
| 1269 | } |
| 1270 | |
| 1271 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1272 | VisitCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1273 | } |
| 1274 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1275 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1276 | LocationSummary* locations = |
| 1277 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1278 | switch (compare->InputAt(0)->GetType()) { |
| 1279 | case Primitive::kPrimLong: { |
| 1280 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1281 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1282 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1283 | break; |
| 1284 | } |
| 1285 | case Primitive::kPrimFloat: |
| 1286 | case Primitive::kPrimDouble: { |
| 1287 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1288 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1289 | locations->SetOut(Location::RequiresRegister()); |
| 1290 | break; |
| 1291 | } |
| 1292 | default: |
| 1293 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 1294 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1295 | } |
| 1296 | |
| 1297 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1298 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1299 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1300 | Location left = locations->InAt(0); |
| 1301 | Location right = locations->InAt(1); |
| 1302 | |
| 1303 | Label less, greater, done; |
| 1304 | Primitive::Type type = compare->InputAt(0)->GetType(); |
| 1305 | switch (type) { |
| 1306 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1307 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1308 | if (right.IsConstant()) { |
| 1309 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1310 | if (IsInt<32>(value)) { |
| 1311 | if (value == 0) { |
| 1312 | __ testq(left_reg, left_reg); |
| 1313 | } else { |
| 1314 | __ cmpq(left_reg, Immediate(static_cast<int32_t>(value))); |
| 1315 | } |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1316 | } else { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1317 | // Value won't fit in an int. |
| 1318 | __ cmpq(left_reg, codegen_->LiteralInt64Address(value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1319 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1320 | } else if (right.IsDoubleStackSlot()) { |
| 1321 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1322 | } else { |
| 1323 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1324 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1325 | break; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1326 | } |
| 1327 | case Primitive::kPrimFloat: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1328 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1329 | if (right.IsConstant()) { |
| 1330 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 1331 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 1332 | } else if (right.IsStackSlot()) { |
| 1333 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1334 | } else { |
| 1335 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1336 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1337 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 1338 | break; |
| 1339 | } |
| 1340 | case Primitive::kPrimDouble: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1341 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1342 | if (right.IsConstant()) { |
| 1343 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1344 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 1345 | } else if (right.IsDoubleStackSlot()) { |
| 1346 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1347 | } else { |
| 1348 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1349 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1350 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 1351 | break; |
| 1352 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1353 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1354 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1355 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1356 | __ movl(out, Immediate(0)); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1357 | __ j(kEqual, &done); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1358 | __ 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] | 1359 | |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1360 | __ Bind(&greater); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1361 | __ movl(out, Immediate(1)); |
| 1362 | __ jmp(&done); |
| 1363 | |
| 1364 | __ Bind(&less); |
| 1365 | __ movl(out, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1366 | |
| 1367 | __ Bind(&done); |
| 1368 | } |
| 1369 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1370 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1371 | LocationSummary* locations = |
| 1372 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1373 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1377 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1378 | UNUSED(constant); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1379 | } |
| 1380 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1381 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 1382 | LocationSummary* locations = |
| 1383 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1384 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1385 | } |
| 1386 | |
| 1387 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant) { |
| 1388 | // Will be generated at use site. |
| 1389 | UNUSED(constant); |
| 1390 | } |
| 1391 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1392 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1393 | LocationSummary* locations = |
| 1394 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1395 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1396 | } |
| 1397 | |
| 1398 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1399 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1400 | UNUSED(constant); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1401 | } |
| 1402 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1403 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 1404 | LocationSummary* locations = |
| 1405 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1406 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1407 | } |
| 1408 | |
| 1409 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 1410 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1411 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1412 | } |
| 1413 | |
| 1414 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1415 | LocationSummary* locations = |
| 1416 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1417 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1418 | } |
| 1419 | |
| 1420 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1421 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1422 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1423 | } |
| 1424 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1425 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1426 | memory_barrier->SetLocations(nullptr); |
| 1427 | } |
| 1428 | |
| 1429 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1430 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 1431 | } |
| 1432 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1433 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 1434 | ret->SetLocations(nullptr); |
| 1435 | } |
| 1436 | |
| 1437 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1438 | UNUSED(ret); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1439 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1440 | } |
| 1441 | |
| 1442 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1443 | LocationSummary* locations = |
| 1444 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1445 | switch (ret->InputAt(0)->GetType()) { |
| 1446 | case Primitive::kPrimBoolean: |
| 1447 | case Primitive::kPrimByte: |
| 1448 | case Primitive::kPrimChar: |
| 1449 | case Primitive::kPrimShort: |
| 1450 | case Primitive::kPrimInt: |
| 1451 | case Primitive::kPrimNot: |
| 1452 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1453 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1454 | break; |
| 1455 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1456 | case Primitive::kPrimFloat: |
| 1457 | case Primitive::kPrimDouble: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1458 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1459 | break; |
| 1460 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1461 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1462 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1463 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 1467 | if (kIsDebugBuild) { |
| 1468 | switch (ret->InputAt(0)->GetType()) { |
| 1469 | case Primitive::kPrimBoolean: |
| 1470 | case Primitive::kPrimByte: |
| 1471 | case Primitive::kPrimChar: |
| 1472 | case Primitive::kPrimShort: |
| 1473 | case Primitive::kPrimInt: |
| 1474 | case Primitive::kPrimNot: |
| 1475 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1476 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1477 | break; |
| 1478 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1479 | case Primitive::kPrimFloat: |
| 1480 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1481 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1482 | XMM0); |
| 1483 | break; |
| 1484 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1485 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1486 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1487 | } |
| 1488 | } |
| 1489 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1490 | } |
| 1491 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1492 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(Primitive::Type type) const { |
| 1493 | switch (type) { |
| 1494 | case Primitive::kPrimBoolean: |
| 1495 | case Primitive::kPrimByte: |
| 1496 | case Primitive::kPrimChar: |
| 1497 | case Primitive::kPrimShort: |
| 1498 | case Primitive::kPrimInt: |
| 1499 | case Primitive::kPrimNot: |
| 1500 | case Primitive::kPrimLong: |
| 1501 | return Location::RegisterLocation(RAX); |
| 1502 | |
| 1503 | case Primitive::kPrimVoid: |
| 1504 | return Location::NoLocation(); |
| 1505 | |
| 1506 | case Primitive::kPrimDouble: |
| 1507 | case Primitive::kPrimFloat: |
| 1508 | return Location::FpuRegisterLocation(XMM0); |
| 1509 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1510 | |
| 1511 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 1515 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1516 | } |
| 1517 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1518 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1519 | switch (type) { |
| 1520 | case Primitive::kPrimBoolean: |
| 1521 | case Primitive::kPrimByte: |
| 1522 | case Primitive::kPrimChar: |
| 1523 | case Primitive::kPrimShort: |
| 1524 | case Primitive::kPrimInt: |
| 1525 | case Primitive::kPrimNot: { |
| 1526 | uint32_t index = gp_index_++; |
| 1527 | stack_index_++; |
| 1528 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1529 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1530 | } else { |
| 1531 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1532 | } |
| 1533 | } |
| 1534 | |
| 1535 | case Primitive::kPrimLong: { |
| 1536 | uint32_t index = gp_index_; |
| 1537 | stack_index_ += 2; |
| 1538 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 1539 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1540 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1541 | } else { |
| 1542 | gp_index_ += 2; |
| 1543 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1544 | } |
| 1545 | } |
| 1546 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1547 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1548 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1549 | stack_index_++; |
| 1550 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1551 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1552 | } else { |
| 1553 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1554 | } |
| 1555 | } |
| 1556 | |
| 1557 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1558 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1559 | stack_index_ += 2; |
| 1560 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1561 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1562 | } else { |
| 1563 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1564 | } |
| 1565 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1566 | |
| 1567 | case Primitive::kPrimVoid: |
| 1568 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1569 | break; |
| 1570 | } |
| 1571 | return Location(); |
| 1572 | } |
| 1573 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1574 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1575 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1576 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1577 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1578 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1579 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1580 | if (intrinsic.TryDispatch(invoke)) { |
| 1581 | return; |
| 1582 | } |
| 1583 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1584 | HandleInvoke(invoke); |
| 1585 | } |
| 1586 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1587 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 1588 | if (invoke->GetLocations()->Intrinsified()) { |
| 1589 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 1590 | intrinsic.Dispatch(invoke); |
| 1591 | return true; |
| 1592 | } |
| 1593 | return false; |
| 1594 | } |
| 1595 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1596 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1597 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1598 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1599 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1600 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1601 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1602 | return; |
| 1603 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1604 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1605 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1606 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1607 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 1608 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1609 | } |
| 1610 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1611 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1612 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1613 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1614 | } |
| 1615 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1616 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1617 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1618 | if (intrinsic.TryDispatch(invoke)) { |
| 1619 | return; |
| 1620 | } |
| 1621 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1622 | HandleInvoke(invoke); |
| 1623 | } |
| 1624 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1625 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1626 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1627 | return; |
| 1628 | } |
| 1629 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1630 | CpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1631 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 1632 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1633 | LocationSummary* locations = invoke->GetLocations(); |
| 1634 | Location receiver = locations->InAt(0); |
| 1635 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 1636 | // temp = object->GetClass(); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1637 | DCHECK(receiver.IsRegister()); |
| 1638 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1639 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1640 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1641 | // temp = temp->GetMethodAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1642 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1643 | // call temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1644 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1645 | kX86_64WordSize).SizeValue())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1646 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1647 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1648 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1649 | } |
| 1650 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1651 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1652 | HandleInvoke(invoke); |
| 1653 | // Add the hidden argument. |
| 1654 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 1655 | } |
| 1656 | |
| 1657 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1658 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1659 | CpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1660 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 1661 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86_64PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1662 | LocationSummary* locations = invoke->GetLocations(); |
| 1663 | Location receiver = locations->InAt(0); |
| 1664 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 1665 | |
| 1666 | // Set the hidden argument. |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 1667 | CpuRegister hidden_reg = invoke->GetLocations()->GetTemp(1).AsRegister<CpuRegister>(); |
| 1668 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1669 | |
| 1670 | // temp = object->GetClass(); |
| 1671 | if (receiver.IsStackSlot()) { |
| 1672 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
| 1673 | __ movl(temp, Address(temp, class_offset)); |
| 1674 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1675 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1676 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1677 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1678 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1679 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1680 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1681 | // call temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1682 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1683 | kX86_64WordSize).SizeValue())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1684 | |
| 1685 | DCHECK(!codegen_->IsLeafMethod()); |
| 1686 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1687 | } |
| 1688 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1689 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 1690 | LocationSummary* locations = |
| 1691 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1692 | switch (neg->GetResultType()) { |
| 1693 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1694 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1695 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1696 | locations->SetOut(Location::SameAsFirstInput()); |
| 1697 | break; |
| 1698 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1699 | case Primitive::kPrimFloat: |
| 1700 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1701 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1702 | locations->SetOut(Location::SameAsFirstInput()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1703 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1704 | break; |
| 1705 | |
| 1706 | default: |
| 1707 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1708 | } |
| 1709 | } |
| 1710 | |
| 1711 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 1712 | LocationSummary* locations = neg->GetLocations(); |
| 1713 | Location out = locations->Out(); |
| 1714 | Location in = locations->InAt(0); |
| 1715 | switch (neg->GetResultType()) { |
| 1716 | case Primitive::kPrimInt: |
| 1717 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1718 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1719 | __ negl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1720 | break; |
| 1721 | |
| 1722 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1723 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1724 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1725 | __ negq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1726 | break; |
| 1727 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1728 | case Primitive::kPrimFloat: { |
| 1729 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1730 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1731 | // Implement float negation with an exclusive or with value |
| 1732 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 1733 | // single-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1734 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1735 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1736 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1737 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1738 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1739 | case Primitive::kPrimDouble: { |
| 1740 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1741 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1742 | // Implement double negation with an exclusive or with value |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1743 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1744 | // a double-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1745 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1746 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1747 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1748 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1749 | |
| 1750 | default: |
| 1751 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1752 | } |
| 1753 | } |
| 1754 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1755 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 1756 | LocationSummary* locations = |
| 1757 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 1758 | Primitive::Type result_type = conversion->GetResultType(); |
| 1759 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1760 | DCHECK_NE(result_type, input_type); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1761 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1762 | // The Java language does not allow treating boolean as an integral type but |
| 1763 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1764 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1765 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1766 | case Primitive::kPrimByte: |
| 1767 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1768 | case Primitive::kPrimBoolean: |
| 1769 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1770 | case Primitive::kPrimShort: |
| 1771 | case Primitive::kPrimInt: |
| 1772 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1773 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1774 | locations->SetInAt(0, Location::Any()); |
| 1775 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1776 | break; |
| 1777 | |
| 1778 | default: |
| 1779 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1780 | << " to " << result_type; |
| 1781 | } |
| 1782 | break; |
| 1783 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1784 | case Primitive::kPrimShort: |
| 1785 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1786 | case Primitive::kPrimBoolean: |
| 1787 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1788 | case Primitive::kPrimByte: |
| 1789 | case Primitive::kPrimInt: |
| 1790 | case Primitive::kPrimChar: |
| 1791 | // Processing a Dex `int-to-short' instruction. |
| 1792 | locations->SetInAt(0, Location::Any()); |
| 1793 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1794 | break; |
| 1795 | |
| 1796 | default: |
| 1797 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1798 | << " to " << result_type; |
| 1799 | } |
| 1800 | break; |
| 1801 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1802 | case Primitive::kPrimInt: |
| 1803 | switch (input_type) { |
| 1804 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1805 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1806 | locations->SetInAt(0, Location::Any()); |
| 1807 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1808 | break; |
| 1809 | |
| 1810 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1811 | // Processing a Dex `float-to-int' instruction. |
| 1812 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1813 | locations->SetOut(Location::RequiresRegister()); |
| 1814 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1815 | break; |
| 1816 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1817 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1818 | // Processing a Dex `double-to-int' instruction. |
| 1819 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1820 | locations->SetOut(Location::RequiresRegister()); |
| 1821 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1822 | break; |
| 1823 | |
| 1824 | default: |
| 1825 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1826 | << " to " << result_type; |
| 1827 | } |
| 1828 | break; |
| 1829 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1830 | case Primitive::kPrimLong: |
| 1831 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1832 | case Primitive::kPrimBoolean: |
| 1833 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1834 | case Primitive::kPrimByte: |
| 1835 | case Primitive::kPrimShort: |
| 1836 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1837 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1838 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1839 | // TODO: We would benefit from a (to-be-implemented) |
| 1840 | // Location::RegisterOrStackSlot requirement for this input. |
| 1841 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1842 | locations->SetOut(Location::RequiresRegister()); |
| 1843 | break; |
| 1844 | |
| 1845 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1846 | // Processing a Dex `float-to-long' instruction. |
| 1847 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1848 | locations->SetOut(Location::RequiresRegister()); |
| 1849 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1850 | break; |
| 1851 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1852 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1853 | // Processing a Dex `double-to-long' instruction. |
| 1854 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1855 | locations->SetOut(Location::RequiresRegister()); |
| 1856 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1857 | break; |
| 1858 | |
| 1859 | default: |
| 1860 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1861 | << " to " << result_type; |
| 1862 | } |
| 1863 | break; |
| 1864 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1865 | case Primitive::kPrimChar: |
| 1866 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1867 | case Primitive::kPrimBoolean: |
| 1868 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1869 | case Primitive::kPrimByte: |
| 1870 | case Primitive::kPrimShort: |
| 1871 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1872 | // Processing a Dex `int-to-char' instruction. |
| 1873 | locations->SetInAt(0, Location::Any()); |
| 1874 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1875 | break; |
| 1876 | |
| 1877 | default: |
| 1878 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1879 | << " to " << result_type; |
| 1880 | } |
| 1881 | break; |
| 1882 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1883 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1884 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1885 | case Primitive::kPrimBoolean: |
| 1886 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1887 | case Primitive::kPrimByte: |
| 1888 | case Primitive::kPrimShort: |
| 1889 | case Primitive::kPrimInt: |
| 1890 | case Primitive::kPrimChar: |
| 1891 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1892 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1893 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1894 | break; |
| 1895 | |
| 1896 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1897 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1898 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1899 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1900 | break; |
| 1901 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1902 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1903 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1904 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1905 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1906 | break; |
| 1907 | |
| 1908 | default: |
| 1909 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1910 | << " to " << result_type; |
| 1911 | }; |
| 1912 | break; |
| 1913 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1914 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1915 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1916 | case Primitive::kPrimBoolean: |
| 1917 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1918 | case Primitive::kPrimByte: |
| 1919 | case Primitive::kPrimShort: |
| 1920 | case Primitive::kPrimInt: |
| 1921 | case Primitive::kPrimChar: |
| 1922 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1923 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1924 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1925 | break; |
| 1926 | |
| 1927 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1928 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1929 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1930 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1931 | break; |
| 1932 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1933 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1934 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1935 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1936 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1937 | break; |
| 1938 | |
| 1939 | default: |
| 1940 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1941 | << " to " << result_type; |
| 1942 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1943 | break; |
| 1944 | |
| 1945 | default: |
| 1946 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1947 | << " to " << result_type; |
| 1948 | } |
| 1949 | } |
| 1950 | |
| 1951 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 1952 | LocationSummary* locations = conversion->GetLocations(); |
| 1953 | Location out = locations->Out(); |
| 1954 | Location in = locations->InAt(0); |
| 1955 | Primitive::Type result_type = conversion->GetResultType(); |
| 1956 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1957 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1958 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1959 | case Primitive::kPrimByte: |
| 1960 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1961 | case Primitive::kPrimBoolean: |
| 1962 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1963 | case Primitive::kPrimShort: |
| 1964 | case Primitive::kPrimInt: |
| 1965 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1966 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1967 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1968 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1969 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1970 | __ movsxb(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1971 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 1972 | } else { |
| 1973 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1974 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1975 | Immediate(static_cast<int8_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 1976 | } |
| 1977 | break; |
| 1978 | |
| 1979 | default: |
| 1980 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1981 | << " to " << result_type; |
| 1982 | } |
| 1983 | break; |
| 1984 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1985 | case Primitive::kPrimShort: |
| 1986 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1987 | case Primitive::kPrimBoolean: |
| 1988 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1989 | case Primitive::kPrimByte: |
| 1990 | case Primitive::kPrimInt: |
| 1991 | case Primitive::kPrimChar: |
| 1992 | // Processing a Dex `int-to-short' instruction. |
| 1993 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1994 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1995 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1996 | __ movsxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1997 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 1998 | } else { |
| 1999 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2000 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2001 | Immediate(static_cast<int16_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2002 | } |
| 2003 | break; |
| 2004 | |
| 2005 | default: |
| 2006 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2007 | << " to " << result_type; |
| 2008 | } |
| 2009 | break; |
| 2010 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2011 | case Primitive::kPrimInt: |
| 2012 | switch (input_type) { |
| 2013 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2014 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2015 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2016 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2017 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2018 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2019 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2020 | } else { |
| 2021 | DCHECK(in.IsConstant()); |
| 2022 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2023 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2024 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2025 | } |
| 2026 | break; |
| 2027 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2028 | case Primitive::kPrimFloat: { |
| 2029 | // Processing a Dex `float-to-int' instruction. |
| 2030 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2031 | CpuRegister output = out.AsRegister<CpuRegister>(); |
| 2032 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 2033 | Label done, nan; |
| 2034 | |
| 2035 | __ movl(output, Immediate(kPrimIntMax)); |
| 2036 | // temp = int-to-float(output) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2037 | __ cvtsi2ss(temp, output, false); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2038 | // if input >= temp goto done |
| 2039 | __ comiss(input, temp); |
| 2040 | __ j(kAboveEqual, &done); |
| 2041 | // if input == NaN goto nan |
| 2042 | __ j(kUnordered, &nan); |
| 2043 | // output = float-to-int-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2044 | __ cvttss2si(output, input, false); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2045 | __ jmp(&done); |
| 2046 | __ Bind(&nan); |
| 2047 | // output = 0 |
| 2048 | __ xorl(output, output); |
| 2049 | __ Bind(&done); |
| 2050 | break; |
| 2051 | } |
| 2052 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2053 | case Primitive::kPrimDouble: { |
| 2054 | // Processing a Dex `double-to-int' instruction. |
| 2055 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2056 | CpuRegister output = out.AsRegister<CpuRegister>(); |
| 2057 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 2058 | Label done, nan; |
| 2059 | |
| 2060 | __ movl(output, Immediate(kPrimIntMax)); |
| 2061 | // temp = int-to-double(output) |
| 2062 | __ cvtsi2sd(temp, output); |
| 2063 | // if input >= temp goto done |
| 2064 | __ comisd(input, temp); |
| 2065 | __ j(kAboveEqual, &done); |
| 2066 | // if input == NaN goto nan |
| 2067 | __ j(kUnordered, &nan); |
| 2068 | // output = double-to-int-truncate(input) |
| 2069 | __ cvttsd2si(output, input); |
| 2070 | __ jmp(&done); |
| 2071 | __ Bind(&nan); |
| 2072 | // output = 0 |
| 2073 | __ xorl(output, output); |
| 2074 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2075 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2076 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2077 | |
| 2078 | default: |
| 2079 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2080 | << " to " << result_type; |
| 2081 | } |
| 2082 | break; |
| 2083 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2084 | case Primitive::kPrimLong: |
| 2085 | switch (input_type) { |
| 2086 | DCHECK(out.IsRegister()); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2087 | case Primitive::kPrimBoolean: |
| 2088 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2089 | case Primitive::kPrimByte: |
| 2090 | case Primitive::kPrimShort: |
| 2091 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2092 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2093 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2094 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2095 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2096 | break; |
| 2097 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2098 | case Primitive::kPrimFloat: { |
| 2099 | // Processing a Dex `float-to-long' instruction. |
| 2100 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2101 | CpuRegister output = out.AsRegister<CpuRegister>(); |
| 2102 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 2103 | Label done, nan; |
| 2104 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2105 | codegen_->Load64BitValue(output, kPrimLongMax); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2106 | // temp = long-to-float(output) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2107 | __ cvtsi2ss(temp, output, true); |
| 2108 | // if input >= temp goto done |
| 2109 | __ comiss(input, temp); |
| 2110 | __ j(kAboveEqual, &done); |
| 2111 | // if input == NaN goto nan |
| 2112 | __ j(kUnordered, &nan); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2113 | // output = float-to-long-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2114 | __ cvttss2si(output, input, true); |
| 2115 | __ jmp(&done); |
| 2116 | __ Bind(&nan); |
| 2117 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2118 | __ xorl(output, output); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2119 | __ Bind(&done); |
| 2120 | break; |
| 2121 | } |
| 2122 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2123 | case Primitive::kPrimDouble: { |
| 2124 | // Processing a Dex `double-to-long' instruction. |
| 2125 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2126 | CpuRegister output = out.AsRegister<CpuRegister>(); |
| 2127 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 2128 | Label done, nan; |
| 2129 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2130 | codegen_->Load64BitValue(output, kPrimLongMax); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2131 | // temp = long-to-double(output) |
| 2132 | __ cvtsi2sd(temp, output, true); |
| 2133 | // if input >= temp goto done |
| 2134 | __ comisd(input, temp); |
| 2135 | __ j(kAboveEqual, &done); |
| 2136 | // if input == NaN goto nan |
| 2137 | __ j(kUnordered, &nan); |
| 2138 | // output = double-to-long-truncate(input) |
| 2139 | __ cvttsd2si(output, input, true); |
| 2140 | __ jmp(&done); |
| 2141 | __ Bind(&nan); |
| 2142 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2143 | __ xorl(output, output); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2144 | __ Bind(&done); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2145 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2146 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2147 | |
| 2148 | default: |
| 2149 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2150 | << " to " << result_type; |
| 2151 | } |
| 2152 | break; |
| 2153 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2154 | case Primitive::kPrimChar: |
| 2155 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2156 | case Primitive::kPrimBoolean: |
| 2157 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2158 | case Primitive::kPrimByte: |
| 2159 | case Primitive::kPrimShort: |
| 2160 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2161 | // Processing a Dex `int-to-char' instruction. |
| 2162 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2163 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2164 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2165 | __ movzxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2166 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2167 | } else { |
| 2168 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2169 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2170 | Immediate(static_cast<uint16_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2171 | } |
| 2172 | break; |
| 2173 | |
| 2174 | default: |
| 2175 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2176 | << " to " << result_type; |
| 2177 | } |
| 2178 | break; |
| 2179 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2180 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2181 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2182 | case Primitive::kPrimBoolean: |
| 2183 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2184 | case Primitive::kPrimByte: |
| 2185 | case Primitive::kPrimShort: |
| 2186 | case Primitive::kPrimInt: |
| 2187 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2188 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2189 | if (in.IsRegister()) { |
| 2190 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2191 | } else if (in.IsConstant()) { |
| 2192 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2193 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2194 | if (v == 0) { |
| 2195 | __ xorps(dest, dest); |
| 2196 | } else { |
| 2197 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2198 | } |
| 2199 | } else { |
| 2200 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2201 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2202 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2203 | break; |
| 2204 | |
| 2205 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2206 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2207 | if (in.IsRegister()) { |
| 2208 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2209 | } else if (in.IsConstant()) { |
| 2210 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2211 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2212 | if (v == 0) { |
| 2213 | __ xorps(dest, dest); |
| 2214 | } else { |
| 2215 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2216 | } |
| 2217 | } else { |
| 2218 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2219 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2220 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2221 | break; |
| 2222 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2223 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2224 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2225 | if (in.IsFpuRegister()) { |
| 2226 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2227 | } else if (in.IsConstant()) { |
| 2228 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2229 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2230 | if (bit_cast<int64_t, double>(v) == 0) { |
| 2231 | __ xorps(dest, dest); |
| 2232 | } else { |
| 2233 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2234 | } |
| 2235 | } else { |
| 2236 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 2237 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2238 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2239 | break; |
| 2240 | |
| 2241 | default: |
| 2242 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2243 | << " to " << result_type; |
| 2244 | }; |
| 2245 | break; |
| 2246 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2247 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2248 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2249 | case Primitive::kPrimBoolean: |
| 2250 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2251 | case Primitive::kPrimByte: |
| 2252 | case Primitive::kPrimShort: |
| 2253 | case Primitive::kPrimInt: |
| 2254 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2255 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2256 | if (in.IsRegister()) { |
| 2257 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2258 | } else if (in.IsConstant()) { |
| 2259 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2260 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2261 | if (v == 0) { |
| 2262 | __ xorpd(dest, dest); |
| 2263 | } else { |
| 2264 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2265 | } |
| 2266 | } else { |
| 2267 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2268 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2269 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2270 | break; |
| 2271 | |
| 2272 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2273 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2274 | if (in.IsRegister()) { |
| 2275 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2276 | } else if (in.IsConstant()) { |
| 2277 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2278 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2279 | if (v == 0) { |
| 2280 | __ xorpd(dest, dest); |
| 2281 | } else { |
| 2282 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2283 | } |
| 2284 | } else { |
| 2285 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2286 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2287 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2288 | break; |
| 2289 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2290 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2291 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2292 | if (in.IsFpuRegister()) { |
| 2293 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2294 | } else if (in.IsConstant()) { |
| 2295 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 2296 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2297 | if (bit_cast<int32_t, float>(v) == 0) { |
| 2298 | __ xorpd(dest, dest); |
| 2299 | } else { |
| 2300 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2301 | } |
| 2302 | } else { |
| 2303 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 2304 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2305 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2306 | break; |
| 2307 | |
| 2308 | default: |
| 2309 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2310 | << " to " << result_type; |
| 2311 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2312 | break; |
| 2313 | |
| 2314 | default: |
| 2315 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2316 | << " to " << result_type; |
| 2317 | } |
| 2318 | } |
| 2319 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2320 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2321 | LocationSummary* locations = |
| 2322 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2323 | switch (add->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2324 | case Primitive::kPrimInt: { |
| 2325 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2326 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2327 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2328 | break; |
| 2329 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2330 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2331 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2332 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2333 | // 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] | 2334 | locations->SetInAt(1, Location::RegisterOrInt32LongConstant(add->InputAt(1))); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2335 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2336 | break; |
| 2337 | } |
| 2338 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2339 | case Primitive::kPrimDouble: |
| 2340 | case Primitive::kPrimFloat: { |
| 2341 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2342 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2343 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2344 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2345 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2346 | |
| 2347 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2348 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2349 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2350 | } |
| 2351 | |
| 2352 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 2353 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2354 | Location first = locations->InAt(0); |
| 2355 | Location second = locations->InAt(1); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2356 | Location out = locations->Out(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2357 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2358 | switch (add->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2359 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2360 | if (second.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2361 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2362 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2363 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2364 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2365 | } else { |
| 2366 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2367 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2368 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2369 | } else if (second.IsConstant()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2370 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2371 | __ addl(out.AsRegister<CpuRegister>(), |
| 2372 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 2373 | } else { |
| 2374 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2375 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 2376 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2377 | } else { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2378 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2379 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2380 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2381 | break; |
| 2382 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2383 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2384 | case Primitive::kPrimLong: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2385 | if (second.IsRegister()) { |
| 2386 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2387 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2388 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2389 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2390 | } else { |
| 2391 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2392 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2393 | } |
| 2394 | } else { |
| 2395 | DCHECK(second.IsConstant()); |
| 2396 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2397 | int32_t int32_value = Low32Bits(value); |
| 2398 | DCHECK_EQ(int32_value, value); |
| 2399 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2400 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 2401 | } else { |
| 2402 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2403 | first.AsRegister<CpuRegister>(), int32_value)); |
| 2404 | } |
| 2405 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2406 | break; |
| 2407 | } |
| 2408 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2409 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2410 | if (second.IsFpuRegister()) { |
| 2411 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2412 | } else if (second.IsConstant()) { |
| 2413 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2414 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 2415 | } else { |
| 2416 | DCHECK(second.IsStackSlot()); |
| 2417 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2418 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2419 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2420 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2421 | } |
| 2422 | |
| 2423 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2424 | if (second.IsFpuRegister()) { |
| 2425 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2426 | } else if (second.IsConstant()) { |
| 2427 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2428 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 2429 | } else { |
| 2430 | DCHECK(second.IsDoubleStackSlot()); |
| 2431 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2432 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2433 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2434 | break; |
| 2435 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2436 | |
| 2437 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2438 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2439 | } |
| 2440 | } |
| 2441 | |
| 2442 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2443 | LocationSummary* locations = |
| 2444 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2445 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2446 | case Primitive::kPrimInt: { |
| 2447 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2448 | locations->SetInAt(1, Location::Any()); |
| 2449 | locations->SetOut(Location::SameAsFirstInput()); |
| 2450 | break; |
| 2451 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2452 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2453 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2454 | locations->SetInAt(1, Location::RegisterOrInt32LongConstant(sub->InputAt(1))); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2455 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2456 | break; |
| 2457 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2458 | case Primitive::kPrimFloat: |
| 2459 | case Primitive::kPrimDouble: { |
| 2460 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2461 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2462 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2463 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2464 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2465 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2466 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2467 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2468 | } |
| 2469 | |
| 2470 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 2471 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2472 | Location first = locations->InAt(0); |
| 2473 | Location second = locations->InAt(1); |
| 2474 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2475 | switch (sub->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2476 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2477 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2478 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2479 | } else if (second.IsConstant()) { |
| 2480 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2481 | __ subl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2482 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2483 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2484 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2485 | break; |
| 2486 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2487 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2488 | if (second.IsConstant()) { |
| 2489 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2490 | DCHECK(IsInt<32>(value)); |
| 2491 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 2492 | } else { |
| 2493 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 2494 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2495 | break; |
| 2496 | } |
| 2497 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2498 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2499 | if (second.IsFpuRegister()) { |
| 2500 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2501 | } else if (second.IsConstant()) { |
| 2502 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2503 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 2504 | } else { |
| 2505 | DCHECK(second.IsStackSlot()); |
| 2506 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2507 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2508 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2509 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2510 | } |
| 2511 | |
| 2512 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2513 | if (second.IsFpuRegister()) { |
| 2514 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2515 | } else if (second.IsConstant()) { |
| 2516 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2517 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 2518 | } else { |
| 2519 | DCHECK(second.IsDoubleStackSlot()); |
| 2520 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2521 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2522 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2523 | break; |
| 2524 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2525 | |
| 2526 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2527 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2528 | } |
| 2529 | } |
| 2530 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2531 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 2532 | LocationSummary* locations = |
| 2533 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2534 | switch (mul->GetResultType()) { |
| 2535 | case Primitive::kPrimInt: { |
| 2536 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2537 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame^] | 2538 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2539 | // Can use 3 operand multiply. |
| 2540 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2541 | } else { |
| 2542 | locations->SetOut(Location::SameAsFirstInput()); |
| 2543 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2544 | break; |
| 2545 | } |
| 2546 | case Primitive::kPrimLong: { |
| 2547 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame^] | 2548 | locations->SetInAt(1, Location::Any()); |
| 2549 | if (mul->InputAt(1)->IsLongConstant() && |
| 2550 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2551 | // Can use 3 operand multiply. |
| 2552 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2553 | } else { |
| 2554 | locations->SetOut(Location::SameAsFirstInput()); |
| 2555 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2556 | break; |
| 2557 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2558 | case Primitive::kPrimFloat: |
| 2559 | case Primitive::kPrimDouble: { |
| 2560 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2561 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2562 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2563 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2564 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2565 | |
| 2566 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2567 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2568 | } |
| 2569 | } |
| 2570 | |
| 2571 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 2572 | LocationSummary* locations = mul->GetLocations(); |
| 2573 | Location first = locations->InAt(0); |
| 2574 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame^] | 2575 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2576 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame^] | 2577 | case Primitive::kPrimInt: |
| 2578 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2579 | // problems where the output may not be the same as the first operand. |
| 2580 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2581 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 2582 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 2583 | } else if (second.IsRegister()) { |
| 2584 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2585 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2586 | } else { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame^] | 2587 | DCHECK(first.Equals(out)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2588 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2589 | __ imull(first.AsRegister<CpuRegister>(), |
| 2590 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2591 | } |
| 2592 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2593 | case Primitive::kPrimLong: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame^] | 2594 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2595 | // problems where the output may not be the same as the first operand. |
| 2596 | if (mul->InputAt(1)->IsLongConstant()) { |
| 2597 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 2598 | if (IsInt<32>(value)) { |
| 2599 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 2600 | Immediate(static_cast<int32_t>(value))); |
| 2601 | } else { |
| 2602 | // Have to use the constant area. |
| 2603 | DCHECK(first.Equals(out)); |
| 2604 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 2605 | } |
| 2606 | } else if (second.IsRegister()) { |
| 2607 | DCHECK(first.Equals(out)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2608 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame^] | 2609 | } else { |
| 2610 | DCHECK(second.IsDoubleStackSlot()); |
| 2611 | DCHECK(first.Equals(out)); |
| 2612 | __ imulq(first.AsRegister<CpuRegister>(), |
| 2613 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2614 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2615 | break; |
| 2616 | } |
| 2617 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2618 | case Primitive::kPrimFloat: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame^] | 2619 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2620 | if (second.IsFpuRegister()) { |
| 2621 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2622 | } else if (second.IsConstant()) { |
| 2623 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 2624 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 2625 | } else { |
| 2626 | DCHECK(second.IsStackSlot()); |
| 2627 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 2628 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2629 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2630 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2631 | } |
| 2632 | |
| 2633 | case Primitive::kPrimDouble: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame^] | 2634 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2635 | if (second.IsFpuRegister()) { |
| 2636 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2637 | } else if (second.IsConstant()) { |
| 2638 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 2639 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 2640 | } else { |
| 2641 | DCHECK(second.IsDoubleStackSlot()); |
| 2642 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 2643 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2644 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2645 | break; |
| 2646 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2647 | |
| 2648 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2649 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2650 | } |
| 2651 | } |
| 2652 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2653 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 2654 | uint32_t stack_adjustment, bool is_float) { |
| 2655 | if (source.IsStackSlot()) { |
| 2656 | DCHECK(is_float); |
| 2657 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 2658 | } else if (source.IsDoubleStackSlot()) { |
| 2659 | DCHECK(!is_float); |
| 2660 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 2661 | } else { |
| 2662 | // Write the value to the temporary location on the stack and load to FP stack. |
| 2663 | if (is_float) { |
| 2664 | Location stack_temp = Location::StackSlot(temp_offset); |
| 2665 | codegen_->Move(stack_temp, source); |
| 2666 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 2667 | } else { |
| 2668 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 2669 | codegen_->Move(stack_temp, source); |
| 2670 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 2671 | } |
| 2672 | } |
| 2673 | } |
| 2674 | |
| 2675 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| 2676 | Primitive::Type type = rem->GetResultType(); |
| 2677 | bool is_float = type == Primitive::kPrimFloat; |
| 2678 | size_t elem_size = Primitive::ComponentSize(type); |
| 2679 | LocationSummary* locations = rem->GetLocations(); |
| 2680 | Location first = locations->InAt(0); |
| 2681 | Location second = locations->InAt(1); |
| 2682 | Location out = locations->Out(); |
| 2683 | |
| 2684 | // Create stack space for 2 elements. |
| 2685 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2686 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 2687 | |
| 2688 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 2689 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 2690 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 2691 | |
| 2692 | // Loop doing FPREM until we stabilize. |
| 2693 | Label retry; |
| 2694 | __ Bind(&retry); |
| 2695 | __ fprem(); |
| 2696 | |
| 2697 | // Move FP status to AX. |
| 2698 | __ fstsw(); |
| 2699 | |
| 2700 | // And see if the argument reduction is complete. This is signaled by the |
| 2701 | // C2 FPU flag bit set to 0. |
| 2702 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 2703 | __ j(kNotEqual, &retry); |
| 2704 | |
| 2705 | // We have settled on the final value. Retrieve it into an XMM register. |
| 2706 | // Store FP top of stack to real stack. |
| 2707 | if (is_float) { |
| 2708 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 2709 | } else { |
| 2710 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 2711 | } |
| 2712 | |
| 2713 | // Pop the 2 items from the FP stack. |
| 2714 | __ fucompp(); |
| 2715 | |
| 2716 | // Load the value from the stack into an XMM register. |
| 2717 | DCHECK(out.IsFpuRegister()) << out; |
| 2718 | if (is_float) { |
| 2719 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 2720 | } else { |
| 2721 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 2722 | } |
| 2723 | |
| 2724 | // And remove the temporary stack space we allocated. |
| 2725 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 2726 | } |
| 2727 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2728 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2729 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2730 | |
| 2731 | LocationSummary* locations = instruction->GetLocations(); |
| 2732 | Location second = locations->InAt(1); |
| 2733 | DCHECK(second.IsConstant()); |
| 2734 | |
| 2735 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 2736 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2737 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2738 | |
| 2739 | DCHECK(imm == 1 || imm == -1); |
| 2740 | |
| 2741 | switch (instruction->GetResultType()) { |
| 2742 | case Primitive::kPrimInt: { |
| 2743 | if (instruction->IsRem()) { |
| 2744 | __ xorl(output_register, output_register); |
| 2745 | } else { |
| 2746 | __ movl(output_register, input_register); |
| 2747 | if (imm == -1) { |
| 2748 | __ negl(output_register); |
| 2749 | } |
| 2750 | } |
| 2751 | break; |
| 2752 | } |
| 2753 | |
| 2754 | case Primitive::kPrimLong: { |
| 2755 | if (instruction->IsRem()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2756 | __ xorl(output_register, output_register); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2757 | } else { |
| 2758 | __ movq(output_register, input_register); |
| 2759 | if (imm == -1) { |
| 2760 | __ negq(output_register); |
| 2761 | } |
| 2762 | } |
| 2763 | break; |
| 2764 | } |
| 2765 | |
| 2766 | default: |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2767 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2768 | } |
| 2769 | } |
| 2770 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2771 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2772 | LocationSummary* locations = instruction->GetLocations(); |
| 2773 | Location second = locations->InAt(1); |
| 2774 | |
| 2775 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 2776 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 2777 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2778 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2779 | |
| 2780 | DCHECK(IsPowerOfTwo(std::abs(imm))); |
| 2781 | |
| 2782 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2783 | |
| 2784 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 2785 | __ leal(tmp, Address(numerator, std::abs(imm) - 1)); |
| 2786 | __ testl(numerator, numerator); |
| 2787 | __ cmov(kGreaterEqual, tmp, numerator); |
| 2788 | int shift = CTZ(imm); |
| 2789 | __ sarl(tmp, Immediate(shift)); |
| 2790 | |
| 2791 | if (imm < 0) { |
| 2792 | __ negl(tmp); |
| 2793 | } |
| 2794 | |
| 2795 | __ movl(output_register, tmp); |
| 2796 | } else { |
| 2797 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 2798 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2799 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2800 | codegen_->Load64BitValue(rdx, std::abs(imm) - 1); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2801 | __ addq(rdx, numerator); |
| 2802 | __ testq(numerator, numerator); |
| 2803 | __ cmov(kGreaterEqual, rdx, numerator); |
| 2804 | int shift = CTZ(imm); |
| 2805 | __ sarq(rdx, Immediate(shift)); |
| 2806 | |
| 2807 | if (imm < 0) { |
| 2808 | __ negq(rdx); |
| 2809 | } |
| 2810 | |
| 2811 | __ movq(output_register, rdx); |
| 2812 | } |
| 2813 | } |
| 2814 | |
| 2815 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2816 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2817 | |
| 2818 | LocationSummary* locations = instruction->GetLocations(); |
| 2819 | Location second = locations->InAt(1); |
| 2820 | |
| 2821 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 2822 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2823 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 2824 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 2825 | : locations->Out().AsRegister<CpuRegister>(); |
| 2826 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 2827 | |
| 2828 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 2829 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 2830 | if (instruction->IsDiv()) { |
| 2831 | DCHECK_EQ(RAX, out.AsRegister()); |
| 2832 | } else { |
| 2833 | DCHECK_EQ(RDX, out.AsRegister()); |
| 2834 | } |
| 2835 | |
| 2836 | int64_t magic; |
| 2837 | int shift; |
| 2838 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2839 | // TODO: can these branches be written as one? |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2840 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 2841 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2842 | |
| 2843 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2844 | |
| 2845 | __ movl(numerator, eax); |
| 2846 | |
| 2847 | Label no_div; |
| 2848 | Label end; |
| 2849 | __ testl(eax, eax); |
| 2850 | __ j(kNotEqual, &no_div); |
| 2851 | |
| 2852 | __ xorl(out, out); |
| 2853 | __ jmp(&end); |
| 2854 | |
| 2855 | __ Bind(&no_div); |
| 2856 | |
| 2857 | __ movl(eax, Immediate(magic)); |
| 2858 | __ imull(numerator); |
| 2859 | |
| 2860 | if (imm > 0 && magic < 0) { |
| 2861 | __ addl(edx, numerator); |
| 2862 | } else if (imm < 0 && magic > 0) { |
| 2863 | __ subl(edx, numerator); |
| 2864 | } |
| 2865 | |
| 2866 | if (shift != 0) { |
| 2867 | __ sarl(edx, Immediate(shift)); |
| 2868 | } |
| 2869 | |
| 2870 | __ movl(eax, edx); |
| 2871 | __ shrl(edx, Immediate(31)); |
| 2872 | __ addl(edx, eax); |
| 2873 | |
| 2874 | if (instruction->IsRem()) { |
| 2875 | __ movl(eax, numerator); |
| 2876 | __ imull(edx, Immediate(imm)); |
| 2877 | __ subl(eax, edx); |
| 2878 | __ movl(edx, eax); |
| 2879 | } else { |
| 2880 | __ movl(eax, edx); |
| 2881 | } |
| 2882 | __ Bind(&end); |
| 2883 | } else { |
| 2884 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2885 | |
| 2886 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 2887 | |
| 2888 | CpuRegister rax = eax; |
| 2889 | CpuRegister rdx = edx; |
| 2890 | |
| 2891 | CalculateMagicAndShiftForDivRem(imm, true /* is_long */, &magic, &shift); |
| 2892 | |
| 2893 | // Save the numerator. |
| 2894 | __ movq(numerator, rax); |
| 2895 | |
| 2896 | // RAX = magic |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2897 | codegen_->Load64BitValue(rax, magic); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2898 | |
| 2899 | // RDX:RAX = magic * numerator |
| 2900 | __ imulq(numerator); |
| 2901 | |
| 2902 | if (imm > 0 && magic < 0) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2903 | // RDX += numerator |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2904 | __ addq(rdx, numerator); |
| 2905 | } else if (imm < 0 && magic > 0) { |
| 2906 | // RDX -= numerator |
| 2907 | __ subq(rdx, numerator); |
| 2908 | } |
| 2909 | |
| 2910 | // Shift if needed. |
| 2911 | if (shift != 0) { |
| 2912 | __ sarq(rdx, Immediate(shift)); |
| 2913 | } |
| 2914 | |
| 2915 | // RDX += 1 if RDX < 0 |
| 2916 | __ movq(rax, rdx); |
| 2917 | __ shrq(rdx, Immediate(63)); |
| 2918 | __ addq(rdx, rax); |
| 2919 | |
| 2920 | if (instruction->IsRem()) { |
| 2921 | __ movq(rax, numerator); |
| 2922 | |
| 2923 | if (IsInt<32>(imm)) { |
| 2924 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 2925 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2926 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2927 | } |
| 2928 | |
| 2929 | __ subq(rax, rdx); |
| 2930 | __ movq(rdx, rax); |
| 2931 | } else { |
| 2932 | __ movq(rax, rdx); |
| 2933 | } |
| 2934 | } |
| 2935 | } |
| 2936 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2937 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 2938 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2939 | Primitive::Type type = instruction->GetResultType(); |
| 2940 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 2941 | |
| 2942 | bool is_div = instruction->IsDiv(); |
| 2943 | LocationSummary* locations = instruction->GetLocations(); |
| 2944 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2945 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 2946 | Location second = locations->InAt(1); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2947 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2948 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2949 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2950 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2951 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2952 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2953 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2954 | if (imm == 0) { |
| 2955 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 2956 | } else if (imm == 1 || imm == -1) { |
| 2957 | DivRemOneOrMinusOne(instruction); |
| 2958 | } else if (instruction->IsDiv() && IsPowerOfTwo(std::abs(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2959 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2960 | } else { |
| 2961 | DCHECK(imm <= -2 || imm >= 2); |
| 2962 | GenerateDivRemWithAnyConstant(instruction); |
| 2963 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2964 | } else { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2965 | SlowPathCodeX86_64* slow_path = |
| 2966 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86_64( |
| 2967 | out.AsRegister(), type, is_div); |
| 2968 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2969 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2970 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 2971 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 2972 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 2973 | // so it's safe to just use negl instead of more complex comparisons. |
| 2974 | if (type == Primitive::kPrimInt) { |
| 2975 | __ cmpl(second_reg, Immediate(-1)); |
| 2976 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2977 | // edx:eax <- sign-extended of eax |
| 2978 | __ cdq(); |
| 2979 | // eax = quotient, edx = remainder |
| 2980 | __ idivl(second_reg); |
| 2981 | } else { |
| 2982 | __ cmpq(second_reg, Immediate(-1)); |
| 2983 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 2984 | // rdx:rax <- sign-extended of rax |
| 2985 | __ cqo(); |
| 2986 | // rax = quotient, rdx = remainder |
| 2987 | __ idivq(second_reg); |
| 2988 | } |
| 2989 | __ Bind(slow_path->GetExitLabel()); |
| 2990 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2991 | } |
| 2992 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2993 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 2994 | LocationSummary* locations = |
| 2995 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 2996 | switch (div->GetResultType()) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2997 | case Primitive::kPrimInt: |
| 2998 | case Primitive::kPrimLong: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2999 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3000 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3001 | locations->SetOut(Location::SameAsFirstInput()); |
| 3002 | // Intel uses edx:eax as the dividend. |
| 3003 | locations->AddTemp(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3004 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3005 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3006 | // output and request another temp. |
| 3007 | if (div->InputAt(1)->IsConstant()) { |
| 3008 | locations->AddTemp(Location::RequiresRegister()); |
| 3009 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3010 | break; |
| 3011 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3012 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3013 | case Primitive::kPrimFloat: |
| 3014 | case Primitive::kPrimDouble: { |
| 3015 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3016 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3017 | locations->SetOut(Location::SameAsFirstInput()); |
| 3018 | break; |
| 3019 | } |
| 3020 | |
| 3021 | default: |
| 3022 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3023 | } |
| 3024 | } |
| 3025 | |
| 3026 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3027 | LocationSummary* locations = div->GetLocations(); |
| 3028 | Location first = locations->InAt(0); |
| 3029 | Location second = locations->InAt(1); |
| 3030 | DCHECK(first.Equals(locations->Out())); |
| 3031 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3032 | Primitive::Type type = div->GetResultType(); |
| 3033 | switch (type) { |
| 3034 | case Primitive::kPrimInt: |
| 3035 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3036 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3037 | break; |
| 3038 | } |
| 3039 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3040 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3041 | if (second.IsFpuRegister()) { |
| 3042 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3043 | } else if (second.IsConstant()) { |
| 3044 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3045 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 3046 | } else { |
| 3047 | DCHECK(second.IsStackSlot()); |
| 3048 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3049 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3050 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3051 | break; |
| 3052 | } |
| 3053 | |
| 3054 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3055 | if (second.IsFpuRegister()) { |
| 3056 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3057 | } else if (second.IsConstant()) { |
| 3058 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3059 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 3060 | } else { |
| 3061 | DCHECK(second.IsDoubleStackSlot()); |
| 3062 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3063 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3064 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3065 | break; |
| 3066 | } |
| 3067 | |
| 3068 | default: |
| 3069 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3070 | } |
| 3071 | } |
| 3072 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3073 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3074 | Primitive::Type type = rem->GetResultType(); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3075 | LocationSummary* locations = |
| 3076 | new (GetGraph()->GetArena()) LocationSummary(rem, LocationSummary::kNoCall); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3077 | |
| 3078 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3079 | case Primitive::kPrimInt: |
| 3080 | case Primitive::kPrimLong: { |
| 3081 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3082 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3083 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3084 | locations->SetOut(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3085 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3086 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3087 | // output and request another temp. |
| 3088 | if (rem->InputAt(1)->IsConstant()) { |
| 3089 | locations->AddTemp(Location::RequiresRegister()); |
| 3090 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3091 | break; |
| 3092 | } |
| 3093 | |
| 3094 | case Primitive::kPrimFloat: |
| 3095 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3096 | locations->SetInAt(0, Location::Any()); |
| 3097 | locations->SetInAt(1, Location::Any()); |
| 3098 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3099 | locations->AddTemp(Location::RegisterLocation(RAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3100 | break; |
| 3101 | } |
| 3102 | |
| 3103 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3104 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3105 | } |
| 3106 | } |
| 3107 | |
| 3108 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| 3109 | Primitive::Type type = rem->GetResultType(); |
| 3110 | switch (type) { |
| 3111 | case Primitive::kPrimInt: |
| 3112 | case Primitive::kPrimLong: { |
| 3113 | GenerateDivRemIntegral(rem); |
| 3114 | break; |
| 3115 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3116 | case Primitive::kPrimFloat: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3117 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3118 | GenerateRemFP(rem); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3119 | break; |
| 3120 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3121 | default: |
| 3122 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3123 | } |
| 3124 | } |
| 3125 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3126 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3127 | LocationSummary* locations = |
| 3128 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3129 | locations->SetInAt(0, Location::Any()); |
| 3130 | if (instruction->HasUses()) { |
| 3131 | locations->SetOut(Location::SameAsFirstInput()); |
| 3132 | } |
| 3133 | } |
| 3134 | |
| 3135 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3136 | SlowPathCodeX86_64* slow_path = |
| 3137 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction); |
| 3138 | codegen_->AddSlowPath(slow_path); |
| 3139 | |
| 3140 | LocationSummary* locations = instruction->GetLocations(); |
| 3141 | Location value = locations->InAt(0); |
| 3142 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3143 | switch (instruction->GetType()) { |
| 3144 | case Primitive::kPrimInt: { |
| 3145 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3146 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3147 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3148 | } else if (value.IsStackSlot()) { |
| 3149 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3150 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3151 | } else { |
| 3152 | DCHECK(value.IsConstant()) << value; |
| 3153 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3154 | __ jmp(slow_path->GetEntryLabel()); |
| 3155 | } |
| 3156 | } |
| 3157 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3158 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3159 | case Primitive::kPrimLong: { |
| 3160 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3161 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3162 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3163 | } else if (value.IsDoubleStackSlot()) { |
| 3164 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3165 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3166 | } else { |
| 3167 | DCHECK(value.IsConstant()) << value; |
| 3168 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3169 | __ jmp(slow_path->GetEntryLabel()); |
| 3170 | } |
| 3171 | } |
| 3172 | break; |
| 3173 | } |
| 3174 | default: |
| 3175 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3176 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3177 | } |
| 3178 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3179 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 3180 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3181 | |
| 3182 | LocationSummary* locations = |
| 3183 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3184 | |
| 3185 | switch (op->GetResultType()) { |
| 3186 | case Primitive::kPrimInt: |
| 3187 | case Primitive::kPrimLong: { |
| 3188 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3189 | // The shift count needs to be in CL. |
| 3190 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 3191 | locations->SetOut(Location::SameAsFirstInput()); |
| 3192 | break; |
| 3193 | } |
| 3194 | default: |
| 3195 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3196 | } |
| 3197 | } |
| 3198 | |
| 3199 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 3200 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3201 | |
| 3202 | LocationSummary* locations = op->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3203 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3204 | Location second = locations->InAt(1); |
| 3205 | |
| 3206 | switch (op->GetResultType()) { |
| 3207 | case Primitive::kPrimInt: { |
| 3208 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3209 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3210 | if (op->IsShl()) { |
| 3211 | __ shll(first_reg, second_reg); |
| 3212 | } else if (op->IsShr()) { |
| 3213 | __ sarl(first_reg, second_reg); |
| 3214 | } else { |
| 3215 | __ shrl(first_reg, second_reg); |
| 3216 | } |
| 3217 | } else { |
Nicolas Geoffray | 486cc19 | 2014-12-08 18:00:55 +0000 | [diff] [blame] | 3218 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3219 | if (op->IsShl()) { |
| 3220 | __ shll(first_reg, imm); |
| 3221 | } else if (op->IsShr()) { |
| 3222 | __ sarl(first_reg, imm); |
| 3223 | } else { |
| 3224 | __ shrl(first_reg, imm); |
| 3225 | } |
| 3226 | } |
| 3227 | break; |
| 3228 | } |
| 3229 | case Primitive::kPrimLong: { |
| 3230 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3231 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3232 | if (op->IsShl()) { |
| 3233 | __ shlq(first_reg, second_reg); |
| 3234 | } else if (op->IsShr()) { |
| 3235 | __ sarq(first_reg, second_reg); |
| 3236 | } else { |
| 3237 | __ shrq(first_reg, second_reg); |
| 3238 | } |
| 3239 | } else { |
Nicolas Geoffray | 486cc19 | 2014-12-08 18:00:55 +0000 | [diff] [blame] | 3240 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3241 | if (op->IsShl()) { |
| 3242 | __ shlq(first_reg, imm); |
| 3243 | } else if (op->IsShr()) { |
| 3244 | __ sarq(first_reg, imm); |
| 3245 | } else { |
| 3246 | __ shrq(first_reg, imm); |
| 3247 | } |
| 3248 | } |
| 3249 | break; |
| 3250 | } |
| 3251 | default: |
| 3252 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3253 | } |
| 3254 | } |
| 3255 | |
| 3256 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 3257 | HandleShift(shl); |
| 3258 | } |
| 3259 | |
| 3260 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 3261 | HandleShift(shl); |
| 3262 | } |
| 3263 | |
| 3264 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 3265 | HandleShift(shr); |
| 3266 | } |
| 3267 | |
| 3268 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 3269 | HandleShift(shr); |
| 3270 | } |
| 3271 | |
| 3272 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 3273 | HandleShift(ushr); |
| 3274 | } |
| 3275 | |
| 3276 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 3277 | HandleShift(ushr); |
| 3278 | } |
| 3279 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3280 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3281 | LocationSummary* locations = |
| 3282 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3283 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3284 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3285 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3286 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3287 | } |
| 3288 | |
| 3289 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
| 3290 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3291 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 3292 | instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3293 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3294 | // of poisoning the reference. |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3295 | __ gs()->call( |
| 3296 | Address::Absolute(GetThreadOffset<kX86_64WordSize>(instruction->GetEntrypoint()), true)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3297 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 3298 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3299 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3300 | } |
| 3301 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3302 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 3303 | LocationSummary* locations = |
| 3304 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3305 | InvokeRuntimeCallingConvention calling_convention; |
| 3306 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3307 | locations->SetOut(Location::RegisterLocation(RAX)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3308 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3309 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3310 | } |
| 3311 | |
| 3312 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| 3313 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3314 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 3315 | instruction->GetTypeIndex()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3316 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3317 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3318 | // of poisoning the reference. |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3319 | __ gs()->call( |
| 3320 | Address::Absolute(GetThreadOffset<kX86_64WordSize>(instruction->GetEntrypoint()), true)); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3321 | |
| 3322 | DCHECK(!codegen_->IsLeafMethod()); |
| 3323 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3324 | } |
| 3325 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3326 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3327 | LocationSummary* locations = |
| 3328 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3329 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3330 | if (location.IsStackSlot()) { |
| 3331 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3332 | } else if (location.IsDoubleStackSlot()) { |
| 3333 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3334 | } |
| 3335 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3336 | } |
| 3337 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3338 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 3339 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3340 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3341 | } |
| 3342 | |
| 3343 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3344 | LocationSummary* locations = |
| 3345 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3346 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3347 | } |
| 3348 | |
| 3349 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 3350 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3351 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3352 | } |
| 3353 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3354 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3355 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3356 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3357 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3358 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3359 | } |
| 3360 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3361 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 3362 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3363 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 3364 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3365 | Location out = locations->Out(); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3366 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3367 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3368 | __ notl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3369 | break; |
| 3370 | |
| 3371 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3372 | __ notq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3373 | break; |
| 3374 | |
| 3375 | default: |
| 3376 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3377 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3378 | } |
| 3379 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3380 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3381 | LocationSummary* locations = |
| 3382 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3383 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3384 | locations->SetOut(Location::SameAsFirstInput()); |
| 3385 | } |
| 3386 | |
| 3387 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3388 | LocationSummary* locations = bool_not->GetLocations(); |
| 3389 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 3390 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 3391 | Location out = locations->Out(); |
| 3392 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 3393 | } |
| 3394 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3395 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3396 | LocationSummary* locations = |
| 3397 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3398 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 3399 | locations->SetInAt(i, Location::Any()); |
| 3400 | } |
| 3401 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3402 | } |
| 3403 | |
| 3404 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3405 | UNUSED(instruction); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3406 | LOG(FATAL) << "Unimplemented"; |
| 3407 | } |
| 3408 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3409 | void InstructionCodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3410 | /* |
| 3411 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 3412 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 3413 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 3414 | */ |
| 3415 | switch (kind) { |
| 3416 | case MemBarrierKind::kAnyAny: { |
| 3417 | __ mfence(); |
| 3418 | break; |
| 3419 | } |
| 3420 | case MemBarrierKind::kAnyStore: |
| 3421 | case MemBarrierKind::kLoadAny: |
| 3422 | case MemBarrierKind::kStoreStore: { |
| 3423 | // nop |
| 3424 | break; |
| 3425 | } |
| 3426 | default: |
| 3427 | LOG(FATAL) << "Unexpected memory barier " << kind; |
| 3428 | } |
| 3429 | } |
| 3430 | |
| 3431 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 3432 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 3433 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3434 | LocationSummary* locations = |
| 3435 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3436 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3437 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3438 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3439 | } else { |
| 3440 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3441 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3442 | } |
| 3443 | |
| 3444 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 3445 | const FieldInfo& field_info) { |
| 3446 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 3447 | |
| 3448 | LocationSummary* locations = instruction->GetLocations(); |
| 3449 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3450 | Location out = locations->Out(); |
| 3451 | bool is_volatile = field_info.IsVolatile(); |
| 3452 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3453 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3454 | |
| 3455 | switch (field_type) { |
| 3456 | case Primitive::kPrimBoolean: { |
| 3457 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3458 | break; |
| 3459 | } |
| 3460 | |
| 3461 | case Primitive::kPrimByte: { |
| 3462 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3463 | break; |
| 3464 | } |
| 3465 | |
| 3466 | case Primitive::kPrimShort: { |
| 3467 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3468 | break; |
| 3469 | } |
| 3470 | |
| 3471 | case Primitive::kPrimChar: { |
| 3472 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3473 | break; |
| 3474 | } |
| 3475 | |
| 3476 | case Primitive::kPrimInt: |
| 3477 | case Primitive::kPrimNot: { |
| 3478 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3479 | break; |
| 3480 | } |
| 3481 | |
| 3482 | case Primitive::kPrimLong: { |
| 3483 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3484 | break; |
| 3485 | } |
| 3486 | |
| 3487 | case Primitive::kPrimFloat: { |
| 3488 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 3489 | break; |
| 3490 | } |
| 3491 | |
| 3492 | case Primitive::kPrimDouble: { |
| 3493 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 3494 | break; |
| 3495 | } |
| 3496 | |
| 3497 | case Primitive::kPrimVoid: |
| 3498 | LOG(FATAL) << "Unreachable type " << field_type; |
| 3499 | UNREACHABLE(); |
| 3500 | } |
| 3501 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3502 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3503 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3504 | if (is_volatile) { |
| 3505 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 3506 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3507 | |
| 3508 | if (field_type == Primitive::kPrimNot) { |
| 3509 | __ MaybeUnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 3510 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3511 | } |
| 3512 | |
| 3513 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 3514 | const FieldInfo& field_info) { |
| 3515 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3516 | |
| 3517 | LocationSummary* locations = |
| 3518 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3519 | Primitive::Type field_type = field_info.GetFieldType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3520 | bool needs_write_barrier = |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3521 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3522 | |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3523 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3524 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
| 3525 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3526 | } else { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3527 | locations->SetInAt(1, Location::RegisterOrInt32LongConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3528 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3529 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3530 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3531 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3532 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3533 | } else if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 3534 | // Temporary register for the reference poisoning. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3535 | locations->AddTemp(Location::RequiresRegister()); |
| 3536 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3537 | } |
| 3538 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3539 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3540 | const FieldInfo& field_info, |
| 3541 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3542 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3543 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3544 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3545 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3546 | Location value = locations->InAt(1); |
| 3547 | bool is_volatile = field_info.IsVolatile(); |
| 3548 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3549 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3550 | |
| 3551 | if (is_volatile) { |
| 3552 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 3553 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3554 | |
| 3555 | switch (field_type) { |
| 3556 | case Primitive::kPrimBoolean: |
| 3557 | case Primitive::kPrimByte: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3558 | if (value.IsConstant()) { |
| 3559 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 3560 | __ movb(Address(base, offset), Immediate(v)); |
| 3561 | } else { |
| 3562 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3563 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3564 | break; |
| 3565 | } |
| 3566 | |
| 3567 | case Primitive::kPrimShort: |
| 3568 | case Primitive::kPrimChar: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3569 | if (value.IsConstant()) { |
| 3570 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 3571 | __ movw(Address(base, offset), Immediate(v)); |
| 3572 | } else { |
| 3573 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3574 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3575 | break; |
| 3576 | } |
| 3577 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3578 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3579 | case Primitive::kPrimNot: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3580 | if (value.IsConstant()) { |
| 3581 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3582 | // `field_type == Primitive::kPrimNot` implies `v == 0`. |
| 3583 | DCHECK((field_type != Primitive::kPrimNot) || (v == 0)); |
| 3584 | // Note: if heap poisoning is enabled, no need to poison |
| 3585 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 3586 | __ movl(Address(base, offset), Immediate(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3587 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3588 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 3589 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3590 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 3591 | __ PoisonHeapReference(temp); |
| 3592 | __ movl(Address(base, offset), temp); |
| 3593 | } else { |
| 3594 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3595 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3596 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3597 | break; |
| 3598 | } |
| 3599 | |
| 3600 | case Primitive::kPrimLong: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3601 | if (value.IsConstant()) { |
| 3602 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| 3603 | DCHECK(IsInt<32>(v)); |
| 3604 | int32_t v_32 = v; |
| 3605 | __ movq(Address(base, offset), Immediate(v_32)); |
| 3606 | } else { |
| 3607 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3608 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3609 | break; |
| 3610 | } |
| 3611 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3612 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3613 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3614 | break; |
| 3615 | } |
| 3616 | |
| 3617 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3618 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3619 | break; |
| 3620 | } |
| 3621 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3622 | case Primitive::kPrimVoid: |
| 3623 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3624 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3625 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3626 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3627 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3628 | |
| 3629 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 3630 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3631 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3632 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3633 | } |
| 3634 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3635 | if (is_volatile) { |
| 3636 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 3637 | } |
| 3638 | } |
| 3639 | |
| 3640 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 3641 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3642 | } |
| 3643 | |
| 3644 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3645 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3646 | } |
| 3647 | |
| 3648 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3649 | HandleFieldGet(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3650 | } |
| 3651 | |
| 3652 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3653 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3654 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3655 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3656 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3657 | HandleFieldGet(instruction); |
| 3658 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3659 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3660 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3661 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3662 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3663 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3664 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3665 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3666 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3667 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3668 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3669 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3670 | } |
| 3671 | |
| 3672 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3673 | LocationSummary* locations = |
| 3674 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3675 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 3676 | ? Location::RequiresRegister() |
| 3677 | : Location::Any(); |
| 3678 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3679 | if (instruction->HasUses()) { |
| 3680 | locations->SetOut(Location::SameAsFirstInput()); |
| 3681 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3682 | } |
| 3683 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3684 | void InstructionCodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3685 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 3686 | return; |
| 3687 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3688 | LocationSummary* locations = instruction->GetLocations(); |
| 3689 | Location obj = locations->InAt(0); |
| 3690 | |
| 3691 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
| 3692 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3693 | } |
| 3694 | |
| 3695 | void InstructionCodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 3696 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3697 | codegen_->AddSlowPath(slow_path); |
| 3698 | |
| 3699 | LocationSummary* locations = instruction->GetLocations(); |
| 3700 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3701 | |
| 3702 | if (obj.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3703 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3704 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3705 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3706 | } else { |
| 3707 | DCHECK(obj.IsConstant()) << obj; |
| 3708 | DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0); |
| 3709 | __ jmp(slow_path->GetEntryLabel()); |
| 3710 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3711 | } |
| 3712 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3713 | } |
| 3714 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3715 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
| 3716 | if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) { |
| 3717 | GenerateImplicitNullCheck(instruction); |
| 3718 | } else { |
| 3719 | GenerateExplicitNullCheck(instruction); |
| 3720 | } |
| 3721 | } |
| 3722 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3723 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3724 | LocationSummary* locations = |
| 3725 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3726 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3727 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3728 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3729 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3730 | } else { |
| 3731 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3732 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3733 | } |
| 3734 | |
| 3735 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 3736 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3737 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3738 | Location index = locations->InAt(1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3739 | Primitive::Type type = instruction->GetType(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3740 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3741 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3742 | case Primitive::kPrimBoolean: { |
| 3743 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3744 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3745 | if (index.IsConstant()) { |
| 3746 | __ movzxb(out, Address(obj, |
| 3747 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 3748 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3749 | __ movzxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3750 | } |
| 3751 | break; |
| 3752 | } |
| 3753 | |
| 3754 | case Primitive::kPrimByte: { |
| 3755 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3756 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3757 | if (index.IsConstant()) { |
| 3758 | __ movsxb(out, Address(obj, |
| 3759 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 3760 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3761 | __ movsxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3762 | } |
| 3763 | break; |
| 3764 | } |
| 3765 | |
| 3766 | case Primitive::kPrimShort: { |
| 3767 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3768 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3769 | if (index.IsConstant()) { |
| 3770 | __ movsxw(out, Address(obj, |
| 3771 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 3772 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3773 | __ movsxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3774 | } |
| 3775 | break; |
| 3776 | } |
| 3777 | |
| 3778 | case Primitive::kPrimChar: { |
| 3779 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3780 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3781 | if (index.IsConstant()) { |
| 3782 | __ movzxw(out, Address(obj, |
| 3783 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 3784 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3785 | __ movzxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3786 | } |
| 3787 | break; |
| 3788 | } |
| 3789 | |
| 3790 | case Primitive::kPrimInt: |
| 3791 | case Primitive::kPrimNot: { |
Roland Levillain | 33d6903 | 2015-06-18 18:20:59 +0100 | [diff] [blame] | 3792 | static_assert(sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 3793 | "art::mirror::HeapReference<mirror::Object> and int32_t have different sizes."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3794 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3795 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3796 | if (index.IsConstant()) { |
| 3797 | __ movl(out, Address(obj, |
| 3798 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 3799 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3800 | __ movl(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3801 | } |
| 3802 | break; |
| 3803 | } |
| 3804 | |
| 3805 | case Primitive::kPrimLong: { |
| 3806 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3807 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3808 | if (index.IsConstant()) { |
| 3809 | __ movq(out, Address(obj, |
| 3810 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 3811 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3812 | __ movq(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3813 | } |
| 3814 | break; |
| 3815 | } |
| 3816 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3817 | case Primitive::kPrimFloat: { |
| 3818 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3819 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3820 | if (index.IsConstant()) { |
| 3821 | __ movss(out, Address(obj, |
| 3822 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 3823 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3824 | __ movss(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3825 | } |
| 3826 | break; |
| 3827 | } |
| 3828 | |
| 3829 | case Primitive::kPrimDouble: { |
| 3830 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3831 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3832 | if (index.IsConstant()) { |
| 3833 | __ movsd(out, Address(obj, |
| 3834 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 3835 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3836 | __ movsd(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3837 | } |
| 3838 | break; |
| 3839 | } |
| 3840 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3841 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3842 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3843 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3844 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3845 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3846 | |
| 3847 | if (type == Primitive::kPrimNot) { |
| 3848 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3849 | __ MaybeUnpoisonHeapReference(out); |
| 3850 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3851 | } |
| 3852 | |
| 3853 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3854 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3855 | |
| 3856 | bool needs_write_barrier = |
| 3857 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 3858 | bool needs_runtime_call = instruction->NeedsTypeCheck(); |
| 3859 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3860 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3861 | instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 3862 | if (needs_runtime_call) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3863 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3864 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3865 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3866 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3867 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3868 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3869 | locations->SetInAt( |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3870 | 1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 3871 | locations->SetInAt(2, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3872 | if (value_type == Primitive::kPrimLong) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3873 | locations->SetInAt(2, Location::RegisterOrInt32LongConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3874 | } else if (value_type == Primitive::kPrimFloat || value_type == Primitive::kPrimDouble) { |
| 3875 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3876 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3877 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3878 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3879 | |
| 3880 | if (needs_write_barrier) { |
| 3881 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3882 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3883 | locations->AddTemp(Location::RequiresRegister()); |
| 3884 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3885 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3886 | } |
| 3887 | |
| 3888 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 3889 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3890 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3891 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3892 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3893 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3894 | bool needs_runtime_call = locations->WillCall(); |
| 3895 | bool needs_write_barrier = |
| 3896 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3897 | |
| 3898 | switch (value_type) { |
| 3899 | case Primitive::kPrimBoolean: |
| 3900 | case Primitive::kPrimByte: { |
| 3901 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3902 | if (index.IsConstant()) { |
| 3903 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3904 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3905 | __ movb(Address(obj, offset), value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3906 | } else { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3907 | __ movb(Address(obj, offset), |
| 3908 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3909 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3910 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3911 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3912 | __ movb(Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset), |
| 3913 | value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3914 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3915 | __ movb(Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3916 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 3917 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3918 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3919 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3920 | break; |
| 3921 | } |
| 3922 | |
| 3923 | case Primitive::kPrimShort: |
| 3924 | case Primitive::kPrimChar: { |
| 3925 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3926 | if (index.IsConstant()) { |
| 3927 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3928 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3929 | __ movw(Address(obj, offset), value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3930 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3931 | DCHECK(value.IsConstant()) << value; |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3932 | __ movw(Address(obj, offset), |
| 3933 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3934 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3935 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3936 | DCHECK(index.IsRegister()) << index; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3937 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3938 | __ movw(Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset), |
| 3939 | value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3940 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3941 | DCHECK(value.IsConstant()) << value; |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3942 | __ movw(Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3943 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 3944 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3945 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3946 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3947 | break; |
| 3948 | } |
| 3949 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3950 | case Primitive::kPrimInt: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3951 | case Primitive::kPrimNot: { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3952 | if (!needs_runtime_call) { |
| 3953 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 3954 | if (index.IsConstant()) { |
| 3955 | size_t offset = |
| 3956 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 3957 | if (value.IsRegister()) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3958 | if (kPoisonHeapReferences && value_type == Primitive::kPrimNot) { |
| 3959 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3960 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 3961 | __ PoisonHeapReference(temp); |
| 3962 | __ movl(Address(obj, offset), temp); |
| 3963 | } else { |
| 3964 | __ movl(Address(obj, offset), value.AsRegister<CpuRegister>()); |
| 3965 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3966 | } else { |
| 3967 | DCHECK(value.IsConstant()) << value; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3968 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3969 | // `value_type == Primitive::kPrimNot` implies `v == 0`. |
| 3970 | DCHECK((value_type != Primitive::kPrimNot) || (v == 0)); |
| 3971 | // Note: if heap poisoning is enabled, no need to poison |
| 3972 | // (negate) `v` if it is a reference, as it would be null. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3973 | __ movl(Address(obj, offset), Immediate(v)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3974 | } |
| 3975 | } else { |
| 3976 | DCHECK(index.IsRegister()) << index; |
| 3977 | if (value.IsRegister()) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3978 | if (kPoisonHeapReferences && value_type == Primitive::kPrimNot) { |
| 3979 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3980 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 3981 | __ PoisonHeapReference(temp); |
| 3982 | __ movl(Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset), temp); |
| 3983 | } else { |
| 3984 | __ movl(Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset), |
| 3985 | value.AsRegister<CpuRegister>()); |
| 3986 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3987 | } else { |
| 3988 | DCHECK(value.IsConstant()) << value; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3989 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3990 | // `value_type == Primitive::kPrimNot` implies `v == 0`. |
| 3991 | DCHECK((value_type != Primitive::kPrimNot) || (v == 0)); |
| 3992 | // Note: if heap poisoning is enabled, no need to poison |
| 3993 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3994 | __ movl(Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset), |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3995 | Immediate(v)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3996 | } |
| 3997 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3998 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3999 | if (needs_write_barrier) { |
| 4000 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4001 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4002 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4003 | codegen_->MarkGCCard( |
| 4004 | temp, card, obj, value.AsRegister<CpuRegister>(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4005 | } |
| 4006 | } else { |
| 4007 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4008 | // Note: if heap poisoning is enabled, pAputObject takes cares |
| 4009 | // of poisoning the reference. |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4010 | __ gs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pAputObject), |
| 4011 | true)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4012 | DCHECK(!codegen_->IsLeafMethod()); |
| 4013 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4014 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4015 | break; |
| 4016 | } |
| 4017 | |
| 4018 | case Primitive::kPrimLong: { |
| 4019 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4020 | if (index.IsConstant()) { |
| 4021 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4022 | if (value.IsRegister()) { |
| 4023 | __ movq(Address(obj, offset), value.AsRegister<CpuRegister>()); |
| 4024 | } else { |
| 4025 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| 4026 | DCHECK(IsInt<32>(v)); |
| 4027 | int32_t v_32 = v; |
| 4028 | __ movq(Address(obj, offset), Immediate(v_32)); |
| 4029 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4030 | } else { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4031 | if (value.IsRegister()) { |
| 4032 | __ movq(Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset), |
| 4033 | value.AsRegister<CpuRegister>()); |
| 4034 | } else { |
| 4035 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| 4036 | DCHECK(IsInt<32>(v)); |
| 4037 | int32_t v_32 = v; |
| 4038 | __ movq(Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset), |
| 4039 | Immediate(v_32)); |
| 4040 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4041 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4042 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4043 | break; |
| 4044 | } |
| 4045 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4046 | case Primitive::kPrimFloat: { |
| 4047 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4048 | if (index.IsConstant()) { |
| 4049 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4050 | DCHECK(value.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4051 | __ movss(Address(obj, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4052 | } else { |
| 4053 | DCHECK(value.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4054 | __ movss(Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset), |
| 4055 | value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4056 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4057 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4058 | break; |
| 4059 | } |
| 4060 | |
| 4061 | case Primitive::kPrimDouble: { |
| 4062 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4063 | if (index.IsConstant()) { |
| 4064 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 4065 | DCHECK(value.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4066 | __ movsd(Address(obj, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4067 | } else { |
| 4068 | DCHECK(value.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4069 | __ movsd(Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset), |
| 4070 | value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4071 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4072 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4073 | break; |
| 4074 | } |
| 4075 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4076 | case Primitive::kPrimVoid: |
| 4077 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4078 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4079 | } |
| 4080 | } |
| 4081 | |
| 4082 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4083 | LocationSummary* locations = |
| 4084 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4085 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4086 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4087 | } |
| 4088 | |
| 4089 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
| 4090 | LocationSummary* locations = instruction->GetLocations(); |
| 4091 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4092 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4093 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4094 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4095 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4096 | } |
| 4097 | |
| 4098 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4099 | LocationSummary* locations = |
| 4100 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4101 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4102 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4103 | if (instruction->HasUses()) { |
| 4104 | locations->SetOut(Location::SameAsFirstInput()); |
| 4105 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4106 | } |
| 4107 | |
| 4108 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4109 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4110 | Location index_loc = locations->InAt(0); |
| 4111 | Location length_loc = locations->InAt(1); |
| 4112 | SlowPathCodeX86_64* slow_path = |
| 4113 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64(instruction, index_loc, length_loc); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4114 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4115 | if (length_loc.IsConstant()) { |
| 4116 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 4117 | if (index_loc.IsConstant()) { |
| 4118 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 4119 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4120 | if (index < 0 || index >= length) { |
| 4121 | codegen_->AddSlowPath(slow_path); |
| 4122 | __ jmp(slow_path->GetEntryLabel()); |
| 4123 | } else { |
| 4124 | // Some optimization after BCE may have generated this, and we should not |
| 4125 | // generate a bounds check if it is a valid range. |
| 4126 | } |
| 4127 | return; |
| 4128 | } |
| 4129 | |
| 4130 | // We have to reverse the jump condition because the length is the constant. |
| 4131 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 4132 | __ cmpl(index_reg, Immediate(length)); |
| 4133 | codegen_->AddSlowPath(slow_path); |
| 4134 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4135 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4136 | CpuRegister length = length_loc.AsRegister<CpuRegister>(); |
| 4137 | if (index_loc.IsConstant()) { |
| 4138 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4139 | __ cmpl(length, Immediate(value)); |
| 4140 | } else { |
| 4141 | __ cmpl(length, index_loc.AsRegister<CpuRegister>()); |
| 4142 | } |
| 4143 | codegen_->AddSlowPath(slow_path); |
| 4144 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4145 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4146 | } |
| 4147 | |
| 4148 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 4149 | CpuRegister card, |
| 4150 | CpuRegister object, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4151 | CpuRegister value, |
| 4152 | bool value_can_be_null) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4153 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4154 | if (value_can_be_null) { |
| 4155 | __ testl(value, value); |
| 4156 | __ j(kEqual, &is_null); |
| 4157 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4158 | __ gs()->movq(card, Address::Absolute( |
| 4159 | Thread::CardTableOffset<kX86_64WordSize>().Int32Value(), true)); |
| 4160 | __ movq(temp, object); |
| 4161 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4162 | __ movb(Address(temp, card, TIMES_1, 0), card); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4163 | if (value_can_be_null) { |
| 4164 | __ Bind(&is_null); |
| 4165 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4166 | } |
| 4167 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4168 | void LocationsBuilderX86_64::VisitTemporary(HTemporary* temp) { |
| 4169 | temp->SetLocations(nullptr); |
| 4170 | } |
| 4171 | |
| 4172 | void InstructionCodeGeneratorX86_64::VisitTemporary(HTemporary* temp) { |
| 4173 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4174 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4175 | } |
| 4176 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4177 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4178 | UNUSED(instruction); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4179 | LOG(FATAL) << "Unimplemented"; |
| 4180 | } |
| 4181 | |
| 4182 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4183 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4184 | } |
| 4185 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4186 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4187 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4188 | } |
| 4189 | |
| 4190 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4191 | HBasicBlock* block = instruction->GetBlock(); |
| 4192 | if (block->GetLoopInformation() != nullptr) { |
| 4193 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4194 | // The back edge will generate the suspend check. |
| 4195 | return; |
| 4196 | } |
| 4197 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4198 | // The goto will generate the suspend check. |
| 4199 | return; |
| 4200 | } |
| 4201 | GenerateSuspendCheck(instruction, nullptr); |
| 4202 | } |
| 4203 | |
| 4204 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 4205 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4206 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4207 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 4208 | if (slow_path == nullptr) { |
| 4209 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
| 4210 | instruction->SetSlowPath(slow_path); |
| 4211 | codegen_->AddSlowPath(slow_path); |
| 4212 | if (successor != nullptr) { |
| 4213 | DCHECK(successor->IsLoopHeader()); |
| 4214 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 4215 | } |
| 4216 | } else { |
| 4217 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 4218 | } |
| 4219 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4220 | __ gs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4221 | Thread::ThreadFlagsOffset<kX86_64WordSize>().Int32Value(), true), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4222 | if (successor == nullptr) { |
| 4223 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4224 | __ Bind(slow_path->GetReturnLabel()); |
| 4225 | } else { |
| 4226 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 4227 | __ jmp(slow_path->GetEntryLabel()); |
| 4228 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4229 | } |
| 4230 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4231 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 4232 | return codegen_->GetAssembler(); |
| 4233 | } |
| 4234 | |
| 4235 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
| 4236 | MoveOperands* move = moves_.Get(index); |
| 4237 | Location source = move->GetSource(); |
| 4238 | Location destination = move->GetDestination(); |
| 4239 | |
| 4240 | if (source.IsRegister()) { |
| 4241 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4242 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4243 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4244 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4245 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4246 | } else { |
| 4247 | DCHECK(destination.IsDoubleStackSlot()); |
| 4248 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4249 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4250 | } |
| 4251 | } else if (source.IsStackSlot()) { |
| 4252 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4253 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4254 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4255 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4256 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4257 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4258 | } else { |
| 4259 | DCHECK(destination.IsStackSlot()); |
| 4260 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 4261 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 4262 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4263 | } else if (source.IsDoubleStackSlot()) { |
| 4264 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4265 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4266 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4267 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4268 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 4269 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4270 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 4271 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4272 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 4273 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 4274 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4275 | } else if (source.IsConstant()) { |
| 4276 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4277 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 4278 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4279 | if (destination.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4280 | if (value == 0) { |
| 4281 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 4282 | } else { |
| 4283 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 4284 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4285 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4286 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4287 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4288 | } |
| 4289 | } else if (constant->IsLongConstant()) { |
| 4290 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 4291 | if (destination.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4292 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4293 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4294 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4295 | codegen_->Load64BitValue(CpuRegister(TMP), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4296 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 4297 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4298 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4299 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4300 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4301 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4302 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4303 | if (value == 0) { |
| 4304 | // easy FP 0.0. |
| 4305 | __ xorps(dest, dest); |
| 4306 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4307 | __ movss(dest, codegen_->LiteralFloatAddress(fp_value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4308 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4309 | } else { |
| 4310 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4311 | Immediate imm(value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4312 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 4313 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4314 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4315 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4316 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4317 | int64_t value = bit_cast<int64_t, double>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4318 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4319 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4320 | if (value == 0) { |
| 4321 | __ xorpd(dest, dest); |
| 4322 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4323 | __ movsd(dest, codegen_->LiteralDoubleAddress(fp_value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4324 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4325 | } else { |
| 4326 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4327 | codegen_->Load64BitValue(CpuRegister(TMP), value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4328 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 4329 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4330 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4331 | } else if (source.IsFpuRegister()) { |
| 4332 | if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4333 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4334 | } else if (destination.IsStackSlot()) { |
| 4335 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4336 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4337 | } else { |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 4338 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4339 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4340 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4341 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4342 | } |
| 4343 | } |
| 4344 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4345 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4346 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4347 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 4348 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4349 | } |
| 4350 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4351 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4352 | ScratchRegisterScope ensure_scratch( |
| 4353 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 4354 | |
| 4355 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 4356 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 4357 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 4358 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 4359 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 4360 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 4361 | CpuRegister(ensure_scratch.GetRegister())); |
| 4362 | } |
| 4363 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4364 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 4365 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 4366 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 4367 | __ movq(reg, CpuRegister(TMP)); |
| 4368 | } |
| 4369 | |
| 4370 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 4371 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4372 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4373 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4374 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 4375 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 4376 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 4377 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 4378 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 4379 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 4380 | CpuRegister(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4381 | } |
| 4382 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4383 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 4384 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 4385 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 4386 | __ movd(reg, CpuRegister(TMP)); |
| 4387 | } |
| 4388 | |
| 4389 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 4390 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 4391 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 4392 | __ movd(reg, CpuRegister(TMP)); |
| 4393 | } |
| 4394 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4395 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
| 4396 | MoveOperands* move = moves_.Get(index); |
| 4397 | Location source = move->GetSource(); |
| 4398 | Location destination = move->GetDestination(); |
| 4399 | |
| 4400 | if (source.IsRegister() && destination.IsRegister()) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4401 | __ xchgq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4402 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4403 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4404 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4405 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4406 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4407 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 4408 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4409 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4410 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4411 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4412 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 4413 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4414 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4415 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 4416 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 4417 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4418 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4419 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4420 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4421 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4422 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4423 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4424 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4425 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4426 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4427 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4428 | } |
| 4429 | } |
| 4430 | |
| 4431 | |
| 4432 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 4433 | __ pushq(CpuRegister(reg)); |
| 4434 | } |
| 4435 | |
| 4436 | |
| 4437 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 4438 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4439 | } |
| 4440 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4441 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
| 4442 | SlowPathCodeX86_64* slow_path, CpuRegister class_reg) { |
| 4443 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 4444 | Immediate(mirror::Class::kStatusInitialized)); |
| 4445 | __ j(kLess, slow_path->GetEntryLabel()); |
| 4446 | __ Bind(slow_path->GetExitLabel()); |
| 4447 | // No need for memory fence, thanks to the X86_64 memory model. |
| 4448 | } |
| 4449 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4450 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4451 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() |
| 4452 | ? LocationSummary::kCallOnSlowPath |
| 4453 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4454 | LocationSummary* locations = |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4455 | new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4456 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4457 | locations->SetOut(Location::RequiresRegister()); |
| 4458 | } |
| 4459 | |
| 4460 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4461 | LocationSummary* locations = cls->GetLocations(); |
| 4462 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4463 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4464 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4465 | DCHECK(!cls->CanCallRuntime()); |
| 4466 | DCHECK(!cls->MustGenerateClinitCheck()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4467 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4468 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4469 | DCHECK(cls->CanCallRuntime()); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4470 | __ movl(out, Address( |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4471 | current_method, ArtMethod::DexCacheResolvedTypesOffset().Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4472 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4473 | __ MaybeUnpoisonHeapReference(out); |
| 4474 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4475 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 4476 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 4477 | codegen_->AddSlowPath(slow_path); |
| 4478 | __ testl(out, out); |
| 4479 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4480 | if (cls->MustGenerateClinitCheck()) { |
| 4481 | GenerateClassInitializationCheck(slow_path, out); |
| 4482 | } else { |
| 4483 | __ Bind(slow_path->GetExitLabel()); |
| 4484 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4485 | } |
| 4486 | } |
| 4487 | |
| 4488 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 4489 | LocationSummary* locations = |
| 4490 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 4491 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4492 | if (check->HasUses()) { |
| 4493 | locations->SetOut(Location::SameAsFirstInput()); |
| 4494 | } |
| 4495 | } |
| 4496 | |
| 4497 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4498 | // We assume the class to not be null. |
| 4499 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 4500 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4501 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4502 | GenerateClassInitializationCheck(slow_path, |
| 4503 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4504 | } |
| 4505 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4506 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
| 4507 | LocationSummary* locations = |
| 4508 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4509 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4510 | locations->SetOut(Location::RequiresRegister()); |
| 4511 | } |
| 4512 | |
| 4513 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) { |
| 4514 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86_64(load); |
| 4515 | codegen_->AddSlowPath(slow_path); |
| 4516 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4517 | LocationSummary* locations = load->GetLocations(); |
| 4518 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4519 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4520 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 4521 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4522 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4523 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4524 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4525 | __ testl(out, out); |
| 4526 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4527 | __ Bind(slow_path->GetExitLabel()); |
| 4528 | } |
| 4529 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4530 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 4531 | LocationSummary* locations = |
| 4532 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 4533 | locations->SetOut(Location::RequiresRegister()); |
| 4534 | } |
| 4535 | |
| 4536 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
| 4537 | Address address = Address::Absolute( |
| 4538 | Thread::ExceptionOffset<kX86_64WordSize>().Int32Value(), true); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4539 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4540 | __ gs()->movl(address, Immediate(0)); |
| 4541 | } |
| 4542 | |
| 4543 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| 4544 | LocationSummary* locations = |
| 4545 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4546 | InvokeRuntimeCallingConvention calling_convention; |
| 4547 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4548 | } |
| 4549 | |
| 4550 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
| 4551 | __ gs()->call( |
| 4552 | Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pDeliverException), true)); |
| 4553 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4554 | } |
| 4555 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4556 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4557 | LocationSummary::CallKind call_kind = instruction->IsClassFinal() |
| 4558 | ? LocationSummary::kNoCall |
| 4559 | : LocationSummary::kCallOnSlowPath; |
| 4560 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4561 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4562 | locations->SetInAt(1, Location::Any()); |
| 4563 | locations->SetOut(Location::RequiresRegister()); |
| 4564 | } |
| 4565 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4566 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4567 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4568 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4569 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4570 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4571 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4572 | Label done, zero; |
| 4573 | SlowPathCodeX86_64* slow_path = nullptr; |
| 4574 | |
| 4575 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4576 | // Avoid null check if we know obj is not null. |
| 4577 | if (instruction->MustDoNullCheck()) { |
| 4578 | __ testl(obj, obj); |
| 4579 | __ j(kEqual, &zero); |
| 4580 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4581 | // Compare the class of `obj` with `cls`. |
| 4582 | __ movl(out, Address(obj, class_offset)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4583 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4584 | if (cls.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4585 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4586 | } else { |
| 4587 | DCHECK(cls.IsStackSlot()) << cls; |
| 4588 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 4589 | } |
| 4590 | if (instruction->IsClassFinal()) { |
| 4591 | // Classes must be equal for the instanceof to succeed. |
| 4592 | __ j(kNotEqual, &zero); |
| 4593 | __ movl(out, Immediate(1)); |
| 4594 | __ jmp(&done); |
| 4595 | } else { |
| 4596 | // If the classes are not equal, we go into a slow path. |
| 4597 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 4598 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64( |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4599 | instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4600 | codegen_->AddSlowPath(slow_path); |
| 4601 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4602 | __ movl(out, Immediate(1)); |
| 4603 | __ jmp(&done); |
| 4604 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4605 | |
| 4606 | if (instruction->MustDoNullCheck() || instruction->IsClassFinal()) { |
| 4607 | __ Bind(&zero); |
| 4608 | __ movl(out, Immediate(0)); |
| 4609 | } |
| 4610 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4611 | if (slow_path != nullptr) { |
| 4612 | __ Bind(slow_path->GetExitLabel()); |
| 4613 | } |
| 4614 | __ Bind(&done); |
| 4615 | } |
| 4616 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4617 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
| 4618 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 4619 | instruction, LocationSummary::kCallOnSlowPath); |
| 4620 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4621 | locations->SetInAt(1, Location::Any()); |
| 4622 | locations->AddTemp(Location::RequiresRegister()); |
| 4623 | } |
| 4624 | |
| 4625 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
| 4626 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4627 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4628 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4629 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4630 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4631 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64( |
| 4632 | instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc()); |
| 4633 | codegen_->AddSlowPath(slow_path); |
| 4634 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4635 | // Avoid null check if we know obj is not null. |
| 4636 | if (instruction->MustDoNullCheck()) { |
| 4637 | __ testl(obj, obj); |
| 4638 | __ j(kEqual, slow_path->GetExitLabel()); |
| 4639 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4640 | // Compare the class of `obj` with `cls`. |
| 4641 | __ movl(temp, Address(obj, class_offset)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4642 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4643 | if (cls.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4644 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4645 | } else { |
| 4646 | DCHECK(cls.IsStackSlot()) << cls; |
| 4647 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 4648 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4649 | // The checkcast succeeds if the classes are equal (fast path). |
| 4650 | // Otherwise, we need to go into the slow path to check the types. |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4651 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4652 | __ Bind(slow_path->GetExitLabel()); |
| 4653 | } |
| 4654 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4655 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4656 | LocationSummary* locations = |
| 4657 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4658 | InvokeRuntimeCallingConvention calling_convention; |
| 4659 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4660 | } |
| 4661 | |
| 4662 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4663 | __ gs()->call(Address::Absolute(instruction->IsEnter() |
| 4664 | ? QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pLockObject) |
| 4665 | : QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, pUnlockObject), |
| 4666 | true)); |
| 4667 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4668 | } |
| 4669 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4670 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 4671 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 4672 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 4673 | |
| 4674 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 4675 | LocationSummary* locations = |
| 4676 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4677 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 4678 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 4679 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4680 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4681 | locations->SetOut(Location::SameAsFirstInput()); |
| 4682 | } |
| 4683 | |
| 4684 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 4685 | HandleBitwiseOperation(instruction); |
| 4686 | } |
| 4687 | |
| 4688 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 4689 | HandleBitwiseOperation(instruction); |
| 4690 | } |
| 4691 | |
| 4692 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 4693 | HandleBitwiseOperation(instruction); |
| 4694 | } |
| 4695 | |
| 4696 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 4697 | LocationSummary* locations = instruction->GetLocations(); |
| 4698 | Location first = locations->InAt(0); |
| 4699 | Location second = locations->InAt(1); |
| 4700 | DCHECK(first.Equals(locations->Out())); |
| 4701 | |
| 4702 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 4703 | if (second.IsRegister()) { |
| 4704 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4705 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4706 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4707 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4708 | } else { |
| 4709 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4710 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4711 | } |
| 4712 | } else if (second.IsConstant()) { |
| 4713 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 4714 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4715 | __ andl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4716 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4717 | __ orl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4718 | } else { |
| 4719 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4720 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4721 | } |
| 4722 | } else { |
| 4723 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 4724 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4725 | __ andl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4726 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4727 | __ orl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4728 | } else { |
| 4729 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4730 | __ xorl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4731 | } |
| 4732 | } |
| 4733 | } else { |
| 4734 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4735 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 4736 | bool second_is_constant = false; |
| 4737 | int64_t value = 0; |
| 4738 | if (second.IsConstant()) { |
| 4739 | second_is_constant = true; |
| 4740 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4741 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4742 | bool is_int32_value = IsInt<32>(value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4743 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4744 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4745 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4746 | if (is_int32_value) { |
| 4747 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 4748 | } else { |
| 4749 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 4750 | } |
| 4751 | } else if (second.IsDoubleStackSlot()) { |
| 4752 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4753 | } else { |
| 4754 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 4755 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4756 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4757 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4758 | if (is_int32_value) { |
| 4759 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 4760 | } else { |
| 4761 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 4762 | } |
| 4763 | } else if (second.IsDoubleStackSlot()) { |
| 4764 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4765 | } else { |
| 4766 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 4767 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4768 | } else { |
| 4769 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4770 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4771 | if (is_int32_value) { |
| 4772 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 4773 | } else { |
| 4774 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 4775 | } |
| 4776 | } else if (second.IsDoubleStackSlot()) { |
| 4777 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4778 | } else { |
| 4779 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 4780 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4781 | } |
| 4782 | } |
| 4783 | } |
| 4784 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4785 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction) { |
| 4786 | // Nothing to do, this should be removed during prepare for register allocator. |
| 4787 | UNUSED(instruction); |
| 4788 | LOG(FATAL) << "Unreachable"; |
| 4789 | } |
| 4790 | |
| 4791 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction) { |
| 4792 | // Nothing to do, this should be removed during prepare for register allocator. |
| 4793 | UNUSED(instruction); |
| 4794 | LOG(FATAL) << "Unreachable"; |
| 4795 | } |
| 4796 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 4797 | void LocationsBuilderX86_64::VisitFakeString(HFakeString* instruction) { |
| 4798 | DCHECK(codegen_->IsBaseline()); |
| 4799 | LocationSummary* locations = |
| 4800 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4801 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); |
| 4802 | } |
| 4803 | |
| 4804 | void InstructionCodeGeneratorX86_64::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { |
| 4805 | DCHECK(codegen_->IsBaseline()); |
| 4806 | // Will be generated at use site. |
| 4807 | } |
| 4808 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4809 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 4810 | if (value == 0) { |
| 4811 | __ xorl(dest, dest); |
| 4812 | } else if (value > 0 && IsInt<32>(value)) { |
| 4813 | // We can use a 32 bit move, as it will zero-extend and is one byte shorter. |
| 4814 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 4815 | } else { |
| 4816 | __ movq(dest, Immediate(value)); |
| 4817 | } |
| 4818 | } |
| 4819 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4820 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 4821 | // Generate the constant area if needed. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 4822 | X86_64Assembler* assembler = GetAssembler(); |
| 4823 | if (!assembler->IsConstantAreaEmpty()) { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4824 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 4825 | // byte values. If used for vectors at a later time, this will need to be |
| 4826 | // updated to 16 bytes with the appropriate offset. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 4827 | assembler->Align(4, 0); |
| 4828 | constant_area_start_ = assembler->CodeSize(); |
| 4829 | assembler->AddConstantArea(); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4830 | } |
| 4831 | |
| 4832 | // And finish up. |
| 4833 | CodeGenerator::Finalize(allocator); |
| 4834 | } |
| 4835 | |
| 4836 | /** |
| 4837 | * Class to handle late fixup of offsets into constant area. |
| 4838 | */ |
| 4839 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocMisc> { |
| 4840 | public: |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 4841 | RIPFixup(const CodeGeneratorX86_64& codegen, int offset) |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4842 | : codegen_(codegen), offset_into_constant_area_(offset) {} |
| 4843 | |
| 4844 | private: |
| 4845 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 4846 | // Patch the correct offset for the instruction. We use the address of the |
| 4847 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 4848 | int constant_offset = codegen_.ConstantAreaStart() + offset_into_constant_area_; |
| 4849 | int relative_position = constant_offset - pos; |
| 4850 | |
| 4851 | // Patch in the right value. |
| 4852 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 4853 | } |
| 4854 | |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 4855 | const CodeGeneratorX86_64& codegen_; |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4856 | |
| 4857 | // Location in constant area that the fixup refers to. |
| 4858 | int offset_into_constant_area_; |
| 4859 | }; |
| 4860 | |
| 4861 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
| 4862 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 4863 | return Address::RIP(fixup); |
| 4864 | } |
| 4865 | |
| 4866 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
| 4867 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 4868 | return Address::RIP(fixup); |
| 4869 | } |
| 4870 | |
| 4871 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
| 4872 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 4873 | return Address::RIP(fixup); |
| 4874 | } |
| 4875 | |
| 4876 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
| 4877 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 4878 | return Address::RIP(fixup); |
| 4879 | } |
| 4880 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4881 | #undef __ |
| 4882 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4883 | } // namespace x86_64 |
| 4884 | } // namespace art |