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" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 21 | #include "compiled_method.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 22 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 23 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 24 | #include "intrinsics.h" |
| 25 | #include "intrinsics_x86_64.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 26 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 27 | #include "mirror/class-inl.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 28 | #include "mirror/object_reference.h" |
| 29 | #include "thread.h" |
| 30 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 31 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 32 | #include "utils/x86_64/assembler_x86_64.h" |
| 33 | #include "utils/x86_64/managed_register_x86_64.h" |
| 34 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 35 | namespace art { |
| 36 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 37 | template<class MirrorType> |
| 38 | class GcRoot; |
| 39 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 40 | namespace x86_64 { |
| 41 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 42 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 43 | static constexpr Register kMethodRegisterArgument = RDI; |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 44 | // The compare/jump sequence will generate about (1.5 * num_entries) instructions. A jump |
| 45 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 46 | // generates less code/data with a small num_entries. |
| 47 | static constexpr uint32_t kPackedSwitchJumpTableThreshold = 5; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 48 | |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 49 | static constexpr Register kCoreCalleeSaves[] = { RBX, RBP, R12, R13, R14, R15 }; |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 50 | static constexpr FloatRegister kFpuCalleeSaves[] = { XMM12, XMM13, XMM14, XMM15 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 51 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 52 | static constexpr int kC2ConditionMask = 0x400; |
| 53 | |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 54 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 55 | #define __ down_cast<X86_64Assembler*>(codegen->GetAssembler())-> // NOLINT |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 56 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86_64PointerSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 57 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 58 | class NullCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 59 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 60 | explicit NullCheckSlowPathX86_64(HNullCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 61 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 62 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 63 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 64 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 65 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 66 | // Live registers will be restored in the catch block if caught. |
| 67 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 68 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame^] | 69 | x86_64_codegen->InvokeRuntime(kQuickThrowNullPointer, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 70 | instruction_, |
| 71 | instruction_->GetDexPc(), |
| 72 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 73 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 74 | } |
| 75 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 76 | bool IsFatal() const OVERRIDE { return true; } |
| 77 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 78 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86_64"; } |
| 79 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 80 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 81 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86_64); |
| 82 | }; |
| 83 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 84 | class DivZeroCheckSlowPathX86_64 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 85 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 86 | explicit DivZeroCheckSlowPathX86_64(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 87 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 88 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 89 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 90 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 91 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 92 | // Live registers will be restored in the catch block if caught. |
| 93 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 94 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame^] | 95 | x86_64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 96 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 99 | bool IsFatal() const OVERRIDE { return true; } |
| 100 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 101 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86_64"; } |
| 102 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 103 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 104 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86_64); |
| 105 | }; |
| 106 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 107 | class DivRemMinusOneSlowPathX86_64 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 108 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 109 | DivRemMinusOneSlowPathX86_64(HInstruction* at, Register reg, Primitive::Type type, bool is_div) |
| 110 | : SlowPathCode(at), cpu_reg_(CpuRegister(reg)), type_(type), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 111 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 112 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 113 | __ Bind(GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 114 | if (type_ == Primitive::kPrimInt) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 115 | if (is_div_) { |
| 116 | __ negl(cpu_reg_); |
| 117 | } else { |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 118 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 119 | } |
| 120 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 121 | } else { |
| 122 | DCHECK_EQ(Primitive::kPrimLong, type_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 123 | if (is_div_) { |
| 124 | __ negq(cpu_reg_); |
| 125 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 126 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 127 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 128 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 129 | __ jmp(GetExitLabel()); |
| 130 | } |
| 131 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 132 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86_64"; } |
| 133 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 134 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 135 | const CpuRegister cpu_reg_; |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 136 | const Primitive::Type type_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 137 | const bool is_div_; |
| 138 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86_64); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 139 | }; |
| 140 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 141 | class SuspendCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 142 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 143 | SuspendCheckSlowPathX86_64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 144 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 145 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 146 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 147 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 148 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame^] | 149 | x86_64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 150 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 151 | if (successor_ == nullptr) { |
| 152 | __ jmp(GetReturnLabel()); |
| 153 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 154 | __ jmp(x86_64_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 155 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 158 | Label* GetReturnLabel() { |
| 159 | DCHECK(successor_ == nullptr); |
| 160 | return &return_label_; |
| 161 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 162 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 163 | HBasicBlock* GetSuccessor() const { |
| 164 | return successor_; |
| 165 | } |
| 166 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 167 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86_64"; } |
| 168 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 169 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 170 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 171 | Label return_label_; |
| 172 | |
| 173 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64); |
| 174 | }; |
| 175 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 176 | class BoundsCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 177 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 178 | explicit BoundsCheckSlowPathX86_64(HBoundsCheck* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 179 | : SlowPathCode(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 180 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 181 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 182 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 183 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 184 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 185 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 186 | // Live registers will be restored in the catch block if caught. |
| 187 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 188 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 189 | // Are we using an array length from memory? |
| 190 | HInstruction* array_length = instruction_->InputAt(1); |
| 191 | Location length_loc = locations->InAt(1); |
| 192 | InvokeRuntimeCallingConvention calling_convention; |
| 193 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { |
| 194 | // Load the array length into our temporary. |
| 195 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 196 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 197 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
| 198 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 199 | // Check for conflicts with index. |
| 200 | if (length_loc.Equals(locations->InAt(0))) { |
| 201 | // We know we aren't using parameter 2. |
| 202 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 203 | } |
| 204 | __ movl(length_loc.AsRegister<CpuRegister>(), array_len); |
| 205 | } |
| 206 | |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 207 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 208 | // move resolver. |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 209 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 210 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 211 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 212 | Primitive::kPrimInt, |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 213 | length_loc, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 214 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 215 | Primitive::kPrimInt); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame^] | 216 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 217 | ? kQuickThrowStringBounds |
| 218 | : kQuickThrowArrayBounds; |
| 219 | x86_64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 220 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 221 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 222 | } |
| 223 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 224 | bool IsFatal() const OVERRIDE { return true; } |
| 225 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 226 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86_64"; } |
| 227 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 228 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 229 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 230 | }; |
| 231 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 232 | class LoadClassSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 233 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 234 | LoadClassSlowPathX86_64(HLoadClass* cls, |
| 235 | HInstruction* at, |
| 236 | uint32_t dex_pc, |
| 237 | bool do_clinit) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 238 | : SlowPathCode(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 239 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 240 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 241 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 242 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 243 | LocationSummary* locations = at_->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 244 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 245 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 246 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 247 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 248 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 249 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 250 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(cls_->GetTypeIndex())); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame^] | 251 | x86_64_codegen->InvokeRuntime(do_clinit_ ? kQuickInitializeStaticStorage : kQuickInitializeType, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 252 | at_, |
| 253 | dex_pc_, |
| 254 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 255 | if (do_clinit_) { |
| 256 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 257 | } else { |
| 258 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 259 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 260 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 261 | Location out = locations->Out(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 262 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 263 | if (out.IsValid()) { |
| 264 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 265 | x86_64_codegen->Move(out, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 266 | } |
| 267 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 268 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 269 | __ jmp(GetExitLabel()); |
| 270 | } |
| 271 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 272 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86_64"; } |
| 273 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 274 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 275 | // The class this slow path will load. |
| 276 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 277 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 278 | // The instruction where this slow path is happening. |
| 279 | // (Might be the load class or an initialization check). |
| 280 | HInstruction* const at_; |
| 281 | |
| 282 | // The dex PC of `at_`. |
| 283 | const uint32_t dex_pc_; |
| 284 | |
| 285 | // Whether to initialize the class. |
| 286 | const bool do_clinit_; |
| 287 | |
| 288 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86_64); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 289 | }; |
| 290 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 291 | class LoadStringSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 292 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 293 | explicit LoadStringSlowPathX86_64(HLoadString* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 294 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 295 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 296 | LocationSummary* locations = instruction_->GetLocations(); |
| 297 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 298 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 299 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 300 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 301 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 302 | |
| 303 | InvokeRuntimeCallingConvention calling_convention; |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 304 | const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 305 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(string_index)); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame^] | 306 | x86_64_codegen->InvokeRuntime(kQuickResolveString, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 307 | instruction_, |
| 308 | instruction_->GetDexPc(), |
| 309 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 310 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 311 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 312 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 313 | __ jmp(GetExitLabel()); |
| 314 | } |
| 315 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 316 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86_64"; } |
| 317 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 318 | private: |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 319 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86_64); |
| 320 | }; |
| 321 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 322 | class TypeCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 323 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 324 | TypeCheckSlowPathX86_64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 325 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 326 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 327 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 328 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 329 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 330 | : locations->Out(); |
| 331 | uint32_t dex_pc = instruction_->GetDexPc(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 332 | DCHECK(instruction_->IsCheckCast() |
| 333 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 334 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 335 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 336 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 337 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 338 | if (!is_fatal_) { |
| 339 | SaveLiveRegisters(codegen, locations); |
| 340 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 341 | |
| 342 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 343 | // move resolver. |
| 344 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 345 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 346 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 347 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 348 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 349 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 350 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 351 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 352 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 353 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame^] | 354 | x86_64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 355 | CheckEntrypointTypes< |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 356 | kQuickInstanceofNonTrivial, size_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 357 | } else { |
| 358 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame^] | 359 | x86_64_codegen->InvokeRuntime(kQuickCheckCast, instruction_, dex_pc, this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 360 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 361 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 362 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 363 | if (!is_fatal_) { |
| 364 | if (instruction_->IsInstanceOf()) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 365 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 366 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 367 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 368 | RestoreLiveRegisters(codegen, locations); |
| 369 | __ jmp(GetExitLabel()); |
| 370 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 371 | } |
| 372 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 373 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86_64"; } |
| 374 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 375 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 376 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 377 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 378 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 379 | |
| 380 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86_64); |
| 381 | }; |
| 382 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 383 | class DeoptimizationSlowPathX86_64 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 384 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 385 | explicit DeoptimizationSlowPathX86_64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 386 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 387 | |
| 388 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 389 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 390 | __ Bind(GetEntryLabel()); |
| 391 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame^] | 392 | x86_64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 393 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 394 | } |
| 395 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 396 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86_64"; } |
| 397 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 398 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 399 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86_64); |
| 400 | }; |
| 401 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 402 | class ArraySetSlowPathX86_64 : public SlowPathCode { |
| 403 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 404 | explicit ArraySetSlowPathX86_64(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 405 | |
| 406 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 407 | LocationSummary* locations = instruction_->GetLocations(); |
| 408 | __ Bind(GetEntryLabel()); |
| 409 | SaveLiveRegisters(codegen, locations); |
| 410 | |
| 411 | InvokeRuntimeCallingConvention calling_convention; |
| 412 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 413 | parallel_move.AddMove( |
| 414 | locations->InAt(0), |
| 415 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 416 | Primitive::kPrimNot, |
| 417 | nullptr); |
| 418 | parallel_move.AddMove( |
| 419 | locations->InAt(1), |
| 420 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 421 | Primitive::kPrimInt, |
| 422 | nullptr); |
| 423 | parallel_move.AddMove( |
| 424 | locations->InAt(2), |
| 425 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 426 | Primitive::kPrimNot, |
| 427 | nullptr); |
| 428 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 429 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 430 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame^] | 431 | x86_64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 432 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 433 | RestoreLiveRegisters(codegen, locations); |
| 434 | __ jmp(GetExitLabel()); |
| 435 | } |
| 436 | |
| 437 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86_64"; } |
| 438 | |
| 439 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 440 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86_64); |
| 441 | }; |
| 442 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 443 | // Slow path marking an object during a read barrier. |
| 444 | class ReadBarrierMarkSlowPathX86_64 : public SlowPathCode { |
| 445 | public: |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 446 | ReadBarrierMarkSlowPathX86_64(HInstruction* instruction, Location obj, bool unpoison) |
| 447 | : SlowPathCode(instruction), obj_(obj), unpoison_(unpoison) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 448 | DCHECK(kEmitCompilerReadBarrier); |
| 449 | } |
| 450 | |
| 451 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86_64"; } |
| 452 | |
| 453 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 454 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 455 | Register reg = obj_.AsRegister<Register>(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 456 | DCHECK(locations->CanCall()); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 457 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 458 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 459 | instruction_->IsStaticFieldGet() || |
| 460 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 461 | instruction_->IsArraySet() || |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 462 | instruction_->IsLoadClass() || |
| 463 | instruction_->IsLoadString() || |
| 464 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 465 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 466 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 467 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 468 | << "Unexpected instruction in read barrier marking slow path: " |
| 469 | << instruction_->DebugName(); |
| 470 | |
| 471 | __ Bind(GetEntryLabel()); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 472 | if (unpoison_) { |
| 473 | // Object* ref = ref_addr->AsMirrorPtr() |
| 474 | __ MaybeUnpoisonHeapReference(obj_.AsRegister<CpuRegister>()); |
| 475 | } |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 476 | // No need to save live registers; it's taken care of by the |
| 477 | // entrypoint. Also, there is no need to update the stack mask, |
| 478 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 479 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 480 | DCHECK_NE(reg, RSP); |
| 481 | DCHECK(0 <= reg && reg < kNumberOfCpuRegisters) << reg; |
| 482 | // "Compact" slow path, saving two moves. |
| 483 | // |
| 484 | // Instead of using the standard runtime calling convention (input |
| 485 | // and output in R0): |
| 486 | // |
| 487 | // RDI <- obj |
| 488 | // RAX <- ReadBarrierMark(RDI) |
| 489 | // obj <- RAX |
| 490 | // |
| 491 | // we just use rX (the register holding `obj`) as input and output |
| 492 | // of a dedicated entrypoint: |
| 493 | // |
| 494 | // rX <- ReadBarrierMarkRegX(rX) |
| 495 | // |
| 496 | int32_t entry_point_offset = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 497 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kX86_64PointerSize>(reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 498 | // This runtime call does not require a stack map. |
| 499 | x86_64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 500 | __ jmp(GetExitLabel()); |
| 501 | } |
| 502 | |
| 503 | private: |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 504 | const Location obj_; |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 505 | const bool unpoison_; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 506 | |
| 507 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86_64); |
| 508 | }; |
| 509 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 510 | // Slow path generating a read barrier for a heap reference. |
| 511 | class ReadBarrierForHeapReferenceSlowPathX86_64 : public SlowPathCode { |
| 512 | public: |
| 513 | ReadBarrierForHeapReferenceSlowPathX86_64(HInstruction* instruction, |
| 514 | Location out, |
| 515 | Location ref, |
| 516 | Location obj, |
| 517 | uint32_t offset, |
| 518 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 519 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 520 | out_(out), |
| 521 | ref_(ref), |
| 522 | obj_(obj), |
| 523 | offset_(offset), |
| 524 | index_(index) { |
| 525 | DCHECK(kEmitCompilerReadBarrier); |
| 526 | // If `obj` is equal to `out` or `ref`, it means the initial |
| 527 | // object has been overwritten by (or after) the heap object |
| 528 | // reference load to be instrumented, e.g.: |
| 529 | // |
| 530 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 531 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 532 | // |
| 533 | // In that case, we have lost the information about the original |
| 534 | // object, and the emitted read barrier cannot work properly. |
| 535 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 536 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 537 | } |
| 538 | |
| 539 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 540 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 541 | LocationSummary* locations = instruction_->GetLocations(); |
| 542 | CpuRegister reg_out = out_.AsRegister<CpuRegister>(); |
| 543 | DCHECK(locations->CanCall()); |
| 544 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.AsRegister())) << out_; |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 545 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 546 | instruction_->IsStaticFieldGet() || |
| 547 | instruction_->IsArrayGet() || |
| 548 | instruction_->IsInstanceOf() || |
| 549 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 550 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 551 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 552 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 553 | |
| 554 | __ Bind(GetEntryLabel()); |
| 555 | SaveLiveRegisters(codegen, locations); |
| 556 | |
| 557 | // We may have to change the index's value, but as `index_` is a |
| 558 | // constant member (like other "inputs" of this slow path), |
| 559 | // introduce a copy of it, `index`. |
| 560 | Location index = index_; |
| 561 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 562 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 563 | if (instruction_->IsArrayGet()) { |
| 564 | // Compute real offset and store it in index_. |
| 565 | Register index_reg = index_.AsRegister<CpuRegister>().AsRegister(); |
| 566 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 567 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 568 | // We are about to change the value of `index_reg` (see the |
| 569 | // calls to art::x86_64::X86_64Assembler::shll and |
| 570 | // art::x86_64::X86_64Assembler::AddImmediate below), but it |
| 571 | // has not been saved by the previous call to |
| 572 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 573 | // callee-save register -- |
| 574 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 575 | // callee-save registers, as it has been designed with the |
| 576 | // assumption that callee-save registers are supposed to be |
| 577 | // handled by the called function. So, as a callee-save |
| 578 | // register, `index_reg` _would_ eventually be saved onto |
| 579 | // the stack, but it would be too late: we would have |
| 580 | // changed its value earlier. Therefore, we manually save |
| 581 | // it here into another freely available register, |
| 582 | // `free_reg`, chosen of course among the caller-save |
| 583 | // registers (as a callee-save `free_reg` register would |
| 584 | // exhibit the same problem). |
| 585 | // |
| 586 | // Note we could have requested a temporary register from |
| 587 | // the register allocator instead; but we prefer not to, as |
| 588 | // this is a slow path, and we know we can find a |
| 589 | // caller-save register that is available. |
| 590 | Register free_reg = FindAvailableCallerSaveRegister(codegen).AsRegister(); |
| 591 | __ movl(CpuRegister(free_reg), CpuRegister(index_reg)); |
| 592 | index_reg = free_reg; |
| 593 | index = Location::RegisterLocation(index_reg); |
| 594 | } else { |
| 595 | // The initial register stored in `index_` has already been |
| 596 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 597 | // (as it is not a callee-save register), so we can freely |
| 598 | // use it. |
| 599 | } |
| 600 | // Shifting the index value contained in `index_reg` by the |
| 601 | // scale factor (2) cannot overflow in practice, as the |
| 602 | // runtime is unable to allocate object arrays with a size |
| 603 | // larger than 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 604 | __ shll(CpuRegister(index_reg), Immediate(TIMES_4)); |
| 605 | static_assert( |
| 606 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 607 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 608 | __ AddImmediate(CpuRegister(index_reg), Immediate(offset_)); |
| 609 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 610 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 611 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 612 | // (as in the case of ArrayGet), as it is actually an offset |
| 613 | // to an object field within an object. |
| 614 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 615 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 616 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 617 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 618 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 619 | DCHECK_EQ(offset_, 0U); |
| 620 | DCHECK(index_.IsRegister()); |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | // We're moving two or three locations to locations that could |
| 625 | // overlap, so we need a parallel move resolver. |
| 626 | InvokeRuntimeCallingConvention calling_convention; |
| 627 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 628 | parallel_move.AddMove(ref_, |
| 629 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 630 | Primitive::kPrimNot, |
| 631 | nullptr); |
| 632 | parallel_move.AddMove(obj_, |
| 633 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 634 | Primitive::kPrimNot, |
| 635 | nullptr); |
| 636 | if (index.IsValid()) { |
| 637 | parallel_move.AddMove(index, |
| 638 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 639 | Primitive::kPrimInt, |
| 640 | nullptr); |
| 641 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 642 | } else { |
| 643 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 644 | __ movl(CpuRegister(calling_convention.GetRegisterAt(2)), Immediate(offset_)); |
| 645 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame^] | 646 | x86_64_codegen->InvokeRuntime(kQuickReadBarrierSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 647 | instruction_, |
| 648 | instruction_->GetDexPc(), |
| 649 | this); |
| 650 | CheckEntrypointTypes< |
| 651 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 652 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 653 | |
| 654 | RestoreLiveRegisters(codegen, locations); |
| 655 | __ jmp(GetExitLabel()); |
| 656 | } |
| 657 | |
| 658 | const char* GetDescription() const OVERRIDE { |
| 659 | return "ReadBarrierForHeapReferenceSlowPathX86_64"; |
| 660 | } |
| 661 | |
| 662 | private: |
| 663 | CpuRegister FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 664 | size_t ref = static_cast<int>(ref_.AsRegister<CpuRegister>().AsRegister()); |
| 665 | size_t obj = static_cast<int>(obj_.AsRegister<CpuRegister>().AsRegister()); |
| 666 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 667 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 668 | return static_cast<CpuRegister>(i); |
| 669 | } |
| 670 | } |
| 671 | // We shall never fail to find a free caller-save register, as |
| 672 | // there are more than two core caller-save registers on x86-64 |
| 673 | // (meaning it is possible to find one which is different from |
| 674 | // `ref` and `obj`). |
| 675 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 676 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 677 | UNREACHABLE(); |
| 678 | } |
| 679 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 680 | const Location out_; |
| 681 | const Location ref_; |
| 682 | const Location obj_; |
| 683 | const uint32_t offset_; |
| 684 | // An additional location containing an index to an array. |
| 685 | // Only used for HArrayGet and the UnsafeGetObject & |
| 686 | // UnsafeGetObjectVolatile intrinsics. |
| 687 | const Location index_; |
| 688 | |
| 689 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86_64); |
| 690 | }; |
| 691 | |
| 692 | // Slow path generating a read barrier for a GC root. |
| 693 | class ReadBarrierForRootSlowPathX86_64 : public SlowPathCode { |
| 694 | public: |
| 695 | ReadBarrierForRootSlowPathX86_64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 696 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 697 | DCHECK(kEmitCompilerReadBarrier); |
| 698 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 699 | |
| 700 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 701 | LocationSummary* locations = instruction_->GetLocations(); |
| 702 | DCHECK(locations->CanCall()); |
| 703 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 704 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 705 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 706 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 707 | |
| 708 | __ Bind(GetEntryLabel()); |
| 709 | SaveLiveRegisters(codegen, locations); |
| 710 | |
| 711 | InvokeRuntimeCallingConvention calling_convention; |
| 712 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 713 | x86_64_codegen->Move(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame^] | 714 | x86_64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 715 | instruction_, |
| 716 | instruction_->GetDexPc(), |
| 717 | this); |
| 718 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 719 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 720 | |
| 721 | RestoreLiveRegisters(codegen, locations); |
| 722 | __ jmp(GetExitLabel()); |
| 723 | } |
| 724 | |
| 725 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86_64"; } |
| 726 | |
| 727 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 728 | const Location out_; |
| 729 | const Location root_; |
| 730 | |
| 731 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86_64); |
| 732 | }; |
| 733 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 734 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 735 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 736 | #define __ down_cast<X86_64Assembler*>(GetAssembler())-> // NOLINT |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 737 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 738 | inline Condition X86_64IntegerCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 739 | switch (cond) { |
| 740 | case kCondEQ: return kEqual; |
| 741 | case kCondNE: return kNotEqual; |
| 742 | case kCondLT: return kLess; |
| 743 | case kCondLE: return kLessEqual; |
| 744 | case kCondGT: return kGreater; |
| 745 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 746 | case kCondB: return kBelow; |
| 747 | case kCondBE: return kBelowEqual; |
| 748 | case kCondA: return kAbove; |
| 749 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 750 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 751 | LOG(FATAL) << "Unreachable"; |
| 752 | UNREACHABLE(); |
| 753 | } |
| 754 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 755 | // Maps FP condition to x86_64 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 756 | inline Condition X86_64FPCondition(IfCondition cond) { |
| 757 | switch (cond) { |
| 758 | case kCondEQ: return kEqual; |
| 759 | case kCondNE: return kNotEqual; |
| 760 | case kCondLT: return kBelow; |
| 761 | case kCondLE: return kBelowEqual; |
| 762 | case kCondGT: return kAbove; |
| 763 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 764 | default: break; // should not happen |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 765 | }; |
| 766 | LOG(FATAL) << "Unreachable"; |
| 767 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 768 | } |
| 769 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 770 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86_64::GetSupportedInvokeStaticOrDirectDispatch( |
| 771 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 772 | MethodReference target_method ATTRIBUTE_UNUSED) { |
| 773 | switch (desired_dispatch_info.code_ptr_location) { |
| 774 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 775 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 776 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 777 | return HInvokeStaticOrDirect::DispatchInfo { |
| 778 | desired_dispatch_info.method_load_kind, |
| 779 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
| 780 | desired_dispatch_info.method_load_data, |
| 781 | 0u |
| 782 | }; |
| 783 | default: |
| 784 | return desired_dispatch_info; |
| 785 | } |
| 786 | } |
| 787 | |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 788 | Location CodeGeneratorX86_64::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 789 | Location temp) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 790 | // All registers are assumed to be correctly set up. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 791 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 792 | switch (invoke->GetMethodLoadKind()) { |
| 793 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 794 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | 7f59d59 | 2015-12-29 16:20:52 +0000 | [diff] [blame] | 795 | __ gs()->movq(temp.AsRegister<CpuRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 796 | Address::Absolute(invoke->GetStringInitOffset(), /* no_rip */ true)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 797 | break; |
| 798 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 799 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 800 | break; |
| 801 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 802 | __ movq(temp.AsRegister<CpuRegister>(), Immediate(invoke->GetMethodAddress())); |
| 803 | break; |
| 804 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 805 | __ movl(temp.AsRegister<CpuRegister>(), Immediate(0)); // Placeholder. |
| 806 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 807 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 808 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 809 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 810 | __ movq(temp.AsRegister<CpuRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 811 | Address::Absolute(kDummy32BitOffset, /* no_rip */ false)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 812 | // Bind a new fixup label at the end of the "movl" insn. |
| 813 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
| 814 | __ Bind(NewPcRelativeDexCacheArrayPatch(*invoke->GetTargetMethod().dex_file, offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 815 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 816 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 817 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 818 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 819 | Register method_reg; |
| 820 | CpuRegister reg = temp.AsRegister<CpuRegister>(); |
| 821 | if (current_method.IsRegister()) { |
| 822 | method_reg = current_method.AsRegister<Register>(); |
| 823 | } else { |
| 824 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 825 | DCHECK(!current_method.IsValid()); |
| 826 | method_reg = reg.AsRegister(); |
| 827 | __ movq(reg, Address(CpuRegister(RSP), kCurrentMethodStackOffset)); |
| 828 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 829 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 830 | __ movq(reg, |
| 831 | Address(CpuRegister(method_reg), |
| 832 | ArtMethod::DexCacheResolvedMethodsOffset(kX86_64PointerSize).SizeValue())); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 833 | // temp = temp[index_in_cache]; |
| 834 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 835 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 836 | __ movq(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 837 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 838 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 839 | } |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 840 | return callee_method; |
| 841 | } |
| 842 | |
| 843 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 844 | Location temp) { |
| 845 | // All registers are assumed to be correctly set up. |
| 846 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 847 | |
| 848 | switch (invoke->GetCodePtrLocation()) { |
| 849 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 850 | __ call(&frame_entry_label_); |
| 851 | break; |
| 852 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 853 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 854 | Label* label = &relative_call_patches_.back().label; |
| 855 | __ call(label); // Bind to the patch label, override at link time. |
| 856 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 857 | break; |
| 858 | } |
| 859 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 860 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 861 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 862 | LOG(FATAL) << "Unsupported"; |
| 863 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 864 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 865 | // (callee_method + offset_of_quick_compiled_code)() |
| 866 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 867 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 868 | kX86_64PointerSize).SizeValue())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 869 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 870 | } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 871 | |
| 872 | DCHECK(!IsLeafMethod()); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 873 | } |
| 874 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 875 | void CodeGeneratorX86_64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 876 | CpuRegister temp = temp_in.AsRegister<CpuRegister>(); |
| 877 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 878 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 879 | |
| 880 | // Use the calling convention instead of the location of the receiver, as |
| 881 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 882 | // slow path, the arguments have been moved to the right place, so here we are |
| 883 | // guaranteed that the receiver is the first register of the calling convention. |
| 884 | InvokeDexCallingConvention calling_convention; |
| 885 | Register receiver = calling_convention.GetRegisterAt(0); |
| 886 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 887 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 888 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 889 | __ movl(temp, Address(CpuRegister(receiver), class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 890 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 891 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 892 | // emit a read barrier for the previous class reference load. |
| 893 | // However this is not required in practice, as this is an |
| 894 | // intermediate/temporary reference and because the current |
| 895 | // concurrent copying collector keeps the from-space memory |
| 896 | // intact/accessible until the end of the marking phase (the |
| 897 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 898 | __ MaybeUnpoisonHeapReference(temp); |
| 899 | // temp = temp->GetMethodAt(method_offset); |
| 900 | __ movq(temp, Address(temp, method_offset)); |
| 901 | // call temp->GetEntryPoint(); |
| 902 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 903 | kX86_64PointerSize).SizeValue())); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 904 | } |
| 905 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 906 | void CodeGeneratorX86_64::RecordSimplePatch() { |
| 907 | if (GetCompilerOptions().GetIncludePatchInformation()) { |
| 908 | simple_patches_.emplace_back(); |
| 909 | __ Bind(&simple_patches_.back()); |
| 910 | } |
| 911 | } |
| 912 | |
| 913 | void CodeGeneratorX86_64::RecordStringPatch(HLoadString* load_string) { |
| 914 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex()); |
| 915 | __ Bind(&string_patches_.back().label); |
| 916 | } |
| 917 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 918 | void CodeGeneratorX86_64::RecordTypePatch(HLoadClass* load_class) { |
| 919 | type_patches_.emplace_back(load_class->GetDexFile(), load_class->GetTypeIndex()); |
| 920 | __ Bind(&type_patches_.back().label); |
| 921 | } |
| 922 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 923 | Label* CodeGeneratorX86_64::NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, |
| 924 | uint32_t element_offset) { |
| 925 | // Add a patch entry and return the label. |
| 926 | pc_relative_dex_cache_patches_.emplace_back(dex_file, element_offset); |
| 927 | return &pc_relative_dex_cache_patches_.back().label; |
| 928 | } |
| 929 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 930 | void CodeGeneratorX86_64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 931 | DCHECK(linker_patches->empty()); |
| 932 | size_t size = |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 933 | method_patches_.size() + |
| 934 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 935 | pc_relative_dex_cache_patches_.size() + |
| 936 | simple_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 937 | string_patches_.size() + |
| 938 | type_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 939 | linker_patches->reserve(size); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 940 | // The label points to the end of the "movl" insn but the literal offset for method |
| 941 | // patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 942 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 943 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 944 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 945 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 946 | info.target_method.dex_file, |
| 947 | info.target_method.dex_method_index)); |
| 948 | } |
| 949 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 950 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 951 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 952 | info.target_method.dex_file, |
| 953 | info.target_method.dex_method_index)); |
| 954 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 955 | for (const PcRelativeDexCacheAccessInfo& info : pc_relative_dex_cache_patches_) { |
| 956 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 957 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 958 | &info.target_dex_file, |
| 959 | info.label.Position(), |
| 960 | info.element_offset)); |
| 961 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 962 | for (const Label& label : simple_patches_) { |
| 963 | uint32_t literal_offset = label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 964 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 965 | } |
| 966 | for (const StringPatchInfo<Label>& info : string_patches_) { |
| 967 | // These are always PC-relative, see GetSupportedLoadStringKind(). |
| 968 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 969 | linker_patches->push_back(LinkerPatch::RelativeStringPatch(literal_offset, |
| 970 | &info.dex_file, |
| 971 | info.label.Position(), |
| 972 | info.string_index)); |
| 973 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 974 | for (const TypePatchInfo<Label>& info : type_patches_) { |
| 975 | // These are always PC-relative, see GetSupportedLoadClassKind(). |
| 976 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 977 | linker_patches->push_back(LinkerPatch::RelativeTypePatch(literal_offset, |
| 978 | &info.dex_file, |
| 979 | info.label.Position(), |
| 980 | info.type_index)); |
| 981 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 982 | } |
| 983 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 984 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 985 | stream << Register(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 989 | stream << FloatRegister(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 990 | } |
| 991 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 992 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 993 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 994 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 995 | } |
| 996 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 997 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 998 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 999 | return kX86_64WordSize; |
| 1000 | } |
| 1001 | |
| 1002 | size_t CodeGeneratorX86_64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1003 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 1004 | return kX86_64WordSize; |
| 1005 | } |
| 1006 | |
| 1007 | size_t CodeGeneratorX86_64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 1008 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 1009 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 1010 | } |
| 1011 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1012 | void CodeGeneratorX86_64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 1013 | HInstruction* instruction, |
| 1014 | uint32_t dex_pc, |
| 1015 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1016 | ValidateInvokeRuntime(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame^] | 1017 | GenerateInvokeRuntime(GetThreadOffset<kX86_64PointerSize>(entrypoint).Int32Value()); |
| 1018 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 1019 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 1020 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 1021 | } |
| 1022 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1023 | void CodeGeneratorX86_64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 1024 | HInstruction* instruction, |
| 1025 | SlowPathCode* slow_path) { |
| 1026 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame^] | 1027 | GenerateInvokeRuntime(entry_point_offset); |
| 1028 | } |
| 1029 | |
| 1030 | void CodeGeneratorX86_64::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1031 | __ gs()->call(Address::Absolute(entry_point_offset, /* no_rip */ true)); |
| 1032 | } |
| 1033 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1034 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1035 | // Use a fake return address register to mimic Quick. |
| 1036 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1037 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1038 | const X86_64InstructionSetFeatures& isa_features, |
| 1039 | const CompilerOptions& compiler_options, |
| 1040 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1041 | : CodeGenerator(graph, |
| 1042 | kNumberOfCpuRegisters, |
| 1043 | kNumberOfFloatRegisters, |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1044 | kNumberOfCpuRegisterPairs, |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1045 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1046 | arraysize(kCoreCalleeSaves)) |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1047 | | (1 << kFakeReturnRegister), |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1048 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1049 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1050 | compiler_options, |
| 1051 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1052 | block_labels_(nullptr), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1053 | location_builder_(graph, this), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1054 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1055 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1056 | assembler_(graph->GetArena()), |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 1057 | isa_features_(isa_features), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1058 | constant_area_start_(0), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 1059 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1060 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1061 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1062 | simple_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1063 | string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1064 | type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 1065 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1066 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 1067 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1068 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1069 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 1070 | CodeGeneratorX86_64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1071 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1072 | assembler_(codegen->GetAssembler()), |
| 1073 | codegen_(codegen) {} |
| 1074 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1075 | void CodeGeneratorX86_64::SetupBlockedRegisters() const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1076 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1077 | blocked_core_registers_[RSP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1078 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1079 | // Block the register used as TMP. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1080 | blocked_core_registers_[TMP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1081 | } |
| 1082 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1083 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1084 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1085 | } |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1086 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1087 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1088 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1089 | } |
| 1090 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1091 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1092 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1093 | __ Bind(&frame_entry_label_); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1094 | bool skip_overflow_check = IsLeafMethod() |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 1095 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1096 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1097 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1098 | if (!skip_overflow_check) { |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1099 | __ testq(CpuRegister(RAX), Address( |
| 1100 | CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1101 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1102 | } |
Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 1103 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1104 | if (HasEmptyFrame()) { |
| 1105 | return; |
| 1106 | } |
| 1107 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1108 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1109 | Register reg = kCoreCalleeSaves[i]; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1110 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1111 | __ pushq(CpuRegister(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1112 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 1113 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1114 | } |
| 1115 | } |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1116 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1117 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1118 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 1119 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1120 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1121 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1122 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1123 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1124 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1125 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1126 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 1127 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1128 | } |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1129 | } |
| 1130 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1131 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1132 | CpuRegister(kMethodRegisterArgument)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | void CodeGeneratorX86_64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1136 | __ cfi().RememberState(); |
| 1137 | if (!HasEmptyFrame()) { |
| 1138 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1139 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| 1140 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1141 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 1142 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1143 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 1144 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 1145 | } |
| 1146 | } |
| 1147 | |
| 1148 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1149 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 1150 | __ cfi().AdjustCFAOffset(-adjust); |
| 1151 | |
| 1152 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1153 | Register reg = kCoreCalleeSaves[i]; |
| 1154 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1155 | __ popq(CpuRegister(reg)); |
| 1156 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 1157 | __ cfi().Restore(DWARFReg(reg)); |
| 1158 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1159 | } |
| 1160 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1161 | __ ret(); |
| 1162 | __ cfi().RestoreState(); |
| 1163 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1164 | } |
| 1165 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1166 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 1167 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1168 | } |
| 1169 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1170 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 1171 | if (source.Equals(destination)) { |
| 1172 | return; |
| 1173 | } |
| 1174 | if (destination.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1175 | CpuRegister dest = destination.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1176 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1177 | __ movq(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1178 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1179 | __ movd(dest, source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1180 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1181 | __ movl(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1182 | } else if (source.IsConstant()) { |
| 1183 | HConstant* constant = source.GetConstant(); |
| 1184 | if (constant->IsLongConstant()) { |
| 1185 | Load64BitValue(dest, constant->AsLongConstant()->GetValue()); |
| 1186 | } else { |
| 1187 | Load32BitValue(dest, GetInt32ValueOf(constant)); |
| 1188 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1189 | } else { |
| 1190 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1191 | __ movq(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1192 | } |
| 1193 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1194 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1195 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1196 | __ movd(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1197 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1198 | __ movaps(dest, source.AsFpuRegister<XmmRegister>()); |
| 1199 | } else if (source.IsConstant()) { |
| 1200 | HConstant* constant = source.GetConstant(); |
| 1201 | int64_t value = CodeGenerator::GetInt64ValueOf(constant); |
| 1202 | if (constant->IsFloatConstant()) { |
| 1203 | Load32BitValue(dest, static_cast<int32_t>(value)); |
| 1204 | } else { |
| 1205 | Load64BitValue(dest, value); |
| 1206 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1207 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1208 | __ movss(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1209 | } else { |
| 1210 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1211 | __ movsd(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1212 | } |
| 1213 | } else if (destination.IsStackSlot()) { |
| 1214 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1215 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1216 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1217 | } else if (source.IsFpuRegister()) { |
| 1218 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1219 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1220 | } else if (source.IsConstant()) { |
| 1221 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1222 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1223 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1224 | } else { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1225 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1226 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1227 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1228 | } |
| 1229 | } else { |
| 1230 | DCHECK(destination.IsDoubleStackSlot()); |
| 1231 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1232 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1233 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1234 | } else if (source.IsFpuRegister()) { |
| 1235 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1236 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1237 | } else if (source.IsConstant()) { |
| 1238 | HConstant* constant = source.GetConstant(); |
Zheng Xu | 12bca97 | 2015-03-30 19:35:50 +0800 | [diff] [blame] | 1239 | int64_t value; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1240 | if (constant->IsDoubleConstant()) { |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 1241 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1242 | } else { |
| 1243 | DCHECK(constant->IsLongConstant()); |
| 1244 | value = constant->AsLongConstant()->GetValue(); |
| 1245 | } |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 1246 | Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1247 | } else { |
| 1248 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1249 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1250 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1251 | } |
| 1252 | } |
| 1253 | } |
| 1254 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1255 | void CodeGeneratorX86_64::MoveConstant(Location location, int32_t value) { |
| 1256 | DCHECK(location.IsRegister()); |
| 1257 | Load64BitValue(location.AsRegister<CpuRegister>(), static_cast<int64_t>(value)); |
| 1258 | } |
| 1259 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1260 | void CodeGeneratorX86_64::MoveLocation( |
| 1261 | Location dst, Location src, Primitive::Type dst_type ATTRIBUTE_UNUSED) { |
| 1262 | Move(dst, src); |
| 1263 | } |
| 1264 | |
| 1265 | void CodeGeneratorX86_64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1266 | if (location.IsRegister()) { |
| 1267 | locations->AddTemp(location); |
| 1268 | } else { |
| 1269 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1270 | } |
| 1271 | } |
| 1272 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1273 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1274 | DCHECK(!successor->IsExitBlock()); |
| 1275 | |
| 1276 | HBasicBlock* block = got->GetBlock(); |
| 1277 | HInstruction* previous = got->GetPrevious(); |
| 1278 | |
| 1279 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1280 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1281 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1282 | return; |
| 1283 | } |
| 1284 | |
| 1285 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1286 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1287 | } |
| 1288 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1289 | __ jmp(codegen_->GetLabelOf(successor)); |
| 1290 | } |
| 1291 | } |
| 1292 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1293 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 1294 | got->SetLocations(nullptr); |
| 1295 | } |
| 1296 | |
| 1297 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 1298 | HandleGoto(got, got->GetSuccessor()); |
| 1299 | } |
| 1300 | |
| 1301 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1302 | try_boundary->SetLocations(nullptr); |
| 1303 | } |
| 1304 | |
| 1305 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1306 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1307 | if (!successor->IsExitBlock()) { |
| 1308 | HandleGoto(try_boundary, successor); |
| 1309 | } |
| 1310 | } |
| 1311 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1312 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 1313 | exit->SetLocations(nullptr); |
| 1314 | } |
| 1315 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1316 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1317 | } |
| 1318 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1319 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1320 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1321 | LabelType* true_label, |
| 1322 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1323 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1324 | __ j(kUnordered, true_label); |
| 1325 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1326 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1327 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1328 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1329 | } |
| 1330 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1331 | void InstructionCodeGeneratorX86_64::GenerateCompareTest(HCondition* condition) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1332 | LocationSummary* locations = condition->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1333 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1334 | Location left = locations->InAt(0); |
| 1335 | Location right = locations->InAt(1); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1336 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1337 | switch (type) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1338 | case Primitive::kPrimBoolean: |
| 1339 | case Primitive::kPrimByte: |
| 1340 | case Primitive::kPrimChar: |
| 1341 | case Primitive::kPrimShort: |
| 1342 | case Primitive::kPrimInt: |
| 1343 | case Primitive::kPrimNot: { |
| 1344 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1345 | if (right.IsConstant()) { |
| 1346 | int32_t value = CodeGenerator::GetInt32ValueOf(right.GetConstant()); |
| 1347 | if (value == 0) { |
| 1348 | __ testl(left_reg, left_reg); |
| 1349 | } else { |
| 1350 | __ cmpl(left_reg, Immediate(value)); |
| 1351 | } |
| 1352 | } else if (right.IsStackSlot()) { |
| 1353 | __ cmpl(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1354 | } else { |
| 1355 | __ cmpl(left_reg, right.AsRegister<CpuRegister>()); |
| 1356 | } |
| 1357 | break; |
| 1358 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1359 | case Primitive::kPrimLong: { |
| 1360 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1361 | if (right.IsConstant()) { |
| 1362 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1363 | codegen_->Compare64BitValue(left_reg, value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1364 | } else if (right.IsDoubleStackSlot()) { |
| 1365 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1366 | } else { |
| 1367 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1368 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1369 | break; |
| 1370 | } |
| 1371 | case Primitive::kPrimFloat: { |
| 1372 | if (right.IsFpuRegister()) { |
| 1373 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1374 | } else if (right.IsConstant()) { |
| 1375 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1376 | codegen_->LiteralFloatAddress( |
| 1377 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1378 | } else { |
| 1379 | DCHECK(right.IsStackSlot()); |
| 1380 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1381 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1382 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1383 | break; |
| 1384 | } |
| 1385 | case Primitive::kPrimDouble: { |
| 1386 | if (right.IsFpuRegister()) { |
| 1387 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1388 | } else if (right.IsConstant()) { |
| 1389 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1390 | codegen_->LiteralDoubleAddress( |
| 1391 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1392 | } else { |
| 1393 | DCHECK(right.IsDoubleStackSlot()); |
| 1394 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1395 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1396 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1397 | break; |
| 1398 | } |
| 1399 | default: |
| 1400 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1401 | } |
| 1402 | } |
| 1403 | |
| 1404 | template<class LabelType> |
| 1405 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HCondition* condition, |
| 1406 | LabelType* true_target_in, |
| 1407 | LabelType* false_target_in) { |
| 1408 | // Generated branching requires both targets to be explicit. If either of the |
| 1409 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1410 | LabelType fallthrough_target; |
| 1411 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1412 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1413 | |
| 1414 | // Generate the comparison to set the CC. |
| 1415 | GenerateCompareTest(condition); |
| 1416 | |
| 1417 | // Now generate the correct jump(s). |
| 1418 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1419 | switch (type) { |
| 1420 | case Primitive::kPrimLong: { |
| 1421 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
| 1422 | break; |
| 1423 | } |
| 1424 | case Primitive::kPrimFloat: { |
| 1425 | GenerateFPJumps(condition, true_target, false_target); |
| 1426 | break; |
| 1427 | } |
| 1428 | case Primitive::kPrimDouble: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1429 | GenerateFPJumps(condition, true_target, false_target); |
| 1430 | break; |
| 1431 | } |
| 1432 | default: |
| 1433 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1434 | } |
| 1435 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1436 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1437 | __ jmp(false_target); |
| 1438 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1439 | |
| 1440 | if (fallthrough_target.IsLinked()) { |
| 1441 | __ Bind(&fallthrough_target); |
| 1442 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1443 | } |
| 1444 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1445 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1446 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1447 | // are set only strictly before `branch`. We can't use the eflags on long |
| 1448 | // conditions if they are materialized due to the complex branching. |
| 1449 | return cond->IsCondition() && |
| 1450 | cond->GetNext() == branch && |
| 1451 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1452 | } |
| 1453 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1454 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1455 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1456 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1457 | LabelType* true_target, |
| 1458 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1459 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1460 | |
| 1461 | if (true_target == nullptr && false_target == nullptr) { |
| 1462 | // Nothing to do. The code always falls through. |
| 1463 | return; |
| 1464 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1465 | // Constant condition, statically compared against "true" (integer value 1). |
| 1466 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1467 | if (true_target != nullptr) { |
| 1468 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1469 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1470 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1471 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1472 | if (false_target != nullptr) { |
| 1473 | __ jmp(false_target); |
| 1474 | } |
| 1475 | } |
| 1476 | return; |
| 1477 | } |
| 1478 | |
| 1479 | // The following code generates these patterns: |
| 1480 | // (1) true_target == nullptr && false_target != nullptr |
| 1481 | // - opposite condition true => branch to false_target |
| 1482 | // (2) true_target != nullptr && false_target == nullptr |
| 1483 | // - condition true => branch to true_target |
| 1484 | // (3) true_target != nullptr && false_target != nullptr |
| 1485 | // - condition true => branch to true_target |
| 1486 | // - branch to false_target |
| 1487 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1488 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1489 | if (true_target == nullptr) { |
| 1490 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1491 | } else { |
| 1492 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
| 1493 | } |
| 1494 | } else { |
| 1495 | // Materialized condition, compare against 0. |
| 1496 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1497 | if (lhs.IsRegister()) { |
| 1498 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1499 | } else { |
| 1500 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), Immediate(0)); |
| 1501 | } |
| 1502 | if (true_target == nullptr) { |
| 1503 | __ j(kEqual, false_target); |
| 1504 | } else { |
| 1505 | __ j(kNotEqual, true_target); |
| 1506 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1507 | } |
| 1508 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1509 | // Condition has not been materialized, use its inputs as the |
| 1510 | // comparison and its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1511 | HCondition* condition = cond->AsCondition(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1512 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1513 | // If this is a long or FP comparison that has been folded into |
| 1514 | // the HCondition, generate the comparison directly. |
| 1515 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1516 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1517 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1518 | return; |
| 1519 | } |
| 1520 | |
| 1521 | Location lhs = condition->GetLocations()->InAt(0); |
| 1522 | Location rhs = condition->GetLocations()->InAt(1); |
| 1523 | if (rhs.IsRegister()) { |
| 1524 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1525 | } else if (rhs.IsConstant()) { |
| 1526 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1527 | codegen_->Compare32BitValue(lhs.AsRegister<CpuRegister>(), constant); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1528 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1529 | __ cmpl(lhs.AsRegister<CpuRegister>(), |
| 1530 | Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1531 | } |
| 1532 | if (true_target == nullptr) { |
| 1533 | __ j(X86_64IntegerCondition(condition->GetOppositeCondition()), false_target); |
| 1534 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1535 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1536 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1537 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1538 | |
| 1539 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1540 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1541 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1542 | __ jmp(false_target); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1543 | } |
| 1544 | } |
| 1545 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1546 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1547 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1548 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1549 | locations->SetInAt(0, Location::Any()); |
| 1550 | } |
| 1551 | } |
| 1552 | |
| 1553 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1554 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1555 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1556 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1557 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1558 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1559 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1560 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1561 | } |
| 1562 | |
| 1563 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1564 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1565 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1566 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1567 | locations->SetInAt(0, Location::Any()); |
| 1568 | } |
| 1569 | } |
| 1570 | |
| 1571 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1572 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86_64>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1573 | GenerateTestAndBranch<Label>(deoptimize, |
| 1574 | /* condition_input_index */ 0, |
| 1575 | slow_path->GetEntryLabel(), |
| 1576 | /* false_target */ nullptr); |
| 1577 | } |
| 1578 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1579 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1580 | // There are no conditional move instructions for XMMs. |
| 1581 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1582 | return false; |
| 1583 | } |
| 1584 | |
| 1585 | // A FP condition doesn't generate the single CC that we need. |
| 1586 | HInstruction* condition = select->GetCondition(); |
| 1587 | if (condition->IsCondition() && |
| 1588 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())) { |
| 1589 | return false; |
| 1590 | } |
| 1591 | |
| 1592 | // We can generate a CMOV for this Select. |
| 1593 | return true; |
| 1594 | } |
| 1595 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1596 | void LocationsBuilderX86_64::VisitSelect(HSelect* select) { |
| 1597 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 1598 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1599 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1600 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1601 | } else { |
| 1602 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1603 | if (SelectCanUseCMOV(select)) { |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1604 | if (select->InputAt(1)->IsConstant()) { |
| 1605 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1606 | } else { |
| 1607 | locations->SetInAt(1, Location::Any()); |
| 1608 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1609 | } else { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1610 | locations->SetInAt(1, Location::Any()); |
| 1611 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1612 | } |
| 1613 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1614 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1615 | } |
| 1616 | locations->SetOut(Location::SameAsFirstInput()); |
| 1617 | } |
| 1618 | |
| 1619 | void InstructionCodeGeneratorX86_64::VisitSelect(HSelect* select) { |
| 1620 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1621 | if (SelectCanUseCMOV(select)) { |
| 1622 | // If both the condition and the source types are integer, we can generate |
| 1623 | // a CMOV to implement Select. |
| 1624 | CpuRegister value_false = locations->InAt(0).AsRegister<CpuRegister>(); |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1625 | Location value_true_loc = locations->InAt(1); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1626 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1627 | |
| 1628 | HInstruction* select_condition = select->GetCondition(); |
| 1629 | Condition cond = kNotEqual; |
| 1630 | |
| 1631 | // Figure out how to test the 'condition'. |
| 1632 | if (select_condition->IsCondition()) { |
| 1633 | HCondition* condition = select_condition->AsCondition(); |
| 1634 | if (!condition->IsEmittedAtUseSite()) { |
| 1635 | // This was a previously materialized condition. |
| 1636 | // Can we use the existing condition code? |
| 1637 | if (AreEflagsSetFrom(condition, select)) { |
| 1638 | // Materialization was the previous instruction. Condition codes are right. |
| 1639 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1640 | } else { |
| 1641 | // No, we have to recreate the condition code. |
| 1642 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1643 | __ testl(cond_reg, cond_reg); |
| 1644 | } |
| 1645 | } else { |
| 1646 | GenerateCompareTest(condition); |
| 1647 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1648 | } |
| 1649 | } else { |
| 1650 | // Must be a boolean condition, which needs to be compared to 0. |
| 1651 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1652 | __ testl(cond_reg, cond_reg); |
| 1653 | } |
| 1654 | |
| 1655 | // If the condition is true, overwrite the output, which already contains false. |
| 1656 | // Generate the correct sized CMOV. |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1657 | bool is_64_bit = Primitive::Is64BitType(select->GetType()); |
| 1658 | if (value_true_loc.IsRegister()) { |
| 1659 | __ cmov(cond, value_false, value_true_loc.AsRegister<CpuRegister>(), is_64_bit); |
| 1660 | } else { |
| 1661 | __ cmov(cond, |
| 1662 | value_false, |
| 1663 | Address(CpuRegister(RSP), value_true_loc.GetStackIndex()), is_64_bit); |
| 1664 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1665 | } else { |
| 1666 | NearLabel false_target; |
| 1667 | GenerateTestAndBranch<NearLabel>(select, |
| 1668 | /* condition_input_index */ 2, |
| 1669 | /* true_target */ nullptr, |
| 1670 | &false_target); |
| 1671 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1672 | __ Bind(&false_target); |
| 1673 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1674 | } |
| 1675 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1676 | void LocationsBuilderX86_64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1677 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1678 | } |
| 1679 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1680 | void InstructionCodeGeneratorX86_64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1681 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1682 | } |
| 1683 | |
| 1684 | void CodeGeneratorX86_64::GenerateNop() { |
| 1685 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1686 | } |
| 1687 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1688 | void LocationsBuilderX86_64::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1689 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1690 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1691 | // Handle the long/FP comparisons made in instruction simplification. |
| 1692 | switch (cond->InputAt(0)->GetType()) { |
| 1693 | case Primitive::kPrimLong: |
| 1694 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1695 | locations->SetInAt(1, Location::Any()); |
| 1696 | break; |
| 1697 | case Primitive::kPrimFloat: |
| 1698 | case Primitive::kPrimDouble: |
| 1699 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1700 | locations->SetInAt(1, Location::Any()); |
| 1701 | break; |
| 1702 | default: |
| 1703 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1704 | locations->SetInAt(1, Location::Any()); |
| 1705 | break; |
| 1706 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1707 | if (!cond->IsEmittedAtUseSite()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1708 | locations->SetOut(Location::RequiresRegister()); |
| 1709 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1710 | } |
| 1711 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1712 | void InstructionCodeGeneratorX86_64::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1713 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1714 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1715 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1716 | |
| 1717 | LocationSummary* locations = cond->GetLocations(); |
| 1718 | Location lhs = locations->InAt(0); |
| 1719 | Location rhs = locations->InAt(1); |
| 1720 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1721 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1722 | |
| 1723 | switch (cond->InputAt(0)->GetType()) { |
| 1724 | default: |
| 1725 | // Integer case. |
| 1726 | |
| 1727 | // Clear output register: setcc only sets the low byte. |
| 1728 | __ xorl(reg, reg); |
| 1729 | |
| 1730 | if (rhs.IsRegister()) { |
| 1731 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1732 | } else if (rhs.IsConstant()) { |
| 1733 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1734 | codegen_->Compare32BitValue(lhs.AsRegister<CpuRegister>(), constant); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1735 | } else { |
| 1736 | __ cmpl(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1737 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1738 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1739 | return; |
| 1740 | case Primitive::kPrimLong: |
| 1741 | // Clear output register: setcc only sets the low byte. |
| 1742 | __ xorl(reg, reg); |
| 1743 | |
| 1744 | if (rhs.IsRegister()) { |
| 1745 | __ cmpq(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1746 | } else if (rhs.IsConstant()) { |
| 1747 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1748 | codegen_->Compare64BitValue(lhs.AsRegister<CpuRegister>(), value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1749 | } else { |
| 1750 | __ cmpq(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1751 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1752 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1753 | return; |
| 1754 | case Primitive::kPrimFloat: { |
| 1755 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1756 | if (rhs.IsConstant()) { |
| 1757 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 1758 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 1759 | } else if (rhs.IsStackSlot()) { |
| 1760 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1761 | } else { |
| 1762 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1763 | } |
| 1764 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1765 | break; |
| 1766 | } |
| 1767 | case Primitive::kPrimDouble: { |
| 1768 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1769 | if (rhs.IsConstant()) { |
| 1770 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1771 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 1772 | } else if (rhs.IsDoubleStackSlot()) { |
| 1773 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1774 | } else { |
| 1775 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1776 | } |
| 1777 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1778 | break; |
| 1779 | } |
| 1780 | } |
| 1781 | |
| 1782 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1783 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1784 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1785 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1786 | __ Bind(&false_label); |
| 1787 | __ xorl(reg, reg); |
| 1788 | __ jmp(&done_label); |
| 1789 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1790 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1791 | __ Bind(&true_label); |
| 1792 | __ movl(reg, Immediate(1)); |
| 1793 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1794 | } |
| 1795 | |
| 1796 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1797 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1798 | } |
| 1799 | |
| 1800 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1801 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1802 | } |
| 1803 | |
| 1804 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1805 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1809 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1810 | } |
| 1811 | |
| 1812 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1813 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1814 | } |
| 1815 | |
| 1816 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1817 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1818 | } |
| 1819 | |
| 1820 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1821 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1822 | } |
| 1823 | |
| 1824 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1825 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1829 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1830 | } |
| 1831 | |
| 1832 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1833 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1834 | } |
| 1835 | |
| 1836 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1837 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1838 | } |
| 1839 | |
| 1840 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1841 | HandleCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1842 | } |
| 1843 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1844 | void LocationsBuilderX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1845 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1846 | } |
| 1847 | |
| 1848 | void InstructionCodeGeneratorX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1849 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1850 | } |
| 1851 | |
| 1852 | void LocationsBuilderX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1853 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1854 | } |
| 1855 | |
| 1856 | void InstructionCodeGeneratorX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1857 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1858 | } |
| 1859 | |
| 1860 | void LocationsBuilderX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1861 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1862 | } |
| 1863 | |
| 1864 | void InstructionCodeGeneratorX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1865 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1866 | } |
| 1867 | |
| 1868 | void LocationsBuilderX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1869 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1870 | } |
| 1871 | |
| 1872 | void InstructionCodeGeneratorX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1873 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1874 | } |
| 1875 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1876 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1877 | LocationSummary* locations = |
| 1878 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1879 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 1880 | case Primitive::kPrimBoolean: |
| 1881 | case Primitive::kPrimByte: |
| 1882 | case Primitive::kPrimShort: |
| 1883 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1884 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1885 | case Primitive::kPrimLong: { |
| 1886 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1887 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1888 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1889 | break; |
| 1890 | } |
| 1891 | case Primitive::kPrimFloat: |
| 1892 | case Primitive::kPrimDouble: { |
| 1893 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1894 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1895 | locations->SetOut(Location::RequiresRegister()); |
| 1896 | break; |
| 1897 | } |
| 1898 | default: |
| 1899 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 1900 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1901 | } |
| 1902 | |
| 1903 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1904 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1905 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1906 | Location left = locations->InAt(0); |
| 1907 | Location right = locations->InAt(1); |
| 1908 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1909 | NearLabel less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1910 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1911 | Condition less_cond = kLess; |
| 1912 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1913 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 1914 | case Primitive::kPrimBoolean: |
| 1915 | case Primitive::kPrimByte: |
| 1916 | case Primitive::kPrimShort: |
| 1917 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1918 | case Primitive::kPrimInt: { |
| 1919 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1920 | if (right.IsConstant()) { |
| 1921 | int32_t value = right.GetConstant()->AsIntConstant()->GetValue(); |
| 1922 | codegen_->Compare32BitValue(left_reg, value); |
| 1923 | } else if (right.IsStackSlot()) { |
| 1924 | __ cmpl(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1925 | } else { |
| 1926 | __ cmpl(left_reg, right.AsRegister<CpuRegister>()); |
| 1927 | } |
| 1928 | break; |
| 1929 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1930 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1931 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1932 | if (right.IsConstant()) { |
| 1933 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1934 | codegen_->Compare64BitValue(left_reg, value); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1935 | } else if (right.IsDoubleStackSlot()) { |
| 1936 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1937 | } else { |
| 1938 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1939 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1940 | break; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1941 | } |
| 1942 | case Primitive::kPrimFloat: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1943 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1944 | if (right.IsConstant()) { |
| 1945 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 1946 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 1947 | } else if (right.IsStackSlot()) { |
| 1948 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1949 | } else { |
| 1950 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1951 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1952 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1953 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1954 | break; |
| 1955 | } |
| 1956 | case Primitive::kPrimDouble: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1957 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1958 | if (right.IsConstant()) { |
| 1959 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1960 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 1961 | } else if (right.IsDoubleStackSlot()) { |
| 1962 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1963 | } else { |
| 1964 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1965 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1966 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1967 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1968 | break; |
| 1969 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1970 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1971 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1972 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1973 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1974 | __ movl(out, Immediate(0)); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1975 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1976 | __ j(less_cond, &less); |
Calin Juravle | fd86124 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1977 | |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1978 | __ Bind(&greater); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1979 | __ movl(out, Immediate(1)); |
| 1980 | __ jmp(&done); |
| 1981 | |
| 1982 | __ Bind(&less); |
| 1983 | __ movl(out, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1984 | |
| 1985 | __ Bind(&done); |
| 1986 | } |
| 1987 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1988 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1989 | LocationSummary* locations = |
| 1990 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1991 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1992 | } |
| 1993 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1994 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1995 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1996 | } |
| 1997 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1998 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 1999 | LocationSummary* locations = |
| 2000 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2001 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2002 | } |
| 2003 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2004 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2005 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2006 | } |
| 2007 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2008 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2009 | LocationSummary* locations = |
| 2010 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2011 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2012 | } |
| 2013 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2014 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2015 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2016 | } |
| 2017 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2018 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 2019 | LocationSummary* locations = |
| 2020 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2021 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2022 | } |
| 2023 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2024 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2025 | // Will be generated at use site. |
| 2026 | } |
| 2027 | |
| 2028 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2029 | LocationSummary* locations = |
| 2030 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2031 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2032 | } |
| 2033 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2034 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant( |
| 2035 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2036 | // Will be generated at use site. |
| 2037 | } |
| 2038 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2039 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2040 | memory_barrier->SetLocations(nullptr); |
| 2041 | } |
| 2042 | |
| 2043 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2044 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2045 | } |
| 2046 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2047 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 2048 | ret->SetLocations(nullptr); |
| 2049 | } |
| 2050 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2051 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2052 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2053 | } |
| 2054 | |
| 2055 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2056 | LocationSummary* locations = |
| 2057 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2058 | switch (ret->InputAt(0)->GetType()) { |
| 2059 | case Primitive::kPrimBoolean: |
| 2060 | case Primitive::kPrimByte: |
| 2061 | case Primitive::kPrimChar: |
| 2062 | case Primitive::kPrimShort: |
| 2063 | case Primitive::kPrimInt: |
| 2064 | case Primitive::kPrimNot: |
| 2065 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2066 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2067 | break; |
| 2068 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2069 | case Primitive::kPrimFloat: |
| 2070 | case Primitive::kPrimDouble: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2071 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2072 | break; |
| 2073 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2074 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2075 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2076 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2077 | } |
| 2078 | |
| 2079 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 2080 | if (kIsDebugBuild) { |
| 2081 | switch (ret->InputAt(0)->GetType()) { |
| 2082 | case Primitive::kPrimBoolean: |
| 2083 | case Primitive::kPrimByte: |
| 2084 | case Primitive::kPrimChar: |
| 2085 | case Primitive::kPrimShort: |
| 2086 | case Primitive::kPrimInt: |
| 2087 | case Primitive::kPrimNot: |
| 2088 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2089 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2090 | break; |
| 2091 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2092 | case Primitive::kPrimFloat: |
| 2093 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2094 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2095 | XMM0); |
| 2096 | break; |
| 2097 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2098 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2099 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2100 | } |
| 2101 | } |
| 2102 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2103 | } |
| 2104 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2105 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(Primitive::Type type) const { |
| 2106 | switch (type) { |
| 2107 | case Primitive::kPrimBoolean: |
| 2108 | case Primitive::kPrimByte: |
| 2109 | case Primitive::kPrimChar: |
| 2110 | case Primitive::kPrimShort: |
| 2111 | case Primitive::kPrimInt: |
| 2112 | case Primitive::kPrimNot: |
| 2113 | case Primitive::kPrimLong: |
| 2114 | return Location::RegisterLocation(RAX); |
| 2115 | |
| 2116 | case Primitive::kPrimVoid: |
| 2117 | return Location::NoLocation(); |
| 2118 | |
| 2119 | case Primitive::kPrimDouble: |
| 2120 | case Primitive::kPrimFloat: |
| 2121 | return Location::FpuRegisterLocation(XMM0); |
| 2122 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2123 | |
| 2124 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2125 | } |
| 2126 | |
| 2127 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 2128 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2129 | } |
| 2130 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2131 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2132 | switch (type) { |
| 2133 | case Primitive::kPrimBoolean: |
| 2134 | case Primitive::kPrimByte: |
| 2135 | case Primitive::kPrimChar: |
| 2136 | case Primitive::kPrimShort: |
| 2137 | case Primitive::kPrimInt: |
| 2138 | case Primitive::kPrimNot: { |
| 2139 | uint32_t index = gp_index_++; |
| 2140 | stack_index_++; |
| 2141 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2142 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2143 | } else { |
| 2144 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2145 | } |
| 2146 | } |
| 2147 | |
| 2148 | case Primitive::kPrimLong: { |
| 2149 | uint32_t index = gp_index_; |
| 2150 | stack_index_ += 2; |
| 2151 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2152 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2153 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2154 | } else { |
| 2155 | gp_index_ += 2; |
| 2156 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2157 | } |
| 2158 | } |
| 2159 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2160 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2161 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2162 | stack_index_++; |
| 2163 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2164 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2165 | } else { |
| 2166 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2167 | } |
| 2168 | } |
| 2169 | |
| 2170 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2171 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2172 | stack_index_ += 2; |
| 2173 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2174 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2175 | } else { |
| 2176 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2177 | } |
| 2178 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2179 | |
| 2180 | case Primitive::kPrimVoid: |
| 2181 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2182 | break; |
| 2183 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2184 | return Location::NoLocation(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2185 | } |
| 2186 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2187 | void LocationsBuilderX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2188 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2189 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2190 | // the method_idx. |
| 2191 | HandleInvoke(invoke); |
| 2192 | } |
| 2193 | |
| 2194 | void InstructionCodeGeneratorX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2195 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2196 | } |
| 2197 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2198 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2199 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2200 | // art::PrepareForRegisterAllocation. |
| 2201 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2202 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2203 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2204 | if (intrinsic.TryDispatch(invoke)) { |
| 2205 | return; |
| 2206 | } |
| 2207 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2208 | HandleInvoke(invoke); |
| 2209 | } |
| 2210 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2211 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 2212 | if (invoke->GetLocations()->Intrinsified()) { |
| 2213 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 2214 | intrinsic.Dispatch(invoke); |
| 2215 | return true; |
| 2216 | } |
| 2217 | return false; |
| 2218 | } |
| 2219 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2220 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2221 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2222 | // art::PrepareForRegisterAllocation. |
| 2223 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2224 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2225 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2226 | return; |
| 2227 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2228 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2229 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2230 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2231 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 2232 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2233 | } |
| 2234 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2235 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2236 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2237 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2238 | } |
| 2239 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2240 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2241 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2242 | if (intrinsic.TryDispatch(invoke)) { |
| 2243 | return; |
| 2244 | } |
| 2245 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2246 | HandleInvoke(invoke); |
| 2247 | } |
| 2248 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2249 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2250 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2251 | return; |
| 2252 | } |
| 2253 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2254 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2255 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2256 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2257 | } |
| 2258 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2259 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2260 | HandleInvoke(invoke); |
| 2261 | // Add the hidden argument. |
| 2262 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 2263 | } |
| 2264 | |
| 2265 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2266 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2267 | LocationSummary* locations = invoke->GetLocations(); |
| 2268 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2269 | CpuRegister hidden_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2270 | Location receiver = locations->InAt(0); |
| 2271 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 2272 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2273 | // Set the hidden argument. This is safe to do this here, as RAX |
| 2274 | // won't be modified thereafter, before the `call` instruction. |
| 2275 | DCHECK_EQ(RAX, hidden_reg.AsRegister()); |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2276 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2277 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2278 | if (receiver.IsStackSlot()) { |
| 2279 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2280 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2281 | __ movl(temp, Address(temp, class_offset)); |
| 2282 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2283 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2284 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2285 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2286 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2287 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2288 | // emit a read barrier for the previous class reference load. |
| 2289 | // However this is not required in practice, as this is an |
| 2290 | // intermediate/temporary reference and because the current |
| 2291 | // concurrent copying collector keeps the from-space memory |
| 2292 | // intact/accessible until the end of the marking phase (the |
| 2293 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2294 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2295 | // temp = temp->GetAddressOfIMT() |
| 2296 | __ movq(temp, |
| 2297 | Address(temp, mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
| 2298 | // temp = temp->GetImtEntryAt(method_offset); |
| 2299 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2300 | invoke->GetImtIndex(), kX86_64PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2301 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2302 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2303 | // call temp->GetEntryPoint(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2304 | __ call(Address( |
| 2305 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64PointerSize).SizeValue())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2306 | |
| 2307 | DCHECK(!codegen_->IsLeafMethod()); |
| 2308 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2309 | } |
| 2310 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2311 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 2312 | LocationSummary* locations = |
| 2313 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2314 | switch (neg->GetResultType()) { |
| 2315 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2316 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2317 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2318 | locations->SetOut(Location::SameAsFirstInput()); |
| 2319 | break; |
| 2320 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2321 | case Primitive::kPrimFloat: |
| 2322 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2323 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2324 | locations->SetOut(Location::SameAsFirstInput()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2325 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2326 | break; |
| 2327 | |
| 2328 | default: |
| 2329 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2330 | } |
| 2331 | } |
| 2332 | |
| 2333 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 2334 | LocationSummary* locations = neg->GetLocations(); |
| 2335 | Location out = locations->Out(); |
| 2336 | Location in = locations->InAt(0); |
| 2337 | switch (neg->GetResultType()) { |
| 2338 | case Primitive::kPrimInt: |
| 2339 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2340 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2341 | __ negl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2342 | break; |
| 2343 | |
| 2344 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2345 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2346 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2347 | __ negq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2348 | break; |
| 2349 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2350 | case Primitive::kPrimFloat: { |
| 2351 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2352 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2353 | // Implement float negation with an exclusive or with value |
| 2354 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2355 | // single-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2356 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2357 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2358 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2359 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2360 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2361 | case Primitive::kPrimDouble: { |
| 2362 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2363 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2364 | // Implement double negation with an exclusive or with value |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2365 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2366 | // a double-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2367 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2368 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2369 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2370 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2371 | |
| 2372 | default: |
| 2373 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2374 | } |
| 2375 | } |
| 2376 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2377 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2378 | LocationSummary* locations = |
| 2379 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 2380 | Primitive::Type result_type = conversion->GetResultType(); |
| 2381 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2382 | DCHECK_NE(result_type, input_type); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2383 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2384 | // The Java language does not allow treating boolean as an integral type but |
| 2385 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2386 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2387 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2388 | case Primitive::kPrimByte: |
| 2389 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2390 | case Primitive::kPrimLong: |
| 2391 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2392 | case Primitive::kPrimBoolean: |
| 2393 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2394 | case Primitive::kPrimShort: |
| 2395 | case Primitive::kPrimInt: |
| 2396 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2397 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2398 | locations->SetInAt(0, Location::Any()); |
| 2399 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2400 | break; |
| 2401 | |
| 2402 | default: |
| 2403 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2404 | << " to " << result_type; |
| 2405 | } |
| 2406 | break; |
| 2407 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2408 | case Primitive::kPrimShort: |
| 2409 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2410 | case Primitive::kPrimLong: |
| 2411 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2412 | case Primitive::kPrimBoolean: |
| 2413 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2414 | case Primitive::kPrimByte: |
| 2415 | case Primitive::kPrimInt: |
| 2416 | case Primitive::kPrimChar: |
| 2417 | // Processing a Dex `int-to-short' instruction. |
| 2418 | locations->SetInAt(0, Location::Any()); |
| 2419 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2420 | break; |
| 2421 | |
| 2422 | default: |
| 2423 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2424 | << " to " << result_type; |
| 2425 | } |
| 2426 | break; |
| 2427 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2428 | case Primitive::kPrimInt: |
| 2429 | switch (input_type) { |
| 2430 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2431 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2432 | locations->SetInAt(0, Location::Any()); |
| 2433 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2434 | break; |
| 2435 | |
| 2436 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2437 | // Processing a Dex `float-to-int' instruction. |
| 2438 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2439 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2440 | break; |
| 2441 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2442 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2443 | // Processing a Dex `double-to-int' instruction. |
| 2444 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2445 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2446 | break; |
| 2447 | |
| 2448 | default: |
| 2449 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2450 | << " to " << result_type; |
| 2451 | } |
| 2452 | break; |
| 2453 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2454 | case Primitive::kPrimLong: |
| 2455 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2456 | case Primitive::kPrimBoolean: |
| 2457 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2458 | case Primitive::kPrimByte: |
| 2459 | case Primitive::kPrimShort: |
| 2460 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2461 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2462 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2463 | // TODO: We would benefit from a (to-be-implemented) |
| 2464 | // Location::RegisterOrStackSlot requirement for this input. |
| 2465 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2466 | locations->SetOut(Location::RequiresRegister()); |
| 2467 | break; |
| 2468 | |
| 2469 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2470 | // Processing a Dex `float-to-long' instruction. |
| 2471 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2472 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2473 | break; |
| 2474 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2475 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2476 | // Processing a Dex `double-to-long' instruction. |
| 2477 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2478 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2479 | break; |
| 2480 | |
| 2481 | default: |
| 2482 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2483 | << " to " << result_type; |
| 2484 | } |
| 2485 | break; |
| 2486 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2487 | case Primitive::kPrimChar: |
| 2488 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2489 | case Primitive::kPrimLong: |
| 2490 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2491 | case Primitive::kPrimBoolean: |
| 2492 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2493 | case Primitive::kPrimByte: |
| 2494 | case Primitive::kPrimShort: |
| 2495 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2496 | // Processing a Dex `int-to-char' instruction. |
| 2497 | locations->SetInAt(0, Location::Any()); |
| 2498 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2499 | break; |
| 2500 | |
| 2501 | default: |
| 2502 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2503 | << " to " << result_type; |
| 2504 | } |
| 2505 | break; |
| 2506 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2507 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2508 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2509 | case Primitive::kPrimBoolean: |
| 2510 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2511 | case Primitive::kPrimByte: |
| 2512 | case Primitive::kPrimShort: |
| 2513 | case Primitive::kPrimInt: |
| 2514 | case Primitive::kPrimChar: |
| 2515 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2516 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2517 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2518 | break; |
| 2519 | |
| 2520 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2521 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2522 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2523 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2524 | break; |
| 2525 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2526 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2527 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2528 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2529 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2530 | break; |
| 2531 | |
| 2532 | default: |
| 2533 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2534 | << " to " << result_type; |
| 2535 | }; |
| 2536 | break; |
| 2537 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2538 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2539 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2540 | case Primitive::kPrimBoolean: |
| 2541 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2542 | case Primitive::kPrimByte: |
| 2543 | case Primitive::kPrimShort: |
| 2544 | case Primitive::kPrimInt: |
| 2545 | case Primitive::kPrimChar: |
| 2546 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2547 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2548 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2549 | break; |
| 2550 | |
| 2551 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2552 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2553 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2554 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2555 | break; |
| 2556 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2557 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2558 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2559 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2560 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2561 | break; |
| 2562 | |
| 2563 | default: |
| 2564 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2565 | << " to " << result_type; |
| 2566 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2567 | break; |
| 2568 | |
| 2569 | default: |
| 2570 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2571 | << " to " << result_type; |
| 2572 | } |
| 2573 | } |
| 2574 | |
| 2575 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2576 | LocationSummary* locations = conversion->GetLocations(); |
| 2577 | Location out = locations->Out(); |
| 2578 | Location in = locations->InAt(0); |
| 2579 | Primitive::Type result_type = conversion->GetResultType(); |
| 2580 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2581 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2582 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2583 | case Primitive::kPrimByte: |
| 2584 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2585 | case Primitive::kPrimLong: |
| 2586 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2587 | case Primitive::kPrimBoolean: |
| 2588 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2589 | case Primitive::kPrimShort: |
| 2590 | case Primitive::kPrimInt: |
| 2591 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2592 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2593 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2594 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2595 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2596 | __ movsxb(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2597 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2598 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2599 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2600 | Immediate(static_cast<int8_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2601 | } |
| 2602 | break; |
| 2603 | |
| 2604 | default: |
| 2605 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2606 | << " to " << result_type; |
| 2607 | } |
| 2608 | break; |
| 2609 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2610 | case Primitive::kPrimShort: |
| 2611 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2612 | case Primitive::kPrimLong: |
| 2613 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2614 | case Primitive::kPrimBoolean: |
| 2615 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2616 | case Primitive::kPrimByte: |
| 2617 | case Primitive::kPrimInt: |
| 2618 | case Primitive::kPrimChar: |
| 2619 | // Processing a Dex `int-to-short' instruction. |
| 2620 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2621 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2622 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2623 | __ movsxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2624 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2625 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2626 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2627 | Immediate(static_cast<int16_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2628 | } |
| 2629 | break; |
| 2630 | |
| 2631 | default: |
| 2632 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2633 | << " to " << result_type; |
| 2634 | } |
| 2635 | break; |
| 2636 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2637 | case Primitive::kPrimInt: |
| 2638 | switch (input_type) { |
| 2639 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2640 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2641 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2642 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2643 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2644 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2645 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2646 | } else { |
| 2647 | DCHECK(in.IsConstant()); |
| 2648 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2649 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2650 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2651 | } |
| 2652 | break; |
| 2653 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2654 | case Primitive::kPrimFloat: { |
| 2655 | // Processing a Dex `float-to-int' instruction. |
| 2656 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2657 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2658 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2659 | |
| 2660 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2661 | // if input >= (float)INT_MAX goto done |
| 2662 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimIntMax)); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2663 | __ j(kAboveEqual, &done); |
| 2664 | // if input == NaN goto nan |
| 2665 | __ j(kUnordered, &nan); |
| 2666 | // output = float-to-int-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2667 | __ cvttss2si(output, input, false); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2668 | __ jmp(&done); |
| 2669 | __ Bind(&nan); |
| 2670 | // output = 0 |
| 2671 | __ xorl(output, output); |
| 2672 | __ Bind(&done); |
| 2673 | break; |
| 2674 | } |
| 2675 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2676 | case Primitive::kPrimDouble: { |
| 2677 | // Processing a Dex `double-to-int' instruction. |
| 2678 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2679 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2680 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2681 | |
| 2682 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2683 | // if input >= (double)INT_MAX goto done |
| 2684 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2685 | __ j(kAboveEqual, &done); |
| 2686 | // if input == NaN goto nan |
| 2687 | __ j(kUnordered, &nan); |
| 2688 | // output = double-to-int-truncate(input) |
| 2689 | __ cvttsd2si(output, input); |
| 2690 | __ jmp(&done); |
| 2691 | __ Bind(&nan); |
| 2692 | // output = 0 |
| 2693 | __ xorl(output, output); |
| 2694 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2695 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2696 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2697 | |
| 2698 | default: |
| 2699 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2700 | << " to " << result_type; |
| 2701 | } |
| 2702 | break; |
| 2703 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2704 | case Primitive::kPrimLong: |
| 2705 | switch (input_type) { |
| 2706 | DCHECK(out.IsRegister()); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2707 | case Primitive::kPrimBoolean: |
| 2708 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2709 | case Primitive::kPrimByte: |
| 2710 | case Primitive::kPrimShort: |
| 2711 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2712 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2713 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2714 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2715 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2716 | break; |
| 2717 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2718 | case Primitive::kPrimFloat: { |
| 2719 | // Processing a Dex `float-to-long' instruction. |
| 2720 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2721 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2722 | NearLabel done, nan; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2723 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2724 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2725 | // if input >= (float)LONG_MAX goto done |
| 2726 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimLongMax)); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2727 | __ j(kAboveEqual, &done); |
| 2728 | // if input == NaN goto nan |
| 2729 | __ j(kUnordered, &nan); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2730 | // output = float-to-long-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2731 | __ cvttss2si(output, input, true); |
| 2732 | __ jmp(&done); |
| 2733 | __ Bind(&nan); |
| 2734 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2735 | __ xorl(output, output); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2736 | __ Bind(&done); |
| 2737 | break; |
| 2738 | } |
| 2739 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2740 | case Primitive::kPrimDouble: { |
| 2741 | // Processing a Dex `double-to-long' instruction. |
| 2742 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2743 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2744 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2745 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2746 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2747 | // if input >= (double)LONG_MAX goto done |
| 2748 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimLongMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2749 | __ j(kAboveEqual, &done); |
| 2750 | // if input == NaN goto nan |
| 2751 | __ j(kUnordered, &nan); |
| 2752 | // output = double-to-long-truncate(input) |
| 2753 | __ cvttsd2si(output, input, true); |
| 2754 | __ jmp(&done); |
| 2755 | __ Bind(&nan); |
| 2756 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2757 | __ xorl(output, output); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2758 | __ Bind(&done); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2759 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2760 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2761 | |
| 2762 | default: |
| 2763 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2764 | << " to " << result_type; |
| 2765 | } |
| 2766 | break; |
| 2767 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2768 | case Primitive::kPrimChar: |
| 2769 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2770 | case Primitive::kPrimLong: |
| 2771 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2772 | case Primitive::kPrimBoolean: |
| 2773 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2774 | case Primitive::kPrimByte: |
| 2775 | case Primitive::kPrimShort: |
| 2776 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2777 | // Processing a Dex `int-to-char' instruction. |
| 2778 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2779 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2780 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2781 | __ movzxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2782 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2783 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2784 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2785 | Immediate(static_cast<uint16_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2786 | } |
| 2787 | break; |
| 2788 | |
| 2789 | default: |
| 2790 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2791 | << " to " << result_type; |
| 2792 | } |
| 2793 | break; |
| 2794 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2795 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2796 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2797 | case Primitive::kPrimBoolean: |
| 2798 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2799 | case Primitive::kPrimByte: |
| 2800 | case Primitive::kPrimShort: |
| 2801 | case Primitive::kPrimInt: |
| 2802 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2803 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2804 | if (in.IsRegister()) { |
| 2805 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2806 | } else if (in.IsConstant()) { |
| 2807 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2808 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2809 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2810 | } else { |
| 2811 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2812 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2813 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2814 | break; |
| 2815 | |
| 2816 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2817 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2818 | if (in.IsRegister()) { |
| 2819 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2820 | } else if (in.IsConstant()) { |
| 2821 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2822 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Pavel Vyssotski | 4c858cd | 2016-03-16 13:59:53 +0600 | [diff] [blame] | 2823 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2824 | } else { |
| 2825 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2826 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2827 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2828 | break; |
| 2829 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2830 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2831 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2832 | if (in.IsFpuRegister()) { |
| 2833 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2834 | } else if (in.IsConstant()) { |
| 2835 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2836 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2837 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2838 | } else { |
| 2839 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 2840 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2841 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2842 | break; |
| 2843 | |
| 2844 | default: |
| 2845 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2846 | << " to " << result_type; |
| 2847 | }; |
| 2848 | break; |
| 2849 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2850 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2851 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2852 | case Primitive::kPrimBoolean: |
| 2853 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2854 | case Primitive::kPrimByte: |
| 2855 | case Primitive::kPrimShort: |
| 2856 | case Primitive::kPrimInt: |
| 2857 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2858 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2859 | if (in.IsRegister()) { |
| 2860 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2861 | } else if (in.IsConstant()) { |
| 2862 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2863 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2864 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2865 | } else { |
| 2866 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2867 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2868 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2869 | break; |
| 2870 | |
| 2871 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2872 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2873 | if (in.IsRegister()) { |
| 2874 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2875 | } else if (in.IsConstant()) { |
| 2876 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2877 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2878 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2879 | } else { |
| 2880 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2881 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2882 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2883 | break; |
| 2884 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2885 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2886 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2887 | if (in.IsFpuRegister()) { |
| 2888 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2889 | } else if (in.IsConstant()) { |
| 2890 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 2891 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2892 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2893 | } else { |
| 2894 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 2895 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2896 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2897 | break; |
| 2898 | |
| 2899 | default: |
| 2900 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2901 | << " to " << result_type; |
| 2902 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2903 | break; |
| 2904 | |
| 2905 | default: |
| 2906 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2907 | << " to " << result_type; |
| 2908 | } |
| 2909 | } |
| 2910 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2911 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2912 | LocationSummary* locations = |
| 2913 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2914 | switch (add->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2915 | case Primitive::kPrimInt: { |
| 2916 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2917 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2918 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2919 | break; |
| 2920 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2921 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2922 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2923 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2924 | // We can use a leaq or addq if the constant can fit in an immediate. |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 2925 | locations->SetInAt(1, Location::RegisterOrInt32Constant(add->InputAt(1))); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2926 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2927 | break; |
| 2928 | } |
| 2929 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2930 | case Primitive::kPrimDouble: |
| 2931 | case Primitive::kPrimFloat: { |
| 2932 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2933 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2934 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2935 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2936 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2937 | |
| 2938 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2939 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2940 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2941 | } |
| 2942 | |
| 2943 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 2944 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2945 | Location first = locations->InAt(0); |
| 2946 | Location second = locations->InAt(1); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2947 | Location out = locations->Out(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2948 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2949 | switch (add->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2950 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2951 | if (second.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2952 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2953 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2954 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2955 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2956 | } else { |
| 2957 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2958 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2959 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2960 | } else if (second.IsConstant()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2961 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2962 | __ addl(out.AsRegister<CpuRegister>(), |
| 2963 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 2964 | } else { |
| 2965 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2966 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 2967 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2968 | } else { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2969 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2970 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2971 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2972 | break; |
| 2973 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2974 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2975 | case Primitive::kPrimLong: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2976 | if (second.IsRegister()) { |
| 2977 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2978 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2979 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2980 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2981 | } else { |
| 2982 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2983 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2984 | } |
| 2985 | } else { |
| 2986 | DCHECK(second.IsConstant()); |
| 2987 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2988 | int32_t int32_value = Low32Bits(value); |
| 2989 | DCHECK_EQ(int32_value, value); |
| 2990 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2991 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 2992 | } else { |
| 2993 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2994 | first.AsRegister<CpuRegister>(), int32_value)); |
| 2995 | } |
| 2996 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2997 | break; |
| 2998 | } |
| 2999 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3000 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3001 | if (second.IsFpuRegister()) { |
| 3002 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3003 | } else if (second.IsConstant()) { |
| 3004 | __ addss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3005 | codegen_->LiteralFloatAddress( |
| 3006 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3007 | } else { |
| 3008 | DCHECK(second.IsStackSlot()); |
| 3009 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3010 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3011 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3012 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3013 | } |
| 3014 | |
| 3015 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3016 | if (second.IsFpuRegister()) { |
| 3017 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3018 | } else if (second.IsConstant()) { |
| 3019 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3020 | codegen_->LiteralDoubleAddress( |
| 3021 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3022 | } else { |
| 3023 | DCHECK(second.IsDoubleStackSlot()); |
| 3024 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3025 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3026 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3027 | break; |
| 3028 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3029 | |
| 3030 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3031 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3032 | } |
| 3033 | } |
| 3034 | |
| 3035 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3036 | LocationSummary* locations = |
| 3037 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3038 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3039 | case Primitive::kPrimInt: { |
| 3040 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3041 | locations->SetInAt(1, Location::Any()); |
| 3042 | locations->SetOut(Location::SameAsFirstInput()); |
| 3043 | break; |
| 3044 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3045 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3046 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 3047 | locations->SetInAt(1, Location::RegisterOrInt32Constant(sub->InputAt(1))); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3048 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3049 | break; |
| 3050 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3051 | case Primitive::kPrimFloat: |
| 3052 | case Primitive::kPrimDouble: { |
| 3053 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3054 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3055 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3056 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3057 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3058 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3059 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3060 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3061 | } |
| 3062 | |
| 3063 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 3064 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3065 | Location first = locations->InAt(0); |
| 3066 | Location second = locations->InAt(1); |
| 3067 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3068 | switch (sub->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3069 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3070 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3071 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3072 | } else if (second.IsConstant()) { |
| 3073 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3074 | __ subl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3075 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3076 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3077 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3078 | break; |
| 3079 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3080 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3081 | if (second.IsConstant()) { |
| 3082 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3083 | DCHECK(IsInt<32>(value)); |
| 3084 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 3085 | } else { |
| 3086 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 3087 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3088 | break; |
| 3089 | } |
| 3090 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3091 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3092 | if (second.IsFpuRegister()) { |
| 3093 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3094 | } else if (second.IsConstant()) { |
| 3095 | __ subss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3096 | codegen_->LiteralFloatAddress( |
| 3097 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3098 | } else { |
| 3099 | DCHECK(second.IsStackSlot()); |
| 3100 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3101 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3102 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3103 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3104 | } |
| 3105 | |
| 3106 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3107 | if (second.IsFpuRegister()) { |
| 3108 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3109 | } else if (second.IsConstant()) { |
| 3110 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3111 | codegen_->LiteralDoubleAddress( |
| 3112 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3113 | } else { |
| 3114 | DCHECK(second.IsDoubleStackSlot()); |
| 3115 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3116 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3117 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3118 | break; |
| 3119 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3120 | |
| 3121 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3122 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3123 | } |
| 3124 | } |
| 3125 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3126 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 3127 | LocationSummary* locations = |
| 3128 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3129 | switch (mul->GetResultType()) { |
| 3130 | case Primitive::kPrimInt: { |
| 3131 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3132 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3133 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3134 | // Can use 3 operand multiply. |
| 3135 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3136 | } else { |
| 3137 | locations->SetOut(Location::SameAsFirstInput()); |
| 3138 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3139 | break; |
| 3140 | } |
| 3141 | case Primitive::kPrimLong: { |
| 3142 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3143 | locations->SetInAt(1, Location::Any()); |
| 3144 | if (mul->InputAt(1)->IsLongConstant() && |
| 3145 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3146 | // Can use 3 operand multiply. |
| 3147 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3148 | } else { |
| 3149 | locations->SetOut(Location::SameAsFirstInput()); |
| 3150 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3151 | break; |
| 3152 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3153 | case Primitive::kPrimFloat: |
| 3154 | case Primitive::kPrimDouble: { |
| 3155 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3156 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3157 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3158 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3159 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3160 | |
| 3161 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3162 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3163 | } |
| 3164 | } |
| 3165 | |
| 3166 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 3167 | LocationSummary* locations = mul->GetLocations(); |
| 3168 | Location first = locations->InAt(0); |
| 3169 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3170 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3171 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3172 | case Primitive::kPrimInt: |
| 3173 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3174 | // problems where the output may not be the same as the first operand. |
| 3175 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3176 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3177 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 3178 | } else if (second.IsRegister()) { |
| 3179 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3180 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3181 | } else { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3182 | DCHECK(first.Equals(out)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3183 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3184 | __ imull(first.AsRegister<CpuRegister>(), |
| 3185 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3186 | } |
| 3187 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3188 | case Primitive::kPrimLong: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3189 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3190 | // problems where the output may not be the same as the first operand. |
| 3191 | if (mul->InputAt(1)->IsLongConstant()) { |
| 3192 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 3193 | if (IsInt<32>(value)) { |
| 3194 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 3195 | Immediate(static_cast<int32_t>(value))); |
| 3196 | } else { |
| 3197 | // Have to use the constant area. |
| 3198 | DCHECK(first.Equals(out)); |
| 3199 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 3200 | } |
| 3201 | } else if (second.IsRegister()) { |
| 3202 | DCHECK(first.Equals(out)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3203 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3204 | } else { |
| 3205 | DCHECK(second.IsDoubleStackSlot()); |
| 3206 | DCHECK(first.Equals(out)); |
| 3207 | __ imulq(first.AsRegister<CpuRegister>(), |
| 3208 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3209 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3210 | break; |
| 3211 | } |
| 3212 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3213 | case Primitive::kPrimFloat: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3214 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3215 | if (second.IsFpuRegister()) { |
| 3216 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3217 | } else if (second.IsConstant()) { |
| 3218 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3219 | codegen_->LiteralFloatAddress( |
| 3220 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3221 | } else { |
| 3222 | DCHECK(second.IsStackSlot()); |
| 3223 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3224 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3225 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3226 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3227 | } |
| 3228 | |
| 3229 | case Primitive::kPrimDouble: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3230 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3231 | if (second.IsFpuRegister()) { |
| 3232 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3233 | } else if (second.IsConstant()) { |
| 3234 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3235 | codegen_->LiteralDoubleAddress( |
| 3236 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3237 | } else { |
| 3238 | DCHECK(second.IsDoubleStackSlot()); |
| 3239 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3240 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3241 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3242 | break; |
| 3243 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3244 | |
| 3245 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3246 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3247 | } |
| 3248 | } |
| 3249 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3250 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 3251 | uint32_t stack_adjustment, bool is_float) { |
| 3252 | if (source.IsStackSlot()) { |
| 3253 | DCHECK(is_float); |
| 3254 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3255 | } else if (source.IsDoubleStackSlot()) { |
| 3256 | DCHECK(!is_float); |
| 3257 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3258 | } else { |
| 3259 | // Write the value to the temporary location on the stack and load to FP stack. |
| 3260 | if (is_float) { |
| 3261 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3262 | codegen_->Move(stack_temp, source); |
| 3263 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 3264 | } else { |
| 3265 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3266 | codegen_->Move(stack_temp, source); |
| 3267 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 3268 | } |
| 3269 | } |
| 3270 | } |
| 3271 | |
| 3272 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| 3273 | Primitive::Type type = rem->GetResultType(); |
| 3274 | bool is_float = type == Primitive::kPrimFloat; |
| 3275 | size_t elem_size = Primitive::ComponentSize(type); |
| 3276 | LocationSummary* locations = rem->GetLocations(); |
| 3277 | Location first = locations->InAt(0); |
| 3278 | Location second = locations->InAt(1); |
| 3279 | Location out = locations->Out(); |
| 3280 | |
| 3281 | // Create stack space for 2 elements. |
| 3282 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3283 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3284 | |
| 3285 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 3286 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 3287 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 3288 | |
| 3289 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3290 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3291 | __ Bind(&retry); |
| 3292 | __ fprem(); |
| 3293 | |
| 3294 | // Move FP status to AX. |
| 3295 | __ fstsw(); |
| 3296 | |
| 3297 | // And see if the argument reduction is complete. This is signaled by the |
| 3298 | // C2 FPU flag bit set to 0. |
| 3299 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 3300 | __ j(kNotEqual, &retry); |
| 3301 | |
| 3302 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3303 | // Store FP top of stack to real stack. |
| 3304 | if (is_float) { |
| 3305 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 3306 | } else { |
| 3307 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 3308 | } |
| 3309 | |
| 3310 | // Pop the 2 items from the FP stack. |
| 3311 | __ fucompp(); |
| 3312 | |
| 3313 | // Load the value from the stack into an XMM register. |
| 3314 | DCHECK(out.IsFpuRegister()) << out; |
| 3315 | if (is_float) { |
| 3316 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3317 | } else { |
| 3318 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3319 | } |
| 3320 | |
| 3321 | // And remove the temporary stack space we allocated. |
| 3322 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3323 | } |
| 3324 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3325 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3326 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3327 | |
| 3328 | LocationSummary* locations = instruction->GetLocations(); |
| 3329 | Location second = locations->InAt(1); |
| 3330 | DCHECK(second.IsConstant()); |
| 3331 | |
| 3332 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3333 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3334 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3335 | |
| 3336 | DCHECK(imm == 1 || imm == -1); |
| 3337 | |
| 3338 | switch (instruction->GetResultType()) { |
| 3339 | case Primitive::kPrimInt: { |
| 3340 | if (instruction->IsRem()) { |
| 3341 | __ xorl(output_register, output_register); |
| 3342 | } else { |
| 3343 | __ movl(output_register, input_register); |
| 3344 | if (imm == -1) { |
| 3345 | __ negl(output_register); |
| 3346 | } |
| 3347 | } |
| 3348 | break; |
| 3349 | } |
| 3350 | |
| 3351 | case Primitive::kPrimLong: { |
| 3352 | if (instruction->IsRem()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3353 | __ xorl(output_register, output_register); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3354 | } else { |
| 3355 | __ movq(output_register, input_register); |
| 3356 | if (imm == -1) { |
| 3357 | __ negq(output_register); |
| 3358 | } |
| 3359 | } |
| 3360 | break; |
| 3361 | } |
| 3362 | |
| 3363 | default: |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3364 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3365 | } |
| 3366 | } |
| 3367 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3368 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3369 | LocationSummary* locations = instruction->GetLocations(); |
| 3370 | Location second = locations->InAt(1); |
| 3371 | |
| 3372 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3373 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3374 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3375 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3376 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3377 | uint64_t abs_imm = AbsOrMin(imm); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3378 | |
| 3379 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3380 | |
| 3381 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3382 | __ leal(tmp, Address(numerator, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3383 | __ testl(numerator, numerator); |
| 3384 | __ cmov(kGreaterEqual, tmp, numerator); |
| 3385 | int shift = CTZ(imm); |
| 3386 | __ sarl(tmp, Immediate(shift)); |
| 3387 | |
| 3388 | if (imm < 0) { |
| 3389 | __ negl(tmp); |
| 3390 | } |
| 3391 | |
| 3392 | __ movl(output_register, tmp); |
| 3393 | } else { |
| 3394 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3395 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3396 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3397 | codegen_->Load64BitValue(rdx, abs_imm - 1); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3398 | __ addq(rdx, numerator); |
| 3399 | __ testq(numerator, numerator); |
| 3400 | __ cmov(kGreaterEqual, rdx, numerator); |
| 3401 | int shift = CTZ(imm); |
| 3402 | __ sarq(rdx, Immediate(shift)); |
| 3403 | |
| 3404 | if (imm < 0) { |
| 3405 | __ negq(rdx); |
| 3406 | } |
| 3407 | |
| 3408 | __ movq(output_register, rdx); |
| 3409 | } |
| 3410 | } |
| 3411 | |
| 3412 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3413 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3414 | |
| 3415 | LocationSummary* locations = instruction->GetLocations(); |
| 3416 | Location second = locations->InAt(1); |
| 3417 | |
| 3418 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 3419 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3420 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3421 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 3422 | : locations->Out().AsRegister<CpuRegister>(); |
| 3423 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3424 | |
| 3425 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 3426 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 3427 | if (instruction->IsDiv()) { |
| 3428 | DCHECK_EQ(RAX, out.AsRegister()); |
| 3429 | } else { |
| 3430 | DCHECK_EQ(RDX, out.AsRegister()); |
| 3431 | } |
| 3432 | |
| 3433 | int64_t magic; |
| 3434 | int shift; |
| 3435 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3436 | // TODO: can these branches be written as one? |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3437 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 3438 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3439 | |
| 3440 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3441 | |
| 3442 | __ movl(numerator, eax); |
| 3443 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3444 | __ movl(eax, Immediate(magic)); |
| 3445 | __ imull(numerator); |
| 3446 | |
| 3447 | if (imm > 0 && magic < 0) { |
| 3448 | __ addl(edx, numerator); |
| 3449 | } else if (imm < 0 && magic > 0) { |
| 3450 | __ subl(edx, numerator); |
| 3451 | } |
| 3452 | |
| 3453 | if (shift != 0) { |
| 3454 | __ sarl(edx, Immediate(shift)); |
| 3455 | } |
| 3456 | |
| 3457 | __ movl(eax, edx); |
| 3458 | __ shrl(edx, Immediate(31)); |
| 3459 | __ addl(edx, eax); |
| 3460 | |
| 3461 | if (instruction->IsRem()) { |
| 3462 | __ movl(eax, numerator); |
| 3463 | __ imull(edx, Immediate(imm)); |
| 3464 | __ subl(eax, edx); |
| 3465 | __ movl(edx, eax); |
| 3466 | } else { |
| 3467 | __ movl(eax, edx); |
| 3468 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3469 | } else { |
| 3470 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3471 | |
| 3472 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3473 | |
| 3474 | CpuRegister rax = eax; |
| 3475 | CpuRegister rdx = edx; |
| 3476 | |
| 3477 | CalculateMagicAndShiftForDivRem(imm, true /* is_long */, &magic, &shift); |
| 3478 | |
| 3479 | // Save the numerator. |
| 3480 | __ movq(numerator, rax); |
| 3481 | |
| 3482 | // RAX = magic |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3483 | codegen_->Load64BitValue(rax, magic); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3484 | |
| 3485 | // RDX:RAX = magic * numerator |
| 3486 | __ imulq(numerator); |
| 3487 | |
| 3488 | if (imm > 0 && magic < 0) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3489 | // RDX += numerator |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3490 | __ addq(rdx, numerator); |
| 3491 | } else if (imm < 0 && magic > 0) { |
| 3492 | // RDX -= numerator |
| 3493 | __ subq(rdx, numerator); |
| 3494 | } |
| 3495 | |
| 3496 | // Shift if needed. |
| 3497 | if (shift != 0) { |
| 3498 | __ sarq(rdx, Immediate(shift)); |
| 3499 | } |
| 3500 | |
| 3501 | // RDX += 1 if RDX < 0 |
| 3502 | __ movq(rax, rdx); |
| 3503 | __ shrq(rdx, Immediate(63)); |
| 3504 | __ addq(rdx, rax); |
| 3505 | |
| 3506 | if (instruction->IsRem()) { |
| 3507 | __ movq(rax, numerator); |
| 3508 | |
| 3509 | if (IsInt<32>(imm)) { |
| 3510 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 3511 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3512 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3513 | } |
| 3514 | |
| 3515 | __ subq(rax, rdx); |
| 3516 | __ movq(rdx, rax); |
| 3517 | } else { |
| 3518 | __ movq(rax, rdx); |
| 3519 | } |
| 3520 | } |
| 3521 | } |
| 3522 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3523 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3524 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3525 | Primitive::Type type = instruction->GetResultType(); |
| 3526 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 3527 | |
| 3528 | bool is_div = instruction->IsDiv(); |
| 3529 | LocationSummary* locations = instruction->GetLocations(); |
| 3530 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3531 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3532 | Location second = locations->InAt(1); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3533 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3534 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3535 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3536 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3537 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3538 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3539 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3540 | if (imm == 0) { |
| 3541 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3542 | } else if (imm == 1 || imm == -1) { |
| 3543 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3544 | } else if (instruction->IsDiv() && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3545 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3546 | } else { |
| 3547 | DCHECK(imm <= -2 || imm >= 2); |
| 3548 | GenerateDivRemWithAnyConstant(instruction); |
| 3549 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3550 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3551 | SlowPathCode* slow_path = |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3552 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86_64( |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3553 | instruction, out.AsRegister(), type, is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3554 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3555 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3556 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3557 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3558 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3559 | // so it's safe to just use negl instead of more complex comparisons. |
| 3560 | if (type == Primitive::kPrimInt) { |
| 3561 | __ cmpl(second_reg, Immediate(-1)); |
| 3562 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3563 | // edx:eax <- sign-extended of eax |
| 3564 | __ cdq(); |
| 3565 | // eax = quotient, edx = remainder |
| 3566 | __ idivl(second_reg); |
| 3567 | } else { |
| 3568 | __ cmpq(second_reg, Immediate(-1)); |
| 3569 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3570 | // rdx:rax <- sign-extended of rax |
| 3571 | __ cqo(); |
| 3572 | // rax = quotient, rdx = remainder |
| 3573 | __ idivq(second_reg); |
| 3574 | } |
| 3575 | __ Bind(slow_path->GetExitLabel()); |
| 3576 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3577 | } |
| 3578 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3579 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3580 | LocationSummary* locations = |
| 3581 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3582 | switch (div->GetResultType()) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3583 | case Primitive::kPrimInt: |
| 3584 | case Primitive::kPrimLong: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3585 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3586 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3587 | locations->SetOut(Location::SameAsFirstInput()); |
| 3588 | // Intel uses edx:eax as the dividend. |
| 3589 | locations->AddTemp(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3590 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3591 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3592 | // output and request another temp. |
| 3593 | if (div->InputAt(1)->IsConstant()) { |
| 3594 | locations->AddTemp(Location::RequiresRegister()); |
| 3595 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3596 | break; |
| 3597 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3598 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3599 | case Primitive::kPrimFloat: |
| 3600 | case Primitive::kPrimDouble: { |
| 3601 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3602 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3603 | locations->SetOut(Location::SameAsFirstInput()); |
| 3604 | break; |
| 3605 | } |
| 3606 | |
| 3607 | default: |
| 3608 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3609 | } |
| 3610 | } |
| 3611 | |
| 3612 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3613 | LocationSummary* locations = div->GetLocations(); |
| 3614 | Location first = locations->InAt(0); |
| 3615 | Location second = locations->InAt(1); |
| 3616 | DCHECK(first.Equals(locations->Out())); |
| 3617 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3618 | Primitive::Type type = div->GetResultType(); |
| 3619 | switch (type) { |
| 3620 | case Primitive::kPrimInt: |
| 3621 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3622 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3623 | break; |
| 3624 | } |
| 3625 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3626 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3627 | if (second.IsFpuRegister()) { |
| 3628 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3629 | } else if (second.IsConstant()) { |
| 3630 | __ divss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3631 | codegen_->LiteralFloatAddress( |
| 3632 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3633 | } else { |
| 3634 | DCHECK(second.IsStackSlot()); |
| 3635 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3636 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3637 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3638 | break; |
| 3639 | } |
| 3640 | |
| 3641 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3642 | if (second.IsFpuRegister()) { |
| 3643 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3644 | } else if (second.IsConstant()) { |
| 3645 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3646 | codegen_->LiteralDoubleAddress( |
| 3647 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3648 | } else { |
| 3649 | DCHECK(second.IsDoubleStackSlot()); |
| 3650 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3651 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3652 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3653 | break; |
| 3654 | } |
| 3655 | |
| 3656 | default: |
| 3657 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3658 | } |
| 3659 | } |
| 3660 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3661 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3662 | Primitive::Type type = rem->GetResultType(); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3663 | LocationSummary* locations = |
| 3664 | new (GetGraph()->GetArena()) LocationSummary(rem, LocationSummary::kNoCall); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3665 | |
| 3666 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3667 | case Primitive::kPrimInt: |
| 3668 | case Primitive::kPrimLong: { |
| 3669 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3670 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3671 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3672 | locations->SetOut(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3673 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3674 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3675 | // output and request another temp. |
| 3676 | if (rem->InputAt(1)->IsConstant()) { |
| 3677 | locations->AddTemp(Location::RequiresRegister()); |
| 3678 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3679 | break; |
| 3680 | } |
| 3681 | |
| 3682 | case Primitive::kPrimFloat: |
| 3683 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3684 | locations->SetInAt(0, Location::Any()); |
| 3685 | locations->SetInAt(1, Location::Any()); |
| 3686 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3687 | locations->AddTemp(Location::RegisterLocation(RAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3688 | break; |
| 3689 | } |
| 3690 | |
| 3691 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3692 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3693 | } |
| 3694 | } |
| 3695 | |
| 3696 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| 3697 | Primitive::Type type = rem->GetResultType(); |
| 3698 | switch (type) { |
| 3699 | case Primitive::kPrimInt: |
| 3700 | case Primitive::kPrimLong: { |
| 3701 | GenerateDivRemIntegral(rem); |
| 3702 | break; |
| 3703 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3704 | case Primitive::kPrimFloat: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3705 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3706 | GenerateRemFP(rem); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3707 | break; |
| 3708 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3709 | default: |
| 3710 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3711 | } |
| 3712 | } |
| 3713 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3714 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3715 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3716 | ? LocationSummary::kCallOnSlowPath |
| 3717 | : LocationSummary::kNoCall; |
| 3718 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3719 | locations->SetInAt(0, Location::Any()); |
| 3720 | if (instruction->HasUses()) { |
| 3721 | locations->SetOut(Location::SameAsFirstInput()); |
| 3722 | } |
| 3723 | } |
| 3724 | |
| 3725 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3726 | SlowPathCode* slow_path = |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3727 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction); |
| 3728 | codegen_->AddSlowPath(slow_path); |
| 3729 | |
| 3730 | LocationSummary* locations = instruction->GetLocations(); |
| 3731 | Location value = locations->InAt(0); |
| 3732 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3733 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3734 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3735 | case Primitive::kPrimByte: |
| 3736 | case Primitive::kPrimChar: |
| 3737 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3738 | case Primitive::kPrimInt: { |
| 3739 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3740 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3741 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3742 | } else if (value.IsStackSlot()) { |
| 3743 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3744 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3745 | } else { |
| 3746 | DCHECK(value.IsConstant()) << value; |
| 3747 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3748 | __ jmp(slow_path->GetEntryLabel()); |
| 3749 | } |
| 3750 | } |
| 3751 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3752 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3753 | case Primitive::kPrimLong: { |
| 3754 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3755 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3756 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3757 | } else if (value.IsDoubleStackSlot()) { |
| 3758 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3759 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3760 | } else { |
| 3761 | DCHECK(value.IsConstant()) << value; |
| 3762 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3763 | __ jmp(slow_path->GetEntryLabel()); |
| 3764 | } |
| 3765 | } |
| 3766 | break; |
| 3767 | } |
| 3768 | default: |
| 3769 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3770 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3771 | } |
| 3772 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3773 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 3774 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3775 | |
| 3776 | LocationSummary* locations = |
| 3777 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3778 | |
| 3779 | switch (op->GetResultType()) { |
| 3780 | case Primitive::kPrimInt: |
| 3781 | case Primitive::kPrimLong: { |
| 3782 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3783 | // The shift count needs to be in CL. |
| 3784 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 3785 | locations->SetOut(Location::SameAsFirstInput()); |
| 3786 | break; |
| 3787 | } |
| 3788 | default: |
| 3789 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3790 | } |
| 3791 | } |
| 3792 | |
| 3793 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 3794 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3795 | |
| 3796 | LocationSummary* locations = op->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3797 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3798 | Location second = locations->InAt(1); |
| 3799 | |
| 3800 | switch (op->GetResultType()) { |
| 3801 | case Primitive::kPrimInt: { |
| 3802 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3803 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3804 | if (op->IsShl()) { |
| 3805 | __ shll(first_reg, second_reg); |
| 3806 | } else if (op->IsShr()) { |
| 3807 | __ sarl(first_reg, second_reg); |
| 3808 | } else { |
| 3809 | __ shrl(first_reg, second_reg); |
| 3810 | } |
| 3811 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3812 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3813 | if (op->IsShl()) { |
| 3814 | __ shll(first_reg, imm); |
| 3815 | } else if (op->IsShr()) { |
| 3816 | __ sarl(first_reg, imm); |
| 3817 | } else { |
| 3818 | __ shrl(first_reg, imm); |
| 3819 | } |
| 3820 | } |
| 3821 | break; |
| 3822 | } |
| 3823 | case Primitive::kPrimLong: { |
| 3824 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3825 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3826 | if (op->IsShl()) { |
| 3827 | __ shlq(first_reg, second_reg); |
| 3828 | } else if (op->IsShr()) { |
| 3829 | __ sarq(first_reg, second_reg); |
| 3830 | } else { |
| 3831 | __ shrq(first_reg, second_reg); |
| 3832 | } |
| 3833 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3834 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3835 | if (op->IsShl()) { |
| 3836 | __ shlq(first_reg, imm); |
| 3837 | } else if (op->IsShr()) { |
| 3838 | __ sarq(first_reg, imm); |
| 3839 | } else { |
| 3840 | __ shrq(first_reg, imm); |
| 3841 | } |
| 3842 | } |
| 3843 | break; |
| 3844 | } |
| 3845 | default: |
| 3846 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3847 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3848 | } |
| 3849 | } |
| 3850 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3851 | void LocationsBuilderX86_64::VisitRor(HRor* ror) { |
| 3852 | LocationSummary* locations = |
| 3853 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3854 | |
| 3855 | switch (ror->GetResultType()) { |
| 3856 | case Primitive::kPrimInt: |
| 3857 | case Primitive::kPrimLong: { |
| 3858 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3859 | // The shift count needs to be in CL (unless it is a constant). |
| 3860 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, ror->InputAt(1))); |
| 3861 | locations->SetOut(Location::SameAsFirstInput()); |
| 3862 | break; |
| 3863 | } |
| 3864 | default: |
| 3865 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3866 | UNREACHABLE(); |
| 3867 | } |
| 3868 | } |
| 3869 | |
| 3870 | void InstructionCodeGeneratorX86_64::VisitRor(HRor* ror) { |
| 3871 | LocationSummary* locations = ror->GetLocations(); |
| 3872 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3873 | Location second = locations->InAt(1); |
| 3874 | |
| 3875 | switch (ror->GetResultType()) { |
| 3876 | case Primitive::kPrimInt: |
| 3877 | if (second.IsRegister()) { |
| 3878 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3879 | __ rorl(first_reg, second_reg); |
| 3880 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3881 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3882 | __ rorl(first_reg, imm); |
| 3883 | } |
| 3884 | break; |
| 3885 | case Primitive::kPrimLong: |
| 3886 | if (second.IsRegister()) { |
| 3887 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3888 | __ rorq(first_reg, second_reg); |
| 3889 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3890 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3891 | __ rorq(first_reg, imm); |
| 3892 | } |
| 3893 | break; |
| 3894 | default: |
| 3895 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3896 | UNREACHABLE(); |
| 3897 | } |
| 3898 | } |
| 3899 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3900 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 3901 | HandleShift(shl); |
| 3902 | } |
| 3903 | |
| 3904 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 3905 | HandleShift(shl); |
| 3906 | } |
| 3907 | |
| 3908 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 3909 | HandleShift(shr); |
| 3910 | } |
| 3911 | |
| 3912 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 3913 | HandleShift(shr); |
| 3914 | } |
| 3915 | |
| 3916 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 3917 | HandleShift(ushr); |
| 3918 | } |
| 3919 | |
| 3920 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 3921 | HandleShift(ushr); |
| 3922 | } |
| 3923 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3924 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3925 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3926 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3927 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3928 | if (instruction->IsStringAlloc()) { |
| 3929 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3930 | } else { |
| 3931 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3932 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3933 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3934 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3935 | } |
| 3936 | |
| 3937 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3938 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3939 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3940 | if (instruction->IsStringAlloc()) { |
| 3941 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3942 | CpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3943 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3944 | __ gs()->movq(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString), /* no_rip */ true)); |
| 3945 | __ call(Address(temp, code_offset.SizeValue())); |
| 3946 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3947 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame^] | 3948 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3949 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 3950 | DCHECK(!codegen_->IsLeafMethod()); |
| 3951 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3952 | } |
| 3953 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3954 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 3955 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3956 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3957 | InvokeRuntimeCallingConvention calling_convention; |
| 3958 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3959 | locations->SetOut(Location::RegisterLocation(RAX)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3960 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3961 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3962 | } |
| 3963 | |
| 3964 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| 3965 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3966 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 3967 | instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3968 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3969 | // of poisoning the reference. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame^] | 3970 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3971 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3972 | |
| 3973 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3974 | } |
| 3975 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3976 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3977 | LocationSummary* locations = |
| 3978 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3979 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3980 | if (location.IsStackSlot()) { |
| 3981 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3982 | } else if (location.IsDoubleStackSlot()) { |
| 3983 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3984 | } |
| 3985 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3986 | } |
| 3987 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3988 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 3989 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3990 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3991 | } |
| 3992 | |
| 3993 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3994 | LocationSummary* locations = |
| 3995 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3996 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3997 | } |
| 3998 | |
| 3999 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 4000 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4001 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4002 | } |
| 4003 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4004 | void LocationsBuilderX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4005 | LocationSummary* locations = |
| 4006 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4007 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4008 | locations->SetOut(Location::RequiresRegister()); |
| 4009 | } |
| 4010 | |
| 4011 | void InstructionCodeGeneratorX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4012 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4013 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4014 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4015 | instruction->GetIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4016 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4017 | Address(locations->InAt(0).AsRegister<CpuRegister>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4018 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4019 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4020 | instruction->GetIndex(), kX86_64PointerSize)); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4021 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4022 | Address(locations->InAt(0).AsRegister<CpuRegister>(), |
| 4023 | mirror::Class::ImtPtrOffset(kX86_64PointerSize).Uint32Value())); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4024 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4025 | Address(locations->Out().AsRegister<CpuRegister>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4026 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4027 | } |
| 4028 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4029 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4030 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4031 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4032 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4033 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4034 | } |
| 4035 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4036 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 4037 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4038 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4039 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4040 | Location out = locations->Out(); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4041 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4042 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4043 | __ notl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4044 | break; |
| 4045 | |
| 4046 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4047 | __ notq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4048 | break; |
| 4049 | |
| 4050 | default: |
| 4051 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4052 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4053 | } |
| 4054 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4055 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4056 | LocationSummary* locations = |
| 4057 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4058 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4059 | locations->SetOut(Location::SameAsFirstInput()); |
| 4060 | } |
| 4061 | |
| 4062 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4063 | LocationSummary* locations = bool_not->GetLocations(); |
| 4064 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4065 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 4066 | Location out = locations->Out(); |
| 4067 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 4068 | } |
| 4069 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4070 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4071 | LocationSummary* locations = |
| 4072 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4073 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4074 | locations->SetInAt(i, Location::Any()); |
| 4075 | } |
| 4076 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4077 | } |
| 4078 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4079 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4080 | LOG(FATAL) << "Unimplemented"; |
| 4081 | } |
| 4082 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4083 | void CodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4084 | /* |
| 4085 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4086 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86-64 memory model. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4087 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4088 | */ |
| 4089 | switch (kind) { |
| 4090 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4091 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4092 | break; |
| 4093 | } |
| 4094 | case MemBarrierKind::kAnyStore: |
| 4095 | case MemBarrierKind::kLoadAny: |
| 4096 | case MemBarrierKind::kStoreStore: { |
| 4097 | // nop |
| 4098 | break; |
| 4099 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4100 | case MemBarrierKind::kNTStoreStore: |
| 4101 | // Non-Temporal Store/Store needs an explicit fence. |
| 4102 | MemoryFence(/* non-temporal */ true); |
| 4103 | break; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4104 | } |
| 4105 | } |
| 4106 | |
| 4107 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 4108 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4109 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4110 | bool object_field_get_with_read_barrier = |
| 4111 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4112 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4113 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4114 | object_field_get_with_read_barrier ? |
| 4115 | LocationSummary::kCallOnSlowPath : |
| 4116 | LocationSummary::kNoCall); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4117 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4118 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4119 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4120 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4121 | // The output overlaps for an object field get when read barriers |
| 4122 | // are enabled: we do not want the move to overwrite the object's |
| 4123 | // location, as we need it to emit the read barrier. |
| 4124 | locations->SetOut( |
| 4125 | Location::RequiresRegister(), |
| 4126 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4127 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4128 | } |
| 4129 | |
| 4130 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 4131 | const FieldInfo& field_info) { |
| 4132 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4133 | |
| 4134 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4135 | Location base_loc = locations->InAt(0); |
| 4136 | CpuRegister base = base_loc.AsRegister<CpuRegister>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4137 | Location out = locations->Out(); |
| 4138 | bool is_volatile = field_info.IsVolatile(); |
| 4139 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4140 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4141 | |
| 4142 | switch (field_type) { |
| 4143 | case Primitive::kPrimBoolean: { |
| 4144 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4145 | break; |
| 4146 | } |
| 4147 | |
| 4148 | case Primitive::kPrimByte: { |
| 4149 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4150 | break; |
| 4151 | } |
| 4152 | |
| 4153 | case Primitive::kPrimShort: { |
| 4154 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4155 | break; |
| 4156 | } |
| 4157 | |
| 4158 | case Primitive::kPrimChar: { |
| 4159 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4160 | break; |
| 4161 | } |
| 4162 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4163 | case Primitive::kPrimInt: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4164 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4165 | break; |
| 4166 | } |
| 4167 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4168 | case Primitive::kPrimNot: { |
| 4169 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4170 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4171 | // Note that a potential implicit null check is handled in this |
| 4172 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4173 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4174 | instruction, out, base, offset, /* needs_null_check */ true); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4175 | if (is_volatile) { |
| 4176 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4177 | } |
| 4178 | } else { |
| 4179 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4180 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4181 | if (is_volatile) { |
| 4182 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4183 | } |
| 4184 | // If read barriers are enabled, emit read barriers other than |
| 4185 | // Baker's using a slow path (and also unpoison the loaded |
| 4186 | // reference, if heap poisoning is enabled). |
| 4187 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4188 | } |
| 4189 | break; |
| 4190 | } |
| 4191 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4192 | case Primitive::kPrimLong: { |
| 4193 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4194 | break; |
| 4195 | } |
| 4196 | |
| 4197 | case Primitive::kPrimFloat: { |
| 4198 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4199 | break; |
| 4200 | } |
| 4201 | |
| 4202 | case Primitive::kPrimDouble: { |
| 4203 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4204 | break; |
| 4205 | } |
| 4206 | |
| 4207 | case Primitive::kPrimVoid: |
| 4208 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4209 | UNREACHABLE(); |
| 4210 | } |
| 4211 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4212 | if (field_type == Primitive::kPrimNot) { |
| 4213 | // Potential implicit null checks, in the case of reference |
| 4214 | // fields, are handled in the previous switch statement. |
| 4215 | } else { |
| 4216 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4217 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4218 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4219 | if (is_volatile) { |
| 4220 | if (field_type == Primitive::kPrimNot) { |
| 4221 | // Memory barriers, in the case of references, are also handled |
| 4222 | // in the previous switch statement. |
| 4223 | } else { |
| 4224 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4225 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4226 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4227 | } |
| 4228 | |
| 4229 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 4230 | const FieldInfo& field_info) { |
| 4231 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4232 | |
| 4233 | LocationSummary* locations = |
| 4234 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4235 | Primitive::Type field_type = field_info.GetFieldType(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4236 | bool is_volatile = field_info.IsVolatile(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4237 | bool needs_write_barrier = |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4238 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4239 | |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4240 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4241 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4242 | if (is_volatile) { |
| 4243 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4244 | locations->SetInAt(1, Location::FpuRegisterOrInt32Constant(instruction->InputAt(1))); |
| 4245 | } else { |
| 4246 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4247 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4248 | } else { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4249 | if (is_volatile) { |
| 4250 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4251 | locations->SetInAt(1, Location::RegisterOrInt32Constant(instruction->InputAt(1))); |
| 4252 | } else { |
| 4253 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4254 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4255 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4256 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4257 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4258 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4259 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4260 | } else if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4261 | // Temporary register for the reference poisoning. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4262 | locations->AddTemp(Location::RequiresRegister()); |
| 4263 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4264 | } |
| 4265 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4266 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4267 | const FieldInfo& field_info, |
| 4268 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4269 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4270 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4271 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4272 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4273 | Location value = locations->InAt(1); |
| 4274 | bool is_volatile = field_info.IsVolatile(); |
| 4275 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4276 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4277 | |
| 4278 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4279 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4280 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4281 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4282 | bool maybe_record_implicit_null_check_done = false; |
| 4283 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4284 | switch (field_type) { |
| 4285 | case Primitive::kPrimBoolean: |
| 4286 | case Primitive::kPrimByte: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4287 | if (value.IsConstant()) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4288 | int8_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4289 | __ movb(Address(base, offset), Immediate(v)); |
| 4290 | } else { |
| 4291 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4292 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4293 | break; |
| 4294 | } |
| 4295 | |
| 4296 | case Primitive::kPrimShort: |
| 4297 | case Primitive::kPrimChar: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4298 | if (value.IsConstant()) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4299 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4300 | __ movw(Address(base, offset), Immediate(v)); |
| 4301 | } else { |
| 4302 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4303 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4304 | break; |
| 4305 | } |
| 4306 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4307 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4308 | case Primitive::kPrimNot: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4309 | if (value.IsConstant()) { |
| 4310 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4311 | // `field_type == Primitive::kPrimNot` implies `v == 0`. |
| 4312 | DCHECK((field_type != Primitive::kPrimNot) || (v == 0)); |
| 4313 | // Note: if heap poisoning is enabled, no need to poison |
| 4314 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 4315 | __ movl(Address(base, offset), Immediate(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4316 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4317 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4318 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4319 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4320 | __ PoisonHeapReference(temp); |
| 4321 | __ movl(Address(base, offset), temp); |
| 4322 | } else { |
| 4323 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4324 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4325 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4326 | break; |
| 4327 | } |
| 4328 | |
| 4329 | case Primitive::kPrimLong: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4330 | if (value.IsConstant()) { |
| 4331 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4332 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4333 | Address(base, offset + sizeof(int32_t)), |
| 4334 | v, |
| 4335 | instruction); |
| 4336 | maybe_record_implicit_null_check_done = true; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4337 | } else { |
| 4338 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4339 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4340 | break; |
| 4341 | } |
| 4342 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4343 | case Primitive::kPrimFloat: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4344 | if (value.IsConstant()) { |
| 4345 | int32_t v = |
| 4346 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4347 | __ movl(Address(base, offset), Immediate(v)); |
| 4348 | } else { |
| 4349 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4350 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4351 | break; |
| 4352 | } |
| 4353 | |
| 4354 | case Primitive::kPrimDouble: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4355 | if (value.IsConstant()) { |
| 4356 | int64_t v = |
| 4357 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4358 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4359 | Address(base, offset + sizeof(int32_t)), |
| 4360 | v, |
| 4361 | instruction); |
| 4362 | maybe_record_implicit_null_check_done = true; |
| 4363 | } else { |
| 4364 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4365 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4366 | break; |
| 4367 | } |
| 4368 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4369 | case Primitive::kPrimVoid: |
| 4370 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4371 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4372 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4373 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4374 | if (!maybe_record_implicit_null_check_done) { |
| 4375 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4376 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4377 | |
| 4378 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4379 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4380 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4381 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4382 | } |
| 4383 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4384 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4385 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4386 | } |
| 4387 | } |
| 4388 | |
| 4389 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4390 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4391 | } |
| 4392 | |
| 4393 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4394 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4395 | } |
| 4396 | |
| 4397 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4398 | HandleFieldGet(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4399 | } |
| 4400 | |
| 4401 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4402 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4403 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4404 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4405 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4406 | HandleFieldGet(instruction); |
| 4407 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4408 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4409 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4410 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4411 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4412 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4413 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4414 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4415 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4416 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4417 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4418 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4419 | } |
| 4420 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4421 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldGet( |
| 4422 | HUnresolvedInstanceFieldGet* instruction) { |
| 4423 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4424 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4425 | instruction, instruction->GetFieldType(), calling_convention); |
| 4426 | } |
| 4427 | |
| 4428 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldGet( |
| 4429 | HUnresolvedInstanceFieldGet* instruction) { |
| 4430 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4431 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4432 | instruction->GetFieldType(), |
| 4433 | instruction->GetFieldIndex(), |
| 4434 | instruction->GetDexPc(), |
| 4435 | calling_convention); |
| 4436 | } |
| 4437 | |
| 4438 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldSet( |
| 4439 | HUnresolvedInstanceFieldSet* instruction) { |
| 4440 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4441 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4442 | instruction, instruction->GetFieldType(), calling_convention); |
| 4443 | } |
| 4444 | |
| 4445 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldSet( |
| 4446 | HUnresolvedInstanceFieldSet* instruction) { |
| 4447 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4448 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4449 | instruction->GetFieldType(), |
| 4450 | instruction->GetFieldIndex(), |
| 4451 | instruction->GetDexPc(), |
| 4452 | calling_convention); |
| 4453 | } |
| 4454 | |
| 4455 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldGet( |
| 4456 | HUnresolvedStaticFieldGet* instruction) { |
| 4457 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4458 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4459 | instruction, instruction->GetFieldType(), calling_convention); |
| 4460 | } |
| 4461 | |
| 4462 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldGet( |
| 4463 | HUnresolvedStaticFieldGet* instruction) { |
| 4464 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4465 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4466 | instruction->GetFieldType(), |
| 4467 | instruction->GetFieldIndex(), |
| 4468 | instruction->GetDexPc(), |
| 4469 | calling_convention); |
| 4470 | } |
| 4471 | |
| 4472 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldSet( |
| 4473 | HUnresolvedStaticFieldSet* instruction) { |
| 4474 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4475 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4476 | instruction, instruction->GetFieldType(), calling_convention); |
| 4477 | } |
| 4478 | |
| 4479 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldSet( |
| 4480 | HUnresolvedStaticFieldSet* instruction) { |
| 4481 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4482 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4483 | instruction->GetFieldType(), |
| 4484 | instruction->GetFieldIndex(), |
| 4485 | instruction->GetDexPc(), |
| 4486 | calling_convention); |
| 4487 | } |
| 4488 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4489 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4490 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4491 | ? LocationSummary::kCallOnSlowPath |
| 4492 | : LocationSummary::kNoCall; |
| 4493 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4494 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4495 | ? Location::RequiresRegister() |
| 4496 | : Location::Any(); |
| 4497 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4498 | if (instruction->HasUses()) { |
| 4499 | locations->SetOut(Location::SameAsFirstInput()); |
| 4500 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4501 | } |
| 4502 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4503 | void CodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4504 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4505 | return; |
| 4506 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4507 | LocationSummary* locations = instruction->GetLocations(); |
| 4508 | Location obj = locations->InAt(0); |
| 4509 | |
| 4510 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4511 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4512 | } |
| 4513 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4514 | void CodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4515 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4516 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4517 | |
| 4518 | LocationSummary* locations = instruction->GetLocations(); |
| 4519 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4520 | |
| 4521 | if (obj.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4522 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4523 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4524 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4525 | } else { |
| 4526 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4527 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4528 | __ jmp(slow_path->GetEntryLabel()); |
| 4529 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4530 | } |
| 4531 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4532 | } |
| 4533 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4534 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4535 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4536 | } |
| 4537 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4538 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4539 | bool object_array_get_with_read_barrier = |
| 4540 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4541 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4542 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4543 | object_array_get_with_read_barrier ? |
| 4544 | LocationSummary::kCallOnSlowPath : |
| 4545 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4546 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4547 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4548 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4549 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4550 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4551 | // The output overlaps for an object array get when read barriers |
| 4552 | // are enabled: we do not want the move to overwrite the array's |
| 4553 | // location, as we need it to emit the read barrier. |
| 4554 | locations->SetOut( |
| 4555 | Location::RequiresRegister(), |
| 4556 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4557 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4558 | } |
| 4559 | |
| 4560 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 4561 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4562 | Location obj_loc = locations->InAt(0); |
| 4563 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4564 | Location index = locations->InAt(1); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4565 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 4566 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4567 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4568 | Primitive::Type type = instruction->GetType(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4569 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4570 | case Primitive::kPrimBoolean: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4571 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4572 | if (index.IsConstant()) { |
| 4573 | __ movzxb(out, Address(obj, |
| 4574 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4575 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4576 | __ movzxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4577 | } |
| 4578 | break; |
| 4579 | } |
| 4580 | |
| 4581 | case Primitive::kPrimByte: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4582 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4583 | if (index.IsConstant()) { |
| 4584 | __ movsxb(out, Address(obj, |
| 4585 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4586 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4587 | __ movsxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4588 | } |
| 4589 | break; |
| 4590 | } |
| 4591 | |
| 4592 | case Primitive::kPrimShort: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4593 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4594 | if (index.IsConstant()) { |
| 4595 | __ movsxw(out, Address(obj, |
| 4596 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4597 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4598 | __ movsxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4599 | } |
| 4600 | break; |
| 4601 | } |
| 4602 | |
| 4603 | case Primitive::kPrimChar: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4604 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4605 | if (index.IsConstant()) { |
| 4606 | __ movzxw(out, Address(obj, |
| 4607 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4608 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4609 | __ movzxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4610 | } |
| 4611 | break; |
| 4612 | } |
| 4613 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4614 | case Primitive::kPrimInt: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4615 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4616 | if (index.IsConstant()) { |
| 4617 | __ movl(out, Address(obj, |
| 4618 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4619 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4620 | __ movl(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4621 | } |
| 4622 | break; |
| 4623 | } |
| 4624 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4625 | case Primitive::kPrimNot: { |
| 4626 | static_assert( |
| 4627 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4628 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4629 | // /* HeapReference<Object> */ out = |
| 4630 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4631 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4632 | // Note that a potential implicit null check is handled in this |
| 4633 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 4634 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4635 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4636 | } else { |
| 4637 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| 4638 | if (index.IsConstant()) { |
| 4639 | uint32_t offset = |
| 4640 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4641 | __ movl(out, Address(obj, offset)); |
| 4642 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4643 | // If read barriers are enabled, emit read barriers other than |
| 4644 | // Baker's using a slow path (and also unpoison the loaded |
| 4645 | // reference, if heap poisoning is enabled). |
| 4646 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 4647 | } else { |
| 4648 | __ movl(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
| 4649 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4650 | // If read barriers are enabled, emit read barriers other than |
| 4651 | // Baker's using a slow path (and also unpoison the loaded |
| 4652 | // reference, if heap poisoning is enabled). |
| 4653 | codegen_->MaybeGenerateReadBarrierSlow( |
| 4654 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 4655 | } |
| 4656 | } |
| 4657 | break; |
| 4658 | } |
| 4659 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4660 | case Primitive::kPrimLong: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4661 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4662 | if (index.IsConstant()) { |
| 4663 | __ movq(out, Address(obj, |
| 4664 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4665 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4666 | __ movq(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4667 | } |
| 4668 | break; |
| 4669 | } |
| 4670 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4671 | case Primitive::kPrimFloat: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4672 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4673 | if (index.IsConstant()) { |
| 4674 | __ movss(out, Address(obj, |
| 4675 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4676 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4677 | __ movss(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4678 | } |
| 4679 | break; |
| 4680 | } |
| 4681 | |
| 4682 | case Primitive::kPrimDouble: { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4683 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4684 | if (index.IsConstant()) { |
| 4685 | __ movsd(out, Address(obj, |
| 4686 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4687 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4688 | __ movsd(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4689 | } |
| 4690 | break; |
| 4691 | } |
| 4692 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4693 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4694 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4695 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4696 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4697 | |
| 4698 | if (type == Primitive::kPrimNot) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4699 | // Potential implicit null checks, in the case of reference |
| 4700 | // arrays, are handled in the previous switch statement. |
| 4701 | } else { |
| 4702 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4703 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4704 | } |
| 4705 | |
| 4706 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4707 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4708 | |
| 4709 | bool needs_write_barrier = |
| 4710 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4711 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4712 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4713 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4714 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 4715 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4716 | LocationSummary::kCallOnSlowPath : |
| 4717 | LocationSummary::kNoCall); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4718 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4719 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4720 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4721 | if (Primitive::IsFloatingPointType(value_type)) { |
| 4722 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4723 | } else { |
| 4724 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 4725 | } |
| 4726 | |
| 4727 | if (needs_write_barrier) { |
| 4728 | // Temporary registers for the write barrier. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4729 | // These registers may be used for Baker read barriers too. |
| 4730 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4731 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4732 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4733 | } |
| 4734 | |
| 4735 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 4736 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4737 | Location array_loc = locations->InAt(0); |
| 4738 | CpuRegister array = array_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4739 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4740 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4741 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4742 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4743 | bool needs_write_barrier = |
| 4744 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4745 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4746 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4747 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4748 | |
| 4749 | switch (value_type) { |
| 4750 | case Primitive::kPrimBoolean: |
| 4751 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4752 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 4753 | Address address = index.IsConstant() |
| 4754 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 4755 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_1, offset); |
| 4756 | if (value.IsRegister()) { |
| 4757 | __ movb(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4758 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4759 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4760 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4761 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4762 | break; |
| 4763 | } |
| 4764 | |
| 4765 | case Primitive::kPrimShort: |
| 4766 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4767 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 4768 | Address address = index.IsConstant() |
| 4769 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 4770 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_2, offset); |
| 4771 | if (value.IsRegister()) { |
| 4772 | __ movw(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4773 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4774 | DCHECK(value.IsConstant()) << value; |
| 4775 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4776 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4777 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4778 | break; |
| 4779 | } |
| 4780 | |
| 4781 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4782 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4783 | Address address = index.IsConstant() |
| 4784 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4785 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4786 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4787 | if (!value.IsRegister()) { |
| 4788 | // Just setting null. |
| 4789 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 4790 | DCHECK(value.IsConstant()) << value; |
| 4791 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4792 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4793 | DCHECK(!needs_write_barrier); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4794 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4795 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4796 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4797 | |
| 4798 | DCHECK(needs_write_barrier); |
| 4799 | CpuRegister register_value = value.AsRegister<CpuRegister>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4800 | // We cannot use a NearLabel for `done`, as its range may be too |
| 4801 | // short when Baker read barriers are enabled. |
| 4802 | Label done; |
| 4803 | NearLabel not_null, do_put; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4804 | SlowPathCode* slow_path = nullptr; |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4805 | Location temp_loc = locations->GetTemp(0); |
| 4806 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4807 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4808 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86_64(instruction); |
| 4809 | codegen_->AddSlowPath(slow_path); |
| 4810 | if (instruction->GetValueCanBeNull()) { |
| 4811 | __ testl(register_value, register_value); |
| 4812 | __ j(kNotEqual, ¬_null); |
| 4813 | __ movl(address, Immediate(0)); |
| 4814 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4815 | __ jmp(&done); |
| 4816 | __ Bind(¬_null); |
| 4817 | } |
| 4818 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4819 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4820 | if (!kUseBakerReadBarrier) { |
| 4821 | // When (non-Baker) read barriers are enabled, the type |
| 4822 | // checking instrumentation requires two read barriers |
| 4823 | // generated by CodeGeneratorX86_64::GenerateReadBarrierSlow: |
| 4824 | // |
| 4825 | // __ movl(temp2, temp); |
| 4826 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 4827 | // __ movl(temp, Address(temp, component_offset)); |
| 4828 | // codegen_->GenerateReadBarrierSlow( |
| 4829 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 4830 | // |
| 4831 | // // /* HeapReference<Class> */ temp2 = register_value->klass_ |
| 4832 | // __ movl(temp2, Address(register_value, class_offset)); |
| 4833 | // codegen_->GenerateReadBarrierSlow( |
| 4834 | // instruction, temp2_loc, temp2_loc, value, class_offset, temp_loc); |
| 4835 | // |
| 4836 | // __ cmpl(temp, temp2); |
| 4837 | // |
| 4838 | // However, the second read barrier may trash `temp`, as it |
| 4839 | // is a temporary register, and as such would not be saved |
| 4840 | // along with live registers before calling the runtime (nor |
| 4841 | // restored afterwards). So in this case, we bail out and |
| 4842 | // delegate the work to the array set slow path. |
| 4843 | // |
| 4844 | // TODO: Extend the register allocator to support a new |
| 4845 | // "(locally) live temp" location so as to avoid always |
| 4846 | // going into the slow path when read barriers are enabled? |
| 4847 | // |
| 4848 | // There is no such problem with Baker read barriers (see below). |
| 4849 | __ jmp(slow_path->GetEntryLabel()); |
| 4850 | } else { |
| 4851 | Location temp2_loc = locations->GetTemp(1); |
| 4852 | CpuRegister temp2 = temp2_loc.AsRegister<CpuRegister>(); |
| 4853 | // /* HeapReference<Class> */ temp = array->klass_ |
| 4854 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4855 | instruction, temp_loc, array, class_offset, /* needs_null_check */ true); |
| 4856 | |
| 4857 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 4858 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4859 | instruction, temp_loc, temp, component_offset, /* needs_null_check */ false); |
| 4860 | // Register `temp` is not trashed by the read barrier |
| 4861 | // emitted by GenerateFieldLoadWithBakerReadBarrier below, |
| 4862 | // as that method produces a call to a ReadBarrierMarkRegX |
| 4863 | // entry point, which saves all potentially live registers, |
| 4864 | // including temporaries such a `temp`. |
| 4865 | // /* HeapReference<Class> */ temp2 = register_value->klass_ |
| 4866 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4867 | instruction, temp2_loc, register_value, class_offset, /* needs_null_check */ false); |
| 4868 | // If heap poisoning is enabled, `temp` and `temp2` have |
| 4869 | // been unpoisoned by the the previous calls to |
| 4870 | // CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier. |
| 4871 | __ cmpl(temp, temp2); |
| 4872 | |
| 4873 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4874 | __ j(kEqual, &do_put); |
| 4875 | // We do not need to emit a read barrier for the |
| 4876 | // following heap reference load, as `temp` is only used |
| 4877 | // in a comparison with null below, and this reference |
| 4878 | // is not kept afterwards. Also, if heap poisoning is |
| 4879 | // enabled, there is no need to unpoison that heap |
| 4880 | // reference for the same reason (comparison with null). |
| 4881 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 4882 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4883 | __ Bind(&do_put); |
| 4884 | } else { |
| 4885 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4886 | } |
| 4887 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4888 | } else { |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4889 | // Non read barrier code. |
| 4890 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4891 | // /* HeapReference<Class> */ temp = array->klass_ |
| 4892 | __ movl(temp, Address(array, class_offset)); |
| 4893 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4894 | __ MaybeUnpoisonHeapReference(temp); |
| 4895 | |
| 4896 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 4897 | __ movl(temp, Address(temp, component_offset)); |
| 4898 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 4899 | // nor the object reference in `register_value->klass`, as |
| 4900 | // we are comparing two poisoned references. |
| 4901 | __ cmpl(temp, Address(register_value, class_offset)); |
| 4902 | |
| 4903 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4904 | __ j(kEqual, &do_put); |
| 4905 | // If heap poisoning is enabled, the `temp` reference has |
| 4906 | // not been unpoisoned yet; unpoison it now. |
| 4907 | __ MaybeUnpoisonHeapReference(temp); |
| 4908 | |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 4909 | // If heap poisoning is enabled, no need to unpoison the |
| 4910 | // heap reference loaded below, as it is only used for a |
| 4911 | // comparison with null. |
| 4912 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4913 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4914 | __ Bind(&do_put); |
| 4915 | } else { |
| 4916 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4917 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4918 | } |
| 4919 | } |
| 4920 | |
| 4921 | if (kPoisonHeapReferences) { |
| 4922 | __ movl(temp, register_value); |
| 4923 | __ PoisonHeapReference(temp); |
| 4924 | __ movl(address, temp); |
| 4925 | } else { |
| 4926 | __ movl(address, register_value); |
| 4927 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4928 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4929 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4930 | } |
| 4931 | |
| 4932 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 4933 | codegen_->MarkGCCard( |
| 4934 | temp, card, array, value.AsRegister<CpuRegister>(), instruction->GetValueCanBeNull()); |
| 4935 | __ Bind(&done); |
| 4936 | |
| 4937 | if (slow_path != nullptr) { |
| 4938 | __ Bind(slow_path->GetExitLabel()); |
| 4939 | } |
| 4940 | |
| 4941 | break; |
| 4942 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4943 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4944 | case Primitive::kPrimInt: { |
| 4945 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4946 | Address address = index.IsConstant() |
| 4947 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4948 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
| 4949 | if (value.IsRegister()) { |
| 4950 | __ movl(address, value.AsRegister<CpuRegister>()); |
| 4951 | } else { |
| 4952 | DCHECK(value.IsConstant()) << value; |
| 4953 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4954 | __ movl(address, Immediate(v)); |
| 4955 | } |
| 4956 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4957 | break; |
| 4958 | } |
| 4959 | |
| 4960 | case Primitive::kPrimLong: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4961 | uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| 4962 | Address address = index.IsConstant() |
| 4963 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 4964 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset); |
| 4965 | if (value.IsRegister()) { |
| 4966 | __ movq(address, value.AsRegister<CpuRegister>()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4967 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4968 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4969 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4970 | Address address_high = index.IsConstant() |
| 4971 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 4972 | offset + sizeof(int32_t)) |
| 4973 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset + sizeof(int32_t)); |
| 4974 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4975 | } |
| 4976 | break; |
| 4977 | } |
| 4978 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4979 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4980 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4981 | Address address = index.IsConstant() |
| 4982 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4983 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4984 | if (value.IsFpuRegister()) { |
| 4985 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 4986 | } else { |
| 4987 | DCHECK(value.IsConstant()); |
| 4988 | int32_t v = |
| 4989 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4990 | __ movl(address, Immediate(v)); |
| 4991 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4992 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4993 | break; |
| 4994 | } |
| 4995 | |
| 4996 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4997 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4998 | Address address = index.IsConstant() |
| 4999 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 5000 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5001 | if (value.IsFpuRegister()) { |
| 5002 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5003 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5004 | } else { |
| 5005 | int64_t v = |
| 5006 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5007 | Address address_high = index.IsConstant() |
| 5008 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 5009 | offset + sizeof(int32_t)) |
| 5010 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset + sizeof(int32_t)); |
| 5011 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| 5012 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5013 | break; |
| 5014 | } |
| 5015 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5016 | case Primitive::kPrimVoid: |
| 5017 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5018 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5019 | } |
| 5020 | } |
| 5021 | |
| 5022 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5023 | LocationSummary* locations = |
| 5024 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5025 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5026 | if (!instruction->IsEmittedAtUseSite()) { |
| 5027 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5028 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5029 | } |
| 5030 | |
| 5031 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5032 | if (instruction->IsEmittedAtUseSite()) { |
| 5033 | return; |
| 5034 | } |
| 5035 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5036 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5037 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5038 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5039 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5040 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5041 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5042 | } |
| 5043 | |
| 5044 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5045 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 5046 | ? LocationSummary::kCallOnSlowPath |
| 5047 | : LocationSummary::kNoCall; |
| 5048 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5049 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5050 | HInstruction* length = instruction->InputAt(1); |
| 5051 | if (!length->IsEmittedAtUseSite()) { |
| 5052 | locations->SetInAt(1, Location::RegisterOrConstant(length)); |
| 5053 | } |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5054 | if (instruction->HasUses()) { |
| 5055 | locations->SetOut(Location::SameAsFirstInput()); |
| 5056 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5057 | } |
| 5058 | |
| 5059 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5060 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5061 | Location index_loc = locations->InAt(0); |
| 5062 | Location length_loc = locations->InAt(1); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5063 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5064 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5065 | if (length_loc.IsConstant()) { |
| 5066 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5067 | if (index_loc.IsConstant()) { |
| 5068 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5069 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5070 | if (index < 0 || index >= length) { |
| 5071 | codegen_->AddSlowPath(slow_path); |
| 5072 | __ jmp(slow_path->GetEntryLabel()); |
| 5073 | } else { |
| 5074 | // Some optimization after BCE may have generated this, and we should not |
| 5075 | // generate a bounds check if it is a valid range. |
| 5076 | } |
| 5077 | return; |
| 5078 | } |
| 5079 | |
| 5080 | // We have to reverse the jump condition because the length is the constant. |
| 5081 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 5082 | __ cmpl(index_reg, Immediate(length)); |
| 5083 | codegen_->AddSlowPath(slow_path); |
| 5084 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5085 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5086 | HInstruction* array_length = instruction->InputAt(1); |
| 5087 | if (array_length->IsEmittedAtUseSite()) { |
| 5088 | // Address the length field in the array. |
| 5089 | DCHECK(array_length->IsArrayLength()); |
| 5090 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5091 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5092 | Address array_len(array_loc.AsRegister<CpuRegister>(), len_offset); |
| 5093 | if (index_loc.IsConstant()) { |
| 5094 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5095 | __ cmpl(array_len, Immediate(value)); |
| 5096 | } else { |
| 5097 | __ cmpl(array_len, index_loc.AsRegister<CpuRegister>()); |
| 5098 | } |
| 5099 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5100 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5101 | CpuRegister length = length_loc.AsRegister<CpuRegister>(); |
| 5102 | if (index_loc.IsConstant()) { |
| 5103 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5104 | __ cmpl(length, Immediate(value)); |
| 5105 | } else { |
| 5106 | __ cmpl(length, index_loc.AsRegister<CpuRegister>()); |
| 5107 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5108 | } |
| 5109 | codegen_->AddSlowPath(slow_path); |
| 5110 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5111 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5112 | } |
| 5113 | |
| 5114 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 5115 | CpuRegister card, |
| 5116 | CpuRegister object, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5117 | CpuRegister value, |
| 5118 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5119 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5120 | if (value_can_be_null) { |
| 5121 | __ testl(value, value); |
| 5122 | __ j(kEqual, &is_null); |
| 5123 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5124 | __ gs()->movq(card, Address::Absolute(Thread::CardTableOffset<kX86_64PointerSize>().Int32Value(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5125 | /* no_rip */ true)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5126 | __ movq(temp, object); |
| 5127 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5128 | __ movb(Address(temp, card, TIMES_1, 0), card); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5129 | if (value_can_be_null) { |
| 5130 | __ Bind(&is_null); |
| 5131 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5132 | } |
| 5133 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5134 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5135 | LOG(FATAL) << "Unimplemented"; |
| 5136 | } |
| 5137 | |
| 5138 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5139 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5140 | } |
| 5141 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5142 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 5143 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 5144 | } |
| 5145 | |
| 5146 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5147 | HBasicBlock* block = instruction->GetBlock(); |
| 5148 | if (block->GetLoopInformation() != nullptr) { |
| 5149 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5150 | // The back edge will generate the suspend check. |
| 5151 | return; |
| 5152 | } |
| 5153 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5154 | // The goto will generate the suspend check. |
| 5155 | return; |
| 5156 | } |
| 5157 | GenerateSuspendCheck(instruction, nullptr); |
| 5158 | } |
| 5159 | |
| 5160 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5161 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5162 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5163 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 5164 | if (slow_path == nullptr) { |
| 5165 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
| 5166 | instruction->SetSlowPath(slow_path); |
| 5167 | codegen_->AddSlowPath(slow_path); |
| 5168 | if (successor != nullptr) { |
| 5169 | DCHECK(successor->IsLoopHeader()); |
| 5170 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5171 | } |
| 5172 | } else { |
| 5173 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5174 | } |
| 5175 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5176 | __ gs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86_64PointerSize>().Int32Value(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5177 | /* no_rip */ true), |
| 5178 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5179 | if (successor == nullptr) { |
| 5180 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5181 | __ Bind(slow_path->GetReturnLabel()); |
| 5182 | } else { |
| 5183 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5184 | __ jmp(slow_path->GetEntryLabel()); |
| 5185 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5186 | } |
| 5187 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5188 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 5189 | return codegen_->GetAssembler(); |
| 5190 | } |
| 5191 | |
| 5192 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5193 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5194 | Location source = move->GetSource(); |
| 5195 | Location destination = move->GetDestination(); |
| 5196 | |
| 5197 | if (source.IsRegister()) { |
| 5198 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5199 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5200 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5201 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5202 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5203 | } else { |
| 5204 | DCHECK(destination.IsDoubleStackSlot()); |
| 5205 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5206 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5207 | } |
| 5208 | } else if (source.IsStackSlot()) { |
| 5209 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5210 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5211 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5212 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5213 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5214 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5215 | } else { |
| 5216 | DCHECK(destination.IsStackSlot()); |
| 5217 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5218 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5219 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5220 | } else if (source.IsDoubleStackSlot()) { |
| 5221 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5222 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5223 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5224 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5225 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 5226 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5227 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 5228 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5229 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5230 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5231 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5232 | } else if (source.IsConstant()) { |
| 5233 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5234 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5235 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5236 | if (destination.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5237 | if (value == 0) { |
| 5238 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 5239 | } else { |
| 5240 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 5241 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5242 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5243 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5244 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5245 | } |
| 5246 | } else if (constant->IsLongConstant()) { |
| 5247 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5248 | if (destination.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5249 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5250 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5251 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5252 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5253 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5254 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5255 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5256 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5257 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5258 | codegen_->Load32BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5259 | } else { |
| 5260 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5261 | Immediate imm(bit_cast<int32_t, float>(fp_value)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5262 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 5263 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5264 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5265 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5266 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5267 | int64_t value = bit_cast<int64_t, double>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5268 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5269 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5270 | codegen_->Load64BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5271 | } else { |
| 5272 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5273 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5274 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5275 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5276 | } else if (source.IsFpuRegister()) { |
| 5277 | if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5278 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5279 | } else if (destination.IsStackSlot()) { |
| 5280 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5281 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5282 | } else { |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 5283 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5284 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5285 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5286 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5287 | } |
| 5288 | } |
| 5289 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5290 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5291 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5292 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 5293 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5294 | } |
| 5295 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5296 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5297 | ScratchRegisterScope ensure_scratch( |
| 5298 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 5299 | |
| 5300 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5301 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5302 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 5303 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5304 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5305 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5306 | CpuRegister(ensure_scratch.GetRegister())); |
| 5307 | } |
| 5308 | |
Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5309 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg1, CpuRegister reg2) { |
| 5310 | __ movq(CpuRegister(TMP), reg1); |
| 5311 | __ movq(reg1, reg2); |
| 5312 | __ movq(reg2, CpuRegister(TMP)); |
| 5313 | } |
| 5314 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5315 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 5316 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5317 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 5318 | __ movq(reg, CpuRegister(TMP)); |
| 5319 | } |
| 5320 | |
| 5321 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 5322 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5323 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5324 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5325 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5326 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5327 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 5328 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5329 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5330 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5331 | CpuRegister(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5332 | } |
| 5333 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5334 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 5335 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5336 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 5337 | __ movd(reg, CpuRegister(TMP)); |
| 5338 | } |
| 5339 | |
| 5340 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 5341 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5342 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 5343 | __ movd(reg, CpuRegister(TMP)); |
| 5344 | } |
| 5345 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5346 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5347 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5348 | Location source = move->GetSource(); |
| 5349 | Location destination = move->GetDestination(); |
| 5350 | |
| 5351 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5352 | Exchange64(source.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5353 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5354 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5355 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5356 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5357 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5358 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5359 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5360 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5361 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5362 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5363 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 5364 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5365 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5366 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 5367 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5368 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5369 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5370 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5371 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5372 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5373 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5374 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5375 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5376 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5377 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5378 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5379 | } |
| 5380 | } |
| 5381 | |
| 5382 | |
| 5383 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 5384 | __ pushq(CpuRegister(reg)); |
| 5385 | } |
| 5386 | |
| 5387 | |
| 5388 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 5389 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5390 | } |
| 5391 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5392 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5393 | SlowPathCode* slow_path, CpuRegister class_reg) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5394 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5395 | Immediate(mirror::Class::kStatusInitialized)); |
| 5396 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5397 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5398 | // No need for memory fence, thanks to the x86-64 memory model. |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5399 | } |
| 5400 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5401 | HLoadClass::LoadKind CodeGeneratorX86_64::GetSupportedLoadClassKind( |
| 5402 | HLoadClass::LoadKind desired_class_load_kind) { |
| 5403 | if (kEmitCompilerReadBarrier) { |
| 5404 | switch (desired_class_load_kind) { |
| 5405 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5406 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5407 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5408 | // TODO: Implement for read barrier. |
| 5409 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 5410 | default: |
| 5411 | break; |
| 5412 | } |
| 5413 | } |
| 5414 | switch (desired_class_load_kind) { |
| 5415 | case HLoadClass::LoadKind::kReferrersClass: |
| 5416 | break; |
| 5417 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5418 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5419 | // We prefer the always-available RIP-relative address for the x86-64 boot image. |
| 5420 | return HLoadClass::LoadKind::kBootImageLinkTimePcRelative; |
| 5421 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5422 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5423 | break; |
| 5424 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5425 | break; |
| 5426 | case HLoadClass::LoadKind::kDexCacheAddress: |
| 5427 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5428 | break; |
| 5429 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 5430 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 5431 | break; |
| 5432 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5433 | break; |
| 5434 | } |
| 5435 | return desired_class_load_kind; |
| 5436 | } |
| 5437 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5438 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5439 | if (cls->NeedsAccessCheck()) { |
| 5440 | InvokeRuntimeCallingConvention calling_convention; |
| 5441 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5442 | cls, |
| 5443 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 5444 | Location::RegisterLocation(RAX), |
| 5445 | /* code_generator_supports_read_barrier */ true); |
| 5446 | return; |
| 5447 | } |
| 5448 | |
| 5449 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || kEmitCompilerReadBarrier) |
| 5450 | ? LocationSummary::kCallOnSlowPath |
| 5451 | : LocationSummary::kNoCall; |
| 5452 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
| 5453 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5454 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 5455 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) { |
| 5456 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5457 | } |
| 5458 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5459 | } |
| 5460 | |
| 5461 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5462 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5463 | if (cls->NeedsAccessCheck()) { |
| 5464 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame^] | 5465 | codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5466 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5467 | return; |
| 5468 | } |
| 5469 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5470 | Location out_loc = locations->Out(); |
| 5471 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5472 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5473 | bool generate_null_check = false; |
| 5474 | switch (cls->GetLoadKind()) { |
| 5475 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5476 | DCHECK(!cls->CanCallRuntime()); |
| 5477 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5478 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5479 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5480 | GenerateGcRootFieldLoad( |
| 5481 | cls, out_loc, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
| 5482 | break; |
| 5483 | } |
| 5484 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5485 | DCHECK(!kEmitCompilerReadBarrier); |
| 5486 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| 5487 | codegen_->RecordTypePatch(cls); |
| 5488 | break; |
| 5489 | case HLoadClass::LoadKind::kBootImageAddress: { |
| 5490 | DCHECK(!kEmitCompilerReadBarrier); |
| 5491 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5492 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 5493 | __ movl(out, Immediate(address)); // Zero-extended. |
| 5494 | codegen_->RecordSimplePatch(); |
| 5495 | break; |
| 5496 | } |
| 5497 | case HLoadClass::LoadKind::kDexCacheAddress: { |
| 5498 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5499 | // /* GcRoot<mirror::Class> */ out = *address |
| 5500 | if (IsUint<32>(cls->GetAddress())) { |
| 5501 | Address address = Address::Absolute(cls->GetAddress(), /* no_rip */ true); |
| 5502 | GenerateGcRootFieldLoad(cls, out_loc, address); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5503 | } else { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5504 | // TODO: Consider using opcode A1, i.e. movl eax, moff32 (with 64-bit address). |
| 5505 | __ movq(out, Immediate(cls->GetAddress())); |
| 5506 | GenerateGcRootFieldLoad(cls, out_loc, Address(out, 0)); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5507 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5508 | generate_null_check = !cls->IsInDexCache(); |
| 5509 | break; |
| 5510 | } |
| 5511 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 5512 | uint32_t offset = cls->GetDexCacheElementOffset(); |
| 5513 | Label* fixup_label = codegen_->NewPcRelativeDexCacheArrayPatch(cls->GetDexFile(), offset); |
| 5514 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5515 | /* no_rip */ false); |
| 5516 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
| 5517 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label); |
| 5518 | generate_null_check = !cls->IsInDexCache(); |
| 5519 | break; |
| 5520 | } |
| 5521 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 5522 | // /* GcRoot<mirror::Class>[] */ out = |
| 5523 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5524 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5525 | __ movq(out, |
| 5526 | Address(current_method, |
| 5527 | ArtMethod::DexCacheResolvedTypesOffset(kX86_64PointerSize).Int32Value())); |
| 5528 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5529 | GenerateGcRootFieldLoad( |
| 5530 | cls, out_loc, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
| 5531 | generate_null_check = !cls->IsInDexCache(); |
| 5532 | break; |
| 5533 | } |
| 5534 | default: |
| 5535 | LOG(FATAL) << "Unexpected load kind: " << cls->GetLoadKind(); |
| 5536 | UNREACHABLE(); |
| 5537 | } |
| 5538 | |
| 5539 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5540 | DCHECK(cls->CanCallRuntime()); |
| 5541 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 5542 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5543 | codegen_->AddSlowPath(slow_path); |
| 5544 | if (generate_null_check) { |
| 5545 | __ testl(out, out); |
| 5546 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5547 | } |
| 5548 | if (cls->MustGenerateClinitCheck()) { |
| 5549 | GenerateClassInitializationCheck(slow_path, out); |
| 5550 | } else { |
| 5551 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5552 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5553 | } |
| 5554 | } |
| 5555 | |
| 5556 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 5557 | LocationSummary* locations = |
| 5558 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5559 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5560 | if (check->HasUses()) { |
| 5561 | locations->SetOut(Location::SameAsFirstInput()); |
| 5562 | } |
| 5563 | } |
| 5564 | |
| 5565 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5566 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5567 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5568 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5569 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5570 | GenerateClassInitializationCheck(slow_path, |
| 5571 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5572 | } |
| 5573 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5574 | HLoadString::LoadKind CodeGeneratorX86_64::GetSupportedLoadStringKind( |
| 5575 | HLoadString::LoadKind desired_string_load_kind) { |
| 5576 | if (kEmitCompilerReadBarrier) { |
| 5577 | switch (desired_string_load_kind) { |
| 5578 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5579 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5580 | case HLoadString::LoadKind::kBootImageAddress: |
| 5581 | // TODO: Implement for read barrier. |
| 5582 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 5583 | default: |
| 5584 | break; |
| 5585 | } |
| 5586 | } |
| 5587 | switch (desired_string_load_kind) { |
| 5588 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5589 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5590 | // We prefer the always-available RIP-relative address for the x86-64 boot image. |
| 5591 | return HLoadString::LoadKind::kBootImageLinkTimePcRelative; |
| 5592 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5593 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5594 | break; |
| 5595 | case HLoadString::LoadKind::kBootImageAddress: |
| 5596 | break; |
| 5597 | case HLoadString::LoadKind::kDexCacheAddress: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5598 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5599 | break; |
| 5600 | case HLoadString::LoadKind::kDexCachePcRelative: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5601 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5602 | break; |
| 5603 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5604 | break; |
| 5605 | } |
| 5606 | return desired_string_load_kind; |
| 5607 | } |
| 5608 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5609 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5610 | LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier) |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5611 | ? LocationSummary::kCallOnSlowPath |
| 5612 | : LocationSummary::kNoCall; |
| 5613 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5614 | if (load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) { |
| 5615 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5616 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5617 | locations->SetOut(Location::RequiresRegister()); |
| 5618 | } |
| 5619 | |
| 5620 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5621 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5622 | Location out_loc = locations->Out(); |
| 5623 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5624 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5625 | switch (load->GetLoadKind()) { |
| 5626 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 5627 | DCHECK(!kEmitCompilerReadBarrier); |
| 5628 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| 5629 | codegen_->RecordStringPatch(load); |
| 5630 | return; // No dex cache slow path. |
| 5631 | } |
| 5632 | case HLoadString::LoadKind::kBootImageAddress: { |
| 5633 | DCHECK(!kEmitCompilerReadBarrier); |
| 5634 | DCHECK_NE(load->GetAddress(), 0u); |
| 5635 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 5636 | __ movl(out, Immediate(address)); // Zero-extended. |
| 5637 | codegen_->RecordSimplePatch(); |
| 5638 | return; // No dex cache slow path. |
| 5639 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5640 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5641 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5642 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5643 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 5644 | // TODO: Re-add the compiler code to do string dex cache lookup again. |
| 5645 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86_64(load); |
| 5646 | codegen_->AddSlowPath(slow_path); |
| 5647 | __ jmp(slow_path->GetEntryLabel()); |
| 5648 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5649 | } |
| 5650 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5651 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5652 | return Address::Absolute(Thread::ExceptionOffset<kX86_64PointerSize>().Int32Value(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5653 | /* no_rip */ true); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5654 | } |
| 5655 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5656 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 5657 | LocationSummary* locations = |
| 5658 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5659 | locations->SetOut(Location::RequiresRegister()); |
| 5660 | } |
| 5661 | |
| 5662 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5663 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 5664 | } |
| 5665 | |
| 5666 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
| 5667 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5668 | } |
| 5669 | |
| 5670 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5671 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5672 | } |
| 5673 | |
| 5674 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| 5675 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 5676 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5677 | InvokeRuntimeCallingConvention calling_convention; |
| 5678 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5679 | } |
| 5680 | |
| 5681 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame^] | 5682 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5683 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5684 | } |
| 5685 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5686 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5687 | return kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5688 | !kUseBakerReadBarrier && |
| 5689 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5690 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5691 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5692 | } |
| 5693 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5694 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5695 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5696 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5697 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5698 | case TypeCheckKind::kExactCheck: |
| 5699 | case TypeCheckKind::kAbstractClassCheck: |
| 5700 | case TypeCheckKind::kClassHierarchyCheck: |
| 5701 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5702 | call_kind = |
| 5703 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5704 | break; |
| 5705 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5706 | case TypeCheckKind::kUnresolvedCheck: |
| 5707 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5708 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5709 | break; |
| 5710 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5711 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5712 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5713 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5714 | locations->SetInAt(1, Location::Any()); |
| 5715 | // Note that TypeCheckSlowPathX86_64 uses this "out" register too. |
| 5716 | locations->SetOut(Location::RequiresRegister()); |
| 5717 | // When read barriers are enabled, we need a temporary register for |
| 5718 | // some cases. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5719 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5720 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5721 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5722 | } |
| 5723 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5724 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5725 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5726 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5727 | Location obj_loc = locations->InAt(0); |
| 5728 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5729 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5730 | Location out_loc = locations->Out(); |
| 5731 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5732 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5733 | locations->GetTemp(0) : |
| 5734 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5735 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5736 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5737 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5738 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5739 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5740 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5741 | |
| 5742 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5743 | // Avoid null check if we know obj is not null. |
| 5744 | if (instruction->MustDoNullCheck()) { |
| 5745 | __ testl(obj, obj); |
| 5746 | __ j(kEqual, &zero); |
| 5747 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5748 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5749 | // /* HeapReference<Class> */ out = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5750 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5751 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5752 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5753 | case TypeCheckKind::kExactCheck: { |
| 5754 | if (cls.IsRegister()) { |
| 5755 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5756 | } else { |
| 5757 | DCHECK(cls.IsStackSlot()) << cls; |
| 5758 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5759 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5760 | if (zero.IsLinked()) { |
| 5761 | // Classes must be equal for the instanceof to succeed. |
| 5762 | __ j(kNotEqual, &zero); |
| 5763 | __ movl(out, Immediate(1)); |
| 5764 | __ jmp(&done); |
| 5765 | } else { |
| 5766 | __ setcc(kEqual, out); |
| 5767 | // setcc only sets the low byte. |
| 5768 | __ andl(out, Immediate(1)); |
| 5769 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5770 | break; |
| 5771 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5772 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5773 | case TypeCheckKind::kAbstractClassCheck: { |
| 5774 | // If the class is abstract, we eagerly fetch the super class of the |
| 5775 | // object to avoid doing a comparison we know will fail. |
| 5776 | NearLabel loop, success; |
| 5777 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5778 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5779 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5780 | __ testl(out, out); |
| 5781 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5782 | __ j(kEqual, &done); |
| 5783 | if (cls.IsRegister()) { |
| 5784 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5785 | } else { |
| 5786 | DCHECK(cls.IsStackSlot()) << cls; |
| 5787 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5788 | } |
| 5789 | __ j(kNotEqual, &loop); |
| 5790 | __ movl(out, Immediate(1)); |
| 5791 | if (zero.IsLinked()) { |
| 5792 | __ jmp(&done); |
| 5793 | } |
| 5794 | break; |
| 5795 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5796 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5797 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5798 | // Walk over the class hierarchy to find a match. |
| 5799 | NearLabel loop, success; |
| 5800 | __ Bind(&loop); |
| 5801 | if (cls.IsRegister()) { |
| 5802 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5803 | } else { |
| 5804 | DCHECK(cls.IsStackSlot()) << cls; |
| 5805 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5806 | } |
| 5807 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5808 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5809 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5810 | __ testl(out, out); |
| 5811 | __ j(kNotEqual, &loop); |
| 5812 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5813 | __ jmp(&done); |
| 5814 | __ Bind(&success); |
| 5815 | __ movl(out, Immediate(1)); |
| 5816 | if (zero.IsLinked()) { |
| 5817 | __ jmp(&done); |
| 5818 | } |
| 5819 | break; |
| 5820 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5821 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5822 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5823 | // Do an exact check. |
| 5824 | NearLabel exact_check; |
| 5825 | if (cls.IsRegister()) { |
| 5826 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5827 | } else { |
| 5828 | DCHECK(cls.IsStackSlot()) << cls; |
| 5829 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5830 | } |
| 5831 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5832 | // Otherwise, we need to check that the object's class is a non-primitive array. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5833 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5834 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5835 | __ testl(out, out); |
| 5836 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5837 | __ j(kEqual, &done); |
| 5838 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5839 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5840 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5841 | __ movl(out, Immediate(1)); |
| 5842 | __ jmp(&done); |
| 5843 | break; |
| 5844 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5845 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5846 | case TypeCheckKind::kArrayCheck: { |
| 5847 | if (cls.IsRegister()) { |
| 5848 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5849 | } else { |
| 5850 | DCHECK(cls.IsStackSlot()) << cls; |
| 5851 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5852 | } |
| 5853 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5854 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5855 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5856 | codegen_->AddSlowPath(slow_path); |
| 5857 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5858 | __ movl(out, Immediate(1)); |
| 5859 | if (zero.IsLinked()) { |
| 5860 | __ jmp(&done); |
| 5861 | } |
| 5862 | break; |
| 5863 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5864 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5865 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5866 | case TypeCheckKind::kInterfaceCheck: { |
| 5867 | // Note that we indeed only call on slow path, but we always go |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 5868 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5869 | // cases. |
| 5870 | // |
| 5871 | // We cannot directly call the InstanceofNonTrivial runtime |
| 5872 | // entry point without resorting to a type checking slow path |
| 5873 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 5874 | // require to assign fixed registers for the inputs of this |
| 5875 | // HInstanceOf instruction (following the runtime calling |
| 5876 | // convention), which might be cluttered by the potential first |
| 5877 | // read barrier emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5878 | // |
| 5879 | // TODO: Introduce a new runtime entry point taking the object |
| 5880 | // to test (instead of its class) as argument, and let it deal |
| 5881 | // with the read barrier issues. This will let us refactor this |
| 5882 | // case of the `switch` code as it was previously (with a direct |
| 5883 | // call to the runtime not using a type checking slow path). |
| 5884 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5885 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5886 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5887 | /* is_fatal */ false); |
| 5888 | codegen_->AddSlowPath(slow_path); |
| 5889 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5890 | if (zero.IsLinked()) { |
| 5891 | __ jmp(&done); |
| 5892 | } |
| 5893 | break; |
| 5894 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5895 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5896 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5897 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5898 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5899 | __ xorl(out, out); |
| 5900 | } |
| 5901 | |
| 5902 | if (done.IsLinked()) { |
| 5903 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5904 | } |
| 5905 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5906 | if (slow_path != nullptr) { |
| 5907 | __ Bind(slow_path->GetExitLabel()); |
| 5908 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5909 | } |
| 5910 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5911 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5912 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5913 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5914 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5915 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5916 | case TypeCheckKind::kExactCheck: |
| 5917 | case TypeCheckKind::kAbstractClassCheck: |
| 5918 | case TypeCheckKind::kClassHierarchyCheck: |
| 5919 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5920 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 5921 | LocationSummary::kCallOnSlowPath : |
| 5922 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5923 | break; |
| 5924 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5925 | case TypeCheckKind::kUnresolvedCheck: |
| 5926 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5927 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5928 | break; |
| 5929 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5930 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 5931 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5932 | locations->SetInAt(1, Location::Any()); |
| 5933 | // Note that TypeCheckSlowPathX86_64 uses this "temp" register too. |
| 5934 | locations->AddTemp(Location::RequiresRegister()); |
| 5935 | // When read barriers are enabled, we need an additional temporary |
| 5936 | // register for some cases. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5937 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5938 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5939 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5940 | } |
| 5941 | |
| 5942 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5943 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5944 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5945 | Location obj_loc = locations->InAt(0); |
| 5946 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5947 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5948 | Location temp_loc = locations->GetTemp(0); |
| 5949 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5950 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5951 | locations->GetTemp(1) : |
| 5952 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5953 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5954 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5955 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5956 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5957 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5958 | bool is_type_check_slow_path_fatal = |
| 5959 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 5960 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5961 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5962 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 5963 | !instruction->CanThrowIntoCatchBlock(); |
| 5964 | SlowPathCode* type_check_slow_path = |
| 5965 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5966 | is_type_check_slow_path_fatal); |
| 5967 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5968 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5969 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5970 | case TypeCheckKind::kExactCheck: |
| 5971 | case TypeCheckKind::kArrayCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5972 | NearLabel done; |
| 5973 | // Avoid null check if we know obj is not null. |
| 5974 | if (instruction->MustDoNullCheck()) { |
| 5975 | __ testl(obj, obj); |
| 5976 | __ j(kEqual, &done); |
| 5977 | } |
| 5978 | |
| 5979 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5980 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5981 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5982 | if (cls.IsRegister()) { |
| 5983 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5984 | } else { |
| 5985 | DCHECK(cls.IsStackSlot()) << cls; |
| 5986 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5987 | } |
| 5988 | // Jump to slow path for throwing the exception or doing a |
| 5989 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5990 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5991 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5992 | break; |
| 5993 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5994 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5995 | case TypeCheckKind::kAbstractClassCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5996 | NearLabel done; |
| 5997 | // Avoid null check if we know obj is not null. |
| 5998 | if (instruction->MustDoNullCheck()) { |
| 5999 | __ testl(obj, obj); |
| 6000 | __ j(kEqual, &done); |
| 6001 | } |
| 6002 | |
| 6003 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6004 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6005 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6006 | // If the class is abstract, we eagerly fetch the super class of the |
| 6007 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6008 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6009 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6010 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6011 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6012 | |
| 6013 | // If the class reference currently in `temp` is not null, jump |
| 6014 | // to the `compare_classes` label to compare it with the checked |
| 6015 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6016 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6017 | __ j(kNotEqual, &compare_classes); |
| 6018 | // Otherwise, jump to the slow path to throw the exception. |
| 6019 | // |
| 6020 | // But before, move back the object's class into `temp` before |
| 6021 | // going into the slow path, as it has been overwritten in the |
| 6022 | // meantime. |
| 6023 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6024 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6025 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6026 | |
| 6027 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6028 | if (cls.IsRegister()) { |
| 6029 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6030 | } else { |
| 6031 | DCHECK(cls.IsStackSlot()) << cls; |
| 6032 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6033 | } |
| 6034 | __ j(kNotEqual, &loop); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6035 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6036 | break; |
| 6037 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6038 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6039 | case TypeCheckKind::kClassHierarchyCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6040 | NearLabel done; |
| 6041 | // Avoid null check if we know obj is not null. |
| 6042 | if (instruction->MustDoNullCheck()) { |
| 6043 | __ testl(obj, obj); |
| 6044 | __ j(kEqual, &done); |
| 6045 | } |
| 6046 | |
| 6047 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6048 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6049 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6050 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6051 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6052 | __ Bind(&loop); |
| 6053 | if (cls.IsRegister()) { |
| 6054 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6055 | } else { |
| 6056 | DCHECK(cls.IsStackSlot()) << cls; |
| 6057 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6058 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6059 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6060 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6061 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6062 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6063 | |
| 6064 | // If the class reference currently in `temp` is not null, jump |
| 6065 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6066 | __ testl(temp, temp); |
| 6067 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6068 | // Otherwise, jump to the slow path to throw the exception. |
| 6069 | // |
| 6070 | // But before, move back the object's class into `temp` before |
| 6071 | // going into the slow path, as it has been overwritten in the |
| 6072 | // meantime. |
| 6073 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6074 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6075 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6076 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6077 | break; |
| 6078 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6079 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6080 | case TypeCheckKind::kArrayObjectCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6081 | // We cannot use a NearLabel here, as its range might be too |
| 6082 | // short in some cases when read barriers are enabled. This has |
| 6083 | // been observed for instance when the code emitted for this |
| 6084 | // case uses high x86-64 registers (R8-R15). |
| 6085 | Label done; |
| 6086 | // Avoid null check if we know obj is not null. |
| 6087 | if (instruction->MustDoNullCheck()) { |
| 6088 | __ testl(obj, obj); |
| 6089 | __ j(kEqual, &done); |
| 6090 | } |
| 6091 | |
| 6092 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6093 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6094 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6095 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6096 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6097 | if (cls.IsRegister()) { |
| 6098 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 6099 | } else { |
| 6100 | DCHECK(cls.IsStackSlot()) << cls; |
| 6101 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 6102 | } |
| 6103 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6104 | |
| 6105 | // Otherwise, we need to check that the object's class is a non-primitive array. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6106 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6107 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6108 | |
| 6109 | // If the component type is not null (i.e. the object is indeed |
| 6110 | // an array), jump to label `check_non_primitive_component_type` |
| 6111 | // to further check that this component type is not a primitive |
| 6112 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6113 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6114 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 6115 | // Otherwise, jump to the slow path to throw the exception. |
| 6116 | // |
| 6117 | // But before, move back the object's class into `temp` before |
| 6118 | // going into the slow path, as it has been overwritten in the |
| 6119 | // meantime. |
| 6120 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6121 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6122 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6123 | |
| 6124 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6125 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6126 | __ j(kEqual, &done); |
| 6127 | // Same comment as above regarding `temp` and the slow path. |
| 6128 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6129 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6130 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6131 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6132 | break; |
| 6133 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6134 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6135 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6136 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6137 | NearLabel done; |
| 6138 | // Avoid null check if we know obj is not null. |
| 6139 | if (instruction->MustDoNullCheck()) { |
| 6140 | __ testl(obj, obj); |
| 6141 | __ j(kEqual, &done); |
| 6142 | } |
| 6143 | |
| 6144 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6145 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6146 | |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6147 | // We always go into the type check slow path for the unresolved |
| 6148 | // and interface check cases. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6149 | // |
| 6150 | // We cannot directly call the CheckCast runtime entry point |
| 6151 | // without resorting to a type checking slow path here (i.e. by |
| 6152 | // calling InvokeRuntime directly), as it would require to |
| 6153 | // assign fixed registers for the inputs of this HInstanceOf |
| 6154 | // instruction (following the runtime calling convention), which |
| 6155 | // might be cluttered by the potential first read barrier |
| 6156 | // emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6157 | // |
| 6158 | // TODO: Introduce a new runtime entry point taking the object |
| 6159 | // to test (instead of its class) as argument, and let it deal |
| 6160 | // with the read barrier issues. This will let us refactor this |
| 6161 | // case of the `switch` code as it was previously (with a direct |
| 6162 | // call to the runtime not using a type checking slow path). |
| 6163 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6164 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6165 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6166 | break; |
| 6167 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6168 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6169 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6170 | } |
| 6171 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6172 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6173 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6174 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6175 | InvokeRuntimeCallingConvention calling_convention; |
| 6176 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6177 | } |
| 6178 | |
| 6179 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame^] | 6180 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6181 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame^] | 6182 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6183 | if (instruction->IsEnter()) { |
| 6184 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6185 | } else { |
| 6186 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6187 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6188 | } |
| 6189 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6190 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6191 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6192 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6193 | |
| 6194 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6195 | LocationSummary* locations = |
| 6196 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6197 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6198 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6199 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6200 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6201 | locations->SetOut(Location::SameAsFirstInput()); |
| 6202 | } |
| 6203 | |
| 6204 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 6205 | HandleBitwiseOperation(instruction); |
| 6206 | } |
| 6207 | |
| 6208 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 6209 | HandleBitwiseOperation(instruction); |
| 6210 | } |
| 6211 | |
| 6212 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 6213 | HandleBitwiseOperation(instruction); |
| 6214 | } |
| 6215 | |
| 6216 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6217 | LocationSummary* locations = instruction->GetLocations(); |
| 6218 | Location first = locations->InAt(0); |
| 6219 | Location second = locations->InAt(1); |
| 6220 | DCHECK(first.Equals(locations->Out())); |
| 6221 | |
| 6222 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6223 | if (second.IsRegister()) { |
| 6224 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6225 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6226 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6227 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6228 | } else { |
| 6229 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6230 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6231 | } |
| 6232 | } else if (second.IsConstant()) { |
| 6233 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 6234 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6235 | __ andl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6236 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6237 | __ orl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6238 | } else { |
| 6239 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6240 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6241 | } |
| 6242 | } else { |
| 6243 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 6244 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6245 | __ andl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6246 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6247 | __ orl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6248 | } else { |
| 6249 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6250 | __ xorl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6251 | } |
| 6252 | } |
| 6253 | } else { |
| 6254 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6255 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 6256 | bool second_is_constant = false; |
| 6257 | int64_t value = 0; |
| 6258 | if (second.IsConstant()) { |
| 6259 | second_is_constant = true; |
| 6260 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6261 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6262 | bool is_int32_value = IsInt<32>(value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6263 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6264 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6265 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6266 | if (is_int32_value) { |
| 6267 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6268 | } else { |
| 6269 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6270 | } |
| 6271 | } else if (second.IsDoubleStackSlot()) { |
| 6272 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6273 | } else { |
| 6274 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 6275 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6276 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6277 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6278 | if (is_int32_value) { |
| 6279 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6280 | } else { |
| 6281 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6282 | } |
| 6283 | } else if (second.IsDoubleStackSlot()) { |
| 6284 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6285 | } else { |
| 6286 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 6287 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6288 | } else { |
| 6289 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6290 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6291 | if (is_int32_value) { |
| 6292 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6293 | } else { |
| 6294 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6295 | } |
| 6296 | } else if (second.IsDoubleStackSlot()) { |
| 6297 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6298 | } else { |
| 6299 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 6300 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6301 | } |
| 6302 | } |
| 6303 | } |
| 6304 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6305 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6306 | Location out, |
| 6307 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6308 | Location maybe_temp) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6309 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6310 | if (kEmitCompilerReadBarrier) { |
| 6311 | if (kUseBakerReadBarrier) { |
| 6312 | // Load with fast path based Baker's read barrier. |
| 6313 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6314 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6315 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6316 | } else { |
| 6317 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6318 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6319 | // in the following move operation, as we will need it for the |
| 6320 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6321 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6322 | __ movl(maybe_temp.AsRegister<CpuRegister>(), out_reg); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6323 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6324 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6325 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6326 | } |
| 6327 | } else { |
| 6328 | // Plain load with no read barrier. |
| 6329 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6330 | __ movl(out_reg, Address(out_reg, offset)); |
| 6331 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6332 | } |
| 6333 | } |
| 6334 | |
| 6335 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6336 | Location out, |
| 6337 | Location obj, |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6338 | uint32_t offset) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6339 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6340 | CpuRegister obj_reg = obj.AsRegister<CpuRegister>(); |
| 6341 | if (kEmitCompilerReadBarrier) { |
| 6342 | if (kUseBakerReadBarrier) { |
| 6343 | // Load with fast path based Baker's read barrier. |
| 6344 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6345 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6346 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6347 | } else { |
| 6348 | // Load with slow path based read barrier. |
| 6349 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6350 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6351 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6352 | } |
| 6353 | } else { |
| 6354 | // Plain load with no read barrier. |
| 6355 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6356 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6357 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6358 | } |
| 6359 | } |
| 6360 | |
| 6361 | void InstructionCodeGeneratorX86_64::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6362 | Location root, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6363 | const Address& address, |
| 6364 | Label* fixup_label) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6365 | CpuRegister root_reg = root.AsRegister<CpuRegister>(); |
| 6366 | if (kEmitCompilerReadBarrier) { |
| 6367 | if (kUseBakerReadBarrier) { |
| 6368 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6369 | // Baker's read barrier are used: |
| 6370 | // |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6371 | // root = *address; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6372 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6373 | // root = ReadBarrier::Mark(root) |
| 6374 | // } |
| 6375 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6376 | // /* GcRoot<mirror::Object> */ root = *address |
| 6377 | __ movl(root_reg, address); |
| 6378 | if (fixup_label != nullptr) { |
| 6379 | __ Bind(fixup_label); |
| 6380 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6381 | static_assert( |
| 6382 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6383 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6384 | "have different sizes."); |
| 6385 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6386 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6387 | "have different sizes."); |
| 6388 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6389 | // Slow path marking the GC root `root`. |
| 6390 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64( |
| 6391 | instruction, root, /* unpoison */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6392 | codegen_->AddSlowPath(slow_path); |
| 6393 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6394 | __ gs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86_64PointerSize>().Int32Value(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6395 | /* no_rip */ true), |
| 6396 | Immediate(0)); |
| 6397 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6398 | __ Bind(slow_path->GetExitLabel()); |
| 6399 | } else { |
| 6400 | // GC root loaded through a slow path for read barriers other |
| 6401 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6402 | // /* GcRoot<mirror::Object>* */ root = address |
| 6403 | __ leaq(root_reg, address); |
| 6404 | if (fixup_label != nullptr) { |
| 6405 | __ Bind(fixup_label); |
| 6406 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6407 | // /* mirror::Object* */ root = root->Read() |
| 6408 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6409 | } |
| 6410 | } else { |
| 6411 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6412 | // /* GcRoot<mirror::Object> */ root = *address |
| 6413 | __ movl(root_reg, address); |
| 6414 | if (fixup_label != nullptr) { |
| 6415 | __ Bind(fixup_label); |
| 6416 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6417 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6418 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6419 | } |
| 6420 | } |
| 6421 | |
| 6422 | void CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6423 | Location ref, |
| 6424 | CpuRegister obj, |
| 6425 | uint32_t offset, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6426 | bool needs_null_check) { |
| 6427 | DCHECK(kEmitCompilerReadBarrier); |
| 6428 | DCHECK(kUseBakerReadBarrier); |
| 6429 | |
| 6430 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6431 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6432 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6433 | } |
| 6434 | |
| 6435 | void CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6436 | Location ref, |
| 6437 | CpuRegister obj, |
| 6438 | uint32_t data_offset, |
| 6439 | Location index, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6440 | bool needs_null_check) { |
| 6441 | DCHECK(kEmitCompilerReadBarrier); |
| 6442 | DCHECK(kUseBakerReadBarrier); |
| 6443 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 6444 | static_assert( |
| 6445 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6446 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6447 | // /* HeapReference<Object> */ ref = |
| 6448 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6449 | Address src = index.IsConstant() ? |
| 6450 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset) : |
| 6451 | Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6452 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6453 | } |
| 6454 | |
| 6455 | void CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6456 | Location ref, |
| 6457 | CpuRegister obj, |
| 6458 | const Address& src, |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6459 | bool needs_null_check) { |
| 6460 | DCHECK(kEmitCompilerReadBarrier); |
| 6461 | DCHECK(kUseBakerReadBarrier); |
| 6462 | |
| 6463 | // In slow path based read barriers, the read barrier call is |
| 6464 | // inserted after the original load. However, in fast path based |
| 6465 | // Baker's read barriers, we need to perform the load of |
| 6466 | // mirror::Object::monitor_ *before* the original reference load. |
| 6467 | // This load-load ordering is required by the read barrier. |
| 6468 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6469 | // |
| 6470 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6471 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6472 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6473 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6474 | // if (is_gray) { |
| 6475 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6476 | // } |
| 6477 | // |
| 6478 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6479 | // slightly more complex as: |
| 6480 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6481 | // the high-bits of rb_state, which are expected to be all zeroes |
| 6482 | // (we use CodeGeneratorX86_64::GenerateMemoryBarrier instead |
| 6483 | // here, which is a no-op thanks to the x86-64 memory model); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6484 | // - it performs additional checks that we do not do here for |
| 6485 | // performance reasons. |
| 6486 | |
| 6487 | CpuRegister ref_reg = ref.AsRegister<CpuRegister>(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6488 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6489 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6490 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 6491 | static_assert(ReadBarrier::white_ptr_ == 0, "Expecting white to have value 0"); |
| 6492 | static_assert(ReadBarrier::gray_ptr_ == 1, "Expecting gray to have value 1"); |
| 6493 | static_assert(ReadBarrier::black_ptr_ == 2, "Expecting black to have value 2"); |
| 6494 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 6495 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 6496 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 6497 | |
| 6498 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6499 | // ref = ReadBarrier::Mark(ref); |
| 6500 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 6501 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6502 | if (needs_null_check) { |
| 6503 | MaybeRecordImplicitNullCheck(instruction); |
| 6504 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6505 | |
| 6506 | // Load fence to prevent load-load reordering. |
| 6507 | // Note that this is a no-op, thanks to the x86-64 memory model. |
| 6508 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6509 | |
| 6510 | // The actual reference load. |
| 6511 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6512 | __ movl(ref_reg, src); // Flags are unaffected. |
| 6513 | |
| 6514 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 6515 | // Slow path marking the object `ref` when it is gray. |
| 6516 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64( |
| 6517 | instruction, ref, /* unpoison */ true); |
| 6518 | AddSlowPath(slow_path); |
| 6519 | |
| 6520 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 6521 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6522 | |
| 6523 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6524 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6525 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6526 | __ Bind(slow_path->GetExitLabel()); |
| 6527 | } |
| 6528 | |
| 6529 | void CodeGeneratorX86_64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6530 | Location out, |
| 6531 | Location ref, |
| 6532 | Location obj, |
| 6533 | uint32_t offset, |
| 6534 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6535 | DCHECK(kEmitCompilerReadBarrier); |
| 6536 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6537 | // Insert a slow path based read barrier *after* the reference load. |
| 6538 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6539 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6540 | // reference will be carried out by the runtime within the slow |
| 6541 | // path. |
| 6542 | // |
| 6543 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6544 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6545 | // not used by the artReadBarrierSlow entry point. |
| 6546 | // |
| 6547 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6548 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6549 | ReadBarrierForHeapReferenceSlowPathX86_64(instruction, out, ref, obj, offset, index); |
| 6550 | AddSlowPath(slow_path); |
| 6551 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6552 | __ jmp(slow_path->GetEntryLabel()); |
| 6553 | __ Bind(slow_path->GetExitLabel()); |
| 6554 | } |
| 6555 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6556 | void CodeGeneratorX86_64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6557 | Location out, |
| 6558 | Location ref, |
| 6559 | Location obj, |
| 6560 | uint32_t offset, |
| 6561 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6562 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6563 | // Baker's read barriers shall be handled by the fast path |
| 6564 | // (CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6565 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6566 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6567 | // by the runtime within the slow path. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6568 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6569 | } else if (kPoisonHeapReferences) { |
| 6570 | __ UnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 6571 | } |
| 6572 | } |
| 6573 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6574 | void CodeGeneratorX86_64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6575 | Location out, |
| 6576 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6577 | DCHECK(kEmitCompilerReadBarrier); |
| 6578 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6579 | // Insert a slow path based read barrier *after* the GC root load. |
| 6580 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6581 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6582 | // not need to do anything special for this here. |
| 6583 | SlowPathCode* slow_path = |
| 6584 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86_64(instruction, out, root); |
| 6585 | AddSlowPath(slow_path); |
| 6586 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6587 | __ jmp(slow_path->GetEntryLabel()); |
| 6588 | __ Bind(slow_path->GetExitLabel()); |
| 6589 | } |
| 6590 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6591 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6592 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6593 | LOG(FATAL) << "Unreachable"; |
| 6594 | } |
| 6595 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6596 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6597 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6598 | LOG(FATAL) << "Unreachable"; |
| 6599 | } |
| 6600 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6601 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6602 | void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6603 | LocationSummary* locations = |
| 6604 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6605 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6606 | locations->AddTemp(Location::RequiresRegister()); |
| 6607 | locations->AddTemp(Location::RequiresRegister()); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6608 | } |
| 6609 | |
| 6610 | void InstructionCodeGeneratorX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6611 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6612 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6613 | LocationSummary* locations = switch_instr->GetLocations(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6614 | CpuRegister value_reg_in = locations->InAt(0).AsRegister<CpuRegister>(); |
| 6615 | CpuRegister temp_reg = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 6616 | CpuRegister base_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6617 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6618 | |
| 6619 | // Should we generate smaller inline compare/jumps? |
| 6620 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 6621 | // Figure out the correct compare values and jump conditions. |
| 6622 | // Handle the first compare/branch as a special case because it might |
| 6623 | // jump to the default case. |
| 6624 | DCHECK_GT(num_entries, 2u); |
| 6625 | Condition first_condition; |
| 6626 | uint32_t index; |
| 6627 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 6628 | if (lower_bound != 0) { |
| 6629 | first_condition = kLess; |
| 6630 | __ cmpl(value_reg_in, Immediate(lower_bound)); |
| 6631 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 6632 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
| 6633 | |
| 6634 | index = 1; |
| 6635 | } else { |
| 6636 | // Handle all the compare/jumps below. |
| 6637 | first_condition = kBelow; |
| 6638 | index = 0; |
| 6639 | } |
| 6640 | |
| 6641 | // Handle the rest of the compare/jumps. |
| 6642 | for (; index + 1 < num_entries; index += 2) { |
| 6643 | int32_t compare_to_value = lower_bound + index + 1; |
| 6644 | __ cmpl(value_reg_in, Immediate(compare_to_value)); |
| 6645 | // Jump to successors[index] if value < case_value[index]. |
| 6646 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 6647 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 6648 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 6649 | } |
| 6650 | |
| 6651 | if (index != num_entries) { |
| 6652 | // There are an odd number of entries. Handle the last one. |
| 6653 | DCHECK_EQ(index + 1, num_entries); |
Nicolas Geoffray | 6ce0173 | 2015-12-30 14:10:13 +0000 | [diff] [blame] | 6654 | __ cmpl(value_reg_in, Immediate(static_cast<int32_t>(lower_bound + index))); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6655 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
| 6656 | } |
| 6657 | |
| 6658 | // And the default for any other value. |
| 6659 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6660 | __ jmp(codegen_->GetLabelOf(default_block)); |
| 6661 | } |
| 6662 | return; |
| 6663 | } |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6664 | |
| 6665 | // Remove the bias, if needed. |
| 6666 | Register value_reg_out = value_reg_in.AsRegister(); |
| 6667 | if (lower_bound != 0) { |
| 6668 | __ leal(temp_reg, Address(value_reg_in, -lower_bound)); |
| 6669 | value_reg_out = temp_reg.AsRegister(); |
| 6670 | } |
| 6671 | CpuRegister value_reg(value_reg_out); |
| 6672 | |
| 6673 | // Is the value in range? |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6674 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 6675 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6676 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6677 | // We are in the range of the table. |
| 6678 | // Load the address of the jump table in the constant area. |
| 6679 | __ leaq(base_reg, codegen_->LiteralCaseTable(switch_instr)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6680 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6681 | // Load the (signed) offset from the jump table. |
| 6682 | __ movsxd(temp_reg, Address(base_reg, value_reg, TIMES_4, 0)); |
| 6683 | |
| 6684 | // Add the offset to the address of the table base. |
| 6685 | __ addq(temp_reg, base_reg); |
| 6686 | |
| 6687 | // And jump. |
| 6688 | __ jmp(temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6689 | } |
| 6690 | |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6691 | void CodeGeneratorX86_64::Load32BitValue(CpuRegister dest, int32_t value) { |
| 6692 | if (value == 0) { |
| 6693 | __ xorl(dest, dest); |
| 6694 | } else { |
| 6695 | __ movl(dest, Immediate(value)); |
| 6696 | } |
| 6697 | } |
| 6698 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6699 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 6700 | if (value == 0) { |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6701 | // Clears upper bits too. |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6702 | __ xorl(dest, dest); |
Vladimir Marko | ed00978 | 2016-02-22 16:54:39 +0000 | [diff] [blame] | 6703 | } else if (IsUint<32>(value)) { |
| 6704 | // We can use a 32 bit move, as it will zero-extend and is shorter. |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6705 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 6706 | } else { |
| 6707 | __ movq(dest, Immediate(value)); |
| 6708 | } |
| 6709 | } |
| 6710 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 6711 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, int32_t value) { |
| 6712 | if (value == 0) { |
| 6713 | __ xorps(dest, dest); |
| 6714 | } else { |
| 6715 | __ movss(dest, LiteralInt32Address(value)); |
| 6716 | } |
| 6717 | } |
| 6718 | |
| 6719 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, int64_t value) { |
| 6720 | if (value == 0) { |
| 6721 | __ xorpd(dest, dest); |
| 6722 | } else { |
| 6723 | __ movsd(dest, LiteralInt64Address(value)); |
| 6724 | } |
| 6725 | } |
| 6726 | |
| 6727 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, float value) { |
| 6728 | Load32BitValue(dest, bit_cast<int32_t, float>(value)); |
| 6729 | } |
| 6730 | |
| 6731 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, double value) { |
| 6732 | Load64BitValue(dest, bit_cast<int64_t, double>(value)); |
| 6733 | } |
| 6734 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 6735 | void CodeGeneratorX86_64::Compare32BitValue(CpuRegister dest, int32_t value) { |
| 6736 | if (value == 0) { |
| 6737 | __ testl(dest, dest); |
| 6738 | } else { |
| 6739 | __ cmpl(dest, Immediate(value)); |
| 6740 | } |
| 6741 | } |
| 6742 | |
| 6743 | void CodeGeneratorX86_64::Compare64BitValue(CpuRegister dest, int64_t value) { |
| 6744 | if (IsInt<32>(value)) { |
| 6745 | if (value == 0) { |
| 6746 | __ testq(dest, dest); |
| 6747 | } else { |
| 6748 | __ cmpq(dest, Immediate(static_cast<int32_t>(value))); |
| 6749 | } |
| 6750 | } else { |
| 6751 | // Value won't fit in an int. |
| 6752 | __ cmpq(dest, LiteralInt64Address(value)); |
| 6753 | } |
| 6754 | } |
| 6755 | |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 6756 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 6757 | DCHECK(dest.IsDoubleStackSlot()); |
| 6758 | if (IsInt<32>(value)) { |
| 6759 | // Can move directly as an int32 constant. |
| 6760 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 6761 | Immediate(static_cast<int32_t>(value))); |
| 6762 | } else { |
| 6763 | Load64BitValue(CpuRegister(TMP), value); |
| 6764 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 6765 | } |
| 6766 | } |
| 6767 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6768 | /** |
| 6769 | * Class to handle late fixup of offsets into constant area. |
| 6770 | */ |
| 6771 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| 6772 | public: |
| 6773 | RIPFixup(CodeGeneratorX86_64& codegen, size_t offset) |
| 6774 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 6775 | |
| 6776 | protected: |
| 6777 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 6778 | |
| 6779 | CodeGeneratorX86_64* codegen_; |
| 6780 | |
| 6781 | private: |
| 6782 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 6783 | // Patch the correct offset for the instruction. We use the address of the |
| 6784 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 6785 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 6786 | int32_t relative_position = constant_offset - pos; |
| 6787 | |
| 6788 | // Patch in the right value. |
| 6789 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 6790 | } |
| 6791 | |
| 6792 | // Location in constant area that the fixup refers to. |
| 6793 | size_t offset_into_constant_area_; |
| 6794 | }; |
| 6795 | |
| 6796 | /** |
| 6797 | t * Class to handle late fixup of offsets to a jump table that will be created in the |
| 6798 | * constant area. |
| 6799 | */ |
| 6800 | class JumpTableRIPFixup : public RIPFixup { |
| 6801 | public: |
| 6802 | JumpTableRIPFixup(CodeGeneratorX86_64& codegen, HPackedSwitch* switch_instr) |
| 6803 | : RIPFixup(codegen, -1), switch_instr_(switch_instr) {} |
| 6804 | |
| 6805 | void CreateJumpTable() { |
| 6806 | X86_64Assembler* assembler = codegen_->GetAssembler(); |
| 6807 | |
| 6808 | // Ensure that the reference to the jump table has the correct offset. |
| 6809 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 6810 | SetOffset(offset_in_constant_table); |
| 6811 | |
| 6812 | // Compute the offset from the start of the function to this jump table. |
| 6813 | const int32_t current_table_offset = assembler->CodeSize() + offset_in_constant_table; |
| 6814 | |
| 6815 | // Populate the jump table with the correct values for the jump table. |
| 6816 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 6817 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 6818 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 6819 | // The value that we want is the target offset - the position of the table. |
| 6820 | for (int32_t i = 0; i < num_entries; i++) { |
| 6821 | HBasicBlock* b = successors[i]; |
| 6822 | Label* l = codegen_->GetLabelOf(b); |
| 6823 | DCHECK(l->IsBound()); |
| 6824 | int32_t offset_to_block = l->Position() - current_table_offset; |
| 6825 | assembler->AppendInt32(offset_to_block); |
| 6826 | } |
| 6827 | } |
| 6828 | |
| 6829 | private: |
| 6830 | const HPackedSwitch* switch_instr_; |
| 6831 | }; |
| 6832 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6833 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 6834 | // Generate the constant area if needed. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 6835 | X86_64Assembler* assembler = GetAssembler(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6836 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 6837 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 byte values. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 6838 | assembler->Align(4, 0); |
| 6839 | constant_area_start_ = assembler->CodeSize(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6840 | |
| 6841 | // Populate any jump tables. |
| 6842 | for (auto jump_table : fixups_to_jump_tables_) { |
| 6843 | jump_table->CreateJumpTable(); |
| 6844 | } |
| 6845 | |
| 6846 | // And now add the constant area to the generated code. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 6847 | assembler->AddConstantArea(); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6848 | } |
| 6849 | |
| 6850 | // And finish up. |
| 6851 | CodeGenerator::Finalize(allocator); |
| 6852 | } |
| 6853 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6854 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
| 6855 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 6856 | return Address::RIP(fixup); |
| 6857 | } |
| 6858 | |
| 6859 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
| 6860 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 6861 | return Address::RIP(fixup); |
| 6862 | } |
| 6863 | |
| 6864 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
| 6865 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 6866 | return Address::RIP(fixup); |
| 6867 | } |
| 6868 | |
| 6869 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
| 6870 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 6871 | return Address::RIP(fixup); |
| 6872 | } |
| 6873 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6874 | // TODO: trg as memory. |
| 6875 | void CodeGeneratorX86_64::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 6876 | if (!trg.IsValid()) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6877 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6878 | return; |
| 6879 | } |
| 6880 | |
| 6881 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 6882 | |
| 6883 | Location return_loc = InvokeDexCallingConventionVisitorX86_64().GetReturnLocation(type); |
| 6884 | if (trg.Equals(return_loc)) { |
| 6885 | return; |
| 6886 | } |
| 6887 | |
| 6888 | // Let the parallel move resolver take care of all of this. |
| 6889 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 6890 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 6891 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 6892 | } |
| 6893 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6894 | Address CodeGeneratorX86_64::LiteralCaseTable(HPackedSwitch* switch_instr) { |
| 6895 | // Create a fixup to be used to create and address the jump table. |
| 6896 | JumpTableRIPFixup* table_fixup = |
| 6897 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 6898 | |
| 6899 | // We have to populate the jump tables. |
| 6900 | fixups_to_jump_tables_.push_back(table_fixup); |
| 6901 | return Address::RIP(table_fixup); |
| 6902 | } |
| 6903 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 6904 | void CodeGeneratorX86_64::MoveInt64ToAddress(const Address& addr_low, |
| 6905 | const Address& addr_high, |
| 6906 | int64_t v, |
| 6907 | HInstruction* instruction) { |
| 6908 | if (IsInt<32>(v)) { |
| 6909 | int32_t v_32 = v; |
| 6910 | __ movq(addr_low, Immediate(v_32)); |
| 6911 | MaybeRecordImplicitNullCheck(instruction); |
| 6912 | } else { |
| 6913 | // Didn't fit in a register. Do it in pieces. |
| 6914 | int32_t low_v = Low32Bits(v); |
| 6915 | int32_t high_v = High32Bits(v); |
| 6916 | __ movl(addr_low, Immediate(low_v)); |
| 6917 | MaybeRecordImplicitNullCheck(instruction); |
| 6918 | __ movl(addr_high, Immediate(high_v)); |
| 6919 | } |
| 6920 | } |
| 6921 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6922 | #undef __ |
| 6923 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 6924 | } // namespace x86_64 |
| 6925 | } // namespace art |