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