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 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 767 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 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. |
| 770 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 771 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 772 | switch (invoke->GetMethodLoadKind()) { |
| 773 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 774 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | 7f59d59 | 2015-12-29 16:20:52 +0000 | [diff] [blame] | 775 | __ gs()->movq(temp.AsRegister<CpuRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 776 | Address::Absolute(invoke->GetStringInitOffset(), /* no_rip */ true)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 777 | break; |
| 778 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 779 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 780 | break; |
| 781 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 782 | __ movq(temp.AsRegister<CpuRegister>(), Immediate(invoke->GetMethodAddress())); |
| 783 | break; |
| 784 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 785 | __ movl(temp.AsRegister<CpuRegister>(), Immediate(0)); // Placeholder. |
| 786 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 787 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 788 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 789 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 790 | __ movq(temp.AsRegister<CpuRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 791 | Address::Absolute(kDummy32BitOffset, /* no_rip */ false)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 792 | // Bind a new fixup label at the end of the "movl" insn. |
| 793 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
| 794 | __ Bind(NewPcRelativeDexCacheArrayPatch(*invoke->GetTargetMethod().dex_file, offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 795 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 796 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 797 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 798 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 799 | Register method_reg; |
| 800 | CpuRegister reg = temp.AsRegister<CpuRegister>(); |
| 801 | if (current_method.IsRegister()) { |
| 802 | method_reg = current_method.AsRegister<Register>(); |
| 803 | } else { |
| 804 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 805 | DCHECK(!current_method.IsValid()); |
| 806 | method_reg = reg.AsRegister(); |
| 807 | __ movq(reg, Address(CpuRegister(RSP), kCurrentMethodStackOffset)); |
| 808 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 809 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 810 | __ movq(reg, |
| 811 | Address(CpuRegister(method_reg), |
| 812 | ArtMethod::DexCacheResolvedMethodsOffset(kX86_64PointerSize).SizeValue())); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 813 | // temp = temp[index_in_cache]; |
| 814 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 815 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 816 | __ movq(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 817 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 818 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | switch (invoke->GetCodePtrLocation()) { |
| 822 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 823 | __ call(&frame_entry_label_); |
| 824 | break; |
| 825 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 826 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 827 | Label* label = &relative_call_patches_.back().label; |
| 828 | __ call(label); // Bind to the patch label, override at link time. |
| 829 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 830 | break; |
| 831 | } |
| 832 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 833 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 834 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 835 | LOG(FATAL) << "Unsupported"; |
| 836 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 837 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 838 | // (callee_method + offset_of_quick_compiled_code)() |
| 839 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 840 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 841 | kX86_64WordSize).SizeValue())); |
| 842 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 843 | } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 844 | |
| 845 | DCHECK(!IsLeafMethod()); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 846 | } |
| 847 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 848 | void CodeGeneratorX86_64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 849 | CpuRegister temp = temp_in.AsRegister<CpuRegister>(); |
| 850 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 851 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 852 | |
| 853 | // Use the calling convention instead of the location of the receiver, as |
| 854 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 855 | // slow path, the arguments have been moved to the right place, so here we are |
| 856 | // guaranteed that the receiver is the first register of the calling convention. |
| 857 | InvokeDexCallingConvention calling_convention; |
| 858 | Register receiver = calling_convention.GetRegisterAt(0); |
| 859 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 860 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 861 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 862 | __ movl(temp, Address(CpuRegister(receiver), class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 863 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 864 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 865 | // emit a read barrier for the previous class reference load. |
| 866 | // However this is not required in practice, as this is an |
| 867 | // intermediate/temporary reference and because the current |
| 868 | // concurrent copying collector keeps the from-space memory |
| 869 | // intact/accessible until the end of the marking phase (the |
| 870 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 871 | __ MaybeUnpoisonHeapReference(temp); |
| 872 | // temp = temp->GetMethodAt(method_offset); |
| 873 | __ movq(temp, Address(temp, method_offset)); |
| 874 | // call temp->GetEntryPoint(); |
| 875 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 876 | kX86_64WordSize).SizeValue())); |
| 877 | } |
| 878 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 879 | void CodeGeneratorX86_64::RecordSimplePatch() { |
| 880 | if (GetCompilerOptions().GetIncludePatchInformation()) { |
| 881 | simple_patches_.emplace_back(); |
| 882 | __ Bind(&simple_patches_.back()); |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | void CodeGeneratorX86_64::RecordStringPatch(HLoadString* load_string) { |
| 887 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex()); |
| 888 | __ Bind(&string_patches_.back().label); |
| 889 | } |
| 890 | |
| 891 | Label* CodeGeneratorX86_64::NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, |
| 892 | uint32_t element_offset) { |
| 893 | // Add a patch entry and return the label. |
| 894 | pc_relative_dex_cache_patches_.emplace_back(dex_file, element_offset); |
| 895 | return &pc_relative_dex_cache_patches_.back().label; |
| 896 | } |
| 897 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 898 | void CodeGeneratorX86_64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 899 | DCHECK(linker_patches->empty()); |
| 900 | size_t size = |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 901 | method_patches_.size() + |
| 902 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 903 | pc_relative_dex_cache_patches_.size() + |
| 904 | simple_patches_.size() + |
| 905 | string_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 906 | linker_patches->reserve(size); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 907 | // The label points to the end of the "movl" insn but the literal offset for method |
| 908 | // patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 909 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 910 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 911 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 912 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 913 | info.target_method.dex_file, |
| 914 | info.target_method.dex_method_index)); |
| 915 | } |
| 916 | for (const MethodPatchInfo<Label>& info : relative_call_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::RelativeCodePatch(literal_offset, |
| 919 | info.target_method.dex_file, |
| 920 | info.target_method.dex_method_index)); |
| 921 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 922 | for (const PcRelativeDexCacheAccessInfo& info : pc_relative_dex_cache_patches_) { |
| 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::DexCacheArrayPatch(literal_offset, |
| 925 | &info.target_dex_file, |
| 926 | info.label.Position(), |
| 927 | info.element_offset)); |
| 928 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 929 | for (const Label& label : simple_patches_) { |
| 930 | uint32_t literal_offset = label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 931 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 932 | } |
| 933 | for (const StringPatchInfo<Label>& info : string_patches_) { |
| 934 | // These are always PC-relative, see GetSupportedLoadStringKind(). |
| 935 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 936 | linker_patches->push_back(LinkerPatch::RelativeStringPatch(literal_offset, |
| 937 | &info.dex_file, |
| 938 | info.label.Position(), |
| 939 | info.string_index)); |
| 940 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 941 | } |
| 942 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 943 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 944 | stream << Register(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 948 | stream << FloatRegister(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 949 | } |
| 950 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 951 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 952 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 953 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 954 | } |
| 955 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 956 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 957 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 958 | return kX86_64WordSize; |
| 959 | } |
| 960 | |
| 961 | size_t CodeGeneratorX86_64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 962 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 963 | return kX86_64WordSize; |
| 964 | } |
| 965 | |
| 966 | size_t CodeGeneratorX86_64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 967 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 968 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 969 | } |
| 970 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 971 | void CodeGeneratorX86_64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 972 | HInstruction* instruction, |
| 973 | uint32_t dex_pc, |
| 974 | SlowPathCode* slow_path) { |
| 975 | InvokeRuntime(GetThreadOffset<kX86_64WordSize>(entrypoint).Int32Value(), |
| 976 | instruction, |
| 977 | dex_pc, |
| 978 | slow_path); |
| 979 | } |
| 980 | |
| 981 | void CodeGeneratorX86_64::InvokeRuntime(int32_t entry_point_offset, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 982 | HInstruction* instruction, |
| 983 | uint32_t dex_pc, |
| 984 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 985 | ValidateInvokeRuntime(instruction, slow_path); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 986 | __ gs()->call(Address::Absolute(entry_point_offset, /* no_rip */ true)); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 987 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 988 | } |
| 989 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 990 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 991 | // Use a fake return address register to mimic Quick. |
| 992 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 993 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 994 | const X86_64InstructionSetFeatures& isa_features, |
| 995 | const CompilerOptions& compiler_options, |
| 996 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 997 | : CodeGenerator(graph, |
| 998 | kNumberOfCpuRegisters, |
| 999 | kNumberOfFloatRegisters, |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1000 | kNumberOfCpuRegisterPairs, |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1001 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 1002 | arraysize(kCoreCalleeSaves)) |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1003 | | (1 << kFakeReturnRegister), |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 1004 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 1005 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1006 | compiler_options, |
| 1007 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1008 | block_labels_(nullptr), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1009 | location_builder_(graph, this), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1010 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1011 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1012 | assembler_(graph->GetArena()), |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 1013 | isa_features_(isa_features), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 1014 | constant_area_start_(0), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 1015 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1016 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1017 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1018 | simple_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 1019 | string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 1020 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1021 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 1022 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1023 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 1024 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 1025 | CodeGeneratorX86_64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1026 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1027 | assembler_(codegen->GetAssembler()), |
| 1028 | codegen_(codegen) {} |
| 1029 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1030 | void CodeGeneratorX86_64::SetupBlockedRegisters() const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1031 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1032 | blocked_core_registers_[RSP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1033 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1034 | // Block the register used as TMP. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1035 | blocked_core_registers_[TMP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1036 | } |
| 1037 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1038 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1039 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1040 | } |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1041 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1042 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1043 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1044 | } |
| 1045 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1046 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1047 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1048 | __ Bind(&frame_entry_label_); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1049 | bool skip_overflow_check = IsLeafMethod() |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 1050 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1051 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1052 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1053 | if (!skip_overflow_check) { |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1054 | __ testq(CpuRegister(RAX), Address( |
| 1055 | CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1056 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1057 | } |
Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 1058 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1059 | if (HasEmptyFrame()) { |
| 1060 | return; |
| 1061 | } |
| 1062 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1063 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1064 | Register reg = kCoreCalleeSaves[i]; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1065 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1066 | __ pushq(CpuRegister(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1067 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 1068 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1069 | } |
| 1070 | } |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1071 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1072 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1073 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 1074 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1075 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1076 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1077 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1078 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1079 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1080 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1081 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 1082 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1083 | } |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1084 | } |
| 1085 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1086 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1087 | CpuRegister(kMethodRegisterArgument)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | void CodeGeneratorX86_64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1091 | __ cfi().RememberState(); |
| 1092 | if (!HasEmptyFrame()) { |
| 1093 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1094 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| 1095 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1096 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 1097 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1098 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 1099 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 1100 | } |
| 1101 | } |
| 1102 | |
| 1103 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1104 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 1105 | __ cfi().AdjustCFAOffset(-adjust); |
| 1106 | |
| 1107 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1108 | Register reg = kCoreCalleeSaves[i]; |
| 1109 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1110 | __ popq(CpuRegister(reg)); |
| 1111 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 1112 | __ cfi().Restore(DWARFReg(reg)); |
| 1113 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1114 | } |
| 1115 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1116 | __ ret(); |
| 1117 | __ cfi().RestoreState(); |
| 1118 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1119 | } |
| 1120 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1121 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 1122 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1123 | } |
| 1124 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1125 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 1126 | if (source.Equals(destination)) { |
| 1127 | return; |
| 1128 | } |
| 1129 | if (destination.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1130 | CpuRegister dest = destination.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1131 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1132 | __ movq(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1133 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1134 | __ movd(dest, source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1135 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1136 | __ movl(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1137 | } else if (source.IsConstant()) { |
| 1138 | HConstant* constant = source.GetConstant(); |
| 1139 | if (constant->IsLongConstant()) { |
| 1140 | Load64BitValue(dest, constant->AsLongConstant()->GetValue()); |
| 1141 | } else { |
| 1142 | Load32BitValue(dest, GetInt32ValueOf(constant)); |
| 1143 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1144 | } else { |
| 1145 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1146 | __ movq(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1147 | } |
| 1148 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1149 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1150 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1151 | __ movd(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1152 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1153 | __ movaps(dest, source.AsFpuRegister<XmmRegister>()); |
| 1154 | } else if (source.IsConstant()) { |
| 1155 | HConstant* constant = source.GetConstant(); |
| 1156 | int64_t value = CodeGenerator::GetInt64ValueOf(constant); |
| 1157 | if (constant->IsFloatConstant()) { |
| 1158 | Load32BitValue(dest, static_cast<int32_t>(value)); |
| 1159 | } else { |
| 1160 | Load64BitValue(dest, value); |
| 1161 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1162 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1163 | __ movss(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1164 | } else { |
| 1165 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1166 | __ movsd(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1167 | } |
| 1168 | } else if (destination.IsStackSlot()) { |
| 1169 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1170 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1171 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1172 | } else if (source.IsFpuRegister()) { |
| 1173 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1174 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1175 | } else if (source.IsConstant()) { |
| 1176 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1177 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1178 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1179 | } else { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1180 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1181 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1182 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1183 | } |
| 1184 | } else { |
| 1185 | DCHECK(destination.IsDoubleStackSlot()); |
| 1186 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1187 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1188 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1189 | } else if (source.IsFpuRegister()) { |
| 1190 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1191 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1192 | } else if (source.IsConstant()) { |
| 1193 | HConstant* constant = source.GetConstant(); |
Zheng Xu | 12bca97 | 2015-03-30 19:35:50 +0800 | [diff] [blame] | 1194 | int64_t value; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1195 | if (constant->IsDoubleConstant()) { |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 1196 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1197 | } else { |
| 1198 | DCHECK(constant->IsLongConstant()); |
| 1199 | value = constant->AsLongConstant()->GetValue(); |
| 1200 | } |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 1201 | Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1202 | } else { |
| 1203 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1204 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1205 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1206 | } |
| 1207 | } |
| 1208 | } |
| 1209 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1210 | void CodeGeneratorX86_64::MoveConstant(Location location, int32_t value) { |
| 1211 | DCHECK(location.IsRegister()); |
| 1212 | Load64BitValue(location.AsRegister<CpuRegister>(), static_cast<int64_t>(value)); |
| 1213 | } |
| 1214 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1215 | void CodeGeneratorX86_64::MoveLocation( |
| 1216 | Location dst, Location src, Primitive::Type dst_type ATTRIBUTE_UNUSED) { |
| 1217 | Move(dst, src); |
| 1218 | } |
| 1219 | |
| 1220 | void CodeGeneratorX86_64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1221 | if (location.IsRegister()) { |
| 1222 | locations->AddTemp(location); |
| 1223 | } else { |
| 1224 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1225 | } |
| 1226 | } |
| 1227 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1228 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1229 | DCHECK(!successor->IsExitBlock()); |
| 1230 | |
| 1231 | HBasicBlock* block = got->GetBlock(); |
| 1232 | HInstruction* previous = got->GetPrevious(); |
| 1233 | |
| 1234 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1235 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1236 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1237 | return; |
| 1238 | } |
| 1239 | |
| 1240 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1241 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1242 | } |
| 1243 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1244 | __ jmp(codegen_->GetLabelOf(successor)); |
| 1245 | } |
| 1246 | } |
| 1247 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1248 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 1249 | got->SetLocations(nullptr); |
| 1250 | } |
| 1251 | |
| 1252 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 1253 | HandleGoto(got, got->GetSuccessor()); |
| 1254 | } |
| 1255 | |
| 1256 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1257 | try_boundary->SetLocations(nullptr); |
| 1258 | } |
| 1259 | |
| 1260 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1261 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1262 | if (!successor->IsExitBlock()) { |
| 1263 | HandleGoto(try_boundary, successor); |
| 1264 | } |
| 1265 | } |
| 1266 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1267 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 1268 | exit->SetLocations(nullptr); |
| 1269 | } |
| 1270 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1271 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1272 | } |
| 1273 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1274 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1275 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1276 | LabelType* true_label, |
| 1277 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1278 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1279 | __ j(kUnordered, true_label); |
| 1280 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1281 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1282 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1283 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1284 | } |
| 1285 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1286 | void InstructionCodeGeneratorX86_64::GenerateCompareTest(HCondition* condition) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1287 | LocationSummary* locations = condition->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1288 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1289 | Location left = locations->InAt(0); |
| 1290 | Location right = locations->InAt(1); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1291 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1292 | switch (type) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1293 | case Primitive::kPrimBoolean: |
| 1294 | case Primitive::kPrimByte: |
| 1295 | case Primitive::kPrimChar: |
| 1296 | case Primitive::kPrimShort: |
| 1297 | case Primitive::kPrimInt: |
| 1298 | case Primitive::kPrimNot: { |
| 1299 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1300 | if (right.IsConstant()) { |
| 1301 | int32_t value = CodeGenerator::GetInt32ValueOf(right.GetConstant()); |
| 1302 | if (value == 0) { |
| 1303 | __ testl(left_reg, left_reg); |
| 1304 | } else { |
| 1305 | __ cmpl(left_reg, Immediate(value)); |
| 1306 | } |
| 1307 | } else if (right.IsStackSlot()) { |
| 1308 | __ cmpl(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1309 | } else { |
| 1310 | __ cmpl(left_reg, right.AsRegister<CpuRegister>()); |
| 1311 | } |
| 1312 | break; |
| 1313 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1314 | case Primitive::kPrimLong: { |
| 1315 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1316 | if (right.IsConstant()) { |
| 1317 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1318 | codegen_->Compare64BitValue(left_reg, value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1319 | } else if (right.IsDoubleStackSlot()) { |
| 1320 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1321 | } else { |
| 1322 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1323 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1324 | break; |
| 1325 | } |
| 1326 | case Primitive::kPrimFloat: { |
| 1327 | if (right.IsFpuRegister()) { |
| 1328 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1329 | } else if (right.IsConstant()) { |
| 1330 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1331 | codegen_->LiteralFloatAddress( |
| 1332 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1333 | } else { |
| 1334 | DCHECK(right.IsStackSlot()); |
| 1335 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1336 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1337 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1338 | break; |
| 1339 | } |
| 1340 | case Primitive::kPrimDouble: { |
| 1341 | if (right.IsFpuRegister()) { |
| 1342 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1343 | } else if (right.IsConstant()) { |
| 1344 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1345 | codegen_->LiteralDoubleAddress( |
| 1346 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1347 | } else { |
| 1348 | DCHECK(right.IsDoubleStackSlot()); |
| 1349 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1350 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1351 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1352 | break; |
| 1353 | } |
| 1354 | default: |
| 1355 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1356 | } |
| 1357 | } |
| 1358 | |
| 1359 | template<class LabelType> |
| 1360 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HCondition* condition, |
| 1361 | LabelType* true_target_in, |
| 1362 | LabelType* false_target_in) { |
| 1363 | // Generated branching requires both targets to be explicit. If either of the |
| 1364 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1365 | LabelType fallthrough_target; |
| 1366 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1367 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1368 | |
| 1369 | // Generate the comparison to set the CC. |
| 1370 | GenerateCompareTest(condition); |
| 1371 | |
| 1372 | // Now generate the correct jump(s). |
| 1373 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1374 | switch (type) { |
| 1375 | case Primitive::kPrimLong: { |
| 1376 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
| 1377 | break; |
| 1378 | } |
| 1379 | case Primitive::kPrimFloat: { |
| 1380 | GenerateFPJumps(condition, true_target, false_target); |
| 1381 | break; |
| 1382 | } |
| 1383 | case Primitive::kPrimDouble: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1384 | GenerateFPJumps(condition, true_target, false_target); |
| 1385 | break; |
| 1386 | } |
| 1387 | default: |
| 1388 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1389 | } |
| 1390 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1391 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1392 | __ jmp(false_target); |
| 1393 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1394 | |
| 1395 | if (fallthrough_target.IsLinked()) { |
| 1396 | __ Bind(&fallthrough_target); |
| 1397 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1398 | } |
| 1399 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1400 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1401 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1402 | // are set only strictly before `branch`. We can't use the eflags on long |
| 1403 | // conditions if they are materialized due to the complex branching. |
| 1404 | return cond->IsCondition() && |
| 1405 | cond->GetNext() == branch && |
| 1406 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1407 | } |
| 1408 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1409 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1410 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1411 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1412 | LabelType* true_target, |
| 1413 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1414 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1415 | |
| 1416 | if (true_target == nullptr && false_target == nullptr) { |
| 1417 | // Nothing to do. The code always falls through. |
| 1418 | return; |
| 1419 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1420 | // Constant condition, statically compared against "true" (integer value 1). |
| 1421 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1422 | if (true_target != nullptr) { |
| 1423 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1424 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1425 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1426 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1427 | if (false_target != nullptr) { |
| 1428 | __ jmp(false_target); |
| 1429 | } |
| 1430 | } |
| 1431 | return; |
| 1432 | } |
| 1433 | |
| 1434 | // The following code generates these patterns: |
| 1435 | // (1) true_target == nullptr && false_target != nullptr |
| 1436 | // - opposite condition true => branch to false_target |
| 1437 | // (2) true_target != nullptr && false_target == nullptr |
| 1438 | // - condition true => branch to true_target |
| 1439 | // (3) true_target != nullptr && false_target != nullptr |
| 1440 | // - condition true => branch to true_target |
| 1441 | // - branch to false_target |
| 1442 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1443 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1444 | if (true_target == nullptr) { |
| 1445 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1446 | } else { |
| 1447 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
| 1448 | } |
| 1449 | } else { |
| 1450 | // Materialized condition, compare against 0. |
| 1451 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1452 | if (lhs.IsRegister()) { |
| 1453 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1454 | } else { |
| 1455 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), Immediate(0)); |
| 1456 | } |
| 1457 | if (true_target == nullptr) { |
| 1458 | __ j(kEqual, false_target); |
| 1459 | } else { |
| 1460 | __ j(kNotEqual, true_target); |
| 1461 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1462 | } |
| 1463 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1464 | // Condition has not been materialized, use its inputs as the |
| 1465 | // comparison and its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1466 | HCondition* condition = cond->AsCondition(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1467 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1468 | // If this is a long or FP comparison that has been folded into |
| 1469 | // the HCondition, generate the comparison directly. |
| 1470 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1471 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1472 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1473 | return; |
| 1474 | } |
| 1475 | |
| 1476 | Location lhs = condition->GetLocations()->InAt(0); |
| 1477 | Location rhs = condition->GetLocations()->InAt(1); |
| 1478 | if (rhs.IsRegister()) { |
| 1479 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1480 | } else if (rhs.IsConstant()) { |
| 1481 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1482 | codegen_->Compare32BitValue(lhs.AsRegister<CpuRegister>(), constant); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1483 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1484 | __ cmpl(lhs.AsRegister<CpuRegister>(), |
| 1485 | Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1486 | } |
| 1487 | if (true_target == nullptr) { |
| 1488 | __ j(X86_64IntegerCondition(condition->GetOppositeCondition()), false_target); |
| 1489 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1490 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1491 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1492 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1493 | |
| 1494 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1495 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1496 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1497 | __ jmp(false_target); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1498 | } |
| 1499 | } |
| 1500 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1501 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1502 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1503 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1504 | locations->SetInAt(0, Location::Any()); |
| 1505 | } |
| 1506 | } |
| 1507 | |
| 1508 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1509 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1510 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1511 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1512 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1513 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1514 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1515 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1516 | } |
| 1517 | |
| 1518 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1519 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1520 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1521 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1522 | locations->SetInAt(0, Location::Any()); |
| 1523 | } |
| 1524 | } |
| 1525 | |
| 1526 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1527 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86_64>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1528 | GenerateTestAndBranch<Label>(deoptimize, |
| 1529 | /* condition_input_index */ 0, |
| 1530 | slow_path->GetEntryLabel(), |
| 1531 | /* false_target */ nullptr); |
| 1532 | } |
| 1533 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1534 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1535 | // There are no conditional move instructions for XMMs. |
| 1536 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1537 | return false; |
| 1538 | } |
| 1539 | |
| 1540 | // A FP condition doesn't generate the single CC that we need. |
| 1541 | HInstruction* condition = select->GetCondition(); |
| 1542 | if (condition->IsCondition() && |
| 1543 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())) { |
| 1544 | return false; |
| 1545 | } |
| 1546 | |
| 1547 | // We can generate a CMOV for this Select. |
| 1548 | return true; |
| 1549 | } |
| 1550 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1551 | void LocationsBuilderX86_64::VisitSelect(HSelect* select) { |
| 1552 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 1553 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1554 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1555 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1556 | } else { |
| 1557 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1558 | if (SelectCanUseCMOV(select)) { |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1559 | if (select->InputAt(1)->IsConstant()) { |
| 1560 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1561 | } else { |
| 1562 | locations->SetInAt(1, Location::Any()); |
| 1563 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1564 | } else { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1565 | locations->SetInAt(1, Location::Any()); |
| 1566 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1567 | } |
| 1568 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1569 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1570 | } |
| 1571 | locations->SetOut(Location::SameAsFirstInput()); |
| 1572 | } |
| 1573 | |
| 1574 | void InstructionCodeGeneratorX86_64::VisitSelect(HSelect* select) { |
| 1575 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1576 | if (SelectCanUseCMOV(select)) { |
| 1577 | // If both the condition and the source types are integer, we can generate |
| 1578 | // a CMOV to implement Select. |
| 1579 | CpuRegister value_false = locations->InAt(0).AsRegister<CpuRegister>(); |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1580 | Location value_true_loc = locations->InAt(1); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1581 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1582 | |
| 1583 | HInstruction* select_condition = select->GetCondition(); |
| 1584 | Condition cond = kNotEqual; |
| 1585 | |
| 1586 | // Figure out how to test the 'condition'. |
| 1587 | if (select_condition->IsCondition()) { |
| 1588 | HCondition* condition = select_condition->AsCondition(); |
| 1589 | if (!condition->IsEmittedAtUseSite()) { |
| 1590 | // This was a previously materialized condition. |
| 1591 | // Can we use the existing condition code? |
| 1592 | if (AreEflagsSetFrom(condition, select)) { |
| 1593 | // Materialization was the previous instruction. Condition codes are right. |
| 1594 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1595 | } else { |
| 1596 | // No, we have to recreate the condition code. |
| 1597 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1598 | __ testl(cond_reg, cond_reg); |
| 1599 | } |
| 1600 | } else { |
| 1601 | GenerateCompareTest(condition); |
| 1602 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1603 | } |
| 1604 | } else { |
| 1605 | // Must be a boolean condition, which needs to be compared to 0. |
| 1606 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1607 | __ testl(cond_reg, cond_reg); |
| 1608 | } |
| 1609 | |
| 1610 | // If the condition is true, overwrite the output, which already contains false. |
| 1611 | // Generate the correct sized CMOV. |
Mark Mendell | dee1b9a | 2016-02-12 14:36:51 -0500 | [diff] [blame] | 1612 | bool is_64_bit = Primitive::Is64BitType(select->GetType()); |
| 1613 | if (value_true_loc.IsRegister()) { |
| 1614 | __ cmov(cond, value_false, value_true_loc.AsRegister<CpuRegister>(), is_64_bit); |
| 1615 | } else { |
| 1616 | __ cmov(cond, |
| 1617 | value_false, |
| 1618 | Address(CpuRegister(RSP), value_true_loc.GetStackIndex()), is_64_bit); |
| 1619 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 1620 | } else { |
| 1621 | NearLabel false_target; |
| 1622 | GenerateTestAndBranch<NearLabel>(select, |
| 1623 | /* condition_input_index */ 2, |
| 1624 | /* true_target */ nullptr, |
| 1625 | &false_target); |
| 1626 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1627 | __ Bind(&false_target); |
| 1628 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1629 | } |
| 1630 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1631 | void LocationsBuilderX86_64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1632 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1633 | } |
| 1634 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1635 | void InstructionCodeGeneratorX86_64::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1636 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1637 | } |
| 1638 | |
| 1639 | void CodeGeneratorX86_64::GenerateNop() { |
| 1640 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1641 | } |
| 1642 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1643 | void LocationsBuilderX86_64::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1644 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1645 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1646 | // Handle the long/FP comparisons made in instruction simplification. |
| 1647 | switch (cond->InputAt(0)->GetType()) { |
| 1648 | case Primitive::kPrimLong: |
| 1649 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1650 | locations->SetInAt(1, Location::Any()); |
| 1651 | break; |
| 1652 | case Primitive::kPrimFloat: |
| 1653 | case Primitive::kPrimDouble: |
| 1654 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1655 | locations->SetInAt(1, Location::Any()); |
| 1656 | break; |
| 1657 | default: |
| 1658 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1659 | locations->SetInAt(1, Location::Any()); |
| 1660 | break; |
| 1661 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1662 | if (!cond->IsEmittedAtUseSite()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1663 | locations->SetOut(Location::RequiresRegister()); |
| 1664 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1665 | } |
| 1666 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1667 | void InstructionCodeGeneratorX86_64::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1668 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1669 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1670 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1671 | |
| 1672 | LocationSummary* locations = cond->GetLocations(); |
| 1673 | Location lhs = locations->InAt(0); |
| 1674 | Location rhs = locations->InAt(1); |
| 1675 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1676 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1677 | |
| 1678 | switch (cond->InputAt(0)->GetType()) { |
| 1679 | default: |
| 1680 | // Integer case. |
| 1681 | |
| 1682 | // Clear output register: setcc only sets the low byte. |
| 1683 | __ xorl(reg, reg); |
| 1684 | |
| 1685 | if (rhs.IsRegister()) { |
| 1686 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1687 | } else if (rhs.IsConstant()) { |
| 1688 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1689 | codegen_->Compare32BitValue(lhs.AsRegister<CpuRegister>(), constant); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1690 | } else { |
| 1691 | __ cmpl(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1692 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1693 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1694 | return; |
| 1695 | case Primitive::kPrimLong: |
| 1696 | // Clear output register: setcc only sets the low byte. |
| 1697 | __ xorl(reg, reg); |
| 1698 | |
| 1699 | if (rhs.IsRegister()) { |
| 1700 | __ cmpq(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1701 | } else if (rhs.IsConstant()) { |
| 1702 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1703 | codegen_->Compare64BitValue(lhs.AsRegister<CpuRegister>(), value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1704 | } else { |
| 1705 | __ cmpq(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1706 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1707 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1708 | return; |
| 1709 | case Primitive::kPrimFloat: { |
| 1710 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1711 | if (rhs.IsConstant()) { |
| 1712 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 1713 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 1714 | } else if (rhs.IsStackSlot()) { |
| 1715 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1716 | } else { |
| 1717 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1718 | } |
| 1719 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1720 | break; |
| 1721 | } |
| 1722 | case Primitive::kPrimDouble: { |
| 1723 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1724 | if (rhs.IsConstant()) { |
| 1725 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1726 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 1727 | } else if (rhs.IsDoubleStackSlot()) { |
| 1728 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1729 | } else { |
| 1730 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1731 | } |
| 1732 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1733 | break; |
| 1734 | } |
| 1735 | } |
| 1736 | |
| 1737 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1738 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1739 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1740 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1741 | __ Bind(&false_label); |
| 1742 | __ xorl(reg, reg); |
| 1743 | __ jmp(&done_label); |
| 1744 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1745 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1746 | __ Bind(&true_label); |
| 1747 | __ movl(reg, Immediate(1)); |
| 1748 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1749 | } |
| 1750 | |
| 1751 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1752 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1753 | } |
| 1754 | |
| 1755 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1756 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1757 | } |
| 1758 | |
| 1759 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1760 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1761 | } |
| 1762 | |
| 1763 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1764 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1765 | } |
| 1766 | |
| 1767 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1768 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1769 | } |
| 1770 | |
| 1771 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1772 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1773 | } |
| 1774 | |
| 1775 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1776 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1780 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1781 | } |
| 1782 | |
| 1783 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1784 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1785 | } |
| 1786 | |
| 1787 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1788 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1792 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1793 | } |
| 1794 | |
| 1795 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1796 | HandleCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1797 | } |
| 1798 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1799 | void LocationsBuilderX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1800 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1801 | } |
| 1802 | |
| 1803 | void InstructionCodeGeneratorX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1804 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1805 | } |
| 1806 | |
| 1807 | void LocationsBuilderX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1808 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | void InstructionCodeGeneratorX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1812 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1813 | } |
| 1814 | |
| 1815 | void LocationsBuilderX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1816 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1817 | } |
| 1818 | |
| 1819 | void InstructionCodeGeneratorX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1820 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1821 | } |
| 1822 | |
| 1823 | void LocationsBuilderX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1824 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1825 | } |
| 1826 | |
| 1827 | void InstructionCodeGeneratorX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1828 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1829 | } |
| 1830 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1831 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1832 | LocationSummary* locations = |
| 1833 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1834 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 1835 | case Primitive::kPrimBoolean: |
| 1836 | case Primitive::kPrimByte: |
| 1837 | case Primitive::kPrimShort: |
| 1838 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1839 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1840 | case Primitive::kPrimLong: { |
| 1841 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1842 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1843 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1844 | break; |
| 1845 | } |
| 1846 | case Primitive::kPrimFloat: |
| 1847 | case Primitive::kPrimDouble: { |
| 1848 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1849 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1850 | locations->SetOut(Location::RequiresRegister()); |
| 1851 | break; |
| 1852 | } |
| 1853 | default: |
| 1854 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 1855 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1856 | } |
| 1857 | |
| 1858 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1859 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1860 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1861 | Location left = locations->InAt(0); |
| 1862 | Location right = locations->InAt(1); |
| 1863 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1864 | NearLabel less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1865 | Primitive::Type type = compare->InputAt(0)->GetType(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1866 | Condition less_cond = kLess; |
| 1867 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1868 | switch (type) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 1869 | case Primitive::kPrimBoolean: |
| 1870 | case Primitive::kPrimByte: |
| 1871 | case Primitive::kPrimShort: |
| 1872 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1873 | case Primitive::kPrimInt: { |
| 1874 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1875 | if (right.IsConstant()) { |
| 1876 | int32_t value = right.GetConstant()->AsIntConstant()->GetValue(); |
| 1877 | codegen_->Compare32BitValue(left_reg, value); |
| 1878 | } else if (right.IsStackSlot()) { |
| 1879 | __ cmpl(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1880 | } else { |
| 1881 | __ cmpl(left_reg, right.AsRegister<CpuRegister>()); |
| 1882 | } |
| 1883 | break; |
| 1884 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1885 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1886 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1887 | if (right.IsConstant()) { |
| 1888 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1889 | codegen_->Compare64BitValue(left_reg, value); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1890 | } else if (right.IsDoubleStackSlot()) { |
| 1891 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1892 | } else { |
| 1893 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1894 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1895 | break; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1896 | } |
| 1897 | case Primitive::kPrimFloat: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1898 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1899 | if (right.IsConstant()) { |
| 1900 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 1901 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 1902 | } else if (right.IsStackSlot()) { |
| 1903 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1904 | } else { |
| 1905 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1906 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1907 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1908 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1909 | break; |
| 1910 | } |
| 1911 | case Primitive::kPrimDouble: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1912 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1913 | if (right.IsConstant()) { |
| 1914 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1915 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 1916 | } else if (right.IsDoubleStackSlot()) { |
| 1917 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1918 | } else { |
| 1919 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1920 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1921 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1922 | less_cond = kBelow; // ucomis{s,d} sets CF |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1923 | break; |
| 1924 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1925 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1926 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1927 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1928 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1929 | __ movl(out, Immediate(0)); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1930 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1931 | __ j(less_cond, &less); |
Calin Juravle | fd86124 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1932 | |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1933 | __ Bind(&greater); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1934 | __ movl(out, Immediate(1)); |
| 1935 | __ jmp(&done); |
| 1936 | |
| 1937 | __ Bind(&less); |
| 1938 | __ movl(out, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1939 | |
| 1940 | __ Bind(&done); |
| 1941 | } |
| 1942 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1943 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1944 | LocationSummary* locations = |
| 1945 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1946 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1947 | } |
| 1948 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1949 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1950 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1951 | } |
| 1952 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1953 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 1954 | LocationSummary* locations = |
| 1955 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1956 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1957 | } |
| 1958 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1959 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1960 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1961 | } |
| 1962 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1963 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1964 | LocationSummary* locations = |
| 1965 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1966 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1967 | } |
| 1968 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1969 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1970 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1971 | } |
| 1972 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1973 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 1974 | LocationSummary* locations = |
| 1975 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1976 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1977 | } |
| 1978 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1979 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1980 | // Will be generated at use site. |
| 1981 | } |
| 1982 | |
| 1983 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1984 | LocationSummary* locations = |
| 1985 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1986 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1987 | } |
| 1988 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1989 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant( |
| 1990 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1991 | // Will be generated at use site. |
| 1992 | } |
| 1993 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1994 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1995 | memory_barrier->SetLocations(nullptr); |
| 1996 | } |
| 1997 | |
| 1998 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 1999 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2000 | } |
| 2001 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2002 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 2003 | ret->SetLocations(nullptr); |
| 2004 | } |
| 2005 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2006 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2007 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2008 | } |
| 2009 | |
| 2010 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2011 | LocationSummary* locations = |
| 2012 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2013 | switch (ret->InputAt(0)->GetType()) { |
| 2014 | case Primitive::kPrimBoolean: |
| 2015 | case Primitive::kPrimByte: |
| 2016 | case Primitive::kPrimChar: |
| 2017 | case Primitive::kPrimShort: |
| 2018 | case Primitive::kPrimInt: |
| 2019 | case Primitive::kPrimNot: |
| 2020 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2021 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2022 | break; |
| 2023 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2024 | case Primitive::kPrimFloat: |
| 2025 | case Primitive::kPrimDouble: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2026 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2027 | break; |
| 2028 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2029 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2030 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2031 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2032 | } |
| 2033 | |
| 2034 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 2035 | if (kIsDebugBuild) { |
| 2036 | switch (ret->InputAt(0)->GetType()) { |
| 2037 | case Primitive::kPrimBoolean: |
| 2038 | case Primitive::kPrimByte: |
| 2039 | case Primitive::kPrimChar: |
| 2040 | case Primitive::kPrimShort: |
| 2041 | case Primitive::kPrimInt: |
| 2042 | case Primitive::kPrimNot: |
| 2043 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2044 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2045 | break; |
| 2046 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2047 | case Primitive::kPrimFloat: |
| 2048 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2049 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2050 | XMM0); |
| 2051 | break; |
| 2052 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2053 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2054 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2055 | } |
| 2056 | } |
| 2057 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2058 | } |
| 2059 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2060 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(Primitive::Type type) const { |
| 2061 | switch (type) { |
| 2062 | case Primitive::kPrimBoolean: |
| 2063 | case Primitive::kPrimByte: |
| 2064 | case Primitive::kPrimChar: |
| 2065 | case Primitive::kPrimShort: |
| 2066 | case Primitive::kPrimInt: |
| 2067 | case Primitive::kPrimNot: |
| 2068 | case Primitive::kPrimLong: |
| 2069 | return Location::RegisterLocation(RAX); |
| 2070 | |
| 2071 | case Primitive::kPrimVoid: |
| 2072 | return Location::NoLocation(); |
| 2073 | |
| 2074 | case Primitive::kPrimDouble: |
| 2075 | case Primitive::kPrimFloat: |
| 2076 | return Location::FpuRegisterLocation(XMM0); |
| 2077 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2078 | |
| 2079 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2080 | } |
| 2081 | |
| 2082 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 2083 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2084 | } |
| 2085 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2086 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2087 | switch (type) { |
| 2088 | case Primitive::kPrimBoolean: |
| 2089 | case Primitive::kPrimByte: |
| 2090 | case Primitive::kPrimChar: |
| 2091 | case Primitive::kPrimShort: |
| 2092 | case Primitive::kPrimInt: |
| 2093 | case Primitive::kPrimNot: { |
| 2094 | uint32_t index = gp_index_++; |
| 2095 | stack_index_++; |
| 2096 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2097 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2098 | } else { |
| 2099 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2100 | } |
| 2101 | } |
| 2102 | |
| 2103 | case Primitive::kPrimLong: { |
| 2104 | uint32_t index = gp_index_; |
| 2105 | stack_index_ += 2; |
| 2106 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2107 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2108 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2109 | } else { |
| 2110 | gp_index_ += 2; |
| 2111 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2112 | } |
| 2113 | } |
| 2114 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2115 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2116 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2117 | stack_index_++; |
| 2118 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2119 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2120 | } else { |
| 2121 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2122 | } |
| 2123 | } |
| 2124 | |
| 2125 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2126 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2127 | stack_index_ += 2; |
| 2128 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2129 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2130 | } else { |
| 2131 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2132 | } |
| 2133 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2134 | |
| 2135 | case Primitive::kPrimVoid: |
| 2136 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2137 | break; |
| 2138 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2139 | return Location::NoLocation(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2140 | } |
| 2141 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2142 | void LocationsBuilderX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2143 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2144 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2145 | // the method_idx. |
| 2146 | HandleInvoke(invoke); |
| 2147 | } |
| 2148 | |
| 2149 | void InstructionCodeGeneratorX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2150 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2151 | } |
| 2152 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2153 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2154 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2155 | // art::PrepareForRegisterAllocation. |
| 2156 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2157 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2158 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2159 | if (intrinsic.TryDispatch(invoke)) { |
| 2160 | return; |
| 2161 | } |
| 2162 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2163 | HandleInvoke(invoke); |
| 2164 | } |
| 2165 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2166 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 2167 | if (invoke->GetLocations()->Intrinsified()) { |
| 2168 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 2169 | intrinsic.Dispatch(invoke); |
| 2170 | return true; |
| 2171 | } |
| 2172 | return false; |
| 2173 | } |
| 2174 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2175 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2176 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2177 | // art::PrepareForRegisterAllocation. |
| 2178 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2179 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2180 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2181 | return; |
| 2182 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2183 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2184 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2185 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2186 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 2187 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2188 | } |
| 2189 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2190 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2191 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2192 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2193 | } |
| 2194 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2195 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2196 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2197 | if (intrinsic.TryDispatch(invoke)) { |
| 2198 | return; |
| 2199 | } |
| 2200 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2201 | HandleInvoke(invoke); |
| 2202 | } |
| 2203 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2204 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2205 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2206 | return; |
| 2207 | } |
| 2208 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2209 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2210 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2211 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2212 | } |
| 2213 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2214 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2215 | HandleInvoke(invoke); |
| 2216 | // Add the hidden argument. |
| 2217 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 2218 | } |
| 2219 | |
| 2220 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2221 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2222 | LocationSummary* locations = invoke->GetLocations(); |
| 2223 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2224 | CpuRegister hidden_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2225 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 2226 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86_64PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2227 | Location receiver = locations->InAt(0); |
| 2228 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 2229 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2230 | // Set the hidden argument. This is safe to do this here, as RAX |
| 2231 | // won't be modified thereafter, before the `call` instruction. |
| 2232 | DCHECK_EQ(RAX, hidden_reg.AsRegister()); |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2233 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2234 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2235 | if (receiver.IsStackSlot()) { |
| 2236 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2237 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2238 | __ movl(temp, Address(temp, class_offset)); |
| 2239 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2240 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2241 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2242 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2243 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2244 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2245 | // emit a read barrier for the previous class reference load. |
| 2246 | // However this is not required in practice, as this is an |
| 2247 | // intermediate/temporary reference and because the current |
| 2248 | // concurrent copying collector keeps the from-space memory |
| 2249 | // intact/accessible until the end of the marking phase (the |
| 2250 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2251 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2252 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2253 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2254 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2255 | __ call(Address(temp, |
| 2256 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64WordSize).SizeValue())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2257 | |
| 2258 | DCHECK(!codegen_->IsLeafMethod()); |
| 2259 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2260 | } |
| 2261 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2262 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 2263 | LocationSummary* locations = |
| 2264 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2265 | switch (neg->GetResultType()) { |
| 2266 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2267 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2268 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2269 | locations->SetOut(Location::SameAsFirstInput()); |
| 2270 | break; |
| 2271 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2272 | case Primitive::kPrimFloat: |
| 2273 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2274 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2275 | locations->SetOut(Location::SameAsFirstInput()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2276 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2277 | break; |
| 2278 | |
| 2279 | default: |
| 2280 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2281 | } |
| 2282 | } |
| 2283 | |
| 2284 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 2285 | LocationSummary* locations = neg->GetLocations(); |
| 2286 | Location out = locations->Out(); |
| 2287 | Location in = locations->InAt(0); |
| 2288 | switch (neg->GetResultType()) { |
| 2289 | case Primitive::kPrimInt: |
| 2290 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2291 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2292 | __ negl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2293 | break; |
| 2294 | |
| 2295 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 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 | __ negq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2299 | break; |
| 2300 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2301 | case Primitive::kPrimFloat: { |
| 2302 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2303 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2304 | // Implement float negation with an exclusive or with value |
| 2305 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2306 | // single-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2307 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2308 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2309 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2310 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2311 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2312 | case Primitive::kPrimDouble: { |
| 2313 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2314 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2315 | // Implement double negation with an exclusive or with value |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2316 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2317 | // a double-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2318 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2319 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2320 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2321 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2322 | |
| 2323 | default: |
| 2324 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2325 | } |
| 2326 | } |
| 2327 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2328 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2329 | LocationSummary* locations = |
| 2330 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 2331 | Primitive::Type result_type = conversion->GetResultType(); |
| 2332 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2333 | DCHECK_NE(result_type, input_type); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2334 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2335 | // The Java language does not allow treating boolean as an integral type but |
| 2336 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2337 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2338 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2339 | case Primitive::kPrimByte: |
| 2340 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2341 | case Primitive::kPrimLong: |
| 2342 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2343 | case Primitive::kPrimBoolean: |
| 2344 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2345 | case Primitive::kPrimShort: |
| 2346 | case Primitive::kPrimInt: |
| 2347 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2348 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2349 | locations->SetInAt(0, Location::Any()); |
| 2350 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2351 | break; |
| 2352 | |
| 2353 | default: |
| 2354 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2355 | << " to " << result_type; |
| 2356 | } |
| 2357 | break; |
| 2358 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2359 | case Primitive::kPrimShort: |
| 2360 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2361 | case Primitive::kPrimLong: |
| 2362 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2363 | case Primitive::kPrimBoolean: |
| 2364 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2365 | case Primitive::kPrimByte: |
| 2366 | case Primitive::kPrimInt: |
| 2367 | case Primitive::kPrimChar: |
| 2368 | // Processing a Dex `int-to-short' instruction. |
| 2369 | locations->SetInAt(0, Location::Any()); |
| 2370 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2371 | break; |
| 2372 | |
| 2373 | default: |
| 2374 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2375 | << " to " << result_type; |
| 2376 | } |
| 2377 | break; |
| 2378 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2379 | case Primitive::kPrimInt: |
| 2380 | switch (input_type) { |
| 2381 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2382 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2383 | locations->SetInAt(0, Location::Any()); |
| 2384 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2385 | break; |
| 2386 | |
| 2387 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2388 | // Processing a Dex `float-to-int' instruction. |
| 2389 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2390 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2391 | break; |
| 2392 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2393 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2394 | // Processing a Dex `double-to-int' instruction. |
| 2395 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2396 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2397 | break; |
| 2398 | |
| 2399 | default: |
| 2400 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2401 | << " to " << result_type; |
| 2402 | } |
| 2403 | break; |
| 2404 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2405 | case Primitive::kPrimLong: |
| 2406 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2407 | case Primitive::kPrimBoolean: |
| 2408 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2409 | case Primitive::kPrimByte: |
| 2410 | case Primitive::kPrimShort: |
| 2411 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2412 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2413 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2414 | // TODO: We would benefit from a (to-be-implemented) |
| 2415 | // Location::RegisterOrStackSlot requirement for this input. |
| 2416 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2417 | locations->SetOut(Location::RequiresRegister()); |
| 2418 | break; |
| 2419 | |
| 2420 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2421 | // Processing a Dex `float-to-long' instruction. |
| 2422 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2423 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2424 | break; |
| 2425 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2426 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2427 | // Processing a Dex `double-to-long' instruction. |
| 2428 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2429 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2430 | break; |
| 2431 | |
| 2432 | default: |
| 2433 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2434 | << " to " << result_type; |
| 2435 | } |
| 2436 | break; |
| 2437 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2438 | case Primitive::kPrimChar: |
| 2439 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2440 | case Primitive::kPrimLong: |
| 2441 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2442 | case Primitive::kPrimBoolean: |
| 2443 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2444 | case Primitive::kPrimByte: |
| 2445 | case Primitive::kPrimShort: |
| 2446 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2447 | // Processing a Dex `int-to-char' instruction. |
| 2448 | locations->SetInAt(0, Location::Any()); |
| 2449 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2450 | break; |
| 2451 | |
| 2452 | default: |
| 2453 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2454 | << " to " << result_type; |
| 2455 | } |
| 2456 | break; |
| 2457 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2458 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2459 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2460 | case Primitive::kPrimBoolean: |
| 2461 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2462 | case Primitive::kPrimByte: |
| 2463 | case Primitive::kPrimShort: |
| 2464 | case Primitive::kPrimInt: |
| 2465 | case Primitive::kPrimChar: |
| 2466 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2467 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2468 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2469 | break; |
| 2470 | |
| 2471 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2472 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2473 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2474 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2475 | break; |
| 2476 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2477 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2478 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2479 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2480 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2481 | break; |
| 2482 | |
| 2483 | default: |
| 2484 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2485 | << " to " << result_type; |
| 2486 | }; |
| 2487 | break; |
| 2488 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2489 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2490 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2491 | case Primitive::kPrimBoolean: |
| 2492 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2493 | case Primitive::kPrimByte: |
| 2494 | case Primitive::kPrimShort: |
| 2495 | case Primitive::kPrimInt: |
| 2496 | case Primitive::kPrimChar: |
| 2497 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2498 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2499 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2500 | break; |
| 2501 | |
| 2502 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2503 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2504 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2505 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2506 | break; |
| 2507 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2508 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2509 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2510 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2511 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2512 | break; |
| 2513 | |
| 2514 | default: |
| 2515 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2516 | << " to " << result_type; |
| 2517 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2518 | break; |
| 2519 | |
| 2520 | default: |
| 2521 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2522 | << " to " << result_type; |
| 2523 | } |
| 2524 | } |
| 2525 | |
| 2526 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2527 | LocationSummary* locations = conversion->GetLocations(); |
| 2528 | Location out = locations->Out(); |
| 2529 | Location in = locations->InAt(0); |
| 2530 | Primitive::Type result_type = conversion->GetResultType(); |
| 2531 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2532 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2533 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2534 | case Primitive::kPrimByte: |
| 2535 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2536 | case Primitive::kPrimLong: |
| 2537 | // Type conversion from long to byte is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2538 | case Primitive::kPrimBoolean: |
| 2539 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2540 | case Primitive::kPrimShort: |
| 2541 | case Primitive::kPrimInt: |
| 2542 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2543 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2544 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2545 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2546 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2547 | __ movsxb(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2548 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2549 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2550 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2551 | Immediate(static_cast<int8_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2552 | } |
| 2553 | break; |
| 2554 | |
| 2555 | default: |
| 2556 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2557 | << " to " << result_type; |
| 2558 | } |
| 2559 | break; |
| 2560 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2561 | case Primitive::kPrimShort: |
| 2562 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2563 | case Primitive::kPrimLong: |
| 2564 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2565 | case Primitive::kPrimBoolean: |
| 2566 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2567 | case Primitive::kPrimByte: |
| 2568 | case Primitive::kPrimInt: |
| 2569 | case Primitive::kPrimChar: |
| 2570 | // Processing a Dex `int-to-short' instruction. |
| 2571 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2572 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2573 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2574 | __ movsxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2575 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2576 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2577 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2578 | Immediate(static_cast<int16_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2579 | } |
| 2580 | break; |
| 2581 | |
| 2582 | default: |
| 2583 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2584 | << " to " << result_type; |
| 2585 | } |
| 2586 | break; |
| 2587 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2588 | case Primitive::kPrimInt: |
| 2589 | switch (input_type) { |
| 2590 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2591 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2592 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2593 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2594 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2595 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2596 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2597 | } else { |
| 2598 | DCHECK(in.IsConstant()); |
| 2599 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2600 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2601 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2602 | } |
| 2603 | break; |
| 2604 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2605 | case Primitive::kPrimFloat: { |
| 2606 | // Processing a Dex `float-to-int' instruction. |
| 2607 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2608 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2609 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2610 | |
| 2611 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2612 | // if input >= (float)INT_MAX goto done |
| 2613 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimIntMax)); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2614 | __ j(kAboveEqual, &done); |
| 2615 | // if input == NaN goto nan |
| 2616 | __ j(kUnordered, &nan); |
| 2617 | // output = float-to-int-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2618 | __ cvttss2si(output, input, false); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2619 | __ jmp(&done); |
| 2620 | __ Bind(&nan); |
| 2621 | // output = 0 |
| 2622 | __ xorl(output, output); |
| 2623 | __ Bind(&done); |
| 2624 | break; |
| 2625 | } |
| 2626 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2627 | case Primitive::kPrimDouble: { |
| 2628 | // Processing a Dex `double-to-int' instruction. |
| 2629 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2630 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2631 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2632 | |
| 2633 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2634 | // if input >= (double)INT_MAX goto done |
| 2635 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2636 | __ j(kAboveEqual, &done); |
| 2637 | // if input == NaN goto nan |
| 2638 | __ j(kUnordered, &nan); |
| 2639 | // output = double-to-int-truncate(input) |
| 2640 | __ cvttsd2si(output, input); |
| 2641 | __ jmp(&done); |
| 2642 | __ Bind(&nan); |
| 2643 | // output = 0 |
| 2644 | __ xorl(output, output); |
| 2645 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2646 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2647 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2648 | |
| 2649 | default: |
| 2650 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2651 | << " to " << result_type; |
| 2652 | } |
| 2653 | break; |
| 2654 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2655 | case Primitive::kPrimLong: |
| 2656 | switch (input_type) { |
| 2657 | DCHECK(out.IsRegister()); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2658 | case Primitive::kPrimBoolean: |
| 2659 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2660 | case Primitive::kPrimByte: |
| 2661 | case Primitive::kPrimShort: |
| 2662 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2663 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2664 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2665 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2666 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2667 | break; |
| 2668 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2669 | case Primitive::kPrimFloat: { |
| 2670 | // Processing a Dex `float-to-long' instruction. |
| 2671 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2672 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2673 | NearLabel done, nan; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2674 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2675 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2676 | // if input >= (float)LONG_MAX goto done |
| 2677 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimLongMax)); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2678 | __ j(kAboveEqual, &done); |
| 2679 | // if input == NaN goto nan |
| 2680 | __ j(kUnordered, &nan); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2681 | // output = float-to-long-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2682 | __ cvttss2si(output, input, true); |
| 2683 | __ jmp(&done); |
| 2684 | __ Bind(&nan); |
| 2685 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2686 | __ xorl(output, output); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2687 | __ Bind(&done); |
| 2688 | break; |
| 2689 | } |
| 2690 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2691 | case Primitive::kPrimDouble: { |
| 2692 | // Processing a Dex `double-to-long' instruction. |
| 2693 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2694 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2695 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2696 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2697 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2698 | // if input >= (double)LONG_MAX goto done |
| 2699 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimLongMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2700 | __ j(kAboveEqual, &done); |
| 2701 | // if input == NaN goto nan |
| 2702 | __ j(kUnordered, &nan); |
| 2703 | // output = double-to-long-truncate(input) |
| 2704 | __ cvttsd2si(output, input, true); |
| 2705 | __ jmp(&done); |
| 2706 | __ Bind(&nan); |
| 2707 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2708 | __ xorl(output, output); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2709 | __ Bind(&done); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2710 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2711 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2712 | |
| 2713 | default: |
| 2714 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2715 | << " to " << result_type; |
| 2716 | } |
| 2717 | break; |
| 2718 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2719 | case Primitive::kPrimChar: |
| 2720 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2721 | case Primitive::kPrimLong: |
| 2722 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2723 | case Primitive::kPrimBoolean: |
| 2724 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2725 | case Primitive::kPrimByte: |
| 2726 | case Primitive::kPrimShort: |
| 2727 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2728 | // Processing a Dex `int-to-char' instruction. |
| 2729 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2730 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2731 | } else if (in.IsStackSlot() || in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2732 | __ movzxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2733 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2734 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2735 | __ movl(out.AsRegister<CpuRegister>(), |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2736 | Immediate(static_cast<uint16_t>(Int64FromConstant(in.GetConstant())))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2737 | } |
| 2738 | break; |
| 2739 | |
| 2740 | default: |
| 2741 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2742 | << " to " << result_type; |
| 2743 | } |
| 2744 | break; |
| 2745 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2746 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2747 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2748 | case Primitive::kPrimBoolean: |
| 2749 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2750 | case Primitive::kPrimByte: |
| 2751 | case Primitive::kPrimShort: |
| 2752 | case Primitive::kPrimInt: |
| 2753 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2754 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2755 | if (in.IsRegister()) { |
| 2756 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2757 | } else if (in.IsConstant()) { |
| 2758 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2759 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2760 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2761 | } else { |
| 2762 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2763 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2764 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2765 | break; |
| 2766 | |
| 2767 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2768 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2769 | if (in.IsRegister()) { |
| 2770 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2771 | } else if (in.IsConstant()) { |
| 2772 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2773 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Pavel Vyssotski | 4c858cd | 2016-03-16 13:59:53 +0600 | [diff] [blame] | 2774 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2775 | } else { |
| 2776 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2777 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2778 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2779 | break; |
| 2780 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2781 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2782 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2783 | if (in.IsFpuRegister()) { |
| 2784 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2785 | } else if (in.IsConstant()) { |
| 2786 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2787 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2788 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2789 | } else { |
| 2790 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 2791 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2792 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2793 | break; |
| 2794 | |
| 2795 | default: |
| 2796 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2797 | << " to " << result_type; |
| 2798 | }; |
| 2799 | break; |
| 2800 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2801 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2802 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2803 | case Primitive::kPrimBoolean: |
| 2804 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2805 | case Primitive::kPrimByte: |
| 2806 | case Primitive::kPrimShort: |
| 2807 | case Primitive::kPrimInt: |
| 2808 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2809 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2810 | if (in.IsRegister()) { |
| 2811 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2812 | } else if (in.IsConstant()) { |
| 2813 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2814 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2815 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2816 | } else { |
| 2817 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2818 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2819 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2820 | break; |
| 2821 | |
| 2822 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2823 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2824 | if (in.IsRegister()) { |
| 2825 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2826 | } else if (in.IsConstant()) { |
| 2827 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2828 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2829 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2830 | } else { |
| 2831 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2832 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2833 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2834 | break; |
| 2835 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2836 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2837 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2838 | if (in.IsFpuRegister()) { |
| 2839 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2840 | } else if (in.IsConstant()) { |
| 2841 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 2842 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 2843 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2844 | } else { |
| 2845 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 2846 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2847 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2848 | break; |
| 2849 | |
| 2850 | default: |
| 2851 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2852 | << " to " << result_type; |
| 2853 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2854 | break; |
| 2855 | |
| 2856 | default: |
| 2857 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2858 | << " to " << result_type; |
| 2859 | } |
| 2860 | } |
| 2861 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2862 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2863 | LocationSummary* locations = |
| 2864 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2865 | switch (add->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2866 | case Primitive::kPrimInt: { |
| 2867 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2868 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2869 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2870 | break; |
| 2871 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2872 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2873 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2874 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2875 | // 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] | 2876 | locations->SetInAt(1, Location::RegisterOrInt32Constant(add->InputAt(1))); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2877 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2878 | break; |
| 2879 | } |
| 2880 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2881 | case Primitive::kPrimDouble: |
| 2882 | case Primitive::kPrimFloat: { |
| 2883 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2884 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2885 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2886 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2887 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2888 | |
| 2889 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2890 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2891 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2892 | } |
| 2893 | |
| 2894 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 2895 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2896 | Location first = locations->InAt(0); |
| 2897 | Location second = locations->InAt(1); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2898 | Location out = locations->Out(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2899 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2900 | switch (add->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2901 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2902 | if (second.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2903 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2904 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2905 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2906 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2907 | } else { |
| 2908 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2909 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2910 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2911 | } else if (second.IsConstant()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2912 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2913 | __ addl(out.AsRegister<CpuRegister>(), |
| 2914 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 2915 | } else { |
| 2916 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2917 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 2918 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2919 | } else { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2920 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2921 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2922 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2923 | break; |
| 2924 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2925 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2926 | case Primitive::kPrimLong: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2927 | if (second.IsRegister()) { |
| 2928 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2929 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2930 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2931 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2932 | } else { |
| 2933 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2934 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2935 | } |
| 2936 | } else { |
| 2937 | DCHECK(second.IsConstant()); |
| 2938 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2939 | int32_t int32_value = Low32Bits(value); |
| 2940 | DCHECK_EQ(int32_value, value); |
| 2941 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2942 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 2943 | } else { |
| 2944 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2945 | first.AsRegister<CpuRegister>(), int32_value)); |
| 2946 | } |
| 2947 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2948 | break; |
| 2949 | } |
| 2950 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2951 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2952 | if (second.IsFpuRegister()) { |
| 2953 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2954 | } else if (second.IsConstant()) { |
| 2955 | __ addss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2956 | codegen_->LiteralFloatAddress( |
| 2957 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2958 | } else { |
| 2959 | DCHECK(second.IsStackSlot()); |
| 2960 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2961 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2962 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2963 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2964 | } |
| 2965 | |
| 2966 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2967 | if (second.IsFpuRegister()) { |
| 2968 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2969 | } else if (second.IsConstant()) { |
| 2970 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2971 | codegen_->LiteralDoubleAddress( |
| 2972 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2973 | } else { |
| 2974 | DCHECK(second.IsDoubleStackSlot()); |
| 2975 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2976 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2977 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2978 | break; |
| 2979 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2980 | |
| 2981 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2982 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2983 | } |
| 2984 | } |
| 2985 | |
| 2986 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2987 | LocationSummary* locations = |
| 2988 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2989 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2990 | case Primitive::kPrimInt: { |
| 2991 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2992 | locations->SetInAt(1, Location::Any()); |
| 2993 | locations->SetOut(Location::SameAsFirstInput()); |
| 2994 | break; |
| 2995 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2996 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2997 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 2998 | locations->SetInAt(1, Location::RegisterOrInt32Constant(sub->InputAt(1))); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2999 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3000 | break; |
| 3001 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3002 | case Primitive::kPrimFloat: |
| 3003 | case Primitive::kPrimDouble: { |
| 3004 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3005 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3006 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3007 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3008 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3009 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3010 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3011 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3012 | } |
| 3013 | |
| 3014 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 3015 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3016 | Location first = locations->InAt(0); |
| 3017 | Location second = locations->InAt(1); |
| 3018 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3019 | switch (sub->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3020 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3021 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3022 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3023 | } else if (second.IsConstant()) { |
| 3024 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3025 | __ subl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3026 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3027 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3028 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3029 | break; |
| 3030 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3031 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3032 | if (second.IsConstant()) { |
| 3033 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3034 | DCHECK(IsInt<32>(value)); |
| 3035 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 3036 | } else { |
| 3037 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 3038 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3039 | break; |
| 3040 | } |
| 3041 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3042 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3043 | if (second.IsFpuRegister()) { |
| 3044 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3045 | } else if (second.IsConstant()) { |
| 3046 | __ subss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3047 | codegen_->LiteralFloatAddress( |
| 3048 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3049 | } else { |
| 3050 | DCHECK(second.IsStackSlot()); |
| 3051 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3052 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3053 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3054 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3055 | } |
| 3056 | |
| 3057 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3058 | if (second.IsFpuRegister()) { |
| 3059 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3060 | } else if (second.IsConstant()) { |
| 3061 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3062 | codegen_->LiteralDoubleAddress( |
| 3063 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3064 | } else { |
| 3065 | DCHECK(second.IsDoubleStackSlot()); |
| 3066 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3067 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3068 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3069 | break; |
| 3070 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3071 | |
| 3072 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3073 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3074 | } |
| 3075 | } |
| 3076 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3077 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 3078 | LocationSummary* locations = |
| 3079 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3080 | switch (mul->GetResultType()) { |
| 3081 | case Primitive::kPrimInt: { |
| 3082 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3083 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3084 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3085 | // Can use 3 operand multiply. |
| 3086 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3087 | } else { |
| 3088 | locations->SetOut(Location::SameAsFirstInput()); |
| 3089 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3090 | break; |
| 3091 | } |
| 3092 | case Primitive::kPrimLong: { |
| 3093 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3094 | locations->SetInAt(1, Location::Any()); |
| 3095 | if (mul->InputAt(1)->IsLongConstant() && |
| 3096 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3097 | // Can use 3 operand multiply. |
| 3098 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3099 | } else { |
| 3100 | locations->SetOut(Location::SameAsFirstInput()); |
| 3101 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3102 | break; |
| 3103 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3104 | case Primitive::kPrimFloat: |
| 3105 | case Primitive::kPrimDouble: { |
| 3106 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3107 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3108 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3109 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3110 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3111 | |
| 3112 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3113 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3114 | } |
| 3115 | } |
| 3116 | |
| 3117 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 3118 | LocationSummary* locations = mul->GetLocations(); |
| 3119 | Location first = locations->InAt(0); |
| 3120 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3121 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3122 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3123 | case Primitive::kPrimInt: |
| 3124 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3125 | // problems where the output may not be the same as the first operand. |
| 3126 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3127 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3128 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 3129 | } else if (second.IsRegister()) { |
| 3130 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3131 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3132 | } else { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3133 | DCHECK(first.Equals(out)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3134 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3135 | __ imull(first.AsRegister<CpuRegister>(), |
| 3136 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3137 | } |
| 3138 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3139 | case Primitive::kPrimLong: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3140 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3141 | // problems where the output may not be the same as the first operand. |
| 3142 | if (mul->InputAt(1)->IsLongConstant()) { |
| 3143 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 3144 | if (IsInt<32>(value)) { |
| 3145 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 3146 | Immediate(static_cast<int32_t>(value))); |
| 3147 | } else { |
| 3148 | // Have to use the constant area. |
| 3149 | DCHECK(first.Equals(out)); |
| 3150 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 3151 | } |
| 3152 | } else if (second.IsRegister()) { |
| 3153 | DCHECK(first.Equals(out)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3154 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3155 | } else { |
| 3156 | DCHECK(second.IsDoubleStackSlot()); |
| 3157 | DCHECK(first.Equals(out)); |
| 3158 | __ imulq(first.AsRegister<CpuRegister>(), |
| 3159 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3160 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3161 | break; |
| 3162 | } |
| 3163 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3164 | case Primitive::kPrimFloat: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3165 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3166 | if (second.IsFpuRegister()) { |
| 3167 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3168 | } else if (second.IsConstant()) { |
| 3169 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3170 | codegen_->LiteralFloatAddress( |
| 3171 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3172 | } else { |
| 3173 | DCHECK(second.IsStackSlot()); |
| 3174 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3175 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3176 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3177 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3178 | } |
| 3179 | |
| 3180 | case Primitive::kPrimDouble: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3181 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3182 | if (second.IsFpuRegister()) { |
| 3183 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3184 | } else if (second.IsConstant()) { |
| 3185 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3186 | codegen_->LiteralDoubleAddress( |
| 3187 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3188 | } else { |
| 3189 | DCHECK(second.IsDoubleStackSlot()); |
| 3190 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3191 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3192 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3193 | break; |
| 3194 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3195 | |
| 3196 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3197 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3198 | } |
| 3199 | } |
| 3200 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3201 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 3202 | uint32_t stack_adjustment, bool is_float) { |
| 3203 | if (source.IsStackSlot()) { |
| 3204 | DCHECK(is_float); |
| 3205 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3206 | } else if (source.IsDoubleStackSlot()) { |
| 3207 | DCHECK(!is_float); |
| 3208 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3209 | } else { |
| 3210 | // Write the value to the temporary location on the stack and load to FP stack. |
| 3211 | if (is_float) { |
| 3212 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3213 | codegen_->Move(stack_temp, source); |
| 3214 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 3215 | } else { |
| 3216 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3217 | codegen_->Move(stack_temp, source); |
| 3218 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 3219 | } |
| 3220 | } |
| 3221 | } |
| 3222 | |
| 3223 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| 3224 | Primitive::Type type = rem->GetResultType(); |
| 3225 | bool is_float = type == Primitive::kPrimFloat; |
| 3226 | size_t elem_size = Primitive::ComponentSize(type); |
| 3227 | LocationSummary* locations = rem->GetLocations(); |
| 3228 | Location first = locations->InAt(0); |
| 3229 | Location second = locations->InAt(1); |
| 3230 | Location out = locations->Out(); |
| 3231 | |
| 3232 | // Create stack space for 2 elements. |
| 3233 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3234 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3235 | |
| 3236 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 3237 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 3238 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 3239 | |
| 3240 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3241 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3242 | __ Bind(&retry); |
| 3243 | __ fprem(); |
| 3244 | |
| 3245 | // Move FP status to AX. |
| 3246 | __ fstsw(); |
| 3247 | |
| 3248 | // And see if the argument reduction is complete. This is signaled by the |
| 3249 | // C2 FPU flag bit set to 0. |
| 3250 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 3251 | __ j(kNotEqual, &retry); |
| 3252 | |
| 3253 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3254 | // Store FP top of stack to real stack. |
| 3255 | if (is_float) { |
| 3256 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 3257 | } else { |
| 3258 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 3259 | } |
| 3260 | |
| 3261 | // Pop the 2 items from the FP stack. |
| 3262 | __ fucompp(); |
| 3263 | |
| 3264 | // Load the value from the stack into an XMM register. |
| 3265 | DCHECK(out.IsFpuRegister()) << out; |
| 3266 | if (is_float) { |
| 3267 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3268 | } else { |
| 3269 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3270 | } |
| 3271 | |
| 3272 | // And remove the temporary stack space we allocated. |
| 3273 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3274 | } |
| 3275 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3276 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3277 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3278 | |
| 3279 | LocationSummary* locations = instruction->GetLocations(); |
| 3280 | Location second = locations->InAt(1); |
| 3281 | DCHECK(second.IsConstant()); |
| 3282 | |
| 3283 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3284 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3285 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3286 | |
| 3287 | DCHECK(imm == 1 || imm == -1); |
| 3288 | |
| 3289 | switch (instruction->GetResultType()) { |
| 3290 | case Primitive::kPrimInt: { |
| 3291 | if (instruction->IsRem()) { |
| 3292 | __ xorl(output_register, output_register); |
| 3293 | } else { |
| 3294 | __ movl(output_register, input_register); |
| 3295 | if (imm == -1) { |
| 3296 | __ negl(output_register); |
| 3297 | } |
| 3298 | } |
| 3299 | break; |
| 3300 | } |
| 3301 | |
| 3302 | case Primitive::kPrimLong: { |
| 3303 | if (instruction->IsRem()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3304 | __ xorl(output_register, output_register); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3305 | } else { |
| 3306 | __ movq(output_register, input_register); |
| 3307 | if (imm == -1) { |
| 3308 | __ negq(output_register); |
| 3309 | } |
| 3310 | } |
| 3311 | break; |
| 3312 | } |
| 3313 | |
| 3314 | default: |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3315 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3316 | } |
| 3317 | } |
| 3318 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3319 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3320 | LocationSummary* locations = instruction->GetLocations(); |
| 3321 | Location second = locations->InAt(1); |
| 3322 | |
| 3323 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3324 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3325 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3326 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3327 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3328 | uint64_t abs_imm = AbsOrMin(imm); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3329 | |
| 3330 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3331 | |
| 3332 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3333 | __ leal(tmp, Address(numerator, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3334 | __ testl(numerator, numerator); |
| 3335 | __ cmov(kGreaterEqual, tmp, numerator); |
| 3336 | int shift = CTZ(imm); |
| 3337 | __ sarl(tmp, Immediate(shift)); |
| 3338 | |
| 3339 | if (imm < 0) { |
| 3340 | __ negl(tmp); |
| 3341 | } |
| 3342 | |
| 3343 | __ movl(output_register, tmp); |
| 3344 | } else { |
| 3345 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3346 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3347 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3348 | codegen_->Load64BitValue(rdx, abs_imm - 1); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3349 | __ addq(rdx, numerator); |
| 3350 | __ testq(numerator, numerator); |
| 3351 | __ cmov(kGreaterEqual, rdx, numerator); |
| 3352 | int shift = CTZ(imm); |
| 3353 | __ sarq(rdx, Immediate(shift)); |
| 3354 | |
| 3355 | if (imm < 0) { |
| 3356 | __ negq(rdx); |
| 3357 | } |
| 3358 | |
| 3359 | __ movq(output_register, rdx); |
| 3360 | } |
| 3361 | } |
| 3362 | |
| 3363 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3364 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3365 | |
| 3366 | LocationSummary* locations = instruction->GetLocations(); |
| 3367 | Location second = locations->InAt(1); |
| 3368 | |
| 3369 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 3370 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3371 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3372 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 3373 | : locations->Out().AsRegister<CpuRegister>(); |
| 3374 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3375 | |
| 3376 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 3377 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 3378 | if (instruction->IsDiv()) { |
| 3379 | DCHECK_EQ(RAX, out.AsRegister()); |
| 3380 | } else { |
| 3381 | DCHECK_EQ(RDX, out.AsRegister()); |
| 3382 | } |
| 3383 | |
| 3384 | int64_t magic; |
| 3385 | int shift; |
| 3386 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3387 | // TODO: can these branches be written as one? |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3388 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 3389 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3390 | |
| 3391 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3392 | |
| 3393 | __ movl(numerator, eax); |
| 3394 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3395 | __ movl(eax, Immediate(magic)); |
| 3396 | __ imull(numerator); |
| 3397 | |
| 3398 | if (imm > 0 && magic < 0) { |
| 3399 | __ addl(edx, numerator); |
| 3400 | } else if (imm < 0 && magic > 0) { |
| 3401 | __ subl(edx, numerator); |
| 3402 | } |
| 3403 | |
| 3404 | if (shift != 0) { |
| 3405 | __ sarl(edx, Immediate(shift)); |
| 3406 | } |
| 3407 | |
| 3408 | __ movl(eax, edx); |
| 3409 | __ shrl(edx, Immediate(31)); |
| 3410 | __ addl(edx, eax); |
| 3411 | |
| 3412 | if (instruction->IsRem()) { |
| 3413 | __ movl(eax, numerator); |
| 3414 | __ imull(edx, Immediate(imm)); |
| 3415 | __ subl(eax, edx); |
| 3416 | __ movl(edx, eax); |
| 3417 | } else { |
| 3418 | __ movl(eax, edx); |
| 3419 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3420 | } else { |
| 3421 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3422 | |
| 3423 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3424 | |
| 3425 | CpuRegister rax = eax; |
| 3426 | CpuRegister rdx = edx; |
| 3427 | |
| 3428 | CalculateMagicAndShiftForDivRem(imm, true /* is_long */, &magic, &shift); |
| 3429 | |
| 3430 | // Save the numerator. |
| 3431 | __ movq(numerator, rax); |
| 3432 | |
| 3433 | // RAX = magic |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3434 | codegen_->Load64BitValue(rax, magic); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3435 | |
| 3436 | // RDX:RAX = magic * numerator |
| 3437 | __ imulq(numerator); |
| 3438 | |
| 3439 | if (imm > 0 && magic < 0) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3440 | // RDX += numerator |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3441 | __ addq(rdx, numerator); |
| 3442 | } else if (imm < 0 && magic > 0) { |
| 3443 | // RDX -= numerator |
| 3444 | __ subq(rdx, numerator); |
| 3445 | } |
| 3446 | |
| 3447 | // Shift if needed. |
| 3448 | if (shift != 0) { |
| 3449 | __ sarq(rdx, Immediate(shift)); |
| 3450 | } |
| 3451 | |
| 3452 | // RDX += 1 if RDX < 0 |
| 3453 | __ movq(rax, rdx); |
| 3454 | __ shrq(rdx, Immediate(63)); |
| 3455 | __ addq(rdx, rax); |
| 3456 | |
| 3457 | if (instruction->IsRem()) { |
| 3458 | __ movq(rax, numerator); |
| 3459 | |
| 3460 | if (IsInt<32>(imm)) { |
| 3461 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 3462 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3463 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3464 | } |
| 3465 | |
| 3466 | __ subq(rax, rdx); |
| 3467 | __ movq(rdx, rax); |
| 3468 | } else { |
| 3469 | __ movq(rax, rdx); |
| 3470 | } |
| 3471 | } |
| 3472 | } |
| 3473 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3474 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3475 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3476 | Primitive::Type type = instruction->GetResultType(); |
| 3477 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 3478 | |
| 3479 | bool is_div = instruction->IsDiv(); |
| 3480 | LocationSummary* locations = instruction->GetLocations(); |
| 3481 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3482 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3483 | Location second = locations->InAt(1); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3484 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3485 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3486 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3487 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3488 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3489 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3490 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3491 | if (imm == 0) { |
| 3492 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3493 | } else if (imm == 1 || imm == -1) { |
| 3494 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3495 | } else if (instruction->IsDiv() && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3496 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3497 | } else { |
| 3498 | DCHECK(imm <= -2 || imm >= 2); |
| 3499 | GenerateDivRemWithAnyConstant(instruction); |
| 3500 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3501 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3502 | SlowPathCode* slow_path = |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3503 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86_64( |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3504 | instruction, out.AsRegister(), type, is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3505 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3506 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3507 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3508 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3509 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3510 | // so it's safe to just use negl instead of more complex comparisons. |
| 3511 | if (type == Primitive::kPrimInt) { |
| 3512 | __ cmpl(second_reg, Immediate(-1)); |
| 3513 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3514 | // edx:eax <- sign-extended of eax |
| 3515 | __ cdq(); |
| 3516 | // eax = quotient, edx = remainder |
| 3517 | __ idivl(second_reg); |
| 3518 | } else { |
| 3519 | __ cmpq(second_reg, Immediate(-1)); |
| 3520 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3521 | // rdx:rax <- sign-extended of rax |
| 3522 | __ cqo(); |
| 3523 | // rax = quotient, rdx = remainder |
| 3524 | __ idivq(second_reg); |
| 3525 | } |
| 3526 | __ Bind(slow_path->GetExitLabel()); |
| 3527 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3528 | } |
| 3529 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3530 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3531 | LocationSummary* locations = |
| 3532 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3533 | switch (div->GetResultType()) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3534 | case Primitive::kPrimInt: |
| 3535 | case Primitive::kPrimLong: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3536 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3537 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3538 | locations->SetOut(Location::SameAsFirstInput()); |
| 3539 | // Intel uses edx:eax as the dividend. |
| 3540 | locations->AddTemp(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3541 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3542 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3543 | // output and request another temp. |
| 3544 | if (div->InputAt(1)->IsConstant()) { |
| 3545 | locations->AddTemp(Location::RequiresRegister()); |
| 3546 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3547 | break; |
| 3548 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3549 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3550 | case Primitive::kPrimFloat: |
| 3551 | case Primitive::kPrimDouble: { |
| 3552 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3553 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3554 | locations->SetOut(Location::SameAsFirstInput()); |
| 3555 | break; |
| 3556 | } |
| 3557 | |
| 3558 | default: |
| 3559 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3560 | } |
| 3561 | } |
| 3562 | |
| 3563 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3564 | LocationSummary* locations = div->GetLocations(); |
| 3565 | Location first = locations->InAt(0); |
| 3566 | Location second = locations->InAt(1); |
| 3567 | DCHECK(first.Equals(locations->Out())); |
| 3568 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3569 | Primitive::Type type = div->GetResultType(); |
| 3570 | switch (type) { |
| 3571 | case Primitive::kPrimInt: |
| 3572 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3573 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3574 | break; |
| 3575 | } |
| 3576 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3577 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3578 | if (second.IsFpuRegister()) { |
| 3579 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3580 | } else if (second.IsConstant()) { |
| 3581 | __ divss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3582 | codegen_->LiteralFloatAddress( |
| 3583 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3584 | } else { |
| 3585 | DCHECK(second.IsStackSlot()); |
| 3586 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3587 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3588 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3589 | break; |
| 3590 | } |
| 3591 | |
| 3592 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3593 | if (second.IsFpuRegister()) { |
| 3594 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3595 | } else if (second.IsConstant()) { |
| 3596 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3597 | codegen_->LiteralDoubleAddress( |
| 3598 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3599 | } else { |
| 3600 | DCHECK(second.IsDoubleStackSlot()); |
| 3601 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3602 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3603 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3604 | break; |
| 3605 | } |
| 3606 | |
| 3607 | default: |
| 3608 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3609 | } |
| 3610 | } |
| 3611 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3612 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3613 | Primitive::Type type = rem->GetResultType(); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3614 | LocationSummary* locations = |
| 3615 | new (GetGraph()->GetArena()) LocationSummary(rem, LocationSummary::kNoCall); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3616 | |
| 3617 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3618 | case Primitive::kPrimInt: |
| 3619 | case Primitive::kPrimLong: { |
| 3620 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3621 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3622 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3623 | locations->SetOut(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3624 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3625 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3626 | // output and request another temp. |
| 3627 | if (rem->InputAt(1)->IsConstant()) { |
| 3628 | locations->AddTemp(Location::RequiresRegister()); |
| 3629 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3630 | break; |
| 3631 | } |
| 3632 | |
| 3633 | case Primitive::kPrimFloat: |
| 3634 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3635 | locations->SetInAt(0, Location::Any()); |
| 3636 | locations->SetInAt(1, Location::Any()); |
| 3637 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3638 | locations->AddTemp(Location::RegisterLocation(RAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3639 | break; |
| 3640 | } |
| 3641 | |
| 3642 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3643 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3644 | } |
| 3645 | } |
| 3646 | |
| 3647 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| 3648 | Primitive::Type type = rem->GetResultType(); |
| 3649 | switch (type) { |
| 3650 | case Primitive::kPrimInt: |
| 3651 | case Primitive::kPrimLong: { |
| 3652 | GenerateDivRemIntegral(rem); |
| 3653 | break; |
| 3654 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3655 | case Primitive::kPrimFloat: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3656 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3657 | GenerateRemFP(rem); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3658 | break; |
| 3659 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3660 | default: |
| 3661 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3662 | } |
| 3663 | } |
| 3664 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3665 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3666 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3667 | ? LocationSummary::kCallOnSlowPath |
| 3668 | : LocationSummary::kNoCall; |
| 3669 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3670 | locations->SetInAt(0, Location::Any()); |
| 3671 | if (instruction->HasUses()) { |
| 3672 | locations->SetOut(Location::SameAsFirstInput()); |
| 3673 | } |
| 3674 | } |
| 3675 | |
| 3676 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3677 | SlowPathCode* slow_path = |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3678 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction); |
| 3679 | codegen_->AddSlowPath(slow_path); |
| 3680 | |
| 3681 | LocationSummary* locations = instruction->GetLocations(); |
| 3682 | Location value = locations->InAt(0); |
| 3683 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3684 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3685 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3686 | case Primitive::kPrimByte: |
| 3687 | case Primitive::kPrimChar: |
| 3688 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3689 | case Primitive::kPrimInt: { |
| 3690 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3691 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3692 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3693 | } else if (value.IsStackSlot()) { |
| 3694 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3695 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3696 | } else { |
| 3697 | DCHECK(value.IsConstant()) << value; |
| 3698 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3699 | __ jmp(slow_path->GetEntryLabel()); |
| 3700 | } |
| 3701 | } |
| 3702 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3703 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3704 | case Primitive::kPrimLong: { |
| 3705 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3706 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3707 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3708 | } else if (value.IsDoubleStackSlot()) { |
| 3709 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3710 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3711 | } else { |
| 3712 | DCHECK(value.IsConstant()) << value; |
| 3713 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3714 | __ jmp(slow_path->GetEntryLabel()); |
| 3715 | } |
| 3716 | } |
| 3717 | break; |
| 3718 | } |
| 3719 | default: |
| 3720 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3721 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3722 | } |
| 3723 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3724 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 3725 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3726 | |
| 3727 | LocationSummary* locations = |
| 3728 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3729 | |
| 3730 | switch (op->GetResultType()) { |
| 3731 | case Primitive::kPrimInt: |
| 3732 | case Primitive::kPrimLong: { |
| 3733 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3734 | // The shift count needs to be in CL. |
| 3735 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 3736 | locations->SetOut(Location::SameAsFirstInput()); |
| 3737 | break; |
| 3738 | } |
| 3739 | default: |
| 3740 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3741 | } |
| 3742 | } |
| 3743 | |
| 3744 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 3745 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3746 | |
| 3747 | LocationSummary* locations = op->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3748 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3749 | Location second = locations->InAt(1); |
| 3750 | |
| 3751 | switch (op->GetResultType()) { |
| 3752 | case Primitive::kPrimInt: { |
| 3753 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3754 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3755 | if (op->IsShl()) { |
| 3756 | __ shll(first_reg, second_reg); |
| 3757 | } else if (op->IsShr()) { |
| 3758 | __ sarl(first_reg, second_reg); |
| 3759 | } else { |
| 3760 | __ shrl(first_reg, second_reg); |
| 3761 | } |
| 3762 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3763 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3764 | if (op->IsShl()) { |
| 3765 | __ shll(first_reg, imm); |
| 3766 | } else if (op->IsShr()) { |
| 3767 | __ sarl(first_reg, imm); |
| 3768 | } else { |
| 3769 | __ shrl(first_reg, imm); |
| 3770 | } |
| 3771 | } |
| 3772 | break; |
| 3773 | } |
| 3774 | case Primitive::kPrimLong: { |
| 3775 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3776 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3777 | if (op->IsShl()) { |
| 3778 | __ shlq(first_reg, second_reg); |
| 3779 | } else if (op->IsShr()) { |
| 3780 | __ sarq(first_reg, second_reg); |
| 3781 | } else { |
| 3782 | __ shrq(first_reg, second_reg); |
| 3783 | } |
| 3784 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3785 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3786 | if (op->IsShl()) { |
| 3787 | __ shlq(first_reg, imm); |
| 3788 | } else if (op->IsShr()) { |
| 3789 | __ sarq(first_reg, imm); |
| 3790 | } else { |
| 3791 | __ shrq(first_reg, imm); |
| 3792 | } |
| 3793 | } |
| 3794 | break; |
| 3795 | } |
| 3796 | default: |
| 3797 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3798 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3799 | } |
| 3800 | } |
| 3801 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3802 | void LocationsBuilderX86_64::VisitRor(HRor* ror) { |
| 3803 | LocationSummary* locations = |
| 3804 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3805 | |
| 3806 | switch (ror->GetResultType()) { |
| 3807 | case Primitive::kPrimInt: |
| 3808 | case Primitive::kPrimLong: { |
| 3809 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3810 | // The shift count needs to be in CL (unless it is a constant). |
| 3811 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, ror->InputAt(1))); |
| 3812 | locations->SetOut(Location::SameAsFirstInput()); |
| 3813 | break; |
| 3814 | } |
| 3815 | default: |
| 3816 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3817 | UNREACHABLE(); |
| 3818 | } |
| 3819 | } |
| 3820 | |
| 3821 | void InstructionCodeGeneratorX86_64::VisitRor(HRor* ror) { |
| 3822 | LocationSummary* locations = ror->GetLocations(); |
| 3823 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3824 | Location second = locations->InAt(1); |
| 3825 | |
| 3826 | switch (ror->GetResultType()) { |
| 3827 | case Primitive::kPrimInt: |
| 3828 | if (second.IsRegister()) { |
| 3829 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3830 | __ rorl(first_reg, second_reg); |
| 3831 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3832 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3833 | __ rorl(first_reg, imm); |
| 3834 | } |
| 3835 | break; |
| 3836 | case Primitive::kPrimLong: |
| 3837 | if (second.IsRegister()) { |
| 3838 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3839 | __ rorq(first_reg, second_reg); |
| 3840 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3841 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3842 | __ rorq(first_reg, imm); |
| 3843 | } |
| 3844 | break; |
| 3845 | default: |
| 3846 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3847 | UNREACHABLE(); |
| 3848 | } |
| 3849 | } |
| 3850 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3851 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 3852 | HandleShift(shl); |
| 3853 | } |
| 3854 | |
| 3855 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 3856 | HandleShift(shl); |
| 3857 | } |
| 3858 | |
| 3859 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 3860 | HandleShift(shr); |
| 3861 | } |
| 3862 | |
| 3863 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 3864 | HandleShift(shr); |
| 3865 | } |
| 3866 | |
| 3867 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 3868 | HandleShift(ushr); |
| 3869 | } |
| 3870 | |
| 3871 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 3872 | HandleShift(ushr); |
| 3873 | } |
| 3874 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3875 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3876 | LocationSummary* locations = |
| 3877 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3878 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3879 | if (instruction->IsStringAlloc()) { |
| 3880 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3881 | } else { |
| 3882 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3883 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3884 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3885 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3886 | } |
| 3887 | |
| 3888 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3889 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3890 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3891 | if (instruction->IsStringAlloc()) { |
| 3892 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3893 | CpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
| 3894 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64WordSize); |
| 3895 | __ gs()->movq(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString), /* no_rip */ true)); |
| 3896 | __ call(Address(temp, code_offset.SizeValue())); |
| 3897 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3898 | } else { |
| 3899 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3900 | instruction, |
| 3901 | instruction->GetDexPc(), |
| 3902 | nullptr); |
| 3903 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 3904 | DCHECK(!codegen_->IsLeafMethod()); |
| 3905 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3906 | } |
| 3907 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3908 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 3909 | LocationSummary* locations = |
| 3910 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3911 | InvokeRuntimeCallingConvention calling_convention; |
| 3912 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3913 | locations->SetOut(Location::RegisterLocation(RAX)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3914 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3915 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3916 | } |
| 3917 | |
| 3918 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| 3919 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3920 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 3921 | instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3922 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3923 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3924 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3925 | instruction, |
| 3926 | instruction->GetDexPc(), |
| 3927 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3928 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3929 | |
| 3930 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3931 | } |
| 3932 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3933 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3934 | LocationSummary* locations = |
| 3935 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3936 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3937 | if (location.IsStackSlot()) { |
| 3938 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3939 | } else if (location.IsDoubleStackSlot()) { |
| 3940 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3941 | } |
| 3942 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3943 | } |
| 3944 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3945 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 3946 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3947 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3948 | } |
| 3949 | |
| 3950 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3951 | LocationSummary* locations = |
| 3952 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3953 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3954 | } |
| 3955 | |
| 3956 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 3957 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3958 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3959 | } |
| 3960 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3961 | void LocationsBuilderX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 3962 | LocationSummary* locations = |
| 3963 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3964 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3965 | locations->SetOut(Location::RequiresRegister()); |
| 3966 | } |
| 3967 | |
| 3968 | void InstructionCodeGeneratorX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 3969 | LocationSummary* locations = instruction->GetLocations(); |
| 3970 | uint32_t method_offset = 0; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3971 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3972 | method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 3973 | instruction->GetIndex(), kX86_64PointerSize).SizeValue(); |
| 3974 | } else { |
| 3975 | method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 3976 | instruction->GetIndex() % mirror::Class::kImtSize, kX86_64PointerSize).Uint32Value(); |
| 3977 | } |
| 3978 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 3979 | Address(locations->InAt(0).AsRegister<CpuRegister>(), method_offset)); |
| 3980 | } |
| 3981 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3982 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3983 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3984 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3985 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3986 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3987 | } |
| 3988 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3989 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 3990 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3991 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 3992 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3993 | Location out = locations->Out(); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3994 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3995 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3996 | __ notl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3997 | break; |
| 3998 | |
| 3999 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4000 | __ notq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4001 | break; |
| 4002 | |
| 4003 | default: |
| 4004 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4005 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4006 | } |
| 4007 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4008 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4009 | LocationSummary* locations = |
| 4010 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4011 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4012 | locations->SetOut(Location::SameAsFirstInput()); |
| 4013 | } |
| 4014 | |
| 4015 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4016 | LocationSummary* locations = bool_not->GetLocations(); |
| 4017 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4018 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 4019 | Location out = locations->Out(); |
| 4020 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 4021 | } |
| 4022 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4023 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4024 | LocationSummary* locations = |
| 4025 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4026 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 4027 | locations->SetInAt(i, Location::Any()); |
| 4028 | } |
| 4029 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4030 | } |
| 4031 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4032 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4033 | LOG(FATAL) << "Unimplemented"; |
| 4034 | } |
| 4035 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4036 | void CodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4037 | /* |
| 4038 | * 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] | 4039 | * 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] | 4040 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4041 | */ |
| 4042 | switch (kind) { |
| 4043 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4044 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4045 | break; |
| 4046 | } |
| 4047 | case MemBarrierKind::kAnyStore: |
| 4048 | case MemBarrierKind::kLoadAny: |
| 4049 | case MemBarrierKind::kStoreStore: { |
| 4050 | // nop |
| 4051 | break; |
| 4052 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4053 | case MemBarrierKind::kNTStoreStore: |
| 4054 | // Non-Temporal Store/Store needs an explicit fence. |
| 4055 | MemoryFence(/* non-temporal */ true); |
| 4056 | break; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4057 | } |
| 4058 | } |
| 4059 | |
| 4060 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 4061 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4062 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4063 | bool object_field_get_with_read_barrier = |
| 4064 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4065 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4066 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4067 | object_field_get_with_read_barrier ? |
| 4068 | LocationSummary::kCallOnSlowPath : |
| 4069 | LocationSummary::kNoCall); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4070 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4071 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4072 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4073 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4074 | // The output overlaps for an object field get when read barriers |
| 4075 | // are enabled: we do not want the move to overwrite the object's |
| 4076 | // location, as we need it to emit the read barrier. |
| 4077 | locations->SetOut( |
| 4078 | Location::RequiresRegister(), |
| 4079 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4080 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4081 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4082 | // We need a temporary register for the read barrier marking slow |
| 4083 | // path in CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier. |
| 4084 | locations->AddTemp(Location::RequiresRegister()); |
| 4085 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4086 | } |
| 4087 | |
| 4088 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 4089 | const FieldInfo& field_info) { |
| 4090 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4091 | |
| 4092 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4093 | Location base_loc = locations->InAt(0); |
| 4094 | CpuRegister base = base_loc.AsRegister<CpuRegister>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4095 | Location out = locations->Out(); |
| 4096 | bool is_volatile = field_info.IsVolatile(); |
| 4097 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4098 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4099 | |
| 4100 | switch (field_type) { |
| 4101 | case Primitive::kPrimBoolean: { |
| 4102 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4103 | break; |
| 4104 | } |
| 4105 | |
| 4106 | case Primitive::kPrimByte: { |
| 4107 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4108 | break; |
| 4109 | } |
| 4110 | |
| 4111 | case Primitive::kPrimShort: { |
| 4112 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4113 | break; |
| 4114 | } |
| 4115 | |
| 4116 | case Primitive::kPrimChar: { |
| 4117 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4118 | break; |
| 4119 | } |
| 4120 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4121 | case Primitive::kPrimInt: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4122 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4123 | break; |
| 4124 | } |
| 4125 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4126 | case Primitive::kPrimNot: { |
| 4127 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4128 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4129 | Location temp_loc = locations->GetTemp(0); |
| 4130 | // Note that a potential implicit null check is handled in this |
| 4131 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4132 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4133 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4134 | if (is_volatile) { |
| 4135 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4136 | } |
| 4137 | } else { |
| 4138 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4139 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4140 | if (is_volatile) { |
| 4141 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4142 | } |
| 4143 | // If read barriers are enabled, emit read barriers other than |
| 4144 | // Baker's using a slow path (and also unpoison the loaded |
| 4145 | // reference, if heap poisoning is enabled). |
| 4146 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4147 | } |
| 4148 | break; |
| 4149 | } |
| 4150 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4151 | case Primitive::kPrimLong: { |
| 4152 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4153 | break; |
| 4154 | } |
| 4155 | |
| 4156 | case Primitive::kPrimFloat: { |
| 4157 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4158 | break; |
| 4159 | } |
| 4160 | |
| 4161 | case Primitive::kPrimDouble: { |
| 4162 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4163 | break; |
| 4164 | } |
| 4165 | |
| 4166 | case Primitive::kPrimVoid: |
| 4167 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4168 | UNREACHABLE(); |
| 4169 | } |
| 4170 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4171 | if (field_type == Primitive::kPrimNot) { |
| 4172 | // Potential implicit null checks, in the case of reference |
| 4173 | // fields, are handled in the previous switch statement. |
| 4174 | } else { |
| 4175 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4176 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4177 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4178 | if (is_volatile) { |
| 4179 | if (field_type == Primitive::kPrimNot) { |
| 4180 | // Memory barriers, in the case of references, are also handled |
| 4181 | // in the previous switch statement. |
| 4182 | } else { |
| 4183 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4184 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4185 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4186 | } |
| 4187 | |
| 4188 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 4189 | const FieldInfo& field_info) { |
| 4190 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4191 | |
| 4192 | LocationSummary* locations = |
| 4193 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4194 | Primitive::Type field_type = field_info.GetFieldType(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4195 | bool is_volatile = field_info.IsVolatile(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4196 | bool needs_write_barrier = |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4197 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4198 | |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4199 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4200 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4201 | if (is_volatile) { |
| 4202 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4203 | locations->SetInAt(1, Location::FpuRegisterOrInt32Constant(instruction->InputAt(1))); |
| 4204 | } else { |
| 4205 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4206 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4207 | } else { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4208 | if (is_volatile) { |
| 4209 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4210 | locations->SetInAt(1, Location::RegisterOrInt32Constant(instruction->InputAt(1))); |
| 4211 | } else { |
| 4212 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4213 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4214 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4215 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4216 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4217 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4218 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4219 | } else if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4220 | // Temporary register for the reference poisoning. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4221 | locations->AddTemp(Location::RequiresRegister()); |
| 4222 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4223 | } |
| 4224 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4225 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4226 | const FieldInfo& field_info, |
| 4227 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4228 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4229 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4230 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4231 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4232 | Location value = locations->InAt(1); |
| 4233 | bool is_volatile = field_info.IsVolatile(); |
| 4234 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4235 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4236 | |
| 4237 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4238 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4239 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4240 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4241 | bool maybe_record_implicit_null_check_done = false; |
| 4242 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4243 | switch (field_type) { |
| 4244 | case Primitive::kPrimBoolean: |
| 4245 | case Primitive::kPrimByte: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4246 | if (value.IsConstant()) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4247 | int8_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4248 | __ movb(Address(base, offset), Immediate(v)); |
| 4249 | } else { |
| 4250 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4251 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4252 | break; |
| 4253 | } |
| 4254 | |
| 4255 | case Primitive::kPrimShort: |
| 4256 | case Primitive::kPrimChar: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4257 | if (value.IsConstant()) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4258 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4259 | __ movw(Address(base, offset), Immediate(v)); |
| 4260 | } else { |
| 4261 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4262 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4263 | break; |
| 4264 | } |
| 4265 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4266 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4267 | case Primitive::kPrimNot: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4268 | if (value.IsConstant()) { |
| 4269 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4270 | // `field_type == Primitive::kPrimNot` implies `v == 0`. |
| 4271 | DCHECK((field_type != Primitive::kPrimNot) || (v == 0)); |
| 4272 | // Note: if heap poisoning is enabled, no need to poison |
| 4273 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 4274 | __ movl(Address(base, offset), Immediate(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4275 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4276 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4277 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4278 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4279 | __ PoisonHeapReference(temp); |
| 4280 | __ movl(Address(base, offset), temp); |
| 4281 | } else { |
| 4282 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4283 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4284 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4285 | break; |
| 4286 | } |
| 4287 | |
| 4288 | case Primitive::kPrimLong: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4289 | if (value.IsConstant()) { |
| 4290 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4291 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4292 | Address(base, offset + sizeof(int32_t)), |
| 4293 | v, |
| 4294 | instruction); |
| 4295 | maybe_record_implicit_null_check_done = true; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4296 | } else { |
| 4297 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4298 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4299 | break; |
| 4300 | } |
| 4301 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4302 | case Primitive::kPrimFloat: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4303 | if (value.IsConstant()) { |
| 4304 | int32_t v = |
| 4305 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4306 | __ movl(Address(base, offset), Immediate(v)); |
| 4307 | } else { |
| 4308 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4309 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4310 | break; |
| 4311 | } |
| 4312 | |
| 4313 | case Primitive::kPrimDouble: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4314 | if (value.IsConstant()) { |
| 4315 | int64_t v = |
| 4316 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4317 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4318 | Address(base, offset + sizeof(int32_t)), |
| 4319 | v, |
| 4320 | instruction); |
| 4321 | maybe_record_implicit_null_check_done = true; |
| 4322 | } else { |
| 4323 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4324 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4325 | break; |
| 4326 | } |
| 4327 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4328 | case Primitive::kPrimVoid: |
| 4329 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4330 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4331 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4332 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4333 | if (!maybe_record_implicit_null_check_done) { |
| 4334 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4335 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4336 | |
| 4337 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4338 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4339 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4340 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4341 | } |
| 4342 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4343 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4344 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4345 | } |
| 4346 | } |
| 4347 | |
| 4348 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4349 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4350 | } |
| 4351 | |
| 4352 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4353 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4354 | } |
| 4355 | |
| 4356 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4357 | HandleFieldGet(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4358 | } |
| 4359 | |
| 4360 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4361 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4362 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4363 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4364 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4365 | HandleFieldGet(instruction); |
| 4366 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4367 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4368 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4369 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4370 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4371 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4372 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4373 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4374 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4375 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4376 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4377 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4378 | } |
| 4379 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4380 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldGet( |
| 4381 | HUnresolvedInstanceFieldGet* instruction) { |
| 4382 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4383 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4384 | instruction, instruction->GetFieldType(), calling_convention); |
| 4385 | } |
| 4386 | |
| 4387 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldGet( |
| 4388 | HUnresolvedInstanceFieldGet* instruction) { |
| 4389 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4390 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4391 | instruction->GetFieldType(), |
| 4392 | instruction->GetFieldIndex(), |
| 4393 | instruction->GetDexPc(), |
| 4394 | calling_convention); |
| 4395 | } |
| 4396 | |
| 4397 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldSet( |
| 4398 | HUnresolvedInstanceFieldSet* instruction) { |
| 4399 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4400 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4401 | instruction, instruction->GetFieldType(), calling_convention); |
| 4402 | } |
| 4403 | |
| 4404 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldSet( |
| 4405 | HUnresolvedInstanceFieldSet* instruction) { |
| 4406 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4407 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4408 | instruction->GetFieldType(), |
| 4409 | instruction->GetFieldIndex(), |
| 4410 | instruction->GetDexPc(), |
| 4411 | calling_convention); |
| 4412 | } |
| 4413 | |
| 4414 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldGet( |
| 4415 | HUnresolvedStaticFieldGet* instruction) { |
| 4416 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4417 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4418 | instruction, instruction->GetFieldType(), calling_convention); |
| 4419 | } |
| 4420 | |
| 4421 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldGet( |
| 4422 | HUnresolvedStaticFieldGet* instruction) { |
| 4423 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4424 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4425 | instruction->GetFieldType(), |
| 4426 | instruction->GetFieldIndex(), |
| 4427 | instruction->GetDexPc(), |
| 4428 | calling_convention); |
| 4429 | } |
| 4430 | |
| 4431 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldSet( |
| 4432 | HUnresolvedStaticFieldSet* instruction) { |
| 4433 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4434 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4435 | instruction, instruction->GetFieldType(), calling_convention); |
| 4436 | } |
| 4437 | |
| 4438 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldSet( |
| 4439 | HUnresolvedStaticFieldSet* instruction) { |
| 4440 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4441 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4442 | instruction->GetFieldType(), |
| 4443 | instruction->GetFieldIndex(), |
| 4444 | instruction->GetDexPc(), |
| 4445 | calling_convention); |
| 4446 | } |
| 4447 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4448 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4449 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4450 | ? LocationSummary::kCallOnSlowPath |
| 4451 | : LocationSummary::kNoCall; |
| 4452 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4453 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4454 | ? Location::RequiresRegister() |
| 4455 | : Location::Any(); |
| 4456 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4457 | if (instruction->HasUses()) { |
| 4458 | locations->SetOut(Location::SameAsFirstInput()); |
| 4459 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4460 | } |
| 4461 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4462 | void CodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4463 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4464 | return; |
| 4465 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4466 | LocationSummary* locations = instruction->GetLocations(); |
| 4467 | Location obj = locations->InAt(0); |
| 4468 | |
| 4469 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4470 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4471 | } |
| 4472 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4473 | void CodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4474 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4475 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4476 | |
| 4477 | LocationSummary* locations = instruction->GetLocations(); |
| 4478 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4479 | |
| 4480 | if (obj.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4481 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4482 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4483 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4484 | } else { |
| 4485 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4486 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4487 | __ jmp(slow_path->GetEntryLabel()); |
| 4488 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4489 | } |
| 4490 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4491 | } |
| 4492 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4493 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4494 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4495 | } |
| 4496 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4497 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4498 | bool object_array_get_with_read_barrier = |
| 4499 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4500 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4501 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4502 | object_array_get_with_read_barrier ? |
| 4503 | LocationSummary::kCallOnSlowPath : |
| 4504 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4505 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4506 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4507 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4508 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4509 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4510 | // The output overlaps for an object array get when read barriers |
| 4511 | // are enabled: we do not want the move to overwrite the array's |
| 4512 | // location, as we need it to emit the read barrier. |
| 4513 | locations->SetOut( |
| 4514 | Location::RequiresRegister(), |
| 4515 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4516 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4517 | // We need a temporary register for the read barrier marking slow |
| 4518 | // path in CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier. |
| 4519 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4520 | locations->AddTemp(Location::RequiresRegister()); |
| 4521 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4522 | } |
| 4523 | |
| 4524 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 4525 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4526 | Location obj_loc = locations->InAt(0); |
| 4527 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4528 | Location index = locations->InAt(1); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4529 | Location out_loc = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4530 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4531 | Primitive::Type type = instruction->GetType(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4532 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4533 | case Primitive::kPrimBoolean: { |
| 4534 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4535 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4536 | if (index.IsConstant()) { |
| 4537 | __ movzxb(out, Address(obj, |
| 4538 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4539 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4540 | __ movzxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4541 | } |
| 4542 | break; |
| 4543 | } |
| 4544 | |
| 4545 | case Primitive::kPrimByte: { |
| 4546 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4547 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4548 | if (index.IsConstant()) { |
| 4549 | __ movsxb(out, Address(obj, |
| 4550 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4551 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4552 | __ movsxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4553 | } |
| 4554 | break; |
| 4555 | } |
| 4556 | |
| 4557 | case Primitive::kPrimShort: { |
| 4558 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4559 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4560 | if (index.IsConstant()) { |
| 4561 | __ movsxw(out, Address(obj, |
| 4562 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4563 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4564 | __ movsxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4565 | } |
| 4566 | break; |
| 4567 | } |
| 4568 | |
| 4569 | case Primitive::kPrimChar: { |
| 4570 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4571 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4572 | if (index.IsConstant()) { |
| 4573 | __ movzxw(out, Address(obj, |
| 4574 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4575 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4576 | __ movzxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4577 | } |
| 4578 | break; |
| 4579 | } |
| 4580 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4581 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4582 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4583 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4584 | if (index.IsConstant()) { |
| 4585 | __ movl(out, Address(obj, |
| 4586 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4587 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4588 | __ movl(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4589 | } |
| 4590 | break; |
| 4591 | } |
| 4592 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4593 | case Primitive::kPrimNot: { |
| 4594 | static_assert( |
| 4595 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4596 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 4597 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4598 | // /* HeapReference<Object> */ out = |
| 4599 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4600 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4601 | Location temp = locations->GetTemp(0); |
| 4602 | // Note that a potential implicit null check is handled in this |
| 4603 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 4604 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 4605 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 4606 | } else { |
| 4607 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| 4608 | if (index.IsConstant()) { |
| 4609 | uint32_t offset = |
| 4610 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4611 | __ movl(out, Address(obj, offset)); |
| 4612 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4613 | // If read barriers are enabled, emit read barriers other than |
| 4614 | // Baker's using a slow path (and also unpoison the loaded |
| 4615 | // reference, if heap poisoning is enabled). |
| 4616 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 4617 | } else { |
| 4618 | __ movl(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
| 4619 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4620 | // If read barriers are enabled, emit read barriers other than |
| 4621 | // Baker's using a slow path (and also unpoison the loaded |
| 4622 | // reference, if heap poisoning is enabled). |
| 4623 | codegen_->MaybeGenerateReadBarrierSlow( |
| 4624 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 4625 | } |
| 4626 | } |
| 4627 | break; |
| 4628 | } |
| 4629 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4630 | case Primitive::kPrimLong: { |
| 4631 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4632 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4633 | if (index.IsConstant()) { |
| 4634 | __ movq(out, Address(obj, |
| 4635 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4636 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4637 | __ movq(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4638 | } |
| 4639 | break; |
| 4640 | } |
| 4641 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4642 | case Primitive::kPrimFloat: { |
| 4643 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4644 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4645 | if (index.IsConstant()) { |
| 4646 | __ movss(out, Address(obj, |
| 4647 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4648 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4649 | __ movss(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4650 | } |
| 4651 | break; |
| 4652 | } |
| 4653 | |
| 4654 | case Primitive::kPrimDouble: { |
| 4655 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4656 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4657 | if (index.IsConstant()) { |
| 4658 | __ movsd(out, Address(obj, |
| 4659 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4660 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4661 | __ movsd(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4662 | } |
| 4663 | break; |
| 4664 | } |
| 4665 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4666 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4667 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4668 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4669 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4670 | |
| 4671 | if (type == Primitive::kPrimNot) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4672 | // Potential implicit null checks, in the case of reference |
| 4673 | // arrays, are handled in the previous switch statement. |
| 4674 | } else { |
| 4675 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4676 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4677 | } |
| 4678 | |
| 4679 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4680 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4681 | |
| 4682 | bool needs_write_barrier = |
| 4683 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4684 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4685 | bool object_array_set_with_read_barrier = |
| 4686 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4687 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4688 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4689 | instruction, |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4690 | (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] | 4691 | LocationSummary::kCallOnSlowPath : |
| 4692 | LocationSummary::kNoCall); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4693 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4694 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4695 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4696 | if (Primitive::IsFloatingPointType(value_type)) { |
| 4697 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4698 | } else { |
| 4699 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 4700 | } |
| 4701 | |
| 4702 | if (needs_write_barrier) { |
| 4703 | // Temporary registers for the write barrier. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4704 | |
| 4705 | // This first temporary register is possibly used for heap |
| 4706 | // reference poisoning and/or read barrier emission too. |
| 4707 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4708 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4709 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4710 | } |
| 4711 | |
| 4712 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 4713 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4714 | Location array_loc = locations->InAt(0); |
| 4715 | CpuRegister array = array_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4716 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4717 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4718 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4719 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4720 | bool needs_write_barrier = |
| 4721 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4722 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4723 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4724 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4725 | |
| 4726 | switch (value_type) { |
| 4727 | case Primitive::kPrimBoolean: |
| 4728 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4729 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 4730 | Address address = index.IsConstant() |
| 4731 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 4732 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_1, offset); |
| 4733 | if (value.IsRegister()) { |
| 4734 | __ movb(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4735 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4736 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4737 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4738 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4739 | break; |
| 4740 | } |
| 4741 | |
| 4742 | case Primitive::kPrimShort: |
| 4743 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4744 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 4745 | Address address = index.IsConstant() |
| 4746 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 4747 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_2, offset); |
| 4748 | if (value.IsRegister()) { |
| 4749 | __ movw(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4750 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4751 | DCHECK(value.IsConstant()) << value; |
| 4752 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4753 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4754 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4755 | break; |
| 4756 | } |
| 4757 | |
| 4758 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4759 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4760 | Address address = index.IsConstant() |
| 4761 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4762 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4763 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4764 | if (!value.IsRegister()) { |
| 4765 | // Just setting null. |
| 4766 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 4767 | DCHECK(value.IsConstant()) << value; |
| 4768 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4769 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4770 | DCHECK(!needs_write_barrier); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4771 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4772 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4773 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4774 | |
| 4775 | DCHECK(needs_write_barrier); |
| 4776 | CpuRegister register_value = value.AsRegister<CpuRegister>(); |
| 4777 | NearLabel done, not_null, do_put; |
| 4778 | SlowPathCode* slow_path = nullptr; |
| 4779 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4780 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4781 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86_64(instruction); |
| 4782 | codegen_->AddSlowPath(slow_path); |
| 4783 | if (instruction->GetValueCanBeNull()) { |
| 4784 | __ testl(register_value, register_value); |
| 4785 | __ j(kNotEqual, ¬_null); |
| 4786 | __ movl(address, Immediate(0)); |
| 4787 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4788 | __ jmp(&done); |
| 4789 | __ Bind(¬_null); |
| 4790 | } |
| 4791 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4792 | if (kEmitCompilerReadBarrier) { |
| 4793 | // When read barriers are enabled, the type checking |
| 4794 | // instrumentation requires two read barriers: |
| 4795 | // |
| 4796 | // __ movl(temp2, temp); |
| 4797 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 4798 | // __ movl(temp, Address(temp, component_offset)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4799 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4800 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 4801 | // |
| 4802 | // // /* HeapReference<Class> */ temp2 = register_value->klass_ |
| 4803 | // __ movl(temp2, Address(register_value, class_offset)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4804 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4805 | // instruction, temp2_loc, temp2_loc, value, class_offset, temp_loc); |
| 4806 | // |
| 4807 | // __ cmpl(temp, temp2); |
| 4808 | // |
| 4809 | // However, the second read barrier may trash `temp`, as it |
| 4810 | // is a temporary register, and as such would not be saved |
| 4811 | // along with live registers before calling the runtime (nor |
| 4812 | // restored afterwards). So in this case, we bail out and |
| 4813 | // delegate the work to the array set slow path. |
| 4814 | // |
| 4815 | // TODO: Extend the register allocator to support a new |
| 4816 | // "(locally) live temp" location so as to avoid always |
| 4817 | // going into the slow path when read barriers are enabled. |
| 4818 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4819 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4820 | // /* HeapReference<Class> */ temp = array->klass_ |
| 4821 | __ movl(temp, Address(array, class_offset)); |
| 4822 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4823 | __ MaybeUnpoisonHeapReference(temp); |
| 4824 | |
| 4825 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 4826 | __ movl(temp, Address(temp, component_offset)); |
| 4827 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 4828 | // nor the object reference in `register_value->klass`, as |
| 4829 | // we are comparing two poisoned references. |
| 4830 | __ cmpl(temp, Address(register_value, class_offset)); |
| 4831 | |
| 4832 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4833 | __ j(kEqual, &do_put); |
| 4834 | // If heap poisoning is enabled, the `temp` reference has |
| 4835 | // not been unpoisoned yet; unpoison it now. |
| 4836 | __ MaybeUnpoisonHeapReference(temp); |
| 4837 | |
| 4838 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 4839 | __ movl(temp, Address(temp, super_offset)); |
| 4840 | // If heap poisoning is enabled, no need to unpoison |
| 4841 | // `temp`, as we are comparing against null below. |
| 4842 | __ testl(temp, temp); |
| 4843 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4844 | __ Bind(&do_put); |
| 4845 | } else { |
| 4846 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4847 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4848 | } |
| 4849 | } |
| 4850 | |
| 4851 | if (kPoisonHeapReferences) { |
| 4852 | __ movl(temp, register_value); |
| 4853 | __ PoisonHeapReference(temp); |
| 4854 | __ movl(address, temp); |
| 4855 | } else { |
| 4856 | __ movl(address, register_value); |
| 4857 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4858 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4859 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4860 | } |
| 4861 | |
| 4862 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 4863 | codegen_->MarkGCCard( |
| 4864 | temp, card, array, value.AsRegister<CpuRegister>(), instruction->GetValueCanBeNull()); |
| 4865 | __ Bind(&done); |
| 4866 | |
| 4867 | if (slow_path != nullptr) { |
| 4868 | __ Bind(slow_path->GetExitLabel()); |
| 4869 | } |
| 4870 | |
| 4871 | break; |
| 4872 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4873 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4874 | case Primitive::kPrimInt: { |
| 4875 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4876 | Address address = index.IsConstant() |
| 4877 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4878 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
| 4879 | if (value.IsRegister()) { |
| 4880 | __ movl(address, value.AsRegister<CpuRegister>()); |
| 4881 | } else { |
| 4882 | DCHECK(value.IsConstant()) << value; |
| 4883 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4884 | __ movl(address, Immediate(v)); |
| 4885 | } |
| 4886 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4887 | break; |
| 4888 | } |
| 4889 | |
| 4890 | case Primitive::kPrimLong: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4891 | uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| 4892 | Address address = index.IsConstant() |
| 4893 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 4894 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset); |
| 4895 | if (value.IsRegister()) { |
| 4896 | __ movq(address, value.AsRegister<CpuRegister>()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4897 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4898 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4899 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4900 | Address address_high = index.IsConstant() |
| 4901 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 4902 | offset + sizeof(int32_t)) |
| 4903 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset + sizeof(int32_t)); |
| 4904 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4905 | } |
| 4906 | break; |
| 4907 | } |
| 4908 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4909 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4910 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4911 | Address address = index.IsConstant() |
| 4912 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4913 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4914 | if (value.IsFpuRegister()) { |
| 4915 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 4916 | } else { |
| 4917 | DCHECK(value.IsConstant()); |
| 4918 | int32_t v = |
| 4919 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4920 | __ movl(address, Immediate(v)); |
| 4921 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4922 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4923 | break; |
| 4924 | } |
| 4925 | |
| 4926 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4927 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4928 | Address address = index.IsConstant() |
| 4929 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 4930 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4931 | if (value.IsFpuRegister()) { |
| 4932 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 4933 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4934 | } else { |
| 4935 | int64_t v = |
| 4936 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4937 | Address address_high = index.IsConstant() |
| 4938 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 4939 | offset + sizeof(int32_t)) |
| 4940 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset + sizeof(int32_t)); |
| 4941 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| 4942 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4943 | break; |
| 4944 | } |
| 4945 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4946 | case Primitive::kPrimVoid: |
| 4947 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4948 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4949 | } |
| 4950 | } |
| 4951 | |
| 4952 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4953 | LocationSummary* locations = |
| 4954 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4955 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4956 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4957 | } |
| 4958 | |
| 4959 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
| 4960 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 4961 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4962 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4963 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4964 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4965 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4966 | } |
| 4967 | |
| 4968 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4969 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4970 | ? LocationSummary::kCallOnSlowPath |
| 4971 | : LocationSummary::kNoCall; |
| 4972 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4973 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4974 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4975 | if (instruction->HasUses()) { |
| 4976 | locations->SetOut(Location::SameAsFirstInput()); |
| 4977 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4978 | } |
| 4979 | |
| 4980 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4981 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4982 | Location index_loc = locations->InAt(0); |
| 4983 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4984 | SlowPathCode* slow_path = |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4985 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4986 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4987 | if (length_loc.IsConstant()) { |
| 4988 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 4989 | if (index_loc.IsConstant()) { |
| 4990 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 4991 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4992 | if (index < 0 || index >= length) { |
| 4993 | codegen_->AddSlowPath(slow_path); |
| 4994 | __ jmp(slow_path->GetEntryLabel()); |
| 4995 | } else { |
| 4996 | // Some optimization after BCE may have generated this, and we should not |
| 4997 | // generate a bounds check if it is a valid range. |
| 4998 | } |
| 4999 | return; |
| 5000 | } |
| 5001 | |
| 5002 | // We have to reverse the jump condition because the length is the constant. |
| 5003 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 5004 | __ cmpl(index_reg, Immediate(length)); |
| 5005 | codegen_->AddSlowPath(slow_path); |
| 5006 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5007 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5008 | CpuRegister length = length_loc.AsRegister<CpuRegister>(); |
| 5009 | if (index_loc.IsConstant()) { |
| 5010 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5011 | __ cmpl(length, Immediate(value)); |
| 5012 | } else { |
| 5013 | __ cmpl(length, index_loc.AsRegister<CpuRegister>()); |
| 5014 | } |
| 5015 | codegen_->AddSlowPath(slow_path); |
| 5016 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5017 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5018 | } |
| 5019 | |
| 5020 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 5021 | CpuRegister card, |
| 5022 | CpuRegister object, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5023 | CpuRegister value, |
| 5024 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5025 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5026 | if (value_can_be_null) { |
| 5027 | __ testl(value, value); |
| 5028 | __ j(kEqual, &is_null); |
| 5029 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5030 | __ gs()->movq(card, Address::Absolute(Thread::CardTableOffset<kX86_64WordSize>().Int32Value(), |
| 5031 | /* no_rip */ true)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5032 | __ movq(temp, object); |
| 5033 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5034 | __ movb(Address(temp, card, TIMES_1, 0), card); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5035 | if (value_can_be_null) { |
| 5036 | __ Bind(&is_null); |
| 5037 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5038 | } |
| 5039 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5040 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5041 | LOG(FATAL) << "Unimplemented"; |
| 5042 | } |
| 5043 | |
| 5044 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5045 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5046 | } |
| 5047 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5048 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 5049 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 5050 | } |
| 5051 | |
| 5052 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5053 | HBasicBlock* block = instruction->GetBlock(); |
| 5054 | if (block->GetLoopInformation() != nullptr) { |
| 5055 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5056 | // The back edge will generate the suspend check. |
| 5057 | return; |
| 5058 | } |
| 5059 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5060 | // The goto will generate the suspend check. |
| 5061 | return; |
| 5062 | } |
| 5063 | GenerateSuspendCheck(instruction, nullptr); |
| 5064 | } |
| 5065 | |
| 5066 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5067 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5068 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5069 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 5070 | if (slow_path == nullptr) { |
| 5071 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
| 5072 | instruction->SetSlowPath(slow_path); |
| 5073 | codegen_->AddSlowPath(slow_path); |
| 5074 | if (successor != nullptr) { |
| 5075 | DCHECK(successor->IsLoopHeader()); |
| 5076 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5077 | } |
| 5078 | } else { |
| 5079 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5080 | } |
| 5081 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5082 | __ gs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86_64WordSize>().Int32Value(), |
| 5083 | /* no_rip */ true), |
| 5084 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5085 | if (successor == nullptr) { |
| 5086 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5087 | __ Bind(slow_path->GetReturnLabel()); |
| 5088 | } else { |
| 5089 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5090 | __ jmp(slow_path->GetEntryLabel()); |
| 5091 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5092 | } |
| 5093 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5094 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 5095 | return codegen_->GetAssembler(); |
| 5096 | } |
| 5097 | |
| 5098 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5099 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5100 | Location source = move->GetSource(); |
| 5101 | Location destination = move->GetDestination(); |
| 5102 | |
| 5103 | if (source.IsRegister()) { |
| 5104 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5105 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5106 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5107 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5108 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5109 | } else { |
| 5110 | DCHECK(destination.IsDoubleStackSlot()); |
| 5111 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5112 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5113 | } |
| 5114 | } else if (source.IsStackSlot()) { |
| 5115 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5116 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5117 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5118 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5119 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5120 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5121 | } else { |
| 5122 | DCHECK(destination.IsStackSlot()); |
| 5123 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5124 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5125 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5126 | } else if (source.IsDoubleStackSlot()) { |
| 5127 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5128 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5129 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5130 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5131 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 5132 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5133 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 5134 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5135 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5136 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5137 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5138 | } else if (source.IsConstant()) { |
| 5139 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5140 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5141 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5142 | if (destination.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5143 | if (value == 0) { |
| 5144 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 5145 | } else { |
| 5146 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 5147 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5148 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5149 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5150 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5151 | } |
| 5152 | } else if (constant->IsLongConstant()) { |
| 5153 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5154 | if (destination.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5155 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5156 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5157 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5158 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5159 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5160 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5161 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5162 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5163 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5164 | codegen_->Load32BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5165 | } else { |
| 5166 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5167 | Immediate imm(bit_cast<int32_t, float>(fp_value)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5168 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 5169 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5170 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5171 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5172 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5173 | int64_t value = bit_cast<int64_t, double>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5174 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5175 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 5176 | codegen_->Load64BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5177 | } else { |
| 5178 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5179 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5180 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5181 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5182 | } else if (source.IsFpuRegister()) { |
| 5183 | if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5184 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5185 | } else if (destination.IsStackSlot()) { |
| 5186 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5187 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5188 | } else { |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 5189 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5190 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5191 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5192 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5193 | } |
| 5194 | } |
| 5195 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5196 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5197 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5198 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 5199 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5200 | } |
| 5201 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5202 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5203 | ScratchRegisterScope ensure_scratch( |
| 5204 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 5205 | |
| 5206 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5207 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5208 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 5209 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5210 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5211 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5212 | CpuRegister(ensure_scratch.GetRegister())); |
| 5213 | } |
| 5214 | |
Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5215 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg1, CpuRegister reg2) { |
| 5216 | __ movq(CpuRegister(TMP), reg1); |
| 5217 | __ movq(reg1, reg2); |
| 5218 | __ movq(reg2, CpuRegister(TMP)); |
| 5219 | } |
| 5220 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5221 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 5222 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5223 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 5224 | __ movq(reg, CpuRegister(TMP)); |
| 5225 | } |
| 5226 | |
| 5227 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 5228 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5229 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5230 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5231 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5232 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5233 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 5234 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5235 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5236 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5237 | CpuRegister(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5238 | } |
| 5239 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5240 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 5241 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5242 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 5243 | __ movd(reg, CpuRegister(TMP)); |
| 5244 | } |
| 5245 | |
| 5246 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 5247 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5248 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 5249 | __ movd(reg, CpuRegister(TMP)); |
| 5250 | } |
| 5251 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5252 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5253 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5254 | Location source = move->GetSource(); |
| 5255 | Location destination = move->GetDestination(); |
| 5256 | |
| 5257 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 8a1c728 | 2015-06-29 15:41:28 -0400 | [diff] [blame] | 5258 | Exchange64(source.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5259 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5260 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5261 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5262 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5263 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5264 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5265 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5266 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5267 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5268 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5269 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 5270 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5271 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5272 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 5273 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5274 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5275 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5276 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5277 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5278 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5279 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5280 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5281 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5282 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5283 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5284 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5285 | } |
| 5286 | } |
| 5287 | |
| 5288 | |
| 5289 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 5290 | __ pushq(CpuRegister(reg)); |
| 5291 | } |
| 5292 | |
| 5293 | |
| 5294 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 5295 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5296 | } |
| 5297 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5298 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5299 | SlowPathCode* slow_path, CpuRegister class_reg) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5300 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5301 | Immediate(mirror::Class::kStatusInitialized)); |
| 5302 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5303 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5304 | // No need for memory fence, thanks to the x86-64 memory model. |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5305 | } |
| 5306 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5307 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5308 | InvokeRuntimeCallingConvention calling_convention; |
| 5309 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5310 | cls, |
| 5311 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5312 | Location::RegisterLocation(RAX), |
| 5313 | /* code_generator_supports_read_barrier */ true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5314 | } |
| 5315 | |
| 5316 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5317 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5318 | if (cls->NeedsAccessCheck()) { |
| 5319 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 5320 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 5321 | cls, |
| 5322 | cls->GetDexPc(), |
| 5323 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5324 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5325 | return; |
| 5326 | } |
| 5327 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5328 | Location out_loc = locations->Out(); |
| 5329 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5330 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5331 | |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5332 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5333 | DCHECK(!cls->CanCallRuntime()); |
| 5334 | DCHECK(!cls->MustGenerateClinitCheck()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5335 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5336 | GenerateGcRootFieldLoad( |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5337 | cls, out_loc, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5338 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5339 | // /* GcRoot<mirror::Class>[] */ out = |
| 5340 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5341 | __ movq(out, Address(current_method, |
| 5342 | ArtMethod::DexCacheResolvedTypesOffset(kX86_64PointerSize).Int32Value())); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5343 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5344 | GenerateGcRootFieldLoad( |
| 5345 | cls, out_loc, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5346 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5347 | if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { |
| 5348 | DCHECK(cls->CanCallRuntime()); |
| 5349 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 5350 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5351 | codegen_->AddSlowPath(slow_path); |
| 5352 | if (!cls->IsInDexCache()) { |
| 5353 | __ testl(out, out); |
| 5354 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5355 | } |
| 5356 | if (cls->MustGenerateClinitCheck()) { |
| 5357 | GenerateClassInitializationCheck(slow_path, out); |
| 5358 | } else { |
| 5359 | __ Bind(slow_path->GetExitLabel()); |
| 5360 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5361 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5362 | } |
| 5363 | } |
| 5364 | |
| 5365 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 5366 | LocationSummary* locations = |
| 5367 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5368 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5369 | if (check->HasUses()) { |
| 5370 | locations->SetOut(Location::SameAsFirstInput()); |
| 5371 | } |
| 5372 | } |
| 5373 | |
| 5374 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5375 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5376 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5377 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5378 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5379 | GenerateClassInitializationCheck(slow_path, |
| 5380 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5381 | } |
| 5382 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5383 | HLoadString::LoadKind CodeGeneratorX86_64::GetSupportedLoadStringKind( |
| 5384 | HLoadString::LoadKind desired_string_load_kind) { |
| 5385 | if (kEmitCompilerReadBarrier) { |
| 5386 | switch (desired_string_load_kind) { |
| 5387 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5388 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5389 | case HLoadString::LoadKind::kBootImageAddress: |
| 5390 | // TODO: Implement for read barrier. |
| 5391 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 5392 | default: |
| 5393 | break; |
| 5394 | } |
| 5395 | } |
| 5396 | switch (desired_string_load_kind) { |
| 5397 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5398 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5399 | // We prefer the always-available RIP-relative address for the x86-64 boot image. |
| 5400 | return HLoadString::LoadKind::kBootImageLinkTimePcRelative; |
| 5401 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5402 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5403 | break; |
| 5404 | case HLoadString::LoadKind::kBootImageAddress: |
| 5405 | break; |
| 5406 | case HLoadString::LoadKind::kDexCacheAddress: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5407 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5408 | break; |
| 5409 | case HLoadString::LoadKind::kDexCachePcRelative: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5410 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5411 | break; |
| 5412 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5413 | break; |
| 5414 | } |
| 5415 | return desired_string_load_kind; |
| 5416 | } |
| 5417 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5418 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5419 | LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier) |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5420 | ? LocationSummary::kCallOnSlowPath |
| 5421 | : LocationSummary::kNoCall; |
| 5422 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5423 | if (load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) { |
| 5424 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5425 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5426 | locations->SetOut(Location::RequiresRegister()); |
| 5427 | } |
| 5428 | |
| 5429 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5430 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5431 | Location out_loc = locations->Out(); |
| 5432 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5433 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5434 | switch (load->GetLoadKind()) { |
| 5435 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 5436 | DCHECK(!kEmitCompilerReadBarrier); |
| 5437 | __ leal(out, Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, /* no_rip */ false)); |
| 5438 | codegen_->RecordStringPatch(load); |
| 5439 | return; // No dex cache slow path. |
| 5440 | } |
| 5441 | case HLoadString::LoadKind::kBootImageAddress: { |
| 5442 | DCHECK(!kEmitCompilerReadBarrier); |
| 5443 | DCHECK_NE(load->GetAddress(), 0u); |
| 5444 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 5445 | __ movl(out, Immediate(address)); // Zero-extended. |
| 5446 | codegen_->RecordSimplePatch(); |
| 5447 | return; // No dex cache slow path. |
| 5448 | } |
| 5449 | case HLoadString::LoadKind::kDexCacheAddress: { |
| 5450 | DCHECK_NE(load->GetAddress(), 0u); |
| 5451 | if (IsUint<32>(load->GetAddress())) { |
| 5452 | Address address = Address::Absolute(load->GetAddress(), /* no_rip */ true); |
| 5453 | GenerateGcRootFieldLoad(load, out_loc, address); |
| 5454 | } else { |
| 5455 | // TODO: Consider using opcode A1, i.e. movl eax, moff32 (with 64-bit address). |
| 5456 | __ movq(out, Immediate(load->GetAddress())); |
| 5457 | GenerateGcRootFieldLoad(load, out_loc, Address(out, 0)); |
| 5458 | } |
| 5459 | break; |
| 5460 | } |
| 5461 | case HLoadString::LoadKind::kDexCachePcRelative: { |
| 5462 | uint32_t offset = load->GetDexCacheElementOffset(); |
| 5463 | Label* fixup_label = codegen_->NewPcRelativeDexCacheArrayPatch(load->GetDexFile(), offset); |
| 5464 | Address address = Address::Absolute(CodeGeneratorX86_64::kDummy32BitOffset, |
| 5465 | /* no_rip */ false); |
| 5466 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label); |
| 5467 | break; |
| 5468 | } |
| 5469 | case HLoadString::LoadKind::kDexCacheViaMethod: { |
| 5470 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5471 | |
| 5472 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5473 | GenerateGcRootFieldLoad( |
| 5474 | load, out_loc, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
| 5475 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
| 5476 | __ movq(out, Address(out, mirror::Class::DexCacheStringsOffset().Uint32Value())); |
| 5477 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 5478 | GenerateGcRootFieldLoad( |
| 5479 | load, out_loc, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
| 5480 | break; |
| 5481 | } |
| 5482 | default: |
| 5483 | LOG(FATAL) << "Unexpected load kind: " << load->GetLoadKind(); |
| 5484 | UNREACHABLE(); |
| 5485 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5486 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5487 | if (!load->IsInDexCache()) { |
| 5488 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86_64(load); |
| 5489 | codegen_->AddSlowPath(slow_path); |
| 5490 | __ testl(out, out); |
| 5491 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5492 | __ Bind(slow_path->GetExitLabel()); |
| 5493 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5494 | } |
| 5495 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5496 | static Address GetExceptionTlsAddress() { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5497 | return Address::Absolute(Thread::ExceptionOffset<kX86_64WordSize>().Int32Value(), |
| 5498 | /* no_rip */ true); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5499 | } |
| 5500 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5501 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 5502 | LocationSummary* locations = |
| 5503 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5504 | locations->SetOut(Location::RequiresRegister()); |
| 5505 | } |
| 5506 | |
| 5507 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5508 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 5509 | } |
| 5510 | |
| 5511 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
| 5512 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5513 | } |
| 5514 | |
| 5515 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5516 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5517 | } |
| 5518 | |
| 5519 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| 5520 | LocationSummary* locations = |
| 5521 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5522 | InvokeRuntimeCallingConvention calling_convention; |
| 5523 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5524 | } |
| 5525 | |
| 5526 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5527 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 5528 | instruction, |
| 5529 | instruction->GetDexPc(), |
| 5530 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5531 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5532 | } |
| 5533 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5534 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5535 | return kEmitCompilerReadBarrier && |
| 5536 | (kUseBakerReadBarrier || |
| 5537 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5538 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5539 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5540 | } |
| 5541 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5542 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5543 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5544 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5545 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5546 | case TypeCheckKind::kExactCheck: |
| 5547 | case TypeCheckKind::kAbstractClassCheck: |
| 5548 | case TypeCheckKind::kClassHierarchyCheck: |
| 5549 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5550 | call_kind = |
| 5551 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5552 | break; |
| 5553 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5554 | case TypeCheckKind::kUnresolvedCheck: |
| 5555 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5556 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5557 | break; |
| 5558 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5559 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5560 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5561 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5562 | locations->SetInAt(1, Location::Any()); |
| 5563 | // Note that TypeCheckSlowPathX86_64 uses this "out" register too. |
| 5564 | locations->SetOut(Location::RequiresRegister()); |
| 5565 | // When read barriers are enabled, we need a temporary register for |
| 5566 | // some cases. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5567 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5568 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5569 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5570 | } |
| 5571 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5572 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5573 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5574 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5575 | Location obj_loc = locations->InAt(0); |
| 5576 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5577 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5578 | Location out_loc = locations->Out(); |
| 5579 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5580 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5581 | locations->GetTemp(0) : |
| 5582 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5583 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5584 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5585 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5586 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5587 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5588 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5589 | |
| 5590 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5591 | // Avoid null check if we know obj is not null. |
| 5592 | if (instruction->MustDoNullCheck()) { |
| 5593 | __ testl(obj, obj); |
| 5594 | __ j(kEqual, &zero); |
| 5595 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5596 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5597 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5598 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5599 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5600 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5601 | case TypeCheckKind::kExactCheck: { |
| 5602 | if (cls.IsRegister()) { |
| 5603 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5604 | } else { |
| 5605 | DCHECK(cls.IsStackSlot()) << cls; |
| 5606 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5607 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5608 | if (zero.IsLinked()) { |
| 5609 | // Classes must be equal for the instanceof to succeed. |
| 5610 | __ j(kNotEqual, &zero); |
| 5611 | __ movl(out, Immediate(1)); |
| 5612 | __ jmp(&done); |
| 5613 | } else { |
| 5614 | __ setcc(kEqual, out); |
| 5615 | // setcc only sets the low byte. |
| 5616 | __ andl(out, Immediate(1)); |
| 5617 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5618 | break; |
| 5619 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5620 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5621 | case TypeCheckKind::kAbstractClassCheck: { |
| 5622 | // If the class is abstract, we eagerly fetch the super class of the |
| 5623 | // object to avoid doing a comparison we know will fail. |
| 5624 | NearLabel loop, success; |
| 5625 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5626 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5627 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5628 | __ testl(out, out); |
| 5629 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5630 | __ j(kEqual, &done); |
| 5631 | if (cls.IsRegister()) { |
| 5632 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5633 | } else { |
| 5634 | DCHECK(cls.IsStackSlot()) << cls; |
| 5635 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5636 | } |
| 5637 | __ j(kNotEqual, &loop); |
| 5638 | __ movl(out, Immediate(1)); |
| 5639 | if (zero.IsLinked()) { |
| 5640 | __ jmp(&done); |
| 5641 | } |
| 5642 | break; |
| 5643 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5644 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5645 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5646 | // Walk over the class hierarchy to find a match. |
| 5647 | NearLabel loop, success; |
| 5648 | __ Bind(&loop); |
| 5649 | if (cls.IsRegister()) { |
| 5650 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5651 | } else { |
| 5652 | DCHECK(cls.IsStackSlot()) << cls; |
| 5653 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5654 | } |
| 5655 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5656 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5657 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5658 | __ testl(out, out); |
| 5659 | __ j(kNotEqual, &loop); |
| 5660 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5661 | __ jmp(&done); |
| 5662 | __ Bind(&success); |
| 5663 | __ movl(out, Immediate(1)); |
| 5664 | if (zero.IsLinked()) { |
| 5665 | __ jmp(&done); |
| 5666 | } |
| 5667 | break; |
| 5668 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5669 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5670 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5671 | // Do an exact check. |
| 5672 | NearLabel exact_check; |
| 5673 | if (cls.IsRegister()) { |
| 5674 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5675 | } else { |
| 5676 | DCHECK(cls.IsStackSlot()) << cls; |
| 5677 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5678 | } |
| 5679 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5680 | // 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] | 5681 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5682 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5683 | __ testl(out, out); |
| 5684 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5685 | __ j(kEqual, &done); |
| 5686 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5687 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5688 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5689 | __ movl(out, Immediate(1)); |
| 5690 | __ jmp(&done); |
| 5691 | break; |
| 5692 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5693 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5694 | case TypeCheckKind::kArrayCheck: { |
| 5695 | if (cls.IsRegister()) { |
| 5696 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5697 | } else { |
| 5698 | DCHECK(cls.IsStackSlot()) << cls; |
| 5699 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5700 | } |
| 5701 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5702 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5703 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5704 | codegen_->AddSlowPath(slow_path); |
| 5705 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5706 | __ movl(out, Immediate(1)); |
| 5707 | if (zero.IsLinked()) { |
| 5708 | __ jmp(&done); |
| 5709 | } |
| 5710 | break; |
| 5711 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5712 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5713 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5714 | case TypeCheckKind::kInterfaceCheck: { |
| 5715 | // 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] | 5716 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5717 | // cases. |
| 5718 | // |
| 5719 | // We cannot directly call the InstanceofNonTrivial runtime |
| 5720 | // entry point without resorting to a type checking slow path |
| 5721 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 5722 | // require to assign fixed registers for the inputs of this |
| 5723 | // HInstanceOf instruction (following the runtime calling |
| 5724 | // convention), which might be cluttered by the potential first |
| 5725 | // read barrier emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5726 | // |
| 5727 | // TODO: Introduce a new runtime entry point taking the object |
| 5728 | // to test (instead of its class) as argument, and let it deal |
| 5729 | // with the read barrier issues. This will let us refactor this |
| 5730 | // case of the `switch` code as it was previously (with a direct |
| 5731 | // call to the runtime not using a type checking slow path). |
| 5732 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5733 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5734 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5735 | /* is_fatal */ false); |
| 5736 | codegen_->AddSlowPath(slow_path); |
| 5737 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5738 | if (zero.IsLinked()) { |
| 5739 | __ jmp(&done); |
| 5740 | } |
| 5741 | break; |
| 5742 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5743 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5744 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5745 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5746 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5747 | __ xorl(out, out); |
| 5748 | } |
| 5749 | |
| 5750 | if (done.IsLinked()) { |
| 5751 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5752 | } |
| 5753 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5754 | if (slow_path != nullptr) { |
| 5755 | __ Bind(slow_path->GetExitLabel()); |
| 5756 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5757 | } |
| 5758 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5759 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5760 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5761 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5762 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5763 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5764 | case TypeCheckKind::kExactCheck: |
| 5765 | case TypeCheckKind::kAbstractClassCheck: |
| 5766 | case TypeCheckKind::kClassHierarchyCheck: |
| 5767 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5768 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 5769 | LocationSummary::kCallOnSlowPath : |
| 5770 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5771 | break; |
| 5772 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5773 | case TypeCheckKind::kUnresolvedCheck: |
| 5774 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5775 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5776 | break; |
| 5777 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5778 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 5779 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5780 | locations->SetInAt(1, Location::Any()); |
| 5781 | // Note that TypeCheckSlowPathX86_64 uses this "temp" register too. |
| 5782 | locations->AddTemp(Location::RequiresRegister()); |
| 5783 | // When read barriers are enabled, we need an additional temporary |
| 5784 | // register for some cases. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5785 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5786 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5787 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5788 | } |
| 5789 | |
| 5790 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5791 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5792 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5793 | Location obj_loc = locations->InAt(0); |
| 5794 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5795 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5796 | Location temp_loc = locations->GetTemp(0); |
| 5797 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5798 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5799 | locations->GetTemp(1) : |
| 5800 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5801 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5802 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5803 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5804 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5805 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5806 | bool is_type_check_slow_path_fatal = |
| 5807 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 5808 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5809 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5810 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 5811 | !instruction->CanThrowIntoCatchBlock(); |
| 5812 | SlowPathCode* type_check_slow_path = |
| 5813 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5814 | is_type_check_slow_path_fatal); |
| 5815 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5816 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5817 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5818 | case TypeCheckKind::kExactCheck: |
| 5819 | case TypeCheckKind::kArrayCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5820 | NearLabel done; |
| 5821 | // Avoid null check if we know obj is not null. |
| 5822 | if (instruction->MustDoNullCheck()) { |
| 5823 | __ testl(obj, obj); |
| 5824 | __ j(kEqual, &done); |
| 5825 | } |
| 5826 | |
| 5827 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5828 | GenerateReferenceLoadTwoRegisters( |
| 5829 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
| 5830 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5831 | if (cls.IsRegister()) { |
| 5832 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5833 | } else { |
| 5834 | DCHECK(cls.IsStackSlot()) << cls; |
| 5835 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5836 | } |
| 5837 | // Jump to slow path for throwing the exception or doing a |
| 5838 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5839 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5840 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5841 | break; |
| 5842 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5843 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5844 | case TypeCheckKind::kAbstractClassCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5845 | NearLabel done; |
| 5846 | // Avoid null check if we know obj is not null. |
| 5847 | if (instruction->MustDoNullCheck()) { |
| 5848 | __ testl(obj, obj); |
| 5849 | __ j(kEqual, &done); |
| 5850 | } |
| 5851 | |
| 5852 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5853 | GenerateReferenceLoadTwoRegisters( |
| 5854 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
| 5855 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5856 | // If the class is abstract, we eagerly fetch the super class of the |
| 5857 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5858 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5859 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5860 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5861 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5862 | |
| 5863 | // If the class reference currently in `temp` is not null, jump |
| 5864 | // to the `compare_classes` label to compare it with the checked |
| 5865 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5866 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5867 | __ j(kNotEqual, &compare_classes); |
| 5868 | // Otherwise, jump to the slow path to throw the exception. |
| 5869 | // |
| 5870 | // But before, move back the object's class into `temp` before |
| 5871 | // going into the slow path, as it has been overwritten in the |
| 5872 | // meantime. |
| 5873 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5874 | GenerateReferenceLoadTwoRegisters( |
| 5875 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5876 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 5877 | |
| 5878 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5879 | if (cls.IsRegister()) { |
| 5880 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5881 | } else { |
| 5882 | DCHECK(cls.IsStackSlot()) << cls; |
| 5883 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5884 | } |
| 5885 | __ j(kNotEqual, &loop); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5886 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5887 | break; |
| 5888 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5889 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5890 | case TypeCheckKind::kClassHierarchyCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5891 | NearLabel done; |
| 5892 | // Avoid null check if we know obj is not null. |
| 5893 | if (instruction->MustDoNullCheck()) { |
| 5894 | __ testl(obj, obj); |
| 5895 | __ j(kEqual, &done); |
| 5896 | } |
| 5897 | |
| 5898 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5899 | GenerateReferenceLoadTwoRegisters( |
| 5900 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
| 5901 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5902 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5903 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5904 | __ Bind(&loop); |
| 5905 | if (cls.IsRegister()) { |
| 5906 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5907 | } else { |
| 5908 | DCHECK(cls.IsStackSlot()) << cls; |
| 5909 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5910 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5911 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5912 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5913 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5914 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5915 | |
| 5916 | // If the class reference currently in `temp` is not null, jump |
| 5917 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5918 | __ testl(temp, temp); |
| 5919 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5920 | // Otherwise, jump to the slow path to throw the exception. |
| 5921 | // |
| 5922 | // But before, move back the object's class into `temp` before |
| 5923 | // going into the slow path, as it has been overwritten in the |
| 5924 | // meantime. |
| 5925 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5926 | GenerateReferenceLoadTwoRegisters( |
| 5927 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5928 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5929 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5930 | break; |
| 5931 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5932 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5933 | case TypeCheckKind::kArrayObjectCheck: { |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5934 | // We cannot use a NearLabel here, as its range might be too |
| 5935 | // short in some cases when read barriers are enabled. This has |
| 5936 | // been observed for instance when the code emitted for this |
| 5937 | // case uses high x86-64 registers (R8-R15). |
| 5938 | Label done; |
| 5939 | // Avoid null check if we know obj is not null. |
| 5940 | if (instruction->MustDoNullCheck()) { |
| 5941 | __ testl(obj, obj); |
| 5942 | __ j(kEqual, &done); |
| 5943 | } |
| 5944 | |
| 5945 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 5946 | GenerateReferenceLoadTwoRegisters( |
| 5947 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
| 5948 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5949 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5950 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5951 | if (cls.IsRegister()) { |
| 5952 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5953 | } else { |
| 5954 | DCHECK(cls.IsStackSlot()) << cls; |
| 5955 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5956 | } |
| 5957 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5958 | |
| 5959 | // 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] | 5960 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5961 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5962 | |
| 5963 | // If the component type is not null (i.e. the object is indeed |
| 5964 | // an array), jump to label `check_non_primitive_component_type` |
| 5965 | // to further check that this component type is not a primitive |
| 5966 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5967 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5968 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 5969 | // Otherwise, jump to the slow path to throw the exception. |
| 5970 | // |
| 5971 | // But before, move back the object's class into `temp` before |
| 5972 | // going into the slow path, as it has been overwritten in the |
| 5973 | // meantime. |
| 5974 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5975 | GenerateReferenceLoadTwoRegisters( |
| 5976 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5977 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 5978 | |
| 5979 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5980 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5981 | __ j(kEqual, &done); |
| 5982 | // Same comment as above regarding `temp` and the slow path. |
| 5983 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5984 | GenerateReferenceLoadTwoRegisters( |
| 5985 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5986 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5987 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5988 | break; |
| 5989 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5990 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5991 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5992 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5993 | NearLabel done; |
| 5994 | // Avoid null check if we know obj is not null. |
| 5995 | if (instruction->MustDoNullCheck()) { |
| 5996 | __ testl(obj, obj); |
| 5997 | __ j(kEqual, &done); |
| 5998 | } |
| 5999 | |
| 6000 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6001 | GenerateReferenceLoadTwoRegisters( |
| 6002 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
| 6003 | |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6004 | // We always go into the type check slow path for the unresolved |
| 6005 | // and interface check cases. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6006 | // |
| 6007 | // We cannot directly call the CheckCast runtime entry point |
| 6008 | // without resorting to a type checking slow path here (i.e. by |
| 6009 | // calling InvokeRuntime directly), as it would require to |
| 6010 | // assign fixed registers for the inputs of this HInstanceOf |
| 6011 | // instruction (following the runtime calling convention), which |
| 6012 | // might be cluttered by the potential first read barrier |
| 6013 | // emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6014 | // |
| 6015 | // TODO: Introduce a new runtime entry point taking the object |
| 6016 | // to test (instead of its class) as argument, and let it deal |
| 6017 | // with the read barrier issues. This will let us refactor this |
| 6018 | // case of the `switch` code as it was previously (with a direct |
| 6019 | // call to the runtime not using a type checking slow path). |
| 6020 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6021 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 6022 | __ Bind(&done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6023 | break; |
| 6024 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6025 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6026 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6027 | } |
| 6028 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6029 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6030 | LocationSummary* locations = |
| 6031 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 6032 | InvokeRuntimeCallingConvention calling_convention; |
| 6033 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6034 | } |
| 6035 | |
| 6036 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6037 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 6038 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 6039 | instruction, |
| 6040 | instruction->GetDexPc(), |
| 6041 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6042 | if (instruction->IsEnter()) { |
| 6043 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6044 | } else { |
| 6045 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6046 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6047 | } |
| 6048 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6049 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6050 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6051 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6052 | |
| 6053 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6054 | LocationSummary* locations = |
| 6055 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6056 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6057 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6058 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6059 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6060 | locations->SetOut(Location::SameAsFirstInput()); |
| 6061 | } |
| 6062 | |
| 6063 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 6064 | HandleBitwiseOperation(instruction); |
| 6065 | } |
| 6066 | |
| 6067 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 6068 | HandleBitwiseOperation(instruction); |
| 6069 | } |
| 6070 | |
| 6071 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 6072 | HandleBitwiseOperation(instruction); |
| 6073 | } |
| 6074 | |
| 6075 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6076 | LocationSummary* locations = instruction->GetLocations(); |
| 6077 | Location first = locations->InAt(0); |
| 6078 | Location second = locations->InAt(1); |
| 6079 | DCHECK(first.Equals(locations->Out())); |
| 6080 | |
| 6081 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6082 | if (second.IsRegister()) { |
| 6083 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6084 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6085 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6086 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6087 | } else { |
| 6088 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6089 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6090 | } |
| 6091 | } else if (second.IsConstant()) { |
| 6092 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 6093 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6094 | __ andl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6095 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6096 | __ orl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6097 | } else { |
| 6098 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6099 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6100 | } |
| 6101 | } else { |
| 6102 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 6103 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6104 | __ andl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6105 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6106 | __ orl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6107 | } else { |
| 6108 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6109 | __ xorl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6110 | } |
| 6111 | } |
| 6112 | } else { |
| 6113 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6114 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 6115 | bool second_is_constant = false; |
| 6116 | int64_t value = 0; |
| 6117 | if (second.IsConstant()) { |
| 6118 | second_is_constant = true; |
| 6119 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6120 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6121 | bool is_int32_value = IsInt<32>(value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6122 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6123 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6124 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6125 | if (is_int32_value) { |
| 6126 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6127 | } else { |
| 6128 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6129 | } |
| 6130 | } else if (second.IsDoubleStackSlot()) { |
| 6131 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6132 | } else { |
| 6133 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 6134 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6135 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6136 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6137 | if (is_int32_value) { |
| 6138 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6139 | } else { |
| 6140 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6141 | } |
| 6142 | } else if (second.IsDoubleStackSlot()) { |
| 6143 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6144 | } else { |
| 6145 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 6146 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6147 | } else { |
| 6148 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6149 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6150 | if (is_int32_value) { |
| 6151 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6152 | } else { |
| 6153 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6154 | } |
| 6155 | } else if (second.IsDoubleStackSlot()) { |
| 6156 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6157 | } else { |
| 6158 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 6159 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6160 | } |
| 6161 | } |
| 6162 | } |
| 6163 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6164 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6165 | Location out, |
| 6166 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6167 | Location maybe_temp) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6168 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6169 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6170 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6171 | if (kUseBakerReadBarrier) { |
| 6172 | // Load with fast path based Baker's read barrier. |
| 6173 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6174 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6175 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6176 | } else { |
| 6177 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6178 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6179 | // in the following move operation, as we will need it for the |
| 6180 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6181 | __ movl(maybe_temp.AsRegister<CpuRegister>(), out_reg); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6182 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6183 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6184 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6185 | } |
| 6186 | } else { |
| 6187 | // Plain load with no read barrier. |
| 6188 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6189 | __ movl(out_reg, Address(out_reg, offset)); |
| 6190 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6191 | } |
| 6192 | } |
| 6193 | |
| 6194 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6195 | Location out, |
| 6196 | Location obj, |
| 6197 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6198 | Location maybe_temp) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6199 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6200 | CpuRegister obj_reg = obj.AsRegister<CpuRegister>(); |
| 6201 | if (kEmitCompilerReadBarrier) { |
| 6202 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6203 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6204 | // Load with fast path based Baker's read barrier. |
| 6205 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6206 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6207 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6208 | } else { |
| 6209 | // Load with slow path based read barrier. |
| 6210 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6211 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6212 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6213 | } |
| 6214 | } else { |
| 6215 | // Plain load with no read barrier. |
| 6216 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6217 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6218 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6219 | } |
| 6220 | } |
| 6221 | |
| 6222 | void InstructionCodeGeneratorX86_64::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6223 | Location root, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6224 | const Address& address, |
| 6225 | Label* fixup_label) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6226 | CpuRegister root_reg = root.AsRegister<CpuRegister>(); |
| 6227 | if (kEmitCompilerReadBarrier) { |
| 6228 | if (kUseBakerReadBarrier) { |
| 6229 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6230 | // Baker's read barrier are used: |
| 6231 | // |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6232 | // root = *address; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6233 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6234 | // root = ReadBarrier::Mark(root) |
| 6235 | // } |
| 6236 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6237 | // /* GcRoot<mirror::Object> */ root = *address |
| 6238 | __ movl(root_reg, address); |
| 6239 | if (fixup_label != nullptr) { |
| 6240 | __ Bind(fixup_label); |
| 6241 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6242 | static_assert( |
| 6243 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6244 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6245 | "have different sizes."); |
| 6246 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6247 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6248 | "have different sizes."); |
| 6249 | |
| 6250 | // Slow path used to mark the GC root `root`. |
| 6251 | SlowPathCode* slow_path = |
| 6252 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64(instruction, root, root); |
| 6253 | codegen_->AddSlowPath(slow_path); |
| 6254 | |
| 6255 | __ gs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86_64WordSize>().Int32Value(), |
| 6256 | /* no_rip */ true), |
| 6257 | Immediate(0)); |
| 6258 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6259 | __ Bind(slow_path->GetExitLabel()); |
| 6260 | } else { |
| 6261 | // GC root loaded through a slow path for read barriers other |
| 6262 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6263 | // /* GcRoot<mirror::Object>* */ root = address |
| 6264 | __ leaq(root_reg, address); |
| 6265 | if (fixup_label != nullptr) { |
| 6266 | __ Bind(fixup_label); |
| 6267 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6268 | // /* mirror::Object* */ root = root->Read() |
| 6269 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6270 | } |
| 6271 | } else { |
| 6272 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6273 | // /* GcRoot<mirror::Object> */ root = *address |
| 6274 | __ movl(root_reg, address); |
| 6275 | if (fixup_label != nullptr) { |
| 6276 | __ Bind(fixup_label); |
| 6277 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6278 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6279 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6280 | } |
| 6281 | } |
| 6282 | |
| 6283 | void CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6284 | Location ref, |
| 6285 | CpuRegister obj, |
| 6286 | uint32_t offset, |
| 6287 | Location temp, |
| 6288 | bool needs_null_check) { |
| 6289 | DCHECK(kEmitCompilerReadBarrier); |
| 6290 | DCHECK(kUseBakerReadBarrier); |
| 6291 | |
| 6292 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6293 | Address src(obj, offset); |
| 6294 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6295 | } |
| 6296 | |
| 6297 | void CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6298 | Location ref, |
| 6299 | CpuRegister obj, |
| 6300 | uint32_t data_offset, |
| 6301 | Location index, |
| 6302 | Location temp, |
| 6303 | bool needs_null_check) { |
| 6304 | DCHECK(kEmitCompilerReadBarrier); |
| 6305 | DCHECK(kUseBakerReadBarrier); |
| 6306 | |
| 6307 | // /* HeapReference<Object> */ ref = |
| 6308 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6309 | Address src = index.IsConstant() ? |
| 6310 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset) : |
| 6311 | Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset); |
| 6312 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6313 | } |
| 6314 | |
| 6315 | void CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6316 | Location ref, |
| 6317 | CpuRegister obj, |
| 6318 | const Address& src, |
| 6319 | Location temp, |
| 6320 | bool needs_null_check) { |
| 6321 | DCHECK(kEmitCompilerReadBarrier); |
| 6322 | DCHECK(kUseBakerReadBarrier); |
| 6323 | |
| 6324 | // In slow path based read barriers, the read barrier call is |
| 6325 | // inserted after the original load. However, in fast path based |
| 6326 | // Baker's read barriers, we need to perform the load of |
| 6327 | // mirror::Object::monitor_ *before* the original reference load. |
| 6328 | // This load-load ordering is required by the read barrier. |
| 6329 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6330 | // |
| 6331 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6332 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6333 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6334 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6335 | // if (is_gray) { |
| 6336 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6337 | // } |
| 6338 | // |
| 6339 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6340 | // slightly more complex as: |
| 6341 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6342 | // the high-bits of rb_state, which are expected to be all zeroes |
| 6343 | // (we use CodeGeneratorX86_64::GenerateMemoryBarrier instead |
| 6344 | // 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] | 6345 | // - it performs additional checks that we do not do here for |
| 6346 | // performance reasons. |
| 6347 | |
| 6348 | CpuRegister ref_reg = ref.AsRegister<CpuRegister>(); |
| 6349 | CpuRegister temp_reg = temp.AsRegister<CpuRegister>(); |
| 6350 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6351 | |
| 6352 | // /* int32_t */ monitor = obj->monitor_ |
| 6353 | __ movl(temp_reg, Address(obj, monitor_offset)); |
| 6354 | if (needs_null_check) { |
| 6355 | MaybeRecordImplicitNullCheck(instruction); |
| 6356 | } |
| 6357 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6358 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6359 | "art::LockWord and int32_t have different sizes."); |
| 6360 | // /* uint32_t */ rb_state = lock_word.ReadBarrierState() |
| 6361 | __ shrl(temp_reg, Immediate(LockWord::kReadBarrierStateShift)); |
| 6362 | __ andl(temp_reg, Immediate(LockWord::kReadBarrierStateMask)); |
| 6363 | static_assert( |
| 6364 | LockWord::kReadBarrierStateMask == ReadBarrier::rb_ptr_mask_, |
| 6365 | "art::LockWord::kReadBarrierStateMask is not equal to art::ReadBarrier::rb_ptr_mask_."); |
| 6366 | |
| 6367 | // Load fence to prevent load-load reordering. |
| 6368 | // Note that this is a no-op, thanks to the x86-64 memory model. |
| 6369 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6370 | |
| 6371 | // The actual reference load. |
| 6372 | // /* HeapReference<Object> */ ref = *src |
| 6373 | __ movl(ref_reg, src); |
| 6374 | |
| 6375 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6376 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6377 | |
| 6378 | // Slow path used to mark the object `ref` when it is gray. |
| 6379 | SlowPathCode* slow_path = |
| 6380 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64(instruction, ref, ref); |
| 6381 | AddSlowPath(slow_path); |
| 6382 | |
| 6383 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6384 | // ref = ReadBarrier::Mark(ref); |
| 6385 | __ cmpl(temp_reg, Immediate(ReadBarrier::gray_ptr_)); |
| 6386 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6387 | __ Bind(slow_path->GetExitLabel()); |
| 6388 | } |
| 6389 | |
| 6390 | void CodeGeneratorX86_64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6391 | Location out, |
| 6392 | Location ref, |
| 6393 | Location obj, |
| 6394 | uint32_t offset, |
| 6395 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6396 | DCHECK(kEmitCompilerReadBarrier); |
| 6397 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6398 | // Insert a slow path based read barrier *after* the reference load. |
| 6399 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6400 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6401 | // reference will be carried out by the runtime within the slow |
| 6402 | // path. |
| 6403 | // |
| 6404 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6405 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6406 | // not used by the artReadBarrierSlow entry point. |
| 6407 | // |
| 6408 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6409 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6410 | ReadBarrierForHeapReferenceSlowPathX86_64(instruction, out, ref, obj, offset, index); |
| 6411 | AddSlowPath(slow_path); |
| 6412 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6413 | __ jmp(slow_path->GetEntryLabel()); |
| 6414 | __ Bind(slow_path->GetExitLabel()); |
| 6415 | } |
| 6416 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6417 | void CodeGeneratorX86_64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6418 | Location out, |
| 6419 | Location ref, |
| 6420 | Location obj, |
| 6421 | uint32_t offset, |
| 6422 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6423 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6424 | // Baker's read barriers shall be handled by the fast path |
| 6425 | // (CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6426 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6427 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6428 | // by the runtime within the slow path. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6429 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6430 | } else if (kPoisonHeapReferences) { |
| 6431 | __ UnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 6432 | } |
| 6433 | } |
| 6434 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6435 | void CodeGeneratorX86_64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6436 | Location out, |
| 6437 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6438 | DCHECK(kEmitCompilerReadBarrier); |
| 6439 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6440 | // Insert a slow path based read barrier *after* the GC root load. |
| 6441 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6442 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6443 | // not need to do anything special for this here. |
| 6444 | SlowPathCode* slow_path = |
| 6445 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86_64(instruction, out, root); |
| 6446 | AddSlowPath(slow_path); |
| 6447 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6448 | __ jmp(slow_path->GetEntryLabel()); |
| 6449 | __ Bind(slow_path->GetExitLabel()); |
| 6450 | } |
| 6451 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6452 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6453 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6454 | LOG(FATAL) << "Unreachable"; |
| 6455 | } |
| 6456 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6457 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6458 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6459 | LOG(FATAL) << "Unreachable"; |
| 6460 | } |
| 6461 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6462 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6463 | void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6464 | LocationSummary* locations = |
| 6465 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6466 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6467 | locations->AddTemp(Location::RequiresRegister()); |
| 6468 | locations->AddTemp(Location::RequiresRegister()); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6469 | } |
| 6470 | |
| 6471 | void InstructionCodeGeneratorX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6472 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6473 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6474 | LocationSummary* locations = switch_instr->GetLocations(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6475 | CpuRegister value_reg_in = locations->InAt(0).AsRegister<CpuRegister>(); |
| 6476 | CpuRegister temp_reg = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 6477 | CpuRegister base_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6478 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6479 | |
| 6480 | // Should we generate smaller inline compare/jumps? |
| 6481 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 6482 | // Figure out the correct compare values and jump conditions. |
| 6483 | // Handle the first compare/branch as a special case because it might |
| 6484 | // jump to the default case. |
| 6485 | DCHECK_GT(num_entries, 2u); |
| 6486 | Condition first_condition; |
| 6487 | uint32_t index; |
| 6488 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 6489 | if (lower_bound != 0) { |
| 6490 | first_condition = kLess; |
| 6491 | __ cmpl(value_reg_in, Immediate(lower_bound)); |
| 6492 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 6493 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
| 6494 | |
| 6495 | index = 1; |
| 6496 | } else { |
| 6497 | // Handle all the compare/jumps below. |
| 6498 | first_condition = kBelow; |
| 6499 | index = 0; |
| 6500 | } |
| 6501 | |
| 6502 | // Handle the rest of the compare/jumps. |
| 6503 | for (; index + 1 < num_entries; index += 2) { |
| 6504 | int32_t compare_to_value = lower_bound + index + 1; |
| 6505 | __ cmpl(value_reg_in, Immediate(compare_to_value)); |
| 6506 | // Jump to successors[index] if value < case_value[index]. |
| 6507 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 6508 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 6509 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 6510 | } |
| 6511 | |
| 6512 | if (index != num_entries) { |
| 6513 | // There are an odd number of entries. Handle the last one. |
| 6514 | DCHECK_EQ(index + 1, num_entries); |
Nicolas Geoffray | 6ce0173 | 2015-12-30 14:10:13 +0000 | [diff] [blame] | 6515 | __ cmpl(value_reg_in, Immediate(static_cast<int32_t>(lower_bound + index))); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6516 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
| 6517 | } |
| 6518 | |
| 6519 | // And the default for any other value. |
| 6520 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6521 | __ jmp(codegen_->GetLabelOf(default_block)); |
| 6522 | } |
| 6523 | return; |
| 6524 | } |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6525 | |
| 6526 | // Remove the bias, if needed. |
| 6527 | Register value_reg_out = value_reg_in.AsRegister(); |
| 6528 | if (lower_bound != 0) { |
| 6529 | __ leal(temp_reg, Address(value_reg_in, -lower_bound)); |
| 6530 | value_reg_out = temp_reg.AsRegister(); |
| 6531 | } |
| 6532 | CpuRegister value_reg(value_reg_out); |
| 6533 | |
| 6534 | // Is the value in range? |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6535 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 6536 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6537 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6538 | // We are in the range of the table. |
| 6539 | // Load the address of the jump table in the constant area. |
| 6540 | __ leaq(base_reg, codegen_->LiteralCaseTable(switch_instr)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6541 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6542 | // Load the (signed) offset from the jump table. |
| 6543 | __ movsxd(temp_reg, Address(base_reg, value_reg, TIMES_4, 0)); |
| 6544 | |
| 6545 | // Add the offset to the address of the table base. |
| 6546 | __ addq(temp_reg, base_reg); |
| 6547 | |
| 6548 | // And jump. |
| 6549 | __ jmp(temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6550 | } |
| 6551 | |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6552 | void CodeGeneratorX86_64::Load32BitValue(CpuRegister dest, int32_t value) { |
| 6553 | if (value == 0) { |
| 6554 | __ xorl(dest, dest); |
| 6555 | } else { |
| 6556 | __ movl(dest, Immediate(value)); |
| 6557 | } |
| 6558 | } |
| 6559 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6560 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 6561 | if (value == 0) { |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6562 | // Clears upper bits too. |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6563 | __ xorl(dest, dest); |
Vladimir Marko | ed00978 | 2016-02-22 16:54:39 +0000 | [diff] [blame] | 6564 | } else if (IsUint<32>(value)) { |
| 6565 | // 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] | 6566 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 6567 | } else { |
| 6568 | __ movq(dest, Immediate(value)); |
| 6569 | } |
| 6570 | } |
| 6571 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame] | 6572 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, int32_t value) { |
| 6573 | if (value == 0) { |
| 6574 | __ xorps(dest, dest); |
| 6575 | } else { |
| 6576 | __ movss(dest, LiteralInt32Address(value)); |
| 6577 | } |
| 6578 | } |
| 6579 | |
| 6580 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, int64_t value) { |
| 6581 | if (value == 0) { |
| 6582 | __ xorpd(dest, dest); |
| 6583 | } else { |
| 6584 | __ movsd(dest, LiteralInt64Address(value)); |
| 6585 | } |
| 6586 | } |
| 6587 | |
| 6588 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, float value) { |
| 6589 | Load32BitValue(dest, bit_cast<int32_t, float>(value)); |
| 6590 | } |
| 6591 | |
| 6592 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, double value) { |
| 6593 | Load64BitValue(dest, bit_cast<int64_t, double>(value)); |
| 6594 | } |
| 6595 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 6596 | void CodeGeneratorX86_64::Compare32BitValue(CpuRegister dest, int32_t value) { |
| 6597 | if (value == 0) { |
| 6598 | __ testl(dest, dest); |
| 6599 | } else { |
| 6600 | __ cmpl(dest, Immediate(value)); |
| 6601 | } |
| 6602 | } |
| 6603 | |
| 6604 | void CodeGeneratorX86_64::Compare64BitValue(CpuRegister dest, int64_t value) { |
| 6605 | if (IsInt<32>(value)) { |
| 6606 | if (value == 0) { |
| 6607 | __ testq(dest, dest); |
| 6608 | } else { |
| 6609 | __ cmpq(dest, Immediate(static_cast<int32_t>(value))); |
| 6610 | } |
| 6611 | } else { |
| 6612 | // Value won't fit in an int. |
| 6613 | __ cmpq(dest, LiteralInt64Address(value)); |
| 6614 | } |
| 6615 | } |
| 6616 | |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 6617 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 6618 | DCHECK(dest.IsDoubleStackSlot()); |
| 6619 | if (IsInt<32>(value)) { |
| 6620 | // Can move directly as an int32 constant. |
| 6621 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 6622 | Immediate(static_cast<int32_t>(value))); |
| 6623 | } else { |
| 6624 | Load64BitValue(CpuRegister(TMP), value); |
| 6625 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 6626 | } |
| 6627 | } |
| 6628 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6629 | /** |
| 6630 | * Class to handle late fixup of offsets into constant area. |
| 6631 | */ |
| 6632 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| 6633 | public: |
| 6634 | RIPFixup(CodeGeneratorX86_64& codegen, size_t offset) |
| 6635 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 6636 | |
| 6637 | protected: |
| 6638 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 6639 | |
| 6640 | CodeGeneratorX86_64* codegen_; |
| 6641 | |
| 6642 | private: |
| 6643 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 6644 | // Patch the correct offset for the instruction. We use the address of the |
| 6645 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 6646 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 6647 | int32_t relative_position = constant_offset - pos; |
| 6648 | |
| 6649 | // Patch in the right value. |
| 6650 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 6651 | } |
| 6652 | |
| 6653 | // Location in constant area that the fixup refers to. |
| 6654 | size_t offset_into_constant_area_; |
| 6655 | }; |
| 6656 | |
| 6657 | /** |
| 6658 | t * Class to handle late fixup of offsets to a jump table that will be created in the |
| 6659 | * constant area. |
| 6660 | */ |
| 6661 | class JumpTableRIPFixup : public RIPFixup { |
| 6662 | public: |
| 6663 | JumpTableRIPFixup(CodeGeneratorX86_64& codegen, HPackedSwitch* switch_instr) |
| 6664 | : RIPFixup(codegen, -1), switch_instr_(switch_instr) {} |
| 6665 | |
| 6666 | void CreateJumpTable() { |
| 6667 | X86_64Assembler* assembler = codegen_->GetAssembler(); |
| 6668 | |
| 6669 | // Ensure that the reference to the jump table has the correct offset. |
| 6670 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 6671 | SetOffset(offset_in_constant_table); |
| 6672 | |
| 6673 | // Compute the offset from the start of the function to this jump table. |
| 6674 | const int32_t current_table_offset = assembler->CodeSize() + offset_in_constant_table; |
| 6675 | |
| 6676 | // Populate the jump table with the correct values for the jump table. |
| 6677 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 6678 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 6679 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 6680 | // The value that we want is the target offset - the position of the table. |
| 6681 | for (int32_t i = 0; i < num_entries; i++) { |
| 6682 | HBasicBlock* b = successors[i]; |
| 6683 | Label* l = codegen_->GetLabelOf(b); |
| 6684 | DCHECK(l->IsBound()); |
| 6685 | int32_t offset_to_block = l->Position() - current_table_offset; |
| 6686 | assembler->AppendInt32(offset_to_block); |
| 6687 | } |
| 6688 | } |
| 6689 | |
| 6690 | private: |
| 6691 | const HPackedSwitch* switch_instr_; |
| 6692 | }; |
| 6693 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6694 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 6695 | // Generate the constant area if needed. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 6696 | X86_64Assembler* assembler = GetAssembler(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6697 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 6698 | // 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] | 6699 | assembler->Align(4, 0); |
| 6700 | constant_area_start_ = assembler->CodeSize(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6701 | |
| 6702 | // Populate any jump tables. |
| 6703 | for (auto jump_table : fixups_to_jump_tables_) { |
| 6704 | jump_table->CreateJumpTable(); |
| 6705 | } |
| 6706 | |
| 6707 | // And now add the constant area to the generated code. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 6708 | assembler->AddConstantArea(); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6709 | } |
| 6710 | |
| 6711 | // And finish up. |
| 6712 | CodeGenerator::Finalize(allocator); |
| 6713 | } |
| 6714 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6715 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
| 6716 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 6717 | return Address::RIP(fixup); |
| 6718 | } |
| 6719 | |
| 6720 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
| 6721 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 6722 | return Address::RIP(fixup); |
| 6723 | } |
| 6724 | |
| 6725 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
| 6726 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 6727 | return Address::RIP(fixup); |
| 6728 | } |
| 6729 | |
| 6730 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
| 6731 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 6732 | return Address::RIP(fixup); |
| 6733 | } |
| 6734 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6735 | // TODO: trg as memory. |
| 6736 | void CodeGeneratorX86_64::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 6737 | if (!trg.IsValid()) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6738 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6739 | return; |
| 6740 | } |
| 6741 | |
| 6742 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 6743 | |
| 6744 | Location return_loc = InvokeDexCallingConventionVisitorX86_64().GetReturnLocation(type); |
| 6745 | if (trg.Equals(return_loc)) { |
| 6746 | return; |
| 6747 | } |
| 6748 | |
| 6749 | // Let the parallel move resolver take care of all of this. |
| 6750 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 6751 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 6752 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 6753 | } |
| 6754 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6755 | Address CodeGeneratorX86_64::LiteralCaseTable(HPackedSwitch* switch_instr) { |
| 6756 | // Create a fixup to be used to create and address the jump table. |
| 6757 | JumpTableRIPFixup* table_fixup = |
| 6758 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 6759 | |
| 6760 | // We have to populate the jump tables. |
| 6761 | fixups_to_jump_tables_.push_back(table_fixup); |
| 6762 | return Address::RIP(table_fixup); |
| 6763 | } |
| 6764 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 6765 | void CodeGeneratorX86_64::MoveInt64ToAddress(const Address& addr_low, |
| 6766 | const Address& addr_high, |
| 6767 | int64_t v, |
| 6768 | HInstruction* instruction) { |
| 6769 | if (IsInt<32>(v)) { |
| 6770 | int32_t v_32 = v; |
| 6771 | __ movq(addr_low, Immediate(v_32)); |
| 6772 | MaybeRecordImplicitNullCheck(instruction); |
| 6773 | } else { |
| 6774 | // Didn't fit in a register. Do it in pieces. |
| 6775 | int32_t low_v = Low32Bits(v); |
| 6776 | int32_t high_v = High32Bits(v); |
| 6777 | __ movl(addr_low, Immediate(low_v)); |
| 6778 | MaybeRecordImplicitNullCheck(instruction); |
| 6779 | __ movl(addr_high, Immediate(high_v)); |
| 6780 | } |
| 6781 | } |
| 6782 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6783 | #undef __ |
| 6784 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 6785 | } // namespace x86_64 |
| 6786 | } // namespace art |