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; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 787 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 788 | __ movq(temp.AsRegister<CpuRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 789 | Address::Absolute(kDummy32BitOffset, /* no_rip */ false)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 790 | // Bind a new fixup label at the end of the "movl" insn. |
| 791 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
| 792 | __ Bind(NewPcRelativeDexCacheArrayPatch(*invoke->GetTargetMethod().dex_file, offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 793 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 794 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 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 | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 811 | // temp = temp[index_in_cache]; |
| 812 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 813 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 814 | __ movq(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 815 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 816 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | switch (invoke->GetCodePtrLocation()) { |
| 820 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 821 | __ call(&frame_entry_label_); |
| 822 | break; |
| 823 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 824 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 825 | Label* label = &relative_call_patches_.back().label; |
| 826 | __ call(label); // Bind to the patch label, override at link time. |
| 827 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 828 | break; |
| 829 | } |
| 830 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 831 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 832 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 833 | LOG(FATAL) << "Unsupported"; |
| 834 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 835 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 836 | // (callee_method + offset_of_quick_compiled_code)() |
| 837 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 838 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 839 | kX86_64WordSize).SizeValue())); |
| 840 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 841 | } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 842 | |
| 843 | DCHECK(!IsLeafMethod()); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 844 | } |
| 845 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 846 | void CodeGeneratorX86_64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 847 | CpuRegister temp = temp_in.AsRegister<CpuRegister>(); |
| 848 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 849 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 850 | |
| 851 | // Use the calling convention instead of the location of the receiver, as |
| 852 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 853 | // slow path, the arguments have been moved to the right place, so here we are |
| 854 | // guaranteed that the receiver is the first register of the calling convention. |
| 855 | InvokeDexCallingConvention calling_convention; |
| 856 | Register receiver = calling_convention.GetRegisterAt(0); |
| 857 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 858 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 859 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 860 | __ movl(temp, Address(CpuRegister(receiver), class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 861 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 862 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 863 | // emit a read barrier for the previous class reference load. |
| 864 | // However this is not required in practice, as this is an |
| 865 | // intermediate/temporary reference and because the current |
| 866 | // concurrent copying collector keeps the from-space memory |
| 867 | // intact/accessible until the end of the marking phase (the |
| 868 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 869 | __ MaybeUnpoisonHeapReference(temp); |
| 870 | // temp = temp->GetMethodAt(method_offset); |
| 871 | __ movq(temp, Address(temp, method_offset)); |
| 872 | // call temp->GetEntryPoint(); |
| 873 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 874 | kX86_64WordSize).SizeValue())); |
| 875 | } |
| 876 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 877 | void CodeGeneratorX86_64::RecordSimplePatch() { |
| 878 | if (GetCompilerOptions().GetIncludePatchInformation()) { |
| 879 | simple_patches_.emplace_back(); |
| 880 | __ Bind(&simple_patches_.back()); |
| 881 | } |
| 882 | } |
| 883 | |
| 884 | void CodeGeneratorX86_64::RecordStringPatch(HLoadString* load_string) { |
| 885 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex()); |
| 886 | __ Bind(&string_patches_.back().label); |
| 887 | } |
| 888 | |
| 889 | Label* CodeGeneratorX86_64::NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, |
| 890 | uint32_t element_offset) { |
| 891 | // Add a patch entry and return the label. |
| 892 | pc_relative_dex_cache_patches_.emplace_back(dex_file, element_offset); |
| 893 | return &pc_relative_dex_cache_patches_.back().label; |
| 894 | } |
| 895 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 896 | void CodeGeneratorX86_64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 897 | DCHECK(linker_patches->empty()); |
| 898 | size_t size = |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 899 | method_patches_.size() + |
| 900 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 901 | pc_relative_dex_cache_patches_.size() + |
| 902 | simple_patches_.size() + |
| 903 | string_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 904 | linker_patches->reserve(size); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 905 | // The label points to the end of the "movl" insn but the literal offset for method |
| 906 | // patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 907 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 908 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 909 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 910 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 911 | info.target_method.dex_file, |
| 912 | info.target_method.dex_method_index)); |
| 913 | } |
| 914 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 915 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 916 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 917 | info.target_method.dex_file, |
| 918 | info.target_method.dex_method_index)); |
| 919 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 920 | for (const PcRelativeDexCacheAccessInfo& info : pc_relative_dex_cache_patches_) { |
| 921 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 922 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 923 | &info.target_dex_file, |
| 924 | info.label.Position(), |
| 925 | info.element_offset)); |
| 926 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 927 | for (const Label& label : simple_patches_) { |
| 928 | uint32_t literal_offset = label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 929 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 930 | } |
| 931 | for (const StringPatchInfo<Label>& info : string_patches_) { |
| 932 | // These are always PC-relative, see GetSupportedLoadStringKind(). |
| 933 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 934 | linker_patches->push_back(LinkerPatch::RelativeStringPatch(literal_offset, |
| 935 | &info.dex_file, |
| 936 | info.label.Position(), |
| 937 | info.string_index)); |
| 938 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 939 | } |
| 940 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 941 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 942 | stream << Register(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 946 | stream << FloatRegister(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 947 | } |
| 948 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 949 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 950 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 951 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 952 | } |
| 953 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 954 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 955 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 956 | return kX86_64WordSize; |
| 957 | } |
| 958 | |
| 959 | size_t CodeGeneratorX86_64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 960 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 961 | return kX86_64WordSize; |
| 962 | } |
| 963 | |
| 964 | size_t CodeGeneratorX86_64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 965 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 966 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 967 | } |
| 968 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 969 | void CodeGeneratorX86_64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 970 | HInstruction* instruction, |
| 971 | uint32_t dex_pc, |
| 972 | SlowPathCode* slow_path) { |
| 973 | InvokeRuntime(GetThreadOffset<kX86_64WordSize>(entrypoint).Int32Value(), |
| 974 | instruction, |
| 975 | dex_pc, |
| 976 | slow_path); |
| 977 | } |
| 978 | |
| 979 | void CodeGeneratorX86_64::InvokeRuntime(int32_t entry_point_offset, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 980 | HInstruction* instruction, |
| 981 | uint32_t dex_pc, |
| 982 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 983 | ValidateInvokeRuntime(instruction, slow_path); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 984 | __ gs()->call(Address::Absolute(entry_point_offset, /* no_rip */ true)); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 985 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 986 | } |
| 987 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 988 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 989 | // Use a fake return address register to mimic Quick. |
| 990 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 991 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 992 | const X86_64InstructionSetFeatures& isa_features, |
| 993 | const CompilerOptions& compiler_options, |
| 994 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 995 | : CodeGenerator(graph, |
| 996 | kNumberOfCpuRegisters, |
| 997 | kNumberOfFloatRegisters, |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 998 | kNumberOfCpuRegisterPairs, |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 999 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1000 | arraysize(kCoreCalleeSaves)) |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1001 | | (1 << kFakeReturnRegister), |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1002 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1003 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1004 | compiler_options, |
| 1005 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1006 | block_labels_(nullptr), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1007 | location_builder_(graph, this), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1008 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1009 | move_resolver_(graph->GetArena(), this), |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 1010 | isa_features_(isa_features), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1011 | constant_area_start_(0), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 1012 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1013 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1014 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1015 | simple_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1016 | string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 1017 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1018 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 1019 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1020 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1021 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 1022 | CodeGeneratorX86_64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1023 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1024 | assembler_(codegen->GetAssembler()), |
| 1025 | codegen_(codegen) {} |
| 1026 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1027 | void CodeGeneratorX86_64::SetupBlockedRegisters() const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1028 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1029 | blocked_core_registers_[RSP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1030 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1031 | // Block the register used as TMP. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1032 | blocked_core_registers_[TMP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1033 | } |
| 1034 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1035 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1036 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1037 | } |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1038 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1039 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1040 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1041 | } |
| 1042 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1043 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1044 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1045 | __ Bind(&frame_entry_label_); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1046 | bool skip_overflow_check = IsLeafMethod() |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 1047 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1048 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1049 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1050 | if (!skip_overflow_check) { |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1051 | __ testq(CpuRegister(RAX), Address( |
| 1052 | CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1053 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1054 | } |
Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 1055 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1056 | if (HasEmptyFrame()) { |
| 1057 | return; |
| 1058 | } |
| 1059 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1060 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1061 | Register reg = kCoreCalleeSaves[i]; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1062 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1063 | __ pushq(CpuRegister(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1064 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 1065 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1066 | } |
| 1067 | } |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1068 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1069 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1070 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 1071 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1072 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1073 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1074 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1075 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1076 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1077 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1078 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 1079 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1080 | } |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1081 | } |
| 1082 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1083 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1084 | CpuRegister(kMethodRegisterArgument)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | void CodeGeneratorX86_64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1088 | __ cfi().RememberState(); |
| 1089 | if (!HasEmptyFrame()) { |
| 1090 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1091 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| 1092 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1093 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 1094 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1095 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 1096 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 1097 | } |
| 1098 | } |
| 1099 | |
| 1100 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1101 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 1102 | __ cfi().AdjustCFAOffset(-adjust); |
| 1103 | |
| 1104 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1105 | Register reg = kCoreCalleeSaves[i]; |
| 1106 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1107 | __ popq(CpuRegister(reg)); |
| 1108 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 1109 | __ cfi().Restore(DWARFReg(reg)); |
| 1110 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1111 | } |
| 1112 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1113 | __ ret(); |
| 1114 | __ cfi().RestoreState(); |
| 1115 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1116 | } |
| 1117 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1118 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 1119 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1120 | } |
| 1121 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1122 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 1123 | if (source.Equals(destination)) { |
| 1124 | return; |
| 1125 | } |
| 1126 | if (destination.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1127 | CpuRegister dest = destination.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1128 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1129 | __ movq(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1130 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1131 | __ movd(dest, source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1132 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1133 | __ movl(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1134 | } else if (source.IsConstant()) { |
| 1135 | HConstant* constant = source.GetConstant(); |
| 1136 | if (constant->IsLongConstant()) { |
| 1137 | Load64BitValue(dest, constant->AsLongConstant()->GetValue()); |
| 1138 | } else { |
| 1139 | Load32BitValue(dest, GetInt32ValueOf(constant)); |
| 1140 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1141 | } else { |
| 1142 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1143 | __ movq(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1144 | } |
| 1145 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1146 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1147 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1148 | __ movd(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1149 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1150 | __ movaps(dest, source.AsFpuRegister<XmmRegister>()); |
| 1151 | } else if (source.IsConstant()) { |
| 1152 | HConstant* constant = source.GetConstant(); |
| 1153 | int64_t value = CodeGenerator::GetInt64ValueOf(constant); |
| 1154 | if (constant->IsFloatConstant()) { |
| 1155 | Load32BitValue(dest, static_cast<int32_t>(value)); |
| 1156 | } else { |
| 1157 | Load64BitValue(dest, value); |
| 1158 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1159 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1160 | __ movss(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1161 | } else { |
| 1162 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1163 | __ movsd(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1164 | } |
| 1165 | } else if (destination.IsStackSlot()) { |
| 1166 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1167 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1168 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1169 | } else if (source.IsFpuRegister()) { |
| 1170 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1171 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1172 | } else if (source.IsConstant()) { |
| 1173 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1174 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1175 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1176 | } else { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1177 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1178 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1179 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1180 | } |
| 1181 | } else { |
| 1182 | DCHECK(destination.IsDoubleStackSlot()); |
| 1183 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1184 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1185 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1186 | } else if (source.IsFpuRegister()) { |
| 1187 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1188 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1189 | } else if (source.IsConstant()) { |
| 1190 | HConstant* constant = source.GetConstant(); |
Zheng Xu | 12bca97 | 2015-03-30 19:35:50 +0800 | [diff] [blame] | 1191 | int64_t value; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1192 | if (constant->IsDoubleConstant()) { |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 1193 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1194 | } else { |
| 1195 | DCHECK(constant->IsLongConstant()); |
| 1196 | value = constant->AsLongConstant()->GetValue(); |
| 1197 | } |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 1198 | Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1199 | } else { |
| 1200 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1201 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1202 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1203 | } |
| 1204 | } |
| 1205 | } |
| 1206 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1207 | void CodeGeneratorX86_64::MoveConstant(Location location, int32_t value) { |
| 1208 | DCHECK(location.IsRegister()); |
| 1209 | Load64BitValue(location.AsRegister<CpuRegister>(), static_cast<int64_t>(value)); |
| 1210 | } |
| 1211 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1212 | void CodeGeneratorX86_64::MoveLocation( |
| 1213 | Location dst, Location src, Primitive::Type dst_type ATTRIBUTE_UNUSED) { |
| 1214 | Move(dst, src); |
| 1215 | } |
| 1216 | |
| 1217 | void CodeGeneratorX86_64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1218 | if (location.IsRegister()) { |
| 1219 | locations->AddTemp(location); |
| 1220 | } else { |
| 1221 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1222 | } |
| 1223 | } |
| 1224 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1225 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1226 | DCHECK(!successor->IsExitBlock()); |
| 1227 | |
| 1228 | HBasicBlock* block = got->GetBlock(); |
| 1229 | HInstruction* previous = got->GetPrevious(); |
| 1230 | |
| 1231 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1232 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1233 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1234 | return; |
| 1235 | } |
| 1236 | |
| 1237 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1238 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1239 | } |
| 1240 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1241 | __ jmp(codegen_->GetLabelOf(successor)); |
| 1242 | } |
| 1243 | } |
| 1244 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1245 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 1246 | got->SetLocations(nullptr); |
| 1247 | } |
| 1248 | |
| 1249 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 1250 | HandleGoto(got, got->GetSuccessor()); |
| 1251 | } |
| 1252 | |
| 1253 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1254 | try_boundary->SetLocations(nullptr); |
| 1255 | } |
| 1256 | |
| 1257 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1258 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1259 | if (!successor->IsExitBlock()) { |
| 1260 | HandleGoto(try_boundary, successor); |
| 1261 | } |
| 1262 | } |
| 1263 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1264 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 1265 | exit->SetLocations(nullptr); |
| 1266 | } |
| 1267 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1268 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1269 | } |
| 1270 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1271 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1272 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1273 | LabelType* true_label, |
| 1274 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1275 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1276 | __ j(kUnordered, true_label); |
| 1277 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1278 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1279 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1280 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1281 | } |
| 1282 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1283 | void InstructionCodeGeneratorX86_64::GenerateCompareTest(HCondition* condition) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1284 | LocationSummary* locations = condition->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1285 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1286 | Location left = locations->InAt(0); |
| 1287 | Location right = locations->InAt(1); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1288 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1289 | switch (type) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1290 | case Primitive::kPrimBoolean: |
| 1291 | case Primitive::kPrimByte: |
| 1292 | case Primitive::kPrimChar: |
| 1293 | case Primitive::kPrimShort: |
| 1294 | case Primitive::kPrimInt: |
| 1295 | case Primitive::kPrimNot: { |
| 1296 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1297 | if (right.IsConstant()) { |
| 1298 | int32_t value = CodeGenerator::GetInt32ValueOf(right.GetConstant()); |
| 1299 | if (value == 0) { |
| 1300 | __ testl(left_reg, left_reg); |
| 1301 | } else { |
| 1302 | __ cmpl(left_reg, Immediate(value)); |
| 1303 | } |
| 1304 | } else if (right.IsStackSlot()) { |
| 1305 | __ cmpl(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1306 | } else { |
| 1307 | __ cmpl(left_reg, right.AsRegister<CpuRegister>()); |
| 1308 | } |
| 1309 | break; |
| 1310 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1311 | case Primitive::kPrimLong: { |
| 1312 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1313 | if (right.IsConstant()) { |
| 1314 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1315 | codegen_->Compare64BitValue(left_reg, value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1316 | } else if (right.IsDoubleStackSlot()) { |
| 1317 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1318 | } else { |
| 1319 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1320 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1321 | break; |
| 1322 | } |
| 1323 | case Primitive::kPrimFloat: { |
| 1324 | if (right.IsFpuRegister()) { |
| 1325 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1326 | } else if (right.IsConstant()) { |
| 1327 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1328 | codegen_->LiteralFloatAddress( |
| 1329 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1330 | } else { |
| 1331 | DCHECK(right.IsStackSlot()); |
| 1332 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1333 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1334 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1335 | break; |
| 1336 | } |
| 1337 | case Primitive::kPrimDouble: { |
| 1338 | if (right.IsFpuRegister()) { |
| 1339 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1340 | } else if (right.IsConstant()) { |
| 1341 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1342 | codegen_->LiteralDoubleAddress( |
| 1343 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1344 | } else { |
| 1345 | DCHECK(right.IsDoubleStackSlot()); |
| 1346 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1347 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1348 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1349 | break; |
| 1350 | } |
| 1351 | default: |
| 1352 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1353 | } |
| 1354 | } |
| 1355 | |
| 1356 | template<class LabelType> |
| 1357 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HCondition* condition, |
| 1358 | LabelType* true_target_in, |
| 1359 | LabelType* false_target_in) { |
| 1360 | // Generated branching requires both targets to be explicit. If either of the |
| 1361 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1362 | LabelType fallthrough_target; |
| 1363 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1364 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1365 | |
| 1366 | // Generate the comparison to set the CC. |
| 1367 | GenerateCompareTest(condition); |
| 1368 | |
| 1369 | // Now generate the correct jump(s). |
| 1370 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1371 | switch (type) { |
| 1372 | case Primitive::kPrimLong: { |
| 1373 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
| 1374 | break; |
| 1375 | } |
| 1376 | case Primitive::kPrimFloat: { |
| 1377 | GenerateFPJumps(condition, true_target, false_target); |
| 1378 | break; |
| 1379 | } |
| 1380 | case Primitive::kPrimDouble: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1381 | GenerateFPJumps(condition, true_target, false_target); |
| 1382 | break; |
| 1383 | } |
| 1384 | default: |
| 1385 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1386 | } |
| 1387 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1388 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1389 | __ jmp(false_target); |
| 1390 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1391 | |
| 1392 | if (fallthrough_target.IsLinked()) { |
| 1393 | __ Bind(&fallthrough_target); |
| 1394 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1395 | } |
| 1396 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1397 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1398 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1399 | // are set only strictly before `branch`. We can't use the eflags on long |
| 1400 | // conditions if they are materialized due to the complex branching. |
| 1401 | return cond->IsCondition() && |
| 1402 | cond->GetNext() == branch && |
| 1403 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1404 | } |
| 1405 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1406 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1407 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1408 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1409 | LabelType* true_target, |
| 1410 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1411 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1412 | |
| 1413 | if (true_target == nullptr && false_target == nullptr) { |
| 1414 | // Nothing to do. The code always falls through. |
| 1415 | return; |
| 1416 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1417 | // Constant condition, statically compared against "true" (integer value 1). |
| 1418 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1419 | if (true_target != nullptr) { |
| 1420 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1421 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1422 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1423 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1424 | if (false_target != nullptr) { |
| 1425 | __ jmp(false_target); |
| 1426 | } |
| 1427 | } |
| 1428 | return; |
| 1429 | } |
| 1430 | |
| 1431 | // The following code generates these patterns: |
| 1432 | // (1) true_target == nullptr && false_target != nullptr |
| 1433 | // - opposite condition true => branch to false_target |
| 1434 | // (2) true_target != nullptr && false_target == nullptr |
| 1435 | // - condition true => branch to true_target |
| 1436 | // (3) true_target != nullptr && false_target != nullptr |
| 1437 | // - condition true => branch to true_target |
| 1438 | // - branch to false_target |
| 1439 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1440 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1441 | if (true_target == nullptr) { |
| 1442 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1443 | } else { |
| 1444 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
| 1445 | } |
| 1446 | } else { |
| 1447 | // Materialized condition, compare against 0. |
| 1448 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1449 | if (lhs.IsRegister()) { |
| 1450 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1451 | } else { |
| 1452 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), Immediate(0)); |
| 1453 | } |
| 1454 | if (true_target == nullptr) { |
| 1455 | __ j(kEqual, false_target); |
| 1456 | } else { |
| 1457 | __ j(kNotEqual, true_target); |
| 1458 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1459 | } |
| 1460 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1461 | // Condition has not been materialized, use its inputs as the |
| 1462 | // comparison and its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1463 | HCondition* condition = cond->AsCondition(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1464 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1465 | // If this is a long or FP comparison that has been folded into |
| 1466 | // the HCondition, generate the comparison directly. |
| 1467 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1468 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1469 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1470 | return; |
| 1471 | } |
| 1472 | |
| 1473 | Location lhs = condition->GetLocations()->InAt(0); |
| 1474 | Location rhs = condition->GetLocations()->InAt(1); |
| 1475 | if (rhs.IsRegister()) { |
| 1476 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1477 | } else if (rhs.IsConstant()) { |
| 1478 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1479 | codegen_->Compare32BitValue(lhs.AsRegister<CpuRegister>(), constant); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1480 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1481 | __ cmpl(lhs.AsRegister<CpuRegister>(), |
| 1482 | Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1483 | } |
| 1484 | if (true_target == nullptr) { |
| 1485 | __ j(X86_64IntegerCondition(condition->GetOppositeCondition()), false_target); |
| 1486 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1487 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1488 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1489 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1490 | |
| 1491 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1492 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1493 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1494 | __ jmp(false_target); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1495 | } |
| 1496 | } |
| 1497 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1498 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1499 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1500 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1501 | locations->SetInAt(0, Location::Any()); |
| 1502 | } |
| 1503 | } |
| 1504 | |
| 1505 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1506 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1507 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1508 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1509 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1510 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1511 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1512 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1513 | } |
| 1514 | |
| 1515 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1516 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1517 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1518 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1519 | locations->SetInAt(0, Location::Any()); |
| 1520 | } |
| 1521 | } |
| 1522 | |
| 1523 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1524 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86_64>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1525 | GenerateTestAndBranch<Label>(deoptimize, |
| 1526 | /* condition_input_index */ 0, |
| 1527 | slow_path->GetEntryLabel(), |
| 1528 | /* false_target */ nullptr); |
| 1529 | } |
| 1530 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1531 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1532 | // There are no conditional move instructions for XMMs. |
| 1533 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1534 | return false; |
| 1535 | } |
| 1536 | |
| 1537 | // A FP condition doesn't generate the single CC that we need. |
| 1538 | HInstruction* condition = select->GetCondition(); |
| 1539 | if (condition->IsCondition() && |
| 1540 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())) { |
| 1541 | return false; |
| 1542 | } |
| 1543 | |
| 1544 | // We can generate a CMOV for this Select. |
| 1545 | return true; |
| 1546 | } |
| 1547 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1548 | void LocationsBuilderX86_64::VisitSelect(HSelect* select) { |
| 1549 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 1550 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1551 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1552 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1553 | } else { |
| 1554 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1555 | if (SelectCanUseCMOV(select)) { |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1556 | if (select->InputAt(1)->IsConstant()) { |
| 1557 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1558 | } else { |
| 1559 | locations->SetInAt(1, Location::Any()); |
| 1560 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1561 | } else { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1562 | locations->SetInAt(1, Location::Any()); |
| 1563 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1564 | } |
| 1565 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1566 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1567 | } |
| 1568 | locations->SetOut(Location::SameAsFirstInput()); |
| 1569 | } |
| 1570 | |
| 1571 | void InstructionCodeGeneratorX86_64::VisitSelect(HSelect* select) { |
| 1572 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1573 | if (SelectCanUseCMOV(select)) { |
| 1574 | // If both the condition and the source types are integer, we can generate |
| 1575 | // a CMOV to implement Select. |
| 1576 | CpuRegister value_false = locations->InAt(0).AsRegister<CpuRegister>(); |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1577 | Location value_true_loc = locations->InAt(1); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1578 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1579 | |
| 1580 | HInstruction* select_condition = select->GetCondition(); |
| 1581 | Condition cond = kNotEqual; |
| 1582 | |
| 1583 | // Figure out how to test the 'condition'. |
| 1584 | if (select_condition->IsCondition()) { |
| 1585 | HCondition* condition = select_condition->AsCondition(); |
| 1586 | if (!condition->IsEmittedAtUseSite()) { |
| 1587 | // This was a previously materialized condition. |
| 1588 | // Can we use the existing condition code? |
| 1589 | if (AreEflagsSetFrom(condition, select)) { |
| 1590 | // Materialization was the previous instruction. Condition codes are right. |
| 1591 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1592 | } else { |
| 1593 | // No, we have to recreate the condition code. |
| 1594 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1595 | __ testl(cond_reg, cond_reg); |
| 1596 | } |
| 1597 | } else { |
| 1598 | GenerateCompareTest(condition); |
| 1599 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1600 | } |
| 1601 | } else { |
| 1602 | // Must be a boolean condition, which needs to be compared to 0. |
| 1603 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1604 | __ testl(cond_reg, cond_reg); |
| 1605 | } |
| 1606 | |
| 1607 | // If the condition is true, overwrite the output, which already contains false. |
| 1608 | // Generate the correct sized CMOV. |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1609 | bool is_64_bit = Primitive::Is64BitType(select->GetType()); |
| 1610 | if (value_true_loc.IsRegister()) { |
| 1611 | __ cmov(cond, value_false, value_true_loc.AsRegister<CpuRegister>(), is_64_bit); |
| 1612 | } else { |
| 1613 | __ cmov(cond, |
| 1614 | value_false, |
| 1615 | Address(CpuRegister(RSP), value_true_loc.GetStackIndex()), is_64_bit); |
| 1616 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1617 | } else { |
| 1618 | NearLabel false_target; |
| 1619 | GenerateTestAndBranch<NearLabel>(select, |
| 1620 | /* condition_input_index */ 2, |
| 1621 | /* true_target */ nullptr, |
| 1622 | &false_target); |
| 1623 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1624 | __ Bind(&false_target); |
| 1625 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1626 | } |
| 1627 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1628 | void LocationsBuilderX86_64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1629 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1630 | } |
| 1631 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1632 | void InstructionCodeGeneratorX86_64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1633 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1634 | } |
| 1635 | |
| 1636 | void CodeGeneratorX86_64::GenerateNop() { |
| 1637 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1638 | } |
| 1639 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1640 | void LocationsBuilderX86_64::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1641 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1642 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1643 | // Handle the long/FP comparisons made in instruction simplification. |
| 1644 | switch (cond->InputAt(0)->GetType()) { |
| 1645 | case Primitive::kPrimLong: |
| 1646 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1647 | locations->SetInAt(1, Location::Any()); |
| 1648 | break; |
| 1649 | case Primitive::kPrimFloat: |
| 1650 | case Primitive::kPrimDouble: |
| 1651 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1652 | locations->SetInAt(1, Location::Any()); |
| 1653 | break; |
| 1654 | default: |
| 1655 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1656 | locations->SetInAt(1, Location::Any()); |
| 1657 | break; |
| 1658 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1659 | if (!cond->IsEmittedAtUseSite()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1660 | locations->SetOut(Location::RequiresRegister()); |
| 1661 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1662 | } |
| 1663 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1664 | void InstructionCodeGeneratorX86_64::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1665 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1666 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1667 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1668 | |
| 1669 | LocationSummary* locations = cond->GetLocations(); |
| 1670 | Location lhs = locations->InAt(0); |
| 1671 | Location rhs = locations->InAt(1); |
| 1672 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1673 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1674 | |
| 1675 | switch (cond->InputAt(0)->GetType()) { |
| 1676 | default: |
| 1677 | // Integer case. |
| 1678 | |
| 1679 | // Clear output register: setcc only sets the low byte. |
| 1680 | __ xorl(reg, reg); |
| 1681 | |
| 1682 | if (rhs.IsRegister()) { |
| 1683 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1684 | } else if (rhs.IsConstant()) { |
| 1685 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1686 | codegen_->Compare32BitValue(lhs.AsRegister<CpuRegister>(), constant); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1687 | } else { |
| 1688 | __ cmpl(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1689 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1690 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1691 | return; |
| 1692 | case Primitive::kPrimLong: |
| 1693 | // Clear output register: setcc only sets the low byte. |
| 1694 | __ xorl(reg, reg); |
| 1695 | |
| 1696 | if (rhs.IsRegister()) { |
| 1697 | __ cmpq(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1698 | } else if (rhs.IsConstant()) { |
| 1699 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1700 | codegen_->Compare64BitValue(lhs.AsRegister<CpuRegister>(), value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1701 | } else { |
| 1702 | __ cmpq(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1703 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1704 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1705 | return; |
| 1706 | case Primitive::kPrimFloat: { |
| 1707 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1708 | if (rhs.IsConstant()) { |
| 1709 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 1710 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 1711 | } else if (rhs.IsStackSlot()) { |
| 1712 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1713 | } else { |
| 1714 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1715 | } |
| 1716 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1717 | break; |
| 1718 | } |
| 1719 | case Primitive::kPrimDouble: { |
| 1720 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1721 | if (rhs.IsConstant()) { |
| 1722 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1723 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 1724 | } else if (rhs.IsDoubleStackSlot()) { |
| 1725 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1726 | } else { |
| 1727 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1728 | } |
| 1729 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1730 | break; |
| 1731 | } |
| 1732 | } |
| 1733 | |
| 1734 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1735 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1736 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1737 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1738 | __ Bind(&false_label); |
| 1739 | __ xorl(reg, reg); |
| 1740 | __ jmp(&done_label); |
| 1741 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1742 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1743 | __ Bind(&true_label); |
| 1744 | __ movl(reg, Immediate(1)); |
| 1745 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1746 | } |
| 1747 | |
| 1748 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1749 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1753 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1754 | } |
| 1755 | |
| 1756 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1757 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1758 | } |
| 1759 | |
| 1760 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1761 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1762 | } |
| 1763 | |
| 1764 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1765 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1769 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1773 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1777 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1778 | } |
| 1779 | |
| 1780 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1781 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1782 | } |
| 1783 | |
| 1784 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1785 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1789 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1790 | } |
| 1791 | |
| 1792 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1793 | HandleCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1794 | } |
| 1795 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1796 | void LocationsBuilderX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1797 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1798 | } |
| 1799 | |
| 1800 | void InstructionCodeGeneratorX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1801 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1802 | } |
| 1803 | |
| 1804 | void LocationsBuilderX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1805 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | void InstructionCodeGeneratorX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1809 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1810 | } |
| 1811 | |
| 1812 | void LocationsBuilderX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1813 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1814 | } |
| 1815 | |
| 1816 | void InstructionCodeGeneratorX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1817 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1818 | } |
| 1819 | |
| 1820 | void LocationsBuilderX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1821 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1822 | } |
| 1823 | |
| 1824 | void InstructionCodeGeneratorX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1825 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1826 | } |
| 1827 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1828 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1829 | LocationSummary* locations = |
| 1830 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1831 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 1832 | case Primitive::kPrimBoolean: |
| 1833 | case Primitive::kPrimByte: |
| 1834 | case Primitive::kPrimShort: |
| 1835 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1836 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1837 | case Primitive::kPrimLong: { |
| 1838 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1839 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1840 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1841 | break; |
| 1842 | } |
| 1843 | case Primitive::kPrimFloat: |
| 1844 | case Primitive::kPrimDouble: { |
| 1845 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1846 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1847 | locations->SetOut(Location::RequiresRegister()); |
| 1848 | break; |
| 1849 | } |
| 1850 | default: |
| 1851 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 1852 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1853 | } |
| 1854 | |
| 1855 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1856 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1857 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1858 | Location left = locations->InAt(0); |
| 1859 | Location right = locations->InAt(1); |
| 1860 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1861 | NearLabel less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1862 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1863 | Condition less_cond = kLess; |
| 1864 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1865 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 1866 | case Primitive::kPrimBoolean: |
| 1867 | case Primitive::kPrimByte: |
| 1868 | case Primitive::kPrimShort: |
| 1869 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1870 | case Primitive::kPrimInt: { |
| 1871 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1872 | if (right.IsConstant()) { |
| 1873 | int32_t value = right.GetConstant()->AsIntConstant()->GetValue(); |
| 1874 | codegen_->Compare32BitValue(left_reg, value); |
| 1875 | } else if (right.IsStackSlot()) { |
| 1876 | __ cmpl(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1877 | } else { |
| 1878 | __ cmpl(left_reg, right.AsRegister<CpuRegister>()); |
| 1879 | } |
| 1880 | break; |
| 1881 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1882 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1883 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1884 | if (right.IsConstant()) { |
| 1885 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1886 | codegen_->Compare64BitValue(left_reg, value); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1887 | } else if (right.IsDoubleStackSlot()) { |
| 1888 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1889 | } else { |
| 1890 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1891 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1892 | break; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1893 | } |
| 1894 | case Primitive::kPrimFloat: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1895 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1896 | if (right.IsConstant()) { |
| 1897 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 1898 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 1899 | } else if (right.IsStackSlot()) { |
| 1900 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1901 | } else { |
| 1902 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1903 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1904 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1905 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1906 | break; |
| 1907 | } |
| 1908 | case Primitive::kPrimDouble: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1909 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1910 | if (right.IsConstant()) { |
| 1911 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1912 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 1913 | } else if (right.IsDoubleStackSlot()) { |
| 1914 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1915 | } else { |
| 1916 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1917 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1918 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1919 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1920 | break; |
| 1921 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1922 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1923 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1924 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1925 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1926 | __ movl(out, Immediate(0)); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1927 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1928 | __ j(less_cond, &less); |
Calin Juravle | fd86124 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1929 | |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1930 | __ Bind(&greater); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1931 | __ movl(out, Immediate(1)); |
| 1932 | __ jmp(&done); |
| 1933 | |
| 1934 | __ Bind(&less); |
| 1935 | __ movl(out, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1936 | |
| 1937 | __ Bind(&done); |
| 1938 | } |
| 1939 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1940 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1941 | LocationSummary* locations = |
| 1942 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1943 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1944 | } |
| 1945 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1946 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1947 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1948 | } |
| 1949 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1950 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 1951 | LocationSummary* locations = |
| 1952 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1953 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1954 | } |
| 1955 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1956 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1957 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1958 | } |
| 1959 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1960 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1961 | LocationSummary* locations = |
| 1962 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1963 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1964 | } |
| 1965 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1966 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1967 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1968 | } |
| 1969 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1970 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 1971 | LocationSummary* locations = |
| 1972 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1973 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1974 | } |
| 1975 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1976 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1977 | // Will be generated at use site. |
| 1978 | } |
| 1979 | |
| 1980 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1981 | LocationSummary* locations = |
| 1982 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1983 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1984 | } |
| 1985 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1986 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant( |
| 1987 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1988 | // Will be generated at use site. |
| 1989 | } |
| 1990 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1991 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1992 | memory_barrier->SetLocations(nullptr); |
| 1993 | } |
| 1994 | |
| 1995 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 1996 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1997 | } |
| 1998 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1999 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 2000 | ret->SetLocations(nullptr); |
| 2001 | } |
| 2002 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2003 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2004 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2005 | } |
| 2006 | |
| 2007 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2008 | LocationSummary* locations = |
| 2009 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2010 | switch (ret->InputAt(0)->GetType()) { |
| 2011 | case Primitive::kPrimBoolean: |
| 2012 | case Primitive::kPrimByte: |
| 2013 | case Primitive::kPrimChar: |
| 2014 | case Primitive::kPrimShort: |
| 2015 | case Primitive::kPrimInt: |
| 2016 | case Primitive::kPrimNot: |
| 2017 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2018 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2019 | break; |
| 2020 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2021 | case Primitive::kPrimFloat: |
| 2022 | case Primitive::kPrimDouble: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2023 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2024 | break; |
| 2025 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2026 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2027 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2028 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2029 | } |
| 2030 | |
| 2031 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 2032 | if (kIsDebugBuild) { |
| 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: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2041 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), 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: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2046 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2047 | XMM0); |
| 2048 | break; |
| 2049 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2050 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2051 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2052 | } |
| 2053 | } |
| 2054 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2055 | } |
| 2056 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2057 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(Primitive::Type type) const { |
| 2058 | switch (type) { |
| 2059 | case Primitive::kPrimBoolean: |
| 2060 | case Primitive::kPrimByte: |
| 2061 | case Primitive::kPrimChar: |
| 2062 | case Primitive::kPrimShort: |
| 2063 | case Primitive::kPrimInt: |
| 2064 | case Primitive::kPrimNot: |
| 2065 | case Primitive::kPrimLong: |
| 2066 | return Location::RegisterLocation(RAX); |
| 2067 | |
| 2068 | case Primitive::kPrimVoid: |
| 2069 | return Location::NoLocation(); |
| 2070 | |
| 2071 | case Primitive::kPrimDouble: |
| 2072 | case Primitive::kPrimFloat: |
| 2073 | return Location::FpuRegisterLocation(XMM0); |
| 2074 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2075 | |
| 2076 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2077 | } |
| 2078 | |
| 2079 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 2080 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2081 | } |
| 2082 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2083 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2084 | switch (type) { |
| 2085 | case Primitive::kPrimBoolean: |
| 2086 | case Primitive::kPrimByte: |
| 2087 | case Primitive::kPrimChar: |
| 2088 | case Primitive::kPrimShort: |
| 2089 | case Primitive::kPrimInt: |
| 2090 | case Primitive::kPrimNot: { |
| 2091 | uint32_t index = gp_index_++; |
| 2092 | stack_index_++; |
| 2093 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2094 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2095 | } else { |
| 2096 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2097 | } |
| 2098 | } |
| 2099 | |
| 2100 | case Primitive::kPrimLong: { |
| 2101 | uint32_t index = gp_index_; |
| 2102 | stack_index_ += 2; |
| 2103 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2104 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2105 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2106 | } else { |
| 2107 | gp_index_ += 2; |
| 2108 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2109 | } |
| 2110 | } |
| 2111 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2112 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2113 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2114 | stack_index_++; |
| 2115 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2116 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2117 | } else { |
| 2118 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2119 | } |
| 2120 | } |
| 2121 | |
| 2122 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2123 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2124 | stack_index_ += 2; |
| 2125 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2126 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2127 | } else { |
| 2128 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2129 | } |
| 2130 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2131 | |
| 2132 | case Primitive::kPrimVoid: |
| 2133 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2134 | break; |
| 2135 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2136 | return Location::NoLocation(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2137 | } |
| 2138 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2139 | void LocationsBuilderX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2140 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2141 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2142 | // the method_idx. |
| 2143 | HandleInvoke(invoke); |
| 2144 | } |
| 2145 | |
| 2146 | void InstructionCodeGeneratorX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2147 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2148 | } |
| 2149 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2150 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2151 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2152 | // art::PrepareForRegisterAllocation. |
| 2153 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2154 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2155 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2156 | if (intrinsic.TryDispatch(invoke)) { |
| 2157 | return; |
| 2158 | } |
| 2159 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2160 | HandleInvoke(invoke); |
| 2161 | } |
| 2162 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2163 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 2164 | if (invoke->GetLocations()->Intrinsified()) { |
| 2165 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 2166 | intrinsic.Dispatch(invoke); |
| 2167 | return true; |
| 2168 | } |
| 2169 | return false; |
| 2170 | } |
| 2171 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2172 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2173 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2174 | // art::PrepareForRegisterAllocation. |
| 2175 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2176 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2177 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2178 | return; |
| 2179 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2180 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2181 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2182 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2183 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 2184 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2185 | } |
| 2186 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2187 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2188 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2189 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2190 | } |
| 2191 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2192 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2193 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2194 | if (intrinsic.TryDispatch(invoke)) { |
| 2195 | return; |
| 2196 | } |
| 2197 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2198 | HandleInvoke(invoke); |
| 2199 | } |
| 2200 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2201 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2202 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2203 | return; |
| 2204 | } |
| 2205 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2206 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2207 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2208 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2209 | } |
| 2210 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2211 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2212 | HandleInvoke(invoke); |
| 2213 | // Add the hidden argument. |
| 2214 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 2215 | } |
| 2216 | |
| 2217 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2218 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2219 | LocationSummary* locations = invoke->GetLocations(); |
| 2220 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2221 | CpuRegister hidden_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2222 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 2223 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86_64PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2224 | Location receiver = locations->InAt(0); |
| 2225 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 2226 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2227 | // Set the hidden argument. This is safe to do this here, as RAX |
| 2228 | // won't be modified thereafter, before the `call` instruction. |
| 2229 | DCHECK_EQ(RAX, hidden_reg.AsRegister()); |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2230 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2231 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2232 | if (receiver.IsStackSlot()) { |
| 2233 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2234 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2235 | __ movl(temp, Address(temp, class_offset)); |
| 2236 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2237 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2238 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2239 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2240 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2241 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2242 | // emit a read barrier for the previous class reference load. |
| 2243 | // However this is not required in practice, as this is an |
| 2244 | // intermediate/temporary reference and because the current |
| 2245 | // concurrent copying collector keeps the from-space memory |
| 2246 | // intact/accessible until the end of the marking phase (the |
| 2247 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2248 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2249 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2250 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2251 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2252 | __ call(Address(temp, |
| 2253 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64WordSize).SizeValue())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2254 | |
| 2255 | DCHECK(!codegen_->IsLeafMethod()); |
| 2256 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2257 | } |
| 2258 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2259 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 2260 | LocationSummary* locations = |
| 2261 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2262 | switch (neg->GetResultType()) { |
| 2263 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2264 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2265 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2266 | locations->SetOut(Location::SameAsFirstInput()); |
| 2267 | break; |
| 2268 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2269 | case Primitive::kPrimFloat: |
| 2270 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2271 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2272 | locations->SetOut(Location::SameAsFirstInput()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2273 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2274 | break; |
| 2275 | |
| 2276 | default: |
| 2277 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2278 | } |
| 2279 | } |
| 2280 | |
| 2281 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 2282 | LocationSummary* locations = neg->GetLocations(); |
| 2283 | Location out = locations->Out(); |
| 2284 | Location in = locations->InAt(0); |
| 2285 | switch (neg->GetResultType()) { |
| 2286 | case Primitive::kPrimInt: |
| 2287 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2288 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2289 | __ negl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2290 | break; |
| 2291 | |
| 2292 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2293 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2294 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2295 | __ negq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2296 | break; |
| 2297 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2298 | case Primitive::kPrimFloat: { |
| 2299 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2300 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2301 | // Implement float negation with an exclusive or with value |
| 2302 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2303 | // single-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2304 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2305 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2306 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2307 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2308 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2309 | case Primitive::kPrimDouble: { |
| 2310 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2311 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2312 | // Implement double negation with an exclusive or with value |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2313 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2314 | // a double-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2315 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2316 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2317 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2318 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2319 | |
| 2320 | default: |
| 2321 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2322 | } |
| 2323 | } |
| 2324 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2325 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2326 | LocationSummary* locations = |
| 2327 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 2328 | Primitive::Type result_type = conversion->GetResultType(); |
| 2329 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2330 | DCHECK_NE(result_type, input_type); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2331 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2332 | // The Java language does not allow treating boolean as an integral type but |
| 2333 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2334 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2335 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2336 | case Primitive::kPrimByte: |
| 2337 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2338 | case Primitive::kPrimLong: |
| 2339 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2340 | case Primitive::kPrimBoolean: |
| 2341 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2342 | case Primitive::kPrimShort: |
| 2343 | case Primitive::kPrimInt: |
| 2344 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2345 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2346 | locations->SetInAt(0, Location::Any()); |
| 2347 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2348 | break; |
| 2349 | |
| 2350 | default: |
| 2351 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2352 | << " to " << result_type; |
| 2353 | } |
| 2354 | break; |
| 2355 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2356 | case Primitive::kPrimShort: |
| 2357 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2358 | case Primitive::kPrimLong: |
| 2359 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2360 | case Primitive::kPrimBoolean: |
| 2361 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2362 | case Primitive::kPrimByte: |
| 2363 | case Primitive::kPrimInt: |
| 2364 | case Primitive::kPrimChar: |
| 2365 | // Processing a Dex `int-to-short' instruction. |
| 2366 | locations->SetInAt(0, Location::Any()); |
| 2367 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2368 | break; |
| 2369 | |
| 2370 | default: |
| 2371 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2372 | << " to " << result_type; |
| 2373 | } |
| 2374 | break; |
| 2375 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2376 | case Primitive::kPrimInt: |
| 2377 | switch (input_type) { |
| 2378 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2379 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2380 | locations->SetInAt(0, Location::Any()); |
| 2381 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2382 | break; |
| 2383 | |
| 2384 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2385 | // Processing a Dex `float-to-int' instruction. |
| 2386 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2387 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2388 | break; |
| 2389 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2390 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2391 | // Processing a Dex `double-to-int' instruction. |
| 2392 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2393 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2394 | break; |
| 2395 | |
| 2396 | default: |
| 2397 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2398 | << " to " << result_type; |
| 2399 | } |
| 2400 | break; |
| 2401 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2402 | case Primitive::kPrimLong: |
| 2403 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2404 | case Primitive::kPrimBoolean: |
| 2405 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2406 | case Primitive::kPrimByte: |
| 2407 | case Primitive::kPrimShort: |
| 2408 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2409 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2410 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2411 | // TODO: We would benefit from a (to-be-implemented) |
| 2412 | // Location::RegisterOrStackSlot requirement for this input. |
| 2413 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2414 | locations->SetOut(Location::RequiresRegister()); |
| 2415 | break; |
| 2416 | |
| 2417 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2418 | // Processing a Dex `float-to-long' instruction. |
| 2419 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2420 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2421 | break; |
| 2422 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2423 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2424 | // Processing a Dex `double-to-long' instruction. |
| 2425 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2426 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2427 | break; |
| 2428 | |
| 2429 | default: |
| 2430 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2431 | << " to " << result_type; |
| 2432 | } |
| 2433 | break; |
| 2434 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2435 | case Primitive::kPrimChar: |
| 2436 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2437 | case Primitive::kPrimLong: |
| 2438 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2439 | case Primitive::kPrimBoolean: |
| 2440 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2441 | case Primitive::kPrimByte: |
| 2442 | case Primitive::kPrimShort: |
| 2443 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2444 | // Processing a Dex `int-to-char' instruction. |
| 2445 | locations->SetInAt(0, Location::Any()); |
| 2446 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2447 | break; |
| 2448 | |
| 2449 | default: |
| 2450 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2451 | << " to " << result_type; |
| 2452 | } |
| 2453 | break; |
| 2454 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2455 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2456 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2457 | case Primitive::kPrimBoolean: |
| 2458 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2459 | case Primitive::kPrimByte: |
| 2460 | case Primitive::kPrimShort: |
| 2461 | case Primitive::kPrimInt: |
| 2462 | case Primitive::kPrimChar: |
| 2463 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2464 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2465 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2466 | break; |
| 2467 | |
| 2468 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2469 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2470 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2471 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2472 | break; |
| 2473 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2474 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2475 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2476 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2477 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2478 | break; |
| 2479 | |
| 2480 | default: |
| 2481 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2482 | << " to " << result_type; |
| 2483 | }; |
| 2484 | break; |
| 2485 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2486 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2487 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2488 | case Primitive::kPrimBoolean: |
| 2489 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2490 | case Primitive::kPrimByte: |
| 2491 | case Primitive::kPrimShort: |
| 2492 | case Primitive::kPrimInt: |
| 2493 | case Primitive::kPrimChar: |
| 2494 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2495 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2496 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2497 | break; |
| 2498 | |
| 2499 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2500 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2501 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2502 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2503 | break; |
| 2504 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2505 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2506 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2507 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2508 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2509 | break; |
| 2510 | |
| 2511 | default: |
| 2512 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2513 | << " to " << result_type; |
| 2514 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2515 | break; |
| 2516 | |
| 2517 | default: |
| 2518 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2519 | << " to " << result_type; |
| 2520 | } |
| 2521 | } |
| 2522 | |
| 2523 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2524 | LocationSummary* locations = conversion->GetLocations(); |
| 2525 | Location out = locations->Out(); |
| 2526 | Location in = locations->InAt(0); |
| 2527 | Primitive::Type result_type = conversion->GetResultType(); |
| 2528 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2529 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2530 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2531 | case Primitive::kPrimByte: |
| 2532 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2533 | case Primitive::kPrimLong: |
| 2534 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2535 | case Primitive::kPrimBoolean: |
| 2536 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2537 | case Primitive::kPrimShort: |
| 2538 | case Primitive::kPrimInt: |
| 2539 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2540 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2541 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2542 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2543 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2544 | __ movsxb(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2545 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2546 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2547 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2548 | Immediate(static_cast<int8_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2549 | } |
| 2550 | break; |
| 2551 | |
| 2552 | default: |
| 2553 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2554 | << " to " << result_type; |
| 2555 | } |
| 2556 | break; |
| 2557 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2558 | case Primitive::kPrimShort: |
| 2559 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2560 | case Primitive::kPrimLong: |
| 2561 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2562 | case Primitive::kPrimBoolean: |
| 2563 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2564 | case Primitive::kPrimByte: |
| 2565 | case Primitive::kPrimInt: |
| 2566 | case Primitive::kPrimChar: |
| 2567 | // Processing a Dex `int-to-short' instruction. |
| 2568 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2569 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2570 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2571 | __ movsxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2572 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2573 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2574 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2575 | Immediate(static_cast<int16_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2576 | } |
| 2577 | break; |
| 2578 | |
| 2579 | default: |
| 2580 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2581 | << " to " << result_type; |
| 2582 | } |
| 2583 | break; |
| 2584 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2585 | case Primitive::kPrimInt: |
| 2586 | switch (input_type) { |
| 2587 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2588 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2589 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2590 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2591 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2592 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2593 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2594 | } else { |
| 2595 | DCHECK(in.IsConstant()); |
| 2596 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2597 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2598 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2599 | } |
| 2600 | break; |
| 2601 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2602 | case Primitive::kPrimFloat: { |
| 2603 | // Processing a Dex `float-to-int' instruction. |
| 2604 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2605 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2606 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2607 | |
| 2608 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2609 | // if input >= (float)INT_MAX goto done |
| 2610 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimIntMax)); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2611 | __ j(kAboveEqual, &done); |
| 2612 | // if input == NaN goto nan |
| 2613 | __ j(kUnordered, &nan); |
| 2614 | // output = float-to-int-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2615 | __ cvttss2si(output, input, false); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2616 | __ jmp(&done); |
| 2617 | __ Bind(&nan); |
| 2618 | // output = 0 |
| 2619 | __ xorl(output, output); |
| 2620 | __ Bind(&done); |
| 2621 | break; |
| 2622 | } |
| 2623 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2624 | case Primitive::kPrimDouble: { |
| 2625 | // Processing a Dex `double-to-int' instruction. |
| 2626 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2627 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2628 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2629 | |
| 2630 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2631 | // if input >= (double)INT_MAX goto done |
| 2632 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2633 | __ j(kAboveEqual, &done); |
| 2634 | // if input == NaN goto nan |
| 2635 | __ j(kUnordered, &nan); |
| 2636 | // output = double-to-int-truncate(input) |
| 2637 | __ cvttsd2si(output, input); |
| 2638 | __ jmp(&done); |
| 2639 | __ Bind(&nan); |
| 2640 | // output = 0 |
| 2641 | __ xorl(output, output); |
| 2642 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2643 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2644 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2645 | |
| 2646 | default: |
| 2647 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2648 | << " to " << result_type; |
| 2649 | } |
| 2650 | break; |
| 2651 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2652 | case Primitive::kPrimLong: |
| 2653 | switch (input_type) { |
| 2654 | DCHECK(out.IsRegister()); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2655 | case Primitive::kPrimBoolean: |
| 2656 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2657 | case Primitive::kPrimByte: |
| 2658 | case Primitive::kPrimShort: |
| 2659 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2660 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2661 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2662 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2663 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2664 | break; |
| 2665 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2666 | case Primitive::kPrimFloat: { |
| 2667 | // Processing a Dex `float-to-long' instruction. |
| 2668 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2669 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2670 | NearLabel done, nan; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2671 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2672 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2673 | // if input >= (float)LONG_MAX goto done |
| 2674 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimLongMax)); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2675 | __ j(kAboveEqual, &done); |
| 2676 | // if input == NaN goto nan |
| 2677 | __ j(kUnordered, &nan); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2678 | // output = float-to-long-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2679 | __ cvttss2si(output, input, true); |
| 2680 | __ jmp(&done); |
| 2681 | __ Bind(&nan); |
| 2682 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2683 | __ xorl(output, output); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2684 | __ Bind(&done); |
| 2685 | break; |
| 2686 | } |
| 2687 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2688 | case Primitive::kPrimDouble: { |
| 2689 | // Processing a Dex `double-to-long' instruction. |
| 2690 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2691 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2692 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2693 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2694 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2695 | // if input >= (double)LONG_MAX goto done |
| 2696 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimLongMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2697 | __ j(kAboveEqual, &done); |
| 2698 | // if input == NaN goto nan |
| 2699 | __ j(kUnordered, &nan); |
| 2700 | // output = double-to-long-truncate(input) |
| 2701 | __ cvttsd2si(output, input, true); |
| 2702 | __ jmp(&done); |
| 2703 | __ Bind(&nan); |
| 2704 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2705 | __ xorl(output, output); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2706 | __ Bind(&done); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2707 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2708 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2709 | |
| 2710 | default: |
| 2711 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2712 | << " to " << result_type; |
| 2713 | } |
| 2714 | break; |
| 2715 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2716 | case Primitive::kPrimChar: |
| 2717 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2718 | case Primitive::kPrimLong: |
| 2719 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2720 | case Primitive::kPrimBoolean: |
| 2721 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2722 | case Primitive::kPrimByte: |
| 2723 | case Primitive::kPrimShort: |
| 2724 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2725 | // Processing a Dex `int-to-char' instruction. |
| 2726 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2727 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2728 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2729 | __ movzxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2730 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2731 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2732 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2733 | Immediate(static_cast<uint16_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2734 | } |
| 2735 | break; |
| 2736 | |
| 2737 | default: |
| 2738 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2739 | << " to " << result_type; |
| 2740 | } |
| 2741 | break; |
| 2742 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2743 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2744 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2745 | case Primitive::kPrimBoolean: |
| 2746 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2747 | case Primitive::kPrimByte: |
| 2748 | case Primitive::kPrimShort: |
| 2749 | case Primitive::kPrimInt: |
| 2750 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2751 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2752 | if (in.IsRegister()) { |
| 2753 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2754 | } else if (in.IsConstant()) { |
| 2755 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2756 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2757 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2758 | } else { |
| 2759 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2760 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2761 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2762 | break; |
| 2763 | |
| 2764 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2765 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2766 | if (in.IsRegister()) { |
| 2767 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2768 | } else if (in.IsConstant()) { |
| 2769 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2770 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Pavel Vyssotski | 4c858cd | 2016-03-16 13:59:53 +0600 | [diff] [blame] | 2771 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2772 | } else { |
| 2773 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2774 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2775 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2776 | break; |
| 2777 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2778 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2779 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2780 | if (in.IsFpuRegister()) { |
| 2781 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2782 | } else if (in.IsConstant()) { |
| 2783 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2784 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2785 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2786 | } else { |
| 2787 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 2788 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2789 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2790 | break; |
| 2791 | |
| 2792 | default: |
| 2793 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2794 | << " to " << result_type; |
| 2795 | }; |
| 2796 | break; |
| 2797 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2798 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2799 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2800 | case Primitive::kPrimBoolean: |
| 2801 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2802 | case Primitive::kPrimByte: |
| 2803 | case Primitive::kPrimShort: |
| 2804 | case Primitive::kPrimInt: |
| 2805 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2806 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2807 | if (in.IsRegister()) { |
| 2808 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2809 | } else if (in.IsConstant()) { |
| 2810 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2811 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2812 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2813 | } else { |
| 2814 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2815 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2816 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2817 | break; |
| 2818 | |
| 2819 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2820 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2821 | if (in.IsRegister()) { |
| 2822 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2823 | } else if (in.IsConstant()) { |
| 2824 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2825 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2826 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2827 | } else { |
| 2828 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2829 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2830 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2831 | break; |
| 2832 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2833 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2834 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2835 | if (in.IsFpuRegister()) { |
| 2836 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2837 | } else if (in.IsConstant()) { |
| 2838 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 2839 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2840 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2841 | } else { |
| 2842 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 2843 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2844 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2845 | break; |
| 2846 | |
| 2847 | default: |
| 2848 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2849 | << " to " << result_type; |
| 2850 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2851 | break; |
| 2852 | |
| 2853 | default: |
| 2854 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2855 | << " to " << result_type; |
| 2856 | } |
| 2857 | } |
| 2858 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2859 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2860 | LocationSummary* locations = |
| 2861 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2862 | switch (add->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2863 | case Primitive::kPrimInt: { |
| 2864 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2865 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2866 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2867 | break; |
| 2868 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2869 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2870 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2871 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2872 | // 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] | 2873 | locations->SetInAt(1, Location::RegisterOrInt32Constant(add->InputAt(1))); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2874 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2875 | break; |
| 2876 | } |
| 2877 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2878 | case Primitive::kPrimDouble: |
| 2879 | case Primitive::kPrimFloat: { |
| 2880 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2881 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2882 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2883 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2884 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2885 | |
| 2886 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2887 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2888 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2889 | } |
| 2890 | |
| 2891 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 2892 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2893 | Location first = locations->InAt(0); |
| 2894 | Location second = locations->InAt(1); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2895 | Location out = locations->Out(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2896 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2897 | switch (add->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2898 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2899 | if (second.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2900 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2901 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2902 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2903 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2904 | } else { |
| 2905 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2906 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2907 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2908 | } else if (second.IsConstant()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2909 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2910 | __ addl(out.AsRegister<CpuRegister>(), |
| 2911 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 2912 | } else { |
| 2913 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2914 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 2915 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2916 | } else { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2917 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2918 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2919 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2920 | break; |
| 2921 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2922 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2923 | case Primitive::kPrimLong: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2924 | if (second.IsRegister()) { |
| 2925 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2926 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2927 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2928 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2929 | } else { |
| 2930 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2931 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2932 | } |
| 2933 | } else { |
| 2934 | DCHECK(second.IsConstant()); |
| 2935 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2936 | int32_t int32_value = Low32Bits(value); |
| 2937 | DCHECK_EQ(int32_value, value); |
| 2938 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2939 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 2940 | } else { |
| 2941 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2942 | first.AsRegister<CpuRegister>(), int32_value)); |
| 2943 | } |
| 2944 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2945 | break; |
| 2946 | } |
| 2947 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2948 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2949 | if (second.IsFpuRegister()) { |
| 2950 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2951 | } else if (second.IsConstant()) { |
| 2952 | __ addss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2953 | codegen_->LiteralFloatAddress( |
| 2954 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2955 | } else { |
| 2956 | DCHECK(second.IsStackSlot()); |
| 2957 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2958 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2959 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2960 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2961 | } |
| 2962 | |
| 2963 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2964 | if (second.IsFpuRegister()) { |
| 2965 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2966 | } else if (second.IsConstant()) { |
| 2967 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2968 | codegen_->LiteralDoubleAddress( |
| 2969 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2970 | } else { |
| 2971 | DCHECK(second.IsDoubleStackSlot()); |
| 2972 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2973 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2974 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2975 | break; |
| 2976 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2977 | |
| 2978 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2979 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2980 | } |
| 2981 | } |
| 2982 | |
| 2983 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2984 | LocationSummary* locations = |
| 2985 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2986 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2987 | case Primitive::kPrimInt: { |
| 2988 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2989 | locations->SetInAt(1, Location::Any()); |
| 2990 | locations->SetOut(Location::SameAsFirstInput()); |
| 2991 | break; |
| 2992 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2993 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2994 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 2995 | locations->SetInAt(1, Location::RegisterOrInt32Constant(sub->InputAt(1))); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2996 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2997 | break; |
| 2998 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2999 | case Primitive::kPrimFloat: |
| 3000 | case Primitive::kPrimDouble: { |
| 3001 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3002 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3003 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3004 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3005 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3006 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3007 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3008 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3009 | } |
| 3010 | |
| 3011 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 3012 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3013 | Location first = locations->InAt(0); |
| 3014 | Location second = locations->InAt(1); |
| 3015 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3016 | switch (sub->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3017 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3018 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3019 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3020 | } else if (second.IsConstant()) { |
| 3021 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3022 | __ subl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3023 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3024 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3025 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3026 | break; |
| 3027 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3028 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3029 | if (second.IsConstant()) { |
| 3030 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3031 | DCHECK(IsInt<32>(value)); |
| 3032 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 3033 | } else { |
| 3034 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 3035 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3036 | break; |
| 3037 | } |
| 3038 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3039 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3040 | if (second.IsFpuRegister()) { |
| 3041 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3042 | } else if (second.IsConstant()) { |
| 3043 | __ subss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3044 | codegen_->LiteralFloatAddress( |
| 3045 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3046 | } else { |
| 3047 | DCHECK(second.IsStackSlot()); |
| 3048 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3049 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3050 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3051 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3052 | } |
| 3053 | |
| 3054 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3055 | if (second.IsFpuRegister()) { |
| 3056 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3057 | } else if (second.IsConstant()) { |
| 3058 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3059 | codegen_->LiteralDoubleAddress( |
| 3060 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3061 | } else { |
| 3062 | DCHECK(second.IsDoubleStackSlot()); |
| 3063 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3064 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3065 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3066 | break; |
| 3067 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3068 | |
| 3069 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3070 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3071 | } |
| 3072 | } |
| 3073 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3074 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 3075 | LocationSummary* locations = |
| 3076 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3077 | switch (mul->GetResultType()) { |
| 3078 | case Primitive::kPrimInt: { |
| 3079 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3080 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3081 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3082 | // Can use 3 operand multiply. |
| 3083 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3084 | } else { |
| 3085 | locations->SetOut(Location::SameAsFirstInput()); |
| 3086 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3087 | break; |
| 3088 | } |
| 3089 | case Primitive::kPrimLong: { |
| 3090 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3091 | locations->SetInAt(1, Location::Any()); |
| 3092 | if (mul->InputAt(1)->IsLongConstant() && |
| 3093 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3094 | // Can use 3 operand multiply. |
| 3095 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3096 | } else { |
| 3097 | locations->SetOut(Location::SameAsFirstInput()); |
| 3098 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3099 | break; |
| 3100 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3101 | case Primitive::kPrimFloat: |
| 3102 | case Primitive::kPrimDouble: { |
| 3103 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3104 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3105 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3106 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3107 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3108 | |
| 3109 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3110 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3111 | } |
| 3112 | } |
| 3113 | |
| 3114 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 3115 | LocationSummary* locations = mul->GetLocations(); |
| 3116 | Location first = locations->InAt(0); |
| 3117 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3118 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3119 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3120 | case Primitive::kPrimInt: |
| 3121 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3122 | // problems where the output may not be the same as the first operand. |
| 3123 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3124 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3125 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 3126 | } else if (second.IsRegister()) { |
| 3127 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3128 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3129 | } else { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3130 | DCHECK(first.Equals(out)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3131 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3132 | __ imull(first.AsRegister<CpuRegister>(), |
| 3133 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3134 | } |
| 3135 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3136 | case Primitive::kPrimLong: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3137 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3138 | // problems where the output may not be the same as the first operand. |
| 3139 | if (mul->InputAt(1)->IsLongConstant()) { |
| 3140 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 3141 | if (IsInt<32>(value)) { |
| 3142 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 3143 | Immediate(static_cast<int32_t>(value))); |
| 3144 | } else { |
| 3145 | // Have to use the constant area. |
| 3146 | DCHECK(first.Equals(out)); |
| 3147 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 3148 | } |
| 3149 | } else if (second.IsRegister()) { |
| 3150 | DCHECK(first.Equals(out)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3151 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3152 | } else { |
| 3153 | DCHECK(second.IsDoubleStackSlot()); |
| 3154 | DCHECK(first.Equals(out)); |
| 3155 | __ imulq(first.AsRegister<CpuRegister>(), |
| 3156 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3157 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3158 | break; |
| 3159 | } |
| 3160 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3161 | case Primitive::kPrimFloat: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3162 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3163 | if (second.IsFpuRegister()) { |
| 3164 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3165 | } else if (second.IsConstant()) { |
| 3166 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3167 | codegen_->LiteralFloatAddress( |
| 3168 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3169 | } else { |
| 3170 | DCHECK(second.IsStackSlot()); |
| 3171 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3172 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3173 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3174 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3175 | } |
| 3176 | |
| 3177 | case Primitive::kPrimDouble: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3178 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3179 | if (second.IsFpuRegister()) { |
| 3180 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3181 | } else if (second.IsConstant()) { |
| 3182 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3183 | codegen_->LiteralDoubleAddress( |
| 3184 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3185 | } else { |
| 3186 | DCHECK(second.IsDoubleStackSlot()); |
| 3187 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3188 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3189 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3190 | break; |
| 3191 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3192 | |
| 3193 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3194 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3195 | } |
| 3196 | } |
| 3197 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3198 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 3199 | uint32_t stack_adjustment, bool is_float) { |
| 3200 | if (source.IsStackSlot()) { |
| 3201 | DCHECK(is_float); |
| 3202 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3203 | } else if (source.IsDoubleStackSlot()) { |
| 3204 | DCHECK(!is_float); |
| 3205 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3206 | } else { |
| 3207 | // Write the value to the temporary location on the stack and load to FP stack. |
| 3208 | if (is_float) { |
| 3209 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3210 | codegen_->Move(stack_temp, source); |
| 3211 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 3212 | } else { |
| 3213 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3214 | codegen_->Move(stack_temp, source); |
| 3215 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 3216 | } |
| 3217 | } |
| 3218 | } |
| 3219 | |
| 3220 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| 3221 | Primitive::Type type = rem->GetResultType(); |
| 3222 | bool is_float = type == Primitive::kPrimFloat; |
| 3223 | size_t elem_size = Primitive::ComponentSize(type); |
| 3224 | LocationSummary* locations = rem->GetLocations(); |
| 3225 | Location first = locations->InAt(0); |
| 3226 | Location second = locations->InAt(1); |
| 3227 | Location out = locations->Out(); |
| 3228 | |
| 3229 | // Create stack space for 2 elements. |
| 3230 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3231 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3232 | |
| 3233 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 3234 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 3235 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 3236 | |
| 3237 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3238 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3239 | __ Bind(&retry); |
| 3240 | __ fprem(); |
| 3241 | |
| 3242 | // Move FP status to AX. |
| 3243 | __ fstsw(); |
| 3244 | |
| 3245 | // And see if the argument reduction is complete. This is signaled by the |
| 3246 | // C2 FPU flag bit set to 0. |
| 3247 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 3248 | __ j(kNotEqual, &retry); |
| 3249 | |
| 3250 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3251 | // Store FP top of stack to real stack. |
| 3252 | if (is_float) { |
| 3253 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 3254 | } else { |
| 3255 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 3256 | } |
| 3257 | |
| 3258 | // Pop the 2 items from the FP stack. |
| 3259 | __ fucompp(); |
| 3260 | |
| 3261 | // Load the value from the stack into an XMM register. |
| 3262 | DCHECK(out.IsFpuRegister()) << out; |
| 3263 | if (is_float) { |
| 3264 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3265 | } else { |
| 3266 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3267 | } |
| 3268 | |
| 3269 | // And remove the temporary stack space we allocated. |
| 3270 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3271 | } |
| 3272 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3273 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3274 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3275 | |
| 3276 | LocationSummary* locations = instruction->GetLocations(); |
| 3277 | Location second = locations->InAt(1); |
| 3278 | DCHECK(second.IsConstant()); |
| 3279 | |
| 3280 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3281 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3282 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3283 | |
| 3284 | DCHECK(imm == 1 || imm == -1); |
| 3285 | |
| 3286 | switch (instruction->GetResultType()) { |
| 3287 | case Primitive::kPrimInt: { |
| 3288 | if (instruction->IsRem()) { |
| 3289 | __ xorl(output_register, output_register); |
| 3290 | } else { |
| 3291 | __ movl(output_register, input_register); |
| 3292 | if (imm == -1) { |
| 3293 | __ negl(output_register); |
| 3294 | } |
| 3295 | } |
| 3296 | break; |
| 3297 | } |
| 3298 | |
| 3299 | case Primitive::kPrimLong: { |
| 3300 | if (instruction->IsRem()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3301 | __ xorl(output_register, output_register); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3302 | } else { |
| 3303 | __ movq(output_register, input_register); |
| 3304 | if (imm == -1) { |
| 3305 | __ negq(output_register); |
| 3306 | } |
| 3307 | } |
| 3308 | break; |
| 3309 | } |
| 3310 | |
| 3311 | default: |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3312 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3313 | } |
| 3314 | } |
| 3315 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3316 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3317 | LocationSummary* locations = instruction->GetLocations(); |
| 3318 | Location second = locations->InAt(1); |
| 3319 | |
| 3320 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3321 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3322 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3323 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3324 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3325 | uint64_t abs_imm = AbsOrMin(imm); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3326 | |
| 3327 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3328 | |
| 3329 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3330 | __ leal(tmp, Address(numerator, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3331 | __ testl(numerator, numerator); |
| 3332 | __ cmov(kGreaterEqual, tmp, numerator); |
| 3333 | int shift = CTZ(imm); |
| 3334 | __ sarl(tmp, Immediate(shift)); |
| 3335 | |
| 3336 | if (imm < 0) { |
| 3337 | __ negl(tmp); |
| 3338 | } |
| 3339 | |
| 3340 | __ movl(output_register, tmp); |
| 3341 | } else { |
| 3342 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3343 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3344 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3345 | codegen_->Load64BitValue(rdx, abs_imm - 1); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3346 | __ addq(rdx, numerator); |
| 3347 | __ testq(numerator, numerator); |
| 3348 | __ cmov(kGreaterEqual, rdx, numerator); |
| 3349 | int shift = CTZ(imm); |
| 3350 | __ sarq(rdx, Immediate(shift)); |
| 3351 | |
| 3352 | if (imm < 0) { |
| 3353 | __ negq(rdx); |
| 3354 | } |
| 3355 | |
| 3356 | __ movq(output_register, rdx); |
| 3357 | } |
| 3358 | } |
| 3359 | |
| 3360 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3361 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3362 | |
| 3363 | LocationSummary* locations = instruction->GetLocations(); |
| 3364 | Location second = locations->InAt(1); |
| 3365 | |
| 3366 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 3367 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3368 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3369 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 3370 | : locations->Out().AsRegister<CpuRegister>(); |
| 3371 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3372 | |
| 3373 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 3374 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 3375 | if (instruction->IsDiv()) { |
| 3376 | DCHECK_EQ(RAX, out.AsRegister()); |
| 3377 | } else { |
| 3378 | DCHECK_EQ(RDX, out.AsRegister()); |
| 3379 | } |
| 3380 | |
| 3381 | int64_t magic; |
| 3382 | int shift; |
| 3383 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3384 | // TODO: can these branches be written as one? |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3385 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 3386 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3387 | |
| 3388 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3389 | |
| 3390 | __ movl(numerator, eax); |
| 3391 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3392 | NearLabel no_div; |
| 3393 | NearLabel end; |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3394 | __ testl(eax, eax); |
| 3395 | __ j(kNotEqual, &no_div); |
| 3396 | |
| 3397 | __ xorl(out, out); |
| 3398 | __ jmp(&end); |
| 3399 | |
| 3400 | __ Bind(&no_div); |
| 3401 | |
| 3402 | __ movl(eax, Immediate(magic)); |
| 3403 | __ imull(numerator); |
| 3404 | |
| 3405 | if (imm > 0 && magic < 0) { |
| 3406 | __ addl(edx, numerator); |
| 3407 | } else if (imm < 0 && magic > 0) { |
| 3408 | __ subl(edx, numerator); |
| 3409 | } |
| 3410 | |
| 3411 | if (shift != 0) { |
| 3412 | __ sarl(edx, Immediate(shift)); |
| 3413 | } |
| 3414 | |
| 3415 | __ movl(eax, edx); |
| 3416 | __ shrl(edx, Immediate(31)); |
| 3417 | __ addl(edx, eax); |
| 3418 | |
| 3419 | if (instruction->IsRem()) { |
| 3420 | __ movl(eax, numerator); |
| 3421 | __ imull(edx, Immediate(imm)); |
| 3422 | __ subl(eax, edx); |
| 3423 | __ movl(edx, eax); |
| 3424 | } else { |
| 3425 | __ movl(eax, edx); |
| 3426 | } |
| 3427 | __ Bind(&end); |
| 3428 | } else { |
| 3429 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3430 | |
| 3431 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3432 | |
| 3433 | CpuRegister rax = eax; |
| 3434 | CpuRegister rdx = edx; |
| 3435 | |
| 3436 | CalculateMagicAndShiftForDivRem(imm, true /* is_long */, &magic, &shift); |
| 3437 | |
| 3438 | // Save the numerator. |
| 3439 | __ movq(numerator, rax); |
| 3440 | |
| 3441 | // RAX = magic |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3442 | codegen_->Load64BitValue(rax, magic); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3443 | |
| 3444 | // RDX:RAX = magic * numerator |
| 3445 | __ imulq(numerator); |
| 3446 | |
| 3447 | if (imm > 0 && magic < 0) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3448 | // RDX += numerator |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3449 | __ addq(rdx, numerator); |
| 3450 | } else if (imm < 0 && magic > 0) { |
| 3451 | // RDX -= numerator |
| 3452 | __ subq(rdx, numerator); |
| 3453 | } |
| 3454 | |
| 3455 | // Shift if needed. |
| 3456 | if (shift != 0) { |
| 3457 | __ sarq(rdx, Immediate(shift)); |
| 3458 | } |
| 3459 | |
| 3460 | // RDX += 1 if RDX < 0 |
| 3461 | __ movq(rax, rdx); |
| 3462 | __ shrq(rdx, Immediate(63)); |
| 3463 | __ addq(rdx, rax); |
| 3464 | |
| 3465 | if (instruction->IsRem()) { |
| 3466 | __ movq(rax, numerator); |
| 3467 | |
| 3468 | if (IsInt<32>(imm)) { |
| 3469 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 3470 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3471 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3472 | } |
| 3473 | |
| 3474 | __ subq(rax, rdx); |
| 3475 | __ movq(rdx, rax); |
| 3476 | } else { |
| 3477 | __ movq(rax, rdx); |
| 3478 | } |
| 3479 | } |
| 3480 | } |
| 3481 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3482 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3483 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3484 | Primitive::Type type = instruction->GetResultType(); |
| 3485 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 3486 | |
| 3487 | bool is_div = instruction->IsDiv(); |
| 3488 | LocationSummary* locations = instruction->GetLocations(); |
| 3489 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3490 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3491 | Location second = locations->InAt(1); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3492 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3493 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3494 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3495 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3496 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3497 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3498 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3499 | if (imm == 0) { |
| 3500 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3501 | } else if (imm == 1 || imm == -1) { |
| 3502 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3503 | } else if (instruction->IsDiv() && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3504 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3505 | } else { |
| 3506 | DCHECK(imm <= -2 || imm >= 2); |
| 3507 | GenerateDivRemWithAnyConstant(instruction); |
| 3508 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3509 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3510 | SlowPathCode* slow_path = |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3511 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86_64( |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3512 | instruction, out.AsRegister(), type, is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3513 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3514 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3515 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3516 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3517 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3518 | // so it's safe to just use negl instead of more complex comparisons. |
| 3519 | if (type == Primitive::kPrimInt) { |
| 3520 | __ cmpl(second_reg, Immediate(-1)); |
| 3521 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3522 | // edx:eax <- sign-extended of eax |
| 3523 | __ cdq(); |
| 3524 | // eax = quotient, edx = remainder |
| 3525 | __ idivl(second_reg); |
| 3526 | } else { |
| 3527 | __ cmpq(second_reg, Immediate(-1)); |
| 3528 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3529 | // rdx:rax <- sign-extended of rax |
| 3530 | __ cqo(); |
| 3531 | // rax = quotient, rdx = remainder |
| 3532 | __ idivq(second_reg); |
| 3533 | } |
| 3534 | __ Bind(slow_path->GetExitLabel()); |
| 3535 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3536 | } |
| 3537 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3538 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3539 | LocationSummary* locations = |
| 3540 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3541 | switch (div->GetResultType()) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3542 | case Primitive::kPrimInt: |
| 3543 | case Primitive::kPrimLong: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3544 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3545 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3546 | locations->SetOut(Location::SameAsFirstInput()); |
| 3547 | // Intel uses edx:eax as the dividend. |
| 3548 | locations->AddTemp(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3549 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3550 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3551 | // output and request another temp. |
| 3552 | if (div->InputAt(1)->IsConstant()) { |
| 3553 | locations->AddTemp(Location::RequiresRegister()); |
| 3554 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3555 | break; |
| 3556 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3557 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3558 | case Primitive::kPrimFloat: |
| 3559 | case Primitive::kPrimDouble: { |
| 3560 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3561 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3562 | locations->SetOut(Location::SameAsFirstInput()); |
| 3563 | break; |
| 3564 | } |
| 3565 | |
| 3566 | default: |
| 3567 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3568 | } |
| 3569 | } |
| 3570 | |
| 3571 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3572 | LocationSummary* locations = div->GetLocations(); |
| 3573 | Location first = locations->InAt(0); |
| 3574 | Location second = locations->InAt(1); |
| 3575 | DCHECK(first.Equals(locations->Out())); |
| 3576 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3577 | Primitive::Type type = div->GetResultType(); |
| 3578 | switch (type) { |
| 3579 | case Primitive::kPrimInt: |
| 3580 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3581 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3582 | break; |
| 3583 | } |
| 3584 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3585 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3586 | if (second.IsFpuRegister()) { |
| 3587 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3588 | } else if (second.IsConstant()) { |
| 3589 | __ divss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3590 | codegen_->LiteralFloatAddress( |
| 3591 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3592 | } else { |
| 3593 | DCHECK(second.IsStackSlot()); |
| 3594 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3595 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3596 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3597 | break; |
| 3598 | } |
| 3599 | |
| 3600 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3601 | if (second.IsFpuRegister()) { |
| 3602 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3603 | } else if (second.IsConstant()) { |
| 3604 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3605 | codegen_->LiteralDoubleAddress( |
| 3606 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3607 | } else { |
| 3608 | DCHECK(second.IsDoubleStackSlot()); |
| 3609 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3610 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3611 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3612 | break; |
| 3613 | } |
| 3614 | |
| 3615 | default: |
| 3616 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3617 | } |
| 3618 | } |
| 3619 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3620 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3621 | Primitive::Type type = rem->GetResultType(); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3622 | LocationSummary* locations = |
| 3623 | new (GetGraph()->GetArena()) LocationSummary(rem, LocationSummary::kNoCall); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3624 | |
| 3625 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3626 | case Primitive::kPrimInt: |
| 3627 | case Primitive::kPrimLong: { |
| 3628 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3629 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3630 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3631 | locations->SetOut(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3632 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3633 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3634 | // output and request another temp. |
| 3635 | if (rem->InputAt(1)->IsConstant()) { |
| 3636 | locations->AddTemp(Location::RequiresRegister()); |
| 3637 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3638 | break; |
| 3639 | } |
| 3640 | |
| 3641 | case Primitive::kPrimFloat: |
| 3642 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3643 | locations->SetInAt(0, Location::Any()); |
| 3644 | locations->SetInAt(1, Location::Any()); |
| 3645 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3646 | locations->AddTemp(Location::RegisterLocation(RAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3647 | break; |
| 3648 | } |
| 3649 | |
| 3650 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3651 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3652 | } |
| 3653 | } |
| 3654 | |
| 3655 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| 3656 | Primitive::Type type = rem->GetResultType(); |
| 3657 | switch (type) { |
| 3658 | case Primitive::kPrimInt: |
| 3659 | case Primitive::kPrimLong: { |
| 3660 | GenerateDivRemIntegral(rem); |
| 3661 | break; |
| 3662 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3663 | case Primitive::kPrimFloat: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3664 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3665 | GenerateRemFP(rem); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3666 | break; |
| 3667 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3668 | default: |
| 3669 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3670 | } |
| 3671 | } |
| 3672 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3673 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3674 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3675 | ? LocationSummary::kCallOnSlowPath |
| 3676 | : LocationSummary::kNoCall; |
| 3677 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3678 | locations->SetInAt(0, Location::Any()); |
| 3679 | if (instruction->HasUses()) { |
| 3680 | locations->SetOut(Location::SameAsFirstInput()); |
| 3681 | } |
| 3682 | } |
| 3683 | |
| 3684 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3685 | SlowPathCode* slow_path = |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3686 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction); |
| 3687 | codegen_->AddSlowPath(slow_path); |
| 3688 | |
| 3689 | LocationSummary* locations = instruction->GetLocations(); |
| 3690 | Location value = locations->InAt(0); |
| 3691 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3692 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3693 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3694 | case Primitive::kPrimByte: |
| 3695 | case Primitive::kPrimChar: |
| 3696 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3697 | case Primitive::kPrimInt: { |
| 3698 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3699 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3700 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3701 | } else if (value.IsStackSlot()) { |
| 3702 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3703 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3704 | } else { |
| 3705 | DCHECK(value.IsConstant()) << value; |
| 3706 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3707 | __ jmp(slow_path->GetEntryLabel()); |
| 3708 | } |
| 3709 | } |
| 3710 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3711 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3712 | case Primitive::kPrimLong: { |
| 3713 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3714 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3715 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3716 | } else if (value.IsDoubleStackSlot()) { |
| 3717 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3718 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3719 | } else { |
| 3720 | DCHECK(value.IsConstant()) << value; |
| 3721 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3722 | __ jmp(slow_path->GetEntryLabel()); |
| 3723 | } |
| 3724 | } |
| 3725 | break; |
| 3726 | } |
| 3727 | default: |
| 3728 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3729 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3730 | } |
| 3731 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3732 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 3733 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3734 | |
| 3735 | LocationSummary* locations = |
| 3736 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3737 | |
| 3738 | switch (op->GetResultType()) { |
| 3739 | case Primitive::kPrimInt: |
| 3740 | case Primitive::kPrimLong: { |
| 3741 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3742 | // The shift count needs to be in CL. |
| 3743 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 3744 | locations->SetOut(Location::SameAsFirstInput()); |
| 3745 | break; |
| 3746 | } |
| 3747 | default: |
| 3748 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3749 | } |
| 3750 | } |
| 3751 | |
| 3752 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 3753 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3754 | |
| 3755 | LocationSummary* locations = op->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3756 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3757 | Location second = locations->InAt(1); |
| 3758 | |
| 3759 | switch (op->GetResultType()) { |
| 3760 | case Primitive::kPrimInt: { |
| 3761 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3762 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3763 | if (op->IsShl()) { |
| 3764 | __ shll(first_reg, second_reg); |
| 3765 | } else if (op->IsShr()) { |
| 3766 | __ sarl(first_reg, second_reg); |
| 3767 | } else { |
| 3768 | __ shrl(first_reg, second_reg); |
| 3769 | } |
| 3770 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3771 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3772 | if (op->IsShl()) { |
| 3773 | __ shll(first_reg, imm); |
| 3774 | } else if (op->IsShr()) { |
| 3775 | __ sarl(first_reg, imm); |
| 3776 | } else { |
| 3777 | __ shrl(first_reg, imm); |
| 3778 | } |
| 3779 | } |
| 3780 | break; |
| 3781 | } |
| 3782 | case Primitive::kPrimLong: { |
| 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 | __ shlq(first_reg, second_reg); |
| 3787 | } else if (op->IsShr()) { |
| 3788 | __ sarq(first_reg, second_reg); |
| 3789 | } else { |
| 3790 | __ shrq(first_reg, second_reg); |
| 3791 | } |
| 3792 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3793 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3794 | if (op->IsShl()) { |
| 3795 | __ shlq(first_reg, imm); |
| 3796 | } else if (op->IsShr()) { |
| 3797 | __ sarq(first_reg, imm); |
| 3798 | } else { |
| 3799 | __ shrq(first_reg, imm); |
| 3800 | } |
| 3801 | } |
| 3802 | break; |
| 3803 | } |
| 3804 | default: |
| 3805 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3806 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3807 | } |
| 3808 | } |
| 3809 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3810 | void LocationsBuilderX86_64::VisitRor(HRor* ror) { |
| 3811 | LocationSummary* locations = |
| 3812 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3813 | |
| 3814 | switch (ror->GetResultType()) { |
| 3815 | case Primitive::kPrimInt: |
| 3816 | case Primitive::kPrimLong: { |
| 3817 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3818 | // The shift count needs to be in CL (unless it is a constant). |
| 3819 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, ror->InputAt(1))); |
| 3820 | locations->SetOut(Location::SameAsFirstInput()); |
| 3821 | break; |
| 3822 | } |
| 3823 | default: |
| 3824 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3825 | UNREACHABLE(); |
| 3826 | } |
| 3827 | } |
| 3828 | |
| 3829 | void InstructionCodeGeneratorX86_64::VisitRor(HRor* ror) { |
| 3830 | LocationSummary* locations = ror->GetLocations(); |
| 3831 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3832 | Location second = locations->InAt(1); |
| 3833 | |
| 3834 | switch (ror->GetResultType()) { |
| 3835 | case Primitive::kPrimInt: |
| 3836 | if (second.IsRegister()) { |
| 3837 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3838 | __ rorl(first_reg, second_reg); |
| 3839 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3840 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3841 | __ rorl(first_reg, imm); |
| 3842 | } |
| 3843 | break; |
| 3844 | case Primitive::kPrimLong: |
| 3845 | if (second.IsRegister()) { |
| 3846 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3847 | __ rorq(first_reg, second_reg); |
| 3848 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3849 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3850 | __ rorq(first_reg, imm); |
| 3851 | } |
| 3852 | break; |
| 3853 | default: |
| 3854 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3855 | UNREACHABLE(); |
| 3856 | } |
| 3857 | } |
| 3858 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3859 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 3860 | HandleShift(shl); |
| 3861 | } |
| 3862 | |
| 3863 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 3864 | HandleShift(shl); |
| 3865 | } |
| 3866 | |
| 3867 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 3868 | HandleShift(shr); |
| 3869 | } |
| 3870 | |
| 3871 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 3872 | HandleShift(shr); |
| 3873 | } |
| 3874 | |
| 3875 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 3876 | HandleShift(ushr); |
| 3877 | } |
| 3878 | |
| 3879 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 3880 | HandleShift(ushr); |
| 3881 | } |
| 3882 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3883 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3884 | LocationSummary* locations = |
| 3885 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3886 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3887 | if (instruction->IsStringAlloc()) { |
| 3888 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3889 | } else { |
| 3890 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3891 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3892 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3893 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3894 | } |
| 3895 | |
| 3896 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3897 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3898 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3899 | if (instruction->IsStringAlloc()) { |
| 3900 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3901 | CpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
| 3902 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64WordSize); |
| 3903 | __ gs()->movq(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString), /* no_rip */ true)); |
| 3904 | __ call(Address(temp, code_offset.SizeValue())); |
| 3905 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3906 | } else { |
| 3907 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3908 | instruction, |
| 3909 | instruction->GetDexPc(), |
| 3910 | nullptr); |
| 3911 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 3912 | DCHECK(!codegen_->IsLeafMethod()); |
| 3913 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3914 | } |
| 3915 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3916 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 3917 | LocationSummary* locations = |
| 3918 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3919 | InvokeRuntimeCallingConvention calling_convention; |
| 3920 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3921 | locations->SetOut(Location::RegisterLocation(RAX)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3922 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3923 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3924 | } |
| 3925 | |
| 3926 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| 3927 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3928 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 3929 | instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3930 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3931 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3932 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3933 | instruction, |
| 3934 | instruction->GetDexPc(), |
| 3935 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3936 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3937 | |
| 3938 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3939 | } |
| 3940 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3941 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3942 | LocationSummary* locations = |
| 3943 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3944 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3945 | if (location.IsStackSlot()) { |
| 3946 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3947 | } else if (location.IsDoubleStackSlot()) { |
| 3948 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3949 | } |
| 3950 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3951 | } |
| 3952 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3953 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 3954 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3955 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3956 | } |
| 3957 | |
| 3958 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3959 | LocationSummary* locations = |
| 3960 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3961 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3962 | } |
| 3963 | |
| 3964 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 3965 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3966 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3967 | } |
| 3968 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3969 | void LocationsBuilderX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 3970 | LocationSummary* locations = |
| 3971 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3972 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3973 | locations->SetOut(Location::RequiresRegister()); |
| 3974 | } |
| 3975 | |
| 3976 | void InstructionCodeGeneratorX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 3977 | LocationSummary* locations = instruction->GetLocations(); |
| 3978 | uint32_t method_offset = 0; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3979 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3980 | method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 3981 | instruction->GetIndex(), kX86_64PointerSize).SizeValue(); |
| 3982 | } else { |
| 3983 | method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 3984 | instruction->GetIndex() % mirror::Class::kImtSize, kX86_64PointerSize).Uint32Value(); |
| 3985 | } |
| 3986 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 3987 | Address(locations->InAt(0).AsRegister<CpuRegister>(), method_offset)); |
| 3988 | } |
| 3989 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3990 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3991 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3992 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3993 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3994 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3995 | } |
| 3996 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3997 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 3998 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3999 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4000 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4001 | Location out = locations->Out(); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4002 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4003 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4004 | __ notl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4005 | break; |
| 4006 | |
| 4007 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4008 | __ notq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4009 | break; |
| 4010 | |
| 4011 | default: |
| 4012 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4013 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4014 | } |
| 4015 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4016 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4017 | LocationSummary* locations = |
| 4018 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4019 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4020 | locations->SetOut(Location::SameAsFirstInput()); |
| 4021 | } |
| 4022 | |
| 4023 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4024 | LocationSummary* locations = bool_not->GetLocations(); |
| 4025 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4026 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 4027 | Location out = locations->Out(); |
| 4028 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 4029 | } |
| 4030 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4031 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4032 | LocationSummary* locations = |
| 4033 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4034 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 4035 | locations->SetInAt(i, Location::Any()); |
| 4036 | } |
| 4037 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4038 | } |
| 4039 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4040 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4041 | LOG(FATAL) << "Unimplemented"; |
| 4042 | } |
| 4043 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4044 | void CodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4045 | /* |
| 4046 | * 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] | 4047 | * 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] | 4048 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4049 | */ |
| 4050 | switch (kind) { |
| 4051 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4052 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4053 | break; |
| 4054 | } |
| 4055 | case MemBarrierKind::kAnyStore: |
| 4056 | case MemBarrierKind::kLoadAny: |
| 4057 | case MemBarrierKind::kStoreStore: { |
| 4058 | // nop |
| 4059 | break; |
| 4060 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame^] | 4061 | case MemBarrierKind::kNTStoreStore: |
| 4062 | // Non-Temporal Store/Store needs an explicit fence. |
| 4063 | MemoryFence(/* non-temporal */ true); |
| 4064 | break; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4065 | } |
| 4066 | } |
| 4067 | |
| 4068 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 4069 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4070 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4071 | bool object_field_get_with_read_barrier = |
| 4072 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4073 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4074 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4075 | object_field_get_with_read_barrier ? |
| 4076 | LocationSummary::kCallOnSlowPath : |
| 4077 | LocationSummary::kNoCall); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4078 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4079 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4080 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4081 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4082 | // The output overlaps for an object field get when read barriers |
| 4083 | // are enabled: we do not want the move to overwrite the object's |
| 4084 | // location, as we need it to emit the read barrier. |
| 4085 | locations->SetOut( |
| 4086 | Location::RequiresRegister(), |
| 4087 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4088 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4089 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4090 | // We need a temporary register for the read barrier marking slow |
| 4091 | // path in CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier. |
| 4092 | locations->AddTemp(Location::RequiresRegister()); |
| 4093 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4094 | } |
| 4095 | |
| 4096 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 4097 | const FieldInfo& field_info) { |
| 4098 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4099 | |
| 4100 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4101 | Location base_loc = locations->InAt(0); |
| 4102 | CpuRegister base = base_loc.AsRegister<CpuRegister>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4103 | Location out = locations->Out(); |
| 4104 | bool is_volatile = field_info.IsVolatile(); |
| 4105 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4106 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4107 | |
| 4108 | switch (field_type) { |
| 4109 | case Primitive::kPrimBoolean: { |
| 4110 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4111 | break; |
| 4112 | } |
| 4113 | |
| 4114 | case Primitive::kPrimByte: { |
| 4115 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4116 | break; |
| 4117 | } |
| 4118 | |
| 4119 | case Primitive::kPrimShort: { |
| 4120 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4121 | break; |
| 4122 | } |
| 4123 | |
| 4124 | case Primitive::kPrimChar: { |
| 4125 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4126 | break; |
| 4127 | } |
| 4128 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4129 | case Primitive::kPrimInt: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4130 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4131 | break; |
| 4132 | } |
| 4133 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4134 | case Primitive::kPrimNot: { |
| 4135 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4136 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4137 | Location temp_loc = locations->GetTemp(0); |
| 4138 | // Note that a potential implicit null check is handled in this |
| 4139 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4140 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4141 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4142 | if (is_volatile) { |
| 4143 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4144 | } |
| 4145 | } else { |
| 4146 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4147 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4148 | if (is_volatile) { |
| 4149 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4150 | } |
| 4151 | // If read barriers are enabled, emit read barriers other than |
| 4152 | // Baker's using a slow path (and also unpoison the loaded |
| 4153 | // reference, if heap poisoning is enabled). |
| 4154 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4155 | } |
| 4156 | break; |
| 4157 | } |
| 4158 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4159 | case Primitive::kPrimLong: { |
| 4160 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4161 | break; |
| 4162 | } |
| 4163 | |
| 4164 | case Primitive::kPrimFloat: { |
| 4165 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4166 | break; |
| 4167 | } |
| 4168 | |
| 4169 | case Primitive::kPrimDouble: { |
| 4170 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4171 | break; |
| 4172 | } |
| 4173 | |
| 4174 | case Primitive::kPrimVoid: |
| 4175 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4176 | UNREACHABLE(); |
| 4177 | } |
| 4178 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4179 | if (field_type == Primitive::kPrimNot) { |
| 4180 | // Potential implicit null checks, in the case of reference |
| 4181 | // fields, are handled in the previous switch statement. |
| 4182 | } else { |
| 4183 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4184 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4185 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4186 | if (is_volatile) { |
| 4187 | if (field_type == Primitive::kPrimNot) { |
| 4188 | // Memory barriers, in the case of references, are also handled |
| 4189 | // in the previous switch statement. |
| 4190 | } else { |
| 4191 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4192 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4193 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4194 | } |
| 4195 | |
| 4196 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 4197 | const FieldInfo& field_info) { |
| 4198 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4199 | |
| 4200 | LocationSummary* locations = |
| 4201 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4202 | Primitive::Type field_type = field_info.GetFieldType(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4203 | bool is_volatile = field_info.IsVolatile(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4204 | bool needs_write_barrier = |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4205 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4206 | |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4207 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4208 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4209 | if (is_volatile) { |
| 4210 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4211 | locations->SetInAt(1, Location::FpuRegisterOrInt32Constant(instruction->InputAt(1))); |
| 4212 | } else { |
| 4213 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4214 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4215 | } else { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4216 | if (is_volatile) { |
| 4217 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4218 | locations->SetInAt(1, Location::RegisterOrInt32Constant(instruction->InputAt(1))); |
| 4219 | } else { |
| 4220 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4221 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4222 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4223 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4224 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4225 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4226 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4227 | } else if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4228 | // Temporary register for the reference poisoning. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4229 | locations->AddTemp(Location::RequiresRegister()); |
| 4230 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4231 | } |
| 4232 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4233 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4234 | const FieldInfo& field_info, |
| 4235 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4236 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4237 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4238 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4239 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4240 | Location value = locations->InAt(1); |
| 4241 | bool is_volatile = field_info.IsVolatile(); |
| 4242 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4243 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4244 | |
| 4245 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4246 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4247 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4248 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4249 | bool maybe_record_implicit_null_check_done = false; |
| 4250 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4251 | switch (field_type) { |
| 4252 | case Primitive::kPrimBoolean: |
| 4253 | case Primitive::kPrimByte: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4254 | if (value.IsConstant()) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4255 | int8_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4256 | __ movb(Address(base, offset), Immediate(v)); |
| 4257 | } else { |
| 4258 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4259 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4260 | break; |
| 4261 | } |
| 4262 | |
| 4263 | case Primitive::kPrimShort: |
| 4264 | case Primitive::kPrimChar: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4265 | if (value.IsConstant()) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4266 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4267 | __ movw(Address(base, offset), Immediate(v)); |
| 4268 | } else { |
| 4269 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4270 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4271 | break; |
| 4272 | } |
| 4273 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4274 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4275 | case Primitive::kPrimNot: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4276 | if (value.IsConstant()) { |
| 4277 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4278 | // `field_type == Primitive::kPrimNot` implies `v == 0`. |
| 4279 | DCHECK((field_type != Primitive::kPrimNot) || (v == 0)); |
| 4280 | // Note: if heap poisoning is enabled, no need to poison |
| 4281 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 4282 | __ movl(Address(base, offset), Immediate(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4283 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4284 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4285 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4286 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4287 | __ PoisonHeapReference(temp); |
| 4288 | __ movl(Address(base, offset), temp); |
| 4289 | } else { |
| 4290 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4291 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4292 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4293 | break; |
| 4294 | } |
| 4295 | |
| 4296 | case Primitive::kPrimLong: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4297 | if (value.IsConstant()) { |
| 4298 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4299 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4300 | Address(base, offset + sizeof(int32_t)), |
| 4301 | v, |
| 4302 | instruction); |
| 4303 | maybe_record_implicit_null_check_done = true; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4304 | } else { |
| 4305 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4306 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4307 | break; |
| 4308 | } |
| 4309 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4310 | case Primitive::kPrimFloat: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4311 | if (value.IsConstant()) { |
| 4312 | int32_t v = |
| 4313 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4314 | __ movl(Address(base, offset), Immediate(v)); |
| 4315 | } else { |
| 4316 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4317 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4318 | break; |
| 4319 | } |
| 4320 | |
| 4321 | case Primitive::kPrimDouble: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4322 | if (value.IsConstant()) { |
| 4323 | int64_t v = |
| 4324 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4325 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4326 | Address(base, offset + sizeof(int32_t)), |
| 4327 | v, |
| 4328 | instruction); |
| 4329 | maybe_record_implicit_null_check_done = true; |
| 4330 | } else { |
| 4331 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4332 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4333 | break; |
| 4334 | } |
| 4335 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4336 | case Primitive::kPrimVoid: |
| 4337 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4338 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4339 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4340 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4341 | if (!maybe_record_implicit_null_check_done) { |
| 4342 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4343 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4344 | |
| 4345 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4346 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4347 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4348 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4349 | } |
| 4350 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4351 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4352 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4353 | } |
| 4354 | } |
| 4355 | |
| 4356 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4357 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4358 | } |
| 4359 | |
| 4360 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4361 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4362 | } |
| 4363 | |
| 4364 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4365 | HandleFieldGet(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4366 | } |
| 4367 | |
| 4368 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4369 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4370 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4371 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4372 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4373 | HandleFieldGet(instruction); |
| 4374 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4375 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4376 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4377 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4378 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4379 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4380 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4381 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4382 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4383 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4384 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4385 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4386 | } |
| 4387 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4388 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldGet( |
| 4389 | HUnresolvedInstanceFieldGet* instruction) { |
| 4390 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4391 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4392 | instruction, instruction->GetFieldType(), calling_convention); |
| 4393 | } |
| 4394 | |
| 4395 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldGet( |
| 4396 | HUnresolvedInstanceFieldGet* instruction) { |
| 4397 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4398 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4399 | instruction->GetFieldType(), |
| 4400 | instruction->GetFieldIndex(), |
| 4401 | instruction->GetDexPc(), |
| 4402 | calling_convention); |
| 4403 | } |
| 4404 | |
| 4405 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldSet( |
| 4406 | HUnresolvedInstanceFieldSet* instruction) { |
| 4407 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4408 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4409 | instruction, instruction->GetFieldType(), calling_convention); |
| 4410 | } |
| 4411 | |
| 4412 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldSet( |
| 4413 | HUnresolvedInstanceFieldSet* instruction) { |
| 4414 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4415 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4416 | instruction->GetFieldType(), |
| 4417 | instruction->GetFieldIndex(), |
| 4418 | instruction->GetDexPc(), |
| 4419 | calling_convention); |
| 4420 | } |
| 4421 | |
| 4422 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldGet( |
| 4423 | HUnresolvedStaticFieldGet* instruction) { |
| 4424 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4425 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4426 | instruction, instruction->GetFieldType(), calling_convention); |
| 4427 | } |
| 4428 | |
| 4429 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldGet( |
| 4430 | HUnresolvedStaticFieldGet* instruction) { |
| 4431 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4432 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4433 | instruction->GetFieldType(), |
| 4434 | instruction->GetFieldIndex(), |
| 4435 | instruction->GetDexPc(), |
| 4436 | calling_convention); |
| 4437 | } |
| 4438 | |
| 4439 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldSet( |
| 4440 | HUnresolvedStaticFieldSet* instruction) { |
| 4441 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4442 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4443 | instruction, instruction->GetFieldType(), calling_convention); |
| 4444 | } |
| 4445 | |
| 4446 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldSet( |
| 4447 | HUnresolvedStaticFieldSet* instruction) { |
| 4448 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4449 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4450 | instruction->GetFieldType(), |
| 4451 | instruction->GetFieldIndex(), |
| 4452 | instruction->GetDexPc(), |
| 4453 | calling_convention); |
| 4454 | } |
| 4455 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4456 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4457 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4458 | ? LocationSummary::kCallOnSlowPath |
| 4459 | : LocationSummary::kNoCall; |
| 4460 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4461 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4462 | ? Location::RequiresRegister() |
| 4463 | : Location::Any(); |
| 4464 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4465 | if (instruction->HasUses()) { |
| 4466 | locations->SetOut(Location::SameAsFirstInput()); |
| 4467 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4468 | } |
| 4469 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4470 | void CodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4471 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4472 | return; |
| 4473 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4474 | LocationSummary* locations = instruction->GetLocations(); |
| 4475 | Location obj = locations->InAt(0); |
| 4476 | |
| 4477 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4478 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4479 | } |
| 4480 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4481 | void CodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4482 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4483 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4484 | |
| 4485 | LocationSummary* locations = instruction->GetLocations(); |
| 4486 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4487 | |
| 4488 | if (obj.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4489 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4490 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4491 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4492 | } else { |
| 4493 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4494 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4495 | __ jmp(slow_path->GetEntryLabel()); |
| 4496 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4497 | } |
| 4498 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4499 | } |
| 4500 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4501 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4502 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4503 | } |
| 4504 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4505 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4506 | bool object_array_get_with_read_barrier = |
| 4507 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4508 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4509 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4510 | object_array_get_with_read_barrier ? |
| 4511 | LocationSummary::kCallOnSlowPath : |
| 4512 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4513 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4514 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4515 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4516 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4517 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4518 | // The output overlaps for an object array get when read barriers |
| 4519 | // are enabled: we do not want the move to overwrite the array's |
| 4520 | // location, as we need it to emit the read barrier. |
| 4521 | locations->SetOut( |
| 4522 | Location::RequiresRegister(), |
| 4523 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4524 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4525 | // We need a temporary register for the read barrier marking slow |
| 4526 | // path in CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier. |
| 4527 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4528 | locations->AddTemp(Location::RequiresRegister()); |
| 4529 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4530 | } |
| 4531 | |
| 4532 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 4533 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4534 | Location obj_loc = locations->InAt(0); |
| 4535 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4536 | Location index = locations->InAt(1); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4537 | Location out_loc = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4538 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4539 | Primitive::Type type = instruction->GetType(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4540 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4541 | case Primitive::kPrimBoolean: { |
| 4542 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4543 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4544 | if (index.IsConstant()) { |
| 4545 | __ movzxb(out, Address(obj, |
| 4546 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4547 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4548 | __ movzxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4549 | } |
| 4550 | break; |
| 4551 | } |
| 4552 | |
| 4553 | case Primitive::kPrimByte: { |
| 4554 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4555 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4556 | if (index.IsConstant()) { |
| 4557 | __ movsxb(out, Address(obj, |
| 4558 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4559 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4560 | __ movsxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4561 | } |
| 4562 | break; |
| 4563 | } |
| 4564 | |
| 4565 | case Primitive::kPrimShort: { |
| 4566 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_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 | __ movsxw(out, Address(obj, |
| 4570 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4571 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4572 | __ movsxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4573 | } |
| 4574 | break; |
| 4575 | } |
| 4576 | |
| 4577 | case Primitive::kPrimChar: { |
| 4578 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_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 | __ movzxw(out, Address(obj, |
| 4582 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4583 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4584 | __ movzxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4585 | } |
| 4586 | break; |
| 4587 | } |
| 4588 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4589 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4590 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_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 | __ movl(out, Address(obj, |
| 4594 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4595 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4596 | __ movl(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4597 | } |
| 4598 | break; |
| 4599 | } |
| 4600 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4601 | case Primitive::kPrimNot: { |
| 4602 | static_assert( |
| 4603 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4604 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 4605 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4606 | // /* HeapReference<Object> */ out = |
| 4607 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4608 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4609 | Location temp = locations->GetTemp(0); |
| 4610 | // Note that a potential implicit null check is handled in this |
| 4611 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 4612 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 4613 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 4614 | } else { |
| 4615 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| 4616 | if (index.IsConstant()) { |
| 4617 | uint32_t offset = |
| 4618 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4619 | __ movl(out, Address(obj, offset)); |
| 4620 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4621 | // If read barriers are enabled, emit read barriers other than |
| 4622 | // Baker's using a slow path (and also unpoison the loaded |
| 4623 | // reference, if heap poisoning is enabled). |
| 4624 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 4625 | } else { |
| 4626 | __ movl(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
| 4627 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4628 | // If read barriers are enabled, emit read barriers other than |
| 4629 | // Baker's using a slow path (and also unpoison the loaded |
| 4630 | // reference, if heap poisoning is enabled). |
| 4631 | codegen_->MaybeGenerateReadBarrierSlow( |
| 4632 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 4633 | } |
| 4634 | } |
| 4635 | break; |
| 4636 | } |
| 4637 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4638 | case Primitive::kPrimLong: { |
| 4639 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4640 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4641 | if (index.IsConstant()) { |
| 4642 | __ movq(out, Address(obj, |
| 4643 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4644 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4645 | __ movq(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4646 | } |
| 4647 | break; |
| 4648 | } |
| 4649 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4650 | case Primitive::kPrimFloat: { |
| 4651 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4652 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4653 | if (index.IsConstant()) { |
| 4654 | __ movss(out, Address(obj, |
| 4655 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4656 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4657 | __ movss(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4658 | } |
| 4659 | break; |
| 4660 | } |
| 4661 | |
| 4662 | case Primitive::kPrimDouble: { |
| 4663 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4664 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4665 | if (index.IsConstant()) { |
| 4666 | __ movsd(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 | __ movsd(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4670 | } |
| 4671 | break; |
| 4672 | } |
| 4673 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4674 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4675 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4676 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4677 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4678 | |
| 4679 | if (type == Primitive::kPrimNot) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4680 | // Potential implicit null checks, in the case of reference |
| 4681 | // arrays, are handled in the previous switch statement. |
| 4682 | } else { |
| 4683 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4684 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4685 | } |
| 4686 | |
| 4687 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4688 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4689 | |
| 4690 | bool needs_write_barrier = |
| 4691 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4692 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4693 | bool object_array_set_with_read_barrier = |
| 4694 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4695 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4696 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4697 | instruction, |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4698 | (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] | 4699 | LocationSummary::kCallOnSlowPath : |
| 4700 | LocationSummary::kNoCall); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4701 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4702 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4703 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4704 | if (Primitive::IsFloatingPointType(value_type)) { |
| 4705 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4706 | } else { |
| 4707 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 4708 | } |
| 4709 | |
| 4710 | if (needs_write_barrier) { |
| 4711 | // Temporary registers for the write barrier. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4712 | |
| 4713 | // This first temporary register is possibly used for heap |
| 4714 | // reference poisoning and/or read barrier emission too. |
| 4715 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4716 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4717 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4718 | } |
| 4719 | |
| 4720 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 4721 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4722 | Location array_loc = locations->InAt(0); |
| 4723 | CpuRegister array = array_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4724 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4725 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4726 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4727 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4728 | bool needs_write_barrier = |
| 4729 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4730 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4731 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4732 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4733 | |
| 4734 | switch (value_type) { |
| 4735 | case Primitive::kPrimBoolean: |
| 4736 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4737 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 4738 | Address address = index.IsConstant() |
| 4739 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 4740 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_1, offset); |
| 4741 | if (value.IsRegister()) { |
| 4742 | __ movb(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4743 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4744 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4745 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4746 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4747 | break; |
| 4748 | } |
| 4749 | |
| 4750 | case Primitive::kPrimShort: |
| 4751 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4752 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 4753 | Address address = index.IsConstant() |
| 4754 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 4755 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_2, offset); |
| 4756 | if (value.IsRegister()) { |
| 4757 | __ movw(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4758 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4759 | DCHECK(value.IsConstant()) << value; |
| 4760 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4761 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4762 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4763 | break; |
| 4764 | } |
| 4765 | |
| 4766 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4767 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4768 | Address address = index.IsConstant() |
| 4769 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4770 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4771 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4772 | if (!value.IsRegister()) { |
| 4773 | // Just setting null. |
| 4774 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 4775 | DCHECK(value.IsConstant()) << value; |
| 4776 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4777 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4778 | DCHECK(!needs_write_barrier); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4779 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4780 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4781 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4782 | |
| 4783 | DCHECK(needs_write_barrier); |
| 4784 | CpuRegister register_value = value.AsRegister<CpuRegister>(); |
| 4785 | NearLabel done, not_null, do_put; |
| 4786 | SlowPathCode* slow_path = nullptr; |
| 4787 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4788 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4789 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86_64(instruction); |
| 4790 | codegen_->AddSlowPath(slow_path); |
| 4791 | if (instruction->GetValueCanBeNull()) { |
| 4792 | __ testl(register_value, register_value); |
| 4793 | __ j(kNotEqual, ¬_null); |
| 4794 | __ movl(address, Immediate(0)); |
| 4795 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4796 | __ jmp(&done); |
| 4797 | __ Bind(¬_null); |
| 4798 | } |
| 4799 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4800 | if (kEmitCompilerReadBarrier) { |
| 4801 | // When read barriers are enabled, the type checking |
| 4802 | // instrumentation requires two read barriers: |
| 4803 | // |
| 4804 | // __ movl(temp2, temp); |
| 4805 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 4806 | // __ movl(temp, Address(temp, component_offset)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4807 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4808 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 4809 | // |
| 4810 | // // /* HeapReference<Class> */ temp2 = register_value->klass_ |
| 4811 | // __ movl(temp2, Address(register_value, class_offset)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4812 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4813 | // instruction, temp2_loc, temp2_loc, value, class_offset, temp_loc); |
| 4814 | // |
| 4815 | // __ cmpl(temp, temp2); |
| 4816 | // |
| 4817 | // However, the second read barrier may trash `temp`, as it |
| 4818 | // is a temporary register, and as such would not be saved |
| 4819 | // along with live registers before calling the runtime (nor |
| 4820 | // restored afterwards). So in this case, we bail out and |
| 4821 | // delegate the work to the array set slow path. |
| 4822 | // |
| 4823 | // TODO: Extend the register allocator to support a new |
| 4824 | // "(locally) live temp" location so as to avoid always |
| 4825 | // going into the slow path when read barriers are enabled. |
| 4826 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4827 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4828 | // /* HeapReference<Class> */ temp = array->klass_ |
| 4829 | __ movl(temp, Address(array, class_offset)); |
| 4830 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4831 | __ MaybeUnpoisonHeapReference(temp); |
| 4832 | |
| 4833 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 4834 | __ movl(temp, Address(temp, component_offset)); |
| 4835 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 4836 | // nor the object reference in `register_value->klass`, as |
| 4837 | // we are comparing two poisoned references. |
| 4838 | __ cmpl(temp, Address(register_value, class_offset)); |
| 4839 | |
| 4840 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4841 | __ j(kEqual, &do_put); |
| 4842 | // If heap poisoning is enabled, the `temp` reference has |
| 4843 | // not been unpoisoned yet; unpoison it now. |
| 4844 | __ MaybeUnpoisonHeapReference(temp); |
| 4845 | |
| 4846 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 4847 | __ movl(temp, Address(temp, super_offset)); |
| 4848 | // If heap poisoning is enabled, no need to unpoison |
| 4849 | // `temp`, as we are comparing against null below. |
| 4850 | __ testl(temp, temp); |
| 4851 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4852 | __ Bind(&do_put); |
| 4853 | } else { |
| 4854 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4855 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4856 | } |
| 4857 | } |
| 4858 | |
| 4859 | if (kPoisonHeapReferences) { |
| 4860 | __ movl(temp, register_value); |
| 4861 | __ PoisonHeapReference(temp); |
| 4862 | __ movl(address, temp); |
| 4863 | } else { |
| 4864 | __ movl(address, register_value); |
| 4865 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4866 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4867 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4868 | } |
| 4869 | |
| 4870 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 4871 | codegen_->MarkGCCard( |
| 4872 | temp, card, array, value.AsRegister<CpuRegister>(), instruction->GetValueCanBeNull()); |
| 4873 | __ Bind(&done); |
| 4874 | |
| 4875 | if (slow_path != nullptr) { |
| 4876 | __ Bind(slow_path->GetExitLabel()); |
| 4877 | } |
| 4878 | |
| 4879 | break; |
| 4880 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4881 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4882 | case Primitive::kPrimInt: { |
| 4883 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4884 | Address address = index.IsConstant() |
| 4885 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4886 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
| 4887 | if (value.IsRegister()) { |
| 4888 | __ movl(address, value.AsRegister<CpuRegister>()); |
| 4889 | } else { |
| 4890 | DCHECK(value.IsConstant()) << value; |
| 4891 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4892 | __ movl(address, Immediate(v)); |
| 4893 | } |
| 4894 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4895 | break; |
| 4896 | } |
| 4897 | |
| 4898 | case Primitive::kPrimLong: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4899 | uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| 4900 | Address address = index.IsConstant() |
| 4901 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 4902 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset); |
| 4903 | if (value.IsRegister()) { |
| 4904 | __ movq(address, value.AsRegister<CpuRegister>()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4905 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4906 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4907 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4908 | Address address_high = index.IsConstant() |
| 4909 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 4910 | offset + sizeof(int32_t)) |
| 4911 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset + sizeof(int32_t)); |
| 4912 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4913 | } |
| 4914 | break; |
| 4915 | } |
| 4916 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4917 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4918 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4919 | Address address = index.IsConstant() |
| 4920 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4921 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4922 | if (value.IsFpuRegister()) { |
| 4923 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 4924 | } else { |
| 4925 | DCHECK(value.IsConstant()); |
| 4926 | int32_t v = |
| 4927 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4928 | __ movl(address, Immediate(v)); |
| 4929 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4930 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4931 | break; |
| 4932 | } |
| 4933 | |
| 4934 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4935 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4936 | Address address = index.IsConstant() |
| 4937 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 4938 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4939 | if (value.IsFpuRegister()) { |
| 4940 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 4941 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4942 | } else { |
| 4943 | int64_t v = |
| 4944 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4945 | Address address_high = index.IsConstant() |
| 4946 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 4947 | offset + sizeof(int32_t)) |
| 4948 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset + sizeof(int32_t)); |
| 4949 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| 4950 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4951 | break; |
| 4952 | } |
| 4953 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4954 | case Primitive::kPrimVoid: |
| 4955 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4956 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4957 | } |
| 4958 | } |
| 4959 | |
| 4960 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4961 | LocationSummary* locations = |
| 4962 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4963 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4964 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4965 | } |
| 4966 | |
| 4967 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
| 4968 | LocationSummary* locations = instruction->GetLocations(); |
| 4969 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4970 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4971 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4972 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4973 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4974 | } |
| 4975 | |
| 4976 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4977 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4978 | ? LocationSummary::kCallOnSlowPath |
| 4979 | : LocationSummary::kNoCall; |
| 4980 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4981 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4982 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4983 | if (instruction->HasUses()) { |
| 4984 | locations->SetOut(Location::SameAsFirstInput()); |
| 4985 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4986 | } |
| 4987 | |
| 4988 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4989 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4990 | Location index_loc = locations->InAt(0); |
| 4991 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4992 | SlowPathCode* slow_path = |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4993 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4994 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4995 | if (length_loc.IsConstant()) { |
| 4996 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 4997 | if (index_loc.IsConstant()) { |
| 4998 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 4999 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5000 | if (index < 0 || index >= length) { |
| 5001 | codegen_->AddSlowPath(slow_path); |
| 5002 | __ jmp(slow_path->GetEntryLabel()); |
| 5003 | } else { |
| 5004 | // Some optimization after BCE may have generated this, and we should not |
| 5005 | // generate a bounds check if it is a valid range. |
| 5006 | } |
| 5007 | return; |
| 5008 | } |
| 5009 | |
| 5010 | // We have to reverse the jump condition because the length is the constant. |
| 5011 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 5012 | __ cmpl(index_reg, Immediate(length)); |
| 5013 | codegen_->AddSlowPath(slow_path); |
| 5014 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5015 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5016 | CpuRegister length = length_loc.AsRegister<CpuRegister>(); |
| 5017 | if (index_loc.IsConstant()) { |
| 5018 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5019 | __ cmpl(length, Immediate(value)); |
| 5020 | } else { |
| 5021 | __ cmpl(length, index_loc.AsRegister<CpuRegister>()); |
| 5022 | } |
| 5023 | codegen_->AddSlowPath(slow_path); |
| 5024 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5025 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5026 | } |
| 5027 | |
| 5028 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 5029 | CpuRegister card, |
| 5030 | CpuRegister object, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5031 | CpuRegister value, |
| 5032 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5033 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5034 | if (value_can_be_null) { |
| 5035 | __ testl(value, value); |
| 5036 | __ j(kEqual, &is_null); |
| 5037 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5038 | __ gs()->movq(card, Address::Absolute(Thread::CardTableOffset<kX86_64WordSize>().Int32Value(), |
| 5039 | /* no_rip */ true)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5040 | __ movq(temp, object); |
| 5041 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5042 | __ movb(Address(temp, card, TIMES_1, 0), card); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5043 | if (value_can_be_null) { |
| 5044 | __ Bind(&is_null); |
| 5045 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5046 | } |
| 5047 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5048 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5049 | LOG(FATAL) << "Unimplemented"; |
| 5050 | } |
| 5051 | |
| 5052 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5053 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5054 | } |
| 5055 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5056 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 5057 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 5058 | } |
| 5059 | |
| 5060 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5061 | HBasicBlock* block = instruction->GetBlock(); |
| 5062 | if (block->GetLoopInformation() != nullptr) { |
| 5063 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5064 | // The back edge will generate the suspend check. |
| 5065 | return; |
| 5066 | } |
| 5067 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5068 | // The goto will generate the suspend check. |
| 5069 | return; |
| 5070 | } |
| 5071 | GenerateSuspendCheck(instruction, nullptr); |
| 5072 | } |
| 5073 | |
| 5074 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5075 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5076 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5077 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 5078 | if (slow_path == nullptr) { |
| 5079 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
| 5080 | instruction->SetSlowPath(slow_path); |
| 5081 | codegen_->AddSlowPath(slow_path); |
| 5082 | if (successor != nullptr) { |
| 5083 | DCHECK(successor->IsLoopHeader()); |
| 5084 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5085 | } |
| 5086 | } else { |
| 5087 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5088 | } |
| 5089 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5090 | __ gs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86_64WordSize>().Int32Value(), |
| 5091 | /* no_rip */ true), |
| 5092 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5093 | if (successor == nullptr) { |
| 5094 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5095 | __ Bind(slow_path->GetReturnLabel()); |
| 5096 | } else { |
| 5097 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5098 | __ jmp(slow_path->GetEntryLabel()); |
| 5099 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5100 | } |
| 5101 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5102 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 5103 | return codegen_->GetAssembler(); |
| 5104 | } |
| 5105 | |
| 5106 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5107 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5108 | Location source = move->GetSource(); |
| 5109 | Location destination = move->GetDestination(); |
| 5110 | |
| 5111 | if (source.IsRegister()) { |
| 5112 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5113 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5114 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5115 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5116 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5117 | } else { |
| 5118 | DCHECK(destination.IsDoubleStackSlot()); |
| 5119 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5120 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5121 | } |
| 5122 | } else if (source.IsStackSlot()) { |
| 5123 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5124 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5125 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5126 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5127 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5128 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5129 | } else { |
| 5130 | DCHECK(destination.IsStackSlot()); |
| 5131 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5132 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5133 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5134 | } else if (source.IsDoubleStackSlot()) { |
| 5135 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5136 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5137 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5138 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5139 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 5140 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5141 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 5142 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5143 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5144 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5145 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5146 | } else if (source.IsConstant()) { |
| 5147 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5148 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5149 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5150 | if (destination.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5151 | if (value == 0) { |
| 5152 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 5153 | } else { |
| 5154 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 5155 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5156 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5157 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5158 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5159 | } |
| 5160 | } else if (constant->IsLongConstant()) { |
| 5161 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5162 | if (destination.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5163 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5164 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5165 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5166 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5167 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5168 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5169 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5170 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5171 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5172 | codegen_->Load32BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5173 | } else { |
| 5174 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5175 | Immediate imm(bit_cast<int32_t, float>(fp_value)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5176 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 5177 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5178 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5179 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5180 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5181 | int64_t value = bit_cast<int64_t, double>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5182 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5183 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5184 | codegen_->Load64BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5185 | } else { |
| 5186 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5187 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5188 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5189 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5190 | } else if (source.IsFpuRegister()) { |
| 5191 | if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5192 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5193 | } else if (destination.IsStackSlot()) { |
| 5194 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5195 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5196 | } else { |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 5197 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5198 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5199 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5200 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5201 | } |
| 5202 | } |
| 5203 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5204 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5205 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5206 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 5207 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5208 | } |
| 5209 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5210 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5211 | ScratchRegisterScope ensure_scratch( |
| 5212 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 5213 | |
| 5214 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5215 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5216 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 5217 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5218 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5219 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5220 | CpuRegister(ensure_scratch.GetRegister())); |
| 5221 | } |
| 5222 | |
Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5223 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg1, CpuRegister reg2) { |
| 5224 | __ movq(CpuRegister(TMP), reg1); |
| 5225 | __ movq(reg1, reg2); |
| 5226 | __ movq(reg2, CpuRegister(TMP)); |
| 5227 | } |
| 5228 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5229 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 5230 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5231 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 5232 | __ movq(reg, CpuRegister(TMP)); |
| 5233 | } |
| 5234 | |
| 5235 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 5236 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5237 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5238 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5239 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5240 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5241 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 5242 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5243 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5244 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5245 | CpuRegister(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5246 | } |
| 5247 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5248 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 5249 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5250 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 5251 | __ movd(reg, CpuRegister(TMP)); |
| 5252 | } |
| 5253 | |
| 5254 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 5255 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5256 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 5257 | __ movd(reg, CpuRegister(TMP)); |
| 5258 | } |
| 5259 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5260 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5261 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5262 | Location source = move->GetSource(); |
| 5263 | Location destination = move->GetDestination(); |
| 5264 | |
| 5265 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5266 | Exchange64(source.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5267 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5268 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5269 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5270 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5271 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5272 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5273 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5274 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5275 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5276 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5277 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 5278 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5279 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5280 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 5281 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5282 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5283 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5284 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5285 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5286 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5287 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5288 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5289 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5290 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5291 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5292 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5293 | } |
| 5294 | } |
| 5295 | |
| 5296 | |
| 5297 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 5298 | __ pushq(CpuRegister(reg)); |
| 5299 | } |
| 5300 | |
| 5301 | |
| 5302 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 5303 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5304 | } |
| 5305 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5306 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5307 | SlowPathCode* slow_path, CpuRegister class_reg) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5308 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5309 | Immediate(mirror::Class::kStatusInitialized)); |
| 5310 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5311 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5312 | // No need for memory fence, thanks to the x86-64 memory model. |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5313 | } |
| 5314 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5315 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5316 | InvokeRuntimeCallingConvention calling_convention; |
| 5317 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5318 | cls, |
| 5319 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5320 | Location::RegisterLocation(RAX), |
| 5321 | /* code_generator_supports_read_barrier */ true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5322 | } |
| 5323 | |
| 5324 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5325 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5326 | if (cls->NeedsAccessCheck()) { |
| 5327 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 5328 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 5329 | cls, |
| 5330 | cls->GetDexPc(), |
| 5331 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5332 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5333 | return; |
| 5334 | } |
| 5335 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5336 | Location out_loc = locations->Out(); |
| 5337 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5338 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5339 | |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5340 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5341 | DCHECK(!cls->CanCallRuntime()); |
| 5342 | DCHECK(!cls->MustGenerateClinitCheck()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5343 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5344 | GenerateGcRootFieldLoad( |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5345 | cls, out_loc, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5346 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5347 | // /* GcRoot<mirror::Class>[] */ out = |
| 5348 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5349 | __ movq(out, Address(current_method, |
| 5350 | ArtMethod::DexCacheResolvedTypesOffset(kX86_64PointerSize).Int32Value())); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5351 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5352 | GenerateGcRootFieldLoad( |
| 5353 | cls, out_loc, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5354 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5355 | if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { |
| 5356 | DCHECK(cls->CanCallRuntime()); |
| 5357 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 5358 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5359 | codegen_->AddSlowPath(slow_path); |
| 5360 | if (!cls->IsInDexCache()) { |
| 5361 | __ testl(out, out); |
| 5362 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5363 | } |
| 5364 | if (cls->MustGenerateClinitCheck()) { |
| 5365 | GenerateClassInitializationCheck(slow_path, out); |
| 5366 | } else { |
| 5367 | __ Bind(slow_path->GetExitLabel()); |
| 5368 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5369 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5370 | } |
| 5371 | } |
| 5372 | |
| 5373 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 5374 | LocationSummary* locations = |
| 5375 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5376 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5377 | if (check->HasUses()) { |
| 5378 | locations->SetOut(Location::SameAsFirstInput()); |
| 5379 | } |
| 5380 | } |
| 5381 | |
| 5382 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5383 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5384 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5385 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5386 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5387 | GenerateClassInitializationCheck(slow_path, |
| 5388 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5389 | } |
| 5390 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5391 | HLoadString::LoadKind CodeGeneratorX86_64::GetSupportedLoadStringKind( |
| 5392 | HLoadString::LoadKind desired_string_load_kind) { |
| 5393 | if (kEmitCompilerReadBarrier) { |
| 5394 | switch (desired_string_load_kind) { |
| 5395 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5396 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5397 | case HLoadString::LoadKind::kBootImageAddress: |
| 5398 | // TODO: Implement for read barrier. |
| 5399 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 5400 | default: |
| 5401 | break; |
| 5402 | } |
| 5403 | } |
| 5404 | switch (desired_string_load_kind) { |
| 5405 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5406 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5407 | // We prefer the always-available RIP-relative address for the x86-64 boot image. |
| 5408 | return HLoadString::LoadKind::kBootImageLinkTimePcRelative; |
| 5409 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5410 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5411 | break; |
| 5412 | case HLoadString::LoadKind::kBootImageAddress: |
| 5413 | break; |
| 5414 | case HLoadString::LoadKind::kDexCacheAddress: |
| 5415 | DCHECK(Runtime::Current()->UseJit()); |
| 5416 | break; |
| 5417 | case HLoadString::LoadKind::kDexCachePcRelative: |
| 5418 | DCHECK(!Runtime::Current()->UseJit()); |
| 5419 | break; |
| 5420 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5421 | break; |
| 5422 | } |
| 5423 | return desired_string_load_kind; |
| 5424 | } |
| 5425 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5426 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5427 | LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier) |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5428 | ? LocationSummary::kCallOnSlowPath |
| 5429 | : LocationSummary::kNoCall; |
| 5430 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5431 | if (load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) { |
| 5432 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5433 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5434 | locations->SetOut(Location::RequiresRegister()); |
| 5435 | } |
| 5436 | |
| 5437 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5438 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5439 | Location out_loc = locations->Out(); |
| 5440 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5441 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5442 | switch (load->GetLoadKind()) { |
| 5443 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 5444 | DCHECK(!kEmitCompilerReadBarrier); |
| 5445 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| 5446 | codegen_->RecordStringPatch(load); |
| 5447 | return; // No dex cache slow path. |
| 5448 | } |
| 5449 | case HLoadString::LoadKind::kBootImageAddress: { |
| 5450 | DCHECK(!kEmitCompilerReadBarrier); |
| 5451 | DCHECK_NE(load->GetAddress(), 0u); |
| 5452 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 5453 | __ movl(out, Immediate(address)); // Zero-extended. |
| 5454 | codegen_->RecordSimplePatch(); |
| 5455 | return; // No dex cache slow path. |
| 5456 | } |
| 5457 | case HLoadString::LoadKind::kDexCacheAddress: { |
| 5458 | DCHECK_NE(load->GetAddress(), 0u); |
| 5459 | if (IsUint<32>(load->GetAddress())) { |
| 5460 | Address address = Address::Absolute(load->GetAddress(), /* no_rip */ true); |
| 5461 | GenerateGcRootFieldLoad(load, out_loc, address); |
| 5462 | } else { |
| 5463 | // TODO: Consider using opcode A1, i.e. movl eax, moff32 (with 64-bit address). |
| 5464 | __ movq(out, Immediate(load->GetAddress())); |
| 5465 | GenerateGcRootFieldLoad(load, out_loc, Address(out, 0)); |
| 5466 | } |
| 5467 | break; |
| 5468 | } |
| 5469 | case HLoadString::LoadKind::kDexCachePcRelative: { |
| 5470 | uint32_t offset = load->GetDexCacheElementOffset(); |
| 5471 | Label* fixup_label = codegen_->NewPcRelativeDexCacheArrayPatch(load->GetDexFile(), offset); |
| 5472 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5473 | /* no_rip */ false); |
| 5474 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label); |
| 5475 | break; |
| 5476 | } |
| 5477 | case HLoadString::LoadKind::kDexCacheViaMethod: { |
| 5478 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5479 | |
| 5480 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5481 | GenerateGcRootFieldLoad( |
| 5482 | load, out_loc, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
| 5483 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
| 5484 | __ movq(out, Address(out, mirror::Class::DexCacheStringsOffset().Uint32Value())); |
| 5485 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 5486 | GenerateGcRootFieldLoad( |
| 5487 | load, out_loc, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
| 5488 | break; |
| 5489 | } |
| 5490 | default: |
| 5491 | LOG(FATAL) << "Unexpected load kind: " << load->GetLoadKind(); |
| 5492 | UNREACHABLE(); |
| 5493 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5494 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5495 | if (!load->IsInDexCache()) { |
| 5496 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86_64(load); |
| 5497 | codegen_->AddSlowPath(slow_path); |
| 5498 | __ testl(out, out); |
| 5499 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5500 | __ Bind(slow_path->GetExitLabel()); |
| 5501 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5502 | } |
| 5503 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5504 | static Address GetExceptionTlsAddress() { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5505 | return Address::Absolute(Thread::ExceptionOffset<kX86_64WordSize>().Int32Value(), |
| 5506 | /* no_rip */ true); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5507 | } |
| 5508 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5509 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 5510 | LocationSummary* locations = |
| 5511 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5512 | locations->SetOut(Location::RequiresRegister()); |
| 5513 | } |
| 5514 | |
| 5515 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5516 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 5517 | } |
| 5518 | |
| 5519 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
| 5520 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5521 | } |
| 5522 | |
| 5523 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5524 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5525 | } |
| 5526 | |
| 5527 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| 5528 | LocationSummary* locations = |
| 5529 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5530 | InvokeRuntimeCallingConvention calling_convention; |
| 5531 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5532 | } |
| 5533 | |
| 5534 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5535 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 5536 | instruction, |
| 5537 | instruction->GetDexPc(), |
| 5538 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5539 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5540 | } |
| 5541 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5542 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5543 | return kEmitCompilerReadBarrier && |
| 5544 | (kUseBakerReadBarrier || |
| 5545 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5546 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5547 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5548 | } |
| 5549 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5550 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5551 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5552 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5553 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5554 | case TypeCheckKind::kExactCheck: |
| 5555 | case TypeCheckKind::kAbstractClassCheck: |
| 5556 | case TypeCheckKind::kClassHierarchyCheck: |
| 5557 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5558 | call_kind = |
| 5559 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5560 | break; |
| 5561 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5562 | case TypeCheckKind::kUnresolvedCheck: |
| 5563 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5564 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5565 | break; |
| 5566 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5567 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5568 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5569 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5570 | locations->SetInAt(1, Location::Any()); |
| 5571 | // Note that TypeCheckSlowPathX86_64 uses this "out" register too. |
| 5572 | locations->SetOut(Location::RequiresRegister()); |
| 5573 | // When read barriers are enabled, we need a temporary register for |
| 5574 | // some cases. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5575 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5576 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5577 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5578 | } |
| 5579 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5580 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5581 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5582 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5583 | Location obj_loc = locations->InAt(0); |
| 5584 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5585 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5586 | Location out_loc = locations->Out(); |
| 5587 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5588 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5589 | locations->GetTemp(0) : |
| 5590 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5591 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5592 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5593 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5594 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5595 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5596 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5597 | |
| 5598 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5599 | // Avoid null check if we know obj is not null. |
| 5600 | if (instruction->MustDoNullCheck()) { |
| 5601 | __ testl(obj, obj); |
| 5602 | __ j(kEqual, &zero); |
| 5603 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5604 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5605 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5606 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5607 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5608 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5609 | case TypeCheckKind::kExactCheck: { |
| 5610 | if (cls.IsRegister()) { |
| 5611 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5612 | } else { |
| 5613 | DCHECK(cls.IsStackSlot()) << cls; |
| 5614 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5615 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5616 | if (zero.IsLinked()) { |
| 5617 | // Classes must be equal for the instanceof to succeed. |
| 5618 | __ j(kNotEqual, &zero); |
| 5619 | __ movl(out, Immediate(1)); |
| 5620 | __ jmp(&done); |
| 5621 | } else { |
| 5622 | __ setcc(kEqual, out); |
| 5623 | // setcc only sets the low byte. |
| 5624 | __ andl(out, Immediate(1)); |
| 5625 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5626 | break; |
| 5627 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5628 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5629 | case TypeCheckKind::kAbstractClassCheck: { |
| 5630 | // If the class is abstract, we eagerly fetch the super class of the |
| 5631 | // object to avoid doing a comparison we know will fail. |
| 5632 | NearLabel loop, success; |
| 5633 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5634 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5635 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5636 | __ testl(out, out); |
| 5637 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5638 | __ j(kEqual, &done); |
| 5639 | if (cls.IsRegister()) { |
| 5640 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5641 | } else { |
| 5642 | DCHECK(cls.IsStackSlot()) << cls; |
| 5643 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5644 | } |
| 5645 | __ j(kNotEqual, &loop); |
| 5646 | __ movl(out, Immediate(1)); |
| 5647 | if (zero.IsLinked()) { |
| 5648 | __ jmp(&done); |
| 5649 | } |
| 5650 | break; |
| 5651 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5652 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5653 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5654 | // Walk over the class hierarchy to find a match. |
| 5655 | NearLabel loop, success; |
| 5656 | __ Bind(&loop); |
| 5657 | if (cls.IsRegister()) { |
| 5658 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5659 | } else { |
| 5660 | DCHECK(cls.IsStackSlot()) << cls; |
| 5661 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5662 | } |
| 5663 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5664 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5665 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5666 | __ testl(out, out); |
| 5667 | __ j(kNotEqual, &loop); |
| 5668 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5669 | __ jmp(&done); |
| 5670 | __ Bind(&success); |
| 5671 | __ movl(out, Immediate(1)); |
| 5672 | if (zero.IsLinked()) { |
| 5673 | __ jmp(&done); |
| 5674 | } |
| 5675 | break; |
| 5676 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5677 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5678 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5679 | // Do an exact check. |
| 5680 | NearLabel exact_check; |
| 5681 | if (cls.IsRegister()) { |
| 5682 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5683 | } else { |
| 5684 | DCHECK(cls.IsStackSlot()) << cls; |
| 5685 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5686 | } |
| 5687 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5688 | // 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] | 5689 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5690 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5691 | __ testl(out, out); |
| 5692 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5693 | __ j(kEqual, &done); |
| 5694 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5695 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5696 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5697 | __ movl(out, Immediate(1)); |
| 5698 | __ jmp(&done); |
| 5699 | break; |
| 5700 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5701 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5702 | case TypeCheckKind::kArrayCheck: { |
| 5703 | if (cls.IsRegister()) { |
| 5704 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5705 | } else { |
| 5706 | DCHECK(cls.IsStackSlot()) << cls; |
| 5707 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5708 | } |
| 5709 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5710 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5711 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5712 | codegen_->AddSlowPath(slow_path); |
| 5713 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5714 | __ movl(out, Immediate(1)); |
| 5715 | if (zero.IsLinked()) { |
| 5716 | __ jmp(&done); |
| 5717 | } |
| 5718 | break; |
| 5719 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5720 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5721 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5722 | case TypeCheckKind::kInterfaceCheck: { |
| 5723 | // 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] | 5724 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5725 | // cases. |
| 5726 | // |
| 5727 | // We cannot directly call the InstanceofNonTrivial runtime |
| 5728 | // entry point without resorting to a type checking slow path |
| 5729 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 5730 | // require to assign fixed registers for the inputs of this |
| 5731 | // HInstanceOf instruction (following the runtime calling |
| 5732 | // convention), which might be cluttered by the potential first |
| 5733 | // read barrier emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5734 | // |
| 5735 | // TODO: Introduce a new runtime entry point taking the object |
| 5736 | // to test (instead of its class) as argument, and let it deal |
| 5737 | // with the read barrier issues. This will let us refactor this |
| 5738 | // case of the `switch` code as it was previously (with a direct |
| 5739 | // call to the runtime not using a type checking slow path). |
| 5740 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5741 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5742 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5743 | /* is_fatal */ false); |
| 5744 | codegen_->AddSlowPath(slow_path); |
| 5745 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5746 | if (zero.IsLinked()) { |
| 5747 | __ jmp(&done); |
| 5748 | } |
| 5749 | break; |
| 5750 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5751 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5752 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5753 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5754 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5755 | __ xorl(out, out); |
| 5756 | } |
| 5757 | |
| 5758 | if (done.IsLinked()) { |
| 5759 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5760 | } |
| 5761 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5762 | if (slow_path != nullptr) { |
| 5763 | __ Bind(slow_path->GetExitLabel()); |
| 5764 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5765 | } |
| 5766 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5767 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5768 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5769 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5770 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5771 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5772 | case TypeCheckKind::kExactCheck: |
| 5773 | case TypeCheckKind::kAbstractClassCheck: |
| 5774 | case TypeCheckKind::kClassHierarchyCheck: |
| 5775 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5776 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 5777 | LocationSummary::kCallOnSlowPath : |
| 5778 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5779 | break; |
| 5780 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5781 | case TypeCheckKind::kUnresolvedCheck: |
| 5782 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5783 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5784 | break; |
| 5785 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5786 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 5787 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5788 | locations->SetInAt(1, Location::Any()); |
| 5789 | // Note that TypeCheckSlowPathX86_64 uses this "temp" register too. |
| 5790 | locations->AddTemp(Location::RequiresRegister()); |
| 5791 | // When read barriers are enabled, we need an additional temporary |
| 5792 | // register for some cases. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5793 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5794 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5795 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5796 | } |
| 5797 | |
| 5798 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5799 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5800 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5801 | Location obj_loc = locations->InAt(0); |
| 5802 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5803 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5804 | Location temp_loc = locations->GetTemp(0); |
| 5805 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5806 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5807 | locations->GetTemp(1) : |
| 5808 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5809 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5810 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5811 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5812 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5813 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5814 | bool is_type_check_slow_path_fatal = |
| 5815 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 5816 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5817 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5818 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 5819 | !instruction->CanThrowIntoCatchBlock(); |
| 5820 | SlowPathCode* type_check_slow_path = |
| 5821 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5822 | is_type_check_slow_path_fatal); |
| 5823 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5824 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5825 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5826 | case TypeCheckKind::kExactCheck: |
| 5827 | case TypeCheckKind::kArrayCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5828 | NearLabel done; |
| 5829 | // Avoid null check if we know obj is not null. |
| 5830 | if (instruction->MustDoNullCheck()) { |
| 5831 | __ testl(obj, obj); |
| 5832 | __ j(kEqual, &done); |
| 5833 | } |
| 5834 | |
| 5835 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5836 | GenerateReferenceLoadTwoRegisters( |
| 5837 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
| 5838 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5839 | if (cls.IsRegister()) { |
| 5840 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5841 | } else { |
| 5842 | DCHECK(cls.IsStackSlot()) << cls; |
| 5843 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5844 | } |
| 5845 | // Jump to slow path for throwing the exception or doing a |
| 5846 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5847 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5848 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5849 | break; |
| 5850 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5851 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5852 | case TypeCheckKind::kAbstractClassCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5853 | NearLabel done; |
| 5854 | // Avoid null check if we know obj is not null. |
| 5855 | if (instruction->MustDoNullCheck()) { |
| 5856 | __ testl(obj, obj); |
| 5857 | __ j(kEqual, &done); |
| 5858 | } |
| 5859 | |
| 5860 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5861 | GenerateReferenceLoadTwoRegisters( |
| 5862 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
| 5863 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5864 | // If the class is abstract, we eagerly fetch the super class of the |
| 5865 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5866 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5867 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5868 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5869 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5870 | |
| 5871 | // If the class reference currently in `temp` is not null, jump |
| 5872 | // to the `compare_classes` label to compare it with the checked |
| 5873 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5874 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5875 | __ j(kNotEqual, &compare_classes); |
| 5876 | // Otherwise, jump to the slow path to throw the exception. |
| 5877 | // |
| 5878 | // But before, move back the object's class into `temp` before |
| 5879 | // going into the slow path, as it has been overwritten in the |
| 5880 | // meantime. |
| 5881 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5882 | GenerateReferenceLoadTwoRegisters( |
| 5883 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5884 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 5885 | |
| 5886 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5887 | if (cls.IsRegister()) { |
| 5888 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5889 | } else { |
| 5890 | DCHECK(cls.IsStackSlot()) << cls; |
| 5891 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5892 | } |
| 5893 | __ j(kNotEqual, &loop); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5894 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5895 | break; |
| 5896 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5897 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5898 | case TypeCheckKind::kClassHierarchyCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5899 | NearLabel done; |
| 5900 | // Avoid null check if we know obj is not null. |
| 5901 | if (instruction->MustDoNullCheck()) { |
| 5902 | __ testl(obj, obj); |
| 5903 | __ j(kEqual, &done); |
| 5904 | } |
| 5905 | |
| 5906 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5907 | GenerateReferenceLoadTwoRegisters( |
| 5908 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
| 5909 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5910 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5911 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5912 | __ Bind(&loop); |
| 5913 | if (cls.IsRegister()) { |
| 5914 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5915 | } else { |
| 5916 | DCHECK(cls.IsStackSlot()) << cls; |
| 5917 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5918 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5919 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5920 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5921 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5922 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5923 | |
| 5924 | // If the class reference currently in `temp` is not null, jump |
| 5925 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5926 | __ testl(temp, temp); |
| 5927 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5928 | // Otherwise, jump to the slow path to throw the exception. |
| 5929 | // |
| 5930 | // But before, move back the object's class into `temp` before |
| 5931 | // going into the slow path, as it has been overwritten in the |
| 5932 | // meantime. |
| 5933 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5934 | GenerateReferenceLoadTwoRegisters( |
| 5935 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5936 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5937 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5938 | break; |
| 5939 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5940 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5941 | case TypeCheckKind::kArrayObjectCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5942 | // We cannot use a NearLabel here, as its range might be too |
| 5943 | // short in some cases when read barriers are enabled. This has |
| 5944 | // been observed for instance when the code emitted for this |
| 5945 | // case uses high x86-64 registers (R8-R15). |
| 5946 | Label done; |
| 5947 | // Avoid null check if we know obj is not null. |
| 5948 | if (instruction->MustDoNullCheck()) { |
| 5949 | __ testl(obj, obj); |
| 5950 | __ j(kEqual, &done); |
| 5951 | } |
| 5952 | |
| 5953 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5954 | GenerateReferenceLoadTwoRegisters( |
| 5955 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
| 5956 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5957 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5958 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5959 | if (cls.IsRegister()) { |
| 5960 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5961 | } else { |
| 5962 | DCHECK(cls.IsStackSlot()) << cls; |
| 5963 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5964 | } |
| 5965 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5966 | |
| 5967 | // 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] | 5968 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5969 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5970 | |
| 5971 | // If the component type is not null (i.e. the object is indeed |
| 5972 | // an array), jump to label `check_non_primitive_component_type` |
| 5973 | // to further check that this component type is not a primitive |
| 5974 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5975 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5976 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 5977 | // Otherwise, jump to the slow path to throw the exception. |
| 5978 | // |
| 5979 | // But before, move back the object's class into `temp` before |
| 5980 | // going into the slow path, as it has been overwritten in the |
| 5981 | // meantime. |
| 5982 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5983 | GenerateReferenceLoadTwoRegisters( |
| 5984 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5985 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 5986 | |
| 5987 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5988 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5989 | __ j(kEqual, &done); |
| 5990 | // Same comment as above regarding `temp` and the slow path. |
| 5991 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5992 | GenerateReferenceLoadTwoRegisters( |
| 5993 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5994 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5995 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5996 | break; |
| 5997 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5998 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5999 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6000 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6001 | NearLabel done; |
| 6002 | // Avoid null check if we know obj is not null. |
| 6003 | if (instruction->MustDoNullCheck()) { |
| 6004 | __ testl(obj, obj); |
| 6005 | __ j(kEqual, &done); |
| 6006 | } |
| 6007 | |
| 6008 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6009 | GenerateReferenceLoadTwoRegisters( |
| 6010 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
| 6011 | |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6012 | // We always go into the type check slow path for the unresolved |
| 6013 | // and interface check cases. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6014 | // |
| 6015 | // We cannot directly call the CheckCast runtime entry point |
| 6016 | // without resorting to a type checking slow path here (i.e. by |
| 6017 | // calling InvokeRuntime directly), as it would require to |
| 6018 | // assign fixed registers for the inputs of this HInstanceOf |
| 6019 | // instruction (following the runtime calling convention), which |
| 6020 | // might be cluttered by the potential first read barrier |
| 6021 | // emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6022 | // |
| 6023 | // TODO: Introduce a new runtime entry point taking the object |
| 6024 | // to test (instead of its class) as argument, and let it deal |
| 6025 | // with the read barrier issues. This will let us refactor this |
| 6026 | // case of the `switch` code as it was previously (with a direct |
| 6027 | // call to the runtime not using a type checking slow path). |
| 6028 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6029 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6030 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6031 | break; |
| 6032 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6033 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6034 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6035 | } |
| 6036 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6037 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6038 | LocationSummary* locations = |
| 6039 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 6040 | InvokeRuntimeCallingConvention calling_convention; |
| 6041 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6042 | } |
| 6043 | |
| 6044 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6045 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 6046 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 6047 | instruction, |
| 6048 | instruction->GetDexPc(), |
| 6049 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6050 | if (instruction->IsEnter()) { |
| 6051 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6052 | } else { |
| 6053 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6054 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6055 | } |
| 6056 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6057 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6058 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6059 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6060 | |
| 6061 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6062 | LocationSummary* locations = |
| 6063 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6064 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6065 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6066 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6067 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6068 | locations->SetOut(Location::SameAsFirstInput()); |
| 6069 | } |
| 6070 | |
| 6071 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 6072 | HandleBitwiseOperation(instruction); |
| 6073 | } |
| 6074 | |
| 6075 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 6076 | HandleBitwiseOperation(instruction); |
| 6077 | } |
| 6078 | |
| 6079 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 6080 | HandleBitwiseOperation(instruction); |
| 6081 | } |
| 6082 | |
| 6083 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6084 | LocationSummary* locations = instruction->GetLocations(); |
| 6085 | Location first = locations->InAt(0); |
| 6086 | Location second = locations->InAt(1); |
| 6087 | DCHECK(first.Equals(locations->Out())); |
| 6088 | |
| 6089 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6090 | if (second.IsRegister()) { |
| 6091 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6092 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6093 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6094 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6095 | } else { |
| 6096 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6097 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6098 | } |
| 6099 | } else if (second.IsConstant()) { |
| 6100 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 6101 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6102 | __ andl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6103 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6104 | __ orl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6105 | } else { |
| 6106 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6107 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6108 | } |
| 6109 | } else { |
| 6110 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 6111 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6112 | __ andl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6113 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6114 | __ orl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6115 | } else { |
| 6116 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6117 | __ xorl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6118 | } |
| 6119 | } |
| 6120 | } else { |
| 6121 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6122 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 6123 | bool second_is_constant = false; |
| 6124 | int64_t value = 0; |
| 6125 | if (second.IsConstant()) { |
| 6126 | second_is_constant = true; |
| 6127 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6128 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6129 | bool is_int32_value = IsInt<32>(value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6130 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6131 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6132 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6133 | if (is_int32_value) { |
| 6134 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6135 | } else { |
| 6136 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6137 | } |
| 6138 | } else if (second.IsDoubleStackSlot()) { |
| 6139 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6140 | } else { |
| 6141 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 6142 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6143 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6144 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6145 | if (is_int32_value) { |
| 6146 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6147 | } else { |
| 6148 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6149 | } |
| 6150 | } else if (second.IsDoubleStackSlot()) { |
| 6151 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6152 | } else { |
| 6153 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 6154 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6155 | } else { |
| 6156 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6157 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6158 | if (is_int32_value) { |
| 6159 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6160 | } else { |
| 6161 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6162 | } |
| 6163 | } else if (second.IsDoubleStackSlot()) { |
| 6164 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6165 | } else { |
| 6166 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 6167 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6168 | } |
| 6169 | } |
| 6170 | } |
| 6171 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6172 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6173 | Location out, |
| 6174 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6175 | Location maybe_temp) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6176 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6177 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6178 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6179 | if (kUseBakerReadBarrier) { |
| 6180 | // Load with fast path based Baker's read barrier. |
| 6181 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6182 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6183 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6184 | } else { |
| 6185 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6186 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6187 | // in the following move operation, as we will need it for the |
| 6188 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6189 | __ movl(maybe_temp.AsRegister<CpuRegister>(), out_reg); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6190 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6191 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6192 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6193 | } |
| 6194 | } else { |
| 6195 | // Plain load with no read barrier. |
| 6196 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6197 | __ movl(out_reg, Address(out_reg, offset)); |
| 6198 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6199 | } |
| 6200 | } |
| 6201 | |
| 6202 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6203 | Location out, |
| 6204 | Location obj, |
| 6205 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6206 | Location maybe_temp) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6207 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6208 | CpuRegister obj_reg = obj.AsRegister<CpuRegister>(); |
| 6209 | if (kEmitCompilerReadBarrier) { |
| 6210 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6211 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6212 | // Load with fast path based Baker's read barrier. |
| 6213 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6214 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6215 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6216 | } else { |
| 6217 | // Load with slow path based read barrier. |
| 6218 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6219 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6220 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6221 | } |
| 6222 | } else { |
| 6223 | // Plain load with no read barrier. |
| 6224 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6225 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6226 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6227 | } |
| 6228 | } |
| 6229 | |
| 6230 | void InstructionCodeGeneratorX86_64::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6231 | Location root, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6232 | const Address& address, |
| 6233 | Label* fixup_label) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6234 | CpuRegister root_reg = root.AsRegister<CpuRegister>(); |
| 6235 | if (kEmitCompilerReadBarrier) { |
| 6236 | if (kUseBakerReadBarrier) { |
| 6237 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6238 | // Baker's read barrier are used: |
| 6239 | // |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6240 | // root = *address; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6241 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6242 | // root = ReadBarrier::Mark(root) |
| 6243 | // } |
| 6244 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6245 | // /* GcRoot<mirror::Object> */ root = *address |
| 6246 | __ movl(root_reg, address); |
| 6247 | if (fixup_label != nullptr) { |
| 6248 | __ Bind(fixup_label); |
| 6249 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6250 | static_assert( |
| 6251 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6252 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6253 | "have different sizes."); |
| 6254 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6255 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6256 | "have different sizes."); |
| 6257 | |
| 6258 | // Slow path used to mark the GC root `root`. |
| 6259 | SlowPathCode* slow_path = |
| 6260 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64(instruction, root, root); |
| 6261 | codegen_->AddSlowPath(slow_path); |
| 6262 | |
| 6263 | __ gs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86_64WordSize>().Int32Value(), |
| 6264 | /* no_rip */ true), |
| 6265 | Immediate(0)); |
| 6266 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6267 | __ Bind(slow_path->GetExitLabel()); |
| 6268 | } else { |
| 6269 | // GC root loaded through a slow path for read barriers other |
| 6270 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6271 | // /* GcRoot<mirror::Object>* */ root = address |
| 6272 | __ leaq(root_reg, address); |
| 6273 | if (fixup_label != nullptr) { |
| 6274 | __ Bind(fixup_label); |
| 6275 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6276 | // /* mirror::Object* */ root = root->Read() |
| 6277 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6278 | } |
| 6279 | } else { |
| 6280 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6281 | // /* GcRoot<mirror::Object> */ root = *address |
| 6282 | __ movl(root_reg, address); |
| 6283 | if (fixup_label != nullptr) { |
| 6284 | __ Bind(fixup_label); |
| 6285 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6286 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6287 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6288 | } |
| 6289 | } |
| 6290 | |
| 6291 | void CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6292 | Location ref, |
| 6293 | CpuRegister obj, |
| 6294 | uint32_t offset, |
| 6295 | Location temp, |
| 6296 | bool needs_null_check) { |
| 6297 | DCHECK(kEmitCompilerReadBarrier); |
| 6298 | DCHECK(kUseBakerReadBarrier); |
| 6299 | |
| 6300 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6301 | Address src(obj, offset); |
| 6302 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6303 | } |
| 6304 | |
| 6305 | void CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6306 | Location ref, |
| 6307 | CpuRegister obj, |
| 6308 | uint32_t data_offset, |
| 6309 | Location index, |
| 6310 | Location temp, |
| 6311 | bool needs_null_check) { |
| 6312 | DCHECK(kEmitCompilerReadBarrier); |
| 6313 | DCHECK(kUseBakerReadBarrier); |
| 6314 | |
| 6315 | // /* HeapReference<Object> */ ref = |
| 6316 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6317 | Address src = index.IsConstant() ? |
| 6318 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset) : |
| 6319 | Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset); |
| 6320 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6321 | } |
| 6322 | |
| 6323 | void CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6324 | Location ref, |
| 6325 | CpuRegister obj, |
| 6326 | const Address& src, |
| 6327 | Location temp, |
| 6328 | bool needs_null_check) { |
| 6329 | DCHECK(kEmitCompilerReadBarrier); |
| 6330 | DCHECK(kUseBakerReadBarrier); |
| 6331 | |
| 6332 | // In slow path based read barriers, the read barrier call is |
| 6333 | // inserted after the original load. However, in fast path based |
| 6334 | // Baker's read barriers, we need to perform the load of |
| 6335 | // mirror::Object::monitor_ *before* the original reference load. |
| 6336 | // This load-load ordering is required by the read barrier. |
| 6337 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6338 | // |
| 6339 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6340 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6341 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6342 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6343 | // if (is_gray) { |
| 6344 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6345 | // } |
| 6346 | // |
| 6347 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6348 | // slightly more complex as: |
| 6349 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6350 | // the high-bits of rb_state, which are expected to be all zeroes |
| 6351 | // (we use CodeGeneratorX86_64::GenerateMemoryBarrier instead |
| 6352 | // 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] | 6353 | // - it performs additional checks that we do not do here for |
| 6354 | // performance reasons. |
| 6355 | |
| 6356 | CpuRegister ref_reg = ref.AsRegister<CpuRegister>(); |
| 6357 | CpuRegister temp_reg = temp.AsRegister<CpuRegister>(); |
| 6358 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6359 | |
| 6360 | // /* int32_t */ monitor = obj->monitor_ |
| 6361 | __ movl(temp_reg, Address(obj, monitor_offset)); |
| 6362 | if (needs_null_check) { |
| 6363 | MaybeRecordImplicitNullCheck(instruction); |
| 6364 | } |
| 6365 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6366 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6367 | "art::LockWord and int32_t have different sizes."); |
| 6368 | // /* uint32_t */ rb_state = lock_word.ReadBarrierState() |
| 6369 | __ shrl(temp_reg, Immediate(LockWord::kReadBarrierStateShift)); |
| 6370 | __ andl(temp_reg, Immediate(LockWord::kReadBarrierStateMask)); |
| 6371 | static_assert( |
| 6372 | LockWord::kReadBarrierStateMask == ReadBarrier::rb_ptr_mask_, |
| 6373 | "art::LockWord::kReadBarrierStateMask is not equal to art::ReadBarrier::rb_ptr_mask_."); |
| 6374 | |
| 6375 | // Load fence to prevent load-load reordering. |
| 6376 | // Note that this is a no-op, thanks to the x86-64 memory model. |
| 6377 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6378 | |
| 6379 | // The actual reference load. |
| 6380 | // /* HeapReference<Object> */ ref = *src |
| 6381 | __ movl(ref_reg, src); |
| 6382 | |
| 6383 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6384 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6385 | |
| 6386 | // Slow path used to mark the object `ref` when it is gray. |
| 6387 | SlowPathCode* slow_path = |
| 6388 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64(instruction, ref, ref); |
| 6389 | AddSlowPath(slow_path); |
| 6390 | |
| 6391 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6392 | // ref = ReadBarrier::Mark(ref); |
| 6393 | __ cmpl(temp_reg, Immediate(ReadBarrier::gray_ptr_)); |
| 6394 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6395 | __ Bind(slow_path->GetExitLabel()); |
| 6396 | } |
| 6397 | |
| 6398 | void CodeGeneratorX86_64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6399 | Location out, |
| 6400 | Location ref, |
| 6401 | Location obj, |
| 6402 | uint32_t offset, |
| 6403 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6404 | DCHECK(kEmitCompilerReadBarrier); |
| 6405 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6406 | // Insert a slow path based read barrier *after* the reference load. |
| 6407 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6408 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6409 | // reference will be carried out by the runtime within the slow |
| 6410 | // path. |
| 6411 | // |
| 6412 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6413 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6414 | // not used by the artReadBarrierSlow entry point. |
| 6415 | // |
| 6416 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6417 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6418 | ReadBarrierForHeapReferenceSlowPathX86_64(instruction, out, ref, obj, offset, index); |
| 6419 | AddSlowPath(slow_path); |
| 6420 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6421 | __ jmp(slow_path->GetEntryLabel()); |
| 6422 | __ Bind(slow_path->GetExitLabel()); |
| 6423 | } |
| 6424 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6425 | void CodeGeneratorX86_64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6426 | Location out, |
| 6427 | Location ref, |
| 6428 | Location obj, |
| 6429 | uint32_t offset, |
| 6430 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6431 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6432 | // Baker's read barriers shall be handled by the fast path |
| 6433 | // (CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6434 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6435 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6436 | // by the runtime within the slow path. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6437 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6438 | } else if (kPoisonHeapReferences) { |
| 6439 | __ UnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 6440 | } |
| 6441 | } |
| 6442 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6443 | void CodeGeneratorX86_64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6444 | Location out, |
| 6445 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6446 | DCHECK(kEmitCompilerReadBarrier); |
| 6447 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6448 | // Insert a slow path based read barrier *after* the GC root load. |
| 6449 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6450 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6451 | // not need to do anything special for this here. |
| 6452 | SlowPathCode* slow_path = |
| 6453 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86_64(instruction, out, root); |
| 6454 | AddSlowPath(slow_path); |
| 6455 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6456 | __ jmp(slow_path->GetEntryLabel()); |
| 6457 | __ Bind(slow_path->GetExitLabel()); |
| 6458 | } |
| 6459 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6460 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6461 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6462 | LOG(FATAL) << "Unreachable"; |
| 6463 | } |
| 6464 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6465 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6466 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6467 | LOG(FATAL) << "Unreachable"; |
| 6468 | } |
| 6469 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6470 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6471 | void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6472 | LocationSummary* locations = |
| 6473 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6474 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6475 | locations->AddTemp(Location::RequiresRegister()); |
| 6476 | locations->AddTemp(Location::RequiresRegister()); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6477 | } |
| 6478 | |
| 6479 | void InstructionCodeGeneratorX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6480 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6481 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6482 | LocationSummary* locations = switch_instr->GetLocations(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6483 | CpuRegister value_reg_in = locations->InAt(0).AsRegister<CpuRegister>(); |
| 6484 | CpuRegister temp_reg = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 6485 | CpuRegister base_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6486 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6487 | |
| 6488 | // Should we generate smaller inline compare/jumps? |
| 6489 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 6490 | // Figure out the correct compare values and jump conditions. |
| 6491 | // Handle the first compare/branch as a special case because it might |
| 6492 | // jump to the default case. |
| 6493 | DCHECK_GT(num_entries, 2u); |
| 6494 | Condition first_condition; |
| 6495 | uint32_t index; |
| 6496 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 6497 | if (lower_bound != 0) { |
| 6498 | first_condition = kLess; |
| 6499 | __ cmpl(value_reg_in, Immediate(lower_bound)); |
| 6500 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 6501 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
| 6502 | |
| 6503 | index = 1; |
| 6504 | } else { |
| 6505 | // Handle all the compare/jumps below. |
| 6506 | first_condition = kBelow; |
| 6507 | index = 0; |
| 6508 | } |
| 6509 | |
| 6510 | // Handle the rest of the compare/jumps. |
| 6511 | for (; index + 1 < num_entries; index += 2) { |
| 6512 | int32_t compare_to_value = lower_bound + index + 1; |
| 6513 | __ cmpl(value_reg_in, Immediate(compare_to_value)); |
| 6514 | // Jump to successors[index] if value < case_value[index]. |
| 6515 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 6516 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 6517 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 6518 | } |
| 6519 | |
| 6520 | if (index != num_entries) { |
| 6521 | // There are an odd number of entries. Handle the last one. |
| 6522 | DCHECK_EQ(index + 1, num_entries); |
Nicolas Geoffray | 6ce0173 | 2015-12-30 14:10:13 +0000 | [diff] [blame] | 6523 | __ cmpl(value_reg_in, Immediate(static_cast<int32_t>(lower_bound + index))); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6524 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
| 6525 | } |
| 6526 | |
| 6527 | // And the default for any other value. |
| 6528 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6529 | __ jmp(codegen_->GetLabelOf(default_block)); |
| 6530 | } |
| 6531 | return; |
| 6532 | } |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6533 | |
| 6534 | // Remove the bias, if needed. |
| 6535 | Register value_reg_out = value_reg_in.AsRegister(); |
| 6536 | if (lower_bound != 0) { |
| 6537 | __ leal(temp_reg, Address(value_reg_in, -lower_bound)); |
| 6538 | value_reg_out = temp_reg.AsRegister(); |
| 6539 | } |
| 6540 | CpuRegister value_reg(value_reg_out); |
| 6541 | |
| 6542 | // Is the value in range? |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6543 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 6544 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6545 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6546 | // We are in the range of the table. |
| 6547 | // Load the address of the jump table in the constant area. |
| 6548 | __ leaq(base_reg, codegen_->LiteralCaseTable(switch_instr)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6549 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6550 | // Load the (signed) offset from the jump table. |
| 6551 | __ movsxd(temp_reg, Address(base_reg, value_reg, TIMES_4, 0)); |
| 6552 | |
| 6553 | // Add the offset to the address of the table base. |
| 6554 | __ addq(temp_reg, base_reg); |
| 6555 | |
| 6556 | // And jump. |
| 6557 | __ jmp(temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6558 | } |
| 6559 | |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6560 | void CodeGeneratorX86_64::Load32BitValue(CpuRegister dest, int32_t value) { |
| 6561 | if (value == 0) { |
| 6562 | __ xorl(dest, dest); |
| 6563 | } else { |
| 6564 | __ movl(dest, Immediate(value)); |
| 6565 | } |
| 6566 | } |
| 6567 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6568 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 6569 | if (value == 0) { |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6570 | // Clears upper bits too. |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6571 | __ xorl(dest, dest); |
Vladimir Marko | ed00978 | 2016-02-22 16:54:39 +0000 | [diff] [blame] | 6572 | } else if (IsUint<32>(value)) { |
| 6573 | // 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] | 6574 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 6575 | } else { |
| 6576 | __ movq(dest, Immediate(value)); |
| 6577 | } |
| 6578 | } |
| 6579 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 6580 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, int32_t value) { |
| 6581 | if (value == 0) { |
| 6582 | __ xorps(dest, dest); |
| 6583 | } else { |
| 6584 | __ movss(dest, LiteralInt32Address(value)); |
| 6585 | } |
| 6586 | } |
| 6587 | |
| 6588 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, int64_t value) { |
| 6589 | if (value == 0) { |
| 6590 | __ xorpd(dest, dest); |
| 6591 | } else { |
| 6592 | __ movsd(dest, LiteralInt64Address(value)); |
| 6593 | } |
| 6594 | } |
| 6595 | |
| 6596 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, float value) { |
| 6597 | Load32BitValue(dest, bit_cast<int32_t, float>(value)); |
| 6598 | } |
| 6599 | |
| 6600 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, double value) { |
| 6601 | Load64BitValue(dest, bit_cast<int64_t, double>(value)); |
| 6602 | } |
| 6603 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 6604 | void CodeGeneratorX86_64::Compare32BitValue(CpuRegister dest, int32_t value) { |
| 6605 | if (value == 0) { |
| 6606 | __ testl(dest, dest); |
| 6607 | } else { |
| 6608 | __ cmpl(dest, Immediate(value)); |
| 6609 | } |
| 6610 | } |
| 6611 | |
| 6612 | void CodeGeneratorX86_64::Compare64BitValue(CpuRegister dest, int64_t value) { |
| 6613 | if (IsInt<32>(value)) { |
| 6614 | if (value == 0) { |
| 6615 | __ testq(dest, dest); |
| 6616 | } else { |
| 6617 | __ cmpq(dest, Immediate(static_cast<int32_t>(value))); |
| 6618 | } |
| 6619 | } else { |
| 6620 | // Value won't fit in an int. |
| 6621 | __ cmpq(dest, LiteralInt64Address(value)); |
| 6622 | } |
| 6623 | } |
| 6624 | |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 6625 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 6626 | DCHECK(dest.IsDoubleStackSlot()); |
| 6627 | if (IsInt<32>(value)) { |
| 6628 | // Can move directly as an int32 constant. |
| 6629 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 6630 | Immediate(static_cast<int32_t>(value))); |
| 6631 | } else { |
| 6632 | Load64BitValue(CpuRegister(TMP), value); |
| 6633 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 6634 | } |
| 6635 | } |
| 6636 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6637 | /** |
| 6638 | * Class to handle late fixup of offsets into constant area. |
| 6639 | */ |
| 6640 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| 6641 | public: |
| 6642 | RIPFixup(CodeGeneratorX86_64& codegen, size_t offset) |
| 6643 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 6644 | |
| 6645 | protected: |
| 6646 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 6647 | |
| 6648 | CodeGeneratorX86_64* codegen_; |
| 6649 | |
| 6650 | private: |
| 6651 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 6652 | // Patch the correct offset for the instruction. We use the address of the |
| 6653 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 6654 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 6655 | int32_t relative_position = constant_offset - pos; |
| 6656 | |
| 6657 | // Patch in the right value. |
| 6658 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 6659 | } |
| 6660 | |
| 6661 | // Location in constant area that the fixup refers to. |
| 6662 | size_t offset_into_constant_area_; |
| 6663 | }; |
| 6664 | |
| 6665 | /** |
| 6666 | t * Class to handle late fixup of offsets to a jump table that will be created in the |
| 6667 | * constant area. |
| 6668 | */ |
| 6669 | class JumpTableRIPFixup : public RIPFixup { |
| 6670 | public: |
| 6671 | JumpTableRIPFixup(CodeGeneratorX86_64& codegen, HPackedSwitch* switch_instr) |
| 6672 | : RIPFixup(codegen, -1), switch_instr_(switch_instr) {} |
| 6673 | |
| 6674 | void CreateJumpTable() { |
| 6675 | X86_64Assembler* assembler = codegen_->GetAssembler(); |
| 6676 | |
| 6677 | // Ensure that the reference to the jump table has the correct offset. |
| 6678 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 6679 | SetOffset(offset_in_constant_table); |
| 6680 | |
| 6681 | // Compute the offset from the start of the function to this jump table. |
| 6682 | const int32_t current_table_offset = assembler->CodeSize() + offset_in_constant_table; |
| 6683 | |
| 6684 | // Populate the jump table with the correct values for the jump table. |
| 6685 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 6686 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 6687 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 6688 | // The value that we want is the target offset - the position of the table. |
| 6689 | for (int32_t i = 0; i < num_entries; i++) { |
| 6690 | HBasicBlock* b = successors[i]; |
| 6691 | Label* l = codegen_->GetLabelOf(b); |
| 6692 | DCHECK(l->IsBound()); |
| 6693 | int32_t offset_to_block = l->Position() - current_table_offset; |
| 6694 | assembler->AppendInt32(offset_to_block); |
| 6695 | } |
| 6696 | } |
| 6697 | |
| 6698 | private: |
| 6699 | const HPackedSwitch* switch_instr_; |
| 6700 | }; |
| 6701 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6702 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 6703 | // Generate the constant area if needed. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 6704 | X86_64Assembler* assembler = GetAssembler(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6705 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 6706 | // 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] | 6707 | assembler->Align(4, 0); |
| 6708 | constant_area_start_ = assembler->CodeSize(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6709 | |
| 6710 | // Populate any jump tables. |
| 6711 | for (auto jump_table : fixups_to_jump_tables_) { |
| 6712 | jump_table->CreateJumpTable(); |
| 6713 | } |
| 6714 | |
| 6715 | // And now add the constant area to the generated code. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 6716 | assembler->AddConstantArea(); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6717 | } |
| 6718 | |
| 6719 | // And finish up. |
| 6720 | CodeGenerator::Finalize(allocator); |
| 6721 | } |
| 6722 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6723 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
| 6724 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 6725 | return Address::RIP(fixup); |
| 6726 | } |
| 6727 | |
| 6728 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
| 6729 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 6730 | return Address::RIP(fixup); |
| 6731 | } |
| 6732 | |
| 6733 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
| 6734 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 6735 | return Address::RIP(fixup); |
| 6736 | } |
| 6737 | |
| 6738 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
| 6739 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 6740 | return Address::RIP(fixup); |
| 6741 | } |
| 6742 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6743 | // TODO: trg as memory. |
| 6744 | void CodeGeneratorX86_64::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 6745 | if (!trg.IsValid()) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6746 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6747 | return; |
| 6748 | } |
| 6749 | |
| 6750 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 6751 | |
| 6752 | Location return_loc = InvokeDexCallingConventionVisitorX86_64().GetReturnLocation(type); |
| 6753 | if (trg.Equals(return_loc)) { |
| 6754 | return; |
| 6755 | } |
| 6756 | |
| 6757 | // Let the parallel move resolver take care of all of this. |
| 6758 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 6759 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 6760 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 6761 | } |
| 6762 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6763 | Address CodeGeneratorX86_64::LiteralCaseTable(HPackedSwitch* switch_instr) { |
| 6764 | // Create a fixup to be used to create and address the jump table. |
| 6765 | JumpTableRIPFixup* table_fixup = |
| 6766 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 6767 | |
| 6768 | // We have to populate the jump tables. |
| 6769 | fixups_to_jump_tables_.push_back(table_fixup); |
| 6770 | return Address::RIP(table_fixup); |
| 6771 | } |
| 6772 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 6773 | void CodeGeneratorX86_64::MoveInt64ToAddress(const Address& addr_low, |
| 6774 | const Address& addr_high, |
| 6775 | int64_t v, |
| 6776 | HInstruction* instruction) { |
| 6777 | if (IsInt<32>(v)) { |
| 6778 | int32_t v_32 = v; |
| 6779 | __ movq(addr_low, Immediate(v_32)); |
| 6780 | MaybeRecordImplicitNullCheck(instruction); |
| 6781 | } else { |
| 6782 | // Didn't fit in a register. Do it in pieces. |
| 6783 | int32_t low_v = Low32Bits(v); |
| 6784 | int32_t high_v = High32Bits(v); |
| 6785 | __ movl(addr_low, Immediate(low_v)); |
| 6786 | MaybeRecordImplicitNullCheck(instruction); |
| 6787 | __ movl(addr_high, Immediate(high_v)); |
| 6788 | } |
| 6789 | } |
| 6790 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6791 | #undef __ |
| 6792 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 6793 | } // namespace x86_64 |
| 6794 | } // namespace art |