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 | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 54 | #define __ down_cast<X86_64Assembler*>(codegen->GetAssembler())-> |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 55 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 56 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 57 | class NullCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 58 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 59 | explicit NullCheckSlowPathX86_64(HNullCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 60 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 61 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 62 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 63 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 64 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 65 | // Live registers will be restored in the catch block if caught. |
| 66 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 67 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 68 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), |
| 69 | instruction_, |
| 70 | instruction_->GetDexPc(), |
| 71 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 72 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 73 | } |
| 74 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 75 | bool IsFatal() const OVERRIDE { return true; } |
| 76 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 77 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86_64"; } |
| 78 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 79 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 80 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86_64); |
| 81 | }; |
| 82 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 83 | class DivZeroCheckSlowPathX86_64 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 84 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 85 | explicit DivZeroCheckSlowPathX86_64(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 86 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 87 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 88 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 89 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 90 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 91 | // Live registers will be restored in the catch block if caught. |
| 92 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 93 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 94 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), |
| 95 | instruction_, |
| 96 | instruction_->GetDexPc(), |
| 97 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 98 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 101 | bool IsFatal() const OVERRIDE { return true; } |
| 102 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 103 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86_64"; } |
| 104 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 105 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 106 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86_64); |
| 107 | }; |
| 108 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 109 | class DivRemMinusOneSlowPathX86_64 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 110 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 111 | DivRemMinusOneSlowPathX86_64(HInstruction* at, Register reg, Primitive::Type type, bool is_div) |
| 112 | : SlowPathCode(at), cpu_reg_(CpuRegister(reg)), type_(type), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 113 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 114 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 115 | __ Bind(GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 116 | if (type_ == Primitive::kPrimInt) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 117 | if (is_div_) { |
| 118 | __ negl(cpu_reg_); |
| 119 | } else { |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 120 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 123 | } else { |
| 124 | DCHECK_EQ(Primitive::kPrimLong, type_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 125 | if (is_div_) { |
| 126 | __ negq(cpu_reg_); |
| 127 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 128 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 129 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 130 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 131 | __ jmp(GetExitLabel()); |
| 132 | } |
| 133 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 134 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86_64"; } |
| 135 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 136 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 137 | const CpuRegister cpu_reg_; |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 138 | const Primitive::Type type_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 139 | const bool is_div_; |
| 140 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86_64); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 141 | }; |
| 142 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 143 | class SuspendCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 144 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 145 | SuspendCheckSlowPathX86_64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 146 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 147 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 148 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 149 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 150 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 151 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 152 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), |
| 153 | instruction_, |
| 154 | instruction_->GetDexPc(), |
| 155 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 156 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 157 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 158 | if (successor_ == nullptr) { |
| 159 | __ jmp(GetReturnLabel()); |
| 160 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 161 | __ jmp(x86_64_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 162 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 165 | Label* GetReturnLabel() { |
| 166 | DCHECK(successor_ == nullptr); |
| 167 | return &return_label_; |
| 168 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 169 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 170 | HBasicBlock* GetSuccessor() const { |
| 171 | return successor_; |
| 172 | } |
| 173 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 174 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86_64"; } |
| 175 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 176 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 177 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 178 | Label return_label_; |
| 179 | |
| 180 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64); |
| 181 | }; |
| 182 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 183 | class BoundsCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 184 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 185 | explicit BoundsCheckSlowPathX86_64(HBoundsCheck* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 186 | : SlowPathCode(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 187 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 188 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 189 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 190 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 191 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 192 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 193 | // Live registers will be restored in the catch block if caught. |
| 194 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 195 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 196 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 197 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 198 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 199 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 200 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 201 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 202 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 203 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 204 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 205 | Primitive::kPrimInt); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 206 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds), |
| 207 | instruction_, |
| 208 | instruction_->GetDexPc(), |
| 209 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 210 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 211 | } |
| 212 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 213 | bool IsFatal() const OVERRIDE { return true; } |
| 214 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 215 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86_64"; } |
| 216 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 217 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 218 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 219 | }; |
| 220 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 221 | class LoadClassSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 222 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 223 | LoadClassSlowPathX86_64(HLoadClass* cls, |
| 224 | HInstruction* at, |
| 225 | uint32_t dex_pc, |
| 226 | bool do_clinit) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 227 | : 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] | 228 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 229 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 230 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 231 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 232 | LocationSummary* locations = at_->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 233 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 234 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 235 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 236 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 237 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 238 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 239 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(cls_->GetTypeIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 240 | x86_64_codegen->InvokeRuntime(do_clinit_ ? |
| 241 | QUICK_ENTRY_POINT(pInitializeStaticStorage) : |
| 242 | QUICK_ENTRY_POINT(pInitializeType), |
| 243 | at_, |
| 244 | dex_pc_, |
| 245 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 246 | if (do_clinit_) { |
| 247 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 248 | } else { |
| 249 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 250 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 251 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 252 | Location out = locations->Out(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 253 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 254 | if (out.IsValid()) { |
| 255 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 256 | x86_64_codegen->Move(out, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 259 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 260 | __ jmp(GetExitLabel()); |
| 261 | } |
| 262 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 263 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86_64"; } |
| 264 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 265 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 266 | // The class this slow path will load. |
| 267 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 268 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 269 | // The instruction where this slow path is happening. |
| 270 | // (Might be the load class or an initialization check). |
| 271 | HInstruction* const at_; |
| 272 | |
| 273 | // The dex PC of `at_`. |
| 274 | const uint32_t dex_pc_; |
| 275 | |
| 276 | // Whether to initialize the class. |
| 277 | const bool do_clinit_; |
| 278 | |
| 279 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86_64); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 280 | }; |
| 281 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 282 | class LoadStringSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 283 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 284 | explicit LoadStringSlowPathX86_64(HLoadString* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 285 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 286 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 287 | LocationSummary* locations = instruction_->GetLocations(); |
| 288 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 289 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 290 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 291 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 292 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 293 | |
| 294 | InvokeRuntimeCallingConvention calling_convention; |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 295 | const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 296 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(string_index)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 297 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), |
| 298 | instruction_, |
| 299 | instruction_->GetDexPc(), |
| 300 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 301 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 302 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 303 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 304 | __ jmp(GetExitLabel()); |
| 305 | } |
| 306 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 307 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86_64"; } |
| 308 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 309 | private: |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 310 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86_64); |
| 311 | }; |
| 312 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 313 | class TypeCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 314 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 315 | TypeCheckSlowPathX86_64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 316 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 317 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 318 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 319 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 320 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 321 | : locations->Out(); |
| 322 | uint32_t dex_pc = instruction_->GetDexPc(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 323 | DCHECK(instruction_->IsCheckCast() |
| 324 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 325 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 326 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 327 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 328 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 329 | if (!is_fatal_) { |
| 330 | SaveLiveRegisters(codegen, locations); |
| 331 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 332 | |
| 333 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 334 | // move resolver. |
| 335 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 336 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 337 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 338 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 339 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 340 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 341 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 342 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 343 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 344 | if (instruction_->IsInstanceOf()) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 345 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 346 | instruction_, |
| 347 | dex_pc, |
| 348 | this); |
| 349 | CheckEntrypointTypes< |
| 350 | kQuickInstanceofNonTrivial, uint32_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 351 | } else { |
| 352 | DCHECK(instruction_->IsCheckCast()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 353 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 354 | instruction_, |
| 355 | dex_pc, |
| 356 | this); |
| 357 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 358 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 359 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 360 | if (!is_fatal_) { |
| 361 | if (instruction_->IsInstanceOf()) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 362 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 363 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 364 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 365 | RestoreLiveRegisters(codegen, locations); |
| 366 | __ jmp(GetExitLabel()); |
| 367 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 368 | } |
| 369 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 370 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86_64"; } |
| 371 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 372 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 373 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 374 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 375 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 376 | |
| 377 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86_64); |
| 378 | }; |
| 379 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 380 | class DeoptimizationSlowPathX86_64 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 381 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 382 | explicit DeoptimizationSlowPathX86_64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 383 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 384 | |
| 385 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 386 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 387 | __ Bind(GetEntryLabel()); |
| 388 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 389 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 390 | instruction_, |
| 391 | instruction_->GetDexPc(), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 392 | 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); |
| 431 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 432 | instruction_, |
| 433 | instruction_->GetDexPc(), |
| 434 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 435 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 436 | RestoreLiveRegisters(codegen, locations); |
| 437 | __ jmp(GetExitLabel()); |
| 438 | } |
| 439 | |
| 440 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86_64"; } |
| 441 | |
| 442 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 443 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86_64); |
| 444 | }; |
| 445 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 446 | // Slow path marking an object during a read barrier. |
| 447 | class ReadBarrierMarkSlowPathX86_64 : public SlowPathCode { |
| 448 | public: |
| 449 | ReadBarrierMarkSlowPathX86_64(HInstruction* instruction, Location out, Location obj) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 450 | : SlowPathCode(instruction), out_(out), obj_(obj) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 451 | DCHECK(kEmitCompilerReadBarrier); |
| 452 | } |
| 453 | |
| 454 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86_64"; } |
| 455 | |
| 456 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 457 | LocationSummary* locations = instruction_->GetLocations(); |
| 458 | Register reg_out = out_.AsRegister<Register>(); |
| 459 | DCHECK(locations->CanCall()); |
| 460 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 461 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 462 | instruction_->IsStaticFieldGet() || |
| 463 | instruction_->IsArrayGet() || |
| 464 | instruction_->IsLoadClass() || |
| 465 | instruction_->IsLoadString() || |
| 466 | instruction_->IsInstanceOf() || |
| 467 | instruction_->IsCheckCast()) |
| 468 | << "Unexpected instruction in read barrier marking slow path: " |
| 469 | << instruction_->DebugName(); |
| 470 | |
| 471 | __ Bind(GetEntryLabel()); |
| 472 | SaveLiveRegisters(codegen, locations); |
| 473 | |
| 474 | InvokeRuntimeCallingConvention calling_convention; |
| 475 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 476 | x86_64_codegen->Move(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), obj_); |
| 477 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierMark), |
| 478 | instruction_, |
| 479 | instruction_->GetDexPc(), |
| 480 | this); |
| 481 | CheckEntrypointTypes<kQuickReadBarrierMark, mirror::Object*, mirror::Object*>(); |
| 482 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 483 | |
| 484 | RestoreLiveRegisters(codegen, locations); |
| 485 | __ jmp(GetExitLabel()); |
| 486 | } |
| 487 | |
| 488 | private: |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 489 | const Location out_; |
| 490 | const Location obj_; |
| 491 | |
| 492 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86_64); |
| 493 | }; |
| 494 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 495 | // Slow path generating a read barrier for a heap reference. |
| 496 | class ReadBarrierForHeapReferenceSlowPathX86_64 : public SlowPathCode { |
| 497 | public: |
| 498 | ReadBarrierForHeapReferenceSlowPathX86_64(HInstruction* instruction, |
| 499 | Location out, |
| 500 | Location ref, |
| 501 | Location obj, |
| 502 | uint32_t offset, |
| 503 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 504 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 505 | out_(out), |
| 506 | ref_(ref), |
| 507 | obj_(obj), |
| 508 | offset_(offset), |
| 509 | index_(index) { |
| 510 | DCHECK(kEmitCompilerReadBarrier); |
| 511 | // If `obj` is equal to `out` or `ref`, it means the initial |
| 512 | // object has been overwritten by (or after) the heap object |
| 513 | // reference load to be instrumented, e.g.: |
| 514 | // |
| 515 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 516 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 517 | // |
| 518 | // In that case, we have lost the information about the original |
| 519 | // object, and the emitted read barrier cannot work properly. |
| 520 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 521 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 522 | } |
| 523 | |
| 524 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 525 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 526 | LocationSummary* locations = instruction_->GetLocations(); |
| 527 | CpuRegister reg_out = out_.AsRegister<CpuRegister>(); |
| 528 | DCHECK(locations->CanCall()); |
| 529 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.AsRegister())) << out_; |
| 530 | DCHECK(!instruction_->IsInvoke() || |
| 531 | (instruction_->IsInvokeStaticOrDirect() && |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 532 | instruction_->GetLocations()->Intrinsified())) |
| 533 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 534 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 535 | |
| 536 | __ Bind(GetEntryLabel()); |
| 537 | SaveLiveRegisters(codegen, locations); |
| 538 | |
| 539 | // We may have to change the index's value, but as `index_` is a |
| 540 | // constant member (like other "inputs" of this slow path), |
| 541 | // introduce a copy of it, `index`. |
| 542 | Location index = index_; |
| 543 | if (index_.IsValid()) { |
| 544 | // Handle `index_` for HArrayGet and intrinsic UnsafeGetObject. |
| 545 | if (instruction_->IsArrayGet()) { |
| 546 | // Compute real offset and store it in index_. |
| 547 | Register index_reg = index_.AsRegister<CpuRegister>().AsRegister(); |
| 548 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 549 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 550 | // We are about to change the value of `index_reg` (see the |
| 551 | // calls to art::x86_64::X86_64Assembler::shll and |
| 552 | // art::x86_64::X86_64Assembler::AddImmediate below), but it |
| 553 | // has not been saved by the previous call to |
| 554 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 555 | // callee-save register -- |
| 556 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 557 | // callee-save registers, as it has been designed with the |
| 558 | // assumption that callee-save registers are supposed to be |
| 559 | // handled by the called function. So, as a callee-save |
| 560 | // register, `index_reg` _would_ eventually be saved onto |
| 561 | // the stack, but it would be too late: we would have |
| 562 | // changed its value earlier. Therefore, we manually save |
| 563 | // it here into another freely available register, |
| 564 | // `free_reg`, chosen of course among the caller-save |
| 565 | // registers (as a callee-save `free_reg` register would |
| 566 | // exhibit the same problem). |
| 567 | // |
| 568 | // Note we could have requested a temporary register from |
| 569 | // the register allocator instead; but we prefer not to, as |
| 570 | // this is a slow path, and we know we can find a |
| 571 | // caller-save register that is available. |
| 572 | Register free_reg = FindAvailableCallerSaveRegister(codegen).AsRegister(); |
| 573 | __ movl(CpuRegister(free_reg), CpuRegister(index_reg)); |
| 574 | index_reg = free_reg; |
| 575 | index = Location::RegisterLocation(index_reg); |
| 576 | } else { |
| 577 | // The initial register stored in `index_` has already been |
| 578 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 579 | // (as it is not a callee-save register), so we can freely |
| 580 | // use it. |
| 581 | } |
| 582 | // Shifting the index value contained in `index_reg` by the |
| 583 | // scale factor (2) cannot overflow in practice, as the |
| 584 | // runtime is unable to allocate object arrays with a size |
| 585 | // larger than 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 586 | __ shll(CpuRegister(index_reg), Immediate(TIMES_4)); |
| 587 | static_assert( |
| 588 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 589 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 590 | __ AddImmediate(CpuRegister(index_reg), Immediate(offset_)); |
| 591 | } else { |
| 592 | DCHECK(instruction_->IsInvoke()); |
| 593 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 594 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 595 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 596 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 597 | DCHECK_EQ(offset_, 0U); |
| 598 | DCHECK(index_.IsRegister()); |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | // We're moving two or three locations to locations that could |
| 603 | // overlap, so we need a parallel move resolver. |
| 604 | InvokeRuntimeCallingConvention calling_convention; |
| 605 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 606 | parallel_move.AddMove(ref_, |
| 607 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 608 | Primitive::kPrimNot, |
| 609 | nullptr); |
| 610 | parallel_move.AddMove(obj_, |
| 611 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 612 | Primitive::kPrimNot, |
| 613 | nullptr); |
| 614 | if (index.IsValid()) { |
| 615 | parallel_move.AddMove(index, |
| 616 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 617 | Primitive::kPrimInt, |
| 618 | nullptr); |
| 619 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 620 | } else { |
| 621 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 622 | __ movl(CpuRegister(calling_convention.GetRegisterAt(2)), Immediate(offset_)); |
| 623 | } |
| 624 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow), |
| 625 | instruction_, |
| 626 | instruction_->GetDexPc(), |
| 627 | this); |
| 628 | CheckEntrypointTypes< |
| 629 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 630 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 631 | |
| 632 | RestoreLiveRegisters(codegen, locations); |
| 633 | __ jmp(GetExitLabel()); |
| 634 | } |
| 635 | |
| 636 | const char* GetDescription() const OVERRIDE { |
| 637 | return "ReadBarrierForHeapReferenceSlowPathX86_64"; |
| 638 | } |
| 639 | |
| 640 | private: |
| 641 | CpuRegister FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 642 | size_t ref = static_cast<int>(ref_.AsRegister<CpuRegister>().AsRegister()); |
| 643 | size_t obj = static_cast<int>(obj_.AsRegister<CpuRegister>().AsRegister()); |
| 644 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 645 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 646 | return static_cast<CpuRegister>(i); |
| 647 | } |
| 648 | } |
| 649 | // We shall never fail to find a free caller-save register, as |
| 650 | // there are more than two core caller-save registers on x86-64 |
| 651 | // (meaning it is possible to find one which is different from |
| 652 | // `ref` and `obj`). |
| 653 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 654 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 655 | UNREACHABLE(); |
| 656 | } |
| 657 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 658 | const Location out_; |
| 659 | const Location ref_; |
| 660 | const Location obj_; |
| 661 | const uint32_t offset_; |
| 662 | // An additional location containing an index to an array. |
| 663 | // Only used for HArrayGet and the UnsafeGetObject & |
| 664 | // UnsafeGetObjectVolatile intrinsics. |
| 665 | const Location index_; |
| 666 | |
| 667 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86_64); |
| 668 | }; |
| 669 | |
| 670 | // Slow path generating a read barrier for a GC root. |
| 671 | class ReadBarrierForRootSlowPathX86_64 : public SlowPathCode { |
| 672 | public: |
| 673 | ReadBarrierForRootSlowPathX86_64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 674 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 675 | DCHECK(kEmitCompilerReadBarrier); |
| 676 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 677 | |
| 678 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 679 | LocationSummary* locations = instruction_->GetLocations(); |
| 680 | DCHECK(locations->CanCall()); |
| 681 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 682 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 683 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 684 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 685 | |
| 686 | __ Bind(GetEntryLabel()); |
| 687 | SaveLiveRegisters(codegen, locations); |
| 688 | |
| 689 | InvokeRuntimeCallingConvention calling_convention; |
| 690 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 691 | x86_64_codegen->Move(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| 692 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow), |
| 693 | instruction_, |
| 694 | instruction_->GetDexPc(), |
| 695 | this); |
| 696 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 697 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 698 | |
| 699 | RestoreLiveRegisters(codegen, locations); |
| 700 | __ jmp(GetExitLabel()); |
| 701 | } |
| 702 | |
| 703 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86_64"; } |
| 704 | |
| 705 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 706 | const Location out_; |
| 707 | const Location root_; |
| 708 | |
| 709 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86_64); |
| 710 | }; |
| 711 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 712 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 713 | #define __ down_cast<X86_64Assembler*>(GetAssembler())-> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 714 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 715 | inline Condition X86_64IntegerCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 716 | switch (cond) { |
| 717 | case kCondEQ: return kEqual; |
| 718 | case kCondNE: return kNotEqual; |
| 719 | case kCondLT: return kLess; |
| 720 | case kCondLE: return kLessEqual; |
| 721 | case kCondGT: return kGreater; |
| 722 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 723 | case kCondB: return kBelow; |
| 724 | case kCondBE: return kBelowEqual; |
| 725 | case kCondA: return kAbove; |
| 726 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 727 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 728 | LOG(FATAL) << "Unreachable"; |
| 729 | UNREACHABLE(); |
| 730 | } |
| 731 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 732 | // Maps FP condition to x86_64 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 733 | inline Condition X86_64FPCondition(IfCondition cond) { |
| 734 | switch (cond) { |
| 735 | case kCondEQ: return kEqual; |
| 736 | case kCondNE: return kNotEqual; |
| 737 | case kCondLT: return kBelow; |
| 738 | case kCondLE: return kBelowEqual; |
| 739 | case kCondGT: return kAbove; |
| 740 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 741 | default: break; // should not happen |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 742 | }; |
| 743 | LOG(FATAL) << "Unreachable"; |
| 744 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 745 | } |
| 746 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 747 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86_64::GetSupportedInvokeStaticOrDirectDispatch( |
| 748 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 749 | MethodReference target_method ATTRIBUTE_UNUSED) { |
| 750 | switch (desired_dispatch_info.code_ptr_location) { |
| 751 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 752 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 753 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 754 | return HInvokeStaticOrDirect::DispatchInfo { |
| 755 | desired_dispatch_info.method_load_kind, |
| 756 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
| 757 | desired_dispatch_info.method_load_data, |
| 758 | 0u |
| 759 | }; |
| 760 | default: |
| 761 | return desired_dispatch_info; |
| 762 | } |
| 763 | } |
| 764 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 765 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 766 | Location temp) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 767 | // All registers are assumed to be correctly set up. |
| 768 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 769 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 770 | switch (invoke->GetMethodLoadKind()) { |
| 771 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 772 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | 7f59d59 | 2015-12-29 16:20:52 +0000 | [diff] [blame] | 773 | __ gs()->movq(temp.AsRegister<CpuRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 774 | Address::Absolute(invoke->GetStringInitOffset(), /* no_rip */ true)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 775 | break; |
| 776 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 777 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 778 | break; |
| 779 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 780 | __ movq(temp.AsRegister<CpuRegister>(), Immediate(invoke->GetMethodAddress())); |
| 781 | break; |
| 782 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 783 | __ movl(temp.AsRegister<CpuRegister>(), Immediate(0)); // Placeholder. |
| 784 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 785 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 786 | break; |
| 787 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 788 | pc_relative_dex_cache_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 789 | invoke->GetDexCacheArrayOffset()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 790 | __ movq(temp.AsRegister<CpuRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 791 | Address::Absolute(kDummy32BitOffset, /* no_rip */ false)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 792 | // Bind the label at the end of the "movl" insn. |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 793 | __ Bind(&pc_relative_dex_cache_patches_.back().label); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 794 | break; |
| 795 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 796 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 797 | Register method_reg; |
| 798 | CpuRegister reg = temp.AsRegister<CpuRegister>(); |
| 799 | if (current_method.IsRegister()) { |
| 800 | method_reg = current_method.AsRegister<Register>(); |
| 801 | } else { |
| 802 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 803 | DCHECK(!current_method.IsValid()); |
| 804 | method_reg = reg.AsRegister(); |
| 805 | __ movq(reg, Address(CpuRegister(RSP), kCurrentMethodStackOffset)); |
| 806 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 807 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 808 | __ movq(reg, |
| 809 | Address(CpuRegister(method_reg), |
| 810 | ArtMethod::DexCacheResolvedMethodsOffset(kX86_64PointerSize).SizeValue())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 811 | // temp = temp[index_in_cache] |
| 812 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 813 | __ movq(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 814 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 815 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | switch (invoke->GetCodePtrLocation()) { |
| 819 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 820 | __ call(&frame_entry_label_); |
| 821 | break; |
| 822 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 823 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 824 | Label* label = &relative_call_patches_.back().label; |
| 825 | __ call(label); // Bind to the patch label, override at link time. |
| 826 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 827 | break; |
| 828 | } |
| 829 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 830 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 831 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 832 | LOG(FATAL) << "Unsupported"; |
| 833 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 834 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 835 | // (callee_method + offset_of_quick_compiled_code)() |
| 836 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 837 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 838 | kX86_64WordSize).SizeValue())); |
| 839 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 840 | } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 841 | |
| 842 | DCHECK(!IsLeafMethod()); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 843 | } |
| 844 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 845 | void CodeGeneratorX86_64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 846 | CpuRegister temp = temp_in.AsRegister<CpuRegister>(); |
| 847 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 848 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 849 | |
| 850 | // Use the calling convention instead of the location of the receiver, as |
| 851 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 852 | // slow path, the arguments have been moved to the right place, so here we are |
| 853 | // guaranteed that the receiver is the first register of the calling convention. |
| 854 | InvokeDexCallingConvention calling_convention; |
| 855 | Register receiver = calling_convention.GetRegisterAt(0); |
| 856 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 857 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 858 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 859 | __ movl(temp, Address(CpuRegister(receiver), class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 860 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 861 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 862 | // emit a read barrier for the previous class reference load. |
| 863 | // However this is not required in practice, as this is an |
| 864 | // intermediate/temporary reference and because the current |
| 865 | // concurrent copying collector keeps the from-space memory |
| 866 | // intact/accessible until the end of the marking phase (the |
| 867 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 868 | __ MaybeUnpoisonHeapReference(temp); |
| 869 | // temp = temp->GetMethodAt(method_offset); |
| 870 | __ movq(temp, Address(temp, method_offset)); |
| 871 | // call temp->GetEntryPoint(); |
| 872 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 873 | kX86_64WordSize).SizeValue())); |
| 874 | } |
| 875 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 876 | void CodeGeneratorX86_64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 877 | DCHECK(linker_patches->empty()); |
| 878 | size_t size = |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 879 | method_patches_.size() + |
| 880 | relative_call_patches_.size() + |
| 881 | pc_relative_dex_cache_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 882 | linker_patches->reserve(size); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 883 | // The label points to the end of the "movl" insn but the literal offset for method |
| 884 | // patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 885 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 886 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 887 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 888 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 889 | info.target_method.dex_file, |
| 890 | info.target_method.dex_method_index)); |
| 891 | } |
| 892 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 893 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 894 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 895 | info.target_method.dex_file, |
| 896 | info.target_method.dex_method_index)); |
| 897 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 898 | for (const PcRelativeDexCacheAccessInfo& info : pc_relative_dex_cache_patches_) { |
| 899 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 900 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 901 | &info.target_dex_file, |
| 902 | info.label.Position(), |
| 903 | info.element_offset)); |
| 904 | } |
| 905 | } |
| 906 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 907 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 908 | stream << Register(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 912 | stream << FloatRegister(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 913 | } |
| 914 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 915 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 916 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 917 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 918 | } |
| 919 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 920 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 921 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 922 | return kX86_64WordSize; |
| 923 | } |
| 924 | |
| 925 | size_t CodeGeneratorX86_64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 926 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 927 | return kX86_64WordSize; |
| 928 | } |
| 929 | |
| 930 | size_t CodeGeneratorX86_64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 931 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 932 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 933 | } |
| 934 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 935 | void CodeGeneratorX86_64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 936 | HInstruction* instruction, |
| 937 | uint32_t dex_pc, |
| 938 | SlowPathCode* slow_path) { |
| 939 | InvokeRuntime(GetThreadOffset<kX86_64WordSize>(entrypoint).Int32Value(), |
| 940 | instruction, |
| 941 | dex_pc, |
| 942 | slow_path); |
| 943 | } |
| 944 | |
| 945 | void CodeGeneratorX86_64::InvokeRuntime(int32_t entry_point_offset, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 946 | HInstruction* instruction, |
| 947 | uint32_t dex_pc, |
| 948 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 949 | ValidateInvokeRuntime(instruction, slow_path); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 950 | __ gs()->call(Address::Absolute(entry_point_offset, /* no_rip */ true)); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 951 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 952 | } |
| 953 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 954 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 955 | // Use a fake return address register to mimic Quick. |
| 956 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 957 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 958 | const X86_64InstructionSetFeatures& isa_features, |
| 959 | const CompilerOptions& compiler_options, |
| 960 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 961 | : CodeGenerator(graph, |
| 962 | kNumberOfCpuRegisters, |
| 963 | kNumberOfFloatRegisters, |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 964 | kNumberOfCpuRegisterPairs, |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 965 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 966 | arraysize(kCoreCalleeSaves)) |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 967 | | (1 << kFakeReturnRegister), |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 968 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 969 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 970 | compiler_options, |
| 971 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 972 | block_labels_(nullptr), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 973 | location_builder_(graph, this), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 974 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 975 | move_resolver_(graph->GetArena(), this), |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 976 | isa_features_(isa_features), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 977 | constant_area_start_(0), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 978 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 979 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 980 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 981 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 982 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 983 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 984 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 985 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 986 | CodeGeneratorX86_64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 987 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 988 | assembler_(codegen->GetAssembler()), |
| 989 | codegen_(codegen) {} |
| 990 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 991 | void CodeGeneratorX86_64::SetupBlockedRegisters() const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 992 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 993 | blocked_core_registers_[RSP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 994 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 995 | // Block the register used as TMP. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 996 | blocked_core_registers_[TMP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 997 | } |
| 998 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 999 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1000 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1001 | } |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1002 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1003 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1004 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1005 | } |
| 1006 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1007 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1008 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1009 | __ Bind(&frame_entry_label_); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1010 | bool skip_overflow_check = IsLeafMethod() |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 1011 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1012 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1013 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1014 | if (!skip_overflow_check) { |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1015 | __ testq(CpuRegister(RAX), Address( |
| 1016 | CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1017 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1018 | } |
Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 1019 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1020 | if (HasEmptyFrame()) { |
| 1021 | return; |
| 1022 | } |
| 1023 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1024 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1025 | Register reg = kCoreCalleeSaves[i]; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1026 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1027 | __ pushq(CpuRegister(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1028 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 1029 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1030 | } |
| 1031 | } |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1032 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1033 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1034 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 1035 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1036 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1037 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1038 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1039 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1040 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1041 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1042 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 1043 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1044 | } |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1045 | } |
| 1046 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1047 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1048 | CpuRegister(kMethodRegisterArgument)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | void CodeGeneratorX86_64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1052 | __ cfi().RememberState(); |
| 1053 | if (!HasEmptyFrame()) { |
| 1054 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1055 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| 1056 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1057 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 1058 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1059 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 1060 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 1061 | } |
| 1062 | } |
| 1063 | |
| 1064 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1065 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 1066 | __ cfi().AdjustCFAOffset(-adjust); |
| 1067 | |
| 1068 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1069 | Register reg = kCoreCalleeSaves[i]; |
| 1070 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1071 | __ popq(CpuRegister(reg)); |
| 1072 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 1073 | __ cfi().Restore(DWARFReg(reg)); |
| 1074 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1075 | } |
| 1076 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1077 | __ ret(); |
| 1078 | __ cfi().RestoreState(); |
| 1079 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1080 | } |
| 1081 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1082 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 1083 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1084 | } |
| 1085 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1086 | Location CodeGeneratorX86_64::GetStackLocation(HLoadLocal* load) const { |
| 1087 | switch (load->GetType()) { |
| 1088 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1089 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1090 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1091 | |
| 1092 | case Primitive::kPrimInt: |
| 1093 | case Primitive::kPrimNot: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1094 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1095 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1096 | |
| 1097 | case Primitive::kPrimBoolean: |
| 1098 | case Primitive::kPrimByte: |
| 1099 | case Primitive::kPrimChar: |
| 1100 | case Primitive::kPrimShort: |
| 1101 | case Primitive::kPrimVoid: |
| 1102 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 1103 | UNREACHABLE(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 1107 | UNREACHABLE(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 1111 | if (source.Equals(destination)) { |
| 1112 | return; |
| 1113 | } |
| 1114 | if (destination.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1115 | CpuRegister dest = destination.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1116 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1117 | __ movq(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1118 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1119 | __ movd(dest, source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1120 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1121 | __ movl(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1122 | } else if (source.IsConstant()) { |
| 1123 | HConstant* constant = source.GetConstant(); |
| 1124 | if (constant->IsLongConstant()) { |
| 1125 | Load64BitValue(dest, constant->AsLongConstant()->GetValue()); |
| 1126 | } else { |
| 1127 | Load32BitValue(dest, GetInt32ValueOf(constant)); |
| 1128 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1129 | } else { |
| 1130 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1131 | __ movq(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1132 | } |
| 1133 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1134 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1135 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1136 | __ movd(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1137 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1138 | __ movaps(dest, source.AsFpuRegister<XmmRegister>()); |
| 1139 | } else if (source.IsConstant()) { |
| 1140 | HConstant* constant = source.GetConstant(); |
| 1141 | int64_t value = CodeGenerator::GetInt64ValueOf(constant); |
| 1142 | if (constant->IsFloatConstant()) { |
| 1143 | Load32BitValue(dest, static_cast<int32_t>(value)); |
| 1144 | } else { |
| 1145 | Load64BitValue(dest, value); |
| 1146 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1147 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1148 | __ movss(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1149 | } else { |
| 1150 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1151 | __ movsd(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1152 | } |
| 1153 | } else if (destination.IsStackSlot()) { |
| 1154 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1155 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1156 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1157 | } else if (source.IsFpuRegister()) { |
| 1158 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1159 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1160 | } else if (source.IsConstant()) { |
| 1161 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1162 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1163 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1164 | } else { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1165 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1166 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1167 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1168 | } |
| 1169 | } else { |
| 1170 | DCHECK(destination.IsDoubleStackSlot()); |
| 1171 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1172 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1173 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1174 | } else if (source.IsFpuRegister()) { |
| 1175 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1176 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1177 | } else if (source.IsConstant()) { |
| 1178 | HConstant* constant = source.GetConstant(); |
Zheng Xu | 12bca97 | 2015-03-30 19:35:50 +0800 | [diff] [blame] | 1179 | int64_t value; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1180 | if (constant->IsDoubleConstant()) { |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 1181 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1182 | } else { |
| 1183 | DCHECK(constant->IsLongConstant()); |
| 1184 | value = constant->AsLongConstant()->GetValue(); |
| 1185 | } |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 1186 | Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1187 | } else { |
| 1188 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1189 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1190 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1191 | } |
| 1192 | } |
| 1193 | } |
| 1194 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1195 | void CodeGeneratorX86_64::MoveConstant(Location location, int32_t value) { |
| 1196 | DCHECK(location.IsRegister()); |
| 1197 | Load64BitValue(location.AsRegister<CpuRegister>(), static_cast<int64_t>(value)); |
| 1198 | } |
| 1199 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1200 | void CodeGeneratorX86_64::MoveLocation( |
| 1201 | Location dst, Location src, Primitive::Type dst_type ATTRIBUTE_UNUSED) { |
| 1202 | Move(dst, src); |
| 1203 | } |
| 1204 | |
| 1205 | void CodeGeneratorX86_64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1206 | if (location.IsRegister()) { |
| 1207 | locations->AddTemp(location); |
| 1208 | } else { |
| 1209 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1210 | } |
| 1211 | } |
| 1212 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1213 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1214 | DCHECK(!successor->IsExitBlock()); |
| 1215 | |
| 1216 | HBasicBlock* block = got->GetBlock(); |
| 1217 | HInstruction* previous = got->GetPrevious(); |
| 1218 | |
| 1219 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1220 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1221 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1222 | return; |
| 1223 | } |
| 1224 | |
| 1225 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1226 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1227 | } |
| 1228 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1229 | __ jmp(codegen_->GetLabelOf(successor)); |
| 1230 | } |
| 1231 | } |
| 1232 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1233 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 1234 | got->SetLocations(nullptr); |
| 1235 | } |
| 1236 | |
| 1237 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 1238 | HandleGoto(got, got->GetSuccessor()); |
| 1239 | } |
| 1240 | |
| 1241 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1242 | try_boundary->SetLocations(nullptr); |
| 1243 | } |
| 1244 | |
| 1245 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1246 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1247 | if (!successor->IsExitBlock()) { |
| 1248 | HandleGoto(try_boundary, successor); |
| 1249 | } |
| 1250 | } |
| 1251 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1252 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 1253 | exit->SetLocations(nullptr); |
| 1254 | } |
| 1255 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1256 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1257 | } |
| 1258 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1259 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1260 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1261 | LabelType* true_label, |
| 1262 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1263 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1264 | __ j(kUnordered, true_label); |
| 1265 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1266 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1267 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1268 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1269 | } |
| 1270 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1271 | void InstructionCodeGeneratorX86_64::GenerateCompareTest(HCondition* condition) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1272 | LocationSummary* locations = condition->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1273 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1274 | Location left = locations->InAt(0); |
| 1275 | Location right = locations->InAt(1); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1276 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1277 | switch (type) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1278 | case Primitive::kPrimBoolean: |
| 1279 | case Primitive::kPrimByte: |
| 1280 | case Primitive::kPrimChar: |
| 1281 | case Primitive::kPrimShort: |
| 1282 | case Primitive::kPrimInt: |
| 1283 | case Primitive::kPrimNot: { |
| 1284 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1285 | if (right.IsConstant()) { |
| 1286 | int32_t value = CodeGenerator::GetInt32ValueOf(right.GetConstant()); |
| 1287 | if (value == 0) { |
| 1288 | __ testl(left_reg, left_reg); |
| 1289 | } else { |
| 1290 | __ cmpl(left_reg, Immediate(value)); |
| 1291 | } |
| 1292 | } else if (right.IsStackSlot()) { |
| 1293 | __ cmpl(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1294 | } else { |
| 1295 | __ cmpl(left_reg, right.AsRegister<CpuRegister>()); |
| 1296 | } |
| 1297 | break; |
| 1298 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1299 | case Primitive::kPrimLong: { |
| 1300 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1301 | if (right.IsConstant()) { |
| 1302 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1303 | codegen_->Compare64BitValue(left_reg, value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1304 | } else if (right.IsDoubleStackSlot()) { |
| 1305 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1306 | } else { |
| 1307 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1308 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1309 | break; |
| 1310 | } |
| 1311 | case Primitive::kPrimFloat: { |
| 1312 | if (right.IsFpuRegister()) { |
| 1313 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1314 | } else if (right.IsConstant()) { |
| 1315 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1316 | codegen_->LiteralFloatAddress( |
| 1317 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1318 | } else { |
| 1319 | DCHECK(right.IsStackSlot()); |
| 1320 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1321 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1322 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1323 | break; |
| 1324 | } |
| 1325 | case Primitive::kPrimDouble: { |
| 1326 | if (right.IsFpuRegister()) { |
| 1327 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1328 | } else if (right.IsConstant()) { |
| 1329 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1330 | codegen_->LiteralDoubleAddress( |
| 1331 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1332 | } else { |
| 1333 | DCHECK(right.IsDoubleStackSlot()); |
| 1334 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1335 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1336 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1337 | break; |
| 1338 | } |
| 1339 | default: |
| 1340 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1341 | } |
| 1342 | } |
| 1343 | |
| 1344 | template<class LabelType> |
| 1345 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HCondition* condition, |
| 1346 | LabelType* true_target_in, |
| 1347 | LabelType* false_target_in) { |
| 1348 | // Generated branching requires both targets to be explicit. If either of the |
| 1349 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1350 | LabelType fallthrough_target; |
| 1351 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1352 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1353 | |
| 1354 | // Generate the comparison to set the CC. |
| 1355 | GenerateCompareTest(condition); |
| 1356 | |
| 1357 | // Now generate the correct jump(s). |
| 1358 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1359 | switch (type) { |
| 1360 | case Primitive::kPrimLong: { |
| 1361 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
| 1362 | break; |
| 1363 | } |
| 1364 | case Primitive::kPrimFloat: { |
| 1365 | GenerateFPJumps(condition, true_target, false_target); |
| 1366 | break; |
| 1367 | } |
| 1368 | case Primitive::kPrimDouble: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1369 | GenerateFPJumps(condition, true_target, false_target); |
| 1370 | break; |
| 1371 | } |
| 1372 | default: |
| 1373 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1374 | } |
| 1375 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1376 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1377 | __ jmp(false_target); |
| 1378 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1379 | |
| 1380 | if (fallthrough_target.IsLinked()) { |
| 1381 | __ Bind(&fallthrough_target); |
| 1382 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1383 | } |
| 1384 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1385 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1386 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1387 | // are set only strictly before `branch`. We can't use the eflags on long |
| 1388 | // conditions if they are materialized due to the complex branching. |
| 1389 | return cond->IsCondition() && |
| 1390 | cond->GetNext() == branch && |
| 1391 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1392 | } |
| 1393 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1394 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1395 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1396 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1397 | LabelType* true_target, |
| 1398 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1399 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1400 | |
| 1401 | if (true_target == nullptr && false_target == nullptr) { |
| 1402 | // Nothing to do. The code always falls through. |
| 1403 | return; |
| 1404 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1405 | // Constant condition, statically compared against 1. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1406 | if (cond->AsIntConstant()->IsOne()) { |
| 1407 | if (true_target != nullptr) { |
| 1408 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1409 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1410 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1411 | DCHECK(cond->AsIntConstant()->IsZero()); |
| 1412 | if (false_target != nullptr) { |
| 1413 | __ jmp(false_target); |
| 1414 | } |
| 1415 | } |
| 1416 | return; |
| 1417 | } |
| 1418 | |
| 1419 | // The following code generates these patterns: |
| 1420 | // (1) true_target == nullptr && false_target != nullptr |
| 1421 | // - opposite condition true => branch to false_target |
| 1422 | // (2) true_target != nullptr && false_target == nullptr |
| 1423 | // - condition true => branch to true_target |
| 1424 | // (3) true_target != nullptr && false_target != nullptr |
| 1425 | // - condition true => branch to true_target |
| 1426 | // - branch to false_target |
| 1427 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1428 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1429 | if (true_target == nullptr) { |
| 1430 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1431 | } else { |
| 1432 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
| 1433 | } |
| 1434 | } else { |
| 1435 | // Materialized condition, compare against 0. |
| 1436 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1437 | if (lhs.IsRegister()) { |
| 1438 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1439 | } else { |
| 1440 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), Immediate(0)); |
| 1441 | } |
| 1442 | if (true_target == nullptr) { |
| 1443 | __ j(kEqual, false_target); |
| 1444 | } else { |
| 1445 | __ j(kNotEqual, true_target); |
| 1446 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1447 | } |
| 1448 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1449 | // Condition has not been materialized, use its inputs as the |
| 1450 | // comparison and its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1451 | HCondition* condition = cond->AsCondition(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1452 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1453 | // If this is a long or FP comparison that has been folded into |
| 1454 | // the HCondition, generate the comparison directly. |
| 1455 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1456 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1457 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1458 | return; |
| 1459 | } |
| 1460 | |
| 1461 | Location lhs = condition->GetLocations()->InAt(0); |
| 1462 | Location rhs = condition->GetLocations()->InAt(1); |
| 1463 | if (rhs.IsRegister()) { |
| 1464 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1465 | } else if (rhs.IsConstant()) { |
| 1466 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1467 | codegen_->Compare32BitValue(lhs.AsRegister<CpuRegister>(), constant); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1468 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1469 | __ cmpl(lhs.AsRegister<CpuRegister>(), |
| 1470 | Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1471 | } |
| 1472 | if (true_target == nullptr) { |
| 1473 | __ j(X86_64IntegerCondition(condition->GetOppositeCondition()), false_target); |
| 1474 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1475 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1476 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1477 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1478 | |
| 1479 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1480 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1481 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1482 | __ jmp(false_target); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1483 | } |
| 1484 | } |
| 1485 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1486 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1487 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1488 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1489 | locations->SetInAt(0, Location::Any()); |
| 1490 | } |
| 1491 | } |
| 1492 | |
| 1493 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1494 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1495 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1496 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1497 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1498 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1499 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1500 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1504 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1505 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1506 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1507 | locations->SetInAt(0, Location::Any()); |
| 1508 | } |
| 1509 | } |
| 1510 | |
| 1511 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1512 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86_64>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1513 | GenerateTestAndBranch<Label>(deoptimize, |
| 1514 | /* condition_input_index */ 0, |
| 1515 | slow_path->GetEntryLabel(), |
| 1516 | /* false_target */ nullptr); |
| 1517 | } |
| 1518 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1519 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1520 | // There are no conditional move instructions for XMMs. |
| 1521 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1522 | return false; |
| 1523 | } |
| 1524 | |
| 1525 | // A FP condition doesn't generate the single CC that we need. |
| 1526 | HInstruction* condition = select->GetCondition(); |
| 1527 | if (condition->IsCondition() && |
| 1528 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())) { |
| 1529 | return false; |
| 1530 | } |
| 1531 | |
| 1532 | // We can generate a CMOV for this Select. |
| 1533 | return true; |
| 1534 | } |
| 1535 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1536 | void LocationsBuilderX86_64::VisitSelect(HSelect* select) { |
| 1537 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 1538 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1539 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1540 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1541 | } else { |
| 1542 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1543 | if (SelectCanUseCMOV(select)) { |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1544 | if (select->InputAt(1)->IsConstant()) { |
| 1545 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1546 | } else { |
| 1547 | locations->SetInAt(1, Location::Any()); |
| 1548 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1549 | } else { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1550 | locations->SetInAt(1, Location::Any()); |
| 1551 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1552 | } |
| 1553 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1554 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1555 | } |
| 1556 | locations->SetOut(Location::SameAsFirstInput()); |
| 1557 | } |
| 1558 | |
| 1559 | void InstructionCodeGeneratorX86_64::VisitSelect(HSelect* select) { |
| 1560 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1561 | if (SelectCanUseCMOV(select)) { |
| 1562 | // If both the condition and the source types are integer, we can generate |
| 1563 | // a CMOV to implement Select. |
| 1564 | CpuRegister value_false = locations->InAt(0).AsRegister<CpuRegister>(); |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1565 | Location value_true_loc = locations->InAt(1); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1566 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1567 | |
| 1568 | HInstruction* select_condition = select->GetCondition(); |
| 1569 | Condition cond = kNotEqual; |
| 1570 | |
| 1571 | // Figure out how to test the 'condition'. |
| 1572 | if (select_condition->IsCondition()) { |
| 1573 | HCondition* condition = select_condition->AsCondition(); |
| 1574 | if (!condition->IsEmittedAtUseSite()) { |
| 1575 | // This was a previously materialized condition. |
| 1576 | // Can we use the existing condition code? |
| 1577 | if (AreEflagsSetFrom(condition, select)) { |
| 1578 | // Materialization was the previous instruction. Condition codes are right. |
| 1579 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1580 | } else { |
| 1581 | // No, we have to recreate the condition code. |
| 1582 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1583 | __ testl(cond_reg, cond_reg); |
| 1584 | } |
| 1585 | } else { |
| 1586 | GenerateCompareTest(condition); |
| 1587 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1588 | } |
| 1589 | } else { |
| 1590 | // Must be a boolean condition, which needs to be compared to 0. |
| 1591 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1592 | __ testl(cond_reg, cond_reg); |
| 1593 | } |
| 1594 | |
| 1595 | // If the condition is true, overwrite the output, which already contains false. |
| 1596 | // Generate the correct sized CMOV. |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1597 | bool is_64_bit = Primitive::Is64BitType(select->GetType()); |
| 1598 | if (value_true_loc.IsRegister()) { |
| 1599 | __ cmov(cond, value_false, value_true_loc.AsRegister<CpuRegister>(), is_64_bit); |
| 1600 | } else { |
| 1601 | __ cmov(cond, |
| 1602 | value_false, |
| 1603 | Address(CpuRegister(RSP), value_true_loc.GetStackIndex()), is_64_bit); |
| 1604 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1605 | } else { |
| 1606 | NearLabel false_target; |
| 1607 | GenerateTestAndBranch<NearLabel>(select, |
| 1608 | /* condition_input_index */ 2, |
| 1609 | /* true_target */ nullptr, |
| 1610 | &false_target); |
| 1611 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1612 | __ Bind(&false_target); |
| 1613 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1614 | } |
| 1615 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1616 | void LocationsBuilderX86_64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1617 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1618 | } |
| 1619 | |
| 1620 | void InstructionCodeGeneratorX86_64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1621 | codegen_->MaybeRecordNativeDebugInfo(info, info->GetDexPc()); |
| 1622 | } |
| 1623 | |
| 1624 | void CodeGeneratorX86_64::GenerateNop() { |
| 1625 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1626 | } |
| 1627 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1628 | void LocationsBuilderX86_64::VisitLocal(HLocal* local) { |
| 1629 | local->SetLocations(nullptr); |
| 1630 | } |
| 1631 | |
| 1632 | void InstructionCodeGeneratorX86_64::VisitLocal(HLocal* local) { |
| 1633 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
| 1634 | } |
| 1635 | |
| 1636 | void LocationsBuilderX86_64::VisitLoadLocal(HLoadLocal* local) { |
| 1637 | local->SetLocations(nullptr); |
| 1638 | } |
| 1639 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1640 | void InstructionCodeGeneratorX86_64::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1641 | // Nothing to do, this is driven by the code generator. |
| 1642 | } |
| 1643 | |
| 1644 | void LocationsBuilderX86_64::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1645 | LocationSummary* locations = |
| 1646 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1647 | switch (store->InputAt(1)->GetType()) { |
| 1648 | case Primitive::kPrimBoolean: |
| 1649 | case Primitive::kPrimByte: |
| 1650 | case Primitive::kPrimChar: |
| 1651 | case Primitive::kPrimShort: |
| 1652 | case Primitive::kPrimInt: |
| 1653 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1654 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1655 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1656 | break; |
| 1657 | |
| 1658 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1659 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1660 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1661 | break; |
| 1662 | |
| 1663 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1664 | LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1665 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1666 | } |
| 1667 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1668 | void InstructionCodeGeneratorX86_64::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1669 | } |
| 1670 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1671 | void LocationsBuilderX86_64::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1672 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1673 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1674 | // Handle the long/FP comparisons made in instruction simplification. |
| 1675 | switch (cond->InputAt(0)->GetType()) { |
| 1676 | case Primitive::kPrimLong: |
| 1677 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1678 | locations->SetInAt(1, Location::Any()); |
| 1679 | break; |
| 1680 | case Primitive::kPrimFloat: |
| 1681 | case Primitive::kPrimDouble: |
| 1682 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1683 | locations->SetInAt(1, Location::Any()); |
| 1684 | break; |
| 1685 | default: |
| 1686 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1687 | locations->SetInAt(1, Location::Any()); |
| 1688 | break; |
| 1689 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1690 | if (!cond->IsEmittedAtUseSite()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1691 | locations->SetOut(Location::RequiresRegister()); |
| 1692 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1693 | } |
| 1694 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1695 | void InstructionCodeGeneratorX86_64::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1696 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1697 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1698 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1699 | |
| 1700 | LocationSummary* locations = cond->GetLocations(); |
| 1701 | Location lhs = locations->InAt(0); |
| 1702 | Location rhs = locations->InAt(1); |
| 1703 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1704 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1705 | |
| 1706 | switch (cond->InputAt(0)->GetType()) { |
| 1707 | default: |
| 1708 | // Integer case. |
| 1709 | |
| 1710 | // Clear output register: setcc only sets the low byte. |
| 1711 | __ xorl(reg, reg); |
| 1712 | |
| 1713 | if (rhs.IsRegister()) { |
| 1714 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1715 | } else if (rhs.IsConstant()) { |
| 1716 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1717 | codegen_->Compare32BitValue(lhs.AsRegister<CpuRegister>(), constant); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1718 | } else { |
| 1719 | __ cmpl(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1720 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1721 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1722 | return; |
| 1723 | case Primitive::kPrimLong: |
| 1724 | // Clear output register: setcc only sets the low byte. |
| 1725 | __ xorl(reg, reg); |
| 1726 | |
| 1727 | if (rhs.IsRegister()) { |
| 1728 | __ cmpq(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1729 | } else if (rhs.IsConstant()) { |
| 1730 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1731 | codegen_->Compare64BitValue(lhs.AsRegister<CpuRegister>(), value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1732 | } else { |
| 1733 | __ cmpq(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1734 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1735 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1736 | return; |
| 1737 | case Primitive::kPrimFloat: { |
| 1738 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1739 | if (rhs.IsConstant()) { |
| 1740 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 1741 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 1742 | } else if (rhs.IsStackSlot()) { |
| 1743 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1744 | } else { |
| 1745 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1746 | } |
| 1747 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1748 | break; |
| 1749 | } |
| 1750 | case Primitive::kPrimDouble: { |
| 1751 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1752 | if (rhs.IsConstant()) { |
| 1753 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1754 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 1755 | } else if (rhs.IsDoubleStackSlot()) { |
| 1756 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1757 | } else { |
| 1758 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1759 | } |
| 1760 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1761 | break; |
| 1762 | } |
| 1763 | } |
| 1764 | |
| 1765 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1766 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1767 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1768 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1769 | __ Bind(&false_label); |
| 1770 | __ xorl(reg, reg); |
| 1771 | __ jmp(&done_label); |
| 1772 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1773 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1774 | __ Bind(&true_label); |
| 1775 | __ movl(reg, Immediate(1)); |
| 1776 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1780 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1781 | } |
| 1782 | |
| 1783 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1784 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1785 | } |
| 1786 | |
| 1787 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1788 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1792 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1793 | } |
| 1794 | |
| 1795 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1796 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1797 | } |
| 1798 | |
| 1799 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1800 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1801 | } |
| 1802 | |
| 1803 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1804 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1805 | } |
| 1806 | |
| 1807 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1808 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1812 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1813 | } |
| 1814 | |
| 1815 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1816 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1817 | } |
| 1818 | |
| 1819 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1820 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1821 | } |
| 1822 | |
| 1823 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1824 | HandleCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1825 | } |
| 1826 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1827 | void LocationsBuilderX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1828 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1829 | } |
| 1830 | |
| 1831 | void InstructionCodeGeneratorX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1832 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | void LocationsBuilderX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1836 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1837 | } |
| 1838 | |
| 1839 | void InstructionCodeGeneratorX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1840 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1841 | } |
| 1842 | |
| 1843 | void LocationsBuilderX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1844 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1845 | } |
| 1846 | |
| 1847 | void InstructionCodeGeneratorX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1848 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1849 | } |
| 1850 | |
| 1851 | void LocationsBuilderX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1852 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1853 | } |
| 1854 | |
| 1855 | void InstructionCodeGeneratorX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1856 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1857 | } |
| 1858 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1859 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1860 | LocationSummary* locations = |
| 1861 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1862 | switch (compare->InputAt(0)->GetType()) { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1863 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1864 | case Primitive::kPrimLong: { |
| 1865 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1866 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1867 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1868 | break; |
| 1869 | } |
| 1870 | case Primitive::kPrimFloat: |
| 1871 | case Primitive::kPrimDouble: { |
| 1872 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1873 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1874 | locations->SetOut(Location::RequiresRegister()); |
| 1875 | break; |
| 1876 | } |
| 1877 | default: |
| 1878 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 1879 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1880 | } |
| 1881 | |
| 1882 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1883 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1884 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1885 | Location left = locations->InAt(0); |
| 1886 | Location right = locations->InAt(1); |
| 1887 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1888 | NearLabel less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1889 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1890 | Condition less_cond = kLess; |
| 1891 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1892 | switch (type) { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1893 | case Primitive::kPrimInt: { |
| 1894 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1895 | if (right.IsConstant()) { |
| 1896 | int32_t value = right.GetConstant()->AsIntConstant()->GetValue(); |
| 1897 | codegen_->Compare32BitValue(left_reg, value); |
| 1898 | } else if (right.IsStackSlot()) { |
| 1899 | __ cmpl(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1900 | } else { |
| 1901 | __ cmpl(left_reg, right.AsRegister<CpuRegister>()); |
| 1902 | } |
| 1903 | break; |
| 1904 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1905 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1906 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1907 | if (right.IsConstant()) { |
| 1908 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1909 | codegen_->Compare64BitValue(left_reg, value); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1910 | } else if (right.IsDoubleStackSlot()) { |
| 1911 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1912 | } else { |
| 1913 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1914 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1915 | break; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1916 | } |
| 1917 | case Primitive::kPrimFloat: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1918 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1919 | if (right.IsConstant()) { |
| 1920 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 1921 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 1922 | } else if (right.IsStackSlot()) { |
| 1923 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1924 | } else { |
| 1925 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1926 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1927 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1928 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1929 | break; |
| 1930 | } |
| 1931 | case Primitive::kPrimDouble: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1932 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1933 | if (right.IsConstant()) { |
| 1934 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1935 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 1936 | } else if (right.IsDoubleStackSlot()) { |
| 1937 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1938 | } else { |
| 1939 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1940 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1941 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1942 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1943 | break; |
| 1944 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1945 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1946 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1947 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1948 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1949 | __ movl(out, Immediate(0)); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1950 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1951 | __ j(less_cond, &less); |
Calin Juravle | fd86124 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1952 | |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1953 | __ Bind(&greater); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1954 | __ movl(out, Immediate(1)); |
| 1955 | __ jmp(&done); |
| 1956 | |
| 1957 | __ Bind(&less); |
| 1958 | __ movl(out, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1959 | |
| 1960 | __ Bind(&done); |
| 1961 | } |
| 1962 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1963 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1964 | LocationSummary* locations = |
| 1965 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1966 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1967 | } |
| 1968 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1969 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1970 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1971 | } |
| 1972 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1973 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 1974 | LocationSummary* locations = |
| 1975 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1976 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1977 | } |
| 1978 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1979 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1980 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1981 | } |
| 1982 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1983 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1984 | LocationSummary* locations = |
| 1985 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1986 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1987 | } |
| 1988 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1989 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1990 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1991 | } |
| 1992 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1993 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 1994 | LocationSummary* locations = |
| 1995 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1996 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1997 | } |
| 1998 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1999 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2000 | // Will be generated at use site. |
| 2001 | } |
| 2002 | |
| 2003 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2004 | LocationSummary* locations = |
| 2005 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2006 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2007 | } |
| 2008 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2009 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant( |
| 2010 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2011 | // Will be generated at use site. |
| 2012 | } |
| 2013 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2014 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2015 | memory_barrier->SetLocations(nullptr); |
| 2016 | } |
| 2017 | |
| 2018 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2019 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2020 | } |
| 2021 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2022 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 2023 | ret->SetLocations(nullptr); |
| 2024 | } |
| 2025 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2026 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2027 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2028 | } |
| 2029 | |
| 2030 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2031 | LocationSummary* locations = |
| 2032 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2033 | switch (ret->InputAt(0)->GetType()) { |
| 2034 | case Primitive::kPrimBoolean: |
| 2035 | case Primitive::kPrimByte: |
| 2036 | case Primitive::kPrimChar: |
| 2037 | case Primitive::kPrimShort: |
| 2038 | case Primitive::kPrimInt: |
| 2039 | case Primitive::kPrimNot: |
| 2040 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2041 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2042 | break; |
| 2043 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2044 | case Primitive::kPrimFloat: |
| 2045 | case Primitive::kPrimDouble: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2046 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2047 | break; |
| 2048 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2049 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2050 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2051 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2052 | } |
| 2053 | |
| 2054 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 2055 | if (kIsDebugBuild) { |
| 2056 | switch (ret->InputAt(0)->GetType()) { |
| 2057 | case Primitive::kPrimBoolean: |
| 2058 | case Primitive::kPrimByte: |
| 2059 | case Primitive::kPrimChar: |
| 2060 | case Primitive::kPrimShort: |
| 2061 | case Primitive::kPrimInt: |
| 2062 | case Primitive::kPrimNot: |
| 2063 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2064 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2065 | break; |
| 2066 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2067 | case Primitive::kPrimFloat: |
| 2068 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2069 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2070 | XMM0); |
| 2071 | break; |
| 2072 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2073 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2074 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2075 | } |
| 2076 | } |
| 2077 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2078 | } |
| 2079 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2080 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(Primitive::Type type) const { |
| 2081 | switch (type) { |
| 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: |
| 2089 | return Location::RegisterLocation(RAX); |
| 2090 | |
| 2091 | case Primitive::kPrimVoid: |
| 2092 | return Location::NoLocation(); |
| 2093 | |
| 2094 | case Primitive::kPrimDouble: |
| 2095 | case Primitive::kPrimFloat: |
| 2096 | return Location::FpuRegisterLocation(XMM0); |
| 2097 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2098 | |
| 2099 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2100 | } |
| 2101 | |
| 2102 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 2103 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2104 | } |
| 2105 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2106 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2107 | switch (type) { |
| 2108 | case Primitive::kPrimBoolean: |
| 2109 | case Primitive::kPrimByte: |
| 2110 | case Primitive::kPrimChar: |
| 2111 | case Primitive::kPrimShort: |
| 2112 | case Primitive::kPrimInt: |
| 2113 | case Primitive::kPrimNot: { |
| 2114 | uint32_t index = gp_index_++; |
| 2115 | stack_index_++; |
| 2116 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2117 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2118 | } else { |
| 2119 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2120 | } |
| 2121 | } |
| 2122 | |
| 2123 | case Primitive::kPrimLong: { |
| 2124 | uint32_t index = gp_index_; |
| 2125 | stack_index_ += 2; |
| 2126 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2127 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2128 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2129 | } else { |
| 2130 | gp_index_ += 2; |
| 2131 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2132 | } |
| 2133 | } |
| 2134 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2135 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2136 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2137 | stack_index_++; |
| 2138 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2139 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2140 | } else { |
| 2141 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2142 | } |
| 2143 | } |
| 2144 | |
| 2145 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2146 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2147 | stack_index_ += 2; |
| 2148 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2149 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2150 | } else { |
| 2151 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2152 | } |
| 2153 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2154 | |
| 2155 | case Primitive::kPrimVoid: |
| 2156 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2157 | break; |
| 2158 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2159 | return Location::NoLocation(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2160 | } |
| 2161 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2162 | void LocationsBuilderX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2163 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2164 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2165 | // the method_idx. |
| 2166 | HandleInvoke(invoke); |
| 2167 | } |
| 2168 | |
| 2169 | void InstructionCodeGeneratorX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2170 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2171 | } |
| 2172 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2173 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2174 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2175 | // art::PrepareForRegisterAllocation. |
| 2176 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2177 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2178 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2179 | if (intrinsic.TryDispatch(invoke)) { |
| 2180 | return; |
| 2181 | } |
| 2182 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2183 | HandleInvoke(invoke); |
| 2184 | } |
| 2185 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2186 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 2187 | if (invoke->GetLocations()->Intrinsified()) { |
| 2188 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 2189 | intrinsic.Dispatch(invoke); |
| 2190 | return true; |
| 2191 | } |
| 2192 | return false; |
| 2193 | } |
| 2194 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2195 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2196 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2197 | // art::PrepareForRegisterAllocation. |
| 2198 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2199 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2200 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2201 | return; |
| 2202 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2203 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2204 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2205 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2206 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 2207 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2208 | } |
| 2209 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2210 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2211 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2212 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2213 | } |
| 2214 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2215 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2216 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2217 | if (intrinsic.TryDispatch(invoke)) { |
| 2218 | return; |
| 2219 | } |
| 2220 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2221 | HandleInvoke(invoke); |
| 2222 | } |
| 2223 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2224 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2225 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2226 | return; |
| 2227 | } |
| 2228 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2229 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2230 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2231 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2232 | } |
| 2233 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2234 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2235 | HandleInvoke(invoke); |
| 2236 | // Add the hidden argument. |
| 2237 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 2238 | } |
| 2239 | |
| 2240 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2241 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2242 | LocationSummary* locations = invoke->GetLocations(); |
| 2243 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2244 | CpuRegister hidden_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2245 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 2246 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86_64PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2247 | Location receiver = locations->InAt(0); |
| 2248 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 2249 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2250 | // Set the hidden argument. This is safe to do this here, as RAX |
| 2251 | // won't be modified thereafter, before the `call` instruction. |
| 2252 | DCHECK_EQ(RAX, hidden_reg.AsRegister()); |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2253 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2254 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2255 | if (receiver.IsStackSlot()) { |
| 2256 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2257 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2258 | __ movl(temp, Address(temp, class_offset)); |
| 2259 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2260 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2261 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2262 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2263 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2264 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2265 | // emit a read barrier for the previous class reference load. |
| 2266 | // However this is not required in practice, as this is an |
| 2267 | // intermediate/temporary reference and because the current |
| 2268 | // concurrent copying collector keeps the from-space memory |
| 2269 | // intact/accessible until the end of the marking phase (the |
| 2270 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2271 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2272 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2273 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2274 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2275 | __ call(Address(temp, |
| 2276 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64WordSize).SizeValue())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2277 | |
| 2278 | DCHECK(!codegen_->IsLeafMethod()); |
| 2279 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2280 | } |
| 2281 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2282 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 2283 | LocationSummary* locations = |
| 2284 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2285 | switch (neg->GetResultType()) { |
| 2286 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2287 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2288 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2289 | locations->SetOut(Location::SameAsFirstInput()); |
| 2290 | break; |
| 2291 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2292 | case Primitive::kPrimFloat: |
| 2293 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2294 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2295 | locations->SetOut(Location::SameAsFirstInput()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2296 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2297 | break; |
| 2298 | |
| 2299 | default: |
| 2300 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2301 | } |
| 2302 | } |
| 2303 | |
| 2304 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 2305 | LocationSummary* locations = neg->GetLocations(); |
| 2306 | Location out = locations->Out(); |
| 2307 | Location in = locations->InAt(0); |
| 2308 | switch (neg->GetResultType()) { |
| 2309 | case Primitive::kPrimInt: |
| 2310 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2311 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2312 | __ negl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2313 | break; |
| 2314 | |
| 2315 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2316 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2317 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2318 | __ negq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2319 | break; |
| 2320 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2321 | case Primitive::kPrimFloat: { |
| 2322 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2323 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2324 | // Implement float negation with an exclusive or with value |
| 2325 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2326 | // single-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2327 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2328 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2329 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2330 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2331 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2332 | case Primitive::kPrimDouble: { |
| 2333 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2334 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2335 | // Implement double negation with an exclusive or with value |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2336 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2337 | // a double-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2338 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2339 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2340 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2341 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2342 | |
| 2343 | default: |
| 2344 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2345 | } |
| 2346 | } |
| 2347 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2348 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2349 | LocationSummary* locations = |
| 2350 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 2351 | Primitive::Type result_type = conversion->GetResultType(); |
| 2352 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2353 | DCHECK_NE(result_type, input_type); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2354 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2355 | // The Java language does not allow treating boolean as an integral type but |
| 2356 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2357 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2358 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2359 | case Primitive::kPrimByte: |
| 2360 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2361 | case Primitive::kPrimLong: |
| 2362 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2363 | case Primitive::kPrimBoolean: |
| 2364 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2365 | case Primitive::kPrimShort: |
| 2366 | case Primitive::kPrimInt: |
| 2367 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2368 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2369 | locations->SetInAt(0, Location::Any()); |
| 2370 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2371 | break; |
| 2372 | |
| 2373 | default: |
| 2374 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2375 | << " to " << result_type; |
| 2376 | } |
| 2377 | break; |
| 2378 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2379 | case Primitive::kPrimShort: |
| 2380 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2381 | case Primitive::kPrimLong: |
| 2382 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2383 | case Primitive::kPrimBoolean: |
| 2384 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2385 | case Primitive::kPrimByte: |
| 2386 | case Primitive::kPrimInt: |
| 2387 | case Primitive::kPrimChar: |
| 2388 | // Processing a Dex `int-to-short' instruction. |
| 2389 | locations->SetInAt(0, Location::Any()); |
| 2390 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2391 | break; |
| 2392 | |
| 2393 | default: |
| 2394 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2395 | << " to " << result_type; |
| 2396 | } |
| 2397 | break; |
| 2398 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2399 | case Primitive::kPrimInt: |
| 2400 | switch (input_type) { |
| 2401 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2402 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2403 | locations->SetInAt(0, Location::Any()); |
| 2404 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2405 | break; |
| 2406 | |
| 2407 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2408 | // Processing a Dex `float-to-int' instruction. |
| 2409 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2410 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2411 | break; |
| 2412 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2413 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2414 | // Processing a Dex `double-to-int' instruction. |
| 2415 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2416 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2417 | break; |
| 2418 | |
| 2419 | default: |
| 2420 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2421 | << " to " << result_type; |
| 2422 | } |
| 2423 | break; |
| 2424 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2425 | case Primitive::kPrimLong: |
| 2426 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2427 | case Primitive::kPrimBoolean: |
| 2428 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2429 | case Primitive::kPrimByte: |
| 2430 | case Primitive::kPrimShort: |
| 2431 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2432 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2433 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2434 | // TODO: We would benefit from a (to-be-implemented) |
| 2435 | // Location::RegisterOrStackSlot requirement for this input. |
| 2436 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2437 | locations->SetOut(Location::RequiresRegister()); |
| 2438 | break; |
| 2439 | |
| 2440 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2441 | // Processing a Dex `float-to-long' instruction. |
| 2442 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2443 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2444 | break; |
| 2445 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2446 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2447 | // Processing a Dex `double-to-long' instruction. |
| 2448 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2449 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2450 | break; |
| 2451 | |
| 2452 | default: |
| 2453 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2454 | << " to " << result_type; |
| 2455 | } |
| 2456 | break; |
| 2457 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2458 | case Primitive::kPrimChar: |
| 2459 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2460 | case Primitive::kPrimLong: |
| 2461 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2462 | case Primitive::kPrimBoolean: |
| 2463 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2464 | case Primitive::kPrimByte: |
| 2465 | case Primitive::kPrimShort: |
| 2466 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2467 | // Processing a Dex `int-to-char' instruction. |
| 2468 | locations->SetInAt(0, Location::Any()); |
| 2469 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2470 | break; |
| 2471 | |
| 2472 | default: |
| 2473 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2474 | << " to " << result_type; |
| 2475 | } |
| 2476 | break; |
| 2477 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2478 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2479 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2480 | case Primitive::kPrimBoolean: |
| 2481 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2482 | case Primitive::kPrimByte: |
| 2483 | case Primitive::kPrimShort: |
| 2484 | case Primitive::kPrimInt: |
| 2485 | case Primitive::kPrimChar: |
| 2486 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2487 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2488 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2489 | break; |
| 2490 | |
| 2491 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2492 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2493 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2494 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2495 | break; |
| 2496 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2497 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2498 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2499 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2500 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2501 | break; |
| 2502 | |
| 2503 | default: |
| 2504 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2505 | << " to " << result_type; |
| 2506 | }; |
| 2507 | break; |
| 2508 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2509 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2510 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2511 | case Primitive::kPrimBoolean: |
| 2512 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2513 | case Primitive::kPrimByte: |
| 2514 | case Primitive::kPrimShort: |
| 2515 | case Primitive::kPrimInt: |
| 2516 | case Primitive::kPrimChar: |
| 2517 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2518 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2519 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2520 | break; |
| 2521 | |
| 2522 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2523 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2524 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2525 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2526 | break; |
| 2527 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2528 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2529 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2530 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2531 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2532 | break; |
| 2533 | |
| 2534 | default: |
| 2535 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2536 | << " to " << result_type; |
| 2537 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2538 | break; |
| 2539 | |
| 2540 | default: |
| 2541 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2542 | << " to " << result_type; |
| 2543 | } |
| 2544 | } |
| 2545 | |
| 2546 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2547 | LocationSummary* locations = conversion->GetLocations(); |
| 2548 | Location out = locations->Out(); |
| 2549 | Location in = locations->InAt(0); |
| 2550 | Primitive::Type result_type = conversion->GetResultType(); |
| 2551 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2552 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2553 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2554 | case Primitive::kPrimByte: |
| 2555 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2556 | case Primitive::kPrimLong: |
| 2557 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2558 | case Primitive::kPrimBoolean: |
| 2559 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2560 | case Primitive::kPrimShort: |
| 2561 | case Primitive::kPrimInt: |
| 2562 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2563 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2564 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2565 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2566 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2567 | __ movsxb(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2568 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2569 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2570 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2571 | Immediate(static_cast<int8_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2572 | } |
| 2573 | break; |
| 2574 | |
| 2575 | default: |
| 2576 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2577 | << " to " << result_type; |
| 2578 | } |
| 2579 | break; |
| 2580 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2581 | case Primitive::kPrimShort: |
| 2582 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2583 | case Primitive::kPrimLong: |
| 2584 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2585 | case Primitive::kPrimBoolean: |
| 2586 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2587 | case Primitive::kPrimByte: |
| 2588 | case Primitive::kPrimInt: |
| 2589 | case Primitive::kPrimChar: |
| 2590 | // Processing a Dex `int-to-short' instruction. |
| 2591 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2592 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2593 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2594 | __ movsxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2595 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2596 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2597 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2598 | Immediate(static_cast<int16_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2599 | } |
| 2600 | break; |
| 2601 | |
| 2602 | default: |
| 2603 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2604 | << " to " << result_type; |
| 2605 | } |
| 2606 | break; |
| 2607 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2608 | case Primitive::kPrimInt: |
| 2609 | switch (input_type) { |
| 2610 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2611 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2612 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2613 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2614 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2615 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2616 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2617 | } else { |
| 2618 | DCHECK(in.IsConstant()); |
| 2619 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2620 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2621 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2622 | } |
| 2623 | break; |
| 2624 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2625 | case Primitive::kPrimFloat: { |
| 2626 | // Processing a Dex `float-to-int' instruction. |
| 2627 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2628 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2629 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2630 | |
| 2631 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2632 | // if input >= (float)INT_MAX goto done |
| 2633 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimIntMax)); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2634 | __ j(kAboveEqual, &done); |
| 2635 | // if input == NaN goto nan |
| 2636 | __ j(kUnordered, &nan); |
| 2637 | // output = float-to-int-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2638 | __ cvttss2si(output, input, false); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2639 | __ jmp(&done); |
| 2640 | __ Bind(&nan); |
| 2641 | // output = 0 |
| 2642 | __ xorl(output, output); |
| 2643 | __ Bind(&done); |
| 2644 | break; |
| 2645 | } |
| 2646 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2647 | case Primitive::kPrimDouble: { |
| 2648 | // Processing a Dex `double-to-int' instruction. |
| 2649 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2650 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2651 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2652 | |
| 2653 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2654 | // if input >= (double)INT_MAX goto done |
| 2655 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2656 | __ j(kAboveEqual, &done); |
| 2657 | // if input == NaN goto nan |
| 2658 | __ j(kUnordered, &nan); |
| 2659 | // output = double-to-int-truncate(input) |
| 2660 | __ cvttsd2si(output, input); |
| 2661 | __ jmp(&done); |
| 2662 | __ Bind(&nan); |
| 2663 | // output = 0 |
| 2664 | __ xorl(output, output); |
| 2665 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2666 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2667 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2668 | |
| 2669 | default: |
| 2670 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2671 | << " to " << result_type; |
| 2672 | } |
| 2673 | break; |
| 2674 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2675 | case Primitive::kPrimLong: |
| 2676 | switch (input_type) { |
| 2677 | DCHECK(out.IsRegister()); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2678 | case Primitive::kPrimBoolean: |
| 2679 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2680 | case Primitive::kPrimByte: |
| 2681 | case Primitive::kPrimShort: |
| 2682 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2683 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2684 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2685 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2686 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2687 | break; |
| 2688 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2689 | case Primitive::kPrimFloat: { |
| 2690 | // Processing a Dex `float-to-long' instruction. |
| 2691 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2692 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2693 | NearLabel done, nan; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2694 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2695 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2696 | // if input >= (float)LONG_MAX goto done |
| 2697 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimLongMax)); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2698 | __ j(kAboveEqual, &done); |
| 2699 | // if input == NaN goto nan |
| 2700 | __ j(kUnordered, &nan); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2701 | // output = float-to-long-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2702 | __ cvttss2si(output, input, true); |
| 2703 | __ jmp(&done); |
| 2704 | __ Bind(&nan); |
| 2705 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2706 | __ xorl(output, output); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2707 | __ Bind(&done); |
| 2708 | break; |
| 2709 | } |
| 2710 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2711 | case Primitive::kPrimDouble: { |
| 2712 | // Processing a Dex `double-to-long' instruction. |
| 2713 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2714 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2715 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2716 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2717 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2718 | // if input >= (double)LONG_MAX goto done |
| 2719 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimLongMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2720 | __ j(kAboveEqual, &done); |
| 2721 | // if input == NaN goto nan |
| 2722 | __ j(kUnordered, &nan); |
| 2723 | // output = double-to-long-truncate(input) |
| 2724 | __ cvttsd2si(output, input, true); |
| 2725 | __ jmp(&done); |
| 2726 | __ Bind(&nan); |
| 2727 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2728 | __ xorl(output, output); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2729 | __ Bind(&done); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2730 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2731 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2732 | |
| 2733 | default: |
| 2734 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2735 | << " to " << result_type; |
| 2736 | } |
| 2737 | break; |
| 2738 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2739 | case Primitive::kPrimChar: |
| 2740 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2741 | case Primitive::kPrimLong: |
| 2742 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2743 | case Primitive::kPrimBoolean: |
| 2744 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2745 | case Primitive::kPrimByte: |
| 2746 | case Primitive::kPrimShort: |
| 2747 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2748 | // Processing a Dex `int-to-char' instruction. |
| 2749 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2750 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2751 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2752 | __ movzxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2753 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2754 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2755 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2756 | Immediate(static_cast<uint16_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2757 | } |
| 2758 | break; |
| 2759 | |
| 2760 | default: |
| 2761 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2762 | << " to " << result_type; |
| 2763 | } |
| 2764 | break; |
| 2765 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2766 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2767 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2768 | case Primitive::kPrimBoolean: |
| 2769 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2770 | case Primitive::kPrimByte: |
| 2771 | case Primitive::kPrimShort: |
| 2772 | case Primitive::kPrimInt: |
| 2773 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2774 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2775 | if (in.IsRegister()) { |
| 2776 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2777 | } else if (in.IsConstant()) { |
| 2778 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2779 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2780 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2781 | } else { |
| 2782 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2783 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2784 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2785 | break; |
| 2786 | |
| 2787 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2788 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2789 | if (in.IsRegister()) { |
| 2790 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2791 | } else if (in.IsConstant()) { |
| 2792 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2793 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2794 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2795 | } else { |
| 2796 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2797 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2798 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2799 | break; |
| 2800 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2801 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2802 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2803 | if (in.IsFpuRegister()) { |
| 2804 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2805 | } else if (in.IsConstant()) { |
| 2806 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2807 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2808 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2809 | } else { |
| 2810 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 2811 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2812 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2813 | break; |
| 2814 | |
| 2815 | default: |
| 2816 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2817 | << " to " << result_type; |
| 2818 | }; |
| 2819 | break; |
| 2820 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2821 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2822 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2823 | case Primitive::kPrimBoolean: |
| 2824 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2825 | case Primitive::kPrimByte: |
| 2826 | case Primitive::kPrimShort: |
| 2827 | case Primitive::kPrimInt: |
| 2828 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2829 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2830 | if (in.IsRegister()) { |
| 2831 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2832 | } else if (in.IsConstant()) { |
| 2833 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2834 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2835 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2836 | } else { |
| 2837 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2838 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2839 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2840 | break; |
| 2841 | |
| 2842 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2843 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2844 | if (in.IsRegister()) { |
| 2845 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2846 | } else if (in.IsConstant()) { |
| 2847 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2848 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2849 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2850 | } else { |
| 2851 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2852 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2853 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2854 | break; |
| 2855 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2856 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2857 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2858 | if (in.IsFpuRegister()) { |
| 2859 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2860 | } else if (in.IsConstant()) { |
| 2861 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 2862 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2863 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2864 | } else { |
| 2865 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 2866 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2867 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2868 | break; |
| 2869 | |
| 2870 | default: |
| 2871 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2872 | << " to " << result_type; |
| 2873 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2874 | break; |
| 2875 | |
| 2876 | default: |
| 2877 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2878 | << " to " << result_type; |
| 2879 | } |
| 2880 | } |
| 2881 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2882 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2883 | LocationSummary* locations = |
| 2884 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2885 | switch (add->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2886 | case Primitive::kPrimInt: { |
| 2887 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2888 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2889 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2890 | break; |
| 2891 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2892 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2893 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2894 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2895 | // 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] | 2896 | locations->SetInAt(1, Location::RegisterOrInt32Constant(add->InputAt(1))); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2897 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2898 | break; |
| 2899 | } |
| 2900 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2901 | case Primitive::kPrimDouble: |
| 2902 | case Primitive::kPrimFloat: { |
| 2903 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2904 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2905 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2906 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2907 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2908 | |
| 2909 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2910 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2911 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2912 | } |
| 2913 | |
| 2914 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 2915 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2916 | Location first = locations->InAt(0); |
| 2917 | Location second = locations->InAt(1); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2918 | Location out = locations->Out(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2919 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2920 | switch (add->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2921 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2922 | if (second.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2923 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2924 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2925 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2926 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2927 | } else { |
| 2928 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2929 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2930 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2931 | } else if (second.IsConstant()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2932 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2933 | __ addl(out.AsRegister<CpuRegister>(), |
| 2934 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 2935 | } else { |
| 2936 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2937 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 2938 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2939 | } else { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2940 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2941 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2942 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2943 | break; |
| 2944 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2945 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2946 | case Primitive::kPrimLong: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2947 | if (second.IsRegister()) { |
| 2948 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2949 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2950 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2951 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2952 | } else { |
| 2953 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2954 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2955 | } |
| 2956 | } else { |
| 2957 | DCHECK(second.IsConstant()); |
| 2958 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2959 | int32_t int32_value = Low32Bits(value); |
| 2960 | DCHECK_EQ(int32_value, value); |
| 2961 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2962 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 2963 | } else { |
| 2964 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2965 | first.AsRegister<CpuRegister>(), int32_value)); |
| 2966 | } |
| 2967 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2968 | break; |
| 2969 | } |
| 2970 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2971 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2972 | if (second.IsFpuRegister()) { |
| 2973 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2974 | } else if (second.IsConstant()) { |
| 2975 | __ addss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2976 | codegen_->LiteralFloatAddress( |
| 2977 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2978 | } else { |
| 2979 | DCHECK(second.IsStackSlot()); |
| 2980 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2981 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2982 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2983 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2984 | } |
| 2985 | |
| 2986 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2987 | if (second.IsFpuRegister()) { |
| 2988 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2989 | } else if (second.IsConstant()) { |
| 2990 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2991 | codegen_->LiteralDoubleAddress( |
| 2992 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2993 | } else { |
| 2994 | DCHECK(second.IsDoubleStackSlot()); |
| 2995 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2996 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2997 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2998 | break; |
| 2999 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3000 | |
| 3001 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3002 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3003 | } |
| 3004 | } |
| 3005 | |
| 3006 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3007 | LocationSummary* locations = |
| 3008 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3009 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3010 | case Primitive::kPrimInt: { |
| 3011 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3012 | locations->SetInAt(1, Location::Any()); |
| 3013 | locations->SetOut(Location::SameAsFirstInput()); |
| 3014 | break; |
| 3015 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3016 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3017 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 3018 | locations->SetInAt(1, Location::RegisterOrInt32Constant(sub->InputAt(1))); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3019 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3020 | break; |
| 3021 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3022 | case Primitive::kPrimFloat: |
| 3023 | case Primitive::kPrimDouble: { |
| 3024 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3025 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3026 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3027 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3028 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3029 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3030 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3031 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3032 | } |
| 3033 | |
| 3034 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 3035 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3036 | Location first = locations->InAt(0); |
| 3037 | Location second = locations->InAt(1); |
| 3038 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3039 | switch (sub->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3040 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3041 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3042 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3043 | } else if (second.IsConstant()) { |
| 3044 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3045 | __ subl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3046 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3047 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3048 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3049 | break; |
| 3050 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3051 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3052 | if (second.IsConstant()) { |
| 3053 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3054 | DCHECK(IsInt<32>(value)); |
| 3055 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 3056 | } else { |
| 3057 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 3058 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3059 | break; |
| 3060 | } |
| 3061 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3062 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3063 | if (second.IsFpuRegister()) { |
| 3064 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3065 | } else if (second.IsConstant()) { |
| 3066 | __ subss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3067 | codegen_->LiteralFloatAddress( |
| 3068 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3069 | } else { |
| 3070 | DCHECK(second.IsStackSlot()); |
| 3071 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3072 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3073 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3074 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3075 | } |
| 3076 | |
| 3077 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3078 | if (second.IsFpuRegister()) { |
| 3079 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3080 | } else if (second.IsConstant()) { |
| 3081 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3082 | codegen_->LiteralDoubleAddress( |
| 3083 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3084 | } else { |
| 3085 | DCHECK(second.IsDoubleStackSlot()); |
| 3086 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3087 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3088 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3089 | break; |
| 3090 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3091 | |
| 3092 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3093 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3094 | } |
| 3095 | } |
| 3096 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3097 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 3098 | LocationSummary* locations = |
| 3099 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3100 | switch (mul->GetResultType()) { |
| 3101 | case Primitive::kPrimInt: { |
| 3102 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3103 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3104 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3105 | // Can use 3 operand multiply. |
| 3106 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3107 | } else { |
| 3108 | locations->SetOut(Location::SameAsFirstInput()); |
| 3109 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3110 | break; |
| 3111 | } |
| 3112 | case Primitive::kPrimLong: { |
| 3113 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3114 | locations->SetInAt(1, Location::Any()); |
| 3115 | if (mul->InputAt(1)->IsLongConstant() && |
| 3116 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3117 | // Can use 3 operand multiply. |
| 3118 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3119 | } else { |
| 3120 | locations->SetOut(Location::SameAsFirstInput()); |
| 3121 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3122 | break; |
| 3123 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3124 | case Primitive::kPrimFloat: |
| 3125 | case Primitive::kPrimDouble: { |
| 3126 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3127 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3128 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3129 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3130 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3131 | |
| 3132 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3133 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3134 | } |
| 3135 | } |
| 3136 | |
| 3137 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 3138 | LocationSummary* locations = mul->GetLocations(); |
| 3139 | Location first = locations->InAt(0); |
| 3140 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3141 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3142 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3143 | case Primitive::kPrimInt: |
| 3144 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3145 | // problems where the output may not be the same as the first operand. |
| 3146 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3147 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3148 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 3149 | } else if (second.IsRegister()) { |
| 3150 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3151 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3152 | } else { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3153 | DCHECK(first.Equals(out)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3154 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3155 | __ imull(first.AsRegister<CpuRegister>(), |
| 3156 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3157 | } |
| 3158 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3159 | case Primitive::kPrimLong: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3160 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3161 | // problems where the output may not be the same as the first operand. |
| 3162 | if (mul->InputAt(1)->IsLongConstant()) { |
| 3163 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 3164 | if (IsInt<32>(value)) { |
| 3165 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 3166 | Immediate(static_cast<int32_t>(value))); |
| 3167 | } else { |
| 3168 | // Have to use the constant area. |
| 3169 | DCHECK(first.Equals(out)); |
| 3170 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 3171 | } |
| 3172 | } else if (second.IsRegister()) { |
| 3173 | DCHECK(first.Equals(out)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3174 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3175 | } else { |
| 3176 | DCHECK(second.IsDoubleStackSlot()); |
| 3177 | DCHECK(first.Equals(out)); |
| 3178 | __ imulq(first.AsRegister<CpuRegister>(), |
| 3179 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3180 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3181 | break; |
| 3182 | } |
| 3183 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3184 | case Primitive::kPrimFloat: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3185 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3186 | if (second.IsFpuRegister()) { |
| 3187 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3188 | } else if (second.IsConstant()) { |
| 3189 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3190 | codegen_->LiteralFloatAddress( |
| 3191 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3192 | } else { |
| 3193 | DCHECK(second.IsStackSlot()); |
| 3194 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3195 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3196 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3197 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3198 | } |
| 3199 | |
| 3200 | case Primitive::kPrimDouble: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3201 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3202 | if (second.IsFpuRegister()) { |
| 3203 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3204 | } else if (second.IsConstant()) { |
| 3205 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3206 | codegen_->LiteralDoubleAddress( |
| 3207 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3208 | } else { |
| 3209 | DCHECK(second.IsDoubleStackSlot()); |
| 3210 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3211 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3212 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3213 | break; |
| 3214 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3215 | |
| 3216 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3217 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3218 | } |
| 3219 | } |
| 3220 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3221 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 3222 | uint32_t stack_adjustment, bool is_float) { |
| 3223 | if (source.IsStackSlot()) { |
| 3224 | DCHECK(is_float); |
| 3225 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3226 | } else if (source.IsDoubleStackSlot()) { |
| 3227 | DCHECK(!is_float); |
| 3228 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3229 | } else { |
| 3230 | // Write the value to the temporary location on the stack and load to FP stack. |
| 3231 | if (is_float) { |
| 3232 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3233 | codegen_->Move(stack_temp, source); |
| 3234 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 3235 | } else { |
| 3236 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3237 | codegen_->Move(stack_temp, source); |
| 3238 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 3239 | } |
| 3240 | } |
| 3241 | } |
| 3242 | |
| 3243 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| 3244 | Primitive::Type type = rem->GetResultType(); |
| 3245 | bool is_float = type == Primitive::kPrimFloat; |
| 3246 | size_t elem_size = Primitive::ComponentSize(type); |
| 3247 | LocationSummary* locations = rem->GetLocations(); |
| 3248 | Location first = locations->InAt(0); |
| 3249 | Location second = locations->InAt(1); |
| 3250 | Location out = locations->Out(); |
| 3251 | |
| 3252 | // Create stack space for 2 elements. |
| 3253 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3254 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3255 | |
| 3256 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 3257 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 3258 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 3259 | |
| 3260 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3261 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3262 | __ Bind(&retry); |
| 3263 | __ fprem(); |
| 3264 | |
| 3265 | // Move FP status to AX. |
| 3266 | __ fstsw(); |
| 3267 | |
| 3268 | // And see if the argument reduction is complete. This is signaled by the |
| 3269 | // C2 FPU flag bit set to 0. |
| 3270 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 3271 | __ j(kNotEqual, &retry); |
| 3272 | |
| 3273 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3274 | // Store FP top of stack to real stack. |
| 3275 | if (is_float) { |
| 3276 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 3277 | } else { |
| 3278 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 3279 | } |
| 3280 | |
| 3281 | // Pop the 2 items from the FP stack. |
| 3282 | __ fucompp(); |
| 3283 | |
| 3284 | // Load the value from the stack into an XMM register. |
| 3285 | DCHECK(out.IsFpuRegister()) << out; |
| 3286 | if (is_float) { |
| 3287 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3288 | } else { |
| 3289 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3290 | } |
| 3291 | |
| 3292 | // And remove the temporary stack space we allocated. |
| 3293 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3294 | } |
| 3295 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3296 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3297 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3298 | |
| 3299 | LocationSummary* locations = instruction->GetLocations(); |
| 3300 | Location second = locations->InAt(1); |
| 3301 | DCHECK(second.IsConstant()); |
| 3302 | |
| 3303 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3304 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3305 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3306 | |
| 3307 | DCHECK(imm == 1 || imm == -1); |
| 3308 | |
| 3309 | switch (instruction->GetResultType()) { |
| 3310 | case Primitive::kPrimInt: { |
| 3311 | if (instruction->IsRem()) { |
| 3312 | __ xorl(output_register, output_register); |
| 3313 | } else { |
| 3314 | __ movl(output_register, input_register); |
| 3315 | if (imm == -1) { |
| 3316 | __ negl(output_register); |
| 3317 | } |
| 3318 | } |
| 3319 | break; |
| 3320 | } |
| 3321 | |
| 3322 | case Primitive::kPrimLong: { |
| 3323 | if (instruction->IsRem()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3324 | __ xorl(output_register, output_register); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3325 | } else { |
| 3326 | __ movq(output_register, input_register); |
| 3327 | if (imm == -1) { |
| 3328 | __ negq(output_register); |
| 3329 | } |
| 3330 | } |
| 3331 | break; |
| 3332 | } |
| 3333 | |
| 3334 | default: |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3335 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3336 | } |
| 3337 | } |
| 3338 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3339 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3340 | LocationSummary* locations = instruction->GetLocations(); |
| 3341 | Location second = locations->InAt(1); |
| 3342 | |
| 3343 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3344 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3345 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3346 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3347 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3348 | uint64_t abs_imm = AbsOrMin(imm); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3349 | |
| 3350 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3351 | |
| 3352 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3353 | __ leal(tmp, Address(numerator, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3354 | __ testl(numerator, numerator); |
| 3355 | __ cmov(kGreaterEqual, tmp, numerator); |
| 3356 | int shift = CTZ(imm); |
| 3357 | __ sarl(tmp, Immediate(shift)); |
| 3358 | |
| 3359 | if (imm < 0) { |
| 3360 | __ negl(tmp); |
| 3361 | } |
| 3362 | |
| 3363 | __ movl(output_register, tmp); |
| 3364 | } else { |
| 3365 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3366 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3367 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3368 | codegen_->Load64BitValue(rdx, abs_imm - 1); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3369 | __ addq(rdx, numerator); |
| 3370 | __ testq(numerator, numerator); |
| 3371 | __ cmov(kGreaterEqual, rdx, numerator); |
| 3372 | int shift = CTZ(imm); |
| 3373 | __ sarq(rdx, Immediate(shift)); |
| 3374 | |
| 3375 | if (imm < 0) { |
| 3376 | __ negq(rdx); |
| 3377 | } |
| 3378 | |
| 3379 | __ movq(output_register, rdx); |
| 3380 | } |
| 3381 | } |
| 3382 | |
| 3383 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3384 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3385 | |
| 3386 | LocationSummary* locations = instruction->GetLocations(); |
| 3387 | Location second = locations->InAt(1); |
| 3388 | |
| 3389 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 3390 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3391 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3392 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 3393 | : locations->Out().AsRegister<CpuRegister>(); |
| 3394 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3395 | |
| 3396 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 3397 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 3398 | if (instruction->IsDiv()) { |
| 3399 | DCHECK_EQ(RAX, out.AsRegister()); |
| 3400 | } else { |
| 3401 | DCHECK_EQ(RDX, out.AsRegister()); |
| 3402 | } |
| 3403 | |
| 3404 | int64_t magic; |
| 3405 | int shift; |
| 3406 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3407 | // TODO: can these branches be written as one? |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3408 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 3409 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3410 | |
| 3411 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3412 | |
| 3413 | __ movl(numerator, eax); |
| 3414 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3415 | NearLabel no_div; |
| 3416 | NearLabel end; |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3417 | __ testl(eax, eax); |
| 3418 | __ j(kNotEqual, &no_div); |
| 3419 | |
| 3420 | __ xorl(out, out); |
| 3421 | __ jmp(&end); |
| 3422 | |
| 3423 | __ Bind(&no_div); |
| 3424 | |
| 3425 | __ movl(eax, Immediate(magic)); |
| 3426 | __ imull(numerator); |
| 3427 | |
| 3428 | if (imm > 0 && magic < 0) { |
| 3429 | __ addl(edx, numerator); |
| 3430 | } else if (imm < 0 && magic > 0) { |
| 3431 | __ subl(edx, numerator); |
| 3432 | } |
| 3433 | |
| 3434 | if (shift != 0) { |
| 3435 | __ sarl(edx, Immediate(shift)); |
| 3436 | } |
| 3437 | |
| 3438 | __ movl(eax, edx); |
| 3439 | __ shrl(edx, Immediate(31)); |
| 3440 | __ addl(edx, eax); |
| 3441 | |
| 3442 | if (instruction->IsRem()) { |
| 3443 | __ movl(eax, numerator); |
| 3444 | __ imull(edx, Immediate(imm)); |
| 3445 | __ subl(eax, edx); |
| 3446 | __ movl(edx, eax); |
| 3447 | } else { |
| 3448 | __ movl(eax, edx); |
| 3449 | } |
| 3450 | __ Bind(&end); |
| 3451 | } else { |
| 3452 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3453 | |
| 3454 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3455 | |
| 3456 | CpuRegister rax = eax; |
| 3457 | CpuRegister rdx = edx; |
| 3458 | |
| 3459 | CalculateMagicAndShiftForDivRem(imm, true /* is_long */, &magic, &shift); |
| 3460 | |
| 3461 | // Save the numerator. |
| 3462 | __ movq(numerator, rax); |
| 3463 | |
| 3464 | // RAX = magic |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3465 | codegen_->Load64BitValue(rax, magic); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3466 | |
| 3467 | // RDX:RAX = magic * numerator |
| 3468 | __ imulq(numerator); |
| 3469 | |
| 3470 | if (imm > 0 && magic < 0) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3471 | // RDX += numerator |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3472 | __ addq(rdx, numerator); |
| 3473 | } else if (imm < 0 && magic > 0) { |
| 3474 | // RDX -= numerator |
| 3475 | __ subq(rdx, numerator); |
| 3476 | } |
| 3477 | |
| 3478 | // Shift if needed. |
| 3479 | if (shift != 0) { |
| 3480 | __ sarq(rdx, Immediate(shift)); |
| 3481 | } |
| 3482 | |
| 3483 | // RDX += 1 if RDX < 0 |
| 3484 | __ movq(rax, rdx); |
| 3485 | __ shrq(rdx, Immediate(63)); |
| 3486 | __ addq(rdx, rax); |
| 3487 | |
| 3488 | if (instruction->IsRem()) { |
| 3489 | __ movq(rax, numerator); |
| 3490 | |
| 3491 | if (IsInt<32>(imm)) { |
| 3492 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 3493 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3494 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3495 | } |
| 3496 | |
| 3497 | __ subq(rax, rdx); |
| 3498 | __ movq(rdx, rax); |
| 3499 | } else { |
| 3500 | __ movq(rax, rdx); |
| 3501 | } |
| 3502 | } |
| 3503 | } |
| 3504 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3505 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3506 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3507 | Primitive::Type type = instruction->GetResultType(); |
| 3508 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 3509 | |
| 3510 | bool is_div = instruction->IsDiv(); |
| 3511 | LocationSummary* locations = instruction->GetLocations(); |
| 3512 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3513 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3514 | Location second = locations->InAt(1); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3515 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3516 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3517 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3518 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3519 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3520 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3521 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3522 | if (imm == 0) { |
| 3523 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3524 | } else if (imm == 1 || imm == -1) { |
| 3525 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3526 | } else if (instruction->IsDiv() && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3527 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3528 | } else { |
| 3529 | DCHECK(imm <= -2 || imm >= 2); |
| 3530 | GenerateDivRemWithAnyConstant(instruction); |
| 3531 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3532 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3533 | SlowPathCode* slow_path = |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3534 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86_64( |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3535 | instruction, out.AsRegister(), type, is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3536 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3537 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3538 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3539 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3540 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3541 | // so it's safe to just use negl instead of more complex comparisons. |
| 3542 | if (type == Primitive::kPrimInt) { |
| 3543 | __ cmpl(second_reg, Immediate(-1)); |
| 3544 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3545 | // edx:eax <- sign-extended of eax |
| 3546 | __ cdq(); |
| 3547 | // eax = quotient, edx = remainder |
| 3548 | __ idivl(second_reg); |
| 3549 | } else { |
| 3550 | __ cmpq(second_reg, Immediate(-1)); |
| 3551 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3552 | // rdx:rax <- sign-extended of rax |
| 3553 | __ cqo(); |
| 3554 | // rax = quotient, rdx = remainder |
| 3555 | __ idivq(second_reg); |
| 3556 | } |
| 3557 | __ Bind(slow_path->GetExitLabel()); |
| 3558 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3559 | } |
| 3560 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3561 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3562 | LocationSummary* locations = |
| 3563 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3564 | switch (div->GetResultType()) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3565 | case Primitive::kPrimInt: |
| 3566 | case Primitive::kPrimLong: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3567 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3568 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3569 | locations->SetOut(Location::SameAsFirstInput()); |
| 3570 | // Intel uses edx:eax as the dividend. |
| 3571 | locations->AddTemp(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3572 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3573 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3574 | // output and request another temp. |
| 3575 | if (div->InputAt(1)->IsConstant()) { |
| 3576 | locations->AddTemp(Location::RequiresRegister()); |
| 3577 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3578 | break; |
| 3579 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3580 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3581 | case Primitive::kPrimFloat: |
| 3582 | case Primitive::kPrimDouble: { |
| 3583 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3584 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3585 | locations->SetOut(Location::SameAsFirstInput()); |
| 3586 | break; |
| 3587 | } |
| 3588 | |
| 3589 | default: |
| 3590 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3591 | } |
| 3592 | } |
| 3593 | |
| 3594 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3595 | LocationSummary* locations = div->GetLocations(); |
| 3596 | Location first = locations->InAt(0); |
| 3597 | Location second = locations->InAt(1); |
| 3598 | DCHECK(first.Equals(locations->Out())); |
| 3599 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3600 | Primitive::Type type = div->GetResultType(); |
| 3601 | switch (type) { |
| 3602 | case Primitive::kPrimInt: |
| 3603 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3604 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3605 | break; |
| 3606 | } |
| 3607 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3608 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3609 | if (second.IsFpuRegister()) { |
| 3610 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3611 | } else if (second.IsConstant()) { |
| 3612 | __ divss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3613 | codegen_->LiteralFloatAddress( |
| 3614 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3615 | } else { |
| 3616 | DCHECK(second.IsStackSlot()); |
| 3617 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3618 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3619 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3620 | break; |
| 3621 | } |
| 3622 | |
| 3623 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3624 | if (second.IsFpuRegister()) { |
| 3625 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3626 | } else if (second.IsConstant()) { |
| 3627 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3628 | codegen_->LiteralDoubleAddress( |
| 3629 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3630 | } else { |
| 3631 | DCHECK(second.IsDoubleStackSlot()); |
| 3632 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3633 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3634 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3635 | break; |
| 3636 | } |
| 3637 | |
| 3638 | default: |
| 3639 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3640 | } |
| 3641 | } |
| 3642 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3643 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3644 | Primitive::Type type = rem->GetResultType(); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3645 | LocationSummary* locations = |
| 3646 | new (GetGraph()->GetArena()) LocationSummary(rem, LocationSummary::kNoCall); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3647 | |
| 3648 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3649 | case Primitive::kPrimInt: |
| 3650 | case Primitive::kPrimLong: { |
| 3651 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3652 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3653 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3654 | locations->SetOut(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3655 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3656 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3657 | // output and request another temp. |
| 3658 | if (rem->InputAt(1)->IsConstant()) { |
| 3659 | locations->AddTemp(Location::RequiresRegister()); |
| 3660 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3661 | break; |
| 3662 | } |
| 3663 | |
| 3664 | case Primitive::kPrimFloat: |
| 3665 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3666 | locations->SetInAt(0, Location::Any()); |
| 3667 | locations->SetInAt(1, Location::Any()); |
| 3668 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3669 | locations->AddTemp(Location::RegisterLocation(RAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3670 | break; |
| 3671 | } |
| 3672 | |
| 3673 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3674 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3675 | } |
| 3676 | } |
| 3677 | |
| 3678 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| 3679 | Primitive::Type type = rem->GetResultType(); |
| 3680 | switch (type) { |
| 3681 | case Primitive::kPrimInt: |
| 3682 | case Primitive::kPrimLong: { |
| 3683 | GenerateDivRemIntegral(rem); |
| 3684 | break; |
| 3685 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3686 | case Primitive::kPrimFloat: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3687 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3688 | GenerateRemFP(rem); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3689 | break; |
| 3690 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3691 | default: |
| 3692 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3693 | } |
| 3694 | } |
| 3695 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3696 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3697 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3698 | ? LocationSummary::kCallOnSlowPath |
| 3699 | : LocationSummary::kNoCall; |
| 3700 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3701 | locations->SetInAt(0, Location::Any()); |
| 3702 | if (instruction->HasUses()) { |
| 3703 | locations->SetOut(Location::SameAsFirstInput()); |
| 3704 | } |
| 3705 | } |
| 3706 | |
| 3707 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3708 | SlowPathCode* slow_path = |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3709 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction); |
| 3710 | codegen_->AddSlowPath(slow_path); |
| 3711 | |
| 3712 | LocationSummary* locations = instruction->GetLocations(); |
| 3713 | Location value = locations->InAt(0); |
| 3714 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3715 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3716 | case Primitive::kPrimByte: |
| 3717 | case Primitive::kPrimChar: |
| 3718 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3719 | case Primitive::kPrimInt: { |
| 3720 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3721 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3722 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3723 | } else if (value.IsStackSlot()) { |
| 3724 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3725 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3726 | } else { |
| 3727 | DCHECK(value.IsConstant()) << value; |
| 3728 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3729 | __ jmp(slow_path->GetEntryLabel()); |
| 3730 | } |
| 3731 | } |
| 3732 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3733 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3734 | case Primitive::kPrimLong: { |
| 3735 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3736 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3737 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3738 | } else if (value.IsDoubleStackSlot()) { |
| 3739 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3740 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3741 | } else { |
| 3742 | DCHECK(value.IsConstant()) << value; |
| 3743 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3744 | __ jmp(slow_path->GetEntryLabel()); |
| 3745 | } |
| 3746 | } |
| 3747 | break; |
| 3748 | } |
| 3749 | default: |
| 3750 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3751 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3752 | } |
| 3753 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3754 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 3755 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3756 | |
| 3757 | LocationSummary* locations = |
| 3758 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3759 | |
| 3760 | switch (op->GetResultType()) { |
| 3761 | case Primitive::kPrimInt: |
| 3762 | case Primitive::kPrimLong: { |
| 3763 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3764 | // The shift count needs to be in CL. |
| 3765 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 3766 | locations->SetOut(Location::SameAsFirstInput()); |
| 3767 | break; |
| 3768 | } |
| 3769 | default: |
| 3770 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3771 | } |
| 3772 | } |
| 3773 | |
| 3774 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 3775 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3776 | |
| 3777 | LocationSummary* locations = op->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3778 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3779 | Location second = locations->InAt(1); |
| 3780 | |
| 3781 | switch (op->GetResultType()) { |
| 3782 | case Primitive::kPrimInt: { |
| 3783 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3784 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3785 | if (op->IsShl()) { |
| 3786 | __ shll(first_reg, second_reg); |
| 3787 | } else if (op->IsShr()) { |
| 3788 | __ sarl(first_reg, second_reg); |
| 3789 | } else { |
| 3790 | __ shrl(first_reg, second_reg); |
| 3791 | } |
| 3792 | } else { |
Nicolas Geoffray | 486cc19 | 2014-12-08 18:00:55 +0000 | [diff] [blame] | 3793 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3794 | if (op->IsShl()) { |
| 3795 | __ shll(first_reg, imm); |
| 3796 | } else if (op->IsShr()) { |
| 3797 | __ sarl(first_reg, imm); |
| 3798 | } else { |
| 3799 | __ shrl(first_reg, imm); |
| 3800 | } |
| 3801 | } |
| 3802 | break; |
| 3803 | } |
| 3804 | case Primitive::kPrimLong: { |
| 3805 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3806 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3807 | if (op->IsShl()) { |
| 3808 | __ shlq(first_reg, second_reg); |
| 3809 | } else if (op->IsShr()) { |
| 3810 | __ sarq(first_reg, second_reg); |
| 3811 | } else { |
| 3812 | __ shrq(first_reg, second_reg); |
| 3813 | } |
| 3814 | } else { |
Nicolas Geoffray | 486cc19 | 2014-12-08 18:00:55 +0000 | [diff] [blame] | 3815 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3816 | if (op->IsShl()) { |
| 3817 | __ shlq(first_reg, imm); |
| 3818 | } else if (op->IsShr()) { |
| 3819 | __ sarq(first_reg, imm); |
| 3820 | } else { |
| 3821 | __ shrq(first_reg, imm); |
| 3822 | } |
| 3823 | } |
| 3824 | break; |
| 3825 | } |
| 3826 | default: |
| 3827 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3828 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3829 | } |
| 3830 | } |
| 3831 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3832 | void LocationsBuilderX86_64::VisitRor(HRor* ror) { |
| 3833 | LocationSummary* locations = |
| 3834 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3835 | |
| 3836 | switch (ror->GetResultType()) { |
| 3837 | case Primitive::kPrimInt: |
| 3838 | case Primitive::kPrimLong: { |
| 3839 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3840 | // The shift count needs to be in CL (unless it is a constant). |
| 3841 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, ror->InputAt(1))); |
| 3842 | locations->SetOut(Location::SameAsFirstInput()); |
| 3843 | break; |
| 3844 | } |
| 3845 | default: |
| 3846 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3847 | UNREACHABLE(); |
| 3848 | } |
| 3849 | } |
| 3850 | |
| 3851 | void InstructionCodeGeneratorX86_64::VisitRor(HRor* ror) { |
| 3852 | LocationSummary* locations = ror->GetLocations(); |
| 3853 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3854 | Location second = locations->InAt(1); |
| 3855 | |
| 3856 | switch (ror->GetResultType()) { |
| 3857 | case Primitive::kPrimInt: |
| 3858 | if (second.IsRegister()) { |
| 3859 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3860 | __ rorl(first_reg, second_reg); |
| 3861 | } else { |
| 3862 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
| 3863 | __ rorl(first_reg, imm); |
| 3864 | } |
| 3865 | break; |
| 3866 | case Primitive::kPrimLong: |
| 3867 | if (second.IsRegister()) { |
| 3868 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3869 | __ rorq(first_reg, second_reg); |
| 3870 | } else { |
| 3871 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue); |
| 3872 | __ rorq(first_reg, imm); |
| 3873 | } |
| 3874 | break; |
| 3875 | default: |
| 3876 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3877 | UNREACHABLE(); |
| 3878 | } |
| 3879 | } |
| 3880 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3881 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 3882 | HandleShift(shl); |
| 3883 | } |
| 3884 | |
| 3885 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 3886 | HandleShift(shl); |
| 3887 | } |
| 3888 | |
| 3889 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 3890 | HandleShift(shr); |
| 3891 | } |
| 3892 | |
| 3893 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 3894 | HandleShift(shr); |
| 3895 | } |
| 3896 | |
| 3897 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 3898 | HandleShift(ushr); |
| 3899 | } |
| 3900 | |
| 3901 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 3902 | HandleShift(ushr); |
| 3903 | } |
| 3904 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3905 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3906 | LocationSummary* locations = |
| 3907 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3908 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3909 | if (instruction->IsStringAlloc()) { |
| 3910 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3911 | } else { |
| 3912 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3913 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3914 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3915 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3916 | } |
| 3917 | |
| 3918 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3919 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3920 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3921 | if (instruction->IsStringAlloc()) { |
| 3922 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3923 | CpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
| 3924 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64WordSize); |
| 3925 | __ gs()->movq(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString), /* no_rip */ true)); |
| 3926 | __ call(Address(temp, code_offset.SizeValue())); |
| 3927 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3928 | } else { |
| 3929 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3930 | instruction, |
| 3931 | instruction->GetDexPc(), |
| 3932 | nullptr); |
| 3933 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 3934 | DCHECK(!codegen_->IsLeafMethod()); |
| 3935 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3936 | } |
| 3937 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3938 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 3939 | LocationSummary* locations = |
| 3940 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3941 | InvokeRuntimeCallingConvention calling_convention; |
| 3942 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3943 | locations->SetOut(Location::RegisterLocation(RAX)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3944 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3945 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3946 | } |
| 3947 | |
| 3948 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| 3949 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3950 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 3951 | instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3952 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3953 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3954 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3955 | instruction, |
| 3956 | instruction->GetDexPc(), |
| 3957 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3958 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3959 | |
| 3960 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3961 | } |
| 3962 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3963 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3964 | LocationSummary* locations = |
| 3965 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3966 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3967 | if (location.IsStackSlot()) { |
| 3968 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3969 | } else if (location.IsDoubleStackSlot()) { |
| 3970 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3971 | } |
| 3972 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3973 | } |
| 3974 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3975 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 3976 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3977 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3978 | } |
| 3979 | |
| 3980 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3981 | LocationSummary* locations = |
| 3982 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3983 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3984 | } |
| 3985 | |
| 3986 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 3987 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3988 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3989 | } |
| 3990 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3991 | void LocationsBuilderX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 3992 | LocationSummary* locations = |
| 3993 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3994 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3995 | locations->SetOut(Location::RequiresRegister()); |
| 3996 | } |
| 3997 | |
| 3998 | void InstructionCodeGeneratorX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 3999 | LocationSummary* locations = instruction->GetLocations(); |
| 4000 | uint32_t method_offset = 0; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame^] | 4001 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4002 | method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4003 | instruction->GetIndex(), kX86_64PointerSize).SizeValue(); |
| 4004 | } else { |
| 4005 | method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 4006 | instruction->GetIndex() % mirror::Class::kImtSize, kX86_64PointerSize).Uint32Value(); |
| 4007 | } |
| 4008 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4009 | Address(locations->InAt(0).AsRegister<CpuRegister>(), method_offset)); |
| 4010 | } |
| 4011 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4012 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4013 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4014 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4015 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4016 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4017 | } |
| 4018 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4019 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 4020 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4021 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4022 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4023 | Location out = locations->Out(); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4024 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4025 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4026 | __ notl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4027 | break; |
| 4028 | |
| 4029 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4030 | __ notq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4031 | break; |
| 4032 | |
| 4033 | default: |
| 4034 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4035 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4036 | } |
| 4037 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4038 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4039 | LocationSummary* locations = |
| 4040 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4041 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4042 | locations->SetOut(Location::SameAsFirstInput()); |
| 4043 | } |
| 4044 | |
| 4045 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4046 | LocationSummary* locations = bool_not->GetLocations(); |
| 4047 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4048 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 4049 | Location out = locations->Out(); |
| 4050 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 4051 | } |
| 4052 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4053 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4054 | LocationSummary* locations = |
| 4055 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4056 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 4057 | locations->SetInAt(i, Location::Any()); |
| 4058 | } |
| 4059 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4060 | } |
| 4061 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4062 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4063 | LOG(FATAL) << "Unimplemented"; |
| 4064 | } |
| 4065 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4066 | void CodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4067 | /* |
| 4068 | * 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] | 4069 | * 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] | 4070 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4071 | */ |
| 4072 | switch (kind) { |
| 4073 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4074 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4075 | break; |
| 4076 | } |
| 4077 | case MemBarrierKind::kAnyStore: |
| 4078 | case MemBarrierKind::kLoadAny: |
| 4079 | case MemBarrierKind::kStoreStore: { |
| 4080 | // nop |
| 4081 | break; |
| 4082 | } |
| 4083 | default: |
| 4084 | LOG(FATAL) << "Unexpected memory barier " << kind; |
| 4085 | } |
| 4086 | } |
| 4087 | |
| 4088 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 4089 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4090 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4091 | bool object_field_get_with_read_barrier = |
| 4092 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4093 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4094 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4095 | object_field_get_with_read_barrier ? |
| 4096 | LocationSummary::kCallOnSlowPath : |
| 4097 | LocationSummary::kNoCall); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4098 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4099 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4100 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4101 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4102 | // The output overlaps for an object field get when read barriers |
| 4103 | // are enabled: we do not want the move to overwrite the object's |
| 4104 | // location, as we need it to emit the read barrier. |
| 4105 | locations->SetOut( |
| 4106 | Location::RequiresRegister(), |
| 4107 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4108 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4109 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4110 | // We need a temporary register for the read barrier marking slow |
| 4111 | // path in CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier. |
| 4112 | locations->AddTemp(Location::RequiresRegister()); |
| 4113 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4114 | } |
| 4115 | |
| 4116 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 4117 | const FieldInfo& field_info) { |
| 4118 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4119 | |
| 4120 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4121 | Location base_loc = locations->InAt(0); |
| 4122 | CpuRegister base = base_loc.AsRegister<CpuRegister>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4123 | Location out = locations->Out(); |
| 4124 | bool is_volatile = field_info.IsVolatile(); |
| 4125 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4126 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4127 | |
| 4128 | switch (field_type) { |
| 4129 | case Primitive::kPrimBoolean: { |
| 4130 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4131 | break; |
| 4132 | } |
| 4133 | |
| 4134 | case Primitive::kPrimByte: { |
| 4135 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4136 | break; |
| 4137 | } |
| 4138 | |
| 4139 | case Primitive::kPrimShort: { |
| 4140 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4141 | break; |
| 4142 | } |
| 4143 | |
| 4144 | case Primitive::kPrimChar: { |
| 4145 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4146 | break; |
| 4147 | } |
| 4148 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4149 | case Primitive::kPrimInt: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4150 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4151 | break; |
| 4152 | } |
| 4153 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4154 | case Primitive::kPrimNot: { |
| 4155 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4156 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4157 | Location temp_loc = locations->GetTemp(0); |
| 4158 | // Note that a potential implicit null check is handled in this |
| 4159 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4160 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4161 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4162 | if (is_volatile) { |
| 4163 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4164 | } |
| 4165 | } else { |
| 4166 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4167 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4168 | if (is_volatile) { |
| 4169 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4170 | } |
| 4171 | // If read barriers are enabled, emit read barriers other than |
| 4172 | // Baker's using a slow path (and also unpoison the loaded |
| 4173 | // reference, if heap poisoning is enabled). |
| 4174 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4175 | } |
| 4176 | break; |
| 4177 | } |
| 4178 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4179 | case Primitive::kPrimLong: { |
| 4180 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4181 | break; |
| 4182 | } |
| 4183 | |
| 4184 | case Primitive::kPrimFloat: { |
| 4185 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4186 | break; |
| 4187 | } |
| 4188 | |
| 4189 | case Primitive::kPrimDouble: { |
| 4190 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4191 | break; |
| 4192 | } |
| 4193 | |
| 4194 | case Primitive::kPrimVoid: |
| 4195 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4196 | UNREACHABLE(); |
| 4197 | } |
| 4198 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4199 | if (field_type == Primitive::kPrimNot) { |
| 4200 | // Potential implicit null checks, in the case of reference |
| 4201 | // fields, are handled in the previous switch statement. |
| 4202 | } else { |
| 4203 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4204 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4205 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4206 | if (is_volatile) { |
| 4207 | if (field_type == Primitive::kPrimNot) { |
| 4208 | // Memory barriers, in the case of references, are also handled |
| 4209 | // in the previous switch statement. |
| 4210 | } else { |
| 4211 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4212 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4213 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4214 | } |
| 4215 | |
| 4216 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 4217 | const FieldInfo& field_info) { |
| 4218 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4219 | |
| 4220 | LocationSummary* locations = |
| 4221 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4222 | Primitive::Type field_type = field_info.GetFieldType(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4223 | bool is_volatile = field_info.IsVolatile(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4224 | bool needs_write_barrier = |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4225 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4226 | |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4227 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4228 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4229 | if (is_volatile) { |
| 4230 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4231 | locations->SetInAt(1, Location::FpuRegisterOrInt32Constant(instruction->InputAt(1))); |
| 4232 | } else { |
| 4233 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4234 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4235 | } else { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4236 | if (is_volatile) { |
| 4237 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4238 | locations->SetInAt(1, Location::RegisterOrInt32Constant(instruction->InputAt(1))); |
| 4239 | } else { |
| 4240 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4241 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4242 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4243 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4244 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4245 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4246 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4247 | } else if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4248 | // Temporary register for the reference poisoning. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4249 | locations->AddTemp(Location::RequiresRegister()); |
| 4250 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4251 | } |
| 4252 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4253 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4254 | const FieldInfo& field_info, |
| 4255 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4256 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4257 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4258 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4259 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4260 | Location value = locations->InAt(1); |
| 4261 | bool is_volatile = field_info.IsVolatile(); |
| 4262 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4263 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4264 | |
| 4265 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4266 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4267 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4268 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4269 | bool maybe_record_implicit_null_check_done = false; |
| 4270 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4271 | switch (field_type) { |
| 4272 | case Primitive::kPrimBoolean: |
| 4273 | case Primitive::kPrimByte: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4274 | if (value.IsConstant()) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4275 | int8_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4276 | __ movb(Address(base, offset), Immediate(v)); |
| 4277 | } else { |
| 4278 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4279 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4280 | break; |
| 4281 | } |
| 4282 | |
| 4283 | case Primitive::kPrimShort: |
| 4284 | case Primitive::kPrimChar: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4285 | if (value.IsConstant()) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4286 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4287 | __ movw(Address(base, offset), Immediate(v)); |
| 4288 | } else { |
| 4289 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4290 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4291 | break; |
| 4292 | } |
| 4293 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4294 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4295 | case Primitive::kPrimNot: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4296 | if (value.IsConstant()) { |
| 4297 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4298 | // `field_type == Primitive::kPrimNot` implies `v == 0`. |
| 4299 | DCHECK((field_type != Primitive::kPrimNot) || (v == 0)); |
| 4300 | // Note: if heap poisoning is enabled, no need to poison |
| 4301 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 4302 | __ movl(Address(base, offset), Immediate(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4303 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4304 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4305 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4306 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4307 | __ PoisonHeapReference(temp); |
| 4308 | __ movl(Address(base, offset), temp); |
| 4309 | } else { |
| 4310 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4311 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4312 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4313 | break; |
| 4314 | } |
| 4315 | |
| 4316 | case Primitive::kPrimLong: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4317 | if (value.IsConstant()) { |
| 4318 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4319 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4320 | Address(base, offset + sizeof(int32_t)), |
| 4321 | v, |
| 4322 | instruction); |
| 4323 | maybe_record_implicit_null_check_done = true; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4324 | } else { |
| 4325 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4326 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4327 | break; |
| 4328 | } |
| 4329 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4330 | case Primitive::kPrimFloat: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4331 | if (value.IsConstant()) { |
| 4332 | int32_t v = |
| 4333 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4334 | __ movl(Address(base, offset), Immediate(v)); |
| 4335 | } else { |
| 4336 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4337 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4338 | break; |
| 4339 | } |
| 4340 | |
| 4341 | case Primitive::kPrimDouble: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4342 | if (value.IsConstant()) { |
| 4343 | int64_t v = |
| 4344 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4345 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4346 | Address(base, offset + sizeof(int32_t)), |
| 4347 | v, |
| 4348 | instruction); |
| 4349 | maybe_record_implicit_null_check_done = true; |
| 4350 | } else { |
| 4351 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4352 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4353 | break; |
| 4354 | } |
| 4355 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4356 | case Primitive::kPrimVoid: |
| 4357 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4358 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4359 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4360 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4361 | if (!maybe_record_implicit_null_check_done) { |
| 4362 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4363 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4364 | |
| 4365 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4366 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4367 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4368 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4369 | } |
| 4370 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4371 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4372 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4373 | } |
| 4374 | } |
| 4375 | |
| 4376 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4377 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4378 | } |
| 4379 | |
| 4380 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4381 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4382 | } |
| 4383 | |
| 4384 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4385 | HandleFieldGet(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4386 | } |
| 4387 | |
| 4388 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4389 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4390 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4391 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4392 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4393 | HandleFieldGet(instruction); |
| 4394 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4395 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4396 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4397 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4398 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4399 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4400 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4401 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4402 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4403 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4404 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4405 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4406 | } |
| 4407 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4408 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldGet( |
| 4409 | HUnresolvedInstanceFieldGet* instruction) { |
| 4410 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4411 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4412 | instruction, instruction->GetFieldType(), calling_convention); |
| 4413 | } |
| 4414 | |
| 4415 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldGet( |
| 4416 | HUnresolvedInstanceFieldGet* instruction) { |
| 4417 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4418 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4419 | instruction->GetFieldType(), |
| 4420 | instruction->GetFieldIndex(), |
| 4421 | instruction->GetDexPc(), |
| 4422 | calling_convention); |
| 4423 | } |
| 4424 | |
| 4425 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldSet( |
| 4426 | HUnresolvedInstanceFieldSet* instruction) { |
| 4427 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4428 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4429 | instruction, instruction->GetFieldType(), calling_convention); |
| 4430 | } |
| 4431 | |
| 4432 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldSet( |
| 4433 | HUnresolvedInstanceFieldSet* instruction) { |
| 4434 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4435 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4436 | instruction->GetFieldType(), |
| 4437 | instruction->GetFieldIndex(), |
| 4438 | instruction->GetDexPc(), |
| 4439 | calling_convention); |
| 4440 | } |
| 4441 | |
| 4442 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldGet( |
| 4443 | HUnresolvedStaticFieldGet* instruction) { |
| 4444 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4445 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4446 | instruction, instruction->GetFieldType(), calling_convention); |
| 4447 | } |
| 4448 | |
| 4449 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldGet( |
| 4450 | HUnresolvedStaticFieldGet* instruction) { |
| 4451 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4452 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4453 | instruction->GetFieldType(), |
| 4454 | instruction->GetFieldIndex(), |
| 4455 | instruction->GetDexPc(), |
| 4456 | calling_convention); |
| 4457 | } |
| 4458 | |
| 4459 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldSet( |
| 4460 | HUnresolvedStaticFieldSet* instruction) { |
| 4461 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4462 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4463 | instruction, instruction->GetFieldType(), calling_convention); |
| 4464 | } |
| 4465 | |
| 4466 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldSet( |
| 4467 | HUnresolvedStaticFieldSet* instruction) { |
| 4468 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4469 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4470 | instruction->GetFieldType(), |
| 4471 | instruction->GetFieldIndex(), |
| 4472 | instruction->GetDexPc(), |
| 4473 | calling_convention); |
| 4474 | } |
| 4475 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4476 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4477 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4478 | ? LocationSummary::kCallOnSlowPath |
| 4479 | : LocationSummary::kNoCall; |
| 4480 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4481 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4482 | ? Location::RequiresRegister() |
| 4483 | : Location::Any(); |
| 4484 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4485 | if (instruction->HasUses()) { |
| 4486 | locations->SetOut(Location::SameAsFirstInput()); |
| 4487 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4488 | } |
| 4489 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4490 | void InstructionCodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4491 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 4492 | return; |
| 4493 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4494 | LocationSummary* locations = instruction->GetLocations(); |
| 4495 | Location obj = locations->InAt(0); |
| 4496 | |
| 4497 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
| 4498 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4499 | } |
| 4500 | |
| 4501 | void InstructionCodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4502 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4503 | codegen_->AddSlowPath(slow_path); |
| 4504 | |
| 4505 | LocationSummary* locations = instruction->GetLocations(); |
| 4506 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4507 | |
| 4508 | if (obj.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4509 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4510 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4511 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4512 | } else { |
| 4513 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4514 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4515 | __ jmp(slow_path->GetEntryLabel()); |
| 4516 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4517 | } |
| 4518 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4519 | } |
| 4520 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4521 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4522 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4523 | GenerateImplicitNullCheck(instruction); |
| 4524 | } else { |
| 4525 | GenerateExplicitNullCheck(instruction); |
| 4526 | } |
| 4527 | } |
| 4528 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4529 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4530 | bool object_array_get_with_read_barrier = |
| 4531 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4532 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4533 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4534 | object_array_get_with_read_barrier ? |
| 4535 | LocationSummary::kCallOnSlowPath : |
| 4536 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4537 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4538 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4539 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4540 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4541 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4542 | // The output overlaps for an object array get when read barriers |
| 4543 | // are enabled: we do not want the move to overwrite the array's |
| 4544 | // location, as we need it to emit the read barrier. |
| 4545 | locations->SetOut( |
| 4546 | Location::RequiresRegister(), |
| 4547 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4548 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4549 | // We need a temporary register for the read barrier marking slow |
| 4550 | // path in CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier. |
| 4551 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4552 | locations->AddTemp(Location::RequiresRegister()); |
| 4553 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4554 | } |
| 4555 | |
| 4556 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 4557 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4558 | Location obj_loc = locations->InAt(0); |
| 4559 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4560 | Location index = locations->InAt(1); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4561 | Location out_loc = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4562 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4563 | Primitive::Type type = instruction->GetType(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4564 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4565 | case Primitive::kPrimBoolean: { |
| 4566 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4567 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4568 | if (index.IsConstant()) { |
| 4569 | __ movzxb(out, Address(obj, |
| 4570 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4571 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4572 | __ movzxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4573 | } |
| 4574 | break; |
| 4575 | } |
| 4576 | |
| 4577 | case Primitive::kPrimByte: { |
| 4578 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4579 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4580 | if (index.IsConstant()) { |
| 4581 | __ movsxb(out, Address(obj, |
| 4582 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4583 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4584 | __ movsxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4585 | } |
| 4586 | break; |
| 4587 | } |
| 4588 | |
| 4589 | case Primitive::kPrimShort: { |
| 4590 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4591 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4592 | if (index.IsConstant()) { |
| 4593 | __ movsxw(out, Address(obj, |
| 4594 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4595 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4596 | __ movsxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4597 | } |
| 4598 | break; |
| 4599 | } |
| 4600 | |
| 4601 | case Primitive::kPrimChar: { |
| 4602 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4603 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4604 | if (index.IsConstant()) { |
| 4605 | __ movzxw(out, Address(obj, |
| 4606 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4607 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4608 | __ movzxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4609 | } |
| 4610 | break; |
| 4611 | } |
| 4612 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4613 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4614 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
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."); |
| 4629 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4630 | // /* HeapReference<Object> */ out = |
| 4631 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4632 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4633 | Location temp = locations->GetTemp(0); |
| 4634 | // Note that a potential implicit null check is handled in this |
| 4635 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 4636 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 4637 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 4638 | } else { |
| 4639 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| 4640 | if (index.IsConstant()) { |
| 4641 | uint32_t offset = |
| 4642 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4643 | __ movl(out, Address(obj, offset)); |
| 4644 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4645 | // If read barriers are enabled, emit read barriers other than |
| 4646 | // Baker's using a slow path (and also unpoison the loaded |
| 4647 | // reference, if heap poisoning is enabled). |
| 4648 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 4649 | } else { |
| 4650 | __ movl(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
| 4651 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4652 | // If read barriers are enabled, emit read barriers other than |
| 4653 | // Baker's using a slow path (and also unpoison the loaded |
| 4654 | // reference, if heap poisoning is enabled). |
| 4655 | codegen_->MaybeGenerateReadBarrierSlow( |
| 4656 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 4657 | } |
| 4658 | } |
| 4659 | break; |
| 4660 | } |
| 4661 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4662 | case Primitive::kPrimLong: { |
| 4663 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4664 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4665 | if (index.IsConstant()) { |
| 4666 | __ movq(out, Address(obj, |
| 4667 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4668 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4669 | __ movq(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4670 | } |
| 4671 | break; |
| 4672 | } |
| 4673 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4674 | case Primitive::kPrimFloat: { |
| 4675 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4676 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4677 | if (index.IsConstant()) { |
| 4678 | __ movss(out, Address(obj, |
| 4679 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4680 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4681 | __ movss(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4682 | } |
| 4683 | break; |
| 4684 | } |
| 4685 | |
| 4686 | case Primitive::kPrimDouble: { |
| 4687 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4688 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4689 | if (index.IsConstant()) { |
| 4690 | __ movsd(out, Address(obj, |
| 4691 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4692 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4693 | __ movsd(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4694 | } |
| 4695 | break; |
| 4696 | } |
| 4697 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4698 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4699 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4700 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4701 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4702 | |
| 4703 | if (type == Primitive::kPrimNot) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4704 | // Potential implicit null checks, in the case of reference |
| 4705 | // arrays, are handled in the previous switch statement. |
| 4706 | } else { |
| 4707 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4708 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4709 | } |
| 4710 | |
| 4711 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4712 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4713 | |
| 4714 | bool needs_write_barrier = |
| 4715 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4716 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4717 | bool object_array_set_with_read_barrier = |
| 4718 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4719 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4720 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4721 | instruction, |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4722 | (may_need_runtime_call_for_type_check || object_array_set_with_read_barrier) ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4723 | LocationSummary::kCallOnSlowPath : |
| 4724 | LocationSummary::kNoCall); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4725 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4726 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4727 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4728 | if (Primitive::IsFloatingPointType(value_type)) { |
| 4729 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4730 | } else { |
| 4731 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 4732 | } |
| 4733 | |
| 4734 | if (needs_write_barrier) { |
| 4735 | // Temporary registers for the write barrier. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4736 | |
| 4737 | // This first temporary register is possibly used for heap |
| 4738 | // reference poisoning and/or read barrier emission too. |
| 4739 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4740 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4741 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4742 | } |
| 4743 | |
| 4744 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 4745 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4746 | Location array_loc = locations->InAt(0); |
| 4747 | CpuRegister array = array_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4748 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4749 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4750 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4751 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4752 | bool needs_write_barrier = |
| 4753 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4754 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4755 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4756 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4757 | |
| 4758 | switch (value_type) { |
| 4759 | case Primitive::kPrimBoolean: |
| 4760 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4761 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 4762 | Address address = index.IsConstant() |
| 4763 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 4764 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_1, offset); |
| 4765 | if (value.IsRegister()) { |
| 4766 | __ movb(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4767 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4768 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4769 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4770 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4771 | break; |
| 4772 | } |
| 4773 | |
| 4774 | case Primitive::kPrimShort: |
| 4775 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4776 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 4777 | Address address = index.IsConstant() |
| 4778 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 4779 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_2, offset); |
| 4780 | if (value.IsRegister()) { |
| 4781 | __ movw(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4782 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4783 | DCHECK(value.IsConstant()) << value; |
| 4784 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4785 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4786 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4787 | break; |
| 4788 | } |
| 4789 | |
| 4790 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4791 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4792 | Address address = index.IsConstant() |
| 4793 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4794 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4795 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4796 | if (!value.IsRegister()) { |
| 4797 | // Just setting null. |
| 4798 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 4799 | DCHECK(value.IsConstant()) << value; |
| 4800 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4801 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4802 | DCHECK(!needs_write_barrier); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4803 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4804 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4805 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4806 | |
| 4807 | DCHECK(needs_write_barrier); |
| 4808 | CpuRegister register_value = value.AsRegister<CpuRegister>(); |
| 4809 | NearLabel done, not_null, do_put; |
| 4810 | SlowPathCode* slow_path = nullptr; |
| 4811 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4812 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4813 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86_64(instruction); |
| 4814 | codegen_->AddSlowPath(slow_path); |
| 4815 | if (instruction->GetValueCanBeNull()) { |
| 4816 | __ testl(register_value, register_value); |
| 4817 | __ j(kNotEqual, ¬_null); |
| 4818 | __ movl(address, Immediate(0)); |
| 4819 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4820 | __ jmp(&done); |
| 4821 | __ Bind(¬_null); |
| 4822 | } |
| 4823 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4824 | if (kEmitCompilerReadBarrier) { |
| 4825 | // When read barriers are enabled, the type checking |
| 4826 | // instrumentation requires two read barriers: |
| 4827 | // |
| 4828 | // __ movl(temp2, temp); |
| 4829 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 4830 | // __ movl(temp, Address(temp, component_offset)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4831 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4832 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 4833 | // |
| 4834 | // // /* HeapReference<Class> */ temp2 = register_value->klass_ |
| 4835 | // __ movl(temp2, Address(register_value, class_offset)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4836 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4837 | // instruction, temp2_loc, temp2_loc, value, class_offset, temp_loc); |
| 4838 | // |
| 4839 | // __ cmpl(temp, temp2); |
| 4840 | // |
| 4841 | // However, the second read barrier may trash `temp`, as it |
| 4842 | // is a temporary register, and as such would not be saved |
| 4843 | // along with live registers before calling the runtime (nor |
| 4844 | // restored afterwards). So in this case, we bail out and |
| 4845 | // delegate the work to the array set slow path. |
| 4846 | // |
| 4847 | // TODO: Extend the register allocator to support a new |
| 4848 | // "(locally) live temp" location so as to avoid always |
| 4849 | // going into the slow path when read barriers are enabled. |
| 4850 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4851 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4852 | // /* HeapReference<Class> */ temp = array->klass_ |
| 4853 | __ movl(temp, Address(array, class_offset)); |
| 4854 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4855 | __ MaybeUnpoisonHeapReference(temp); |
| 4856 | |
| 4857 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 4858 | __ movl(temp, Address(temp, component_offset)); |
| 4859 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 4860 | // nor the object reference in `register_value->klass`, as |
| 4861 | // we are comparing two poisoned references. |
| 4862 | __ cmpl(temp, Address(register_value, class_offset)); |
| 4863 | |
| 4864 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4865 | __ j(kEqual, &do_put); |
| 4866 | // If heap poisoning is enabled, the `temp` reference has |
| 4867 | // not been unpoisoned yet; unpoison it now. |
| 4868 | __ MaybeUnpoisonHeapReference(temp); |
| 4869 | |
| 4870 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 4871 | __ movl(temp, Address(temp, super_offset)); |
| 4872 | // If heap poisoning is enabled, no need to unpoison |
| 4873 | // `temp`, as we are comparing against null below. |
| 4874 | __ testl(temp, temp); |
| 4875 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4876 | __ Bind(&do_put); |
| 4877 | } else { |
| 4878 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4879 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4880 | } |
| 4881 | } |
| 4882 | |
| 4883 | if (kPoisonHeapReferences) { |
| 4884 | __ movl(temp, register_value); |
| 4885 | __ PoisonHeapReference(temp); |
| 4886 | __ movl(address, temp); |
| 4887 | } else { |
| 4888 | __ movl(address, register_value); |
| 4889 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4890 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4891 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4892 | } |
| 4893 | |
| 4894 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 4895 | codegen_->MarkGCCard( |
| 4896 | temp, card, array, value.AsRegister<CpuRegister>(), instruction->GetValueCanBeNull()); |
| 4897 | __ Bind(&done); |
| 4898 | |
| 4899 | if (slow_path != nullptr) { |
| 4900 | __ Bind(slow_path->GetExitLabel()); |
| 4901 | } |
| 4902 | |
| 4903 | break; |
| 4904 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4905 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4906 | case Primitive::kPrimInt: { |
| 4907 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4908 | Address address = index.IsConstant() |
| 4909 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4910 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
| 4911 | if (value.IsRegister()) { |
| 4912 | __ movl(address, value.AsRegister<CpuRegister>()); |
| 4913 | } else { |
| 4914 | DCHECK(value.IsConstant()) << value; |
| 4915 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4916 | __ movl(address, Immediate(v)); |
| 4917 | } |
| 4918 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4919 | break; |
| 4920 | } |
| 4921 | |
| 4922 | case Primitive::kPrimLong: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4923 | uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| 4924 | Address address = index.IsConstant() |
| 4925 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 4926 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset); |
| 4927 | if (value.IsRegister()) { |
| 4928 | __ movq(address, value.AsRegister<CpuRegister>()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4929 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4930 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4931 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4932 | Address address_high = index.IsConstant() |
| 4933 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 4934 | offset + sizeof(int32_t)) |
| 4935 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset + sizeof(int32_t)); |
| 4936 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4937 | } |
| 4938 | break; |
| 4939 | } |
| 4940 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4941 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4942 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4943 | Address address = index.IsConstant() |
| 4944 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4945 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4946 | if (value.IsFpuRegister()) { |
| 4947 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 4948 | } else { |
| 4949 | DCHECK(value.IsConstant()); |
| 4950 | int32_t v = |
| 4951 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4952 | __ movl(address, Immediate(v)); |
| 4953 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4954 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4955 | break; |
| 4956 | } |
| 4957 | |
| 4958 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4959 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4960 | Address address = index.IsConstant() |
| 4961 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 4962 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4963 | if (value.IsFpuRegister()) { |
| 4964 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 4965 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4966 | } else { |
| 4967 | int64_t v = |
| 4968 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4969 | Address address_high = index.IsConstant() |
| 4970 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 4971 | offset + sizeof(int32_t)) |
| 4972 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset + sizeof(int32_t)); |
| 4973 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| 4974 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4975 | break; |
| 4976 | } |
| 4977 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4978 | case Primitive::kPrimVoid: |
| 4979 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4980 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4981 | } |
| 4982 | } |
| 4983 | |
| 4984 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4985 | LocationSummary* locations = |
| 4986 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4987 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4988 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4989 | } |
| 4990 | |
| 4991 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
| 4992 | LocationSummary* locations = instruction->GetLocations(); |
| 4993 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4994 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4995 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4996 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4997 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4998 | } |
| 4999 | |
| 5000 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5001 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 5002 | ? LocationSummary::kCallOnSlowPath |
| 5003 | : LocationSummary::kNoCall; |
| 5004 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5005 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5006 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5007 | if (instruction->HasUses()) { |
| 5008 | locations->SetOut(Location::SameAsFirstInput()); |
| 5009 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5010 | } |
| 5011 | |
| 5012 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5013 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5014 | Location index_loc = locations->InAt(0); |
| 5015 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5016 | SlowPathCode* slow_path = |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5017 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5018 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5019 | if (length_loc.IsConstant()) { |
| 5020 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5021 | if (index_loc.IsConstant()) { |
| 5022 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5023 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5024 | if (index < 0 || index >= length) { |
| 5025 | codegen_->AddSlowPath(slow_path); |
| 5026 | __ jmp(slow_path->GetEntryLabel()); |
| 5027 | } else { |
| 5028 | // Some optimization after BCE may have generated this, and we should not |
| 5029 | // generate a bounds check if it is a valid range. |
| 5030 | } |
| 5031 | return; |
| 5032 | } |
| 5033 | |
| 5034 | // We have to reverse the jump condition because the length is the constant. |
| 5035 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 5036 | __ cmpl(index_reg, Immediate(length)); |
| 5037 | codegen_->AddSlowPath(slow_path); |
| 5038 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5039 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5040 | CpuRegister length = length_loc.AsRegister<CpuRegister>(); |
| 5041 | if (index_loc.IsConstant()) { |
| 5042 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5043 | __ cmpl(length, Immediate(value)); |
| 5044 | } else { |
| 5045 | __ cmpl(length, index_loc.AsRegister<CpuRegister>()); |
| 5046 | } |
| 5047 | codegen_->AddSlowPath(slow_path); |
| 5048 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5049 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5050 | } |
| 5051 | |
| 5052 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 5053 | CpuRegister card, |
| 5054 | CpuRegister object, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5055 | CpuRegister value, |
| 5056 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5057 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5058 | if (value_can_be_null) { |
| 5059 | __ testl(value, value); |
| 5060 | __ j(kEqual, &is_null); |
| 5061 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5062 | __ gs()->movq(card, Address::Absolute(Thread::CardTableOffset<kX86_64WordSize>().Int32Value(), |
| 5063 | /* no_rip */ true)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5064 | __ movq(temp, object); |
| 5065 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5066 | __ movb(Address(temp, card, TIMES_1, 0), card); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5067 | if (value_can_be_null) { |
| 5068 | __ Bind(&is_null); |
| 5069 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5070 | } |
| 5071 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5072 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5073 | LOG(FATAL) << "Unimplemented"; |
| 5074 | } |
| 5075 | |
| 5076 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5077 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5078 | } |
| 5079 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5080 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 5081 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 5082 | } |
| 5083 | |
| 5084 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5085 | HBasicBlock* block = instruction->GetBlock(); |
| 5086 | if (block->GetLoopInformation() != nullptr) { |
| 5087 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5088 | // The back edge will generate the suspend check. |
| 5089 | return; |
| 5090 | } |
| 5091 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5092 | // The goto will generate the suspend check. |
| 5093 | return; |
| 5094 | } |
| 5095 | GenerateSuspendCheck(instruction, nullptr); |
| 5096 | } |
| 5097 | |
| 5098 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5099 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5100 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5101 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 5102 | if (slow_path == nullptr) { |
| 5103 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
| 5104 | instruction->SetSlowPath(slow_path); |
| 5105 | codegen_->AddSlowPath(slow_path); |
| 5106 | if (successor != nullptr) { |
| 5107 | DCHECK(successor->IsLoopHeader()); |
| 5108 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5109 | } |
| 5110 | } else { |
| 5111 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5112 | } |
| 5113 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5114 | __ gs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86_64WordSize>().Int32Value(), |
| 5115 | /* no_rip */ true), |
| 5116 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5117 | if (successor == nullptr) { |
| 5118 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5119 | __ Bind(slow_path->GetReturnLabel()); |
| 5120 | } else { |
| 5121 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5122 | __ jmp(slow_path->GetEntryLabel()); |
| 5123 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5124 | } |
| 5125 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5126 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 5127 | return codegen_->GetAssembler(); |
| 5128 | } |
| 5129 | |
| 5130 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5131 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5132 | Location source = move->GetSource(); |
| 5133 | Location destination = move->GetDestination(); |
| 5134 | |
| 5135 | if (source.IsRegister()) { |
| 5136 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5137 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5138 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5139 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5140 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5141 | } else { |
| 5142 | DCHECK(destination.IsDoubleStackSlot()); |
| 5143 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5144 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5145 | } |
| 5146 | } else if (source.IsStackSlot()) { |
| 5147 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5148 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5149 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5150 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5151 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5152 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5153 | } else { |
| 5154 | DCHECK(destination.IsStackSlot()); |
| 5155 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5156 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5157 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5158 | } else if (source.IsDoubleStackSlot()) { |
| 5159 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5160 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5161 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5162 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5163 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 5164 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5165 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 5166 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5167 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5168 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5169 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5170 | } else if (source.IsConstant()) { |
| 5171 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5172 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5173 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5174 | if (destination.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5175 | if (value == 0) { |
| 5176 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 5177 | } else { |
| 5178 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 5179 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5180 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5181 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5182 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5183 | } |
| 5184 | } else if (constant->IsLongConstant()) { |
| 5185 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5186 | if (destination.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5187 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5188 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5189 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5190 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5191 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5192 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5193 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5194 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5195 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5196 | codegen_->Load32BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5197 | } else { |
| 5198 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5199 | Immediate imm(bit_cast<int32_t, float>(fp_value)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5200 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 5201 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5202 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5203 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5204 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5205 | int64_t value = bit_cast<int64_t, double>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5206 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5207 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5208 | codegen_->Load64BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5209 | } else { |
| 5210 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5211 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5212 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5213 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5214 | } else if (source.IsFpuRegister()) { |
| 5215 | if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5216 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5217 | } else if (destination.IsStackSlot()) { |
| 5218 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5219 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5220 | } else { |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 5221 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5222 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5223 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5224 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5225 | } |
| 5226 | } |
| 5227 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5228 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5229 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5230 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 5231 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5232 | } |
| 5233 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5234 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5235 | ScratchRegisterScope ensure_scratch( |
| 5236 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 5237 | |
| 5238 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5239 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5240 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 5241 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5242 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5243 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5244 | CpuRegister(ensure_scratch.GetRegister())); |
| 5245 | } |
| 5246 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5247 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 5248 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5249 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 5250 | __ movq(reg, CpuRegister(TMP)); |
| 5251 | } |
| 5252 | |
| 5253 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 5254 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5255 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5256 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5257 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5258 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5259 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 5260 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5261 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5262 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5263 | CpuRegister(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5264 | } |
| 5265 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5266 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 5267 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5268 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 5269 | __ movd(reg, CpuRegister(TMP)); |
| 5270 | } |
| 5271 | |
| 5272 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 5273 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5274 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 5275 | __ movd(reg, CpuRegister(TMP)); |
| 5276 | } |
| 5277 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5278 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5279 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5280 | Location source = move->GetSource(); |
| 5281 | Location destination = move->GetDestination(); |
| 5282 | |
| 5283 | if (source.IsRegister() && destination.IsRegister()) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5284 | __ xchgq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5285 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5286 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5287 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5288 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5289 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5290 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5291 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5292 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5293 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5294 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5295 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 5296 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5297 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5298 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 5299 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5300 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5301 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5302 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5303 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5304 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5305 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5306 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5307 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5308 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5309 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5310 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5311 | } |
| 5312 | } |
| 5313 | |
| 5314 | |
| 5315 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 5316 | __ pushq(CpuRegister(reg)); |
| 5317 | } |
| 5318 | |
| 5319 | |
| 5320 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 5321 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5322 | } |
| 5323 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5324 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5325 | SlowPathCode* slow_path, CpuRegister class_reg) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5326 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5327 | Immediate(mirror::Class::kStatusInitialized)); |
| 5328 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5329 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5330 | // No need for memory fence, thanks to the x86-64 memory model. |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5331 | } |
| 5332 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5333 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5334 | InvokeRuntimeCallingConvention calling_convention; |
| 5335 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5336 | cls, |
| 5337 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5338 | Location::RegisterLocation(RAX), |
| 5339 | /* code_generator_supports_read_barrier */ true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5340 | } |
| 5341 | |
| 5342 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5343 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5344 | if (cls->NeedsAccessCheck()) { |
| 5345 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 5346 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 5347 | cls, |
| 5348 | cls->GetDexPc(), |
| 5349 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5350 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5351 | return; |
| 5352 | } |
| 5353 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5354 | Location out_loc = locations->Out(); |
| 5355 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5356 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5357 | |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5358 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5359 | DCHECK(!cls->CanCallRuntime()); |
| 5360 | DCHECK(!cls->MustGenerateClinitCheck()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5361 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5362 | GenerateGcRootFieldLoad( |
| 5363 | cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5364 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5365 | // /* GcRoot<mirror::Class>[] */ out = |
| 5366 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5367 | __ movq(out, Address(current_method, |
| 5368 | ArtMethod::DexCacheResolvedTypesOffset(kX86_64PointerSize).Int32Value())); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5369 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5370 | GenerateGcRootFieldLoad(cls, out_loc, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5371 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5372 | if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { |
| 5373 | DCHECK(cls->CanCallRuntime()); |
| 5374 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 5375 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5376 | codegen_->AddSlowPath(slow_path); |
| 5377 | if (!cls->IsInDexCache()) { |
| 5378 | __ testl(out, out); |
| 5379 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5380 | } |
| 5381 | if (cls->MustGenerateClinitCheck()) { |
| 5382 | GenerateClassInitializationCheck(slow_path, out); |
| 5383 | } else { |
| 5384 | __ Bind(slow_path->GetExitLabel()); |
| 5385 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5386 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5387 | } |
| 5388 | } |
| 5389 | |
| 5390 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 5391 | LocationSummary* locations = |
| 5392 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5393 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5394 | if (check->HasUses()) { |
| 5395 | locations->SetOut(Location::SameAsFirstInput()); |
| 5396 | } |
| 5397 | } |
| 5398 | |
| 5399 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5400 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5401 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5402 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5403 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5404 | GenerateClassInitializationCheck(slow_path, |
| 5405 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5406 | } |
| 5407 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5408 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5409 | LocationSummary::CallKind call_kind = (!load->IsInDexCache() || kEmitCompilerReadBarrier) |
| 5410 | ? LocationSummary::kCallOnSlowPath |
| 5411 | : LocationSummary::kNoCall; |
| 5412 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5413 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5414 | locations->SetOut(Location::RequiresRegister()); |
| 5415 | } |
| 5416 | |
| 5417 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5418 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5419 | Location out_loc = locations->Out(); |
| 5420 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5421 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5422 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5423 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5424 | GenerateGcRootFieldLoad( |
| 5425 | load, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5426 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
| 5427 | __ movq(out, Address(out, mirror::Class::DexCacheStringsOffset().Uint32Value())); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5428 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 5429 | GenerateGcRootFieldLoad( |
| 5430 | load, out_loc, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5431 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5432 | if (!load->IsInDexCache()) { |
| 5433 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86_64(load); |
| 5434 | codegen_->AddSlowPath(slow_path); |
| 5435 | __ testl(out, out); |
| 5436 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5437 | __ Bind(slow_path->GetExitLabel()); |
| 5438 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5439 | } |
| 5440 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5441 | static Address GetExceptionTlsAddress() { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5442 | return Address::Absolute(Thread::ExceptionOffset<kX86_64WordSize>().Int32Value(), |
| 5443 | /* no_rip */ true); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5444 | } |
| 5445 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5446 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 5447 | LocationSummary* locations = |
| 5448 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5449 | locations->SetOut(Location::RequiresRegister()); |
| 5450 | } |
| 5451 | |
| 5452 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5453 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 5454 | } |
| 5455 | |
| 5456 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
| 5457 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5458 | } |
| 5459 | |
| 5460 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5461 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5462 | } |
| 5463 | |
| 5464 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| 5465 | LocationSummary* locations = |
| 5466 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5467 | InvokeRuntimeCallingConvention calling_convention; |
| 5468 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5469 | } |
| 5470 | |
| 5471 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5472 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 5473 | instruction, |
| 5474 | instruction->GetDexPc(), |
| 5475 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5476 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5477 | } |
| 5478 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5479 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5480 | return kEmitCompilerReadBarrier && |
| 5481 | (kUseBakerReadBarrier || |
| 5482 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5483 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5484 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5485 | } |
| 5486 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5487 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5488 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5489 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5490 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5491 | case TypeCheckKind::kExactCheck: |
| 5492 | case TypeCheckKind::kAbstractClassCheck: |
| 5493 | case TypeCheckKind::kClassHierarchyCheck: |
| 5494 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5495 | call_kind = |
| 5496 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5497 | break; |
| 5498 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5499 | case TypeCheckKind::kUnresolvedCheck: |
| 5500 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5501 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5502 | break; |
| 5503 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5504 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5505 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5506 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5507 | locations->SetInAt(1, Location::Any()); |
| 5508 | // Note that TypeCheckSlowPathX86_64 uses this "out" register too. |
| 5509 | locations->SetOut(Location::RequiresRegister()); |
| 5510 | // When read barriers are enabled, we need a temporary register for |
| 5511 | // some cases. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5512 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5513 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5514 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5515 | } |
| 5516 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5517 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5518 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5519 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5520 | Location obj_loc = locations->InAt(0); |
| 5521 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5522 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5523 | Location out_loc = locations->Out(); |
| 5524 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5525 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5526 | locations->GetTemp(0) : |
| 5527 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5528 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5529 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5530 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5531 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5532 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5533 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5534 | |
| 5535 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5536 | // Avoid null check if we know obj is not null. |
| 5537 | if (instruction->MustDoNullCheck()) { |
| 5538 | __ testl(obj, obj); |
| 5539 | __ j(kEqual, &zero); |
| 5540 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5541 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5542 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5543 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5544 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5545 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5546 | case TypeCheckKind::kExactCheck: { |
| 5547 | if (cls.IsRegister()) { |
| 5548 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5549 | } else { |
| 5550 | DCHECK(cls.IsStackSlot()) << cls; |
| 5551 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5552 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5553 | if (zero.IsLinked()) { |
| 5554 | // Classes must be equal for the instanceof to succeed. |
| 5555 | __ j(kNotEqual, &zero); |
| 5556 | __ movl(out, Immediate(1)); |
| 5557 | __ jmp(&done); |
| 5558 | } else { |
| 5559 | __ setcc(kEqual, out); |
| 5560 | // setcc only sets the low byte. |
| 5561 | __ andl(out, Immediate(1)); |
| 5562 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5563 | break; |
| 5564 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5565 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5566 | case TypeCheckKind::kAbstractClassCheck: { |
| 5567 | // If the class is abstract, we eagerly fetch the super class of the |
| 5568 | // object to avoid doing a comparison we know will fail. |
| 5569 | NearLabel loop, success; |
| 5570 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5571 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5572 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5573 | __ testl(out, out); |
| 5574 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5575 | __ j(kEqual, &done); |
| 5576 | if (cls.IsRegister()) { |
| 5577 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5578 | } else { |
| 5579 | DCHECK(cls.IsStackSlot()) << cls; |
| 5580 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5581 | } |
| 5582 | __ j(kNotEqual, &loop); |
| 5583 | __ movl(out, Immediate(1)); |
| 5584 | if (zero.IsLinked()) { |
| 5585 | __ jmp(&done); |
| 5586 | } |
| 5587 | break; |
| 5588 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5589 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5590 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5591 | // Walk over the class hierarchy to find a match. |
| 5592 | NearLabel loop, success; |
| 5593 | __ Bind(&loop); |
| 5594 | if (cls.IsRegister()) { |
| 5595 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5596 | } else { |
| 5597 | DCHECK(cls.IsStackSlot()) << cls; |
| 5598 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5599 | } |
| 5600 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5601 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5602 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5603 | __ testl(out, out); |
| 5604 | __ j(kNotEqual, &loop); |
| 5605 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5606 | __ jmp(&done); |
| 5607 | __ Bind(&success); |
| 5608 | __ movl(out, Immediate(1)); |
| 5609 | if (zero.IsLinked()) { |
| 5610 | __ jmp(&done); |
| 5611 | } |
| 5612 | break; |
| 5613 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5614 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5615 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5616 | // Do an exact check. |
| 5617 | NearLabel exact_check; |
| 5618 | if (cls.IsRegister()) { |
| 5619 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5620 | } else { |
| 5621 | DCHECK(cls.IsStackSlot()) << cls; |
| 5622 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5623 | } |
| 5624 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5625 | // 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] | 5626 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5627 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5628 | __ testl(out, out); |
| 5629 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5630 | __ j(kEqual, &done); |
| 5631 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5632 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5633 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5634 | __ movl(out, Immediate(1)); |
| 5635 | __ jmp(&done); |
| 5636 | break; |
| 5637 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5638 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5639 | case TypeCheckKind::kArrayCheck: { |
| 5640 | if (cls.IsRegister()) { |
| 5641 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5642 | } else { |
| 5643 | DCHECK(cls.IsStackSlot()) << cls; |
| 5644 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5645 | } |
| 5646 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5647 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5648 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5649 | codegen_->AddSlowPath(slow_path); |
| 5650 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5651 | __ movl(out, Immediate(1)); |
| 5652 | if (zero.IsLinked()) { |
| 5653 | __ jmp(&done); |
| 5654 | } |
| 5655 | break; |
| 5656 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5657 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5658 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5659 | case TypeCheckKind::kInterfaceCheck: { |
| 5660 | // 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] | 5661 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5662 | // cases. |
| 5663 | // |
| 5664 | // We cannot directly call the InstanceofNonTrivial runtime |
| 5665 | // entry point without resorting to a type checking slow path |
| 5666 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 5667 | // require to assign fixed registers for the inputs of this |
| 5668 | // HInstanceOf instruction (following the runtime calling |
| 5669 | // convention), which might be cluttered by the potential first |
| 5670 | // read barrier emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5671 | // |
| 5672 | // TODO: Introduce a new runtime entry point taking the object |
| 5673 | // to test (instead of its class) as argument, and let it deal |
| 5674 | // with the read barrier issues. This will let us refactor this |
| 5675 | // case of the `switch` code as it was previously (with a direct |
| 5676 | // call to the runtime not using a type checking slow path). |
| 5677 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5678 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5679 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5680 | /* is_fatal */ false); |
| 5681 | codegen_->AddSlowPath(slow_path); |
| 5682 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5683 | if (zero.IsLinked()) { |
| 5684 | __ jmp(&done); |
| 5685 | } |
| 5686 | break; |
| 5687 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5688 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5689 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5690 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5691 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5692 | __ xorl(out, out); |
| 5693 | } |
| 5694 | |
| 5695 | if (done.IsLinked()) { |
| 5696 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5697 | } |
| 5698 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5699 | if (slow_path != nullptr) { |
| 5700 | __ Bind(slow_path->GetExitLabel()); |
| 5701 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5702 | } |
| 5703 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5704 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5705 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5706 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5707 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5708 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5709 | case TypeCheckKind::kExactCheck: |
| 5710 | case TypeCheckKind::kAbstractClassCheck: |
| 5711 | case TypeCheckKind::kClassHierarchyCheck: |
| 5712 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5713 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 5714 | LocationSummary::kCallOnSlowPath : |
| 5715 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5716 | break; |
| 5717 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5718 | case TypeCheckKind::kUnresolvedCheck: |
| 5719 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5720 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5721 | break; |
| 5722 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5723 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 5724 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5725 | locations->SetInAt(1, Location::Any()); |
| 5726 | // Note that TypeCheckSlowPathX86_64 uses this "temp" register too. |
| 5727 | locations->AddTemp(Location::RequiresRegister()); |
| 5728 | // When read barriers are enabled, we need an additional temporary |
| 5729 | // register for some cases. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5730 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5731 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5732 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5733 | } |
| 5734 | |
| 5735 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5736 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5737 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5738 | Location obj_loc = locations->InAt(0); |
| 5739 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5740 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5741 | Location temp_loc = locations->GetTemp(0); |
| 5742 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5743 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5744 | locations->GetTemp(1) : |
| 5745 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5746 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5747 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5748 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5749 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5750 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5751 | bool is_type_check_slow_path_fatal = |
| 5752 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 5753 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5754 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5755 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 5756 | !instruction->CanThrowIntoCatchBlock(); |
| 5757 | SlowPathCode* type_check_slow_path = |
| 5758 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5759 | is_type_check_slow_path_fatal); |
| 5760 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5761 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5762 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5763 | case TypeCheckKind::kExactCheck: |
| 5764 | case TypeCheckKind::kArrayCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5765 | NearLabel done; |
| 5766 | // Avoid null check if we know obj is not null. |
| 5767 | if (instruction->MustDoNullCheck()) { |
| 5768 | __ testl(obj, obj); |
| 5769 | __ j(kEqual, &done); |
| 5770 | } |
| 5771 | |
| 5772 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5773 | GenerateReferenceLoadTwoRegisters( |
| 5774 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
| 5775 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5776 | if (cls.IsRegister()) { |
| 5777 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5778 | } else { |
| 5779 | DCHECK(cls.IsStackSlot()) << cls; |
| 5780 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5781 | } |
| 5782 | // Jump to slow path for throwing the exception or doing a |
| 5783 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5784 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5785 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5786 | break; |
| 5787 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5788 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5789 | case TypeCheckKind::kAbstractClassCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5790 | NearLabel done; |
| 5791 | // Avoid null check if we know obj is not null. |
| 5792 | if (instruction->MustDoNullCheck()) { |
| 5793 | __ testl(obj, obj); |
| 5794 | __ j(kEqual, &done); |
| 5795 | } |
| 5796 | |
| 5797 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5798 | GenerateReferenceLoadTwoRegisters( |
| 5799 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
| 5800 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5801 | // If the class is abstract, we eagerly fetch the super class of the |
| 5802 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5803 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5804 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5805 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5806 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5807 | |
| 5808 | // If the class reference currently in `temp` is not null, jump |
| 5809 | // to the `compare_classes` label to compare it with the checked |
| 5810 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5811 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5812 | __ j(kNotEqual, &compare_classes); |
| 5813 | // Otherwise, jump to the slow path to throw the exception. |
| 5814 | // |
| 5815 | // But before, move back the object's class into `temp` before |
| 5816 | // going into the slow path, as it has been overwritten in the |
| 5817 | // meantime. |
| 5818 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5819 | GenerateReferenceLoadTwoRegisters( |
| 5820 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5821 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 5822 | |
| 5823 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5824 | if (cls.IsRegister()) { |
| 5825 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5826 | } else { |
| 5827 | DCHECK(cls.IsStackSlot()) << cls; |
| 5828 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5829 | } |
| 5830 | __ j(kNotEqual, &loop); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5831 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5832 | break; |
| 5833 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5834 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5835 | case TypeCheckKind::kClassHierarchyCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5836 | NearLabel done; |
| 5837 | // Avoid null check if we know obj is not null. |
| 5838 | if (instruction->MustDoNullCheck()) { |
| 5839 | __ testl(obj, obj); |
| 5840 | __ j(kEqual, &done); |
| 5841 | } |
| 5842 | |
| 5843 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5844 | GenerateReferenceLoadTwoRegisters( |
| 5845 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
| 5846 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5847 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5848 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5849 | __ Bind(&loop); |
| 5850 | if (cls.IsRegister()) { |
| 5851 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5852 | } else { |
| 5853 | DCHECK(cls.IsStackSlot()) << cls; |
| 5854 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5855 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5856 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5857 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5858 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5859 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5860 | |
| 5861 | // If the class reference currently in `temp` is not null, jump |
| 5862 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5863 | __ testl(temp, temp); |
| 5864 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5865 | // Otherwise, jump to the slow path to throw the exception. |
| 5866 | // |
| 5867 | // But before, move back the object's class into `temp` before |
| 5868 | // going into the slow path, as it has been overwritten in the |
| 5869 | // meantime. |
| 5870 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5871 | GenerateReferenceLoadTwoRegisters( |
| 5872 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5873 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5874 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5875 | break; |
| 5876 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5877 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5878 | case TypeCheckKind::kArrayObjectCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5879 | // We cannot use a NearLabel here, as its range might be too |
| 5880 | // short in some cases when read barriers are enabled. This has |
| 5881 | // been observed for instance when the code emitted for this |
| 5882 | // case uses high x86-64 registers (R8-R15). |
| 5883 | Label done; |
| 5884 | // Avoid null check if we know obj is not null. |
| 5885 | if (instruction->MustDoNullCheck()) { |
| 5886 | __ testl(obj, obj); |
| 5887 | __ j(kEqual, &done); |
| 5888 | } |
| 5889 | |
| 5890 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5891 | GenerateReferenceLoadTwoRegisters( |
| 5892 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
| 5893 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5894 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5895 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5896 | if (cls.IsRegister()) { |
| 5897 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5898 | } else { |
| 5899 | DCHECK(cls.IsStackSlot()) << cls; |
| 5900 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5901 | } |
| 5902 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5903 | |
| 5904 | // 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] | 5905 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5906 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5907 | |
| 5908 | // If the component type is not null (i.e. the object is indeed |
| 5909 | // an array), jump to label `check_non_primitive_component_type` |
| 5910 | // to further check that this component type is not a primitive |
| 5911 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5912 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5913 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 5914 | // Otherwise, jump to the slow path to throw the exception. |
| 5915 | // |
| 5916 | // But before, move back the object's class into `temp` before |
| 5917 | // going into the slow path, as it has been overwritten in the |
| 5918 | // meantime. |
| 5919 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5920 | GenerateReferenceLoadTwoRegisters( |
| 5921 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5922 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 5923 | |
| 5924 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5925 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5926 | __ j(kEqual, &done); |
| 5927 | // Same comment as above regarding `temp` and the slow path. |
| 5928 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5929 | GenerateReferenceLoadTwoRegisters( |
| 5930 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5931 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5932 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5933 | break; |
| 5934 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5935 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5936 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5937 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5938 | NearLabel done; |
| 5939 | // Avoid null check if we know obj is not null. |
| 5940 | if (instruction->MustDoNullCheck()) { |
| 5941 | __ testl(obj, obj); |
| 5942 | __ j(kEqual, &done); |
| 5943 | } |
| 5944 | |
| 5945 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5946 | GenerateReferenceLoadTwoRegisters( |
| 5947 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
| 5948 | |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 5949 | // We always go into the type check slow path for the unresolved |
| 5950 | // and interface check cases. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5951 | // |
| 5952 | // We cannot directly call the CheckCast runtime entry point |
| 5953 | // without resorting to a type checking slow path here (i.e. by |
| 5954 | // calling InvokeRuntime directly), as it would require to |
| 5955 | // assign fixed registers for the inputs of this HInstanceOf |
| 5956 | // instruction (following the runtime calling convention), which |
| 5957 | // might be cluttered by the potential first read barrier |
| 5958 | // emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5959 | // |
| 5960 | // TODO: Introduce a new runtime entry point taking the object |
| 5961 | // to test (instead of its class) as argument, and let it deal |
| 5962 | // with the read barrier issues. This will let us refactor this |
| 5963 | // case of the `switch` code as it was previously (with a direct |
| 5964 | // call to the runtime not using a type checking slow path). |
| 5965 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5966 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5967 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5968 | break; |
| 5969 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5970 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5971 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5972 | } |
| 5973 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5974 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5975 | LocationSummary* locations = |
| 5976 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5977 | InvokeRuntimeCallingConvention calling_convention; |
| 5978 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5979 | } |
| 5980 | |
| 5981 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5982 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 5983 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 5984 | instruction, |
| 5985 | instruction->GetDexPc(), |
| 5986 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5987 | if (instruction->IsEnter()) { |
| 5988 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 5989 | } else { |
| 5990 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 5991 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5992 | } |
| 5993 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5994 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 5995 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 5996 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 5997 | |
| 5998 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5999 | LocationSummary* locations = |
| 6000 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6001 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6002 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6003 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6004 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6005 | locations->SetOut(Location::SameAsFirstInput()); |
| 6006 | } |
| 6007 | |
| 6008 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 6009 | HandleBitwiseOperation(instruction); |
| 6010 | } |
| 6011 | |
| 6012 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 6013 | HandleBitwiseOperation(instruction); |
| 6014 | } |
| 6015 | |
| 6016 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 6017 | HandleBitwiseOperation(instruction); |
| 6018 | } |
| 6019 | |
| 6020 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6021 | LocationSummary* locations = instruction->GetLocations(); |
| 6022 | Location first = locations->InAt(0); |
| 6023 | Location second = locations->InAt(1); |
| 6024 | DCHECK(first.Equals(locations->Out())); |
| 6025 | |
| 6026 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6027 | if (second.IsRegister()) { |
| 6028 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6029 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6030 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6031 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6032 | } else { |
| 6033 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6034 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6035 | } |
| 6036 | } else if (second.IsConstant()) { |
| 6037 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 6038 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6039 | __ andl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6040 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6041 | __ orl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6042 | } else { |
| 6043 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6044 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6045 | } |
| 6046 | } else { |
| 6047 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 6048 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6049 | __ andl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6050 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6051 | __ orl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6052 | } else { |
| 6053 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6054 | __ xorl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6055 | } |
| 6056 | } |
| 6057 | } else { |
| 6058 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6059 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 6060 | bool second_is_constant = false; |
| 6061 | int64_t value = 0; |
| 6062 | if (second.IsConstant()) { |
| 6063 | second_is_constant = true; |
| 6064 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6065 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6066 | bool is_int32_value = IsInt<32>(value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6067 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6068 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6069 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6070 | if (is_int32_value) { |
| 6071 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6072 | } else { |
| 6073 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6074 | } |
| 6075 | } else if (second.IsDoubleStackSlot()) { |
| 6076 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6077 | } else { |
| 6078 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 6079 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6080 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6081 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6082 | if (is_int32_value) { |
| 6083 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6084 | } else { |
| 6085 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6086 | } |
| 6087 | } else if (second.IsDoubleStackSlot()) { |
| 6088 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6089 | } else { |
| 6090 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 6091 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6092 | } else { |
| 6093 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6094 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6095 | if (is_int32_value) { |
| 6096 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6097 | } else { |
| 6098 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6099 | } |
| 6100 | } else if (second.IsDoubleStackSlot()) { |
| 6101 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6102 | } else { |
| 6103 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 6104 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6105 | } |
| 6106 | } |
| 6107 | } |
| 6108 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6109 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6110 | Location out, |
| 6111 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6112 | Location maybe_temp) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6113 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6114 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6115 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6116 | if (kUseBakerReadBarrier) { |
| 6117 | // Load with fast path based Baker's read barrier. |
| 6118 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6119 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6120 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6121 | } else { |
| 6122 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6123 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6124 | // in the following move operation, as we will need it for the |
| 6125 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6126 | __ movl(maybe_temp.AsRegister<CpuRegister>(), out_reg); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6127 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6128 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6129 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6130 | } |
| 6131 | } else { |
| 6132 | // Plain load with no read barrier. |
| 6133 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6134 | __ movl(out_reg, Address(out_reg, offset)); |
| 6135 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6136 | } |
| 6137 | } |
| 6138 | |
| 6139 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6140 | Location out, |
| 6141 | Location obj, |
| 6142 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6143 | Location maybe_temp) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6144 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6145 | CpuRegister obj_reg = obj.AsRegister<CpuRegister>(); |
| 6146 | if (kEmitCompilerReadBarrier) { |
| 6147 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6148 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6149 | // Load with fast path based Baker's read barrier. |
| 6150 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6151 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6152 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6153 | } else { |
| 6154 | // Load with slow path based read barrier. |
| 6155 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6156 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6157 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6158 | } |
| 6159 | } else { |
| 6160 | // Plain load with no read barrier. |
| 6161 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6162 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6163 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6164 | } |
| 6165 | } |
| 6166 | |
| 6167 | void InstructionCodeGeneratorX86_64::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6168 | Location root, |
| 6169 | CpuRegister obj, |
| 6170 | uint32_t offset) { |
| 6171 | CpuRegister root_reg = root.AsRegister<CpuRegister>(); |
| 6172 | if (kEmitCompilerReadBarrier) { |
| 6173 | if (kUseBakerReadBarrier) { |
| 6174 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6175 | // Baker's read barrier are used: |
| 6176 | // |
| 6177 | // root = obj.field; |
| 6178 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6179 | // root = ReadBarrier::Mark(root) |
| 6180 | // } |
| 6181 | |
| 6182 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6183 | __ movl(root_reg, Address(obj, offset)); |
| 6184 | static_assert( |
| 6185 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6186 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6187 | "have different sizes."); |
| 6188 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6189 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6190 | "have different sizes."); |
| 6191 | |
| 6192 | // Slow path used to mark the GC root `root`. |
| 6193 | SlowPathCode* slow_path = |
| 6194 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64(instruction, root, root); |
| 6195 | codegen_->AddSlowPath(slow_path); |
| 6196 | |
| 6197 | __ gs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86_64WordSize>().Int32Value(), |
| 6198 | /* no_rip */ true), |
| 6199 | Immediate(0)); |
| 6200 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6201 | __ Bind(slow_path->GetExitLabel()); |
| 6202 | } else { |
| 6203 | // GC root loaded through a slow path for read barriers other |
| 6204 | // than Baker's. |
| 6205 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6206 | __ leaq(root_reg, Address(obj, offset)); |
| 6207 | // /* mirror::Object* */ root = root->Read() |
| 6208 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6209 | } |
| 6210 | } else { |
| 6211 | // Plain GC root load with no read barrier. |
| 6212 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6213 | __ movl(root_reg, Address(obj, offset)); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6214 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6215 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6216 | } |
| 6217 | } |
| 6218 | |
| 6219 | void CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6220 | Location ref, |
| 6221 | CpuRegister obj, |
| 6222 | uint32_t offset, |
| 6223 | Location temp, |
| 6224 | bool needs_null_check) { |
| 6225 | DCHECK(kEmitCompilerReadBarrier); |
| 6226 | DCHECK(kUseBakerReadBarrier); |
| 6227 | |
| 6228 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6229 | Address src(obj, offset); |
| 6230 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6231 | } |
| 6232 | |
| 6233 | void CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6234 | Location ref, |
| 6235 | CpuRegister obj, |
| 6236 | uint32_t data_offset, |
| 6237 | Location index, |
| 6238 | Location temp, |
| 6239 | bool needs_null_check) { |
| 6240 | DCHECK(kEmitCompilerReadBarrier); |
| 6241 | DCHECK(kUseBakerReadBarrier); |
| 6242 | |
| 6243 | // /* HeapReference<Object> */ ref = |
| 6244 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6245 | Address src = index.IsConstant() ? |
| 6246 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset) : |
| 6247 | Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset); |
| 6248 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6249 | } |
| 6250 | |
| 6251 | void CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6252 | Location ref, |
| 6253 | CpuRegister obj, |
| 6254 | const Address& src, |
| 6255 | Location temp, |
| 6256 | bool needs_null_check) { |
| 6257 | DCHECK(kEmitCompilerReadBarrier); |
| 6258 | DCHECK(kUseBakerReadBarrier); |
| 6259 | |
| 6260 | // In slow path based read barriers, the read barrier call is |
| 6261 | // inserted after the original load. However, in fast path based |
| 6262 | // Baker's read barriers, we need to perform the load of |
| 6263 | // mirror::Object::monitor_ *before* the original reference load. |
| 6264 | // This load-load ordering is required by the read barrier. |
| 6265 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6266 | // |
| 6267 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6268 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6269 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6270 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6271 | // if (is_gray) { |
| 6272 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6273 | // } |
| 6274 | // |
| 6275 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6276 | // slightly more complex as: |
| 6277 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6278 | // the high-bits of rb_state, which are expected to be all zeroes |
| 6279 | // (we use CodeGeneratorX86_64::GenerateMemoryBarrier instead |
| 6280 | // 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] | 6281 | // - it performs additional checks that we do not do here for |
| 6282 | // performance reasons. |
| 6283 | |
| 6284 | CpuRegister ref_reg = ref.AsRegister<CpuRegister>(); |
| 6285 | CpuRegister temp_reg = temp.AsRegister<CpuRegister>(); |
| 6286 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6287 | |
| 6288 | // /* int32_t */ monitor = obj->monitor_ |
| 6289 | __ movl(temp_reg, Address(obj, monitor_offset)); |
| 6290 | if (needs_null_check) { |
| 6291 | MaybeRecordImplicitNullCheck(instruction); |
| 6292 | } |
| 6293 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6294 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6295 | "art::LockWord and int32_t have different sizes."); |
| 6296 | // /* uint32_t */ rb_state = lock_word.ReadBarrierState() |
| 6297 | __ shrl(temp_reg, Immediate(LockWord::kReadBarrierStateShift)); |
| 6298 | __ andl(temp_reg, Immediate(LockWord::kReadBarrierStateMask)); |
| 6299 | static_assert( |
| 6300 | LockWord::kReadBarrierStateMask == ReadBarrier::rb_ptr_mask_, |
| 6301 | "art::LockWord::kReadBarrierStateMask is not equal to art::ReadBarrier::rb_ptr_mask_."); |
| 6302 | |
| 6303 | // Load fence to prevent load-load reordering. |
| 6304 | // Note that this is a no-op, thanks to the x86-64 memory model. |
| 6305 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6306 | |
| 6307 | // The actual reference load. |
| 6308 | // /* HeapReference<Object> */ ref = *src |
| 6309 | __ movl(ref_reg, src); |
| 6310 | |
| 6311 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6312 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6313 | |
| 6314 | // Slow path used to mark the object `ref` when it is gray. |
| 6315 | SlowPathCode* slow_path = |
| 6316 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64(instruction, ref, ref); |
| 6317 | AddSlowPath(slow_path); |
| 6318 | |
| 6319 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6320 | // ref = ReadBarrier::Mark(ref); |
| 6321 | __ cmpl(temp_reg, Immediate(ReadBarrier::gray_ptr_)); |
| 6322 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6323 | __ Bind(slow_path->GetExitLabel()); |
| 6324 | } |
| 6325 | |
| 6326 | void CodeGeneratorX86_64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6327 | Location out, |
| 6328 | Location ref, |
| 6329 | Location obj, |
| 6330 | uint32_t offset, |
| 6331 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6332 | DCHECK(kEmitCompilerReadBarrier); |
| 6333 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6334 | // Insert a slow path based read barrier *after* the reference load. |
| 6335 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6336 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6337 | // reference will be carried out by the runtime within the slow |
| 6338 | // path. |
| 6339 | // |
| 6340 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6341 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6342 | // not used by the artReadBarrierSlow entry point. |
| 6343 | // |
| 6344 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6345 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6346 | ReadBarrierForHeapReferenceSlowPathX86_64(instruction, out, ref, obj, offset, index); |
| 6347 | AddSlowPath(slow_path); |
| 6348 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6349 | __ jmp(slow_path->GetEntryLabel()); |
| 6350 | __ Bind(slow_path->GetExitLabel()); |
| 6351 | } |
| 6352 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6353 | void CodeGeneratorX86_64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6354 | Location out, |
| 6355 | Location ref, |
| 6356 | Location obj, |
| 6357 | uint32_t offset, |
| 6358 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6359 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6360 | // Baker's read barriers shall be handled by the fast path |
| 6361 | // (CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6362 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6363 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6364 | // by the runtime within the slow path. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6365 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6366 | } else if (kPoisonHeapReferences) { |
| 6367 | __ UnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 6368 | } |
| 6369 | } |
| 6370 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6371 | void CodeGeneratorX86_64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6372 | Location out, |
| 6373 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6374 | DCHECK(kEmitCompilerReadBarrier); |
| 6375 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6376 | // Insert a slow path based read barrier *after* the GC root load. |
| 6377 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6378 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6379 | // not need to do anything special for this here. |
| 6380 | SlowPathCode* slow_path = |
| 6381 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86_64(instruction, out, root); |
| 6382 | AddSlowPath(slow_path); |
| 6383 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6384 | __ jmp(slow_path->GetEntryLabel()); |
| 6385 | __ Bind(slow_path->GetExitLabel()); |
| 6386 | } |
| 6387 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6388 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6389 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6390 | LOG(FATAL) << "Unreachable"; |
| 6391 | } |
| 6392 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6393 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6394 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6395 | LOG(FATAL) << "Unreachable"; |
| 6396 | } |
| 6397 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6398 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6399 | void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6400 | LocationSummary* locations = |
| 6401 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6402 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6403 | locations->AddTemp(Location::RequiresRegister()); |
| 6404 | locations->AddTemp(Location::RequiresRegister()); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6405 | } |
| 6406 | |
| 6407 | void InstructionCodeGeneratorX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6408 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6409 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6410 | LocationSummary* locations = switch_instr->GetLocations(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6411 | CpuRegister value_reg_in = locations->InAt(0).AsRegister<CpuRegister>(); |
| 6412 | CpuRegister temp_reg = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 6413 | CpuRegister base_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6414 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6415 | |
| 6416 | // Should we generate smaller inline compare/jumps? |
| 6417 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 6418 | // Figure out the correct compare values and jump conditions. |
| 6419 | // Handle the first compare/branch as a special case because it might |
| 6420 | // jump to the default case. |
| 6421 | DCHECK_GT(num_entries, 2u); |
| 6422 | Condition first_condition; |
| 6423 | uint32_t index; |
| 6424 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 6425 | if (lower_bound != 0) { |
| 6426 | first_condition = kLess; |
| 6427 | __ cmpl(value_reg_in, Immediate(lower_bound)); |
| 6428 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 6429 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
| 6430 | |
| 6431 | index = 1; |
| 6432 | } else { |
| 6433 | // Handle all the compare/jumps below. |
| 6434 | first_condition = kBelow; |
| 6435 | index = 0; |
| 6436 | } |
| 6437 | |
| 6438 | // Handle the rest of the compare/jumps. |
| 6439 | for (; index + 1 < num_entries; index += 2) { |
| 6440 | int32_t compare_to_value = lower_bound + index + 1; |
| 6441 | __ cmpl(value_reg_in, Immediate(compare_to_value)); |
| 6442 | // Jump to successors[index] if value < case_value[index]. |
| 6443 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 6444 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 6445 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 6446 | } |
| 6447 | |
| 6448 | if (index != num_entries) { |
| 6449 | // There are an odd number of entries. Handle the last one. |
| 6450 | DCHECK_EQ(index + 1, num_entries); |
Nicolas Geoffray | 6ce0173 | 2015-12-30 14:10:13 +0000 | [diff] [blame] | 6451 | __ cmpl(value_reg_in, Immediate(static_cast<int32_t>(lower_bound + index))); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6452 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
| 6453 | } |
| 6454 | |
| 6455 | // And the default for any other value. |
| 6456 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6457 | __ jmp(codegen_->GetLabelOf(default_block)); |
| 6458 | } |
| 6459 | return; |
| 6460 | } |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6461 | |
| 6462 | // Remove the bias, if needed. |
| 6463 | Register value_reg_out = value_reg_in.AsRegister(); |
| 6464 | if (lower_bound != 0) { |
| 6465 | __ leal(temp_reg, Address(value_reg_in, -lower_bound)); |
| 6466 | value_reg_out = temp_reg.AsRegister(); |
| 6467 | } |
| 6468 | CpuRegister value_reg(value_reg_out); |
| 6469 | |
| 6470 | // Is the value in range? |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6471 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 6472 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6473 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6474 | // We are in the range of the table. |
| 6475 | // Load the address of the jump table in the constant area. |
| 6476 | __ leaq(base_reg, codegen_->LiteralCaseTable(switch_instr)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6477 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6478 | // Load the (signed) offset from the jump table. |
| 6479 | __ movsxd(temp_reg, Address(base_reg, value_reg, TIMES_4, 0)); |
| 6480 | |
| 6481 | // Add the offset to the address of the table base. |
| 6482 | __ addq(temp_reg, base_reg); |
| 6483 | |
| 6484 | // And jump. |
| 6485 | __ jmp(temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6486 | } |
| 6487 | |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6488 | void CodeGeneratorX86_64::Load32BitValue(CpuRegister dest, int32_t value) { |
| 6489 | if (value == 0) { |
| 6490 | __ xorl(dest, dest); |
| 6491 | } else { |
| 6492 | __ movl(dest, Immediate(value)); |
| 6493 | } |
| 6494 | } |
| 6495 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6496 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 6497 | if (value == 0) { |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6498 | // Clears upper bits too. |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6499 | __ xorl(dest, dest); |
Vladimir Marko | ed00978 | 2016-02-22 16:54:39 +0000 | [diff] [blame] | 6500 | } else if (IsUint<32>(value)) { |
| 6501 | // 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] | 6502 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 6503 | } else { |
| 6504 | __ movq(dest, Immediate(value)); |
| 6505 | } |
| 6506 | } |
| 6507 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 6508 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, int32_t value) { |
| 6509 | if (value == 0) { |
| 6510 | __ xorps(dest, dest); |
| 6511 | } else { |
| 6512 | __ movss(dest, LiteralInt32Address(value)); |
| 6513 | } |
| 6514 | } |
| 6515 | |
| 6516 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, int64_t value) { |
| 6517 | if (value == 0) { |
| 6518 | __ xorpd(dest, dest); |
| 6519 | } else { |
| 6520 | __ movsd(dest, LiteralInt64Address(value)); |
| 6521 | } |
| 6522 | } |
| 6523 | |
| 6524 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, float value) { |
| 6525 | Load32BitValue(dest, bit_cast<int32_t, float>(value)); |
| 6526 | } |
| 6527 | |
| 6528 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, double value) { |
| 6529 | Load64BitValue(dest, bit_cast<int64_t, double>(value)); |
| 6530 | } |
| 6531 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 6532 | void CodeGeneratorX86_64::Compare32BitValue(CpuRegister dest, int32_t value) { |
| 6533 | if (value == 0) { |
| 6534 | __ testl(dest, dest); |
| 6535 | } else { |
| 6536 | __ cmpl(dest, Immediate(value)); |
| 6537 | } |
| 6538 | } |
| 6539 | |
| 6540 | void CodeGeneratorX86_64::Compare64BitValue(CpuRegister dest, int64_t value) { |
| 6541 | if (IsInt<32>(value)) { |
| 6542 | if (value == 0) { |
| 6543 | __ testq(dest, dest); |
| 6544 | } else { |
| 6545 | __ cmpq(dest, Immediate(static_cast<int32_t>(value))); |
| 6546 | } |
| 6547 | } else { |
| 6548 | // Value won't fit in an int. |
| 6549 | __ cmpq(dest, LiteralInt64Address(value)); |
| 6550 | } |
| 6551 | } |
| 6552 | |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 6553 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 6554 | DCHECK(dest.IsDoubleStackSlot()); |
| 6555 | if (IsInt<32>(value)) { |
| 6556 | // Can move directly as an int32 constant. |
| 6557 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 6558 | Immediate(static_cast<int32_t>(value))); |
| 6559 | } else { |
| 6560 | Load64BitValue(CpuRegister(TMP), value); |
| 6561 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 6562 | } |
| 6563 | } |
| 6564 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6565 | /** |
| 6566 | * Class to handle late fixup of offsets into constant area. |
| 6567 | */ |
| 6568 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| 6569 | public: |
| 6570 | RIPFixup(CodeGeneratorX86_64& codegen, size_t offset) |
| 6571 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 6572 | |
| 6573 | protected: |
| 6574 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 6575 | |
| 6576 | CodeGeneratorX86_64* codegen_; |
| 6577 | |
| 6578 | private: |
| 6579 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 6580 | // Patch the correct offset for the instruction. We use the address of the |
| 6581 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 6582 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 6583 | int32_t relative_position = constant_offset - pos; |
| 6584 | |
| 6585 | // Patch in the right value. |
| 6586 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 6587 | } |
| 6588 | |
| 6589 | // Location in constant area that the fixup refers to. |
| 6590 | size_t offset_into_constant_area_; |
| 6591 | }; |
| 6592 | |
| 6593 | /** |
| 6594 | t * Class to handle late fixup of offsets to a jump table that will be created in the |
| 6595 | * constant area. |
| 6596 | */ |
| 6597 | class JumpTableRIPFixup : public RIPFixup { |
| 6598 | public: |
| 6599 | JumpTableRIPFixup(CodeGeneratorX86_64& codegen, HPackedSwitch* switch_instr) |
| 6600 | : RIPFixup(codegen, -1), switch_instr_(switch_instr) {} |
| 6601 | |
| 6602 | void CreateJumpTable() { |
| 6603 | X86_64Assembler* assembler = codegen_->GetAssembler(); |
| 6604 | |
| 6605 | // Ensure that the reference to the jump table has the correct offset. |
| 6606 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 6607 | SetOffset(offset_in_constant_table); |
| 6608 | |
| 6609 | // Compute the offset from the start of the function to this jump table. |
| 6610 | const int32_t current_table_offset = assembler->CodeSize() + offset_in_constant_table; |
| 6611 | |
| 6612 | // Populate the jump table with the correct values for the jump table. |
| 6613 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 6614 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 6615 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 6616 | // The value that we want is the target offset - the position of the table. |
| 6617 | for (int32_t i = 0; i < num_entries; i++) { |
| 6618 | HBasicBlock* b = successors[i]; |
| 6619 | Label* l = codegen_->GetLabelOf(b); |
| 6620 | DCHECK(l->IsBound()); |
| 6621 | int32_t offset_to_block = l->Position() - current_table_offset; |
| 6622 | assembler->AppendInt32(offset_to_block); |
| 6623 | } |
| 6624 | } |
| 6625 | |
| 6626 | private: |
| 6627 | const HPackedSwitch* switch_instr_; |
| 6628 | }; |
| 6629 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6630 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 6631 | // Generate the constant area if needed. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 6632 | X86_64Assembler* assembler = GetAssembler(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6633 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 6634 | // 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] | 6635 | assembler->Align(4, 0); |
| 6636 | constant_area_start_ = assembler->CodeSize(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6637 | |
| 6638 | // Populate any jump tables. |
| 6639 | for (auto jump_table : fixups_to_jump_tables_) { |
| 6640 | jump_table->CreateJumpTable(); |
| 6641 | } |
| 6642 | |
| 6643 | // And now add the constant area to the generated code. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 6644 | assembler->AddConstantArea(); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6645 | } |
| 6646 | |
| 6647 | // And finish up. |
| 6648 | CodeGenerator::Finalize(allocator); |
| 6649 | } |
| 6650 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6651 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
| 6652 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 6653 | return Address::RIP(fixup); |
| 6654 | } |
| 6655 | |
| 6656 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
| 6657 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 6658 | return Address::RIP(fixup); |
| 6659 | } |
| 6660 | |
| 6661 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
| 6662 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 6663 | return Address::RIP(fixup); |
| 6664 | } |
| 6665 | |
| 6666 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
| 6667 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 6668 | return Address::RIP(fixup); |
| 6669 | } |
| 6670 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6671 | // TODO: trg as memory. |
| 6672 | void CodeGeneratorX86_64::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 6673 | if (!trg.IsValid()) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6674 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6675 | return; |
| 6676 | } |
| 6677 | |
| 6678 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 6679 | |
| 6680 | Location return_loc = InvokeDexCallingConventionVisitorX86_64().GetReturnLocation(type); |
| 6681 | if (trg.Equals(return_loc)) { |
| 6682 | return; |
| 6683 | } |
| 6684 | |
| 6685 | // Let the parallel move resolver take care of all of this. |
| 6686 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 6687 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 6688 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 6689 | } |
| 6690 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6691 | Address CodeGeneratorX86_64::LiteralCaseTable(HPackedSwitch* switch_instr) { |
| 6692 | // Create a fixup to be used to create and address the jump table. |
| 6693 | JumpTableRIPFixup* table_fixup = |
| 6694 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 6695 | |
| 6696 | // We have to populate the jump tables. |
| 6697 | fixups_to_jump_tables_.push_back(table_fixup); |
| 6698 | return Address::RIP(table_fixup); |
| 6699 | } |
| 6700 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 6701 | void CodeGeneratorX86_64::MoveInt64ToAddress(const Address& addr_low, |
| 6702 | const Address& addr_high, |
| 6703 | int64_t v, |
| 6704 | HInstruction* instruction) { |
| 6705 | if (IsInt<32>(v)) { |
| 6706 | int32_t v_32 = v; |
| 6707 | __ movq(addr_low, Immediate(v_32)); |
| 6708 | MaybeRecordImplicitNullCheck(instruction); |
| 6709 | } else { |
| 6710 | // Didn't fit in a register. Do it in pieces. |
| 6711 | int32_t low_v = Low32Bits(v); |
| 6712 | int32_t high_v = High32Bits(v); |
| 6713 | __ movl(addr_low, Immediate(low_v)); |
| 6714 | MaybeRecordImplicitNullCheck(instruction); |
| 6715 | __ movl(addr_high, Immediate(high_v)); |
| 6716 | } |
| 6717 | } |
| 6718 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6719 | #undef __ |
| 6720 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 6721 | } // namespace x86_64 |
| 6722 | } // namespace art |