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