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 | |
Chih-Hung Hsieh | fba3997 | 2016-05-11 11:26:48 -0700 | [diff] [blame] | 54 | // NOLINT on __ macro to suppress wrong warning/fix from clang-tidy. |
| 55 | #define __ down_cast<X86_64Assembler*>(codegen->GetAssembler())-> // NOLINT |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 56 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 57 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 58 | class NullCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 59 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 60 | explicit NullCheckSlowPathX86_64(HNullCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 61 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 62 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 63 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 64 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 65 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 66 | // Live registers will be restored in the catch block if caught. |
| 67 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 68 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 69 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), |
| 70 | instruction_, |
| 71 | instruction_->GetDexPc(), |
| 72 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 73 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 74 | } |
| 75 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 76 | bool IsFatal() const OVERRIDE { return true; } |
| 77 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 78 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86_64"; } |
| 79 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 80 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 81 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86_64); |
| 82 | }; |
| 83 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 84 | class DivZeroCheckSlowPathX86_64 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 85 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 86 | explicit DivZeroCheckSlowPathX86_64(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 87 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 88 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 89 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 90 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 91 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 92 | // Live registers will be restored in the catch block if caught. |
| 93 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 94 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 95 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), |
| 96 | instruction_, |
| 97 | instruction_->GetDexPc(), |
| 98 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 99 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 102 | bool IsFatal() const OVERRIDE { return true; } |
| 103 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 104 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86_64"; } |
| 105 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 106 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 107 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86_64); |
| 108 | }; |
| 109 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 110 | class DivRemMinusOneSlowPathX86_64 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 111 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 112 | DivRemMinusOneSlowPathX86_64(HInstruction* at, Register reg, Primitive::Type type, bool is_div) |
| 113 | : SlowPathCode(at), cpu_reg_(CpuRegister(reg)), type_(type), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 114 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 115 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 116 | __ Bind(GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 117 | if (type_ == Primitive::kPrimInt) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 118 | if (is_div_) { |
| 119 | __ negl(cpu_reg_); |
| 120 | } else { |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 121 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 124 | } else { |
| 125 | DCHECK_EQ(Primitive::kPrimLong, type_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 126 | if (is_div_) { |
| 127 | __ negq(cpu_reg_); |
| 128 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 129 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 130 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 131 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 132 | __ jmp(GetExitLabel()); |
| 133 | } |
| 134 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 135 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86_64"; } |
| 136 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 137 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 138 | const CpuRegister cpu_reg_; |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 139 | const Primitive::Type type_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 140 | const bool is_div_; |
| 141 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86_64); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 142 | }; |
| 143 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 144 | class SuspendCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 145 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 146 | SuspendCheckSlowPathX86_64(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 147 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 148 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 149 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 150 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 151 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 152 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 153 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), |
| 154 | instruction_, |
| 155 | instruction_->GetDexPc(), |
| 156 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 157 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 158 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 159 | if (successor_ == nullptr) { |
| 160 | __ jmp(GetReturnLabel()); |
| 161 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 162 | __ jmp(x86_64_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 163 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 166 | Label* GetReturnLabel() { |
| 167 | DCHECK(successor_ == nullptr); |
| 168 | return &return_label_; |
| 169 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 170 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 171 | HBasicBlock* GetSuccessor() const { |
| 172 | return successor_; |
| 173 | } |
| 174 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 175 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86_64"; } |
| 176 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 177 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 178 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 179 | Label return_label_; |
| 180 | |
| 181 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64); |
| 182 | }; |
| 183 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 184 | class BoundsCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 185 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 186 | explicit BoundsCheckSlowPathX86_64(HBoundsCheck* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 187 | : SlowPathCode(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 188 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 189 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 190 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 191 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 192 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 193 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 194 | // Live registers will be restored in the catch block if caught. |
| 195 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 196 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 197 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 198 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 199 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 200 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 201 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 202 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 203 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 204 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 205 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 206 | Primitive::kPrimInt); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 207 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds), |
| 208 | instruction_, |
| 209 | instruction_->GetDexPc(), |
| 210 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 211 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 212 | } |
| 213 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 214 | bool IsFatal() const OVERRIDE { return true; } |
| 215 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 216 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86_64"; } |
| 217 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 218 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 219 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 220 | }; |
| 221 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 222 | class LoadClassSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 223 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 224 | LoadClassSlowPathX86_64(HLoadClass* cls, |
| 225 | HInstruction* at, |
| 226 | uint32_t dex_pc, |
| 227 | bool do_clinit) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 228 | : 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] | 229 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 230 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 231 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 232 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 233 | LocationSummary* locations = at_->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 234 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 235 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 236 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 237 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 238 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 239 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 240 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(cls_->GetTypeIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 241 | x86_64_codegen->InvokeRuntime(do_clinit_ ? |
| 242 | QUICK_ENTRY_POINT(pInitializeStaticStorage) : |
| 243 | QUICK_ENTRY_POINT(pInitializeType), |
| 244 | at_, |
| 245 | dex_pc_, |
| 246 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 247 | if (do_clinit_) { |
| 248 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 249 | } else { |
| 250 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 251 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 252 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 253 | Location out = locations->Out(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 254 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 255 | if (out.IsValid()) { |
| 256 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 257 | x86_64_codegen->Move(out, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 258 | } |
| 259 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 260 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 261 | __ jmp(GetExitLabel()); |
| 262 | } |
| 263 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 264 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86_64"; } |
| 265 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 266 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 267 | // The class this slow path will load. |
| 268 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 269 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 270 | // The instruction where this slow path is happening. |
| 271 | // (Might be the load class or an initialization check). |
| 272 | HInstruction* const at_; |
| 273 | |
| 274 | // The dex PC of `at_`. |
| 275 | const uint32_t dex_pc_; |
| 276 | |
| 277 | // Whether to initialize the class. |
| 278 | const bool do_clinit_; |
| 279 | |
| 280 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86_64); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 281 | }; |
| 282 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 283 | class LoadStringSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 284 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 285 | explicit LoadStringSlowPathX86_64(HLoadString* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 286 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 287 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 288 | LocationSummary* locations = instruction_->GetLocations(); |
| 289 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 290 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 291 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 292 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 293 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 294 | |
| 295 | InvokeRuntimeCallingConvention calling_convention; |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 296 | const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 297 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(string_index)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 298 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), |
| 299 | instruction_, |
| 300 | instruction_->GetDexPc(), |
| 301 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 302 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 303 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 304 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 305 | __ jmp(GetExitLabel()); |
| 306 | } |
| 307 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 308 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86_64"; } |
| 309 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 310 | private: |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 311 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86_64); |
| 312 | }; |
| 313 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 314 | class TypeCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 315 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 316 | TypeCheckSlowPathX86_64(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 317 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 318 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 319 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 320 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 321 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 322 | : locations->Out(); |
| 323 | uint32_t dex_pc = instruction_->GetDexPc(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 324 | DCHECK(instruction_->IsCheckCast() |
| 325 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 326 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 327 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 328 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 329 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 330 | if (!is_fatal_) { |
| 331 | SaveLiveRegisters(codegen, locations); |
| 332 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 333 | |
| 334 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 335 | // move resolver. |
| 336 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 337 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 338 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 339 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 340 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 341 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 342 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 343 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 344 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 345 | if (instruction_->IsInstanceOf()) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 346 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 347 | instruction_, |
| 348 | dex_pc, |
| 349 | this); |
| 350 | CheckEntrypointTypes< |
| 351 | kQuickInstanceofNonTrivial, uint32_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 352 | } else { |
| 353 | DCHECK(instruction_->IsCheckCast()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 354 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 355 | instruction_, |
| 356 | dex_pc, |
| 357 | this); |
| 358 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 359 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 360 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 361 | if (!is_fatal_) { |
| 362 | if (instruction_->IsInstanceOf()) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 363 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 364 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 365 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 366 | RestoreLiveRegisters(codegen, locations); |
| 367 | __ jmp(GetExitLabel()); |
| 368 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 371 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86_64"; } |
| 372 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 373 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 374 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 375 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 376 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 377 | |
| 378 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86_64); |
| 379 | }; |
| 380 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 381 | class DeoptimizationSlowPathX86_64 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 382 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 383 | explicit DeoptimizationSlowPathX86_64(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 384 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 385 | |
| 386 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 387 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 388 | __ Bind(GetEntryLabel()); |
| 389 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 390 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 391 | instruction_, |
| 392 | instruction_->GetDexPc(), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 393 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 394 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 397 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86_64"; } |
| 398 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 399 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 400 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86_64); |
| 401 | }; |
| 402 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 403 | class ArraySetSlowPathX86_64 : public SlowPathCode { |
| 404 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 405 | explicit ArraySetSlowPathX86_64(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 406 | |
| 407 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 408 | LocationSummary* locations = instruction_->GetLocations(); |
| 409 | __ Bind(GetEntryLabel()); |
| 410 | SaveLiveRegisters(codegen, locations); |
| 411 | |
| 412 | InvokeRuntimeCallingConvention calling_convention; |
| 413 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 414 | parallel_move.AddMove( |
| 415 | locations->InAt(0), |
| 416 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 417 | Primitive::kPrimNot, |
| 418 | nullptr); |
| 419 | parallel_move.AddMove( |
| 420 | locations->InAt(1), |
| 421 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 422 | Primitive::kPrimInt, |
| 423 | nullptr); |
| 424 | parallel_move.AddMove( |
| 425 | locations->InAt(2), |
| 426 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 427 | Primitive::kPrimNot, |
| 428 | nullptr); |
| 429 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 430 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 431 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 432 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 433 | instruction_, |
| 434 | instruction_->GetDexPc(), |
| 435 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 436 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 437 | RestoreLiveRegisters(codegen, locations); |
| 438 | __ jmp(GetExitLabel()); |
| 439 | } |
| 440 | |
| 441 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86_64"; } |
| 442 | |
| 443 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 444 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86_64); |
| 445 | }; |
| 446 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 447 | // Slow path marking an object during a read barrier. |
| 448 | class ReadBarrierMarkSlowPathX86_64 : public SlowPathCode { |
| 449 | public: |
| 450 | ReadBarrierMarkSlowPathX86_64(HInstruction* instruction, Location out, Location obj) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 451 | : SlowPathCode(instruction), out_(out), obj_(obj) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 452 | DCHECK(kEmitCompilerReadBarrier); |
| 453 | } |
| 454 | |
| 455 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86_64"; } |
| 456 | |
| 457 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 458 | LocationSummary* locations = instruction_->GetLocations(); |
| 459 | Register reg_out = out_.AsRegister<Register>(); |
| 460 | DCHECK(locations->CanCall()); |
| 461 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 462 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 463 | instruction_->IsStaticFieldGet() || |
| 464 | instruction_->IsArrayGet() || |
| 465 | instruction_->IsLoadClass() || |
| 466 | instruction_->IsLoadString() || |
| 467 | instruction_->IsInstanceOf() || |
| 468 | instruction_->IsCheckCast()) |
| 469 | << "Unexpected instruction in read barrier marking slow path: " |
| 470 | << instruction_->DebugName(); |
| 471 | |
| 472 | __ Bind(GetEntryLabel()); |
| 473 | SaveLiveRegisters(codegen, locations); |
| 474 | |
| 475 | InvokeRuntimeCallingConvention calling_convention; |
| 476 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 477 | x86_64_codegen->Move(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), obj_); |
| 478 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierMark), |
| 479 | instruction_, |
| 480 | instruction_->GetDexPc(), |
| 481 | this); |
| 482 | CheckEntrypointTypes<kQuickReadBarrierMark, mirror::Object*, mirror::Object*>(); |
| 483 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 484 | |
| 485 | RestoreLiveRegisters(codegen, locations); |
| 486 | __ jmp(GetExitLabel()); |
| 487 | } |
| 488 | |
| 489 | private: |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 490 | const Location out_; |
| 491 | const Location obj_; |
| 492 | |
| 493 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86_64); |
| 494 | }; |
| 495 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 496 | // Slow path generating a read barrier for a heap reference. |
| 497 | class ReadBarrierForHeapReferenceSlowPathX86_64 : public SlowPathCode { |
| 498 | public: |
| 499 | ReadBarrierForHeapReferenceSlowPathX86_64(HInstruction* instruction, |
| 500 | Location out, |
| 501 | Location ref, |
| 502 | Location obj, |
| 503 | uint32_t offset, |
| 504 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 505 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 506 | out_(out), |
| 507 | ref_(ref), |
| 508 | obj_(obj), |
| 509 | offset_(offset), |
| 510 | index_(index) { |
| 511 | DCHECK(kEmitCompilerReadBarrier); |
| 512 | // If `obj` is equal to `out` or `ref`, it means the initial |
| 513 | // object has been overwritten by (or after) the heap object |
| 514 | // reference load to be instrumented, e.g.: |
| 515 | // |
| 516 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 517 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 518 | // |
| 519 | // In that case, we have lost the information about the original |
| 520 | // object, and the emitted read barrier cannot work properly. |
| 521 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 522 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 523 | } |
| 524 | |
| 525 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 526 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 527 | LocationSummary* locations = instruction_->GetLocations(); |
| 528 | CpuRegister reg_out = out_.AsRegister<CpuRegister>(); |
| 529 | DCHECK(locations->CanCall()); |
| 530 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.AsRegister())) << out_; |
| 531 | DCHECK(!instruction_->IsInvoke() || |
| 532 | (instruction_->IsInvokeStaticOrDirect() && |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 533 | instruction_->GetLocations()->Intrinsified())) |
| 534 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 535 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 536 | |
| 537 | __ Bind(GetEntryLabel()); |
| 538 | SaveLiveRegisters(codegen, locations); |
| 539 | |
| 540 | // We may have to change the index's value, but as `index_` is a |
| 541 | // constant member (like other "inputs" of this slow path), |
| 542 | // introduce a copy of it, `index`. |
| 543 | Location index = index_; |
| 544 | if (index_.IsValid()) { |
| 545 | // Handle `index_` for HArrayGet and intrinsic UnsafeGetObject. |
| 546 | if (instruction_->IsArrayGet()) { |
| 547 | // Compute real offset and store it in index_. |
| 548 | Register index_reg = index_.AsRegister<CpuRegister>().AsRegister(); |
| 549 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 550 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 551 | // We are about to change the value of `index_reg` (see the |
| 552 | // calls to art::x86_64::X86_64Assembler::shll and |
| 553 | // art::x86_64::X86_64Assembler::AddImmediate below), but it |
| 554 | // has not been saved by the previous call to |
| 555 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 556 | // callee-save register -- |
| 557 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 558 | // callee-save registers, as it has been designed with the |
| 559 | // assumption that callee-save registers are supposed to be |
| 560 | // handled by the called function. So, as a callee-save |
| 561 | // register, `index_reg` _would_ eventually be saved onto |
| 562 | // the stack, but it would be too late: we would have |
| 563 | // changed its value earlier. Therefore, we manually save |
| 564 | // it here into another freely available register, |
| 565 | // `free_reg`, chosen of course among the caller-save |
| 566 | // registers (as a callee-save `free_reg` register would |
| 567 | // exhibit the same problem). |
| 568 | // |
| 569 | // Note we could have requested a temporary register from |
| 570 | // the register allocator instead; but we prefer not to, as |
| 571 | // this is a slow path, and we know we can find a |
| 572 | // caller-save register that is available. |
| 573 | Register free_reg = FindAvailableCallerSaveRegister(codegen).AsRegister(); |
| 574 | __ movl(CpuRegister(free_reg), CpuRegister(index_reg)); |
| 575 | index_reg = free_reg; |
| 576 | index = Location::RegisterLocation(index_reg); |
| 577 | } else { |
| 578 | // The initial register stored in `index_` has already been |
| 579 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 580 | // (as it is not a callee-save register), so we can freely |
| 581 | // use it. |
| 582 | } |
| 583 | // Shifting the index value contained in `index_reg` by the |
| 584 | // scale factor (2) cannot overflow in practice, as the |
| 585 | // runtime is unable to allocate object arrays with a size |
| 586 | // larger than 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 587 | __ shll(CpuRegister(index_reg), Immediate(TIMES_4)); |
| 588 | static_assert( |
| 589 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 590 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 591 | __ AddImmediate(CpuRegister(index_reg), Immediate(offset_)); |
| 592 | } else { |
| 593 | DCHECK(instruction_->IsInvoke()); |
| 594 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 595 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 596 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 597 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 598 | DCHECK_EQ(offset_, 0U); |
| 599 | DCHECK(index_.IsRegister()); |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | // We're moving two or three locations to locations that could |
| 604 | // overlap, so we need a parallel move resolver. |
| 605 | InvokeRuntimeCallingConvention calling_convention; |
| 606 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 607 | parallel_move.AddMove(ref_, |
| 608 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 609 | Primitive::kPrimNot, |
| 610 | nullptr); |
| 611 | parallel_move.AddMove(obj_, |
| 612 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 613 | Primitive::kPrimNot, |
| 614 | nullptr); |
| 615 | if (index.IsValid()) { |
| 616 | parallel_move.AddMove(index, |
| 617 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 618 | Primitive::kPrimInt, |
| 619 | nullptr); |
| 620 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 621 | } else { |
| 622 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 623 | __ movl(CpuRegister(calling_convention.GetRegisterAt(2)), Immediate(offset_)); |
| 624 | } |
| 625 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow), |
| 626 | instruction_, |
| 627 | instruction_->GetDexPc(), |
| 628 | this); |
| 629 | CheckEntrypointTypes< |
| 630 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 631 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 632 | |
| 633 | RestoreLiveRegisters(codegen, locations); |
| 634 | __ jmp(GetExitLabel()); |
| 635 | } |
| 636 | |
| 637 | const char* GetDescription() const OVERRIDE { |
| 638 | return "ReadBarrierForHeapReferenceSlowPathX86_64"; |
| 639 | } |
| 640 | |
| 641 | private: |
| 642 | CpuRegister FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 643 | size_t ref = static_cast<int>(ref_.AsRegister<CpuRegister>().AsRegister()); |
| 644 | size_t obj = static_cast<int>(obj_.AsRegister<CpuRegister>().AsRegister()); |
| 645 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 646 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 647 | return static_cast<CpuRegister>(i); |
| 648 | } |
| 649 | } |
| 650 | // We shall never fail to find a free caller-save register, as |
| 651 | // there are more than two core caller-save registers on x86-64 |
| 652 | // (meaning it is possible to find one which is different from |
| 653 | // `ref` and `obj`). |
| 654 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 655 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 656 | UNREACHABLE(); |
| 657 | } |
| 658 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 659 | const Location out_; |
| 660 | const Location ref_; |
| 661 | const Location obj_; |
| 662 | const uint32_t offset_; |
| 663 | // An additional location containing an index to an array. |
| 664 | // Only used for HArrayGet and the UnsafeGetObject & |
| 665 | // UnsafeGetObjectVolatile intrinsics. |
| 666 | const Location index_; |
| 667 | |
| 668 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86_64); |
| 669 | }; |
| 670 | |
| 671 | // Slow path generating a read barrier for a GC root. |
| 672 | class ReadBarrierForRootSlowPathX86_64 : public SlowPathCode { |
| 673 | public: |
| 674 | ReadBarrierForRootSlowPathX86_64(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 675 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 676 | DCHECK(kEmitCompilerReadBarrier); |
| 677 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 678 | |
| 679 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 680 | LocationSummary* locations = instruction_->GetLocations(); |
| 681 | DCHECK(locations->CanCall()); |
| 682 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 683 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 684 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 685 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 686 | |
| 687 | __ Bind(GetEntryLabel()); |
| 688 | SaveLiveRegisters(codegen, locations); |
| 689 | |
| 690 | InvokeRuntimeCallingConvention calling_convention; |
| 691 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 692 | x86_64_codegen->Move(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| 693 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow), |
| 694 | instruction_, |
| 695 | instruction_->GetDexPc(), |
| 696 | this); |
| 697 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 698 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 699 | |
| 700 | RestoreLiveRegisters(codegen, locations); |
| 701 | __ jmp(GetExitLabel()); |
| 702 | } |
| 703 | |
| 704 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86_64"; } |
| 705 | |
| 706 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 707 | const Location out_; |
| 708 | const Location root_; |
| 709 | |
| 710 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86_64); |
| 711 | }; |
| 712 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 713 | #undef __ |
Chih-Hung Hsieh | fba3997 | 2016-05-11 11:26:48 -0700 | [diff] [blame] | 714 | // NOLINT on __ macro to suppress wrong warning/fix from clang-tidy. |
| 715 | #define __ down_cast<X86_64Assembler*>(GetAssembler())-> // NOLINT |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 716 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 717 | inline Condition X86_64IntegerCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 718 | switch (cond) { |
| 719 | case kCondEQ: return kEqual; |
| 720 | case kCondNE: return kNotEqual; |
| 721 | case kCondLT: return kLess; |
| 722 | case kCondLE: return kLessEqual; |
| 723 | case kCondGT: return kGreater; |
| 724 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 725 | case kCondB: return kBelow; |
| 726 | case kCondBE: return kBelowEqual; |
| 727 | case kCondA: return kAbove; |
| 728 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 729 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 730 | LOG(FATAL) << "Unreachable"; |
| 731 | UNREACHABLE(); |
| 732 | } |
| 733 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 734 | // Maps FP condition to x86_64 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 735 | inline Condition X86_64FPCondition(IfCondition cond) { |
| 736 | switch (cond) { |
| 737 | case kCondEQ: return kEqual; |
| 738 | case kCondNE: return kNotEqual; |
| 739 | case kCondLT: return kBelow; |
| 740 | case kCondLE: return kBelowEqual; |
| 741 | case kCondGT: return kAbove; |
| 742 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 743 | default: break; // should not happen |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 744 | }; |
| 745 | LOG(FATAL) << "Unreachable"; |
| 746 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 747 | } |
| 748 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 749 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86_64::GetSupportedInvokeStaticOrDirectDispatch( |
| 750 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 751 | MethodReference target_method ATTRIBUTE_UNUSED) { |
| 752 | switch (desired_dispatch_info.code_ptr_location) { |
| 753 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 754 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 755 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 756 | return HInvokeStaticOrDirect::DispatchInfo { |
| 757 | desired_dispatch_info.method_load_kind, |
| 758 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
| 759 | desired_dispatch_info.method_load_data, |
| 760 | 0u |
| 761 | }; |
| 762 | default: |
| 763 | return desired_dispatch_info; |
| 764 | } |
| 765 | } |
| 766 | |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 767 | Location CodeGeneratorX86_64::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 768 | Location temp) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 769 | // All registers are assumed to be correctly set up. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 770 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 771 | switch (invoke->GetMethodLoadKind()) { |
| 772 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 773 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | 7f59d59 | 2015-12-29 16:20:52 +0000 | [diff] [blame] | 774 | __ gs()->movq(temp.AsRegister<CpuRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 775 | Address::Absolute(invoke->GetStringInitOffset(), /* no_rip */ true)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 776 | break; |
| 777 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 778 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 779 | break; |
| 780 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 781 | __ movq(temp.AsRegister<CpuRegister>(), Immediate(invoke->GetMethodAddress())); |
| 782 | break; |
| 783 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 784 | __ movl(temp.AsRegister<CpuRegister>(), Immediate(0)); // Placeholder. |
| 785 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 786 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 787 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 788 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 789 | __ movq(temp.AsRegister<CpuRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 790 | Address::Absolute(kDummy32BitOffset, /* no_rip */ false)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 791 | // Bind a new fixup label at the end of the "movl" insn. |
| 792 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
| 793 | __ Bind(NewPcRelativeDexCacheArrayPatch(*invoke->GetTargetMethod().dex_file, offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 794 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 795 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 796 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 797 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 798 | Register method_reg; |
| 799 | CpuRegister reg = temp.AsRegister<CpuRegister>(); |
| 800 | if (current_method.IsRegister()) { |
| 801 | method_reg = current_method.AsRegister<Register>(); |
| 802 | } else { |
| 803 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 804 | DCHECK(!current_method.IsValid()); |
| 805 | method_reg = reg.AsRegister(); |
| 806 | __ movq(reg, Address(CpuRegister(RSP), kCurrentMethodStackOffset)); |
| 807 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 808 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 809 | __ movq(reg, |
| 810 | Address(CpuRegister(method_reg), |
| 811 | ArtMethod::DexCacheResolvedMethodsOffset(kX86_64PointerSize).SizeValue())); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 812 | // temp = temp[index_in_cache]; |
| 813 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 814 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 815 | __ movq(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 816 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 817 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 818 | } |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 819 | return callee_method; |
| 820 | } |
| 821 | |
| 822 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 823 | Location temp) { |
| 824 | // All registers are assumed to be correctly set up. |
| 825 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 826 | |
| 827 | switch (invoke->GetCodePtrLocation()) { |
| 828 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 829 | __ call(&frame_entry_label_); |
| 830 | break; |
| 831 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 832 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 833 | Label* label = &relative_call_patches_.back().label; |
| 834 | __ call(label); // Bind to the patch label, override at link time. |
| 835 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 836 | break; |
| 837 | } |
| 838 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 839 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 840 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 841 | LOG(FATAL) << "Unsupported"; |
| 842 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 843 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 844 | // (callee_method + offset_of_quick_compiled_code)() |
| 845 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 846 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 847 | kX86_64WordSize).SizeValue())); |
| 848 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 849 | } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 850 | |
| 851 | DCHECK(!IsLeafMethod()); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 852 | } |
| 853 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 854 | void CodeGeneratorX86_64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 855 | CpuRegister temp = temp_in.AsRegister<CpuRegister>(); |
| 856 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 857 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 858 | |
| 859 | // Use the calling convention instead of the location of the receiver, as |
| 860 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 861 | // slow path, the arguments have been moved to the right place, so here we are |
| 862 | // guaranteed that the receiver is the first register of the calling convention. |
| 863 | InvokeDexCallingConvention calling_convention; |
| 864 | Register receiver = calling_convention.GetRegisterAt(0); |
| 865 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 866 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 867 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 868 | __ movl(temp, Address(CpuRegister(receiver), class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 869 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 870 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 871 | // emit a read barrier for the previous class reference load. |
| 872 | // However this is not required in practice, as this is an |
| 873 | // intermediate/temporary reference and because the current |
| 874 | // concurrent copying collector keeps the from-space memory |
| 875 | // intact/accessible until the end of the marking phase (the |
| 876 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 877 | __ MaybeUnpoisonHeapReference(temp); |
| 878 | // temp = temp->GetMethodAt(method_offset); |
| 879 | __ movq(temp, Address(temp, method_offset)); |
| 880 | // call temp->GetEntryPoint(); |
| 881 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 882 | kX86_64WordSize).SizeValue())); |
| 883 | } |
| 884 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 885 | void CodeGeneratorX86_64::RecordSimplePatch() { |
| 886 | if (GetCompilerOptions().GetIncludePatchInformation()) { |
| 887 | simple_patches_.emplace_back(); |
| 888 | __ Bind(&simple_patches_.back()); |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | void CodeGeneratorX86_64::RecordStringPatch(HLoadString* load_string) { |
| 893 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex()); |
| 894 | __ Bind(&string_patches_.back().label); |
| 895 | } |
| 896 | |
| 897 | Label* CodeGeneratorX86_64::NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, |
| 898 | uint32_t element_offset) { |
| 899 | // Add a patch entry and return the label. |
| 900 | pc_relative_dex_cache_patches_.emplace_back(dex_file, element_offset); |
| 901 | return &pc_relative_dex_cache_patches_.back().label; |
| 902 | } |
| 903 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 904 | void CodeGeneratorX86_64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 905 | DCHECK(linker_patches->empty()); |
| 906 | size_t size = |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 907 | method_patches_.size() + |
| 908 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 909 | pc_relative_dex_cache_patches_.size() + |
| 910 | simple_patches_.size() + |
| 911 | string_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 912 | linker_patches->reserve(size); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 913 | // The label points to the end of the "movl" insn but the literal offset for method |
| 914 | // patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 915 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 916 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 917 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 918 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 919 | info.target_method.dex_file, |
| 920 | info.target_method.dex_method_index)); |
| 921 | } |
| 922 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 923 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 924 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 925 | info.target_method.dex_file, |
| 926 | info.target_method.dex_method_index)); |
| 927 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 928 | for (const PcRelativeDexCacheAccessInfo& info : pc_relative_dex_cache_patches_) { |
| 929 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 930 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 931 | &info.target_dex_file, |
| 932 | info.label.Position(), |
| 933 | info.element_offset)); |
| 934 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 935 | for (const Label& label : simple_patches_) { |
| 936 | uint32_t literal_offset = label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 937 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 938 | } |
| 939 | for (const StringPatchInfo<Label>& info : string_patches_) { |
| 940 | // These are always PC-relative, see GetSupportedLoadStringKind(). |
| 941 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 942 | linker_patches->push_back(LinkerPatch::RelativeStringPatch(literal_offset, |
| 943 | &info.dex_file, |
| 944 | info.label.Position(), |
| 945 | info.string_index)); |
| 946 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 947 | } |
| 948 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 949 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 950 | stream << Register(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 954 | stream << FloatRegister(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 955 | } |
| 956 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 957 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 958 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 959 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 960 | } |
| 961 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 962 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 963 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 964 | return kX86_64WordSize; |
| 965 | } |
| 966 | |
| 967 | size_t CodeGeneratorX86_64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 968 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 969 | return kX86_64WordSize; |
| 970 | } |
| 971 | |
| 972 | size_t CodeGeneratorX86_64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 973 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 974 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 975 | } |
| 976 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 977 | void CodeGeneratorX86_64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 978 | HInstruction* instruction, |
| 979 | uint32_t dex_pc, |
| 980 | SlowPathCode* slow_path) { |
| 981 | InvokeRuntime(GetThreadOffset<kX86_64WordSize>(entrypoint).Int32Value(), |
| 982 | instruction, |
| 983 | dex_pc, |
| 984 | slow_path); |
| 985 | } |
| 986 | |
| 987 | void CodeGeneratorX86_64::InvokeRuntime(int32_t entry_point_offset, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 988 | HInstruction* instruction, |
| 989 | uint32_t dex_pc, |
| 990 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 991 | ValidateInvokeRuntime(instruction, slow_path); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 992 | __ gs()->call(Address::Absolute(entry_point_offset, /* no_rip */ true)); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 993 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 994 | } |
| 995 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 996 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 997 | // Use a fake return address register to mimic Quick. |
| 998 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 999 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1000 | const X86_64InstructionSetFeatures& isa_features, |
| 1001 | const CompilerOptions& compiler_options, |
| 1002 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1003 | : CodeGenerator(graph, |
| 1004 | kNumberOfCpuRegisters, |
| 1005 | kNumberOfFloatRegisters, |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1006 | kNumberOfCpuRegisterPairs, |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1007 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1008 | arraysize(kCoreCalleeSaves)) |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1009 | | (1 << kFakeReturnRegister), |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1010 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1011 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1012 | compiler_options, |
| 1013 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1014 | block_labels_(nullptr), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1015 | location_builder_(graph, this), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1016 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1017 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1018 | assembler_(graph->GetArena()), |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 1019 | isa_features_(isa_features), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1020 | constant_area_start_(0), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 1021 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1022 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1023 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1024 | simple_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1025 | string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 1026 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1027 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 1028 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1029 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1030 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 1031 | CodeGeneratorX86_64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1032 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1033 | assembler_(codegen->GetAssembler()), |
| 1034 | codegen_(codegen) {} |
| 1035 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1036 | void CodeGeneratorX86_64::SetupBlockedRegisters() const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1037 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1038 | blocked_core_registers_[RSP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1039 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1040 | // Block the register used as TMP. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1041 | blocked_core_registers_[TMP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1042 | } |
| 1043 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1044 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1045 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1046 | } |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1047 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1048 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1049 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1050 | } |
| 1051 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1052 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1053 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1054 | __ Bind(&frame_entry_label_); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1055 | bool skip_overflow_check = IsLeafMethod() |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 1056 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1057 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1058 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1059 | if (!skip_overflow_check) { |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1060 | __ testq(CpuRegister(RAX), Address( |
| 1061 | CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1062 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1063 | } |
Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 1064 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1065 | if (HasEmptyFrame()) { |
| 1066 | return; |
| 1067 | } |
| 1068 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1069 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1070 | Register reg = kCoreCalleeSaves[i]; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1071 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1072 | __ pushq(CpuRegister(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1073 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 1074 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1075 | } |
| 1076 | } |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1077 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1078 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1079 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 1080 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1081 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1082 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1083 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1084 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1085 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1086 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1087 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 1088 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1089 | } |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1090 | } |
| 1091 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1092 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1093 | CpuRegister(kMethodRegisterArgument)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1094 | } |
| 1095 | |
| 1096 | void CodeGeneratorX86_64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1097 | __ cfi().RememberState(); |
| 1098 | if (!HasEmptyFrame()) { |
| 1099 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1100 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| 1101 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1102 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 1103 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1104 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 1105 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 1106 | } |
| 1107 | } |
| 1108 | |
| 1109 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1110 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 1111 | __ cfi().AdjustCFAOffset(-adjust); |
| 1112 | |
| 1113 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1114 | Register reg = kCoreCalleeSaves[i]; |
| 1115 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1116 | __ popq(CpuRegister(reg)); |
| 1117 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 1118 | __ cfi().Restore(DWARFReg(reg)); |
| 1119 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1120 | } |
| 1121 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1122 | __ ret(); |
| 1123 | __ cfi().RestoreState(); |
| 1124 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1125 | } |
| 1126 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1127 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 1128 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1129 | } |
| 1130 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1131 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 1132 | if (source.Equals(destination)) { |
| 1133 | return; |
| 1134 | } |
| 1135 | if (destination.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1136 | CpuRegister dest = destination.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1137 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1138 | __ movq(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1139 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1140 | __ movd(dest, source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1141 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1142 | __ movl(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1143 | } else if (source.IsConstant()) { |
| 1144 | HConstant* constant = source.GetConstant(); |
| 1145 | if (constant->IsLongConstant()) { |
| 1146 | Load64BitValue(dest, constant->AsLongConstant()->GetValue()); |
| 1147 | } else { |
| 1148 | Load32BitValue(dest, GetInt32ValueOf(constant)); |
| 1149 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1150 | } else { |
| 1151 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1152 | __ movq(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1153 | } |
| 1154 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1155 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1156 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1157 | __ movd(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1158 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1159 | __ movaps(dest, source.AsFpuRegister<XmmRegister>()); |
| 1160 | } else if (source.IsConstant()) { |
| 1161 | HConstant* constant = source.GetConstant(); |
| 1162 | int64_t value = CodeGenerator::GetInt64ValueOf(constant); |
| 1163 | if (constant->IsFloatConstant()) { |
| 1164 | Load32BitValue(dest, static_cast<int32_t>(value)); |
| 1165 | } else { |
| 1166 | Load64BitValue(dest, value); |
| 1167 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1168 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1169 | __ movss(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1170 | } else { |
| 1171 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1172 | __ movsd(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1173 | } |
| 1174 | } else if (destination.IsStackSlot()) { |
| 1175 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1176 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1177 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1178 | } else if (source.IsFpuRegister()) { |
| 1179 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1180 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1181 | } else if (source.IsConstant()) { |
| 1182 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1183 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1184 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1185 | } else { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1186 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1187 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1188 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1189 | } |
| 1190 | } else { |
| 1191 | DCHECK(destination.IsDoubleStackSlot()); |
| 1192 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1193 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1194 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1195 | } else if (source.IsFpuRegister()) { |
| 1196 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1197 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1198 | } else if (source.IsConstant()) { |
| 1199 | HConstant* constant = source.GetConstant(); |
Zheng Xu | 12bca97 | 2015-03-30 19:35:50 +0800 | [diff] [blame] | 1200 | int64_t value; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1201 | if (constant->IsDoubleConstant()) { |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 1202 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1203 | } else { |
| 1204 | DCHECK(constant->IsLongConstant()); |
| 1205 | value = constant->AsLongConstant()->GetValue(); |
| 1206 | } |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 1207 | Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1208 | } else { |
| 1209 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1210 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1211 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1212 | } |
| 1213 | } |
| 1214 | } |
| 1215 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1216 | void CodeGeneratorX86_64::MoveConstant(Location location, int32_t value) { |
| 1217 | DCHECK(location.IsRegister()); |
| 1218 | Load64BitValue(location.AsRegister<CpuRegister>(), static_cast<int64_t>(value)); |
| 1219 | } |
| 1220 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1221 | void CodeGeneratorX86_64::MoveLocation( |
| 1222 | Location dst, Location src, Primitive::Type dst_type ATTRIBUTE_UNUSED) { |
| 1223 | Move(dst, src); |
| 1224 | } |
| 1225 | |
| 1226 | void CodeGeneratorX86_64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1227 | if (location.IsRegister()) { |
| 1228 | locations->AddTemp(location); |
| 1229 | } else { |
| 1230 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1231 | } |
| 1232 | } |
| 1233 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1234 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1235 | DCHECK(!successor->IsExitBlock()); |
| 1236 | |
| 1237 | HBasicBlock* block = got->GetBlock(); |
| 1238 | HInstruction* previous = got->GetPrevious(); |
| 1239 | |
| 1240 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1241 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1242 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1243 | return; |
| 1244 | } |
| 1245 | |
| 1246 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1247 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1248 | } |
| 1249 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1250 | __ jmp(codegen_->GetLabelOf(successor)); |
| 1251 | } |
| 1252 | } |
| 1253 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1254 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 1255 | got->SetLocations(nullptr); |
| 1256 | } |
| 1257 | |
| 1258 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 1259 | HandleGoto(got, got->GetSuccessor()); |
| 1260 | } |
| 1261 | |
| 1262 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1263 | try_boundary->SetLocations(nullptr); |
| 1264 | } |
| 1265 | |
| 1266 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1267 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1268 | if (!successor->IsExitBlock()) { |
| 1269 | HandleGoto(try_boundary, successor); |
| 1270 | } |
| 1271 | } |
| 1272 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1273 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 1274 | exit->SetLocations(nullptr); |
| 1275 | } |
| 1276 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1277 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1278 | } |
| 1279 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1280 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1281 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1282 | LabelType* true_label, |
| 1283 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1284 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1285 | __ j(kUnordered, true_label); |
| 1286 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1287 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1288 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1289 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1290 | } |
| 1291 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1292 | void InstructionCodeGeneratorX86_64::GenerateCompareTest(HCondition* condition) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1293 | LocationSummary* locations = condition->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1294 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1295 | Location left = locations->InAt(0); |
| 1296 | Location right = locations->InAt(1); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1297 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1298 | switch (type) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1299 | case Primitive::kPrimBoolean: |
| 1300 | case Primitive::kPrimByte: |
| 1301 | case Primitive::kPrimChar: |
| 1302 | case Primitive::kPrimShort: |
| 1303 | case Primitive::kPrimInt: |
| 1304 | case Primitive::kPrimNot: { |
| 1305 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1306 | if (right.IsConstant()) { |
| 1307 | int32_t value = CodeGenerator::GetInt32ValueOf(right.GetConstant()); |
| 1308 | if (value == 0) { |
| 1309 | __ testl(left_reg, left_reg); |
| 1310 | } else { |
| 1311 | __ cmpl(left_reg, Immediate(value)); |
| 1312 | } |
| 1313 | } else if (right.IsStackSlot()) { |
| 1314 | __ cmpl(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1315 | } else { |
| 1316 | __ cmpl(left_reg, right.AsRegister<CpuRegister>()); |
| 1317 | } |
| 1318 | break; |
| 1319 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1320 | case Primitive::kPrimLong: { |
| 1321 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1322 | if (right.IsConstant()) { |
| 1323 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1324 | codegen_->Compare64BitValue(left_reg, value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1325 | } else if (right.IsDoubleStackSlot()) { |
| 1326 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1327 | } else { |
| 1328 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1329 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1330 | break; |
| 1331 | } |
| 1332 | case Primitive::kPrimFloat: { |
| 1333 | if (right.IsFpuRegister()) { |
| 1334 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1335 | } else if (right.IsConstant()) { |
| 1336 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1337 | codegen_->LiteralFloatAddress( |
| 1338 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1339 | } else { |
| 1340 | DCHECK(right.IsStackSlot()); |
| 1341 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1342 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1343 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1344 | break; |
| 1345 | } |
| 1346 | case Primitive::kPrimDouble: { |
| 1347 | if (right.IsFpuRegister()) { |
| 1348 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1349 | } else if (right.IsConstant()) { |
| 1350 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1351 | codegen_->LiteralDoubleAddress( |
| 1352 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1353 | } else { |
| 1354 | DCHECK(right.IsDoubleStackSlot()); |
| 1355 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1356 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1357 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1358 | break; |
| 1359 | } |
| 1360 | default: |
| 1361 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1362 | } |
| 1363 | } |
| 1364 | |
| 1365 | template<class LabelType> |
| 1366 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HCondition* condition, |
| 1367 | LabelType* true_target_in, |
| 1368 | LabelType* false_target_in) { |
| 1369 | // Generated branching requires both targets to be explicit. If either of the |
| 1370 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1371 | LabelType fallthrough_target; |
| 1372 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1373 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1374 | |
| 1375 | // Generate the comparison to set the CC. |
| 1376 | GenerateCompareTest(condition); |
| 1377 | |
| 1378 | // Now generate the correct jump(s). |
| 1379 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1380 | switch (type) { |
| 1381 | case Primitive::kPrimLong: { |
| 1382 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
| 1383 | break; |
| 1384 | } |
| 1385 | case Primitive::kPrimFloat: { |
| 1386 | GenerateFPJumps(condition, true_target, false_target); |
| 1387 | break; |
| 1388 | } |
| 1389 | case Primitive::kPrimDouble: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1390 | GenerateFPJumps(condition, true_target, false_target); |
| 1391 | break; |
| 1392 | } |
| 1393 | default: |
| 1394 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1395 | } |
| 1396 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1397 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1398 | __ jmp(false_target); |
| 1399 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1400 | |
| 1401 | if (fallthrough_target.IsLinked()) { |
| 1402 | __ Bind(&fallthrough_target); |
| 1403 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1404 | } |
| 1405 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1406 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1407 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1408 | // are set only strictly before `branch`. We can't use the eflags on long |
| 1409 | // conditions if they are materialized due to the complex branching. |
| 1410 | return cond->IsCondition() && |
| 1411 | cond->GetNext() == branch && |
| 1412 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1413 | } |
| 1414 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1415 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1416 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1417 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1418 | LabelType* true_target, |
| 1419 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1420 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1421 | |
| 1422 | if (true_target == nullptr && false_target == nullptr) { |
| 1423 | // Nothing to do. The code always falls through. |
| 1424 | return; |
| 1425 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1426 | // Constant condition, statically compared against "true" (integer value 1). |
| 1427 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1428 | if (true_target != nullptr) { |
| 1429 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1430 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1431 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1432 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1433 | if (false_target != nullptr) { |
| 1434 | __ jmp(false_target); |
| 1435 | } |
| 1436 | } |
| 1437 | return; |
| 1438 | } |
| 1439 | |
| 1440 | // The following code generates these patterns: |
| 1441 | // (1) true_target == nullptr && false_target != nullptr |
| 1442 | // - opposite condition true => branch to false_target |
| 1443 | // (2) true_target != nullptr && false_target == nullptr |
| 1444 | // - condition true => branch to true_target |
| 1445 | // (3) true_target != nullptr && false_target != nullptr |
| 1446 | // - condition true => branch to true_target |
| 1447 | // - branch to false_target |
| 1448 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1449 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1450 | if (true_target == nullptr) { |
| 1451 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1452 | } else { |
| 1453 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
| 1454 | } |
| 1455 | } else { |
| 1456 | // Materialized condition, compare against 0. |
| 1457 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1458 | if (lhs.IsRegister()) { |
| 1459 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1460 | } else { |
| 1461 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), Immediate(0)); |
| 1462 | } |
| 1463 | if (true_target == nullptr) { |
| 1464 | __ j(kEqual, false_target); |
| 1465 | } else { |
| 1466 | __ j(kNotEqual, true_target); |
| 1467 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1468 | } |
| 1469 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1470 | // Condition has not been materialized, use its inputs as the |
| 1471 | // comparison and its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1472 | HCondition* condition = cond->AsCondition(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1473 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1474 | // If this is a long or FP comparison that has been folded into |
| 1475 | // the HCondition, generate the comparison directly. |
| 1476 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1477 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1478 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1479 | return; |
| 1480 | } |
| 1481 | |
| 1482 | Location lhs = condition->GetLocations()->InAt(0); |
| 1483 | Location rhs = condition->GetLocations()->InAt(1); |
| 1484 | if (rhs.IsRegister()) { |
| 1485 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1486 | } else if (rhs.IsConstant()) { |
| 1487 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1488 | codegen_->Compare32BitValue(lhs.AsRegister<CpuRegister>(), constant); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1489 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1490 | __ cmpl(lhs.AsRegister<CpuRegister>(), |
| 1491 | Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1492 | } |
| 1493 | if (true_target == nullptr) { |
| 1494 | __ j(X86_64IntegerCondition(condition->GetOppositeCondition()), false_target); |
| 1495 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1496 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1497 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1498 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1499 | |
| 1500 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1501 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1502 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1503 | __ jmp(false_target); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1504 | } |
| 1505 | } |
| 1506 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1507 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1508 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1509 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1510 | locations->SetInAt(0, Location::Any()); |
| 1511 | } |
| 1512 | } |
| 1513 | |
| 1514 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1515 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1516 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1517 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1518 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1519 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1520 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1521 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1525 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1526 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1527 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1528 | locations->SetInAt(0, Location::Any()); |
| 1529 | } |
| 1530 | } |
| 1531 | |
| 1532 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1533 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86_64>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1534 | GenerateTestAndBranch<Label>(deoptimize, |
| 1535 | /* condition_input_index */ 0, |
| 1536 | slow_path->GetEntryLabel(), |
| 1537 | /* false_target */ nullptr); |
| 1538 | } |
| 1539 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1540 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1541 | // There are no conditional move instructions for XMMs. |
| 1542 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1543 | return false; |
| 1544 | } |
| 1545 | |
| 1546 | // A FP condition doesn't generate the single CC that we need. |
| 1547 | HInstruction* condition = select->GetCondition(); |
| 1548 | if (condition->IsCondition() && |
| 1549 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())) { |
| 1550 | return false; |
| 1551 | } |
| 1552 | |
| 1553 | // We can generate a CMOV for this Select. |
| 1554 | return true; |
| 1555 | } |
| 1556 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1557 | void LocationsBuilderX86_64::VisitSelect(HSelect* select) { |
| 1558 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 1559 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1560 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1561 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1562 | } else { |
| 1563 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1564 | if (SelectCanUseCMOV(select)) { |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1565 | if (select->InputAt(1)->IsConstant()) { |
| 1566 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1567 | } else { |
| 1568 | locations->SetInAt(1, Location::Any()); |
| 1569 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1570 | } else { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1571 | locations->SetInAt(1, Location::Any()); |
| 1572 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1573 | } |
| 1574 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1575 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1576 | } |
| 1577 | locations->SetOut(Location::SameAsFirstInput()); |
| 1578 | } |
| 1579 | |
| 1580 | void InstructionCodeGeneratorX86_64::VisitSelect(HSelect* select) { |
| 1581 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1582 | if (SelectCanUseCMOV(select)) { |
| 1583 | // If both the condition and the source types are integer, we can generate |
| 1584 | // a CMOV to implement Select. |
| 1585 | CpuRegister value_false = locations->InAt(0).AsRegister<CpuRegister>(); |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1586 | Location value_true_loc = locations->InAt(1); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1587 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1588 | |
| 1589 | HInstruction* select_condition = select->GetCondition(); |
| 1590 | Condition cond = kNotEqual; |
| 1591 | |
| 1592 | // Figure out how to test the 'condition'. |
| 1593 | if (select_condition->IsCondition()) { |
| 1594 | HCondition* condition = select_condition->AsCondition(); |
| 1595 | if (!condition->IsEmittedAtUseSite()) { |
| 1596 | // This was a previously materialized condition. |
| 1597 | // Can we use the existing condition code? |
| 1598 | if (AreEflagsSetFrom(condition, select)) { |
| 1599 | // Materialization was the previous instruction. Condition codes are right. |
| 1600 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1601 | } else { |
| 1602 | // No, we have to recreate the condition code. |
| 1603 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1604 | __ testl(cond_reg, cond_reg); |
| 1605 | } |
| 1606 | } else { |
| 1607 | GenerateCompareTest(condition); |
| 1608 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1609 | } |
| 1610 | } else { |
| 1611 | // Must be a boolean condition, which needs to be compared to 0. |
| 1612 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1613 | __ testl(cond_reg, cond_reg); |
| 1614 | } |
| 1615 | |
| 1616 | // If the condition is true, overwrite the output, which already contains false. |
| 1617 | // Generate the correct sized CMOV. |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1618 | bool is_64_bit = Primitive::Is64BitType(select->GetType()); |
| 1619 | if (value_true_loc.IsRegister()) { |
| 1620 | __ cmov(cond, value_false, value_true_loc.AsRegister<CpuRegister>(), is_64_bit); |
| 1621 | } else { |
| 1622 | __ cmov(cond, |
| 1623 | value_false, |
| 1624 | Address(CpuRegister(RSP), value_true_loc.GetStackIndex()), is_64_bit); |
| 1625 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1626 | } else { |
| 1627 | NearLabel false_target; |
| 1628 | GenerateTestAndBranch<NearLabel>(select, |
| 1629 | /* condition_input_index */ 2, |
| 1630 | /* true_target */ nullptr, |
| 1631 | &false_target); |
| 1632 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1633 | __ Bind(&false_target); |
| 1634 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1635 | } |
| 1636 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1637 | void LocationsBuilderX86_64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1638 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1639 | } |
| 1640 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1641 | void InstructionCodeGeneratorX86_64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1642 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1643 | } |
| 1644 | |
| 1645 | void CodeGeneratorX86_64::GenerateNop() { |
| 1646 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1647 | } |
| 1648 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1649 | void LocationsBuilderX86_64::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1650 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1651 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1652 | // Handle the long/FP comparisons made in instruction simplification. |
| 1653 | switch (cond->InputAt(0)->GetType()) { |
| 1654 | case Primitive::kPrimLong: |
| 1655 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1656 | locations->SetInAt(1, Location::Any()); |
| 1657 | break; |
| 1658 | case Primitive::kPrimFloat: |
| 1659 | case Primitive::kPrimDouble: |
| 1660 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1661 | locations->SetInAt(1, Location::Any()); |
| 1662 | break; |
| 1663 | default: |
| 1664 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1665 | locations->SetInAt(1, Location::Any()); |
| 1666 | break; |
| 1667 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1668 | if (!cond->IsEmittedAtUseSite()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1669 | locations->SetOut(Location::RequiresRegister()); |
| 1670 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1671 | } |
| 1672 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1673 | void InstructionCodeGeneratorX86_64::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1674 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1675 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1676 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1677 | |
| 1678 | LocationSummary* locations = cond->GetLocations(); |
| 1679 | Location lhs = locations->InAt(0); |
| 1680 | Location rhs = locations->InAt(1); |
| 1681 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1682 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1683 | |
| 1684 | switch (cond->InputAt(0)->GetType()) { |
| 1685 | default: |
| 1686 | // Integer case. |
| 1687 | |
| 1688 | // Clear output register: setcc only sets the low byte. |
| 1689 | __ xorl(reg, reg); |
| 1690 | |
| 1691 | if (rhs.IsRegister()) { |
| 1692 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1693 | } else if (rhs.IsConstant()) { |
| 1694 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1695 | codegen_->Compare32BitValue(lhs.AsRegister<CpuRegister>(), constant); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1696 | } else { |
| 1697 | __ cmpl(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1698 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1699 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1700 | return; |
| 1701 | case Primitive::kPrimLong: |
| 1702 | // Clear output register: setcc only sets the low byte. |
| 1703 | __ xorl(reg, reg); |
| 1704 | |
| 1705 | if (rhs.IsRegister()) { |
| 1706 | __ cmpq(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1707 | } else if (rhs.IsConstant()) { |
| 1708 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1709 | codegen_->Compare64BitValue(lhs.AsRegister<CpuRegister>(), value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1710 | } else { |
| 1711 | __ cmpq(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1712 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1713 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1714 | return; |
| 1715 | case Primitive::kPrimFloat: { |
| 1716 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1717 | if (rhs.IsConstant()) { |
| 1718 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 1719 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 1720 | } else if (rhs.IsStackSlot()) { |
| 1721 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1722 | } else { |
| 1723 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1724 | } |
| 1725 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1726 | break; |
| 1727 | } |
| 1728 | case Primitive::kPrimDouble: { |
| 1729 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1730 | if (rhs.IsConstant()) { |
| 1731 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1732 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 1733 | } else if (rhs.IsDoubleStackSlot()) { |
| 1734 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1735 | } else { |
| 1736 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1737 | } |
| 1738 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1739 | break; |
| 1740 | } |
| 1741 | } |
| 1742 | |
| 1743 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1744 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1745 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1746 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1747 | __ Bind(&false_label); |
| 1748 | __ xorl(reg, reg); |
| 1749 | __ jmp(&done_label); |
| 1750 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1751 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1752 | __ Bind(&true_label); |
| 1753 | __ movl(reg, Immediate(1)); |
| 1754 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1758 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1759 | } |
| 1760 | |
| 1761 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1762 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1766 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1770 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1774 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1775 | } |
| 1776 | |
| 1777 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1778 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1782 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1783 | } |
| 1784 | |
| 1785 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1786 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1790 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1794 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1798 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1799 | } |
| 1800 | |
| 1801 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1802 | HandleCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1803 | } |
| 1804 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1805 | void LocationsBuilderX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1806 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | void InstructionCodeGeneratorX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1810 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | void LocationsBuilderX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1814 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | void InstructionCodeGeneratorX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1818 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | void LocationsBuilderX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1822 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1823 | } |
| 1824 | |
| 1825 | void InstructionCodeGeneratorX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1826 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1827 | } |
| 1828 | |
| 1829 | void LocationsBuilderX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1830 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1831 | } |
| 1832 | |
| 1833 | void InstructionCodeGeneratorX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1834 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1835 | } |
| 1836 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1837 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1838 | LocationSummary* locations = |
| 1839 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1840 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 1841 | case Primitive::kPrimBoolean: |
| 1842 | case Primitive::kPrimByte: |
| 1843 | case Primitive::kPrimShort: |
| 1844 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1845 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1846 | case Primitive::kPrimLong: { |
| 1847 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1848 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1849 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1850 | break; |
| 1851 | } |
| 1852 | case Primitive::kPrimFloat: |
| 1853 | case Primitive::kPrimDouble: { |
| 1854 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1855 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1856 | locations->SetOut(Location::RequiresRegister()); |
| 1857 | break; |
| 1858 | } |
| 1859 | default: |
| 1860 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 1861 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1862 | } |
| 1863 | |
| 1864 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1865 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1866 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1867 | Location left = locations->InAt(0); |
| 1868 | Location right = locations->InAt(1); |
| 1869 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1870 | NearLabel less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1871 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1872 | Condition less_cond = kLess; |
| 1873 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1874 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 1875 | case Primitive::kPrimBoolean: |
| 1876 | case Primitive::kPrimByte: |
| 1877 | case Primitive::kPrimShort: |
| 1878 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1879 | case Primitive::kPrimInt: { |
| 1880 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1881 | if (right.IsConstant()) { |
| 1882 | int32_t value = right.GetConstant()->AsIntConstant()->GetValue(); |
| 1883 | codegen_->Compare32BitValue(left_reg, value); |
| 1884 | } else if (right.IsStackSlot()) { |
| 1885 | __ cmpl(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1886 | } else { |
| 1887 | __ cmpl(left_reg, right.AsRegister<CpuRegister>()); |
| 1888 | } |
| 1889 | break; |
| 1890 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1891 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1892 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1893 | if (right.IsConstant()) { |
| 1894 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1895 | codegen_->Compare64BitValue(left_reg, value); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1896 | } else if (right.IsDoubleStackSlot()) { |
| 1897 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1898 | } else { |
| 1899 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1900 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1901 | break; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1902 | } |
| 1903 | case Primitive::kPrimFloat: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1904 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1905 | if (right.IsConstant()) { |
| 1906 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 1907 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 1908 | } else if (right.IsStackSlot()) { |
| 1909 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1910 | } else { |
| 1911 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1912 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1913 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1914 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1915 | break; |
| 1916 | } |
| 1917 | case Primitive::kPrimDouble: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1918 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1919 | if (right.IsConstant()) { |
| 1920 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1921 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 1922 | } else if (right.IsDoubleStackSlot()) { |
| 1923 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1924 | } else { |
| 1925 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1926 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1927 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1928 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1929 | break; |
| 1930 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1931 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1932 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1933 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1934 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1935 | __ movl(out, Immediate(0)); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1936 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1937 | __ j(less_cond, &less); |
Calin Juravle | fd86124 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1938 | |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1939 | __ Bind(&greater); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1940 | __ movl(out, Immediate(1)); |
| 1941 | __ jmp(&done); |
| 1942 | |
| 1943 | __ Bind(&less); |
| 1944 | __ movl(out, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1945 | |
| 1946 | __ Bind(&done); |
| 1947 | } |
| 1948 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1949 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1950 | LocationSummary* locations = |
| 1951 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1952 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1953 | } |
| 1954 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1955 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1956 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1957 | } |
| 1958 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1959 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 1960 | LocationSummary* locations = |
| 1961 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1962 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1963 | } |
| 1964 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1965 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1966 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1967 | } |
| 1968 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1969 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1970 | LocationSummary* locations = |
| 1971 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1972 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1973 | } |
| 1974 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1975 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1976 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1977 | } |
| 1978 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1979 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 1980 | LocationSummary* locations = |
| 1981 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1982 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1983 | } |
| 1984 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1985 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1986 | // Will be generated at use site. |
| 1987 | } |
| 1988 | |
| 1989 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1990 | LocationSummary* locations = |
| 1991 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1992 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1993 | } |
| 1994 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1995 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant( |
| 1996 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1997 | // Will be generated at use site. |
| 1998 | } |
| 1999 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2000 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2001 | memory_barrier->SetLocations(nullptr); |
| 2002 | } |
| 2003 | |
| 2004 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2005 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2006 | } |
| 2007 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2008 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 2009 | ret->SetLocations(nullptr); |
| 2010 | } |
| 2011 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2012 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2013 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2014 | } |
| 2015 | |
| 2016 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2017 | LocationSummary* locations = |
| 2018 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2019 | switch (ret->InputAt(0)->GetType()) { |
| 2020 | case Primitive::kPrimBoolean: |
| 2021 | case Primitive::kPrimByte: |
| 2022 | case Primitive::kPrimChar: |
| 2023 | case Primitive::kPrimShort: |
| 2024 | case Primitive::kPrimInt: |
| 2025 | case Primitive::kPrimNot: |
| 2026 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2027 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2028 | break; |
| 2029 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2030 | case Primitive::kPrimFloat: |
| 2031 | case Primitive::kPrimDouble: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2032 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2033 | break; |
| 2034 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2035 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2036 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2037 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2038 | } |
| 2039 | |
| 2040 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 2041 | if (kIsDebugBuild) { |
| 2042 | switch (ret->InputAt(0)->GetType()) { |
| 2043 | case Primitive::kPrimBoolean: |
| 2044 | case Primitive::kPrimByte: |
| 2045 | case Primitive::kPrimChar: |
| 2046 | case Primitive::kPrimShort: |
| 2047 | case Primitive::kPrimInt: |
| 2048 | case Primitive::kPrimNot: |
| 2049 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2050 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2051 | break; |
| 2052 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2053 | case Primitive::kPrimFloat: |
| 2054 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2055 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2056 | XMM0); |
| 2057 | break; |
| 2058 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2059 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2060 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2061 | } |
| 2062 | } |
| 2063 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2064 | } |
| 2065 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2066 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(Primitive::Type type) const { |
| 2067 | switch (type) { |
| 2068 | case Primitive::kPrimBoolean: |
| 2069 | case Primitive::kPrimByte: |
| 2070 | case Primitive::kPrimChar: |
| 2071 | case Primitive::kPrimShort: |
| 2072 | case Primitive::kPrimInt: |
| 2073 | case Primitive::kPrimNot: |
| 2074 | case Primitive::kPrimLong: |
| 2075 | return Location::RegisterLocation(RAX); |
| 2076 | |
| 2077 | case Primitive::kPrimVoid: |
| 2078 | return Location::NoLocation(); |
| 2079 | |
| 2080 | case Primitive::kPrimDouble: |
| 2081 | case Primitive::kPrimFloat: |
| 2082 | return Location::FpuRegisterLocation(XMM0); |
| 2083 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2084 | |
| 2085 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2086 | } |
| 2087 | |
| 2088 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 2089 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2090 | } |
| 2091 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2092 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2093 | switch (type) { |
| 2094 | case Primitive::kPrimBoolean: |
| 2095 | case Primitive::kPrimByte: |
| 2096 | case Primitive::kPrimChar: |
| 2097 | case Primitive::kPrimShort: |
| 2098 | case Primitive::kPrimInt: |
| 2099 | case Primitive::kPrimNot: { |
| 2100 | uint32_t index = gp_index_++; |
| 2101 | stack_index_++; |
| 2102 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2103 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2104 | } else { |
| 2105 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2106 | } |
| 2107 | } |
| 2108 | |
| 2109 | case Primitive::kPrimLong: { |
| 2110 | uint32_t index = gp_index_; |
| 2111 | stack_index_ += 2; |
| 2112 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2113 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2114 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2115 | } else { |
| 2116 | gp_index_ += 2; |
| 2117 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2118 | } |
| 2119 | } |
| 2120 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2121 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2122 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2123 | stack_index_++; |
| 2124 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2125 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2126 | } else { |
| 2127 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2128 | } |
| 2129 | } |
| 2130 | |
| 2131 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2132 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2133 | stack_index_ += 2; |
| 2134 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2135 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2136 | } else { |
| 2137 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2138 | } |
| 2139 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2140 | |
| 2141 | case Primitive::kPrimVoid: |
| 2142 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2143 | break; |
| 2144 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2145 | return Location::NoLocation(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2146 | } |
| 2147 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2148 | void LocationsBuilderX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2149 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2150 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2151 | // the method_idx. |
| 2152 | HandleInvoke(invoke); |
| 2153 | } |
| 2154 | |
| 2155 | void InstructionCodeGeneratorX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2156 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2157 | } |
| 2158 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2159 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2160 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2161 | // art::PrepareForRegisterAllocation. |
| 2162 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2163 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2164 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2165 | if (intrinsic.TryDispatch(invoke)) { |
| 2166 | return; |
| 2167 | } |
| 2168 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2169 | HandleInvoke(invoke); |
| 2170 | } |
| 2171 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2172 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 2173 | if (invoke->GetLocations()->Intrinsified()) { |
| 2174 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 2175 | intrinsic.Dispatch(invoke); |
| 2176 | return true; |
| 2177 | } |
| 2178 | return false; |
| 2179 | } |
| 2180 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2181 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2182 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2183 | // art::PrepareForRegisterAllocation. |
| 2184 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2185 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2186 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2187 | return; |
| 2188 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2189 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2190 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2191 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2192 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 2193 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2194 | } |
| 2195 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2196 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2197 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2198 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2199 | } |
| 2200 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2201 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2202 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2203 | if (intrinsic.TryDispatch(invoke)) { |
| 2204 | return; |
| 2205 | } |
| 2206 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2207 | HandleInvoke(invoke); |
| 2208 | } |
| 2209 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2210 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2211 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2212 | return; |
| 2213 | } |
| 2214 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2215 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2216 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2217 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2218 | } |
| 2219 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2220 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2221 | HandleInvoke(invoke); |
| 2222 | // Add the hidden argument. |
| 2223 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 2224 | } |
| 2225 | |
| 2226 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2227 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2228 | LocationSummary* locations = invoke->GetLocations(); |
| 2229 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2230 | CpuRegister hidden_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2231 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 2232 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86_64PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2233 | Location receiver = locations->InAt(0); |
| 2234 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 2235 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2236 | // Set the hidden argument. This is safe to do this here, as RAX |
| 2237 | // won't be modified thereafter, before the `call` instruction. |
| 2238 | DCHECK_EQ(RAX, hidden_reg.AsRegister()); |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2239 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2240 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2241 | if (receiver.IsStackSlot()) { |
| 2242 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2243 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2244 | __ movl(temp, Address(temp, class_offset)); |
| 2245 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2246 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2247 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2248 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2249 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2250 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2251 | // emit a read barrier for the previous class reference load. |
| 2252 | // However this is not required in practice, as this is an |
| 2253 | // intermediate/temporary reference and because the current |
| 2254 | // concurrent copying collector keeps the from-space memory |
| 2255 | // intact/accessible until the end of the marking phase (the |
| 2256 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2257 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2258 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2259 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2260 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2261 | __ call(Address(temp, |
| 2262 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64WordSize).SizeValue())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2263 | |
| 2264 | DCHECK(!codegen_->IsLeafMethod()); |
| 2265 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2266 | } |
| 2267 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2268 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 2269 | LocationSummary* locations = |
| 2270 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2271 | switch (neg->GetResultType()) { |
| 2272 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2273 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2274 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2275 | locations->SetOut(Location::SameAsFirstInput()); |
| 2276 | break; |
| 2277 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2278 | case Primitive::kPrimFloat: |
| 2279 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2280 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2281 | locations->SetOut(Location::SameAsFirstInput()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2282 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2283 | break; |
| 2284 | |
| 2285 | default: |
| 2286 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2287 | } |
| 2288 | } |
| 2289 | |
| 2290 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 2291 | LocationSummary* locations = neg->GetLocations(); |
| 2292 | Location out = locations->Out(); |
| 2293 | Location in = locations->InAt(0); |
| 2294 | switch (neg->GetResultType()) { |
| 2295 | case Primitive::kPrimInt: |
| 2296 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2297 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2298 | __ negl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2299 | break; |
| 2300 | |
| 2301 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2302 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2303 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2304 | __ negq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2305 | break; |
| 2306 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2307 | case Primitive::kPrimFloat: { |
| 2308 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2309 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2310 | // Implement float negation with an exclusive or with value |
| 2311 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2312 | // single-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2313 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2314 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2315 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2316 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2317 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2318 | case Primitive::kPrimDouble: { |
| 2319 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2320 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2321 | // Implement double negation with an exclusive or with value |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2322 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2323 | // a double-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2324 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2325 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2326 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2327 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2328 | |
| 2329 | default: |
| 2330 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2331 | } |
| 2332 | } |
| 2333 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2334 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2335 | LocationSummary* locations = |
| 2336 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 2337 | Primitive::Type result_type = conversion->GetResultType(); |
| 2338 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2339 | DCHECK_NE(result_type, input_type); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2340 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2341 | // The Java language does not allow treating boolean as an integral type but |
| 2342 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2343 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2344 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2345 | case Primitive::kPrimByte: |
| 2346 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2347 | case Primitive::kPrimLong: |
| 2348 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2349 | case Primitive::kPrimBoolean: |
| 2350 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2351 | case Primitive::kPrimShort: |
| 2352 | case Primitive::kPrimInt: |
| 2353 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2354 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2355 | locations->SetInAt(0, Location::Any()); |
| 2356 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2357 | break; |
| 2358 | |
| 2359 | default: |
| 2360 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2361 | << " to " << result_type; |
| 2362 | } |
| 2363 | break; |
| 2364 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2365 | case Primitive::kPrimShort: |
| 2366 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2367 | case Primitive::kPrimLong: |
| 2368 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2369 | case Primitive::kPrimBoolean: |
| 2370 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2371 | case Primitive::kPrimByte: |
| 2372 | case Primitive::kPrimInt: |
| 2373 | case Primitive::kPrimChar: |
| 2374 | // Processing a Dex `int-to-short' instruction. |
| 2375 | locations->SetInAt(0, Location::Any()); |
| 2376 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2377 | break; |
| 2378 | |
| 2379 | default: |
| 2380 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2381 | << " to " << result_type; |
| 2382 | } |
| 2383 | break; |
| 2384 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2385 | case Primitive::kPrimInt: |
| 2386 | switch (input_type) { |
| 2387 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2388 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2389 | locations->SetInAt(0, Location::Any()); |
| 2390 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2391 | break; |
| 2392 | |
| 2393 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2394 | // Processing a Dex `float-to-int' instruction. |
| 2395 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2396 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2397 | break; |
| 2398 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2399 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2400 | // Processing a Dex `double-to-int' instruction. |
| 2401 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2402 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2403 | break; |
| 2404 | |
| 2405 | default: |
| 2406 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2407 | << " to " << result_type; |
| 2408 | } |
| 2409 | break; |
| 2410 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2411 | case Primitive::kPrimLong: |
| 2412 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2413 | case Primitive::kPrimBoolean: |
| 2414 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2415 | case Primitive::kPrimByte: |
| 2416 | case Primitive::kPrimShort: |
| 2417 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2418 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2419 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2420 | // TODO: We would benefit from a (to-be-implemented) |
| 2421 | // Location::RegisterOrStackSlot requirement for this input. |
| 2422 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2423 | locations->SetOut(Location::RequiresRegister()); |
| 2424 | break; |
| 2425 | |
| 2426 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2427 | // Processing a Dex `float-to-long' instruction. |
| 2428 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2429 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2430 | break; |
| 2431 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2432 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2433 | // Processing a Dex `double-to-long' instruction. |
| 2434 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2435 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2436 | break; |
| 2437 | |
| 2438 | default: |
| 2439 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2440 | << " to " << result_type; |
| 2441 | } |
| 2442 | break; |
| 2443 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2444 | case Primitive::kPrimChar: |
| 2445 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2446 | case Primitive::kPrimLong: |
| 2447 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2448 | case Primitive::kPrimBoolean: |
| 2449 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2450 | case Primitive::kPrimByte: |
| 2451 | case Primitive::kPrimShort: |
| 2452 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2453 | // Processing a Dex `int-to-char' instruction. |
| 2454 | locations->SetInAt(0, Location::Any()); |
| 2455 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2456 | break; |
| 2457 | |
| 2458 | default: |
| 2459 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2460 | << " to " << result_type; |
| 2461 | } |
| 2462 | break; |
| 2463 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2464 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2465 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2466 | case Primitive::kPrimBoolean: |
| 2467 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2468 | case Primitive::kPrimByte: |
| 2469 | case Primitive::kPrimShort: |
| 2470 | case Primitive::kPrimInt: |
| 2471 | case Primitive::kPrimChar: |
| 2472 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2473 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2474 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2475 | break; |
| 2476 | |
| 2477 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2478 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2479 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2480 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2481 | break; |
| 2482 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2483 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2484 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2485 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2486 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2487 | break; |
| 2488 | |
| 2489 | default: |
| 2490 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2491 | << " to " << result_type; |
| 2492 | }; |
| 2493 | break; |
| 2494 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2495 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2496 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2497 | case Primitive::kPrimBoolean: |
| 2498 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2499 | case Primitive::kPrimByte: |
| 2500 | case Primitive::kPrimShort: |
| 2501 | case Primitive::kPrimInt: |
| 2502 | case Primitive::kPrimChar: |
| 2503 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2504 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2505 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2506 | break; |
| 2507 | |
| 2508 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2509 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2510 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2511 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2512 | break; |
| 2513 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2514 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2515 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2516 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2517 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2518 | break; |
| 2519 | |
| 2520 | default: |
| 2521 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2522 | << " to " << result_type; |
| 2523 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2524 | break; |
| 2525 | |
| 2526 | default: |
| 2527 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2528 | << " to " << result_type; |
| 2529 | } |
| 2530 | } |
| 2531 | |
| 2532 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2533 | LocationSummary* locations = conversion->GetLocations(); |
| 2534 | Location out = locations->Out(); |
| 2535 | Location in = locations->InAt(0); |
| 2536 | Primitive::Type result_type = conversion->GetResultType(); |
| 2537 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2538 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2539 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2540 | case Primitive::kPrimByte: |
| 2541 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2542 | case Primitive::kPrimLong: |
| 2543 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2544 | case Primitive::kPrimBoolean: |
| 2545 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2546 | case Primitive::kPrimShort: |
| 2547 | case Primitive::kPrimInt: |
| 2548 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2549 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2550 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2551 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2552 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2553 | __ movsxb(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2554 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2555 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2556 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2557 | Immediate(static_cast<int8_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2558 | } |
| 2559 | break; |
| 2560 | |
| 2561 | default: |
| 2562 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2563 | << " to " << result_type; |
| 2564 | } |
| 2565 | break; |
| 2566 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2567 | case Primitive::kPrimShort: |
| 2568 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2569 | case Primitive::kPrimLong: |
| 2570 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2571 | case Primitive::kPrimBoolean: |
| 2572 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2573 | case Primitive::kPrimByte: |
| 2574 | case Primitive::kPrimInt: |
| 2575 | case Primitive::kPrimChar: |
| 2576 | // Processing a Dex `int-to-short' instruction. |
| 2577 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2578 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2579 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2580 | __ movsxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2581 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2582 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2583 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2584 | Immediate(static_cast<int16_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2585 | } |
| 2586 | break; |
| 2587 | |
| 2588 | default: |
| 2589 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2590 | << " to " << result_type; |
| 2591 | } |
| 2592 | break; |
| 2593 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2594 | case Primitive::kPrimInt: |
| 2595 | switch (input_type) { |
| 2596 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2597 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2598 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2599 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2600 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2601 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2602 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2603 | } else { |
| 2604 | DCHECK(in.IsConstant()); |
| 2605 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2606 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2607 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2608 | } |
| 2609 | break; |
| 2610 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2611 | case Primitive::kPrimFloat: { |
| 2612 | // Processing a Dex `float-to-int' instruction. |
| 2613 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2614 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2615 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2616 | |
| 2617 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2618 | // if input >= (float)INT_MAX goto done |
| 2619 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimIntMax)); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2620 | __ j(kAboveEqual, &done); |
| 2621 | // if input == NaN goto nan |
| 2622 | __ j(kUnordered, &nan); |
| 2623 | // output = float-to-int-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2624 | __ cvttss2si(output, input, false); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2625 | __ jmp(&done); |
| 2626 | __ Bind(&nan); |
| 2627 | // output = 0 |
| 2628 | __ xorl(output, output); |
| 2629 | __ Bind(&done); |
| 2630 | break; |
| 2631 | } |
| 2632 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2633 | case Primitive::kPrimDouble: { |
| 2634 | // Processing a Dex `double-to-int' instruction. |
| 2635 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2636 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2637 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2638 | |
| 2639 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2640 | // if input >= (double)INT_MAX goto done |
| 2641 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2642 | __ j(kAboveEqual, &done); |
| 2643 | // if input == NaN goto nan |
| 2644 | __ j(kUnordered, &nan); |
| 2645 | // output = double-to-int-truncate(input) |
| 2646 | __ cvttsd2si(output, input); |
| 2647 | __ jmp(&done); |
| 2648 | __ Bind(&nan); |
| 2649 | // output = 0 |
| 2650 | __ xorl(output, output); |
| 2651 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2652 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2653 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2654 | |
| 2655 | default: |
| 2656 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2657 | << " to " << result_type; |
| 2658 | } |
| 2659 | break; |
| 2660 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2661 | case Primitive::kPrimLong: |
| 2662 | switch (input_type) { |
| 2663 | DCHECK(out.IsRegister()); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2664 | case Primitive::kPrimBoolean: |
| 2665 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2666 | case Primitive::kPrimByte: |
| 2667 | case Primitive::kPrimShort: |
| 2668 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2669 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2670 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2671 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2672 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2673 | break; |
| 2674 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2675 | case Primitive::kPrimFloat: { |
| 2676 | // Processing a Dex `float-to-long' instruction. |
| 2677 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2678 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2679 | NearLabel done, nan; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2680 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2681 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2682 | // if input >= (float)LONG_MAX goto done |
| 2683 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimLongMax)); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2684 | __ j(kAboveEqual, &done); |
| 2685 | // if input == NaN goto nan |
| 2686 | __ j(kUnordered, &nan); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2687 | // output = float-to-long-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2688 | __ cvttss2si(output, input, true); |
| 2689 | __ jmp(&done); |
| 2690 | __ Bind(&nan); |
| 2691 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2692 | __ xorl(output, output); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2693 | __ Bind(&done); |
| 2694 | break; |
| 2695 | } |
| 2696 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2697 | case Primitive::kPrimDouble: { |
| 2698 | // Processing a Dex `double-to-long' instruction. |
| 2699 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2700 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2701 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2702 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2703 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2704 | // if input >= (double)LONG_MAX goto done |
| 2705 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimLongMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2706 | __ j(kAboveEqual, &done); |
| 2707 | // if input == NaN goto nan |
| 2708 | __ j(kUnordered, &nan); |
| 2709 | // output = double-to-long-truncate(input) |
| 2710 | __ cvttsd2si(output, input, true); |
| 2711 | __ jmp(&done); |
| 2712 | __ Bind(&nan); |
| 2713 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2714 | __ xorl(output, output); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2715 | __ Bind(&done); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2716 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2717 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2718 | |
| 2719 | default: |
| 2720 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2721 | << " to " << result_type; |
| 2722 | } |
| 2723 | break; |
| 2724 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2725 | case Primitive::kPrimChar: |
| 2726 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2727 | case Primitive::kPrimLong: |
| 2728 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2729 | case Primitive::kPrimBoolean: |
| 2730 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2731 | case Primitive::kPrimByte: |
| 2732 | case Primitive::kPrimShort: |
| 2733 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2734 | // Processing a Dex `int-to-char' instruction. |
| 2735 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2736 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2737 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2738 | __ movzxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2739 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2740 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2741 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2742 | Immediate(static_cast<uint16_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2743 | } |
| 2744 | break; |
| 2745 | |
| 2746 | default: |
| 2747 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2748 | << " to " << result_type; |
| 2749 | } |
| 2750 | break; |
| 2751 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2752 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2753 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2754 | case Primitive::kPrimBoolean: |
| 2755 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2756 | case Primitive::kPrimByte: |
| 2757 | case Primitive::kPrimShort: |
| 2758 | case Primitive::kPrimInt: |
| 2759 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2760 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2761 | if (in.IsRegister()) { |
| 2762 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2763 | } else if (in.IsConstant()) { |
| 2764 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2765 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2766 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2767 | } else { |
| 2768 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2769 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2770 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2771 | break; |
| 2772 | |
| 2773 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2774 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2775 | if (in.IsRegister()) { |
| 2776 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2777 | } else if (in.IsConstant()) { |
| 2778 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2779 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Pavel Vyssotski | 4c858cd | 2016-03-16 13:59:53 +0600 | [diff] [blame] | 2780 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2781 | } else { |
| 2782 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2783 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2784 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2785 | break; |
| 2786 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2787 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2788 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2789 | if (in.IsFpuRegister()) { |
| 2790 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2791 | } else if (in.IsConstant()) { |
| 2792 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2793 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2794 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2795 | } else { |
| 2796 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 2797 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2798 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2799 | break; |
| 2800 | |
| 2801 | default: |
| 2802 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2803 | << " to " << result_type; |
| 2804 | }; |
| 2805 | break; |
| 2806 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2807 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2808 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2809 | case Primitive::kPrimBoolean: |
| 2810 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2811 | case Primitive::kPrimByte: |
| 2812 | case Primitive::kPrimShort: |
| 2813 | case Primitive::kPrimInt: |
| 2814 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2815 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2816 | if (in.IsRegister()) { |
| 2817 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2818 | } else if (in.IsConstant()) { |
| 2819 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2820 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2821 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2822 | } else { |
| 2823 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2824 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2825 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2826 | break; |
| 2827 | |
| 2828 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2829 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2830 | if (in.IsRegister()) { |
| 2831 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2832 | } else if (in.IsConstant()) { |
| 2833 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2834 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2835 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2836 | } else { |
| 2837 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2838 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2839 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2840 | break; |
| 2841 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2842 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2843 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2844 | if (in.IsFpuRegister()) { |
| 2845 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2846 | } else if (in.IsConstant()) { |
| 2847 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 2848 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2849 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2850 | } else { |
| 2851 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 2852 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2853 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2854 | break; |
| 2855 | |
| 2856 | default: |
| 2857 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2858 | << " to " << result_type; |
| 2859 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2860 | break; |
| 2861 | |
| 2862 | default: |
| 2863 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2864 | << " to " << result_type; |
| 2865 | } |
| 2866 | } |
| 2867 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2868 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2869 | LocationSummary* locations = |
| 2870 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2871 | switch (add->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2872 | case Primitive::kPrimInt: { |
| 2873 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2874 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2875 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2876 | break; |
| 2877 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2878 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2879 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2880 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2881 | // 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] | 2882 | locations->SetInAt(1, Location::RegisterOrInt32Constant(add->InputAt(1))); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2883 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2884 | break; |
| 2885 | } |
| 2886 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2887 | case Primitive::kPrimDouble: |
| 2888 | case Primitive::kPrimFloat: { |
| 2889 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2890 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2891 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2892 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2893 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2894 | |
| 2895 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2896 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2897 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2898 | } |
| 2899 | |
| 2900 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 2901 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2902 | Location first = locations->InAt(0); |
| 2903 | Location second = locations->InAt(1); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2904 | Location out = locations->Out(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2905 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2906 | switch (add->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2907 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2908 | if (second.IsRegister()) { |
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>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2911 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2912 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2913 | } else { |
| 2914 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2915 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2916 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2917 | } else if (second.IsConstant()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2918 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2919 | __ addl(out.AsRegister<CpuRegister>(), |
| 2920 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 2921 | } else { |
| 2922 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2923 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 2924 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2925 | } else { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2926 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2927 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2928 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2929 | break; |
| 2930 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2931 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2932 | case Primitive::kPrimLong: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2933 | if (second.IsRegister()) { |
| 2934 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2935 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2936 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2937 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2938 | } else { |
| 2939 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2940 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2941 | } |
| 2942 | } else { |
| 2943 | DCHECK(second.IsConstant()); |
| 2944 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2945 | int32_t int32_value = Low32Bits(value); |
| 2946 | DCHECK_EQ(int32_value, value); |
| 2947 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2948 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 2949 | } else { |
| 2950 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2951 | first.AsRegister<CpuRegister>(), int32_value)); |
| 2952 | } |
| 2953 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2954 | break; |
| 2955 | } |
| 2956 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2957 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2958 | if (second.IsFpuRegister()) { |
| 2959 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2960 | } else if (second.IsConstant()) { |
| 2961 | __ addss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2962 | codegen_->LiteralFloatAddress( |
| 2963 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2964 | } else { |
| 2965 | DCHECK(second.IsStackSlot()); |
| 2966 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2967 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2968 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2969 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2970 | } |
| 2971 | |
| 2972 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2973 | if (second.IsFpuRegister()) { |
| 2974 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2975 | } else if (second.IsConstant()) { |
| 2976 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2977 | codegen_->LiteralDoubleAddress( |
| 2978 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2979 | } else { |
| 2980 | DCHECK(second.IsDoubleStackSlot()); |
| 2981 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2982 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2983 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2984 | break; |
| 2985 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2986 | |
| 2987 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2988 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2989 | } |
| 2990 | } |
| 2991 | |
| 2992 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2993 | LocationSummary* locations = |
| 2994 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2995 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2996 | case Primitive::kPrimInt: { |
| 2997 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2998 | locations->SetInAt(1, Location::Any()); |
| 2999 | locations->SetOut(Location::SameAsFirstInput()); |
| 3000 | break; |
| 3001 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3002 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3003 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 3004 | locations->SetInAt(1, Location::RegisterOrInt32Constant(sub->InputAt(1))); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3005 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3006 | break; |
| 3007 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3008 | case Primitive::kPrimFloat: |
| 3009 | case Primitive::kPrimDouble: { |
| 3010 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3011 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3012 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3013 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3014 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3015 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3016 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3017 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3018 | } |
| 3019 | |
| 3020 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 3021 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3022 | Location first = locations->InAt(0); |
| 3023 | Location second = locations->InAt(1); |
| 3024 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3025 | switch (sub->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3026 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3027 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3028 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3029 | } else if (second.IsConstant()) { |
| 3030 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3031 | __ subl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3032 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3033 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3034 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3035 | break; |
| 3036 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3037 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3038 | if (second.IsConstant()) { |
| 3039 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3040 | DCHECK(IsInt<32>(value)); |
| 3041 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 3042 | } else { |
| 3043 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 3044 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3045 | break; |
| 3046 | } |
| 3047 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3048 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3049 | if (second.IsFpuRegister()) { |
| 3050 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3051 | } else if (second.IsConstant()) { |
| 3052 | __ subss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3053 | codegen_->LiteralFloatAddress( |
| 3054 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3055 | } else { |
| 3056 | DCHECK(second.IsStackSlot()); |
| 3057 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3058 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3059 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3060 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3061 | } |
| 3062 | |
| 3063 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3064 | if (second.IsFpuRegister()) { |
| 3065 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3066 | } else if (second.IsConstant()) { |
| 3067 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3068 | codegen_->LiteralDoubleAddress( |
| 3069 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3070 | } else { |
| 3071 | DCHECK(second.IsDoubleStackSlot()); |
| 3072 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3073 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3074 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3075 | break; |
| 3076 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3077 | |
| 3078 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3079 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3080 | } |
| 3081 | } |
| 3082 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3083 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 3084 | LocationSummary* locations = |
| 3085 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3086 | switch (mul->GetResultType()) { |
| 3087 | case Primitive::kPrimInt: { |
| 3088 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3089 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3090 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3091 | // Can use 3 operand multiply. |
| 3092 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3093 | } else { |
| 3094 | locations->SetOut(Location::SameAsFirstInput()); |
| 3095 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3096 | break; |
| 3097 | } |
| 3098 | case Primitive::kPrimLong: { |
| 3099 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3100 | locations->SetInAt(1, Location::Any()); |
| 3101 | if (mul->InputAt(1)->IsLongConstant() && |
| 3102 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3103 | // Can use 3 operand multiply. |
| 3104 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3105 | } else { |
| 3106 | locations->SetOut(Location::SameAsFirstInput()); |
| 3107 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3108 | break; |
| 3109 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3110 | case Primitive::kPrimFloat: |
| 3111 | case Primitive::kPrimDouble: { |
| 3112 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3113 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3114 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3115 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3116 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3117 | |
| 3118 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3119 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3120 | } |
| 3121 | } |
| 3122 | |
| 3123 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 3124 | LocationSummary* locations = mul->GetLocations(); |
| 3125 | Location first = locations->InAt(0); |
| 3126 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3127 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3128 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3129 | case Primitive::kPrimInt: |
| 3130 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3131 | // problems where the output may not be the same as the first operand. |
| 3132 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3133 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3134 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 3135 | } else if (second.IsRegister()) { |
| 3136 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3137 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3138 | } else { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3139 | DCHECK(first.Equals(out)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3140 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3141 | __ imull(first.AsRegister<CpuRegister>(), |
| 3142 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3143 | } |
| 3144 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3145 | case Primitive::kPrimLong: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3146 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3147 | // problems where the output may not be the same as the first operand. |
| 3148 | if (mul->InputAt(1)->IsLongConstant()) { |
| 3149 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 3150 | if (IsInt<32>(value)) { |
| 3151 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 3152 | Immediate(static_cast<int32_t>(value))); |
| 3153 | } else { |
| 3154 | // Have to use the constant area. |
| 3155 | DCHECK(first.Equals(out)); |
| 3156 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 3157 | } |
| 3158 | } else if (second.IsRegister()) { |
| 3159 | DCHECK(first.Equals(out)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3160 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3161 | } else { |
| 3162 | DCHECK(second.IsDoubleStackSlot()); |
| 3163 | DCHECK(first.Equals(out)); |
| 3164 | __ imulq(first.AsRegister<CpuRegister>(), |
| 3165 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3166 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3167 | break; |
| 3168 | } |
| 3169 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3170 | case Primitive::kPrimFloat: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3171 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3172 | if (second.IsFpuRegister()) { |
| 3173 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3174 | } else if (second.IsConstant()) { |
| 3175 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3176 | codegen_->LiteralFloatAddress( |
| 3177 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3178 | } else { |
| 3179 | DCHECK(second.IsStackSlot()); |
| 3180 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3181 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3182 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3183 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3184 | } |
| 3185 | |
| 3186 | case Primitive::kPrimDouble: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3187 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3188 | if (second.IsFpuRegister()) { |
| 3189 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3190 | } else if (second.IsConstant()) { |
| 3191 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3192 | codegen_->LiteralDoubleAddress( |
| 3193 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3194 | } else { |
| 3195 | DCHECK(second.IsDoubleStackSlot()); |
| 3196 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3197 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3198 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3199 | break; |
| 3200 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3201 | |
| 3202 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3203 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3204 | } |
| 3205 | } |
| 3206 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3207 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 3208 | uint32_t stack_adjustment, bool is_float) { |
| 3209 | if (source.IsStackSlot()) { |
| 3210 | DCHECK(is_float); |
| 3211 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3212 | } else if (source.IsDoubleStackSlot()) { |
| 3213 | DCHECK(!is_float); |
| 3214 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3215 | } else { |
| 3216 | // Write the value to the temporary location on the stack and load to FP stack. |
| 3217 | if (is_float) { |
| 3218 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3219 | codegen_->Move(stack_temp, source); |
| 3220 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 3221 | } else { |
| 3222 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3223 | codegen_->Move(stack_temp, source); |
| 3224 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 3225 | } |
| 3226 | } |
| 3227 | } |
| 3228 | |
| 3229 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| 3230 | Primitive::Type type = rem->GetResultType(); |
| 3231 | bool is_float = type == Primitive::kPrimFloat; |
| 3232 | size_t elem_size = Primitive::ComponentSize(type); |
| 3233 | LocationSummary* locations = rem->GetLocations(); |
| 3234 | Location first = locations->InAt(0); |
| 3235 | Location second = locations->InAt(1); |
| 3236 | Location out = locations->Out(); |
| 3237 | |
| 3238 | // Create stack space for 2 elements. |
| 3239 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3240 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3241 | |
| 3242 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 3243 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 3244 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 3245 | |
| 3246 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3247 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3248 | __ Bind(&retry); |
| 3249 | __ fprem(); |
| 3250 | |
| 3251 | // Move FP status to AX. |
| 3252 | __ fstsw(); |
| 3253 | |
| 3254 | // And see if the argument reduction is complete. This is signaled by the |
| 3255 | // C2 FPU flag bit set to 0. |
| 3256 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 3257 | __ j(kNotEqual, &retry); |
| 3258 | |
| 3259 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3260 | // Store FP top of stack to real stack. |
| 3261 | if (is_float) { |
| 3262 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 3263 | } else { |
| 3264 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 3265 | } |
| 3266 | |
| 3267 | // Pop the 2 items from the FP stack. |
| 3268 | __ fucompp(); |
| 3269 | |
| 3270 | // Load the value from the stack into an XMM register. |
| 3271 | DCHECK(out.IsFpuRegister()) << out; |
| 3272 | if (is_float) { |
| 3273 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3274 | } else { |
| 3275 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3276 | } |
| 3277 | |
| 3278 | // And remove the temporary stack space we allocated. |
| 3279 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3280 | } |
| 3281 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3282 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3283 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3284 | |
| 3285 | LocationSummary* locations = instruction->GetLocations(); |
| 3286 | Location second = locations->InAt(1); |
| 3287 | DCHECK(second.IsConstant()); |
| 3288 | |
| 3289 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3290 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3291 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3292 | |
| 3293 | DCHECK(imm == 1 || imm == -1); |
| 3294 | |
| 3295 | switch (instruction->GetResultType()) { |
| 3296 | case Primitive::kPrimInt: { |
| 3297 | if (instruction->IsRem()) { |
| 3298 | __ xorl(output_register, output_register); |
| 3299 | } else { |
| 3300 | __ movl(output_register, input_register); |
| 3301 | if (imm == -1) { |
| 3302 | __ negl(output_register); |
| 3303 | } |
| 3304 | } |
| 3305 | break; |
| 3306 | } |
| 3307 | |
| 3308 | case Primitive::kPrimLong: { |
| 3309 | if (instruction->IsRem()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3310 | __ xorl(output_register, output_register); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3311 | } else { |
| 3312 | __ movq(output_register, input_register); |
| 3313 | if (imm == -1) { |
| 3314 | __ negq(output_register); |
| 3315 | } |
| 3316 | } |
| 3317 | break; |
| 3318 | } |
| 3319 | |
| 3320 | default: |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3321 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3322 | } |
| 3323 | } |
| 3324 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3325 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3326 | LocationSummary* locations = instruction->GetLocations(); |
| 3327 | Location second = locations->InAt(1); |
| 3328 | |
| 3329 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3330 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3331 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3332 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3333 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3334 | uint64_t abs_imm = AbsOrMin(imm); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3335 | |
| 3336 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3337 | |
| 3338 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3339 | __ leal(tmp, Address(numerator, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3340 | __ testl(numerator, numerator); |
| 3341 | __ cmov(kGreaterEqual, tmp, numerator); |
| 3342 | int shift = CTZ(imm); |
| 3343 | __ sarl(tmp, Immediate(shift)); |
| 3344 | |
| 3345 | if (imm < 0) { |
| 3346 | __ negl(tmp); |
| 3347 | } |
| 3348 | |
| 3349 | __ movl(output_register, tmp); |
| 3350 | } else { |
| 3351 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3352 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3353 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3354 | codegen_->Load64BitValue(rdx, abs_imm - 1); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3355 | __ addq(rdx, numerator); |
| 3356 | __ testq(numerator, numerator); |
| 3357 | __ cmov(kGreaterEqual, rdx, numerator); |
| 3358 | int shift = CTZ(imm); |
| 3359 | __ sarq(rdx, Immediate(shift)); |
| 3360 | |
| 3361 | if (imm < 0) { |
| 3362 | __ negq(rdx); |
| 3363 | } |
| 3364 | |
| 3365 | __ movq(output_register, rdx); |
| 3366 | } |
| 3367 | } |
| 3368 | |
| 3369 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3370 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3371 | |
| 3372 | LocationSummary* locations = instruction->GetLocations(); |
| 3373 | Location second = locations->InAt(1); |
| 3374 | |
| 3375 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 3376 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3377 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3378 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 3379 | : locations->Out().AsRegister<CpuRegister>(); |
| 3380 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3381 | |
| 3382 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 3383 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 3384 | if (instruction->IsDiv()) { |
| 3385 | DCHECK_EQ(RAX, out.AsRegister()); |
| 3386 | } else { |
| 3387 | DCHECK_EQ(RDX, out.AsRegister()); |
| 3388 | } |
| 3389 | |
| 3390 | int64_t magic; |
| 3391 | int shift; |
| 3392 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3393 | // TODO: can these branches be written as one? |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3394 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 3395 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3396 | |
| 3397 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3398 | |
| 3399 | __ movl(numerator, eax); |
| 3400 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3401 | __ movl(eax, Immediate(magic)); |
| 3402 | __ imull(numerator); |
| 3403 | |
| 3404 | if (imm > 0 && magic < 0) { |
| 3405 | __ addl(edx, numerator); |
| 3406 | } else if (imm < 0 && magic > 0) { |
| 3407 | __ subl(edx, numerator); |
| 3408 | } |
| 3409 | |
| 3410 | if (shift != 0) { |
| 3411 | __ sarl(edx, Immediate(shift)); |
| 3412 | } |
| 3413 | |
| 3414 | __ movl(eax, edx); |
| 3415 | __ shrl(edx, Immediate(31)); |
| 3416 | __ addl(edx, eax); |
| 3417 | |
| 3418 | if (instruction->IsRem()) { |
| 3419 | __ movl(eax, numerator); |
| 3420 | __ imull(edx, Immediate(imm)); |
| 3421 | __ subl(eax, edx); |
| 3422 | __ movl(edx, eax); |
| 3423 | } else { |
| 3424 | __ movl(eax, edx); |
| 3425 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3426 | } else { |
| 3427 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3428 | |
| 3429 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3430 | |
| 3431 | CpuRegister rax = eax; |
| 3432 | CpuRegister rdx = edx; |
| 3433 | |
| 3434 | CalculateMagicAndShiftForDivRem(imm, true /* is_long */, &magic, &shift); |
| 3435 | |
| 3436 | // Save the numerator. |
| 3437 | __ movq(numerator, rax); |
| 3438 | |
| 3439 | // RAX = magic |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3440 | codegen_->Load64BitValue(rax, magic); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3441 | |
| 3442 | // RDX:RAX = magic * numerator |
| 3443 | __ imulq(numerator); |
| 3444 | |
| 3445 | if (imm > 0 && magic < 0) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3446 | // RDX += numerator |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3447 | __ addq(rdx, numerator); |
| 3448 | } else if (imm < 0 && magic > 0) { |
| 3449 | // RDX -= numerator |
| 3450 | __ subq(rdx, numerator); |
| 3451 | } |
| 3452 | |
| 3453 | // Shift if needed. |
| 3454 | if (shift != 0) { |
| 3455 | __ sarq(rdx, Immediate(shift)); |
| 3456 | } |
| 3457 | |
| 3458 | // RDX += 1 if RDX < 0 |
| 3459 | __ movq(rax, rdx); |
| 3460 | __ shrq(rdx, Immediate(63)); |
| 3461 | __ addq(rdx, rax); |
| 3462 | |
| 3463 | if (instruction->IsRem()) { |
| 3464 | __ movq(rax, numerator); |
| 3465 | |
| 3466 | if (IsInt<32>(imm)) { |
| 3467 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 3468 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3469 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3470 | } |
| 3471 | |
| 3472 | __ subq(rax, rdx); |
| 3473 | __ movq(rdx, rax); |
| 3474 | } else { |
| 3475 | __ movq(rax, rdx); |
| 3476 | } |
| 3477 | } |
| 3478 | } |
| 3479 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3480 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3481 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3482 | Primitive::Type type = instruction->GetResultType(); |
| 3483 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 3484 | |
| 3485 | bool is_div = instruction->IsDiv(); |
| 3486 | LocationSummary* locations = instruction->GetLocations(); |
| 3487 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3488 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3489 | Location second = locations->InAt(1); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3490 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3491 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3492 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3493 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3494 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3495 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3496 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3497 | if (imm == 0) { |
| 3498 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3499 | } else if (imm == 1 || imm == -1) { |
| 3500 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3501 | } else if (instruction->IsDiv() && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3502 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3503 | } else { |
| 3504 | DCHECK(imm <= -2 || imm >= 2); |
| 3505 | GenerateDivRemWithAnyConstant(instruction); |
| 3506 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3507 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3508 | SlowPathCode* slow_path = |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3509 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86_64( |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3510 | instruction, out.AsRegister(), type, is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3511 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3512 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3513 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3514 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3515 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3516 | // so it's safe to just use negl instead of more complex comparisons. |
| 3517 | if (type == Primitive::kPrimInt) { |
| 3518 | __ cmpl(second_reg, Immediate(-1)); |
| 3519 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3520 | // edx:eax <- sign-extended of eax |
| 3521 | __ cdq(); |
| 3522 | // eax = quotient, edx = remainder |
| 3523 | __ idivl(second_reg); |
| 3524 | } else { |
| 3525 | __ cmpq(second_reg, Immediate(-1)); |
| 3526 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3527 | // rdx:rax <- sign-extended of rax |
| 3528 | __ cqo(); |
| 3529 | // rax = quotient, rdx = remainder |
| 3530 | __ idivq(second_reg); |
| 3531 | } |
| 3532 | __ Bind(slow_path->GetExitLabel()); |
| 3533 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3534 | } |
| 3535 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3536 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3537 | LocationSummary* locations = |
| 3538 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3539 | switch (div->GetResultType()) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3540 | case Primitive::kPrimInt: |
| 3541 | case Primitive::kPrimLong: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3542 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3543 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3544 | locations->SetOut(Location::SameAsFirstInput()); |
| 3545 | // Intel uses edx:eax as the dividend. |
| 3546 | locations->AddTemp(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3547 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3548 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3549 | // output and request another temp. |
| 3550 | if (div->InputAt(1)->IsConstant()) { |
| 3551 | locations->AddTemp(Location::RequiresRegister()); |
| 3552 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3553 | break; |
| 3554 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3555 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3556 | case Primitive::kPrimFloat: |
| 3557 | case Primitive::kPrimDouble: { |
| 3558 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3559 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3560 | locations->SetOut(Location::SameAsFirstInput()); |
| 3561 | break; |
| 3562 | } |
| 3563 | |
| 3564 | default: |
| 3565 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3566 | } |
| 3567 | } |
| 3568 | |
| 3569 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3570 | LocationSummary* locations = div->GetLocations(); |
| 3571 | Location first = locations->InAt(0); |
| 3572 | Location second = locations->InAt(1); |
| 3573 | DCHECK(first.Equals(locations->Out())); |
| 3574 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3575 | Primitive::Type type = div->GetResultType(); |
| 3576 | switch (type) { |
| 3577 | case Primitive::kPrimInt: |
| 3578 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3579 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3580 | break; |
| 3581 | } |
| 3582 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3583 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3584 | if (second.IsFpuRegister()) { |
| 3585 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3586 | } else if (second.IsConstant()) { |
| 3587 | __ divss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3588 | codegen_->LiteralFloatAddress( |
| 3589 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3590 | } else { |
| 3591 | DCHECK(second.IsStackSlot()); |
| 3592 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3593 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3594 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3595 | break; |
| 3596 | } |
| 3597 | |
| 3598 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3599 | if (second.IsFpuRegister()) { |
| 3600 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3601 | } else if (second.IsConstant()) { |
| 3602 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3603 | codegen_->LiteralDoubleAddress( |
| 3604 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3605 | } else { |
| 3606 | DCHECK(second.IsDoubleStackSlot()); |
| 3607 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3608 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3609 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3610 | break; |
| 3611 | } |
| 3612 | |
| 3613 | default: |
| 3614 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3615 | } |
| 3616 | } |
| 3617 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3618 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3619 | Primitive::Type type = rem->GetResultType(); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3620 | LocationSummary* locations = |
| 3621 | new (GetGraph()->GetArena()) LocationSummary(rem, LocationSummary::kNoCall); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3622 | |
| 3623 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3624 | case Primitive::kPrimInt: |
| 3625 | case Primitive::kPrimLong: { |
| 3626 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3627 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3628 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3629 | locations->SetOut(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3630 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3631 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3632 | // output and request another temp. |
| 3633 | if (rem->InputAt(1)->IsConstant()) { |
| 3634 | locations->AddTemp(Location::RequiresRegister()); |
| 3635 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3636 | break; |
| 3637 | } |
| 3638 | |
| 3639 | case Primitive::kPrimFloat: |
| 3640 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3641 | locations->SetInAt(0, Location::Any()); |
| 3642 | locations->SetInAt(1, Location::Any()); |
| 3643 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3644 | locations->AddTemp(Location::RegisterLocation(RAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3645 | break; |
| 3646 | } |
| 3647 | |
| 3648 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3649 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3650 | } |
| 3651 | } |
| 3652 | |
| 3653 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| 3654 | Primitive::Type type = rem->GetResultType(); |
| 3655 | switch (type) { |
| 3656 | case Primitive::kPrimInt: |
| 3657 | case Primitive::kPrimLong: { |
| 3658 | GenerateDivRemIntegral(rem); |
| 3659 | break; |
| 3660 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3661 | case Primitive::kPrimFloat: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3662 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3663 | GenerateRemFP(rem); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3664 | break; |
| 3665 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3666 | default: |
| 3667 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3668 | } |
| 3669 | } |
| 3670 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3671 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3672 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3673 | ? LocationSummary::kCallOnSlowPath |
| 3674 | : LocationSummary::kNoCall; |
| 3675 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3676 | locations->SetInAt(0, Location::Any()); |
| 3677 | if (instruction->HasUses()) { |
| 3678 | locations->SetOut(Location::SameAsFirstInput()); |
| 3679 | } |
| 3680 | } |
| 3681 | |
| 3682 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3683 | SlowPathCode* slow_path = |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3684 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction); |
| 3685 | codegen_->AddSlowPath(slow_path); |
| 3686 | |
| 3687 | LocationSummary* locations = instruction->GetLocations(); |
| 3688 | Location value = locations->InAt(0); |
| 3689 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3690 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3691 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3692 | case Primitive::kPrimByte: |
| 3693 | case Primitive::kPrimChar: |
| 3694 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3695 | case Primitive::kPrimInt: { |
| 3696 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3697 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3698 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3699 | } else if (value.IsStackSlot()) { |
| 3700 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3701 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3702 | } else { |
| 3703 | DCHECK(value.IsConstant()) << value; |
| 3704 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3705 | __ jmp(slow_path->GetEntryLabel()); |
| 3706 | } |
| 3707 | } |
| 3708 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3709 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3710 | case Primitive::kPrimLong: { |
| 3711 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3712 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3713 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3714 | } else if (value.IsDoubleStackSlot()) { |
| 3715 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3716 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3717 | } else { |
| 3718 | DCHECK(value.IsConstant()) << value; |
| 3719 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3720 | __ jmp(slow_path->GetEntryLabel()); |
| 3721 | } |
| 3722 | } |
| 3723 | break; |
| 3724 | } |
| 3725 | default: |
| 3726 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3727 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3728 | } |
| 3729 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3730 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 3731 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3732 | |
| 3733 | LocationSummary* locations = |
| 3734 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3735 | |
| 3736 | switch (op->GetResultType()) { |
| 3737 | case Primitive::kPrimInt: |
| 3738 | case Primitive::kPrimLong: { |
| 3739 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3740 | // The shift count needs to be in CL. |
| 3741 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 3742 | locations->SetOut(Location::SameAsFirstInput()); |
| 3743 | break; |
| 3744 | } |
| 3745 | default: |
| 3746 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3747 | } |
| 3748 | } |
| 3749 | |
| 3750 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 3751 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3752 | |
| 3753 | LocationSummary* locations = op->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3754 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3755 | Location second = locations->InAt(1); |
| 3756 | |
| 3757 | switch (op->GetResultType()) { |
| 3758 | case Primitive::kPrimInt: { |
| 3759 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3760 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3761 | if (op->IsShl()) { |
| 3762 | __ shll(first_reg, second_reg); |
| 3763 | } else if (op->IsShr()) { |
| 3764 | __ sarl(first_reg, second_reg); |
| 3765 | } else { |
| 3766 | __ shrl(first_reg, second_reg); |
| 3767 | } |
| 3768 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3769 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3770 | if (op->IsShl()) { |
| 3771 | __ shll(first_reg, imm); |
| 3772 | } else if (op->IsShr()) { |
| 3773 | __ sarl(first_reg, imm); |
| 3774 | } else { |
| 3775 | __ shrl(first_reg, imm); |
| 3776 | } |
| 3777 | } |
| 3778 | break; |
| 3779 | } |
| 3780 | case Primitive::kPrimLong: { |
| 3781 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3782 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3783 | if (op->IsShl()) { |
| 3784 | __ shlq(first_reg, second_reg); |
| 3785 | } else if (op->IsShr()) { |
| 3786 | __ sarq(first_reg, second_reg); |
| 3787 | } else { |
| 3788 | __ shrq(first_reg, second_reg); |
| 3789 | } |
| 3790 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3791 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3792 | if (op->IsShl()) { |
| 3793 | __ shlq(first_reg, imm); |
| 3794 | } else if (op->IsShr()) { |
| 3795 | __ sarq(first_reg, imm); |
| 3796 | } else { |
| 3797 | __ shrq(first_reg, imm); |
| 3798 | } |
| 3799 | } |
| 3800 | break; |
| 3801 | } |
| 3802 | default: |
| 3803 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3804 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3805 | } |
| 3806 | } |
| 3807 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3808 | void LocationsBuilderX86_64::VisitRor(HRor* ror) { |
| 3809 | LocationSummary* locations = |
| 3810 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3811 | |
| 3812 | switch (ror->GetResultType()) { |
| 3813 | case Primitive::kPrimInt: |
| 3814 | case Primitive::kPrimLong: { |
| 3815 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3816 | // The shift count needs to be in CL (unless it is a constant). |
| 3817 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, ror->InputAt(1))); |
| 3818 | locations->SetOut(Location::SameAsFirstInput()); |
| 3819 | break; |
| 3820 | } |
| 3821 | default: |
| 3822 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3823 | UNREACHABLE(); |
| 3824 | } |
| 3825 | } |
| 3826 | |
| 3827 | void InstructionCodeGeneratorX86_64::VisitRor(HRor* ror) { |
| 3828 | LocationSummary* locations = ror->GetLocations(); |
| 3829 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3830 | Location second = locations->InAt(1); |
| 3831 | |
| 3832 | switch (ror->GetResultType()) { |
| 3833 | case Primitive::kPrimInt: |
| 3834 | if (second.IsRegister()) { |
| 3835 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3836 | __ rorl(first_reg, second_reg); |
| 3837 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3838 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3839 | __ rorl(first_reg, imm); |
| 3840 | } |
| 3841 | break; |
| 3842 | case Primitive::kPrimLong: |
| 3843 | if (second.IsRegister()) { |
| 3844 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3845 | __ rorq(first_reg, second_reg); |
| 3846 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3847 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3848 | __ rorq(first_reg, imm); |
| 3849 | } |
| 3850 | break; |
| 3851 | default: |
| 3852 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3853 | UNREACHABLE(); |
| 3854 | } |
| 3855 | } |
| 3856 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3857 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 3858 | HandleShift(shl); |
| 3859 | } |
| 3860 | |
| 3861 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 3862 | HandleShift(shl); |
| 3863 | } |
| 3864 | |
| 3865 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 3866 | HandleShift(shr); |
| 3867 | } |
| 3868 | |
| 3869 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 3870 | HandleShift(shr); |
| 3871 | } |
| 3872 | |
| 3873 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 3874 | HandleShift(ushr); |
| 3875 | } |
| 3876 | |
| 3877 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 3878 | HandleShift(ushr); |
| 3879 | } |
| 3880 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3881 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3882 | LocationSummary* locations = |
| 3883 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3884 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3885 | if (instruction->IsStringAlloc()) { |
| 3886 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3887 | } else { |
| 3888 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3889 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3890 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3891 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3892 | } |
| 3893 | |
| 3894 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3895 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3896 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3897 | if (instruction->IsStringAlloc()) { |
| 3898 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3899 | CpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
| 3900 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64WordSize); |
| 3901 | __ gs()->movq(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString), /* no_rip */ true)); |
| 3902 | __ call(Address(temp, code_offset.SizeValue())); |
| 3903 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3904 | } else { |
| 3905 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3906 | instruction, |
| 3907 | instruction->GetDexPc(), |
| 3908 | nullptr); |
| 3909 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 3910 | DCHECK(!codegen_->IsLeafMethod()); |
| 3911 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3912 | } |
| 3913 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3914 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 3915 | LocationSummary* locations = |
| 3916 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3917 | InvokeRuntimeCallingConvention calling_convention; |
| 3918 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3919 | locations->SetOut(Location::RegisterLocation(RAX)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3920 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3921 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3922 | } |
| 3923 | |
| 3924 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| 3925 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3926 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 3927 | instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3928 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3929 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3930 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3931 | instruction, |
| 3932 | instruction->GetDexPc(), |
| 3933 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3934 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3935 | |
| 3936 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3937 | } |
| 3938 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3939 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3940 | LocationSummary* locations = |
| 3941 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3942 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3943 | if (location.IsStackSlot()) { |
| 3944 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3945 | } else if (location.IsDoubleStackSlot()) { |
| 3946 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3947 | } |
| 3948 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3949 | } |
| 3950 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3951 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 3952 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3953 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3954 | } |
| 3955 | |
| 3956 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3957 | LocationSummary* locations = |
| 3958 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3959 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3960 | } |
| 3961 | |
| 3962 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 3963 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3964 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3965 | } |
| 3966 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3967 | void LocationsBuilderX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 3968 | LocationSummary* locations = |
| 3969 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3970 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3971 | locations->SetOut(Location::RequiresRegister()); |
| 3972 | } |
| 3973 | |
| 3974 | void InstructionCodeGeneratorX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 3975 | LocationSummary* locations = instruction->GetLocations(); |
| 3976 | uint32_t method_offset = 0; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3977 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3978 | method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 3979 | instruction->GetIndex(), kX86_64PointerSize).SizeValue(); |
| 3980 | } else { |
| 3981 | method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 3982 | instruction->GetIndex() % mirror::Class::kImtSize, kX86_64PointerSize).Uint32Value(); |
| 3983 | } |
| 3984 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 3985 | Address(locations->InAt(0).AsRegister<CpuRegister>(), method_offset)); |
| 3986 | } |
| 3987 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3988 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3989 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3990 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3991 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3992 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3993 | } |
| 3994 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3995 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 3996 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3997 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 3998 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3999 | Location out = locations->Out(); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4000 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4001 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4002 | __ notl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4003 | break; |
| 4004 | |
| 4005 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4006 | __ notq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4007 | break; |
| 4008 | |
| 4009 | default: |
| 4010 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4011 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4012 | } |
| 4013 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4014 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4015 | LocationSummary* locations = |
| 4016 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4017 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4018 | locations->SetOut(Location::SameAsFirstInput()); |
| 4019 | } |
| 4020 | |
| 4021 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4022 | LocationSummary* locations = bool_not->GetLocations(); |
| 4023 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4024 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 4025 | Location out = locations->Out(); |
| 4026 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 4027 | } |
| 4028 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4029 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4030 | LocationSummary* locations = |
| 4031 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 4032 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4033 | locations->SetInAt(i, Location::Any()); |
| 4034 | } |
| 4035 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4036 | } |
| 4037 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4038 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4039 | LOG(FATAL) << "Unimplemented"; |
| 4040 | } |
| 4041 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4042 | void CodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4043 | /* |
| 4044 | * 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] | 4045 | * 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] | 4046 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4047 | */ |
| 4048 | switch (kind) { |
| 4049 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4050 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4051 | break; |
| 4052 | } |
| 4053 | case MemBarrierKind::kAnyStore: |
| 4054 | case MemBarrierKind::kLoadAny: |
| 4055 | case MemBarrierKind::kStoreStore: { |
| 4056 | // nop |
| 4057 | break; |
| 4058 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4059 | case MemBarrierKind::kNTStoreStore: |
| 4060 | // Non-Temporal Store/Store needs an explicit fence. |
| 4061 | MemoryFence(/* non-temporal */ true); |
| 4062 | break; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4063 | } |
| 4064 | } |
| 4065 | |
| 4066 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 4067 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4068 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4069 | bool object_field_get_with_read_barrier = |
| 4070 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4071 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4072 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4073 | object_field_get_with_read_barrier ? |
| 4074 | LocationSummary::kCallOnSlowPath : |
| 4075 | LocationSummary::kNoCall); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4076 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4077 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4078 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4079 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4080 | // The output overlaps for an object field get when read barriers |
| 4081 | // are enabled: we do not want the move to overwrite the object's |
| 4082 | // location, as we need it to emit the read barrier. |
| 4083 | locations->SetOut( |
| 4084 | Location::RequiresRegister(), |
| 4085 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4086 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4087 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4088 | // We need a temporary register for the read barrier marking slow |
| 4089 | // path in CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier. |
| 4090 | locations->AddTemp(Location::RequiresRegister()); |
| 4091 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4092 | } |
| 4093 | |
| 4094 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 4095 | const FieldInfo& field_info) { |
| 4096 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4097 | |
| 4098 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4099 | Location base_loc = locations->InAt(0); |
| 4100 | CpuRegister base = base_loc.AsRegister<CpuRegister>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4101 | Location out = locations->Out(); |
| 4102 | bool is_volatile = field_info.IsVolatile(); |
| 4103 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4104 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4105 | |
| 4106 | switch (field_type) { |
| 4107 | case Primitive::kPrimBoolean: { |
| 4108 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4109 | break; |
| 4110 | } |
| 4111 | |
| 4112 | case Primitive::kPrimByte: { |
| 4113 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4114 | break; |
| 4115 | } |
| 4116 | |
| 4117 | case Primitive::kPrimShort: { |
| 4118 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4119 | break; |
| 4120 | } |
| 4121 | |
| 4122 | case Primitive::kPrimChar: { |
| 4123 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4124 | break; |
| 4125 | } |
| 4126 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4127 | case Primitive::kPrimInt: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4128 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4129 | break; |
| 4130 | } |
| 4131 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4132 | case Primitive::kPrimNot: { |
| 4133 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4134 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4135 | Location temp_loc = locations->GetTemp(0); |
| 4136 | // Note that a potential implicit null check is handled in this |
| 4137 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4138 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4139 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4140 | if (is_volatile) { |
| 4141 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4142 | } |
| 4143 | } else { |
| 4144 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4145 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4146 | if (is_volatile) { |
| 4147 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4148 | } |
| 4149 | // If read barriers are enabled, emit read barriers other than |
| 4150 | // Baker's using a slow path (and also unpoison the loaded |
| 4151 | // reference, if heap poisoning is enabled). |
| 4152 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4153 | } |
| 4154 | break; |
| 4155 | } |
| 4156 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4157 | case Primitive::kPrimLong: { |
| 4158 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4159 | break; |
| 4160 | } |
| 4161 | |
| 4162 | case Primitive::kPrimFloat: { |
| 4163 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4164 | break; |
| 4165 | } |
| 4166 | |
| 4167 | case Primitive::kPrimDouble: { |
| 4168 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4169 | break; |
| 4170 | } |
| 4171 | |
| 4172 | case Primitive::kPrimVoid: |
| 4173 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4174 | UNREACHABLE(); |
| 4175 | } |
| 4176 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4177 | if (field_type == Primitive::kPrimNot) { |
| 4178 | // Potential implicit null checks, in the case of reference |
| 4179 | // fields, are handled in the previous switch statement. |
| 4180 | } else { |
| 4181 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4182 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4183 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4184 | if (is_volatile) { |
| 4185 | if (field_type == Primitive::kPrimNot) { |
| 4186 | // Memory barriers, in the case of references, are also handled |
| 4187 | // in the previous switch statement. |
| 4188 | } else { |
| 4189 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4190 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4191 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4192 | } |
| 4193 | |
| 4194 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 4195 | const FieldInfo& field_info) { |
| 4196 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4197 | |
| 4198 | LocationSummary* locations = |
| 4199 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4200 | Primitive::Type field_type = field_info.GetFieldType(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4201 | bool is_volatile = field_info.IsVolatile(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4202 | bool needs_write_barrier = |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4203 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4204 | |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4205 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4206 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4207 | if (is_volatile) { |
| 4208 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4209 | locations->SetInAt(1, Location::FpuRegisterOrInt32Constant(instruction->InputAt(1))); |
| 4210 | } else { |
| 4211 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4212 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4213 | } else { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4214 | if (is_volatile) { |
| 4215 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4216 | locations->SetInAt(1, Location::RegisterOrInt32Constant(instruction->InputAt(1))); |
| 4217 | } else { |
| 4218 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4219 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4220 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4221 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4222 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4223 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4224 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4225 | } else if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4226 | // Temporary register for the reference poisoning. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4227 | locations->AddTemp(Location::RequiresRegister()); |
| 4228 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4229 | } |
| 4230 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4231 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4232 | const FieldInfo& field_info, |
| 4233 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4234 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4235 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4236 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4237 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4238 | Location value = locations->InAt(1); |
| 4239 | bool is_volatile = field_info.IsVolatile(); |
| 4240 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4241 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4242 | |
| 4243 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4244 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4245 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4246 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4247 | bool maybe_record_implicit_null_check_done = false; |
| 4248 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4249 | switch (field_type) { |
| 4250 | case Primitive::kPrimBoolean: |
| 4251 | case Primitive::kPrimByte: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4252 | if (value.IsConstant()) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4253 | int8_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4254 | __ movb(Address(base, offset), Immediate(v)); |
| 4255 | } else { |
| 4256 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4257 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4258 | break; |
| 4259 | } |
| 4260 | |
| 4261 | case Primitive::kPrimShort: |
| 4262 | case Primitive::kPrimChar: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4263 | if (value.IsConstant()) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4264 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4265 | __ movw(Address(base, offset), Immediate(v)); |
| 4266 | } else { |
| 4267 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4268 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4269 | break; |
| 4270 | } |
| 4271 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4272 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4273 | case Primitive::kPrimNot: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4274 | if (value.IsConstant()) { |
| 4275 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4276 | // `field_type == Primitive::kPrimNot` implies `v == 0`. |
| 4277 | DCHECK((field_type != Primitive::kPrimNot) || (v == 0)); |
| 4278 | // Note: if heap poisoning is enabled, no need to poison |
| 4279 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 4280 | __ movl(Address(base, offset), Immediate(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4281 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4282 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4283 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4284 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4285 | __ PoisonHeapReference(temp); |
| 4286 | __ movl(Address(base, offset), temp); |
| 4287 | } else { |
| 4288 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4289 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4290 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4291 | break; |
| 4292 | } |
| 4293 | |
| 4294 | case Primitive::kPrimLong: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4295 | if (value.IsConstant()) { |
| 4296 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4297 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4298 | Address(base, offset + sizeof(int32_t)), |
| 4299 | v, |
| 4300 | instruction); |
| 4301 | maybe_record_implicit_null_check_done = true; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4302 | } else { |
| 4303 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4304 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4305 | break; |
| 4306 | } |
| 4307 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4308 | case Primitive::kPrimFloat: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4309 | if (value.IsConstant()) { |
| 4310 | int32_t v = |
| 4311 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4312 | __ movl(Address(base, offset), Immediate(v)); |
| 4313 | } else { |
| 4314 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4315 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4316 | break; |
| 4317 | } |
| 4318 | |
| 4319 | case Primitive::kPrimDouble: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4320 | if (value.IsConstant()) { |
| 4321 | int64_t v = |
| 4322 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4323 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4324 | Address(base, offset + sizeof(int32_t)), |
| 4325 | v, |
| 4326 | instruction); |
| 4327 | maybe_record_implicit_null_check_done = true; |
| 4328 | } else { |
| 4329 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4330 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4331 | break; |
| 4332 | } |
| 4333 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4334 | case Primitive::kPrimVoid: |
| 4335 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4336 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4337 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4338 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4339 | if (!maybe_record_implicit_null_check_done) { |
| 4340 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4341 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4342 | |
| 4343 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4344 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4345 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4346 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4347 | } |
| 4348 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4349 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4350 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4351 | } |
| 4352 | } |
| 4353 | |
| 4354 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4355 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4356 | } |
| 4357 | |
| 4358 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4359 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4360 | } |
| 4361 | |
| 4362 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4363 | HandleFieldGet(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4364 | } |
| 4365 | |
| 4366 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4367 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4368 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4369 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4370 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4371 | HandleFieldGet(instruction); |
| 4372 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4373 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4374 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4375 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4376 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4377 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4378 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4379 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4380 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4381 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4382 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4383 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4384 | } |
| 4385 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4386 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldGet( |
| 4387 | HUnresolvedInstanceFieldGet* instruction) { |
| 4388 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4389 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4390 | instruction, instruction->GetFieldType(), calling_convention); |
| 4391 | } |
| 4392 | |
| 4393 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldGet( |
| 4394 | HUnresolvedInstanceFieldGet* instruction) { |
| 4395 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4396 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4397 | instruction->GetFieldType(), |
| 4398 | instruction->GetFieldIndex(), |
| 4399 | instruction->GetDexPc(), |
| 4400 | calling_convention); |
| 4401 | } |
| 4402 | |
| 4403 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldSet( |
| 4404 | HUnresolvedInstanceFieldSet* instruction) { |
| 4405 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4406 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4407 | instruction, instruction->GetFieldType(), calling_convention); |
| 4408 | } |
| 4409 | |
| 4410 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldSet( |
| 4411 | HUnresolvedInstanceFieldSet* instruction) { |
| 4412 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4413 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4414 | instruction->GetFieldType(), |
| 4415 | instruction->GetFieldIndex(), |
| 4416 | instruction->GetDexPc(), |
| 4417 | calling_convention); |
| 4418 | } |
| 4419 | |
| 4420 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldGet( |
| 4421 | HUnresolvedStaticFieldGet* instruction) { |
| 4422 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4423 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4424 | instruction, instruction->GetFieldType(), calling_convention); |
| 4425 | } |
| 4426 | |
| 4427 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldGet( |
| 4428 | HUnresolvedStaticFieldGet* instruction) { |
| 4429 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4430 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4431 | instruction->GetFieldType(), |
| 4432 | instruction->GetFieldIndex(), |
| 4433 | instruction->GetDexPc(), |
| 4434 | calling_convention); |
| 4435 | } |
| 4436 | |
| 4437 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldSet( |
| 4438 | HUnresolvedStaticFieldSet* instruction) { |
| 4439 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4440 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4441 | instruction, instruction->GetFieldType(), calling_convention); |
| 4442 | } |
| 4443 | |
| 4444 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldSet( |
| 4445 | HUnresolvedStaticFieldSet* instruction) { |
| 4446 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4447 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4448 | instruction->GetFieldType(), |
| 4449 | instruction->GetFieldIndex(), |
| 4450 | instruction->GetDexPc(), |
| 4451 | calling_convention); |
| 4452 | } |
| 4453 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4454 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4455 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4456 | ? LocationSummary::kCallOnSlowPath |
| 4457 | : LocationSummary::kNoCall; |
| 4458 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4459 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4460 | ? Location::RequiresRegister() |
| 4461 | : Location::Any(); |
| 4462 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4463 | if (instruction->HasUses()) { |
| 4464 | locations->SetOut(Location::SameAsFirstInput()); |
| 4465 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4466 | } |
| 4467 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4468 | void CodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4469 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4470 | return; |
| 4471 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4472 | LocationSummary* locations = instruction->GetLocations(); |
| 4473 | Location obj = locations->InAt(0); |
| 4474 | |
| 4475 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4476 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4477 | } |
| 4478 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4479 | void CodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4480 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4481 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4482 | |
| 4483 | LocationSummary* locations = instruction->GetLocations(); |
| 4484 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4485 | |
| 4486 | if (obj.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4487 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4488 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4489 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4490 | } else { |
| 4491 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4492 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4493 | __ jmp(slow_path->GetEntryLabel()); |
| 4494 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4495 | } |
| 4496 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4497 | } |
| 4498 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4499 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4500 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4501 | } |
| 4502 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4503 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4504 | bool object_array_get_with_read_barrier = |
| 4505 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4506 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4507 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4508 | object_array_get_with_read_barrier ? |
| 4509 | LocationSummary::kCallOnSlowPath : |
| 4510 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4511 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4512 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4513 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4514 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4515 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4516 | // The output overlaps for an object array get when read barriers |
| 4517 | // are enabled: we do not want the move to overwrite the array's |
| 4518 | // location, as we need it to emit the read barrier. |
| 4519 | locations->SetOut( |
| 4520 | Location::RequiresRegister(), |
| 4521 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4522 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4523 | // We need a temporary register for the read barrier marking slow |
| 4524 | // path in CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier. |
| 4525 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4526 | locations->AddTemp(Location::RequiresRegister()); |
| 4527 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4528 | } |
| 4529 | |
| 4530 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 4531 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4532 | Location obj_loc = locations->InAt(0); |
| 4533 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4534 | Location index = locations->InAt(1); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4535 | Location out_loc = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4536 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4537 | Primitive::Type type = instruction->GetType(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4538 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4539 | case Primitive::kPrimBoolean: { |
| 4540 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4541 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4542 | if (index.IsConstant()) { |
| 4543 | __ movzxb(out, Address(obj, |
| 4544 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4545 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4546 | __ movzxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4547 | } |
| 4548 | break; |
| 4549 | } |
| 4550 | |
| 4551 | case Primitive::kPrimByte: { |
| 4552 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4553 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4554 | if (index.IsConstant()) { |
| 4555 | __ movsxb(out, Address(obj, |
| 4556 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4557 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4558 | __ movsxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4559 | } |
| 4560 | break; |
| 4561 | } |
| 4562 | |
| 4563 | case Primitive::kPrimShort: { |
| 4564 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4565 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4566 | if (index.IsConstant()) { |
| 4567 | __ movsxw(out, Address(obj, |
| 4568 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4569 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4570 | __ movsxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4571 | } |
| 4572 | break; |
| 4573 | } |
| 4574 | |
| 4575 | case Primitive::kPrimChar: { |
| 4576 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4577 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4578 | if (index.IsConstant()) { |
| 4579 | __ movzxw(out, Address(obj, |
| 4580 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4581 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4582 | __ movzxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4583 | } |
| 4584 | break; |
| 4585 | } |
| 4586 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4587 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4588 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4589 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4590 | if (index.IsConstant()) { |
| 4591 | __ movl(out, Address(obj, |
| 4592 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4593 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4594 | __ movl(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4595 | } |
| 4596 | break; |
| 4597 | } |
| 4598 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4599 | case Primitive::kPrimNot: { |
| 4600 | static_assert( |
| 4601 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4602 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 4603 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4604 | // /* HeapReference<Object> */ out = |
| 4605 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4606 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4607 | Location temp = locations->GetTemp(0); |
| 4608 | // Note that a potential implicit null check is handled in this |
| 4609 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 4610 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 4611 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 4612 | } else { |
| 4613 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| 4614 | if (index.IsConstant()) { |
| 4615 | uint32_t offset = |
| 4616 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4617 | __ movl(out, Address(obj, offset)); |
| 4618 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4619 | // If read barriers are enabled, emit read barriers other than |
| 4620 | // Baker's using a slow path (and also unpoison the loaded |
| 4621 | // reference, if heap poisoning is enabled). |
| 4622 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 4623 | } else { |
| 4624 | __ movl(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
| 4625 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4626 | // If read barriers are enabled, emit read barriers other than |
| 4627 | // Baker's using a slow path (and also unpoison the loaded |
| 4628 | // reference, if heap poisoning is enabled). |
| 4629 | codegen_->MaybeGenerateReadBarrierSlow( |
| 4630 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 4631 | } |
| 4632 | } |
| 4633 | break; |
| 4634 | } |
| 4635 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4636 | case Primitive::kPrimLong: { |
| 4637 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4638 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4639 | if (index.IsConstant()) { |
| 4640 | __ movq(out, Address(obj, |
| 4641 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4642 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4643 | __ movq(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4644 | } |
| 4645 | break; |
| 4646 | } |
| 4647 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4648 | case Primitive::kPrimFloat: { |
| 4649 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4650 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4651 | if (index.IsConstant()) { |
| 4652 | __ movss(out, Address(obj, |
| 4653 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4654 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4655 | __ movss(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4656 | } |
| 4657 | break; |
| 4658 | } |
| 4659 | |
| 4660 | case Primitive::kPrimDouble: { |
| 4661 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4662 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4663 | if (index.IsConstant()) { |
| 4664 | __ movsd(out, Address(obj, |
| 4665 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4666 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4667 | __ movsd(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4668 | } |
| 4669 | break; |
| 4670 | } |
| 4671 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4672 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4673 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4674 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4675 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4676 | |
| 4677 | if (type == Primitive::kPrimNot) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4678 | // Potential implicit null checks, in the case of reference |
| 4679 | // arrays, are handled in the previous switch statement. |
| 4680 | } else { |
| 4681 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4682 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4683 | } |
| 4684 | |
| 4685 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4686 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4687 | |
| 4688 | bool needs_write_barrier = |
| 4689 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4690 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4691 | bool object_array_set_with_read_barrier = |
| 4692 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4693 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4694 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4695 | instruction, |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4696 | (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] | 4697 | LocationSummary::kCallOnSlowPath : |
| 4698 | LocationSummary::kNoCall); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4699 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4700 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4701 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4702 | if (Primitive::IsFloatingPointType(value_type)) { |
| 4703 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4704 | } else { |
| 4705 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 4706 | } |
| 4707 | |
| 4708 | if (needs_write_barrier) { |
| 4709 | // Temporary registers for the write barrier. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4710 | |
| 4711 | // This first temporary register is possibly used for heap |
| 4712 | // reference poisoning and/or read barrier emission too. |
| 4713 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4714 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4715 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4716 | } |
| 4717 | |
| 4718 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 4719 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4720 | Location array_loc = locations->InAt(0); |
| 4721 | CpuRegister array = array_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4722 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4723 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4724 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4725 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4726 | bool needs_write_barrier = |
| 4727 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4728 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4729 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4730 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4731 | |
| 4732 | switch (value_type) { |
| 4733 | case Primitive::kPrimBoolean: |
| 4734 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4735 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 4736 | Address address = index.IsConstant() |
| 4737 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 4738 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_1, offset); |
| 4739 | if (value.IsRegister()) { |
| 4740 | __ movb(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4741 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4742 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4743 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4744 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4745 | break; |
| 4746 | } |
| 4747 | |
| 4748 | case Primitive::kPrimShort: |
| 4749 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4750 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 4751 | Address address = index.IsConstant() |
| 4752 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 4753 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_2, offset); |
| 4754 | if (value.IsRegister()) { |
| 4755 | __ movw(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4756 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4757 | DCHECK(value.IsConstant()) << value; |
| 4758 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4759 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4760 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4761 | break; |
| 4762 | } |
| 4763 | |
| 4764 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4765 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4766 | Address address = index.IsConstant() |
| 4767 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4768 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4769 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4770 | if (!value.IsRegister()) { |
| 4771 | // Just setting null. |
| 4772 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 4773 | DCHECK(value.IsConstant()) << value; |
| 4774 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4775 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4776 | DCHECK(!needs_write_barrier); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4777 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4778 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4779 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4780 | |
| 4781 | DCHECK(needs_write_barrier); |
| 4782 | CpuRegister register_value = value.AsRegister<CpuRegister>(); |
| 4783 | NearLabel done, not_null, do_put; |
| 4784 | SlowPathCode* slow_path = nullptr; |
| 4785 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4786 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4787 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86_64(instruction); |
| 4788 | codegen_->AddSlowPath(slow_path); |
| 4789 | if (instruction->GetValueCanBeNull()) { |
| 4790 | __ testl(register_value, register_value); |
| 4791 | __ j(kNotEqual, ¬_null); |
| 4792 | __ movl(address, Immediate(0)); |
| 4793 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4794 | __ jmp(&done); |
| 4795 | __ Bind(¬_null); |
| 4796 | } |
| 4797 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4798 | if (kEmitCompilerReadBarrier) { |
| 4799 | // When read barriers are enabled, the type checking |
| 4800 | // instrumentation requires two read barriers: |
| 4801 | // |
| 4802 | // __ movl(temp2, temp); |
| 4803 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 4804 | // __ movl(temp, Address(temp, component_offset)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4805 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4806 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 4807 | // |
| 4808 | // // /* HeapReference<Class> */ temp2 = register_value->klass_ |
| 4809 | // __ movl(temp2, Address(register_value, class_offset)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4810 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4811 | // instruction, temp2_loc, temp2_loc, value, class_offset, temp_loc); |
| 4812 | // |
| 4813 | // __ cmpl(temp, temp2); |
| 4814 | // |
| 4815 | // However, the second read barrier may trash `temp`, as it |
| 4816 | // is a temporary register, and as such would not be saved |
| 4817 | // along with live registers before calling the runtime (nor |
| 4818 | // restored afterwards). So in this case, we bail out and |
| 4819 | // delegate the work to the array set slow path. |
| 4820 | // |
| 4821 | // TODO: Extend the register allocator to support a new |
| 4822 | // "(locally) live temp" location so as to avoid always |
| 4823 | // going into the slow path when read barriers are enabled. |
| 4824 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4825 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4826 | // /* HeapReference<Class> */ temp = array->klass_ |
| 4827 | __ movl(temp, Address(array, class_offset)); |
| 4828 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4829 | __ MaybeUnpoisonHeapReference(temp); |
| 4830 | |
| 4831 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 4832 | __ movl(temp, Address(temp, component_offset)); |
| 4833 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 4834 | // nor the object reference in `register_value->klass`, as |
| 4835 | // we are comparing two poisoned references. |
| 4836 | __ cmpl(temp, Address(register_value, class_offset)); |
| 4837 | |
| 4838 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4839 | __ j(kEqual, &do_put); |
| 4840 | // If heap poisoning is enabled, the `temp` reference has |
| 4841 | // not been unpoisoned yet; unpoison it now. |
| 4842 | __ MaybeUnpoisonHeapReference(temp); |
| 4843 | |
| 4844 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 4845 | __ movl(temp, Address(temp, super_offset)); |
| 4846 | // If heap poisoning is enabled, no need to unpoison |
| 4847 | // `temp`, as we are comparing against null below. |
| 4848 | __ testl(temp, temp); |
| 4849 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4850 | __ Bind(&do_put); |
| 4851 | } else { |
| 4852 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4853 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4854 | } |
| 4855 | } |
| 4856 | |
| 4857 | if (kPoisonHeapReferences) { |
| 4858 | __ movl(temp, register_value); |
| 4859 | __ PoisonHeapReference(temp); |
| 4860 | __ movl(address, temp); |
| 4861 | } else { |
| 4862 | __ movl(address, register_value); |
| 4863 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4864 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4865 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4866 | } |
| 4867 | |
| 4868 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 4869 | codegen_->MarkGCCard( |
| 4870 | temp, card, array, value.AsRegister<CpuRegister>(), instruction->GetValueCanBeNull()); |
| 4871 | __ Bind(&done); |
| 4872 | |
| 4873 | if (slow_path != nullptr) { |
| 4874 | __ Bind(slow_path->GetExitLabel()); |
| 4875 | } |
| 4876 | |
| 4877 | break; |
| 4878 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4879 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4880 | case Primitive::kPrimInt: { |
| 4881 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4882 | Address address = index.IsConstant() |
| 4883 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4884 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
| 4885 | if (value.IsRegister()) { |
| 4886 | __ movl(address, value.AsRegister<CpuRegister>()); |
| 4887 | } else { |
| 4888 | DCHECK(value.IsConstant()) << value; |
| 4889 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4890 | __ movl(address, Immediate(v)); |
| 4891 | } |
| 4892 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4893 | break; |
| 4894 | } |
| 4895 | |
| 4896 | case Primitive::kPrimLong: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4897 | uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| 4898 | Address address = index.IsConstant() |
| 4899 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 4900 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset); |
| 4901 | if (value.IsRegister()) { |
| 4902 | __ movq(address, value.AsRegister<CpuRegister>()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4903 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4904 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4905 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4906 | Address address_high = index.IsConstant() |
| 4907 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 4908 | offset + sizeof(int32_t)) |
| 4909 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset + sizeof(int32_t)); |
| 4910 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4911 | } |
| 4912 | break; |
| 4913 | } |
| 4914 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4915 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4916 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4917 | Address address = index.IsConstant() |
| 4918 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4919 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4920 | if (value.IsFpuRegister()) { |
| 4921 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 4922 | } else { |
| 4923 | DCHECK(value.IsConstant()); |
| 4924 | int32_t v = |
| 4925 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4926 | __ movl(address, Immediate(v)); |
| 4927 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4928 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4929 | break; |
| 4930 | } |
| 4931 | |
| 4932 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4933 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4934 | Address address = index.IsConstant() |
| 4935 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 4936 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4937 | if (value.IsFpuRegister()) { |
| 4938 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 4939 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4940 | } else { |
| 4941 | int64_t v = |
| 4942 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4943 | Address address_high = index.IsConstant() |
| 4944 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 4945 | offset + sizeof(int32_t)) |
| 4946 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset + sizeof(int32_t)); |
| 4947 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| 4948 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4949 | break; |
| 4950 | } |
| 4951 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4952 | case Primitive::kPrimVoid: |
| 4953 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4954 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4955 | } |
| 4956 | } |
| 4957 | |
| 4958 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4959 | LocationSummary* locations = |
| 4960 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4961 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4962 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4963 | } |
| 4964 | |
| 4965 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
| 4966 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 4967 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4968 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4969 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4970 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4971 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4972 | } |
| 4973 | |
| 4974 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4975 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4976 | ? LocationSummary::kCallOnSlowPath |
| 4977 | : LocationSummary::kNoCall; |
| 4978 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4979 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4980 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4981 | if (instruction->HasUses()) { |
| 4982 | locations->SetOut(Location::SameAsFirstInput()); |
| 4983 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4984 | } |
| 4985 | |
| 4986 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4987 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4988 | Location index_loc = locations->InAt(0); |
| 4989 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4990 | SlowPathCode* slow_path = |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4991 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4992 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4993 | if (length_loc.IsConstant()) { |
| 4994 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 4995 | if (index_loc.IsConstant()) { |
| 4996 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 4997 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4998 | if (index < 0 || index >= length) { |
| 4999 | codegen_->AddSlowPath(slow_path); |
| 5000 | __ jmp(slow_path->GetEntryLabel()); |
| 5001 | } else { |
| 5002 | // Some optimization after BCE may have generated this, and we should not |
| 5003 | // generate a bounds check if it is a valid range. |
| 5004 | } |
| 5005 | return; |
| 5006 | } |
| 5007 | |
| 5008 | // We have to reverse the jump condition because the length is the constant. |
| 5009 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 5010 | __ cmpl(index_reg, Immediate(length)); |
| 5011 | codegen_->AddSlowPath(slow_path); |
| 5012 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5013 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5014 | CpuRegister length = length_loc.AsRegister<CpuRegister>(); |
| 5015 | if (index_loc.IsConstant()) { |
| 5016 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5017 | __ cmpl(length, Immediate(value)); |
| 5018 | } else { |
| 5019 | __ cmpl(length, index_loc.AsRegister<CpuRegister>()); |
| 5020 | } |
| 5021 | codegen_->AddSlowPath(slow_path); |
| 5022 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5023 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5024 | } |
| 5025 | |
| 5026 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 5027 | CpuRegister card, |
| 5028 | CpuRegister object, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5029 | CpuRegister value, |
| 5030 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5031 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5032 | if (value_can_be_null) { |
| 5033 | __ testl(value, value); |
| 5034 | __ j(kEqual, &is_null); |
| 5035 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5036 | __ gs()->movq(card, Address::Absolute(Thread::CardTableOffset<kX86_64WordSize>().Int32Value(), |
| 5037 | /* no_rip */ true)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5038 | __ movq(temp, object); |
| 5039 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5040 | __ movb(Address(temp, card, TIMES_1, 0), card); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5041 | if (value_can_be_null) { |
| 5042 | __ Bind(&is_null); |
| 5043 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5044 | } |
| 5045 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5046 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5047 | LOG(FATAL) << "Unimplemented"; |
| 5048 | } |
| 5049 | |
| 5050 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5051 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5052 | } |
| 5053 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5054 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 5055 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 5056 | } |
| 5057 | |
| 5058 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5059 | HBasicBlock* block = instruction->GetBlock(); |
| 5060 | if (block->GetLoopInformation() != nullptr) { |
| 5061 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5062 | // The back edge will generate the suspend check. |
| 5063 | return; |
| 5064 | } |
| 5065 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5066 | // The goto will generate the suspend check. |
| 5067 | return; |
| 5068 | } |
| 5069 | GenerateSuspendCheck(instruction, nullptr); |
| 5070 | } |
| 5071 | |
| 5072 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5073 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5074 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5075 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 5076 | if (slow_path == nullptr) { |
| 5077 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
| 5078 | instruction->SetSlowPath(slow_path); |
| 5079 | codegen_->AddSlowPath(slow_path); |
| 5080 | if (successor != nullptr) { |
| 5081 | DCHECK(successor->IsLoopHeader()); |
| 5082 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5083 | } |
| 5084 | } else { |
| 5085 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5086 | } |
| 5087 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5088 | __ gs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86_64WordSize>().Int32Value(), |
| 5089 | /* no_rip */ true), |
| 5090 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5091 | if (successor == nullptr) { |
| 5092 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5093 | __ Bind(slow_path->GetReturnLabel()); |
| 5094 | } else { |
| 5095 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5096 | __ jmp(slow_path->GetEntryLabel()); |
| 5097 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5098 | } |
| 5099 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5100 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 5101 | return codegen_->GetAssembler(); |
| 5102 | } |
| 5103 | |
| 5104 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5105 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5106 | Location source = move->GetSource(); |
| 5107 | Location destination = move->GetDestination(); |
| 5108 | |
| 5109 | if (source.IsRegister()) { |
| 5110 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5111 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5112 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5113 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5114 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5115 | } else { |
| 5116 | DCHECK(destination.IsDoubleStackSlot()); |
| 5117 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5118 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5119 | } |
| 5120 | } else if (source.IsStackSlot()) { |
| 5121 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5122 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5123 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5124 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5125 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5126 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5127 | } else { |
| 5128 | DCHECK(destination.IsStackSlot()); |
| 5129 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5130 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5131 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5132 | } else if (source.IsDoubleStackSlot()) { |
| 5133 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5134 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5135 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5136 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5137 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 5138 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5139 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 5140 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5141 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5142 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5143 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5144 | } else if (source.IsConstant()) { |
| 5145 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5146 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5147 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5148 | if (destination.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5149 | if (value == 0) { |
| 5150 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 5151 | } else { |
| 5152 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 5153 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5154 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5155 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5156 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5157 | } |
| 5158 | } else if (constant->IsLongConstant()) { |
| 5159 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5160 | if (destination.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5161 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5162 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5163 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5164 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5165 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5166 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5167 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5168 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5169 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5170 | codegen_->Load32BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5171 | } else { |
| 5172 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5173 | Immediate imm(bit_cast<int32_t, float>(fp_value)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5174 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 5175 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5176 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5177 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5178 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5179 | int64_t value = bit_cast<int64_t, double>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5180 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5181 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5182 | codegen_->Load64BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5183 | } else { |
| 5184 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5185 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5186 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5187 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5188 | } else if (source.IsFpuRegister()) { |
| 5189 | if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5190 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5191 | } else if (destination.IsStackSlot()) { |
| 5192 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5193 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5194 | } else { |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 5195 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5196 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5197 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5198 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5199 | } |
| 5200 | } |
| 5201 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5202 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5203 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5204 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 5205 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5206 | } |
| 5207 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5208 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5209 | ScratchRegisterScope ensure_scratch( |
| 5210 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 5211 | |
| 5212 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5213 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5214 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 5215 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5216 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5217 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5218 | CpuRegister(ensure_scratch.GetRegister())); |
| 5219 | } |
| 5220 | |
Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5221 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg1, CpuRegister reg2) { |
| 5222 | __ movq(CpuRegister(TMP), reg1); |
| 5223 | __ movq(reg1, reg2); |
| 5224 | __ movq(reg2, CpuRegister(TMP)); |
| 5225 | } |
| 5226 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5227 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 5228 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5229 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 5230 | __ movq(reg, CpuRegister(TMP)); |
| 5231 | } |
| 5232 | |
| 5233 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 5234 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5235 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5236 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5237 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5238 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5239 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 5240 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5241 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5242 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5243 | CpuRegister(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5244 | } |
| 5245 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5246 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 5247 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5248 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 5249 | __ movd(reg, CpuRegister(TMP)); |
| 5250 | } |
| 5251 | |
| 5252 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 5253 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5254 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 5255 | __ movd(reg, CpuRegister(TMP)); |
| 5256 | } |
| 5257 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5258 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5259 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5260 | Location source = move->GetSource(); |
| 5261 | Location destination = move->GetDestination(); |
| 5262 | |
| 5263 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5264 | Exchange64(source.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5265 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5266 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5267 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5268 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5269 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5270 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5271 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5272 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5273 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5274 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5275 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 5276 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5277 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5278 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 5279 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5280 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5281 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5282 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5283 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5284 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5285 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5286 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5287 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5288 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5289 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5290 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5291 | } |
| 5292 | } |
| 5293 | |
| 5294 | |
| 5295 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 5296 | __ pushq(CpuRegister(reg)); |
| 5297 | } |
| 5298 | |
| 5299 | |
| 5300 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 5301 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5302 | } |
| 5303 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5304 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5305 | SlowPathCode* slow_path, CpuRegister class_reg) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5306 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5307 | Immediate(mirror::Class::kStatusInitialized)); |
| 5308 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5309 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5310 | // No need for memory fence, thanks to the x86-64 memory model. |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5311 | } |
| 5312 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5313 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5314 | InvokeRuntimeCallingConvention calling_convention; |
| 5315 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5316 | cls, |
| 5317 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5318 | Location::RegisterLocation(RAX), |
| 5319 | /* code_generator_supports_read_barrier */ true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5320 | } |
| 5321 | |
| 5322 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5323 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5324 | if (cls->NeedsAccessCheck()) { |
| 5325 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 5326 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 5327 | cls, |
| 5328 | cls->GetDexPc(), |
| 5329 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5330 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5331 | return; |
| 5332 | } |
| 5333 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5334 | Location out_loc = locations->Out(); |
| 5335 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5336 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5337 | |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5338 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5339 | DCHECK(!cls->CanCallRuntime()); |
| 5340 | DCHECK(!cls->MustGenerateClinitCheck()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5341 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5342 | GenerateGcRootFieldLoad( |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5343 | cls, out_loc, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5344 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5345 | // /* GcRoot<mirror::Class>[] */ out = |
| 5346 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5347 | __ movq(out, Address(current_method, |
| 5348 | ArtMethod::DexCacheResolvedTypesOffset(kX86_64PointerSize).Int32Value())); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5349 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5350 | GenerateGcRootFieldLoad( |
| 5351 | cls, out_loc, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5352 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5353 | if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { |
| 5354 | DCHECK(cls->CanCallRuntime()); |
| 5355 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 5356 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5357 | codegen_->AddSlowPath(slow_path); |
| 5358 | if (!cls->IsInDexCache()) { |
| 5359 | __ testl(out, out); |
| 5360 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5361 | } |
| 5362 | if (cls->MustGenerateClinitCheck()) { |
| 5363 | GenerateClassInitializationCheck(slow_path, out); |
| 5364 | } else { |
| 5365 | __ Bind(slow_path->GetExitLabel()); |
| 5366 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5367 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5368 | } |
| 5369 | } |
| 5370 | |
| 5371 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 5372 | LocationSummary* locations = |
| 5373 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5374 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5375 | if (check->HasUses()) { |
| 5376 | locations->SetOut(Location::SameAsFirstInput()); |
| 5377 | } |
| 5378 | } |
| 5379 | |
| 5380 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5381 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5382 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5383 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5384 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5385 | GenerateClassInitializationCheck(slow_path, |
| 5386 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5387 | } |
| 5388 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5389 | HLoadString::LoadKind CodeGeneratorX86_64::GetSupportedLoadStringKind( |
| 5390 | HLoadString::LoadKind desired_string_load_kind) { |
| 5391 | if (kEmitCompilerReadBarrier) { |
| 5392 | switch (desired_string_load_kind) { |
| 5393 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5394 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5395 | case HLoadString::LoadKind::kBootImageAddress: |
| 5396 | // TODO: Implement for read barrier. |
| 5397 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 5398 | default: |
| 5399 | break; |
| 5400 | } |
| 5401 | } |
| 5402 | switch (desired_string_load_kind) { |
| 5403 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5404 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5405 | // We prefer the always-available RIP-relative address for the x86-64 boot image. |
| 5406 | return HLoadString::LoadKind::kBootImageLinkTimePcRelative; |
| 5407 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5408 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5409 | break; |
| 5410 | case HLoadString::LoadKind::kBootImageAddress: |
| 5411 | break; |
| 5412 | case HLoadString::LoadKind::kDexCacheAddress: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5413 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5414 | break; |
| 5415 | case HLoadString::LoadKind::kDexCachePcRelative: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5416 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5417 | break; |
| 5418 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5419 | break; |
| 5420 | } |
| 5421 | return desired_string_load_kind; |
| 5422 | } |
| 5423 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5424 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5425 | LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier) |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5426 | ? LocationSummary::kCallOnSlowPath |
| 5427 | : LocationSummary::kNoCall; |
| 5428 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5429 | if (load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) { |
| 5430 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5431 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5432 | locations->SetOut(Location::RequiresRegister()); |
| 5433 | } |
| 5434 | |
| 5435 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5436 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5437 | Location out_loc = locations->Out(); |
| 5438 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5439 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5440 | switch (load->GetLoadKind()) { |
| 5441 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 5442 | DCHECK(!kEmitCompilerReadBarrier); |
| 5443 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| 5444 | codegen_->RecordStringPatch(load); |
| 5445 | return; // No dex cache slow path. |
| 5446 | } |
| 5447 | case HLoadString::LoadKind::kBootImageAddress: { |
| 5448 | DCHECK(!kEmitCompilerReadBarrier); |
| 5449 | DCHECK_NE(load->GetAddress(), 0u); |
| 5450 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 5451 | __ movl(out, Immediate(address)); // Zero-extended. |
| 5452 | codegen_->RecordSimplePatch(); |
| 5453 | return; // No dex cache slow path. |
| 5454 | } |
| 5455 | case HLoadString::LoadKind::kDexCacheAddress: { |
| 5456 | DCHECK_NE(load->GetAddress(), 0u); |
| 5457 | if (IsUint<32>(load->GetAddress())) { |
| 5458 | Address address = Address::Absolute(load->GetAddress(), /* no_rip */ true); |
| 5459 | GenerateGcRootFieldLoad(load, out_loc, address); |
| 5460 | } else { |
| 5461 | // TODO: Consider using opcode A1, i.e. movl eax, moff32 (with 64-bit address). |
| 5462 | __ movq(out, Immediate(load->GetAddress())); |
| 5463 | GenerateGcRootFieldLoad(load, out_loc, Address(out, 0)); |
| 5464 | } |
| 5465 | break; |
| 5466 | } |
| 5467 | case HLoadString::LoadKind::kDexCachePcRelative: { |
| 5468 | uint32_t offset = load->GetDexCacheElementOffset(); |
| 5469 | Label* fixup_label = codegen_->NewPcRelativeDexCacheArrayPatch(load->GetDexFile(), offset); |
| 5470 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5471 | /* no_rip */ false); |
| 5472 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label); |
| 5473 | break; |
| 5474 | } |
| 5475 | case HLoadString::LoadKind::kDexCacheViaMethod: { |
| 5476 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5477 | |
| 5478 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5479 | GenerateGcRootFieldLoad( |
| 5480 | load, out_loc, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
| 5481 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
| 5482 | __ movq(out, Address(out, mirror::Class::DexCacheStringsOffset().Uint32Value())); |
| 5483 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 5484 | GenerateGcRootFieldLoad( |
| 5485 | load, out_loc, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
| 5486 | break; |
| 5487 | } |
| 5488 | default: |
| 5489 | LOG(FATAL) << "Unexpected load kind: " << load->GetLoadKind(); |
| 5490 | UNREACHABLE(); |
| 5491 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5492 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5493 | if (!load->IsInDexCache()) { |
| 5494 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86_64(load); |
| 5495 | codegen_->AddSlowPath(slow_path); |
| 5496 | __ testl(out, out); |
| 5497 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5498 | __ Bind(slow_path->GetExitLabel()); |
| 5499 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5500 | } |
| 5501 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5502 | static Address GetExceptionTlsAddress() { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5503 | return Address::Absolute(Thread::ExceptionOffset<kX86_64WordSize>().Int32Value(), |
| 5504 | /* no_rip */ true); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5505 | } |
| 5506 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5507 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 5508 | LocationSummary* locations = |
| 5509 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5510 | locations->SetOut(Location::RequiresRegister()); |
| 5511 | } |
| 5512 | |
| 5513 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5514 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 5515 | } |
| 5516 | |
| 5517 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
| 5518 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5519 | } |
| 5520 | |
| 5521 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5522 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5523 | } |
| 5524 | |
| 5525 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| 5526 | LocationSummary* locations = |
| 5527 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5528 | InvokeRuntimeCallingConvention calling_convention; |
| 5529 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5530 | } |
| 5531 | |
| 5532 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5533 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 5534 | instruction, |
| 5535 | instruction->GetDexPc(), |
| 5536 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5537 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5538 | } |
| 5539 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5540 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5541 | return kEmitCompilerReadBarrier && |
| 5542 | (kUseBakerReadBarrier || |
| 5543 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5544 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5545 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5546 | } |
| 5547 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5548 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5549 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5550 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5551 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5552 | case TypeCheckKind::kExactCheck: |
| 5553 | case TypeCheckKind::kAbstractClassCheck: |
| 5554 | case TypeCheckKind::kClassHierarchyCheck: |
| 5555 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5556 | call_kind = |
| 5557 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5558 | break; |
| 5559 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5560 | case TypeCheckKind::kUnresolvedCheck: |
| 5561 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5562 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5563 | break; |
| 5564 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5565 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5566 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5567 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5568 | locations->SetInAt(1, Location::Any()); |
| 5569 | // Note that TypeCheckSlowPathX86_64 uses this "out" register too. |
| 5570 | locations->SetOut(Location::RequiresRegister()); |
| 5571 | // When read barriers are enabled, we need a temporary register for |
| 5572 | // some cases. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5573 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5574 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5575 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5576 | } |
| 5577 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5578 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5579 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5580 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5581 | Location obj_loc = locations->InAt(0); |
| 5582 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5583 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5584 | Location out_loc = locations->Out(); |
| 5585 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5586 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5587 | locations->GetTemp(0) : |
| 5588 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5589 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5590 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5591 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5592 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5593 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5594 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5595 | |
| 5596 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5597 | // Avoid null check if we know obj is not null. |
| 5598 | if (instruction->MustDoNullCheck()) { |
| 5599 | __ testl(obj, obj); |
| 5600 | __ j(kEqual, &zero); |
| 5601 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5602 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5603 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5604 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5605 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5606 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5607 | case TypeCheckKind::kExactCheck: { |
| 5608 | if (cls.IsRegister()) { |
| 5609 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5610 | } else { |
| 5611 | DCHECK(cls.IsStackSlot()) << cls; |
| 5612 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5613 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5614 | if (zero.IsLinked()) { |
| 5615 | // Classes must be equal for the instanceof to succeed. |
| 5616 | __ j(kNotEqual, &zero); |
| 5617 | __ movl(out, Immediate(1)); |
| 5618 | __ jmp(&done); |
| 5619 | } else { |
| 5620 | __ setcc(kEqual, out); |
| 5621 | // setcc only sets the low byte. |
| 5622 | __ andl(out, Immediate(1)); |
| 5623 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5624 | break; |
| 5625 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5626 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5627 | case TypeCheckKind::kAbstractClassCheck: { |
| 5628 | // If the class is abstract, we eagerly fetch the super class of the |
| 5629 | // object to avoid doing a comparison we know will fail. |
| 5630 | NearLabel loop, success; |
| 5631 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5632 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5633 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5634 | __ testl(out, out); |
| 5635 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5636 | __ j(kEqual, &done); |
| 5637 | if (cls.IsRegister()) { |
| 5638 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5639 | } else { |
| 5640 | DCHECK(cls.IsStackSlot()) << cls; |
| 5641 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5642 | } |
| 5643 | __ j(kNotEqual, &loop); |
| 5644 | __ movl(out, Immediate(1)); |
| 5645 | if (zero.IsLinked()) { |
| 5646 | __ jmp(&done); |
| 5647 | } |
| 5648 | break; |
| 5649 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5650 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5651 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5652 | // Walk over the class hierarchy to find a match. |
| 5653 | NearLabel loop, success; |
| 5654 | __ Bind(&loop); |
| 5655 | if (cls.IsRegister()) { |
| 5656 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5657 | } else { |
| 5658 | DCHECK(cls.IsStackSlot()) << cls; |
| 5659 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5660 | } |
| 5661 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5662 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5663 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5664 | __ testl(out, out); |
| 5665 | __ j(kNotEqual, &loop); |
| 5666 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5667 | __ jmp(&done); |
| 5668 | __ Bind(&success); |
| 5669 | __ movl(out, Immediate(1)); |
| 5670 | if (zero.IsLinked()) { |
| 5671 | __ jmp(&done); |
| 5672 | } |
| 5673 | break; |
| 5674 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5675 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5676 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5677 | // Do an exact check. |
| 5678 | NearLabel exact_check; |
| 5679 | if (cls.IsRegister()) { |
| 5680 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5681 | } else { |
| 5682 | DCHECK(cls.IsStackSlot()) << cls; |
| 5683 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5684 | } |
| 5685 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5686 | // 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] | 5687 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5688 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5689 | __ testl(out, out); |
| 5690 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5691 | __ j(kEqual, &done); |
| 5692 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5693 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5694 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5695 | __ movl(out, Immediate(1)); |
| 5696 | __ jmp(&done); |
| 5697 | break; |
| 5698 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5699 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5700 | case TypeCheckKind::kArrayCheck: { |
| 5701 | if (cls.IsRegister()) { |
| 5702 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5703 | } else { |
| 5704 | DCHECK(cls.IsStackSlot()) << cls; |
| 5705 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5706 | } |
| 5707 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5708 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5709 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5710 | codegen_->AddSlowPath(slow_path); |
| 5711 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5712 | __ movl(out, Immediate(1)); |
| 5713 | if (zero.IsLinked()) { |
| 5714 | __ jmp(&done); |
| 5715 | } |
| 5716 | break; |
| 5717 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5718 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5719 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5720 | case TypeCheckKind::kInterfaceCheck: { |
| 5721 | // 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] | 5722 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5723 | // cases. |
| 5724 | // |
| 5725 | // We cannot directly call the InstanceofNonTrivial runtime |
| 5726 | // entry point without resorting to a type checking slow path |
| 5727 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 5728 | // require to assign fixed registers for the inputs of this |
| 5729 | // HInstanceOf instruction (following the runtime calling |
| 5730 | // convention), which might be cluttered by the potential first |
| 5731 | // read barrier emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5732 | // |
| 5733 | // TODO: Introduce a new runtime entry point taking the object |
| 5734 | // to test (instead of its class) as argument, and let it deal |
| 5735 | // with the read barrier issues. This will let us refactor this |
| 5736 | // case of the `switch` code as it was previously (with a direct |
| 5737 | // call to the runtime not using a type checking slow path). |
| 5738 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5739 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5740 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5741 | /* is_fatal */ false); |
| 5742 | codegen_->AddSlowPath(slow_path); |
| 5743 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5744 | if (zero.IsLinked()) { |
| 5745 | __ jmp(&done); |
| 5746 | } |
| 5747 | break; |
| 5748 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5749 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5750 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5751 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5752 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5753 | __ xorl(out, out); |
| 5754 | } |
| 5755 | |
| 5756 | if (done.IsLinked()) { |
| 5757 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5758 | } |
| 5759 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5760 | if (slow_path != nullptr) { |
| 5761 | __ Bind(slow_path->GetExitLabel()); |
| 5762 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5763 | } |
| 5764 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5765 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5766 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5767 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5768 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5769 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5770 | case TypeCheckKind::kExactCheck: |
| 5771 | case TypeCheckKind::kAbstractClassCheck: |
| 5772 | case TypeCheckKind::kClassHierarchyCheck: |
| 5773 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5774 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 5775 | LocationSummary::kCallOnSlowPath : |
| 5776 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5777 | break; |
| 5778 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5779 | case TypeCheckKind::kUnresolvedCheck: |
| 5780 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5781 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5782 | break; |
| 5783 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5784 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 5785 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5786 | locations->SetInAt(1, Location::Any()); |
| 5787 | // Note that TypeCheckSlowPathX86_64 uses this "temp" register too. |
| 5788 | locations->AddTemp(Location::RequiresRegister()); |
| 5789 | // When read barriers are enabled, we need an additional temporary |
| 5790 | // register for some cases. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5791 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5792 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5793 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5794 | } |
| 5795 | |
| 5796 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5797 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5798 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5799 | Location obj_loc = locations->InAt(0); |
| 5800 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5801 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5802 | Location temp_loc = locations->GetTemp(0); |
| 5803 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5804 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5805 | locations->GetTemp(1) : |
| 5806 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5807 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5808 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5809 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5810 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5811 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5812 | bool is_type_check_slow_path_fatal = |
| 5813 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 5814 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5815 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5816 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 5817 | !instruction->CanThrowIntoCatchBlock(); |
| 5818 | SlowPathCode* type_check_slow_path = |
| 5819 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5820 | is_type_check_slow_path_fatal); |
| 5821 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5822 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5823 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5824 | case TypeCheckKind::kExactCheck: |
| 5825 | case TypeCheckKind::kArrayCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5826 | NearLabel done; |
| 5827 | // Avoid null check if we know obj is not null. |
| 5828 | if (instruction->MustDoNullCheck()) { |
| 5829 | __ testl(obj, obj); |
| 5830 | __ j(kEqual, &done); |
| 5831 | } |
| 5832 | |
| 5833 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5834 | GenerateReferenceLoadTwoRegisters( |
| 5835 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
| 5836 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5837 | if (cls.IsRegister()) { |
| 5838 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5839 | } else { |
| 5840 | DCHECK(cls.IsStackSlot()) << cls; |
| 5841 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5842 | } |
| 5843 | // Jump to slow path for throwing the exception or doing a |
| 5844 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5845 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5846 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5847 | break; |
| 5848 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5849 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5850 | case TypeCheckKind::kAbstractClassCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5851 | NearLabel done; |
| 5852 | // Avoid null check if we know obj is not null. |
| 5853 | if (instruction->MustDoNullCheck()) { |
| 5854 | __ testl(obj, obj); |
| 5855 | __ j(kEqual, &done); |
| 5856 | } |
| 5857 | |
| 5858 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5859 | GenerateReferenceLoadTwoRegisters( |
| 5860 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
| 5861 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5862 | // If the class is abstract, we eagerly fetch the super class of the |
| 5863 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5864 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5865 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5866 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5867 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5868 | |
| 5869 | // If the class reference currently in `temp` is not null, jump |
| 5870 | // to the `compare_classes` label to compare it with the checked |
| 5871 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5872 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5873 | __ j(kNotEqual, &compare_classes); |
| 5874 | // Otherwise, jump to the slow path to throw the exception. |
| 5875 | // |
| 5876 | // But before, move back the object's class into `temp` before |
| 5877 | // going into the slow path, as it has been overwritten in the |
| 5878 | // meantime. |
| 5879 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5880 | GenerateReferenceLoadTwoRegisters( |
| 5881 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5882 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 5883 | |
| 5884 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5885 | if (cls.IsRegister()) { |
| 5886 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5887 | } else { |
| 5888 | DCHECK(cls.IsStackSlot()) << cls; |
| 5889 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5890 | } |
| 5891 | __ j(kNotEqual, &loop); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5892 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5893 | break; |
| 5894 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5895 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5896 | case TypeCheckKind::kClassHierarchyCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5897 | NearLabel done; |
| 5898 | // Avoid null check if we know obj is not null. |
| 5899 | if (instruction->MustDoNullCheck()) { |
| 5900 | __ testl(obj, obj); |
| 5901 | __ j(kEqual, &done); |
| 5902 | } |
| 5903 | |
| 5904 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5905 | GenerateReferenceLoadTwoRegisters( |
| 5906 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
| 5907 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5908 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5909 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5910 | __ Bind(&loop); |
| 5911 | if (cls.IsRegister()) { |
| 5912 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5913 | } else { |
| 5914 | DCHECK(cls.IsStackSlot()) << cls; |
| 5915 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5916 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5917 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5918 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5919 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5920 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5921 | |
| 5922 | // If the class reference currently in `temp` is not null, jump |
| 5923 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5924 | __ testl(temp, temp); |
| 5925 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5926 | // Otherwise, jump to the slow path to throw the exception. |
| 5927 | // |
| 5928 | // But before, move back the object's class into `temp` before |
| 5929 | // going into the slow path, as it has been overwritten in the |
| 5930 | // meantime. |
| 5931 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5932 | GenerateReferenceLoadTwoRegisters( |
| 5933 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5934 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5935 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5936 | break; |
| 5937 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5938 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5939 | case TypeCheckKind::kArrayObjectCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5940 | // We cannot use a NearLabel here, as its range might be too |
| 5941 | // short in some cases when read barriers are enabled. This has |
| 5942 | // been observed for instance when the code emitted for this |
| 5943 | // case uses high x86-64 registers (R8-R15). |
| 5944 | Label done; |
| 5945 | // Avoid null check if we know obj is not null. |
| 5946 | if (instruction->MustDoNullCheck()) { |
| 5947 | __ testl(obj, obj); |
| 5948 | __ j(kEqual, &done); |
| 5949 | } |
| 5950 | |
| 5951 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5952 | GenerateReferenceLoadTwoRegisters( |
| 5953 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
| 5954 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5955 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5956 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5957 | if (cls.IsRegister()) { |
| 5958 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5959 | } else { |
| 5960 | DCHECK(cls.IsStackSlot()) << cls; |
| 5961 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5962 | } |
| 5963 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5964 | |
| 5965 | // 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] | 5966 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5967 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5968 | |
| 5969 | // If the component type is not null (i.e. the object is indeed |
| 5970 | // an array), jump to label `check_non_primitive_component_type` |
| 5971 | // to further check that this component type is not a primitive |
| 5972 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5973 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5974 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 5975 | // Otherwise, jump to the slow path to throw the exception. |
| 5976 | // |
| 5977 | // But before, move back the object's class into `temp` before |
| 5978 | // going into the slow path, as it has been overwritten in the |
| 5979 | // meantime. |
| 5980 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5981 | GenerateReferenceLoadTwoRegisters( |
| 5982 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5983 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 5984 | |
| 5985 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5986 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5987 | __ j(kEqual, &done); |
| 5988 | // Same comment as above regarding `temp` and the slow path. |
| 5989 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5990 | GenerateReferenceLoadTwoRegisters( |
| 5991 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5992 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5993 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5994 | break; |
| 5995 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5996 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5997 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5998 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5999 | NearLabel done; |
| 6000 | // Avoid null check if we know obj is not null. |
| 6001 | if (instruction->MustDoNullCheck()) { |
| 6002 | __ testl(obj, obj); |
| 6003 | __ j(kEqual, &done); |
| 6004 | } |
| 6005 | |
| 6006 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6007 | GenerateReferenceLoadTwoRegisters( |
| 6008 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
| 6009 | |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6010 | // We always go into the type check slow path for the unresolved |
| 6011 | // and interface check cases. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6012 | // |
| 6013 | // We cannot directly call the CheckCast runtime entry point |
| 6014 | // without resorting to a type checking slow path here (i.e. by |
| 6015 | // calling InvokeRuntime directly), as it would require to |
| 6016 | // assign fixed registers for the inputs of this HInstanceOf |
| 6017 | // instruction (following the runtime calling convention), which |
| 6018 | // might be cluttered by the potential first read barrier |
| 6019 | // emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6020 | // |
| 6021 | // TODO: Introduce a new runtime entry point taking the object |
| 6022 | // to test (instead of its class) as argument, and let it deal |
| 6023 | // with the read barrier issues. This will let us refactor this |
| 6024 | // case of the `switch` code as it was previously (with a direct |
| 6025 | // call to the runtime not using a type checking slow path). |
| 6026 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6027 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6028 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6029 | break; |
| 6030 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6031 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6032 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6033 | } |
| 6034 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6035 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6036 | LocationSummary* locations = |
| 6037 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 6038 | InvokeRuntimeCallingConvention calling_convention; |
| 6039 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6040 | } |
| 6041 | |
| 6042 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6043 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 6044 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 6045 | instruction, |
| 6046 | instruction->GetDexPc(), |
| 6047 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6048 | if (instruction->IsEnter()) { |
| 6049 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6050 | } else { |
| 6051 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6052 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6053 | } |
| 6054 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6055 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6056 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6057 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6058 | |
| 6059 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6060 | LocationSummary* locations = |
| 6061 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6062 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6063 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6064 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6065 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6066 | locations->SetOut(Location::SameAsFirstInput()); |
| 6067 | } |
| 6068 | |
| 6069 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 6070 | HandleBitwiseOperation(instruction); |
| 6071 | } |
| 6072 | |
| 6073 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 6074 | HandleBitwiseOperation(instruction); |
| 6075 | } |
| 6076 | |
| 6077 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 6078 | HandleBitwiseOperation(instruction); |
| 6079 | } |
| 6080 | |
| 6081 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6082 | LocationSummary* locations = instruction->GetLocations(); |
| 6083 | Location first = locations->InAt(0); |
| 6084 | Location second = locations->InAt(1); |
| 6085 | DCHECK(first.Equals(locations->Out())); |
| 6086 | |
| 6087 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6088 | if (second.IsRegister()) { |
| 6089 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6090 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6091 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6092 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6093 | } else { |
| 6094 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6095 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6096 | } |
| 6097 | } else if (second.IsConstant()) { |
| 6098 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 6099 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6100 | __ andl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6101 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6102 | __ orl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6103 | } else { |
| 6104 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6105 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6106 | } |
| 6107 | } else { |
| 6108 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 6109 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6110 | __ andl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6111 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6112 | __ orl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6113 | } else { |
| 6114 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6115 | __ xorl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6116 | } |
| 6117 | } |
| 6118 | } else { |
| 6119 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6120 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 6121 | bool second_is_constant = false; |
| 6122 | int64_t value = 0; |
| 6123 | if (second.IsConstant()) { |
| 6124 | second_is_constant = true; |
| 6125 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6126 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6127 | bool is_int32_value = IsInt<32>(value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6128 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6129 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6130 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6131 | if (is_int32_value) { |
| 6132 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6133 | } else { |
| 6134 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6135 | } |
| 6136 | } else if (second.IsDoubleStackSlot()) { |
| 6137 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6138 | } else { |
| 6139 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 6140 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6141 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6142 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6143 | if (is_int32_value) { |
| 6144 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6145 | } else { |
| 6146 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6147 | } |
| 6148 | } else if (second.IsDoubleStackSlot()) { |
| 6149 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6150 | } else { |
| 6151 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 6152 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6153 | } else { |
| 6154 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6155 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6156 | if (is_int32_value) { |
| 6157 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6158 | } else { |
| 6159 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6160 | } |
| 6161 | } else if (second.IsDoubleStackSlot()) { |
| 6162 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6163 | } else { |
| 6164 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 6165 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6166 | } |
| 6167 | } |
| 6168 | } |
| 6169 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6170 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6171 | Location out, |
| 6172 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6173 | Location maybe_temp) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6174 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6175 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6176 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6177 | if (kUseBakerReadBarrier) { |
| 6178 | // Load with fast path based Baker's read barrier. |
| 6179 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6180 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6181 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6182 | } else { |
| 6183 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6184 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6185 | // in the following move operation, as we will need it for the |
| 6186 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6187 | __ movl(maybe_temp.AsRegister<CpuRegister>(), out_reg); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6188 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6189 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6190 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6191 | } |
| 6192 | } else { |
| 6193 | // Plain load with no read barrier. |
| 6194 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6195 | __ movl(out_reg, Address(out_reg, offset)); |
| 6196 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6197 | } |
| 6198 | } |
| 6199 | |
| 6200 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6201 | Location out, |
| 6202 | Location obj, |
| 6203 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6204 | Location maybe_temp) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6205 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6206 | CpuRegister obj_reg = obj.AsRegister<CpuRegister>(); |
| 6207 | if (kEmitCompilerReadBarrier) { |
| 6208 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6209 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6210 | // Load with fast path based Baker's read barrier. |
| 6211 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6212 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6213 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6214 | } else { |
| 6215 | // Load with slow path based read barrier. |
| 6216 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6217 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6218 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6219 | } |
| 6220 | } else { |
| 6221 | // Plain load with no read barrier. |
| 6222 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6223 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6224 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6225 | } |
| 6226 | } |
| 6227 | |
| 6228 | void InstructionCodeGeneratorX86_64::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6229 | Location root, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6230 | const Address& address, |
| 6231 | Label* fixup_label) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6232 | CpuRegister root_reg = root.AsRegister<CpuRegister>(); |
| 6233 | if (kEmitCompilerReadBarrier) { |
| 6234 | if (kUseBakerReadBarrier) { |
| 6235 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6236 | // Baker's read barrier are used: |
| 6237 | // |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6238 | // root = *address; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6239 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6240 | // root = ReadBarrier::Mark(root) |
| 6241 | // } |
| 6242 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6243 | // /* GcRoot<mirror::Object> */ root = *address |
| 6244 | __ movl(root_reg, address); |
| 6245 | if (fixup_label != nullptr) { |
| 6246 | __ Bind(fixup_label); |
| 6247 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6248 | static_assert( |
| 6249 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6250 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6251 | "have different sizes."); |
| 6252 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6253 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6254 | "have different sizes."); |
| 6255 | |
| 6256 | // Slow path used to mark the GC root `root`. |
| 6257 | SlowPathCode* slow_path = |
| 6258 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64(instruction, root, root); |
| 6259 | codegen_->AddSlowPath(slow_path); |
| 6260 | |
| 6261 | __ gs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86_64WordSize>().Int32Value(), |
| 6262 | /* no_rip */ true), |
| 6263 | Immediate(0)); |
| 6264 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6265 | __ Bind(slow_path->GetExitLabel()); |
| 6266 | } else { |
| 6267 | // GC root loaded through a slow path for read barriers other |
| 6268 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6269 | // /* GcRoot<mirror::Object>* */ root = address |
| 6270 | __ leaq(root_reg, address); |
| 6271 | if (fixup_label != nullptr) { |
| 6272 | __ Bind(fixup_label); |
| 6273 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6274 | // /* mirror::Object* */ root = root->Read() |
| 6275 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6276 | } |
| 6277 | } else { |
| 6278 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6279 | // /* GcRoot<mirror::Object> */ root = *address |
| 6280 | __ movl(root_reg, address); |
| 6281 | if (fixup_label != nullptr) { |
| 6282 | __ Bind(fixup_label); |
| 6283 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6284 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6285 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6286 | } |
| 6287 | } |
| 6288 | |
| 6289 | void CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6290 | Location ref, |
| 6291 | CpuRegister obj, |
| 6292 | uint32_t offset, |
| 6293 | Location temp, |
| 6294 | bool needs_null_check) { |
| 6295 | DCHECK(kEmitCompilerReadBarrier); |
| 6296 | DCHECK(kUseBakerReadBarrier); |
| 6297 | |
| 6298 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6299 | Address src(obj, offset); |
| 6300 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6301 | } |
| 6302 | |
| 6303 | void CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6304 | Location ref, |
| 6305 | CpuRegister obj, |
| 6306 | uint32_t data_offset, |
| 6307 | Location index, |
| 6308 | Location temp, |
| 6309 | bool needs_null_check) { |
| 6310 | DCHECK(kEmitCompilerReadBarrier); |
| 6311 | DCHECK(kUseBakerReadBarrier); |
| 6312 | |
| 6313 | // /* HeapReference<Object> */ ref = |
| 6314 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6315 | Address src = index.IsConstant() ? |
| 6316 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset) : |
| 6317 | Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset); |
| 6318 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6319 | } |
| 6320 | |
| 6321 | void CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6322 | Location ref, |
| 6323 | CpuRegister obj, |
| 6324 | const Address& src, |
| 6325 | Location temp, |
| 6326 | bool needs_null_check) { |
| 6327 | DCHECK(kEmitCompilerReadBarrier); |
| 6328 | DCHECK(kUseBakerReadBarrier); |
| 6329 | |
| 6330 | // In slow path based read barriers, the read barrier call is |
| 6331 | // inserted after the original load. However, in fast path based |
| 6332 | // Baker's read barriers, we need to perform the load of |
| 6333 | // mirror::Object::monitor_ *before* the original reference load. |
| 6334 | // This load-load ordering is required by the read barrier. |
| 6335 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6336 | // |
| 6337 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6338 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6339 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6340 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6341 | // if (is_gray) { |
| 6342 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6343 | // } |
| 6344 | // |
| 6345 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6346 | // slightly more complex as: |
| 6347 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6348 | // the high-bits of rb_state, which are expected to be all zeroes |
| 6349 | // (we use CodeGeneratorX86_64::GenerateMemoryBarrier instead |
| 6350 | // 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] | 6351 | // - it performs additional checks that we do not do here for |
| 6352 | // performance reasons. |
| 6353 | |
| 6354 | CpuRegister ref_reg = ref.AsRegister<CpuRegister>(); |
| 6355 | CpuRegister temp_reg = temp.AsRegister<CpuRegister>(); |
| 6356 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6357 | |
| 6358 | // /* int32_t */ monitor = obj->monitor_ |
| 6359 | __ movl(temp_reg, Address(obj, monitor_offset)); |
| 6360 | if (needs_null_check) { |
| 6361 | MaybeRecordImplicitNullCheck(instruction); |
| 6362 | } |
| 6363 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6364 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6365 | "art::LockWord and int32_t have different sizes."); |
| 6366 | // /* uint32_t */ rb_state = lock_word.ReadBarrierState() |
| 6367 | __ shrl(temp_reg, Immediate(LockWord::kReadBarrierStateShift)); |
| 6368 | __ andl(temp_reg, Immediate(LockWord::kReadBarrierStateMask)); |
| 6369 | static_assert( |
| 6370 | LockWord::kReadBarrierStateMask == ReadBarrier::rb_ptr_mask_, |
| 6371 | "art::LockWord::kReadBarrierStateMask is not equal to art::ReadBarrier::rb_ptr_mask_."); |
| 6372 | |
| 6373 | // Load fence to prevent load-load reordering. |
| 6374 | // Note that this is a no-op, thanks to the x86-64 memory model. |
| 6375 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6376 | |
| 6377 | // The actual reference load. |
| 6378 | // /* HeapReference<Object> */ ref = *src |
| 6379 | __ movl(ref_reg, src); |
| 6380 | |
| 6381 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6382 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6383 | |
| 6384 | // Slow path used to mark the object `ref` when it is gray. |
| 6385 | SlowPathCode* slow_path = |
| 6386 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64(instruction, ref, ref); |
| 6387 | AddSlowPath(slow_path); |
| 6388 | |
| 6389 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6390 | // ref = ReadBarrier::Mark(ref); |
| 6391 | __ cmpl(temp_reg, Immediate(ReadBarrier::gray_ptr_)); |
| 6392 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6393 | __ Bind(slow_path->GetExitLabel()); |
| 6394 | } |
| 6395 | |
| 6396 | void CodeGeneratorX86_64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6397 | Location out, |
| 6398 | Location ref, |
| 6399 | Location obj, |
| 6400 | uint32_t offset, |
| 6401 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6402 | DCHECK(kEmitCompilerReadBarrier); |
| 6403 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6404 | // Insert a slow path based read barrier *after* the reference load. |
| 6405 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6406 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6407 | // reference will be carried out by the runtime within the slow |
| 6408 | // path. |
| 6409 | // |
| 6410 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6411 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6412 | // not used by the artReadBarrierSlow entry point. |
| 6413 | // |
| 6414 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6415 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6416 | ReadBarrierForHeapReferenceSlowPathX86_64(instruction, out, ref, obj, offset, index); |
| 6417 | AddSlowPath(slow_path); |
| 6418 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6419 | __ jmp(slow_path->GetEntryLabel()); |
| 6420 | __ Bind(slow_path->GetExitLabel()); |
| 6421 | } |
| 6422 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6423 | void CodeGeneratorX86_64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6424 | Location out, |
| 6425 | Location ref, |
| 6426 | Location obj, |
| 6427 | uint32_t offset, |
| 6428 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6429 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6430 | // Baker's read barriers shall be handled by the fast path |
| 6431 | // (CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6432 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6433 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6434 | // by the runtime within the slow path. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6435 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6436 | } else if (kPoisonHeapReferences) { |
| 6437 | __ UnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 6438 | } |
| 6439 | } |
| 6440 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6441 | void CodeGeneratorX86_64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6442 | Location out, |
| 6443 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6444 | DCHECK(kEmitCompilerReadBarrier); |
| 6445 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6446 | // Insert a slow path based read barrier *after* the GC root load. |
| 6447 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6448 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6449 | // not need to do anything special for this here. |
| 6450 | SlowPathCode* slow_path = |
| 6451 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86_64(instruction, out, root); |
| 6452 | AddSlowPath(slow_path); |
| 6453 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6454 | __ jmp(slow_path->GetEntryLabel()); |
| 6455 | __ Bind(slow_path->GetExitLabel()); |
| 6456 | } |
| 6457 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6458 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6459 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6460 | LOG(FATAL) << "Unreachable"; |
| 6461 | } |
| 6462 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6463 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6464 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6465 | LOG(FATAL) << "Unreachable"; |
| 6466 | } |
| 6467 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6468 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6469 | void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6470 | LocationSummary* locations = |
| 6471 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6472 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6473 | locations->AddTemp(Location::RequiresRegister()); |
| 6474 | locations->AddTemp(Location::RequiresRegister()); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6475 | } |
| 6476 | |
| 6477 | void InstructionCodeGeneratorX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6478 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6479 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6480 | LocationSummary* locations = switch_instr->GetLocations(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6481 | CpuRegister value_reg_in = locations->InAt(0).AsRegister<CpuRegister>(); |
| 6482 | CpuRegister temp_reg = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 6483 | CpuRegister base_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6484 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6485 | |
| 6486 | // Should we generate smaller inline compare/jumps? |
| 6487 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 6488 | // Figure out the correct compare values and jump conditions. |
| 6489 | // Handle the first compare/branch as a special case because it might |
| 6490 | // jump to the default case. |
| 6491 | DCHECK_GT(num_entries, 2u); |
| 6492 | Condition first_condition; |
| 6493 | uint32_t index; |
| 6494 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 6495 | if (lower_bound != 0) { |
| 6496 | first_condition = kLess; |
| 6497 | __ cmpl(value_reg_in, Immediate(lower_bound)); |
| 6498 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 6499 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
| 6500 | |
| 6501 | index = 1; |
| 6502 | } else { |
| 6503 | // Handle all the compare/jumps below. |
| 6504 | first_condition = kBelow; |
| 6505 | index = 0; |
| 6506 | } |
| 6507 | |
| 6508 | // Handle the rest of the compare/jumps. |
| 6509 | for (; index + 1 < num_entries; index += 2) { |
| 6510 | int32_t compare_to_value = lower_bound + index + 1; |
| 6511 | __ cmpl(value_reg_in, Immediate(compare_to_value)); |
| 6512 | // Jump to successors[index] if value < case_value[index]. |
| 6513 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 6514 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 6515 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 6516 | } |
| 6517 | |
| 6518 | if (index != num_entries) { |
| 6519 | // There are an odd number of entries. Handle the last one. |
| 6520 | DCHECK_EQ(index + 1, num_entries); |
Nicolas Geoffray | 6ce0173 | 2015-12-30 14:10:13 +0000 | [diff] [blame] | 6521 | __ cmpl(value_reg_in, Immediate(static_cast<int32_t>(lower_bound + index))); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6522 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
| 6523 | } |
| 6524 | |
| 6525 | // And the default for any other value. |
| 6526 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6527 | __ jmp(codegen_->GetLabelOf(default_block)); |
| 6528 | } |
| 6529 | return; |
| 6530 | } |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6531 | |
| 6532 | // Remove the bias, if needed. |
| 6533 | Register value_reg_out = value_reg_in.AsRegister(); |
| 6534 | if (lower_bound != 0) { |
| 6535 | __ leal(temp_reg, Address(value_reg_in, -lower_bound)); |
| 6536 | value_reg_out = temp_reg.AsRegister(); |
| 6537 | } |
| 6538 | CpuRegister value_reg(value_reg_out); |
| 6539 | |
| 6540 | // Is the value in range? |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6541 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 6542 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6543 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6544 | // We are in the range of the table. |
| 6545 | // Load the address of the jump table in the constant area. |
| 6546 | __ leaq(base_reg, codegen_->LiteralCaseTable(switch_instr)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6547 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6548 | // Load the (signed) offset from the jump table. |
| 6549 | __ movsxd(temp_reg, Address(base_reg, value_reg, TIMES_4, 0)); |
| 6550 | |
| 6551 | // Add the offset to the address of the table base. |
| 6552 | __ addq(temp_reg, base_reg); |
| 6553 | |
| 6554 | // And jump. |
| 6555 | __ jmp(temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6556 | } |
| 6557 | |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6558 | void CodeGeneratorX86_64::Load32BitValue(CpuRegister dest, int32_t value) { |
| 6559 | if (value == 0) { |
| 6560 | __ xorl(dest, dest); |
| 6561 | } else { |
| 6562 | __ movl(dest, Immediate(value)); |
| 6563 | } |
| 6564 | } |
| 6565 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6566 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 6567 | if (value == 0) { |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6568 | // Clears upper bits too. |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6569 | __ xorl(dest, dest); |
Vladimir Marko | ed00978 | 2016-02-22 16:54:39 +0000 | [diff] [blame] | 6570 | } else if (IsUint<32>(value)) { |
| 6571 | // 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] | 6572 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 6573 | } else { |
| 6574 | __ movq(dest, Immediate(value)); |
| 6575 | } |
| 6576 | } |
| 6577 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 6578 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, int32_t value) { |
| 6579 | if (value == 0) { |
| 6580 | __ xorps(dest, dest); |
| 6581 | } else { |
| 6582 | __ movss(dest, LiteralInt32Address(value)); |
| 6583 | } |
| 6584 | } |
| 6585 | |
| 6586 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, int64_t value) { |
| 6587 | if (value == 0) { |
| 6588 | __ xorpd(dest, dest); |
| 6589 | } else { |
| 6590 | __ movsd(dest, LiteralInt64Address(value)); |
| 6591 | } |
| 6592 | } |
| 6593 | |
| 6594 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, float value) { |
| 6595 | Load32BitValue(dest, bit_cast<int32_t, float>(value)); |
| 6596 | } |
| 6597 | |
| 6598 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, double value) { |
| 6599 | Load64BitValue(dest, bit_cast<int64_t, double>(value)); |
| 6600 | } |
| 6601 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 6602 | void CodeGeneratorX86_64::Compare32BitValue(CpuRegister dest, int32_t value) { |
| 6603 | if (value == 0) { |
| 6604 | __ testl(dest, dest); |
| 6605 | } else { |
| 6606 | __ cmpl(dest, Immediate(value)); |
| 6607 | } |
| 6608 | } |
| 6609 | |
| 6610 | void CodeGeneratorX86_64::Compare64BitValue(CpuRegister dest, int64_t value) { |
| 6611 | if (IsInt<32>(value)) { |
| 6612 | if (value == 0) { |
| 6613 | __ testq(dest, dest); |
| 6614 | } else { |
| 6615 | __ cmpq(dest, Immediate(static_cast<int32_t>(value))); |
| 6616 | } |
| 6617 | } else { |
| 6618 | // Value won't fit in an int. |
| 6619 | __ cmpq(dest, LiteralInt64Address(value)); |
| 6620 | } |
| 6621 | } |
| 6622 | |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 6623 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 6624 | DCHECK(dest.IsDoubleStackSlot()); |
| 6625 | if (IsInt<32>(value)) { |
| 6626 | // Can move directly as an int32 constant. |
| 6627 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 6628 | Immediate(static_cast<int32_t>(value))); |
| 6629 | } else { |
| 6630 | Load64BitValue(CpuRegister(TMP), value); |
| 6631 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 6632 | } |
| 6633 | } |
| 6634 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6635 | /** |
| 6636 | * Class to handle late fixup of offsets into constant area. |
| 6637 | */ |
| 6638 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| 6639 | public: |
| 6640 | RIPFixup(CodeGeneratorX86_64& codegen, size_t offset) |
| 6641 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 6642 | |
| 6643 | protected: |
| 6644 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 6645 | |
| 6646 | CodeGeneratorX86_64* codegen_; |
| 6647 | |
| 6648 | private: |
| 6649 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 6650 | // Patch the correct offset for the instruction. We use the address of the |
| 6651 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 6652 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 6653 | int32_t relative_position = constant_offset - pos; |
| 6654 | |
| 6655 | // Patch in the right value. |
| 6656 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 6657 | } |
| 6658 | |
| 6659 | // Location in constant area that the fixup refers to. |
| 6660 | size_t offset_into_constant_area_; |
| 6661 | }; |
| 6662 | |
| 6663 | /** |
| 6664 | t * Class to handle late fixup of offsets to a jump table that will be created in the |
| 6665 | * constant area. |
| 6666 | */ |
| 6667 | class JumpTableRIPFixup : public RIPFixup { |
| 6668 | public: |
| 6669 | JumpTableRIPFixup(CodeGeneratorX86_64& codegen, HPackedSwitch* switch_instr) |
| 6670 | : RIPFixup(codegen, -1), switch_instr_(switch_instr) {} |
| 6671 | |
| 6672 | void CreateJumpTable() { |
| 6673 | X86_64Assembler* assembler = codegen_->GetAssembler(); |
| 6674 | |
| 6675 | // Ensure that the reference to the jump table has the correct offset. |
| 6676 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 6677 | SetOffset(offset_in_constant_table); |
| 6678 | |
| 6679 | // Compute the offset from the start of the function to this jump table. |
| 6680 | const int32_t current_table_offset = assembler->CodeSize() + offset_in_constant_table; |
| 6681 | |
| 6682 | // Populate the jump table with the correct values for the jump table. |
| 6683 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 6684 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 6685 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 6686 | // The value that we want is the target offset - the position of the table. |
| 6687 | for (int32_t i = 0; i < num_entries; i++) { |
| 6688 | HBasicBlock* b = successors[i]; |
| 6689 | Label* l = codegen_->GetLabelOf(b); |
| 6690 | DCHECK(l->IsBound()); |
| 6691 | int32_t offset_to_block = l->Position() - current_table_offset; |
| 6692 | assembler->AppendInt32(offset_to_block); |
| 6693 | } |
| 6694 | } |
| 6695 | |
| 6696 | private: |
| 6697 | const HPackedSwitch* switch_instr_; |
| 6698 | }; |
| 6699 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6700 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 6701 | // Generate the constant area if needed. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 6702 | X86_64Assembler* assembler = GetAssembler(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6703 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 6704 | // 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] | 6705 | assembler->Align(4, 0); |
| 6706 | constant_area_start_ = assembler->CodeSize(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6707 | |
| 6708 | // Populate any jump tables. |
| 6709 | for (auto jump_table : fixups_to_jump_tables_) { |
| 6710 | jump_table->CreateJumpTable(); |
| 6711 | } |
| 6712 | |
| 6713 | // And now add the constant area to the generated code. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 6714 | assembler->AddConstantArea(); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6715 | } |
| 6716 | |
| 6717 | // And finish up. |
| 6718 | CodeGenerator::Finalize(allocator); |
| 6719 | } |
| 6720 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6721 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
| 6722 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 6723 | return Address::RIP(fixup); |
| 6724 | } |
| 6725 | |
| 6726 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
| 6727 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 6728 | return Address::RIP(fixup); |
| 6729 | } |
| 6730 | |
| 6731 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
| 6732 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 6733 | return Address::RIP(fixup); |
| 6734 | } |
| 6735 | |
| 6736 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
| 6737 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 6738 | return Address::RIP(fixup); |
| 6739 | } |
| 6740 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6741 | // TODO: trg as memory. |
| 6742 | void CodeGeneratorX86_64::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 6743 | if (!trg.IsValid()) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6744 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6745 | return; |
| 6746 | } |
| 6747 | |
| 6748 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 6749 | |
| 6750 | Location return_loc = InvokeDexCallingConventionVisitorX86_64().GetReturnLocation(type); |
| 6751 | if (trg.Equals(return_loc)) { |
| 6752 | return; |
| 6753 | } |
| 6754 | |
| 6755 | // Let the parallel move resolver take care of all of this. |
| 6756 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 6757 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 6758 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 6759 | } |
| 6760 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6761 | Address CodeGeneratorX86_64::LiteralCaseTable(HPackedSwitch* switch_instr) { |
| 6762 | // Create a fixup to be used to create and address the jump table. |
| 6763 | JumpTableRIPFixup* table_fixup = |
| 6764 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 6765 | |
| 6766 | // We have to populate the jump tables. |
| 6767 | fixups_to_jump_tables_.push_back(table_fixup); |
| 6768 | return Address::RIP(table_fixup); |
| 6769 | } |
| 6770 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 6771 | void CodeGeneratorX86_64::MoveInt64ToAddress(const Address& addr_low, |
| 6772 | const Address& addr_high, |
| 6773 | int64_t v, |
| 6774 | HInstruction* instruction) { |
| 6775 | if (IsInt<32>(v)) { |
| 6776 | int32_t v_32 = v; |
| 6777 | __ movq(addr_low, Immediate(v_32)); |
| 6778 | MaybeRecordImplicitNullCheck(instruction); |
| 6779 | } else { |
| 6780 | // Didn't fit in a register. Do it in pieces. |
| 6781 | int32_t low_v = Low32Bits(v); |
| 6782 | int32_t high_v = High32Bits(v); |
| 6783 | __ movl(addr_low, Immediate(low_v)); |
| 6784 | MaybeRecordImplicitNullCheck(instruction); |
| 6785 | __ movl(addr_high, Immediate(high_v)); |
| 6786 | } |
| 6787 | } |
| 6788 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6789 | #undef __ |
| 6790 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 6791 | } // namespace x86_64 |
| 6792 | } // namespace art |