Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_x86_64.h" |
| 18 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 19 | #include "art_method.h" |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 20 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 21 | #include "compiled_method.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 22 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 23 | #include "gc/accounting/card_table.h" |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 24 | #include "intrinsics.h" |
| 25 | #include "intrinsics_x86_64.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 26 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 27 | #include "mirror/class-inl.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 28 | #include "mirror/object_reference.h" |
| 29 | #include "thread.h" |
| 30 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 31 | #include "utils/stack_checks.h" |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 32 | #include "utils/x86_64/assembler_x86_64.h" |
| 33 | #include "utils/x86_64/managed_register_x86_64.h" |
| 34 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 35 | namespace art { |
| 36 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 37 | template<class MirrorType> |
| 38 | class GcRoot; |
| 39 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 40 | namespace x86_64 { |
| 41 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 42 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 43 | static constexpr Register kMethodRegisterArgument = RDI; |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 44 | // The compare/jump sequence will generate about (1.5 * num_entries) instructions. A jump |
| 45 | // table version generates 7 instructions and num_entries literals. Compare/jump sequence will |
| 46 | // generates less code/data with a small num_entries. |
| 47 | static constexpr uint32_t kPackedSwitchJumpTableThreshold = 5; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 48 | |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 49 | static constexpr Register kCoreCalleeSaves[] = { RBX, RBP, R12, R13, R14, R15 }; |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 50 | static constexpr FloatRegister kFpuCalleeSaves[] = { XMM12, XMM13, XMM14, XMM15 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 51 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 52 | static constexpr int kC2ConditionMask = 0x400; |
| 53 | |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 54 | #define __ down_cast<X86_64Assembler*>(codegen->GetAssembler())-> |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 55 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 56 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 57 | class NullCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 58 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 59 | explicit NullCheckSlowPathX86_64(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 60 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 61 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 62 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 63 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 64 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 65 | // Live registers will be restored in the catch block if caught. |
| 66 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 67 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 68 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), |
| 69 | instruction_, |
| 70 | instruction_->GetDexPc(), |
| 71 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 72 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 73 | } |
| 74 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 75 | bool IsFatal() const OVERRIDE { return true; } |
| 76 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 77 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86_64"; } |
| 78 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 79 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 80 | HNullCheck* const instruction_; |
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: |
| 86 | explicit DivZeroCheckSlowPathX86_64(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 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: |
| 107 | HDivZeroCheck* const instruction_; |
| 108 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86_64); |
| 109 | }; |
| 110 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 111 | class DivRemMinusOneSlowPathX86_64 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 112 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 113 | DivRemMinusOneSlowPathX86_64(Register reg, Primitive::Type type, bool is_div) |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 114 | : cpu_reg_(CpuRegister(reg)), type_(type), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 115 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 116 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 117 | __ Bind(GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 118 | if (type_ == Primitive::kPrimInt) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 119 | if (is_div_) { |
| 120 | __ negl(cpu_reg_); |
| 121 | } else { |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 122 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 125 | } else { |
| 126 | DCHECK_EQ(Primitive::kPrimLong, type_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 127 | if (is_div_) { |
| 128 | __ negq(cpu_reg_); |
| 129 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 130 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 131 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 132 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 133 | __ jmp(GetExitLabel()); |
| 134 | } |
| 135 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 136 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86_64"; } |
| 137 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 138 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 139 | const CpuRegister cpu_reg_; |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 140 | const Primitive::Type type_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 141 | const bool is_div_; |
| 142 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86_64); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 143 | }; |
| 144 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 145 | class SuspendCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 146 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 147 | SuspendCheckSlowPathX86_64(HSuspendCheck* instruction, HBasicBlock* successor) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 148 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 149 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 150 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 151 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 152 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 153 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 154 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), |
| 155 | instruction_, |
| 156 | instruction_->GetDexPc(), |
| 157 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 158 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 159 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 160 | if (successor_ == nullptr) { |
| 161 | __ jmp(GetReturnLabel()); |
| 162 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 163 | __ jmp(x86_64_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 164 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 167 | Label* GetReturnLabel() { |
| 168 | DCHECK(successor_ == nullptr); |
| 169 | return &return_label_; |
| 170 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 171 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 172 | HBasicBlock* GetSuccessor() const { |
| 173 | return successor_; |
| 174 | } |
| 175 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 176 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86_64"; } |
| 177 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 178 | private: |
| 179 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 180 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 181 | Label return_label_; |
| 182 | |
| 183 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64); |
| 184 | }; |
| 185 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 186 | class BoundsCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 187 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 188 | explicit BoundsCheckSlowPathX86_64(HBoundsCheck* instruction) |
| 189 | : instruction_(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 190 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 191 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 192 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 193 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 194 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 195 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 196 | // Live registers will be restored in the catch block if caught. |
| 197 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 198 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 199 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 200 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 201 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 202 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 203 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 204 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 205 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 206 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 207 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 208 | Primitive::kPrimInt); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 209 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds), |
| 210 | instruction_, |
| 211 | instruction_->GetDexPc(), |
| 212 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 213 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 214 | } |
| 215 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 216 | bool IsFatal() const OVERRIDE { return true; } |
| 217 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 218 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86_64"; } |
| 219 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 220 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 221 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 222 | |
| 223 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 224 | }; |
| 225 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 226 | class LoadClassSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 227 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 228 | LoadClassSlowPathX86_64(HLoadClass* cls, |
| 229 | HInstruction* at, |
| 230 | uint32_t dex_pc, |
| 231 | bool do_clinit) |
| 232 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 233 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 234 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 235 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 236 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 237 | LocationSummary* locations = at_->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 238 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 239 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 240 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 241 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 242 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 243 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 244 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(cls_->GetTypeIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 245 | x86_64_codegen->InvokeRuntime(do_clinit_ ? |
| 246 | QUICK_ENTRY_POINT(pInitializeStaticStorage) : |
| 247 | QUICK_ENTRY_POINT(pInitializeType), |
| 248 | at_, |
| 249 | dex_pc_, |
| 250 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 251 | if (do_clinit_) { |
| 252 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 253 | } else { |
| 254 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 255 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 256 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 257 | Location out = locations->Out(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 258 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 259 | if (out.IsValid()) { |
| 260 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 261 | x86_64_codegen->Move(out, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 262 | } |
| 263 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 264 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 265 | __ jmp(GetExitLabel()); |
| 266 | } |
| 267 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 268 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86_64"; } |
| 269 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 270 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 271 | // The class this slow path will load. |
| 272 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 273 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 274 | // The instruction where this slow path is happening. |
| 275 | // (Might be the load class or an initialization check). |
| 276 | HInstruction* const at_; |
| 277 | |
| 278 | // The dex PC of `at_`. |
| 279 | const uint32_t dex_pc_; |
| 280 | |
| 281 | // Whether to initialize the class. |
| 282 | const bool do_clinit_; |
| 283 | |
| 284 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86_64); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 285 | }; |
| 286 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 287 | class LoadStringSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 288 | public: |
| 289 | explicit LoadStringSlowPathX86_64(HLoadString* instruction) : instruction_(instruction) {} |
| 290 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 291 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 292 | LocationSummary* locations = instruction_->GetLocations(); |
| 293 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 294 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 295 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 296 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 297 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 298 | |
| 299 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 300 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 301 | Immediate(instruction_->GetStringIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 302 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), |
| 303 | instruction_, |
| 304 | instruction_->GetDexPc(), |
| 305 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 306 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 307 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 308 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 309 | __ jmp(GetExitLabel()); |
| 310 | } |
| 311 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 312 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86_64"; } |
| 313 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 314 | private: |
| 315 | HLoadString* const instruction_; |
| 316 | |
| 317 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86_64); |
| 318 | }; |
| 319 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 320 | class TypeCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 321 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 322 | TypeCheckSlowPathX86_64(HInstruction* instruction, bool is_fatal) |
| 323 | : instruction_(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 324 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 325 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 326 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 327 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 328 | : locations->Out(); |
| 329 | uint32_t dex_pc = instruction_->GetDexPc(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 330 | DCHECK(instruction_->IsCheckCast() |
| 331 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 332 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 333 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 334 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 335 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 336 | if (!is_fatal_) { |
| 337 | SaveLiveRegisters(codegen, locations); |
| 338 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 339 | |
| 340 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 341 | // move resolver. |
| 342 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 343 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 344 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 345 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 346 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 347 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 348 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 349 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 350 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 351 | if (instruction_->IsInstanceOf()) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 352 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 353 | instruction_, |
| 354 | dex_pc, |
| 355 | this); |
| 356 | CheckEntrypointTypes< |
| 357 | kQuickInstanceofNonTrivial, uint32_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 358 | } else { |
| 359 | DCHECK(instruction_->IsCheckCast()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 360 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 361 | instruction_, |
| 362 | dex_pc, |
| 363 | this); |
| 364 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 365 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 366 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 367 | if (!is_fatal_) { |
| 368 | if (instruction_->IsInstanceOf()) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 369 | x86_64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 370 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 371 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 372 | RestoreLiveRegisters(codegen, locations); |
| 373 | __ jmp(GetExitLabel()); |
| 374 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 375 | } |
| 376 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 377 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86_64"; } |
| 378 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 379 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 380 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 381 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 382 | HInstruction* const instruction_; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 383 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 384 | |
| 385 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86_64); |
| 386 | }; |
| 387 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 388 | class DeoptimizationSlowPathX86_64 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 389 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 390 | explicit DeoptimizationSlowPathX86_64(HDeoptimize* instruction) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 391 | : instruction_(instruction) {} |
| 392 | |
| 393 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 394 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 395 | __ Bind(GetEntryLabel()); |
| 396 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 397 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 398 | instruction_, |
| 399 | instruction_->GetDexPc(), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 400 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 401 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 404 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86_64"; } |
| 405 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 406 | private: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 407 | HDeoptimize* const instruction_; |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 408 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86_64); |
| 409 | }; |
| 410 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 411 | class ArraySetSlowPathX86_64 : public SlowPathCode { |
| 412 | public: |
| 413 | explicit ArraySetSlowPathX86_64(HInstruction* instruction) : instruction_(instruction) {} |
| 414 | |
| 415 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 416 | LocationSummary* locations = instruction_->GetLocations(); |
| 417 | __ Bind(GetEntryLabel()); |
| 418 | SaveLiveRegisters(codegen, locations); |
| 419 | |
| 420 | InvokeRuntimeCallingConvention calling_convention; |
| 421 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 422 | parallel_move.AddMove( |
| 423 | locations->InAt(0), |
| 424 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 425 | Primitive::kPrimNot, |
| 426 | nullptr); |
| 427 | parallel_move.AddMove( |
| 428 | locations->InAt(1), |
| 429 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 430 | Primitive::kPrimInt, |
| 431 | nullptr); |
| 432 | parallel_move.AddMove( |
| 433 | locations->InAt(2), |
| 434 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 435 | Primitive::kPrimNot, |
| 436 | nullptr); |
| 437 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 438 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 439 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 440 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 441 | instruction_, |
| 442 | instruction_->GetDexPc(), |
| 443 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 444 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 445 | RestoreLiveRegisters(codegen, locations); |
| 446 | __ jmp(GetExitLabel()); |
| 447 | } |
| 448 | |
| 449 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86_64"; } |
| 450 | |
| 451 | private: |
| 452 | HInstruction* const instruction_; |
| 453 | |
| 454 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86_64); |
| 455 | }; |
| 456 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 457 | // Slow path marking an object during a read barrier. |
| 458 | class ReadBarrierMarkSlowPathX86_64 : public SlowPathCode { |
| 459 | public: |
| 460 | ReadBarrierMarkSlowPathX86_64(HInstruction* instruction, Location out, Location obj) |
| 461 | : instruction_(instruction), out_(out), obj_(obj) { |
| 462 | DCHECK(kEmitCompilerReadBarrier); |
| 463 | } |
| 464 | |
| 465 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86_64"; } |
| 466 | |
| 467 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 468 | LocationSummary* locations = instruction_->GetLocations(); |
| 469 | Register reg_out = out_.AsRegister<Register>(); |
| 470 | DCHECK(locations->CanCall()); |
| 471 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 472 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 473 | instruction_->IsStaticFieldGet() || |
| 474 | instruction_->IsArrayGet() || |
| 475 | instruction_->IsLoadClass() || |
| 476 | instruction_->IsLoadString() || |
| 477 | instruction_->IsInstanceOf() || |
| 478 | instruction_->IsCheckCast()) |
| 479 | << "Unexpected instruction in read barrier marking slow path: " |
| 480 | << instruction_->DebugName(); |
| 481 | |
| 482 | __ Bind(GetEntryLabel()); |
| 483 | SaveLiveRegisters(codegen, locations); |
| 484 | |
| 485 | InvokeRuntimeCallingConvention calling_convention; |
| 486 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 487 | x86_64_codegen->Move(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), obj_); |
| 488 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierMark), |
| 489 | instruction_, |
| 490 | instruction_->GetDexPc(), |
| 491 | this); |
| 492 | CheckEntrypointTypes<kQuickReadBarrierMark, mirror::Object*, mirror::Object*>(); |
| 493 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 494 | |
| 495 | RestoreLiveRegisters(codegen, locations); |
| 496 | __ jmp(GetExitLabel()); |
| 497 | } |
| 498 | |
| 499 | private: |
| 500 | HInstruction* const instruction_; |
| 501 | const Location out_; |
| 502 | const Location obj_; |
| 503 | |
| 504 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86_64); |
| 505 | }; |
| 506 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 507 | // Slow path generating a read barrier for a heap reference. |
| 508 | class ReadBarrierForHeapReferenceSlowPathX86_64 : public SlowPathCode { |
| 509 | public: |
| 510 | ReadBarrierForHeapReferenceSlowPathX86_64(HInstruction* instruction, |
| 511 | Location out, |
| 512 | Location ref, |
| 513 | Location obj, |
| 514 | uint32_t offset, |
| 515 | Location index) |
| 516 | : instruction_(instruction), |
| 517 | out_(out), |
| 518 | ref_(ref), |
| 519 | obj_(obj), |
| 520 | offset_(offset), |
| 521 | index_(index) { |
| 522 | DCHECK(kEmitCompilerReadBarrier); |
| 523 | // If `obj` is equal to `out` or `ref`, it means the initial |
| 524 | // object has been overwritten by (or after) the heap object |
| 525 | // reference load to be instrumented, e.g.: |
| 526 | // |
| 527 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 528 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 529 | // |
| 530 | // In that case, we have lost the information about the original |
| 531 | // object, and the emitted read barrier cannot work properly. |
| 532 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 533 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 534 | } |
| 535 | |
| 536 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 537 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 538 | LocationSummary* locations = instruction_->GetLocations(); |
| 539 | CpuRegister reg_out = out_.AsRegister<CpuRegister>(); |
| 540 | DCHECK(locations->CanCall()); |
| 541 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.AsRegister())) << out_; |
| 542 | DCHECK(!instruction_->IsInvoke() || |
| 543 | (instruction_->IsInvokeStaticOrDirect() && |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 544 | instruction_->GetLocations()->Intrinsified())) |
| 545 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 546 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 547 | |
| 548 | __ Bind(GetEntryLabel()); |
| 549 | SaveLiveRegisters(codegen, locations); |
| 550 | |
| 551 | // We may have to change the index's value, but as `index_` is a |
| 552 | // constant member (like other "inputs" of this slow path), |
| 553 | // introduce a copy of it, `index`. |
| 554 | Location index = index_; |
| 555 | if (index_.IsValid()) { |
| 556 | // Handle `index_` for HArrayGet and intrinsic UnsafeGetObject. |
| 557 | if (instruction_->IsArrayGet()) { |
| 558 | // Compute real offset and store it in index_. |
| 559 | Register index_reg = index_.AsRegister<CpuRegister>().AsRegister(); |
| 560 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 561 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 562 | // We are about to change the value of `index_reg` (see the |
| 563 | // calls to art::x86_64::X86_64Assembler::shll and |
| 564 | // art::x86_64::X86_64Assembler::AddImmediate below), but it |
| 565 | // has not been saved by the previous call to |
| 566 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 567 | // callee-save register -- |
| 568 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 569 | // callee-save registers, as it has been designed with the |
| 570 | // assumption that callee-save registers are supposed to be |
| 571 | // handled by the called function. So, as a callee-save |
| 572 | // register, `index_reg` _would_ eventually be saved onto |
| 573 | // the stack, but it would be too late: we would have |
| 574 | // changed its value earlier. Therefore, we manually save |
| 575 | // it here into another freely available register, |
| 576 | // `free_reg`, chosen of course among the caller-save |
| 577 | // registers (as a callee-save `free_reg` register would |
| 578 | // exhibit the same problem). |
| 579 | // |
| 580 | // Note we could have requested a temporary register from |
| 581 | // the register allocator instead; but we prefer not to, as |
| 582 | // this is a slow path, and we know we can find a |
| 583 | // caller-save register that is available. |
| 584 | Register free_reg = FindAvailableCallerSaveRegister(codegen).AsRegister(); |
| 585 | __ movl(CpuRegister(free_reg), CpuRegister(index_reg)); |
| 586 | index_reg = free_reg; |
| 587 | index = Location::RegisterLocation(index_reg); |
| 588 | } else { |
| 589 | // The initial register stored in `index_` has already been |
| 590 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 591 | // (as it is not a callee-save register), so we can freely |
| 592 | // use it. |
| 593 | } |
| 594 | // Shifting the index value contained in `index_reg` by the |
| 595 | // scale factor (2) cannot overflow in practice, as the |
| 596 | // runtime is unable to allocate object arrays with a size |
| 597 | // larger than 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 598 | __ shll(CpuRegister(index_reg), Immediate(TIMES_4)); |
| 599 | static_assert( |
| 600 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 601 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 602 | __ AddImmediate(CpuRegister(index_reg), Immediate(offset_)); |
| 603 | } else { |
| 604 | DCHECK(instruction_->IsInvoke()); |
| 605 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 606 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 607 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 608 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 609 | DCHECK_EQ(offset_, 0U); |
| 610 | DCHECK(index_.IsRegister()); |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | // We're moving two or three locations to locations that could |
| 615 | // overlap, so we need a parallel move resolver. |
| 616 | InvokeRuntimeCallingConvention calling_convention; |
| 617 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 618 | parallel_move.AddMove(ref_, |
| 619 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 620 | Primitive::kPrimNot, |
| 621 | nullptr); |
| 622 | parallel_move.AddMove(obj_, |
| 623 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 624 | Primitive::kPrimNot, |
| 625 | nullptr); |
| 626 | if (index.IsValid()) { |
| 627 | parallel_move.AddMove(index, |
| 628 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 629 | Primitive::kPrimInt, |
| 630 | nullptr); |
| 631 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 632 | } else { |
| 633 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 634 | __ movl(CpuRegister(calling_convention.GetRegisterAt(2)), Immediate(offset_)); |
| 635 | } |
| 636 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow), |
| 637 | instruction_, |
| 638 | instruction_->GetDexPc(), |
| 639 | this); |
| 640 | CheckEntrypointTypes< |
| 641 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 642 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 643 | |
| 644 | RestoreLiveRegisters(codegen, locations); |
| 645 | __ jmp(GetExitLabel()); |
| 646 | } |
| 647 | |
| 648 | const char* GetDescription() const OVERRIDE { |
| 649 | return "ReadBarrierForHeapReferenceSlowPathX86_64"; |
| 650 | } |
| 651 | |
| 652 | private: |
| 653 | CpuRegister FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 654 | size_t ref = static_cast<int>(ref_.AsRegister<CpuRegister>().AsRegister()); |
| 655 | size_t obj = static_cast<int>(obj_.AsRegister<CpuRegister>().AsRegister()); |
| 656 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 657 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 658 | return static_cast<CpuRegister>(i); |
| 659 | } |
| 660 | } |
| 661 | // We shall never fail to find a free caller-save register, as |
| 662 | // there are more than two core caller-save registers on x86-64 |
| 663 | // (meaning it is possible to find one which is different from |
| 664 | // `ref` and `obj`). |
| 665 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 666 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 667 | UNREACHABLE(); |
| 668 | } |
| 669 | |
| 670 | HInstruction* const instruction_; |
| 671 | const Location out_; |
| 672 | const Location ref_; |
| 673 | const Location obj_; |
| 674 | const uint32_t offset_; |
| 675 | // An additional location containing an index to an array. |
| 676 | // Only used for HArrayGet and the UnsafeGetObject & |
| 677 | // UnsafeGetObjectVolatile intrinsics. |
| 678 | const Location index_; |
| 679 | |
| 680 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86_64); |
| 681 | }; |
| 682 | |
| 683 | // Slow path generating a read barrier for a GC root. |
| 684 | class ReadBarrierForRootSlowPathX86_64 : public SlowPathCode { |
| 685 | public: |
| 686 | ReadBarrierForRootSlowPathX86_64(HInstruction* instruction, Location out, Location root) |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 687 | : instruction_(instruction), out_(out), root_(root) { |
| 688 | DCHECK(kEmitCompilerReadBarrier); |
| 689 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 690 | |
| 691 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 692 | LocationSummary* locations = instruction_->GetLocations(); |
| 693 | DCHECK(locations->CanCall()); |
| 694 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg())); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 695 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 696 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 697 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 698 | |
| 699 | __ Bind(GetEntryLabel()); |
| 700 | SaveLiveRegisters(codegen, locations); |
| 701 | |
| 702 | InvokeRuntimeCallingConvention calling_convention; |
| 703 | CodeGeneratorX86_64* x86_64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 704 | x86_64_codegen->Move(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| 705 | x86_64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow), |
| 706 | instruction_, |
| 707 | instruction_->GetDexPc(), |
| 708 | this); |
| 709 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 710 | x86_64_codegen->Move(out_, Location::RegisterLocation(RAX)); |
| 711 | |
| 712 | RestoreLiveRegisters(codegen, locations); |
| 713 | __ jmp(GetExitLabel()); |
| 714 | } |
| 715 | |
| 716 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86_64"; } |
| 717 | |
| 718 | private: |
| 719 | HInstruction* const instruction_; |
| 720 | const Location out_; |
| 721 | const Location root_; |
| 722 | |
| 723 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86_64); |
| 724 | }; |
| 725 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 726 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 727 | #define __ down_cast<X86_64Assembler*>(GetAssembler())-> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 728 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 729 | inline Condition X86_64IntegerCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 730 | switch (cond) { |
| 731 | case kCondEQ: return kEqual; |
| 732 | case kCondNE: return kNotEqual; |
| 733 | case kCondLT: return kLess; |
| 734 | case kCondLE: return kLessEqual; |
| 735 | case kCondGT: return kGreater; |
| 736 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 737 | case kCondB: return kBelow; |
| 738 | case kCondBE: return kBelowEqual; |
| 739 | case kCondA: return kAbove; |
| 740 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 741 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 742 | LOG(FATAL) << "Unreachable"; |
| 743 | UNREACHABLE(); |
| 744 | } |
| 745 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 746 | // Maps FP condition to x86_64 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 747 | inline Condition X86_64FPCondition(IfCondition cond) { |
| 748 | switch (cond) { |
| 749 | case kCondEQ: return kEqual; |
| 750 | case kCondNE: return kNotEqual; |
| 751 | case kCondLT: return kBelow; |
| 752 | case kCondLE: return kBelowEqual; |
| 753 | case kCondGT: return kAbove; |
| 754 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 755 | default: break; // should not happen |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 756 | }; |
| 757 | LOG(FATAL) << "Unreachable"; |
| 758 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 759 | } |
| 760 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 761 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86_64::GetSupportedInvokeStaticOrDirectDispatch( |
| 762 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 763 | MethodReference target_method ATTRIBUTE_UNUSED) { |
| 764 | switch (desired_dispatch_info.code_ptr_location) { |
| 765 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 766 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 767 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 768 | return HInvokeStaticOrDirect::DispatchInfo { |
| 769 | desired_dispatch_info.method_load_kind, |
| 770 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
| 771 | desired_dispatch_info.method_load_data, |
| 772 | 0u |
| 773 | }; |
| 774 | default: |
| 775 | return desired_dispatch_info; |
| 776 | } |
| 777 | } |
| 778 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 779 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 780 | Location temp) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 781 | // All registers are assumed to be correctly set up. |
| 782 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 783 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 784 | switch (invoke->GetMethodLoadKind()) { |
| 785 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 786 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | 7f59d59 | 2015-12-29 16:20:52 +0000 | [diff] [blame] | 787 | __ gs()->movq(temp.AsRegister<CpuRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 788 | Address::Absolute(invoke->GetStringInitOffset(), /* no_rip */ true)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 789 | break; |
| 790 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 791 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 792 | break; |
| 793 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 794 | __ movq(temp.AsRegister<CpuRegister>(), Immediate(invoke->GetMethodAddress())); |
| 795 | break; |
| 796 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 797 | __ movl(temp.AsRegister<CpuRegister>(), Immediate(0)); // Placeholder. |
| 798 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 799 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 800 | break; |
| 801 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 802 | pc_relative_dex_cache_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 803 | invoke->GetDexCacheArrayOffset()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 804 | __ movq(temp.AsRegister<CpuRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 805 | Address::Absolute(kDummy32BitOffset, /* no_rip */ false)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 806 | // Bind the label at the end of the "movl" insn. |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 807 | __ Bind(&pc_relative_dex_cache_patches_.back().label); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 808 | break; |
| 809 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 810 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 811 | Register method_reg; |
| 812 | CpuRegister reg = temp.AsRegister<CpuRegister>(); |
| 813 | if (current_method.IsRegister()) { |
| 814 | method_reg = current_method.AsRegister<Register>(); |
| 815 | } else { |
| 816 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 817 | DCHECK(!current_method.IsValid()); |
| 818 | method_reg = reg.AsRegister(); |
| 819 | __ movq(reg, Address(CpuRegister(RSP), kCurrentMethodStackOffset)); |
| 820 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 821 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 822 | __ movq(reg, |
| 823 | Address(CpuRegister(method_reg), |
| 824 | ArtMethod::DexCacheResolvedMethodsOffset(kX86_64PointerSize).SizeValue())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 825 | // temp = temp[index_in_cache] |
| 826 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 827 | __ movq(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 828 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 829 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | switch (invoke->GetCodePtrLocation()) { |
| 833 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 834 | __ call(&frame_entry_label_); |
| 835 | break; |
| 836 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 837 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 838 | Label* label = &relative_call_patches_.back().label; |
| 839 | __ call(label); // Bind to the patch label, override at link time. |
| 840 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 841 | break; |
| 842 | } |
| 843 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 844 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 845 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 846 | LOG(FATAL) << "Unsupported"; |
| 847 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 848 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 849 | // (callee_method + offset_of_quick_compiled_code)() |
| 850 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 851 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 852 | kX86_64WordSize).SizeValue())); |
| 853 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 854 | } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 855 | |
| 856 | DCHECK(!IsLeafMethod()); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 857 | } |
| 858 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 859 | void CodeGeneratorX86_64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 860 | CpuRegister temp = temp_in.AsRegister<CpuRegister>(); |
| 861 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 862 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 863 | |
| 864 | // Use the calling convention instead of the location of the receiver, as |
| 865 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 866 | // slow path, the arguments have been moved to the right place, so here we are |
| 867 | // guaranteed that the receiver is the first register of the calling convention. |
| 868 | InvokeDexCallingConvention calling_convention; |
| 869 | Register receiver = calling_convention.GetRegisterAt(0); |
| 870 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 871 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 872 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 873 | __ movl(temp, Address(CpuRegister(receiver), class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 874 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 875 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 876 | // emit a read barrier for the previous class reference load. |
| 877 | // However this is not required in practice, as this is an |
| 878 | // intermediate/temporary reference and because the current |
| 879 | // concurrent copying collector keeps the from-space memory |
| 880 | // intact/accessible until the end of the marking phase (the |
| 881 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 882 | __ MaybeUnpoisonHeapReference(temp); |
| 883 | // temp = temp->GetMethodAt(method_offset); |
| 884 | __ movq(temp, Address(temp, method_offset)); |
| 885 | // call temp->GetEntryPoint(); |
| 886 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 887 | kX86_64WordSize).SizeValue())); |
| 888 | } |
| 889 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 890 | void CodeGeneratorX86_64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 891 | DCHECK(linker_patches->empty()); |
| 892 | size_t size = |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 893 | method_patches_.size() + |
| 894 | relative_call_patches_.size() + |
| 895 | pc_relative_dex_cache_patches_.size(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 896 | linker_patches->reserve(size); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 897 | // The label points to the end of the "movl" insn but the literal offset for method |
| 898 | // patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 899 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 900 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 901 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 902 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 903 | info.target_method.dex_file, |
| 904 | info.target_method.dex_method_index)); |
| 905 | } |
| 906 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 907 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 908 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 909 | info.target_method.dex_file, |
| 910 | info.target_method.dex_method_index)); |
| 911 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 912 | for (const PcRelativeDexCacheAccessInfo& info : pc_relative_dex_cache_patches_) { |
| 913 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 914 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 915 | &info.target_dex_file, |
| 916 | info.label.Position(), |
| 917 | info.element_offset)); |
| 918 | } |
| 919 | } |
| 920 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 921 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 922 | stream << Register(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 926 | stream << FloatRegister(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 927 | } |
| 928 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 929 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 930 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 931 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 932 | } |
| 933 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 934 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 935 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 936 | return kX86_64WordSize; |
| 937 | } |
| 938 | |
| 939 | size_t CodeGeneratorX86_64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 940 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 941 | return kX86_64WordSize; |
| 942 | } |
| 943 | |
| 944 | size_t CodeGeneratorX86_64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 945 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 946 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 947 | } |
| 948 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 949 | void CodeGeneratorX86_64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 950 | HInstruction* instruction, |
| 951 | uint32_t dex_pc, |
| 952 | SlowPathCode* slow_path) { |
| 953 | InvokeRuntime(GetThreadOffset<kX86_64WordSize>(entrypoint).Int32Value(), |
| 954 | instruction, |
| 955 | dex_pc, |
| 956 | slow_path); |
| 957 | } |
| 958 | |
| 959 | void CodeGeneratorX86_64::InvokeRuntime(int32_t entry_point_offset, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 960 | HInstruction* instruction, |
| 961 | uint32_t dex_pc, |
| 962 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 963 | ValidateInvokeRuntime(instruction, slow_path); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 964 | __ gs()->call(Address::Absolute(entry_point_offset, /* no_rip */ true)); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 965 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 966 | } |
| 967 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 968 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 969 | // Use a fake return address register to mimic Quick. |
| 970 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 971 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 972 | const X86_64InstructionSetFeatures& isa_features, |
| 973 | const CompilerOptions& compiler_options, |
| 974 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 975 | : CodeGenerator(graph, |
| 976 | kNumberOfCpuRegisters, |
| 977 | kNumberOfFloatRegisters, |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 978 | kNumberOfCpuRegisterPairs, |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 979 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 980 | arraysize(kCoreCalleeSaves)) |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 981 | | (1 << kFakeReturnRegister), |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 982 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 983 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 984 | compiler_options, |
| 985 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 986 | block_labels_(nullptr), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 987 | location_builder_(graph, this), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 988 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 989 | move_resolver_(graph->GetArena(), this), |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 990 | isa_features_(isa_features), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 991 | constant_area_start_(0), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 992 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 993 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 994 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 995 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 996 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 997 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 998 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 999 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 1000 | CodeGeneratorX86_64* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1001 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1002 | assembler_(codegen->GetAssembler()), |
| 1003 | codegen_(codegen) {} |
| 1004 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1005 | void CodeGeneratorX86_64::SetupBlockedRegisters() const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1006 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1007 | blocked_core_registers_[RSP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1008 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1009 | // Block the register used as TMP. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1010 | blocked_core_registers_[TMP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1011 | } |
| 1012 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1013 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1014 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1015 | } |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1016 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1017 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1018 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1019 | } |
| 1020 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1021 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1022 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1023 | __ Bind(&frame_entry_label_); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1024 | bool skip_overflow_check = IsLeafMethod() |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 1025 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1026 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1027 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1028 | if (!skip_overflow_check) { |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1029 | __ testq(CpuRegister(RAX), Address( |
| 1030 | CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1031 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1032 | } |
Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 1033 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1034 | if (HasEmptyFrame()) { |
| 1035 | return; |
| 1036 | } |
| 1037 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1038 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1039 | Register reg = kCoreCalleeSaves[i]; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 1040 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1041 | __ pushq(CpuRegister(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1042 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 1043 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 1044 | } |
| 1045 | } |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 1046 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1047 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1048 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 1049 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1050 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1051 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1052 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1053 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 1054 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1055 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1056 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 1057 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1058 | } |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1059 | } |
| 1060 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1061 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1062 | CpuRegister(kMethodRegisterArgument)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | void CodeGeneratorX86_64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1066 | __ cfi().RememberState(); |
| 1067 | if (!HasEmptyFrame()) { |
| 1068 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 1069 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| 1070 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 1071 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 1072 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 1073 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 1074 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 1075 | } |
| 1076 | } |
| 1077 | |
| 1078 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 1079 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 1080 | __ cfi().AdjustCFAOffset(-adjust); |
| 1081 | |
| 1082 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 1083 | Register reg = kCoreCalleeSaves[i]; |
| 1084 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 1085 | __ popq(CpuRegister(reg)); |
| 1086 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 1087 | __ cfi().Restore(DWARFReg(reg)); |
| 1088 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1089 | } |
| 1090 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1091 | __ ret(); |
| 1092 | __ cfi().RestoreState(); |
| 1093 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1094 | } |
| 1095 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1096 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 1097 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1098 | } |
| 1099 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1100 | Location CodeGeneratorX86_64::GetStackLocation(HLoadLocal* load) const { |
| 1101 | switch (load->GetType()) { |
| 1102 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1103 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1104 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1105 | |
| 1106 | case Primitive::kPrimInt: |
| 1107 | case Primitive::kPrimNot: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1108 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1109 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1110 | |
| 1111 | case Primitive::kPrimBoolean: |
| 1112 | case Primitive::kPrimByte: |
| 1113 | case Primitive::kPrimChar: |
| 1114 | case Primitive::kPrimShort: |
| 1115 | case Primitive::kPrimVoid: |
| 1116 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 1117 | UNREACHABLE(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 1121 | UNREACHABLE(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 1125 | if (source.Equals(destination)) { |
| 1126 | return; |
| 1127 | } |
| 1128 | if (destination.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame^] | 1129 | CpuRegister dest = destination.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1130 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame^] | 1131 | __ movq(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1132 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame^] | 1133 | __ movd(dest, source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1134 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame^] | 1135 | __ movl(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1136 | } else if (source.IsConstant()) { |
| 1137 | HConstant* constant = source.GetConstant(); |
| 1138 | if (constant->IsLongConstant()) { |
| 1139 | Load64BitValue(dest, constant->AsLongConstant()->GetValue()); |
| 1140 | } else { |
| 1141 | Load32BitValue(dest, GetInt32ValueOf(constant)); |
| 1142 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1143 | } else { |
| 1144 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame^] | 1145 | __ movq(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1146 | } |
| 1147 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame^] | 1148 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1149 | if (source.IsRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame^] | 1150 | __ movd(dest, source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1151 | } else if (source.IsFpuRegister()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame^] | 1152 | __ movaps(dest, source.AsFpuRegister<XmmRegister>()); |
| 1153 | } else if (source.IsConstant()) { |
| 1154 | HConstant* constant = source.GetConstant(); |
| 1155 | int64_t value = CodeGenerator::GetInt64ValueOf(constant); |
| 1156 | if (constant->IsFloatConstant()) { |
| 1157 | Load32BitValue(dest, static_cast<int32_t>(value)); |
| 1158 | } else { |
| 1159 | Load64BitValue(dest, value); |
| 1160 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1161 | } else if (source.IsStackSlot()) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame^] | 1162 | __ movss(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1163 | } else { |
| 1164 | DCHECK(source.IsDoubleStackSlot()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame^] | 1165 | __ movsd(dest, Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1166 | } |
| 1167 | } else if (destination.IsStackSlot()) { |
| 1168 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1169 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1170 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1171 | } else if (source.IsFpuRegister()) { |
| 1172 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1173 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1174 | } else if (source.IsConstant()) { |
| 1175 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1176 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1177 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1178 | } else { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1179 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1180 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1181 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1182 | } |
| 1183 | } else { |
| 1184 | DCHECK(destination.IsDoubleStackSlot()); |
| 1185 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1186 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1187 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1188 | } else if (source.IsFpuRegister()) { |
| 1189 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1190 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1191 | } else if (source.IsConstant()) { |
| 1192 | HConstant* constant = source.GetConstant(); |
Zheng Xu | 12bca97 | 2015-03-30 19:35:50 +0800 | [diff] [blame] | 1193 | int64_t value; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1194 | if (constant->IsDoubleConstant()) { |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 1195 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 1196 | } else { |
| 1197 | DCHECK(constant->IsLongConstant()); |
| 1198 | value = constant->AsLongConstant()->GetValue(); |
| 1199 | } |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 1200 | Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1201 | } else { |
| 1202 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 1203 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 1204 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1205 | } |
| 1206 | } |
| 1207 | } |
| 1208 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1209 | void CodeGeneratorX86_64::Move(HInstruction* instruction, |
| 1210 | Location location, |
| 1211 | HInstruction* move_for) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1212 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1213 | if (instruction->IsCurrentMethod()) { |
Mathieu Chartier | e3b034a | 2015-05-31 14:29:23 -0700 | [diff] [blame] | 1214 | Move(location, Location::DoubleStackSlot(kCurrentMethodStackOffset)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1215 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1216 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1217 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1218 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1219 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 1220 | Immediate imm(GetInt32ValueOf(const_to_move)); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1221 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1222 | __ movl(location.AsRegister<CpuRegister>(), imm); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1223 | } else if (location.IsStackSlot()) { |
| 1224 | __ movl(Address(CpuRegister(RSP), location.GetStackIndex()), imm); |
| 1225 | } else { |
| 1226 | DCHECK(location.IsConstant()); |
| 1227 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 1228 | } |
| 1229 | } else if (const_to_move->IsLongConstant()) { |
| 1230 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 1231 | if (location.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 1232 | Load64BitValue(location.AsRegister<CpuRegister>(), value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1233 | } else if (location.IsDoubleStackSlot()) { |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 1234 | Store64BitValueToStack(location, value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1235 | } else { |
| 1236 | DCHECK(location.IsConstant()); |
| 1237 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 1238 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1239 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 1240 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1241 | switch (instruction->GetType()) { |
| 1242 | case Primitive::kPrimBoolean: |
| 1243 | case Primitive::kPrimByte: |
| 1244 | case Primitive::kPrimChar: |
| 1245 | case Primitive::kPrimShort: |
| 1246 | case Primitive::kPrimInt: |
| 1247 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1248 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1249 | Move(location, Location::StackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
| 1250 | break; |
| 1251 | |
| 1252 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1253 | case Primitive::kPrimDouble: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1254 | Move(location, |
| 1255 | Location::DoubleStackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1256 | break; |
| 1257 | |
| 1258 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1259 | LOG(FATAL) << "Unexpected local type " << instruction->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1260 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 1261 | } else if (instruction->IsTemporary()) { |
| 1262 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
| 1263 | Move(location, temp_location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1264 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1265 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1266 | switch (instruction->GetType()) { |
| 1267 | case Primitive::kPrimBoolean: |
| 1268 | case Primitive::kPrimByte: |
| 1269 | case Primitive::kPrimChar: |
| 1270 | case Primitive::kPrimShort: |
| 1271 | case Primitive::kPrimInt: |
| 1272 | case Primitive::kPrimNot: |
| 1273 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1274 | case Primitive::kPrimFloat: |
| 1275 | case Primitive::kPrimDouble: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1276 | Move(location, locations->Out()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1277 | break; |
| 1278 | |
| 1279 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1280 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1281 | } |
| 1282 | } |
| 1283 | } |
| 1284 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1285 | void CodeGeneratorX86_64::MoveConstant(Location location, int32_t value) { |
| 1286 | DCHECK(location.IsRegister()); |
| 1287 | Load64BitValue(location.AsRegister<CpuRegister>(), static_cast<int64_t>(value)); |
| 1288 | } |
| 1289 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1290 | void CodeGeneratorX86_64::MoveLocation( |
| 1291 | Location dst, Location src, Primitive::Type dst_type ATTRIBUTE_UNUSED) { |
| 1292 | Move(dst, src); |
| 1293 | } |
| 1294 | |
| 1295 | void CodeGeneratorX86_64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1296 | if (location.IsRegister()) { |
| 1297 | locations->AddTemp(location); |
| 1298 | } else { |
| 1299 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1300 | } |
| 1301 | } |
| 1302 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1303 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1304 | DCHECK(!successor->IsExitBlock()); |
| 1305 | |
| 1306 | HBasicBlock* block = got->GetBlock(); |
| 1307 | HInstruction* previous = got->GetPrevious(); |
| 1308 | |
| 1309 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1310 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1311 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1312 | return; |
| 1313 | } |
| 1314 | |
| 1315 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1316 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1317 | } |
| 1318 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1319 | __ jmp(codegen_->GetLabelOf(successor)); |
| 1320 | } |
| 1321 | } |
| 1322 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1323 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 1324 | got->SetLocations(nullptr); |
| 1325 | } |
| 1326 | |
| 1327 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 1328 | HandleGoto(got, got->GetSuccessor()); |
| 1329 | } |
| 1330 | |
| 1331 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1332 | try_boundary->SetLocations(nullptr); |
| 1333 | } |
| 1334 | |
| 1335 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1336 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1337 | if (!successor->IsExitBlock()) { |
| 1338 | HandleGoto(try_boundary, successor); |
| 1339 | } |
| 1340 | } |
| 1341 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1342 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 1343 | exit->SetLocations(nullptr); |
| 1344 | } |
| 1345 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1346 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1347 | } |
| 1348 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1349 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1350 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1351 | LabelType* true_label, |
| 1352 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1353 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1354 | __ j(kUnordered, true_label); |
| 1355 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1356 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1357 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1358 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1359 | } |
| 1360 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame^] | 1361 | void InstructionCodeGeneratorX86_64::GenerateCompareTest(HCondition* condition) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1362 | LocationSummary* locations = condition->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame^] | 1363 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1364 | Location left = locations->InAt(0); |
| 1365 | Location right = locations->InAt(1); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1366 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1367 | switch (type) { |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame^] | 1368 | case Primitive::kPrimBoolean: |
| 1369 | case Primitive::kPrimByte: |
| 1370 | case Primitive::kPrimChar: |
| 1371 | case Primitive::kPrimShort: |
| 1372 | case Primitive::kPrimInt: |
| 1373 | case Primitive::kPrimNot: { |
| 1374 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1375 | if (right.IsConstant()) { |
| 1376 | int32_t value = CodeGenerator::GetInt32ValueOf(right.GetConstant()); |
| 1377 | if (value == 0) { |
| 1378 | __ testl(left_reg, left_reg); |
| 1379 | } else { |
| 1380 | __ cmpl(left_reg, Immediate(value)); |
| 1381 | } |
| 1382 | } else if (right.IsStackSlot()) { |
| 1383 | __ cmpl(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1384 | } else { |
| 1385 | __ cmpl(left_reg, right.AsRegister<CpuRegister>()); |
| 1386 | } |
| 1387 | break; |
| 1388 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1389 | case Primitive::kPrimLong: { |
| 1390 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1391 | if (right.IsConstant()) { |
| 1392 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 1393 | if (IsInt<32>(value)) { |
| 1394 | if (value == 0) { |
| 1395 | __ testq(left_reg, left_reg); |
| 1396 | } else { |
| 1397 | __ cmpq(left_reg, Immediate(static_cast<int32_t>(value))); |
| 1398 | } |
| 1399 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1400 | // Value won't fit in a 32-bit integer. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1401 | __ cmpq(left_reg, codegen_->LiteralInt64Address(value)); |
| 1402 | } |
| 1403 | } else if (right.IsDoubleStackSlot()) { |
| 1404 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1405 | } else { |
| 1406 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1407 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1408 | break; |
| 1409 | } |
| 1410 | case Primitive::kPrimFloat: { |
| 1411 | if (right.IsFpuRegister()) { |
| 1412 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1413 | } else if (right.IsConstant()) { |
| 1414 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1415 | codegen_->LiteralFloatAddress( |
| 1416 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1417 | } else { |
| 1418 | DCHECK(right.IsStackSlot()); |
| 1419 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1420 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1421 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1422 | break; |
| 1423 | } |
| 1424 | case Primitive::kPrimDouble: { |
| 1425 | if (right.IsFpuRegister()) { |
| 1426 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1427 | } else if (right.IsConstant()) { |
| 1428 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1429 | codegen_->LiteralDoubleAddress( |
| 1430 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1431 | } else { |
| 1432 | DCHECK(right.IsDoubleStackSlot()); |
| 1433 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1434 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1435 | } |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame^] | 1436 | break; |
| 1437 | } |
| 1438 | default: |
| 1439 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1440 | } |
| 1441 | } |
| 1442 | |
| 1443 | template<class LabelType> |
| 1444 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HCondition* condition, |
| 1445 | LabelType* true_target_in, |
| 1446 | LabelType* false_target_in) { |
| 1447 | // Generated branching requires both targets to be explicit. If either of the |
| 1448 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1449 | LabelType fallthrough_target; |
| 1450 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1451 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1452 | |
| 1453 | // Generate the comparison to set the CC. |
| 1454 | GenerateCompareTest(condition); |
| 1455 | |
| 1456 | // Now generate the correct jump(s). |
| 1457 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1458 | switch (type) { |
| 1459 | case Primitive::kPrimLong: { |
| 1460 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
| 1461 | break; |
| 1462 | } |
| 1463 | case Primitive::kPrimFloat: { |
| 1464 | GenerateFPJumps(condition, true_target, false_target); |
| 1465 | break; |
| 1466 | } |
| 1467 | case Primitive::kPrimDouble: { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1468 | GenerateFPJumps(condition, true_target, false_target); |
| 1469 | break; |
| 1470 | } |
| 1471 | default: |
| 1472 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1473 | } |
| 1474 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1475 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1476 | __ jmp(false_target); |
| 1477 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1478 | |
| 1479 | if (fallthrough_target.IsLinked()) { |
| 1480 | __ Bind(&fallthrough_target); |
| 1481 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1482 | } |
| 1483 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1484 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1485 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1486 | // are set only strictly before `branch`. We can't use the eflags on long |
| 1487 | // conditions if they are materialized due to the complex branching. |
| 1488 | return cond->IsCondition() && |
| 1489 | cond->GetNext() == branch && |
| 1490 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1491 | } |
| 1492 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1493 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1494 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1495 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1496 | LabelType* true_target, |
| 1497 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1498 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1499 | |
| 1500 | if (true_target == nullptr && false_target == nullptr) { |
| 1501 | // Nothing to do. The code always falls through. |
| 1502 | return; |
| 1503 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1504 | // Constant condition, statically compared against 1. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1505 | if (cond->AsIntConstant()->IsOne()) { |
| 1506 | if (true_target != nullptr) { |
| 1507 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1508 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1509 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1510 | DCHECK(cond->AsIntConstant()->IsZero()); |
| 1511 | if (false_target != nullptr) { |
| 1512 | __ jmp(false_target); |
| 1513 | } |
| 1514 | } |
| 1515 | return; |
| 1516 | } |
| 1517 | |
| 1518 | // The following code generates these patterns: |
| 1519 | // (1) true_target == nullptr && false_target != nullptr |
| 1520 | // - opposite condition true => branch to false_target |
| 1521 | // (2) true_target != nullptr && false_target == nullptr |
| 1522 | // - condition true => branch to true_target |
| 1523 | // (3) true_target != nullptr && false_target != nullptr |
| 1524 | // - condition true => branch to true_target |
| 1525 | // - branch to false_target |
| 1526 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1527 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1528 | if (true_target == nullptr) { |
| 1529 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1530 | } else { |
| 1531 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
| 1532 | } |
| 1533 | } else { |
| 1534 | // Materialized condition, compare against 0. |
| 1535 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1536 | if (lhs.IsRegister()) { |
| 1537 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1538 | } else { |
| 1539 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), Immediate(0)); |
| 1540 | } |
| 1541 | if (true_target == nullptr) { |
| 1542 | __ j(kEqual, false_target); |
| 1543 | } else { |
| 1544 | __ j(kNotEqual, true_target); |
| 1545 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1546 | } |
| 1547 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1548 | // Condition has not been materialized, use its inputs as the |
| 1549 | // comparison and its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1550 | HCondition* condition = cond->AsCondition(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1551 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1552 | // If this is a long or FP comparison that has been folded into |
| 1553 | // the HCondition, generate the comparison directly. |
| 1554 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1555 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1556 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1557 | return; |
| 1558 | } |
| 1559 | |
| 1560 | Location lhs = condition->GetLocations()->InAt(0); |
| 1561 | Location rhs = condition->GetLocations()->InAt(1); |
| 1562 | if (rhs.IsRegister()) { |
| 1563 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1564 | } else if (rhs.IsConstant()) { |
| 1565 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1566 | if (constant == 0) { |
| 1567 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1568 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1569 | __ cmpl(lhs.AsRegister<CpuRegister>(), Immediate(constant)); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1570 | } |
| 1571 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1572 | __ cmpl(lhs.AsRegister<CpuRegister>(), |
| 1573 | Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1574 | } |
| 1575 | if (true_target == nullptr) { |
| 1576 | __ j(X86_64IntegerCondition(condition->GetOppositeCondition()), false_target); |
| 1577 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1578 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1579 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1580 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1581 | |
| 1582 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1583 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1584 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1585 | __ jmp(false_target); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1586 | } |
| 1587 | } |
| 1588 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1589 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1590 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1591 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1592 | locations->SetInAt(0, Location::Any()); |
| 1593 | } |
| 1594 | } |
| 1595 | |
| 1596 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1597 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1598 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1599 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1600 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1601 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1602 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1603 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1604 | } |
| 1605 | |
| 1606 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1607 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1608 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1609 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1610 | locations->SetInAt(0, Location::Any()); |
| 1611 | } |
| 1612 | } |
| 1613 | |
| 1614 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1615 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86_64>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1616 | GenerateTestAndBranch<Label>(deoptimize, |
| 1617 | /* condition_input_index */ 0, |
| 1618 | slow_path->GetEntryLabel(), |
| 1619 | /* false_target */ nullptr); |
| 1620 | } |
| 1621 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame^] | 1622 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1623 | // There are no conditional move instructions for XMMs. |
| 1624 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1625 | return false; |
| 1626 | } |
| 1627 | |
| 1628 | // A FP condition doesn't generate the single CC that we need. |
| 1629 | HInstruction* condition = select->GetCondition(); |
| 1630 | if (condition->IsCondition() && |
| 1631 | Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())) { |
| 1632 | return false; |
| 1633 | } |
| 1634 | |
| 1635 | // We can generate a CMOV for this Select. |
| 1636 | return true; |
| 1637 | } |
| 1638 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1639 | void LocationsBuilderX86_64::VisitSelect(HSelect* select) { |
| 1640 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 1641 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1642 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame^] | 1643 | // Since we can't use CMOV, there is no need to force 'true' into a register. |
| 1644 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1645 | } else { |
| 1646 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame^] | 1647 | if (SelectCanUseCMOV(select)) { |
| 1648 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1649 | } else { |
| 1650 | // Since we can't use CMOV, there is no need to force 'true' into a register. |
| 1651 | locations->SetInAt(1, Location::Any()); |
| 1652 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1653 | } |
| 1654 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1655 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1656 | } |
| 1657 | locations->SetOut(Location::SameAsFirstInput()); |
| 1658 | } |
| 1659 | |
| 1660 | void InstructionCodeGeneratorX86_64::VisitSelect(HSelect* select) { |
| 1661 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame^] | 1662 | if (SelectCanUseCMOV(select)) { |
| 1663 | // If both the condition and the source types are integer, we can generate |
| 1664 | // a CMOV to implement Select. |
| 1665 | CpuRegister value_false = locations->InAt(0).AsRegister<CpuRegister>(); |
| 1666 | CpuRegister value_true = locations->InAt(1).AsRegister<CpuRegister>(); |
| 1667 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1668 | |
| 1669 | HInstruction* select_condition = select->GetCondition(); |
| 1670 | Condition cond = kNotEqual; |
| 1671 | |
| 1672 | // Figure out how to test the 'condition'. |
| 1673 | if (select_condition->IsCondition()) { |
| 1674 | HCondition* condition = select_condition->AsCondition(); |
| 1675 | if (!condition->IsEmittedAtUseSite()) { |
| 1676 | // This was a previously materialized condition. |
| 1677 | // Can we use the existing condition code? |
| 1678 | if (AreEflagsSetFrom(condition, select)) { |
| 1679 | // Materialization was the previous instruction. Condition codes are right. |
| 1680 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1681 | } else { |
| 1682 | // No, we have to recreate the condition code. |
| 1683 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1684 | __ testl(cond_reg, cond_reg); |
| 1685 | } |
| 1686 | } else { |
| 1687 | GenerateCompareTest(condition); |
| 1688 | cond = X86_64IntegerCondition(condition->GetCondition()); |
| 1689 | } |
| 1690 | } else { |
| 1691 | // Must be a boolean condition, which needs to be compared to 0. |
| 1692 | CpuRegister cond_reg = locations->InAt(2).AsRegister<CpuRegister>(); |
| 1693 | __ testl(cond_reg, cond_reg); |
| 1694 | } |
| 1695 | |
| 1696 | // If the condition is true, overwrite the output, which already contains false. |
| 1697 | // Generate the correct sized CMOV. |
| 1698 | __ cmov(cond, value_false, value_true, select->GetType() == Primitive::kPrimLong); |
| 1699 | } else { |
| 1700 | NearLabel false_target; |
| 1701 | GenerateTestAndBranch<NearLabel>(select, |
| 1702 | /* condition_input_index */ 2, |
| 1703 | /* true_target */ nullptr, |
| 1704 | &false_target); |
| 1705 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1706 | __ Bind(&false_target); |
| 1707 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1708 | } |
| 1709 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1710 | void LocationsBuilderX86_64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1711 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1712 | } |
| 1713 | |
| 1714 | void InstructionCodeGeneratorX86_64::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
David Srbecky | b7070a2 | 2016-01-08 18:13:53 +0000 | [diff] [blame] | 1715 | if (codegen_->HasStackMapAtCurrentPc()) { |
| 1716 | // Ensure that we do not collide with the stack map of the previous instruction. |
| 1717 | __ nop(); |
| 1718 | } |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1719 | codegen_->RecordPcInfo(info, info->GetDexPc()); |
| 1720 | } |
| 1721 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1722 | void LocationsBuilderX86_64::VisitLocal(HLocal* local) { |
| 1723 | local->SetLocations(nullptr); |
| 1724 | } |
| 1725 | |
| 1726 | void InstructionCodeGeneratorX86_64::VisitLocal(HLocal* local) { |
| 1727 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
| 1728 | } |
| 1729 | |
| 1730 | void LocationsBuilderX86_64::VisitLoadLocal(HLoadLocal* local) { |
| 1731 | local->SetLocations(nullptr); |
| 1732 | } |
| 1733 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1734 | void InstructionCodeGeneratorX86_64::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1735 | // Nothing to do, this is driven by the code generator. |
| 1736 | } |
| 1737 | |
| 1738 | void LocationsBuilderX86_64::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1739 | LocationSummary* locations = |
| 1740 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1741 | switch (store->InputAt(1)->GetType()) { |
| 1742 | case Primitive::kPrimBoolean: |
| 1743 | case Primitive::kPrimByte: |
| 1744 | case Primitive::kPrimChar: |
| 1745 | case Primitive::kPrimShort: |
| 1746 | case Primitive::kPrimInt: |
| 1747 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1748 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1749 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1750 | break; |
| 1751 | |
| 1752 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1753 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1754 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1755 | break; |
| 1756 | |
| 1757 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1758 | LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1759 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1760 | } |
| 1761 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1762 | void InstructionCodeGeneratorX86_64::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1763 | } |
| 1764 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1765 | void LocationsBuilderX86_64::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1766 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1767 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1768 | // Handle the long/FP comparisons made in instruction simplification. |
| 1769 | switch (cond->InputAt(0)->GetType()) { |
| 1770 | case Primitive::kPrimLong: |
| 1771 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1772 | locations->SetInAt(1, Location::Any()); |
| 1773 | break; |
| 1774 | case Primitive::kPrimFloat: |
| 1775 | case Primitive::kPrimDouble: |
| 1776 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1777 | locations->SetInAt(1, Location::Any()); |
| 1778 | break; |
| 1779 | default: |
| 1780 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1781 | locations->SetInAt(1, Location::Any()); |
| 1782 | break; |
| 1783 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1784 | if (!cond->IsEmittedAtUseSite()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1785 | locations->SetOut(Location::RequiresRegister()); |
| 1786 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1787 | } |
| 1788 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1789 | void InstructionCodeGeneratorX86_64::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1790 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1791 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1792 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1793 | |
| 1794 | LocationSummary* locations = cond->GetLocations(); |
| 1795 | Location lhs = locations->InAt(0); |
| 1796 | Location rhs = locations->InAt(1); |
| 1797 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1798 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1799 | |
| 1800 | switch (cond->InputAt(0)->GetType()) { |
| 1801 | default: |
| 1802 | // Integer case. |
| 1803 | |
| 1804 | // Clear output register: setcc only sets the low byte. |
| 1805 | __ xorl(reg, reg); |
| 1806 | |
| 1807 | if (rhs.IsRegister()) { |
| 1808 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1809 | } else if (rhs.IsConstant()) { |
| 1810 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1811 | if (constant == 0) { |
| 1812 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1813 | } else { |
| 1814 | __ cmpl(lhs.AsRegister<CpuRegister>(), Immediate(constant)); |
| 1815 | } |
| 1816 | } else { |
| 1817 | __ cmpl(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1818 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1819 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1820 | return; |
| 1821 | case Primitive::kPrimLong: |
| 1822 | // Clear output register: setcc only sets the low byte. |
| 1823 | __ xorl(reg, reg); |
| 1824 | |
| 1825 | if (rhs.IsRegister()) { |
| 1826 | __ cmpq(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1827 | } else if (rhs.IsConstant()) { |
| 1828 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
| 1829 | if (IsInt<32>(value)) { |
| 1830 | if (value == 0) { |
| 1831 | __ testq(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1832 | } else { |
| 1833 | __ cmpq(lhs.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 1834 | } |
| 1835 | } else { |
| 1836 | // Value won't fit in an int. |
| 1837 | __ cmpq(lhs.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 1838 | } |
| 1839 | } else { |
| 1840 | __ cmpq(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1841 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1842 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1843 | return; |
| 1844 | case Primitive::kPrimFloat: { |
| 1845 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1846 | if (rhs.IsConstant()) { |
| 1847 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 1848 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 1849 | } else if (rhs.IsStackSlot()) { |
| 1850 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1851 | } else { |
| 1852 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1853 | } |
| 1854 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1855 | break; |
| 1856 | } |
| 1857 | case Primitive::kPrimDouble: { |
| 1858 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1859 | if (rhs.IsConstant()) { |
| 1860 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1861 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 1862 | } else if (rhs.IsDoubleStackSlot()) { |
| 1863 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1864 | } else { |
| 1865 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1866 | } |
| 1867 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1868 | break; |
| 1869 | } |
| 1870 | } |
| 1871 | |
| 1872 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1873 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1874 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1875 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1876 | __ Bind(&false_label); |
| 1877 | __ xorl(reg, reg); |
| 1878 | __ jmp(&done_label); |
| 1879 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1880 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1881 | __ Bind(&true_label); |
| 1882 | __ movl(reg, Immediate(1)); |
| 1883 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1884 | } |
| 1885 | |
| 1886 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1887 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1888 | } |
| 1889 | |
| 1890 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1891 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1892 | } |
| 1893 | |
| 1894 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1895 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1896 | } |
| 1897 | |
| 1898 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1899 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1900 | } |
| 1901 | |
| 1902 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1903 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1904 | } |
| 1905 | |
| 1906 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1907 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1908 | } |
| 1909 | |
| 1910 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1911 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1912 | } |
| 1913 | |
| 1914 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1915 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1916 | } |
| 1917 | |
| 1918 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1919 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1920 | } |
| 1921 | |
| 1922 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1923 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1924 | } |
| 1925 | |
| 1926 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1927 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1928 | } |
| 1929 | |
| 1930 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1931 | HandleCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1932 | } |
| 1933 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1934 | void LocationsBuilderX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1935 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1936 | } |
| 1937 | |
| 1938 | void InstructionCodeGeneratorX86_64::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1939 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1940 | } |
| 1941 | |
| 1942 | void LocationsBuilderX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1943 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1944 | } |
| 1945 | |
| 1946 | void InstructionCodeGeneratorX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1947 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1948 | } |
| 1949 | |
| 1950 | void LocationsBuilderX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1951 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1952 | } |
| 1953 | |
| 1954 | void InstructionCodeGeneratorX86_64::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1955 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | void LocationsBuilderX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1959 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | void InstructionCodeGeneratorX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1963 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1964 | } |
| 1965 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1966 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1967 | LocationSummary* locations = |
| 1968 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1969 | switch (compare->InputAt(0)->GetType()) { |
| 1970 | case Primitive::kPrimLong: { |
| 1971 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1972 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1973 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1974 | break; |
| 1975 | } |
| 1976 | case Primitive::kPrimFloat: |
| 1977 | case Primitive::kPrimDouble: { |
| 1978 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1979 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1980 | locations->SetOut(Location::RequiresRegister()); |
| 1981 | break; |
| 1982 | } |
| 1983 | default: |
| 1984 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 1985 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1986 | } |
| 1987 | |
| 1988 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1989 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1990 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1991 | Location left = locations->InAt(0); |
| 1992 | Location right = locations->InAt(1); |
| 1993 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1994 | NearLabel less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1995 | Primitive::Type type = compare->InputAt(0)->GetType(); |
| 1996 | switch (type) { |
| 1997 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1998 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1999 | if (right.IsConstant()) { |
| 2000 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2001 | if (IsInt<32>(value)) { |
| 2002 | if (value == 0) { |
| 2003 | __ testq(left_reg, left_reg); |
| 2004 | } else { |
| 2005 | __ cmpq(left_reg, Immediate(static_cast<int32_t>(value))); |
| 2006 | } |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2007 | } else { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2008 | // Value won't fit in an int. |
| 2009 | __ cmpq(left_reg, codegen_->LiteralInt64Address(value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2010 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2011 | } else if (right.IsDoubleStackSlot()) { |
| 2012 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2013 | } else { |
| 2014 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 2015 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2016 | break; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2017 | } |
| 2018 | case Primitive::kPrimFloat: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2019 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 2020 | if (right.IsConstant()) { |
| 2021 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 2022 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 2023 | } else if (right.IsStackSlot()) { |
| 2024 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 2025 | } else { |
| 2026 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 2027 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2028 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 2029 | break; |
| 2030 | } |
| 2031 | case Primitive::kPrimDouble: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2032 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 2033 | if (right.IsConstant()) { |
| 2034 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2035 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 2036 | } else if (right.IsDoubleStackSlot()) { |
| 2037 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 2038 | } else { |
| 2039 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 2040 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2041 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 2042 | break; |
| 2043 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2044 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2045 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2046 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2047 | __ movl(out, Immediate(0)); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2048 | __ j(kEqual, &done); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2049 | __ j(type == Primitive::kPrimLong ? kLess : kBelow, &less); // ucomis{s,d} sets CF (kBelow) |
Calin Juravle | fd86124 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2050 | |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 2051 | __ Bind(&greater); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2052 | __ movl(out, Immediate(1)); |
| 2053 | __ jmp(&done); |
| 2054 | |
| 2055 | __ Bind(&less); |
| 2056 | __ movl(out, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2057 | |
| 2058 | __ Bind(&done); |
| 2059 | } |
| 2060 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2061 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2062 | LocationSummary* locations = |
| 2063 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2064 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2065 | } |
| 2066 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2067 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2068 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2069 | } |
| 2070 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2071 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 2072 | LocationSummary* locations = |
| 2073 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2074 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2075 | } |
| 2076 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2077 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2078 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2079 | } |
| 2080 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2081 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2082 | LocationSummary* locations = |
| 2083 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2084 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2085 | } |
| 2086 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2087 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2088 | // Will be generated at use site. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2089 | } |
| 2090 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2091 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 2092 | LocationSummary* locations = |
| 2093 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2094 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2095 | } |
| 2096 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2097 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2098 | // Will be generated at use site. |
| 2099 | } |
| 2100 | |
| 2101 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 2102 | LocationSummary* locations = |
| 2103 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 2104 | locations->SetOut(Location::ConstantLocation(constant)); |
| 2105 | } |
| 2106 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2107 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant( |
| 2108 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2109 | // Will be generated at use site. |
| 2110 | } |
| 2111 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2112 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 2113 | memory_barrier->SetLocations(nullptr); |
| 2114 | } |
| 2115 | |
| 2116 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2117 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2118 | } |
| 2119 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2120 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 2121 | ret->SetLocations(nullptr); |
| 2122 | } |
| 2123 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2124 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2125 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2126 | } |
| 2127 | |
| 2128 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2129 | LocationSummary* locations = |
| 2130 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2131 | switch (ret->InputAt(0)->GetType()) { |
| 2132 | case Primitive::kPrimBoolean: |
| 2133 | case Primitive::kPrimByte: |
| 2134 | case Primitive::kPrimChar: |
| 2135 | case Primitive::kPrimShort: |
| 2136 | case Primitive::kPrimInt: |
| 2137 | case Primitive::kPrimNot: |
| 2138 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2139 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2140 | break; |
| 2141 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2142 | case Primitive::kPrimFloat: |
| 2143 | case Primitive::kPrimDouble: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2144 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2145 | break; |
| 2146 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2147 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2148 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2149 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2150 | } |
| 2151 | |
| 2152 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 2153 | if (kIsDebugBuild) { |
| 2154 | switch (ret->InputAt(0)->GetType()) { |
| 2155 | case Primitive::kPrimBoolean: |
| 2156 | case Primitive::kPrimByte: |
| 2157 | case Primitive::kPrimChar: |
| 2158 | case Primitive::kPrimShort: |
| 2159 | case Primitive::kPrimInt: |
| 2160 | case Primitive::kPrimNot: |
| 2161 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2162 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2163 | break; |
| 2164 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2165 | case Primitive::kPrimFloat: |
| 2166 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2167 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2168 | XMM0); |
| 2169 | break; |
| 2170 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2171 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2172 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2173 | } |
| 2174 | } |
| 2175 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2176 | } |
| 2177 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2178 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(Primitive::Type type) const { |
| 2179 | switch (type) { |
| 2180 | case Primitive::kPrimBoolean: |
| 2181 | case Primitive::kPrimByte: |
| 2182 | case Primitive::kPrimChar: |
| 2183 | case Primitive::kPrimShort: |
| 2184 | case Primitive::kPrimInt: |
| 2185 | case Primitive::kPrimNot: |
| 2186 | case Primitive::kPrimLong: |
| 2187 | return Location::RegisterLocation(RAX); |
| 2188 | |
| 2189 | case Primitive::kPrimVoid: |
| 2190 | return Location::NoLocation(); |
| 2191 | |
| 2192 | case Primitive::kPrimDouble: |
| 2193 | case Primitive::kPrimFloat: |
| 2194 | return Location::FpuRegisterLocation(XMM0); |
| 2195 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 2196 | |
| 2197 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2198 | } |
| 2199 | |
| 2200 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 2201 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 2202 | } |
| 2203 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2204 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2205 | switch (type) { |
| 2206 | case Primitive::kPrimBoolean: |
| 2207 | case Primitive::kPrimByte: |
| 2208 | case Primitive::kPrimChar: |
| 2209 | case Primitive::kPrimShort: |
| 2210 | case Primitive::kPrimInt: |
| 2211 | case Primitive::kPrimNot: { |
| 2212 | uint32_t index = gp_index_++; |
| 2213 | stack_index_++; |
| 2214 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2215 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2216 | } else { |
| 2217 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2218 | } |
| 2219 | } |
| 2220 | |
| 2221 | case Primitive::kPrimLong: { |
| 2222 | uint32_t index = gp_index_; |
| 2223 | stack_index_ += 2; |
| 2224 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2225 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2226 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2227 | } else { |
| 2228 | gp_index_ += 2; |
| 2229 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2230 | } |
| 2231 | } |
| 2232 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2233 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2234 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2235 | stack_index_++; |
| 2236 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2237 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2238 | } else { |
| 2239 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 2240 | } |
| 2241 | } |
| 2242 | |
| 2243 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2244 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2245 | stack_index_ += 2; |
| 2246 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2247 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2248 | } else { |
| 2249 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 2250 | } |
| 2251 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2252 | |
| 2253 | case Primitive::kPrimVoid: |
| 2254 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 2255 | break; |
| 2256 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2257 | return Location::NoLocation(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2258 | } |
| 2259 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2260 | void LocationsBuilderX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2261 | // The trampoline uses the same calling convention as dex calling conventions, |
| 2262 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 2263 | // the method_idx. |
| 2264 | HandleInvoke(invoke); |
| 2265 | } |
| 2266 | |
| 2267 | void InstructionCodeGeneratorX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2268 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2269 | } |
| 2270 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2271 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2272 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2273 | // art::PrepareForRegisterAllocation. |
| 2274 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2275 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2276 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2277 | if (intrinsic.TryDispatch(invoke)) { |
| 2278 | return; |
| 2279 | } |
| 2280 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2281 | HandleInvoke(invoke); |
| 2282 | } |
| 2283 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2284 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 2285 | if (invoke->GetLocations()->Intrinsified()) { |
| 2286 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 2287 | intrinsic.Dispatch(invoke); |
| 2288 | return true; |
| 2289 | } |
| 2290 | return false; |
| 2291 | } |
| 2292 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2293 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2294 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2295 | // art::PrepareForRegisterAllocation. |
| 2296 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2297 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2298 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2299 | return; |
| 2300 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2301 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2302 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2303 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 2304 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 2305 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2306 | } |
| 2307 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2308 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2309 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2310 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2311 | } |
| 2312 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2313 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2314 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2315 | if (intrinsic.TryDispatch(invoke)) { |
| 2316 | return; |
| 2317 | } |
| 2318 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2319 | HandleInvoke(invoke); |
| 2320 | } |
| 2321 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2322 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2323 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2324 | return; |
| 2325 | } |
| 2326 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2327 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2328 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2329 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2330 | } |
| 2331 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2332 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2333 | HandleInvoke(invoke); |
| 2334 | // Add the hidden argument. |
| 2335 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 2336 | } |
| 2337 | |
| 2338 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2339 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2340 | LocationSummary* locations = invoke->GetLocations(); |
| 2341 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2342 | CpuRegister hidden_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2343 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 2344 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86_64PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2345 | Location receiver = locations->InAt(0); |
| 2346 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 2347 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2348 | // Set the hidden argument. This is safe to do this here, as RAX |
| 2349 | // won't be modified thereafter, before the `call` instruction. |
| 2350 | DCHECK_EQ(RAX, hidden_reg.AsRegister()); |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2351 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2352 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2353 | if (receiver.IsStackSlot()) { |
| 2354 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2355 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2356 | __ movl(temp, Address(temp, class_offset)); |
| 2357 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2358 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2359 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2360 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2361 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2362 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2363 | // emit a read barrier for the previous class reference load. |
| 2364 | // However this is not required in practice, as this is an |
| 2365 | // intermediate/temporary reference and because the current |
| 2366 | // concurrent copying collector keeps the from-space memory |
| 2367 | // intact/accessible until the end of the marking phase (the |
| 2368 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2369 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2370 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2371 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2372 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2373 | __ call(Address(temp, |
| 2374 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64WordSize).SizeValue())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2375 | |
| 2376 | DCHECK(!codegen_->IsLeafMethod()); |
| 2377 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2378 | } |
| 2379 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2380 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 2381 | LocationSummary* locations = |
| 2382 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2383 | switch (neg->GetResultType()) { |
| 2384 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2385 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2386 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2387 | locations->SetOut(Location::SameAsFirstInput()); |
| 2388 | break; |
| 2389 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2390 | case Primitive::kPrimFloat: |
| 2391 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2392 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2393 | locations->SetOut(Location::SameAsFirstInput()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2394 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2395 | break; |
| 2396 | |
| 2397 | default: |
| 2398 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2399 | } |
| 2400 | } |
| 2401 | |
| 2402 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 2403 | LocationSummary* locations = neg->GetLocations(); |
| 2404 | Location out = locations->Out(); |
| 2405 | Location in = locations->InAt(0); |
| 2406 | switch (neg->GetResultType()) { |
| 2407 | case Primitive::kPrimInt: |
| 2408 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2409 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2410 | __ negl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2411 | break; |
| 2412 | |
| 2413 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2414 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2415 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2416 | __ negq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2417 | break; |
| 2418 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2419 | case Primitive::kPrimFloat: { |
| 2420 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2421 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2422 | // Implement float negation with an exclusive or with value |
| 2423 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2424 | // single-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2425 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2426 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2427 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2428 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2429 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2430 | case Primitive::kPrimDouble: { |
| 2431 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2432 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2433 | // Implement double negation with an exclusive or with value |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2434 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2435 | // a double-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2436 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2437 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2438 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2439 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2440 | |
| 2441 | default: |
| 2442 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2443 | } |
| 2444 | } |
| 2445 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2446 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2447 | LocationSummary* locations = |
| 2448 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 2449 | Primitive::Type result_type = conversion->GetResultType(); |
| 2450 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2451 | DCHECK_NE(result_type, input_type); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2452 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2453 | // The Java language does not allow treating boolean as an integral type but |
| 2454 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2455 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2456 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2457 | case Primitive::kPrimByte: |
| 2458 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2459 | case Primitive::kPrimBoolean: |
| 2460 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2461 | case Primitive::kPrimShort: |
| 2462 | case Primitive::kPrimInt: |
| 2463 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2464 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2465 | locations->SetInAt(0, Location::Any()); |
| 2466 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2467 | break; |
| 2468 | |
| 2469 | default: |
| 2470 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2471 | << " to " << result_type; |
| 2472 | } |
| 2473 | break; |
| 2474 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2475 | case Primitive::kPrimShort: |
| 2476 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2477 | case Primitive::kPrimBoolean: |
| 2478 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2479 | case Primitive::kPrimByte: |
| 2480 | case Primitive::kPrimInt: |
| 2481 | case Primitive::kPrimChar: |
| 2482 | // Processing a Dex `int-to-short' instruction. |
| 2483 | locations->SetInAt(0, Location::Any()); |
| 2484 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2485 | break; |
| 2486 | |
| 2487 | default: |
| 2488 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2489 | << " to " << result_type; |
| 2490 | } |
| 2491 | break; |
| 2492 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2493 | case Primitive::kPrimInt: |
| 2494 | switch (input_type) { |
| 2495 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2496 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2497 | locations->SetInAt(0, Location::Any()); |
| 2498 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2499 | break; |
| 2500 | |
| 2501 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2502 | // Processing a Dex `float-to-int' instruction. |
| 2503 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2504 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2505 | break; |
| 2506 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2507 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2508 | // Processing a Dex `double-to-int' instruction. |
| 2509 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2510 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2511 | break; |
| 2512 | |
| 2513 | default: |
| 2514 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2515 | << " to " << result_type; |
| 2516 | } |
| 2517 | break; |
| 2518 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2519 | case Primitive::kPrimLong: |
| 2520 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2521 | case Primitive::kPrimBoolean: |
| 2522 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2523 | case Primitive::kPrimByte: |
| 2524 | case Primitive::kPrimShort: |
| 2525 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2526 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2527 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2528 | // TODO: We would benefit from a (to-be-implemented) |
| 2529 | // Location::RegisterOrStackSlot requirement for this input. |
| 2530 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2531 | locations->SetOut(Location::RequiresRegister()); |
| 2532 | break; |
| 2533 | |
| 2534 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2535 | // Processing a Dex `float-to-long' instruction. |
| 2536 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2537 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2538 | break; |
| 2539 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2540 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2541 | // Processing a Dex `double-to-long' instruction. |
| 2542 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2543 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2544 | break; |
| 2545 | |
| 2546 | default: |
| 2547 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2548 | << " to " << result_type; |
| 2549 | } |
| 2550 | break; |
| 2551 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2552 | case Primitive::kPrimChar: |
| 2553 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2554 | case Primitive::kPrimBoolean: |
| 2555 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2556 | case Primitive::kPrimByte: |
| 2557 | case Primitive::kPrimShort: |
| 2558 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2559 | // Processing a Dex `int-to-char' instruction. |
| 2560 | locations->SetInAt(0, Location::Any()); |
| 2561 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2562 | break; |
| 2563 | |
| 2564 | default: |
| 2565 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2566 | << " to " << result_type; |
| 2567 | } |
| 2568 | break; |
| 2569 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2570 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2571 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2572 | case Primitive::kPrimBoolean: |
| 2573 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2574 | case Primitive::kPrimByte: |
| 2575 | case Primitive::kPrimShort: |
| 2576 | case Primitive::kPrimInt: |
| 2577 | case Primitive::kPrimChar: |
| 2578 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2579 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2580 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2581 | break; |
| 2582 | |
| 2583 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2584 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2585 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2586 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2587 | break; |
| 2588 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2589 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2590 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2591 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2592 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2593 | break; |
| 2594 | |
| 2595 | default: |
| 2596 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2597 | << " to " << result_type; |
| 2598 | }; |
| 2599 | break; |
| 2600 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2601 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2602 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2603 | case Primitive::kPrimBoolean: |
| 2604 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2605 | case Primitive::kPrimByte: |
| 2606 | case Primitive::kPrimShort: |
| 2607 | case Primitive::kPrimInt: |
| 2608 | case Primitive::kPrimChar: |
| 2609 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2610 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2611 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2612 | break; |
| 2613 | |
| 2614 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2615 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2616 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2617 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2618 | break; |
| 2619 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2620 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2621 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2622 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2623 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2624 | break; |
| 2625 | |
| 2626 | default: |
| 2627 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2628 | << " to " << result_type; |
| 2629 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2630 | break; |
| 2631 | |
| 2632 | default: |
| 2633 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2634 | << " to " << result_type; |
| 2635 | } |
| 2636 | } |
| 2637 | |
| 2638 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2639 | LocationSummary* locations = conversion->GetLocations(); |
| 2640 | Location out = locations->Out(); |
| 2641 | Location in = locations->InAt(0); |
| 2642 | Primitive::Type result_type = conversion->GetResultType(); |
| 2643 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2644 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2645 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2646 | case Primitive::kPrimByte: |
| 2647 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2648 | case Primitive::kPrimBoolean: |
| 2649 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2650 | case Primitive::kPrimShort: |
| 2651 | case Primitive::kPrimInt: |
| 2652 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2653 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2654 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2655 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2656 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2657 | __ movsxb(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2658 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2659 | } else { |
| 2660 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2661 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2662 | Immediate(static_cast<int8_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2663 | } |
| 2664 | break; |
| 2665 | |
| 2666 | default: |
| 2667 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2668 | << " to " << result_type; |
| 2669 | } |
| 2670 | break; |
| 2671 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2672 | case Primitive::kPrimShort: |
| 2673 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2674 | case Primitive::kPrimBoolean: |
| 2675 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2676 | case Primitive::kPrimByte: |
| 2677 | case Primitive::kPrimInt: |
| 2678 | case Primitive::kPrimChar: |
| 2679 | // Processing a Dex `int-to-short' instruction. |
| 2680 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2681 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2682 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2683 | __ movsxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2684 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2685 | } else { |
| 2686 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2687 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2688 | Immediate(static_cast<int16_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2689 | } |
| 2690 | break; |
| 2691 | |
| 2692 | default: |
| 2693 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2694 | << " to " << result_type; |
| 2695 | } |
| 2696 | break; |
| 2697 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2698 | case Primitive::kPrimInt: |
| 2699 | switch (input_type) { |
| 2700 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2701 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2702 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2703 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2704 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2705 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2706 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2707 | } else { |
| 2708 | DCHECK(in.IsConstant()); |
| 2709 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2710 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2711 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2712 | } |
| 2713 | break; |
| 2714 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2715 | case Primitive::kPrimFloat: { |
| 2716 | // Processing a Dex `float-to-int' instruction. |
| 2717 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2718 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2719 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2720 | |
| 2721 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2722 | // if input >= (float)INT_MAX goto done |
| 2723 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimIntMax)); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2724 | __ j(kAboveEqual, &done); |
| 2725 | // if input == NaN goto nan |
| 2726 | __ j(kUnordered, &nan); |
| 2727 | // output = float-to-int-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2728 | __ cvttss2si(output, input, false); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2729 | __ jmp(&done); |
| 2730 | __ Bind(&nan); |
| 2731 | // output = 0 |
| 2732 | __ xorl(output, output); |
| 2733 | __ Bind(&done); |
| 2734 | break; |
| 2735 | } |
| 2736 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2737 | case Primitive::kPrimDouble: { |
| 2738 | // Processing a Dex `double-to-int' instruction. |
| 2739 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2740 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2741 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2742 | |
| 2743 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2744 | // if input >= (double)INT_MAX goto done |
| 2745 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2746 | __ j(kAboveEqual, &done); |
| 2747 | // if input == NaN goto nan |
| 2748 | __ j(kUnordered, &nan); |
| 2749 | // output = double-to-int-truncate(input) |
| 2750 | __ cvttsd2si(output, input); |
| 2751 | __ jmp(&done); |
| 2752 | __ Bind(&nan); |
| 2753 | // output = 0 |
| 2754 | __ xorl(output, output); |
| 2755 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2756 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2757 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2758 | |
| 2759 | default: |
| 2760 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2761 | << " to " << result_type; |
| 2762 | } |
| 2763 | break; |
| 2764 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2765 | case Primitive::kPrimLong: |
| 2766 | switch (input_type) { |
| 2767 | DCHECK(out.IsRegister()); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2768 | case Primitive::kPrimBoolean: |
| 2769 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2770 | case Primitive::kPrimByte: |
| 2771 | case Primitive::kPrimShort: |
| 2772 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2773 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2774 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2775 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2776 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2777 | break; |
| 2778 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2779 | case Primitive::kPrimFloat: { |
| 2780 | // Processing a Dex `float-to-long' instruction. |
| 2781 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2782 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2783 | NearLabel done, nan; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2784 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2785 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2786 | // if input >= (float)LONG_MAX goto done |
| 2787 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimLongMax)); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2788 | __ j(kAboveEqual, &done); |
| 2789 | // if input == NaN goto nan |
| 2790 | __ j(kUnordered, &nan); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2791 | // output = float-to-long-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2792 | __ cvttss2si(output, input, true); |
| 2793 | __ jmp(&done); |
| 2794 | __ Bind(&nan); |
| 2795 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2796 | __ xorl(output, output); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2797 | __ Bind(&done); |
| 2798 | break; |
| 2799 | } |
| 2800 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2801 | case Primitive::kPrimDouble: { |
| 2802 | // Processing a Dex `double-to-long' instruction. |
| 2803 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2804 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2805 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2806 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2807 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2808 | // if input >= (double)LONG_MAX goto done |
| 2809 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimLongMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2810 | __ j(kAboveEqual, &done); |
| 2811 | // if input == NaN goto nan |
| 2812 | __ j(kUnordered, &nan); |
| 2813 | // output = double-to-long-truncate(input) |
| 2814 | __ cvttsd2si(output, input, true); |
| 2815 | __ jmp(&done); |
| 2816 | __ Bind(&nan); |
| 2817 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2818 | __ xorl(output, output); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2819 | __ Bind(&done); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2820 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2821 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2822 | |
| 2823 | default: |
| 2824 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2825 | << " to " << result_type; |
| 2826 | } |
| 2827 | break; |
| 2828 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2829 | case Primitive::kPrimChar: |
| 2830 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2831 | case Primitive::kPrimBoolean: |
| 2832 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2833 | case Primitive::kPrimByte: |
| 2834 | case Primitive::kPrimShort: |
| 2835 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2836 | // Processing a Dex `int-to-char' instruction. |
| 2837 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2838 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2839 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2840 | __ movzxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2841 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2842 | } else { |
| 2843 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2844 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 2845 | Immediate(static_cast<uint16_t>( |
| 2846 | in.GetConstant()->AsIntConstant()->GetValue()))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2847 | } |
| 2848 | break; |
| 2849 | |
| 2850 | default: |
| 2851 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2852 | << " to " << result_type; |
| 2853 | } |
| 2854 | break; |
| 2855 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2856 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2857 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2858 | case Primitive::kPrimBoolean: |
| 2859 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2860 | case Primitive::kPrimByte: |
| 2861 | case Primitive::kPrimShort: |
| 2862 | case Primitive::kPrimInt: |
| 2863 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2864 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2865 | if (in.IsRegister()) { |
| 2866 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2867 | } else if (in.IsConstant()) { |
| 2868 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2869 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame^] | 2870 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2871 | } else { |
| 2872 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2873 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2874 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2875 | break; |
| 2876 | |
| 2877 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2878 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2879 | if (in.IsRegister()) { |
| 2880 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2881 | } else if (in.IsConstant()) { |
| 2882 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2883 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame^] | 2884 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2885 | } else { |
| 2886 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2887 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2888 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2889 | break; |
| 2890 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2891 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2892 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2893 | if (in.IsFpuRegister()) { |
| 2894 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2895 | } else if (in.IsConstant()) { |
| 2896 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2897 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame^] | 2898 | codegen_->Load32BitValue(dest, static_cast<float>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2899 | } else { |
| 2900 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 2901 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2902 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2903 | break; |
| 2904 | |
| 2905 | default: |
| 2906 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2907 | << " to " << result_type; |
| 2908 | }; |
| 2909 | break; |
| 2910 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2911 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2912 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2913 | case Primitive::kPrimBoolean: |
| 2914 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2915 | case Primitive::kPrimByte: |
| 2916 | case Primitive::kPrimShort: |
| 2917 | case Primitive::kPrimInt: |
| 2918 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2919 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2920 | if (in.IsRegister()) { |
| 2921 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2922 | } else if (in.IsConstant()) { |
| 2923 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2924 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame^] | 2925 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2926 | } else { |
| 2927 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2928 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2929 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2930 | break; |
| 2931 | |
| 2932 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2933 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2934 | if (in.IsRegister()) { |
| 2935 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2936 | } else if (in.IsConstant()) { |
| 2937 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2938 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame^] | 2939 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2940 | } else { |
| 2941 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2942 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2943 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2944 | break; |
| 2945 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2946 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2947 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2948 | if (in.IsFpuRegister()) { |
| 2949 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2950 | } else if (in.IsConstant()) { |
| 2951 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 2952 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame^] | 2953 | codegen_->Load64BitValue(dest, static_cast<double>(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2954 | } else { |
| 2955 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 2956 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2957 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2958 | break; |
| 2959 | |
| 2960 | default: |
| 2961 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2962 | << " to " << result_type; |
| 2963 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2964 | break; |
| 2965 | |
| 2966 | default: |
| 2967 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2968 | << " to " << result_type; |
| 2969 | } |
| 2970 | } |
| 2971 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2972 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2973 | LocationSummary* locations = |
| 2974 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2975 | switch (add->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2976 | case Primitive::kPrimInt: { |
| 2977 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2978 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2979 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2980 | break; |
| 2981 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2982 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2983 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2984 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2985 | // 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] | 2986 | locations->SetInAt(1, Location::RegisterOrInt32Constant(add->InputAt(1))); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2987 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2988 | break; |
| 2989 | } |
| 2990 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2991 | case Primitive::kPrimDouble: |
| 2992 | case Primitive::kPrimFloat: { |
| 2993 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2994 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2995 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2996 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2997 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2998 | |
| 2999 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3000 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3001 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3002 | } |
| 3003 | |
| 3004 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 3005 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3006 | Location first = locations->InAt(0); |
| 3007 | Location second = locations->InAt(1); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3008 | Location out = locations->Out(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3009 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3010 | switch (add->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3011 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3012 | if (second.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3013 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3014 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3015 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3016 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3017 | } else { |
| 3018 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3019 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3020 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3021 | } else if (second.IsConstant()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3022 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3023 | __ addl(out.AsRegister<CpuRegister>(), |
| 3024 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 3025 | } else { |
| 3026 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 3027 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 3028 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3029 | } else { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3030 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3031 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3032 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3033 | break; |
| 3034 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3035 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3036 | case Primitive::kPrimLong: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3037 | if (second.IsRegister()) { |
| 3038 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3039 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3040 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 3041 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3042 | } else { |
| 3043 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3044 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 3045 | } |
| 3046 | } else { |
| 3047 | DCHECK(second.IsConstant()); |
| 3048 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3049 | int32_t int32_value = Low32Bits(value); |
| 3050 | DCHECK_EQ(int32_value, value); |
| 3051 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 3052 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 3053 | } else { |
| 3054 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 3055 | first.AsRegister<CpuRegister>(), int32_value)); |
| 3056 | } |
| 3057 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3058 | break; |
| 3059 | } |
| 3060 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3061 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3062 | if (second.IsFpuRegister()) { |
| 3063 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3064 | } else if (second.IsConstant()) { |
| 3065 | __ addss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3066 | codegen_->LiteralFloatAddress( |
| 3067 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3068 | } else { |
| 3069 | DCHECK(second.IsStackSlot()); |
| 3070 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 3071 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3072 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3073 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3074 | } |
| 3075 | |
| 3076 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3077 | if (second.IsFpuRegister()) { |
| 3078 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3079 | } else if (second.IsConstant()) { |
| 3080 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3081 | codegen_->LiteralDoubleAddress( |
| 3082 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3083 | } else { |
| 3084 | DCHECK(second.IsDoubleStackSlot()); |
| 3085 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 3086 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3087 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3088 | break; |
| 3089 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3090 | |
| 3091 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3092 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3093 | } |
| 3094 | } |
| 3095 | |
| 3096 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3097 | LocationSummary* locations = |
| 3098 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3099 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3100 | case Primitive::kPrimInt: { |
| 3101 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3102 | locations->SetInAt(1, Location::Any()); |
| 3103 | locations->SetOut(Location::SameAsFirstInput()); |
| 3104 | break; |
| 3105 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3106 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3107 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 3108 | locations->SetInAt(1, Location::RegisterOrInt32Constant(sub->InputAt(1))); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3109 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3110 | break; |
| 3111 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3112 | case Primitive::kPrimFloat: |
| 3113 | case Primitive::kPrimDouble: { |
| 3114 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3115 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3116 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3117 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3118 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3119 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3120 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3121 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3122 | } |
| 3123 | |
| 3124 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 3125 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3126 | Location first = locations->InAt(0); |
| 3127 | Location second = locations->InAt(1); |
| 3128 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3129 | switch (sub->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3130 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3131 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3132 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3133 | } else if (second.IsConstant()) { |
| 3134 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3135 | __ subl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3136 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3137 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 3138 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3139 | break; |
| 3140 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3141 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3142 | if (second.IsConstant()) { |
| 3143 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3144 | DCHECK(IsInt<32>(value)); |
| 3145 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 3146 | } else { |
| 3147 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 3148 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3149 | break; |
| 3150 | } |
| 3151 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3152 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3153 | if (second.IsFpuRegister()) { |
| 3154 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3155 | } else if (second.IsConstant()) { |
| 3156 | __ subss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3157 | codegen_->LiteralFloatAddress( |
| 3158 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3159 | } else { |
| 3160 | DCHECK(second.IsStackSlot()); |
| 3161 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 3162 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3163 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3164 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3165 | } |
| 3166 | |
| 3167 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3168 | if (second.IsFpuRegister()) { |
| 3169 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3170 | } else if (second.IsConstant()) { |
| 3171 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3172 | codegen_->LiteralDoubleAddress( |
| 3173 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3174 | } else { |
| 3175 | DCHECK(second.IsDoubleStackSlot()); |
| 3176 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3177 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3178 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3179 | break; |
| 3180 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3181 | |
| 3182 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3183 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3184 | } |
| 3185 | } |
| 3186 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3187 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 3188 | LocationSummary* locations = |
| 3189 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3190 | switch (mul->GetResultType()) { |
| 3191 | case Primitive::kPrimInt: { |
| 3192 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3193 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3194 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3195 | // Can use 3 operand multiply. |
| 3196 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3197 | } else { |
| 3198 | locations->SetOut(Location::SameAsFirstInput()); |
| 3199 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3200 | break; |
| 3201 | } |
| 3202 | case Primitive::kPrimLong: { |
| 3203 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3204 | locations->SetInAt(1, Location::Any()); |
| 3205 | if (mul->InputAt(1)->IsLongConstant() && |
| 3206 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3207 | // Can use 3 operand multiply. |
| 3208 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3209 | } else { |
| 3210 | locations->SetOut(Location::SameAsFirstInput()); |
| 3211 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3212 | break; |
| 3213 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3214 | case Primitive::kPrimFloat: |
| 3215 | case Primitive::kPrimDouble: { |
| 3216 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3217 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3218 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3219 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3220 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3221 | |
| 3222 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3223 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3224 | } |
| 3225 | } |
| 3226 | |
| 3227 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 3228 | LocationSummary* locations = mul->GetLocations(); |
| 3229 | Location first = locations->InAt(0); |
| 3230 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3231 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3232 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3233 | case Primitive::kPrimInt: |
| 3234 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3235 | // problems where the output may not be the same as the first operand. |
| 3236 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3237 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3238 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 3239 | } else if (second.IsRegister()) { |
| 3240 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3241 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3242 | } else { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3243 | DCHECK(first.Equals(out)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3244 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3245 | __ imull(first.AsRegister<CpuRegister>(), |
| 3246 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3247 | } |
| 3248 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3249 | case Primitive::kPrimLong: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3250 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3251 | // problems where the output may not be the same as the first operand. |
| 3252 | if (mul->InputAt(1)->IsLongConstant()) { |
| 3253 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 3254 | if (IsInt<32>(value)) { |
| 3255 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 3256 | Immediate(static_cast<int32_t>(value))); |
| 3257 | } else { |
| 3258 | // Have to use the constant area. |
| 3259 | DCHECK(first.Equals(out)); |
| 3260 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 3261 | } |
| 3262 | } else if (second.IsRegister()) { |
| 3263 | DCHECK(first.Equals(out)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3264 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3265 | } else { |
| 3266 | DCHECK(second.IsDoubleStackSlot()); |
| 3267 | DCHECK(first.Equals(out)); |
| 3268 | __ imulq(first.AsRegister<CpuRegister>(), |
| 3269 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3270 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3271 | break; |
| 3272 | } |
| 3273 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3274 | case Primitive::kPrimFloat: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3275 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3276 | if (second.IsFpuRegister()) { |
| 3277 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3278 | } else if (second.IsConstant()) { |
| 3279 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3280 | codegen_->LiteralFloatAddress( |
| 3281 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3282 | } else { |
| 3283 | DCHECK(second.IsStackSlot()); |
| 3284 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3285 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3286 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3287 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3288 | } |
| 3289 | |
| 3290 | case Primitive::kPrimDouble: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3291 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3292 | if (second.IsFpuRegister()) { |
| 3293 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3294 | } else if (second.IsConstant()) { |
| 3295 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3296 | codegen_->LiteralDoubleAddress( |
| 3297 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3298 | } else { |
| 3299 | DCHECK(second.IsDoubleStackSlot()); |
| 3300 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3301 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3302 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3303 | break; |
| 3304 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3305 | |
| 3306 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3307 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3308 | } |
| 3309 | } |
| 3310 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3311 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 3312 | uint32_t stack_adjustment, bool is_float) { |
| 3313 | if (source.IsStackSlot()) { |
| 3314 | DCHECK(is_float); |
| 3315 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3316 | } else if (source.IsDoubleStackSlot()) { |
| 3317 | DCHECK(!is_float); |
| 3318 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 3319 | } else { |
| 3320 | // Write the value to the temporary location on the stack and load to FP stack. |
| 3321 | if (is_float) { |
| 3322 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3323 | codegen_->Move(stack_temp, source); |
| 3324 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 3325 | } else { |
| 3326 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3327 | codegen_->Move(stack_temp, source); |
| 3328 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 3329 | } |
| 3330 | } |
| 3331 | } |
| 3332 | |
| 3333 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| 3334 | Primitive::Type type = rem->GetResultType(); |
| 3335 | bool is_float = type == Primitive::kPrimFloat; |
| 3336 | size_t elem_size = Primitive::ComponentSize(type); |
| 3337 | LocationSummary* locations = rem->GetLocations(); |
| 3338 | Location first = locations->InAt(0); |
| 3339 | Location second = locations->InAt(1); |
| 3340 | Location out = locations->Out(); |
| 3341 | |
| 3342 | // Create stack space for 2 elements. |
| 3343 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3344 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3345 | |
| 3346 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 3347 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 3348 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 3349 | |
| 3350 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3351 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3352 | __ Bind(&retry); |
| 3353 | __ fprem(); |
| 3354 | |
| 3355 | // Move FP status to AX. |
| 3356 | __ fstsw(); |
| 3357 | |
| 3358 | // And see if the argument reduction is complete. This is signaled by the |
| 3359 | // C2 FPU flag bit set to 0. |
| 3360 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 3361 | __ j(kNotEqual, &retry); |
| 3362 | |
| 3363 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3364 | // Store FP top of stack to real stack. |
| 3365 | if (is_float) { |
| 3366 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 3367 | } else { |
| 3368 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 3369 | } |
| 3370 | |
| 3371 | // Pop the 2 items from the FP stack. |
| 3372 | __ fucompp(); |
| 3373 | |
| 3374 | // Load the value from the stack into an XMM register. |
| 3375 | DCHECK(out.IsFpuRegister()) << out; |
| 3376 | if (is_float) { |
| 3377 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3378 | } else { |
| 3379 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 3380 | } |
| 3381 | |
| 3382 | // And remove the temporary stack space we allocated. |
| 3383 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 3384 | } |
| 3385 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3386 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3387 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3388 | |
| 3389 | LocationSummary* locations = instruction->GetLocations(); |
| 3390 | Location second = locations->InAt(1); |
| 3391 | DCHECK(second.IsConstant()); |
| 3392 | |
| 3393 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3394 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3395 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3396 | |
| 3397 | DCHECK(imm == 1 || imm == -1); |
| 3398 | |
| 3399 | switch (instruction->GetResultType()) { |
| 3400 | case Primitive::kPrimInt: { |
| 3401 | if (instruction->IsRem()) { |
| 3402 | __ xorl(output_register, output_register); |
| 3403 | } else { |
| 3404 | __ movl(output_register, input_register); |
| 3405 | if (imm == -1) { |
| 3406 | __ negl(output_register); |
| 3407 | } |
| 3408 | } |
| 3409 | break; |
| 3410 | } |
| 3411 | |
| 3412 | case Primitive::kPrimLong: { |
| 3413 | if (instruction->IsRem()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3414 | __ xorl(output_register, output_register); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3415 | } else { |
| 3416 | __ movq(output_register, input_register); |
| 3417 | if (imm == -1) { |
| 3418 | __ negq(output_register); |
| 3419 | } |
| 3420 | } |
| 3421 | break; |
| 3422 | } |
| 3423 | |
| 3424 | default: |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3425 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3426 | } |
| 3427 | } |
| 3428 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3429 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3430 | LocationSummary* locations = instruction->GetLocations(); |
| 3431 | Location second = locations->InAt(1); |
| 3432 | |
| 3433 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 3434 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3435 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3436 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3437 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3438 | uint64_t abs_imm = AbsOrMin(imm); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3439 | |
| 3440 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3441 | |
| 3442 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3443 | __ leal(tmp, Address(numerator, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3444 | __ testl(numerator, numerator); |
| 3445 | __ cmov(kGreaterEqual, tmp, numerator); |
| 3446 | int shift = CTZ(imm); |
| 3447 | __ sarl(tmp, Immediate(shift)); |
| 3448 | |
| 3449 | if (imm < 0) { |
| 3450 | __ negl(tmp); |
| 3451 | } |
| 3452 | |
| 3453 | __ movl(output_register, tmp); |
| 3454 | } else { |
| 3455 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3456 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3457 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3458 | codegen_->Load64BitValue(rdx, abs_imm - 1); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3459 | __ addq(rdx, numerator); |
| 3460 | __ testq(numerator, numerator); |
| 3461 | __ cmov(kGreaterEqual, rdx, numerator); |
| 3462 | int shift = CTZ(imm); |
| 3463 | __ sarq(rdx, Immediate(shift)); |
| 3464 | |
| 3465 | if (imm < 0) { |
| 3466 | __ negq(rdx); |
| 3467 | } |
| 3468 | |
| 3469 | __ movq(output_register, rdx); |
| 3470 | } |
| 3471 | } |
| 3472 | |
| 3473 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3474 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3475 | |
| 3476 | LocationSummary* locations = instruction->GetLocations(); |
| 3477 | Location second = locations->InAt(1); |
| 3478 | |
| 3479 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 3480 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3481 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3482 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 3483 | : locations->Out().AsRegister<CpuRegister>(); |
| 3484 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3485 | |
| 3486 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 3487 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 3488 | if (instruction->IsDiv()) { |
| 3489 | DCHECK_EQ(RAX, out.AsRegister()); |
| 3490 | } else { |
| 3491 | DCHECK_EQ(RDX, out.AsRegister()); |
| 3492 | } |
| 3493 | |
| 3494 | int64_t magic; |
| 3495 | int shift; |
| 3496 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3497 | // TODO: can these branches be written as one? |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3498 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 3499 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3500 | |
| 3501 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3502 | |
| 3503 | __ movl(numerator, eax); |
| 3504 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3505 | NearLabel no_div; |
| 3506 | NearLabel end; |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3507 | __ testl(eax, eax); |
| 3508 | __ j(kNotEqual, &no_div); |
| 3509 | |
| 3510 | __ xorl(out, out); |
| 3511 | __ jmp(&end); |
| 3512 | |
| 3513 | __ Bind(&no_div); |
| 3514 | |
| 3515 | __ movl(eax, Immediate(magic)); |
| 3516 | __ imull(numerator); |
| 3517 | |
| 3518 | if (imm > 0 && magic < 0) { |
| 3519 | __ addl(edx, numerator); |
| 3520 | } else if (imm < 0 && magic > 0) { |
| 3521 | __ subl(edx, numerator); |
| 3522 | } |
| 3523 | |
| 3524 | if (shift != 0) { |
| 3525 | __ sarl(edx, Immediate(shift)); |
| 3526 | } |
| 3527 | |
| 3528 | __ movl(eax, edx); |
| 3529 | __ shrl(edx, Immediate(31)); |
| 3530 | __ addl(edx, eax); |
| 3531 | |
| 3532 | if (instruction->IsRem()) { |
| 3533 | __ movl(eax, numerator); |
| 3534 | __ imull(edx, Immediate(imm)); |
| 3535 | __ subl(eax, edx); |
| 3536 | __ movl(edx, eax); |
| 3537 | } else { |
| 3538 | __ movl(eax, edx); |
| 3539 | } |
| 3540 | __ Bind(&end); |
| 3541 | } else { |
| 3542 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3543 | |
| 3544 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3545 | |
| 3546 | CpuRegister rax = eax; |
| 3547 | CpuRegister rdx = edx; |
| 3548 | |
| 3549 | CalculateMagicAndShiftForDivRem(imm, true /* is_long */, &magic, &shift); |
| 3550 | |
| 3551 | // Save the numerator. |
| 3552 | __ movq(numerator, rax); |
| 3553 | |
| 3554 | // RAX = magic |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3555 | codegen_->Load64BitValue(rax, magic); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3556 | |
| 3557 | // RDX:RAX = magic * numerator |
| 3558 | __ imulq(numerator); |
| 3559 | |
| 3560 | if (imm > 0 && magic < 0) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3561 | // RDX += numerator |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3562 | __ addq(rdx, numerator); |
| 3563 | } else if (imm < 0 && magic > 0) { |
| 3564 | // RDX -= numerator |
| 3565 | __ subq(rdx, numerator); |
| 3566 | } |
| 3567 | |
| 3568 | // Shift if needed. |
| 3569 | if (shift != 0) { |
| 3570 | __ sarq(rdx, Immediate(shift)); |
| 3571 | } |
| 3572 | |
| 3573 | // RDX += 1 if RDX < 0 |
| 3574 | __ movq(rax, rdx); |
| 3575 | __ shrq(rdx, Immediate(63)); |
| 3576 | __ addq(rdx, rax); |
| 3577 | |
| 3578 | if (instruction->IsRem()) { |
| 3579 | __ movq(rax, numerator); |
| 3580 | |
| 3581 | if (IsInt<32>(imm)) { |
| 3582 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 3583 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3584 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3585 | } |
| 3586 | |
| 3587 | __ subq(rax, rdx); |
| 3588 | __ movq(rdx, rax); |
| 3589 | } else { |
| 3590 | __ movq(rax, rdx); |
| 3591 | } |
| 3592 | } |
| 3593 | } |
| 3594 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3595 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3596 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3597 | Primitive::Type type = instruction->GetResultType(); |
| 3598 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 3599 | |
| 3600 | bool is_div = instruction->IsDiv(); |
| 3601 | LocationSummary* locations = instruction->GetLocations(); |
| 3602 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3603 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3604 | Location second = locations->InAt(1); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3605 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3606 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3607 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3608 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3609 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3610 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3611 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3612 | if (imm == 0) { |
| 3613 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3614 | } else if (imm == 1 || imm == -1) { |
| 3615 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3616 | } else if (instruction->IsDiv() && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3617 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3618 | } else { |
| 3619 | DCHECK(imm <= -2 || imm >= 2); |
| 3620 | GenerateDivRemWithAnyConstant(instruction); |
| 3621 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3622 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3623 | SlowPathCode* slow_path = |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3624 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86_64( |
| 3625 | out.AsRegister(), type, is_div); |
| 3626 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3627 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3628 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3629 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3630 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3631 | // so it's safe to just use negl instead of more complex comparisons. |
| 3632 | if (type == Primitive::kPrimInt) { |
| 3633 | __ cmpl(second_reg, Immediate(-1)); |
| 3634 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3635 | // edx:eax <- sign-extended of eax |
| 3636 | __ cdq(); |
| 3637 | // eax = quotient, edx = remainder |
| 3638 | __ idivl(second_reg); |
| 3639 | } else { |
| 3640 | __ cmpq(second_reg, Immediate(-1)); |
| 3641 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3642 | // rdx:rax <- sign-extended of rax |
| 3643 | __ cqo(); |
| 3644 | // rax = quotient, rdx = remainder |
| 3645 | __ idivq(second_reg); |
| 3646 | } |
| 3647 | __ Bind(slow_path->GetExitLabel()); |
| 3648 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3649 | } |
| 3650 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3651 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3652 | LocationSummary* locations = |
| 3653 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3654 | switch (div->GetResultType()) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3655 | case Primitive::kPrimInt: |
| 3656 | case Primitive::kPrimLong: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3657 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3658 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3659 | locations->SetOut(Location::SameAsFirstInput()); |
| 3660 | // Intel uses edx:eax as the dividend. |
| 3661 | locations->AddTemp(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3662 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3663 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3664 | // output and request another temp. |
| 3665 | if (div->InputAt(1)->IsConstant()) { |
| 3666 | locations->AddTemp(Location::RequiresRegister()); |
| 3667 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3668 | break; |
| 3669 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3670 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3671 | case Primitive::kPrimFloat: |
| 3672 | case Primitive::kPrimDouble: { |
| 3673 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3674 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3675 | locations->SetOut(Location::SameAsFirstInput()); |
| 3676 | break; |
| 3677 | } |
| 3678 | |
| 3679 | default: |
| 3680 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3681 | } |
| 3682 | } |
| 3683 | |
| 3684 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3685 | LocationSummary* locations = div->GetLocations(); |
| 3686 | Location first = locations->InAt(0); |
| 3687 | Location second = locations->InAt(1); |
| 3688 | DCHECK(first.Equals(locations->Out())); |
| 3689 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3690 | Primitive::Type type = div->GetResultType(); |
| 3691 | switch (type) { |
| 3692 | case Primitive::kPrimInt: |
| 3693 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3694 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3695 | break; |
| 3696 | } |
| 3697 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3698 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3699 | if (second.IsFpuRegister()) { |
| 3700 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3701 | } else if (second.IsConstant()) { |
| 3702 | __ divss(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3703 | codegen_->LiteralFloatAddress( |
| 3704 | second.GetConstant()->AsFloatConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3705 | } else { |
| 3706 | DCHECK(second.IsStackSlot()); |
| 3707 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3708 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3709 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3710 | break; |
| 3711 | } |
| 3712 | |
| 3713 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3714 | if (second.IsFpuRegister()) { |
| 3715 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3716 | } else if (second.IsConstant()) { |
| 3717 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 3718 | codegen_->LiteralDoubleAddress( |
| 3719 | second.GetConstant()->AsDoubleConstant()->GetValue())); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3720 | } else { |
| 3721 | DCHECK(second.IsDoubleStackSlot()); |
| 3722 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3723 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3724 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3725 | break; |
| 3726 | } |
| 3727 | |
| 3728 | default: |
| 3729 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3730 | } |
| 3731 | } |
| 3732 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3733 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3734 | Primitive::Type type = rem->GetResultType(); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3735 | LocationSummary* locations = |
| 3736 | new (GetGraph()->GetArena()) LocationSummary(rem, LocationSummary::kNoCall); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3737 | |
| 3738 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3739 | case Primitive::kPrimInt: |
| 3740 | case Primitive::kPrimLong: { |
| 3741 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3742 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3743 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3744 | locations->SetOut(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3745 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3746 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3747 | // output and request another temp. |
| 3748 | if (rem->InputAt(1)->IsConstant()) { |
| 3749 | locations->AddTemp(Location::RequiresRegister()); |
| 3750 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3751 | break; |
| 3752 | } |
| 3753 | |
| 3754 | case Primitive::kPrimFloat: |
| 3755 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3756 | locations->SetInAt(0, Location::Any()); |
| 3757 | locations->SetInAt(1, Location::Any()); |
| 3758 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3759 | locations->AddTemp(Location::RegisterLocation(RAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3760 | break; |
| 3761 | } |
| 3762 | |
| 3763 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3764 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3765 | } |
| 3766 | } |
| 3767 | |
| 3768 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| 3769 | Primitive::Type type = rem->GetResultType(); |
| 3770 | switch (type) { |
| 3771 | case Primitive::kPrimInt: |
| 3772 | case Primitive::kPrimLong: { |
| 3773 | GenerateDivRemIntegral(rem); |
| 3774 | break; |
| 3775 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3776 | case Primitive::kPrimFloat: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3777 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3778 | GenerateRemFP(rem); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3779 | break; |
| 3780 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3781 | default: |
| 3782 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3783 | } |
| 3784 | } |
| 3785 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3786 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3787 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3788 | ? LocationSummary::kCallOnSlowPath |
| 3789 | : LocationSummary::kNoCall; |
| 3790 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3791 | locations->SetInAt(0, Location::Any()); |
| 3792 | if (instruction->HasUses()) { |
| 3793 | locations->SetOut(Location::SameAsFirstInput()); |
| 3794 | } |
| 3795 | } |
| 3796 | |
| 3797 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3798 | SlowPathCode* slow_path = |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3799 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction); |
| 3800 | codegen_->AddSlowPath(slow_path); |
| 3801 | |
| 3802 | LocationSummary* locations = instruction->GetLocations(); |
| 3803 | Location value = locations->InAt(0); |
| 3804 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3805 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3806 | case Primitive::kPrimByte: |
| 3807 | case Primitive::kPrimChar: |
| 3808 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3809 | case Primitive::kPrimInt: { |
| 3810 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3811 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3812 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3813 | } else if (value.IsStackSlot()) { |
| 3814 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3815 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3816 | } else { |
| 3817 | DCHECK(value.IsConstant()) << value; |
| 3818 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3819 | __ jmp(slow_path->GetEntryLabel()); |
| 3820 | } |
| 3821 | } |
| 3822 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3823 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3824 | case Primitive::kPrimLong: { |
| 3825 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3826 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3827 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3828 | } else if (value.IsDoubleStackSlot()) { |
| 3829 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3830 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3831 | } else { |
| 3832 | DCHECK(value.IsConstant()) << value; |
| 3833 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3834 | __ jmp(slow_path->GetEntryLabel()); |
| 3835 | } |
| 3836 | } |
| 3837 | break; |
| 3838 | } |
| 3839 | default: |
| 3840 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3841 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3842 | } |
| 3843 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3844 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 3845 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3846 | |
| 3847 | LocationSummary* locations = |
| 3848 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3849 | |
| 3850 | switch (op->GetResultType()) { |
| 3851 | case Primitive::kPrimInt: |
| 3852 | case Primitive::kPrimLong: { |
| 3853 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3854 | // The shift count needs to be in CL. |
| 3855 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 3856 | locations->SetOut(Location::SameAsFirstInput()); |
| 3857 | break; |
| 3858 | } |
| 3859 | default: |
| 3860 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3861 | } |
| 3862 | } |
| 3863 | |
| 3864 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 3865 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3866 | |
| 3867 | LocationSummary* locations = op->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3868 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3869 | Location second = locations->InAt(1); |
| 3870 | |
| 3871 | switch (op->GetResultType()) { |
| 3872 | case Primitive::kPrimInt: { |
| 3873 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3874 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3875 | if (op->IsShl()) { |
| 3876 | __ shll(first_reg, second_reg); |
| 3877 | } else if (op->IsShr()) { |
| 3878 | __ sarl(first_reg, second_reg); |
| 3879 | } else { |
| 3880 | __ shrl(first_reg, second_reg); |
| 3881 | } |
| 3882 | } else { |
Nicolas Geoffray | 486cc19 | 2014-12-08 18:00:55 +0000 | [diff] [blame] | 3883 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3884 | if (op->IsShl()) { |
| 3885 | __ shll(first_reg, imm); |
| 3886 | } else if (op->IsShr()) { |
| 3887 | __ sarl(first_reg, imm); |
| 3888 | } else { |
| 3889 | __ shrl(first_reg, imm); |
| 3890 | } |
| 3891 | } |
| 3892 | break; |
| 3893 | } |
| 3894 | case Primitive::kPrimLong: { |
| 3895 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3896 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3897 | if (op->IsShl()) { |
| 3898 | __ shlq(first_reg, second_reg); |
| 3899 | } else if (op->IsShr()) { |
| 3900 | __ sarq(first_reg, second_reg); |
| 3901 | } else { |
| 3902 | __ shrq(first_reg, second_reg); |
| 3903 | } |
| 3904 | } else { |
Nicolas Geoffray | 486cc19 | 2014-12-08 18:00:55 +0000 | [diff] [blame] | 3905 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3906 | if (op->IsShl()) { |
| 3907 | __ shlq(first_reg, imm); |
| 3908 | } else if (op->IsShr()) { |
| 3909 | __ sarq(first_reg, imm); |
| 3910 | } else { |
| 3911 | __ shrq(first_reg, imm); |
| 3912 | } |
| 3913 | } |
| 3914 | break; |
| 3915 | } |
| 3916 | default: |
| 3917 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
Vladimir Marko | 351dddf | 2015-12-11 16:34:46 +0000 | [diff] [blame] | 3918 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3919 | } |
| 3920 | } |
| 3921 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3922 | void LocationsBuilderX86_64::VisitRor(HRor* ror) { |
| 3923 | LocationSummary* locations = |
| 3924 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3925 | |
| 3926 | switch (ror->GetResultType()) { |
| 3927 | case Primitive::kPrimInt: |
| 3928 | case Primitive::kPrimLong: { |
| 3929 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3930 | // The shift count needs to be in CL (unless it is a constant). |
| 3931 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, ror->InputAt(1))); |
| 3932 | locations->SetOut(Location::SameAsFirstInput()); |
| 3933 | break; |
| 3934 | } |
| 3935 | default: |
| 3936 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3937 | UNREACHABLE(); |
| 3938 | } |
| 3939 | } |
| 3940 | |
| 3941 | void InstructionCodeGeneratorX86_64::VisitRor(HRor* ror) { |
| 3942 | LocationSummary* locations = ror->GetLocations(); |
| 3943 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3944 | Location second = locations->InAt(1); |
| 3945 | |
| 3946 | switch (ror->GetResultType()) { |
| 3947 | case Primitive::kPrimInt: |
| 3948 | if (second.IsRegister()) { |
| 3949 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3950 | __ rorl(first_reg, second_reg); |
| 3951 | } else { |
| 3952 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
| 3953 | __ rorl(first_reg, imm); |
| 3954 | } |
| 3955 | break; |
| 3956 | case Primitive::kPrimLong: |
| 3957 | if (second.IsRegister()) { |
| 3958 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3959 | __ rorq(first_reg, second_reg); |
| 3960 | } else { |
| 3961 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue); |
| 3962 | __ rorq(first_reg, imm); |
| 3963 | } |
| 3964 | break; |
| 3965 | default: |
| 3966 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3967 | UNREACHABLE(); |
| 3968 | } |
| 3969 | } |
| 3970 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3971 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 3972 | HandleShift(shl); |
| 3973 | } |
| 3974 | |
| 3975 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 3976 | HandleShift(shl); |
| 3977 | } |
| 3978 | |
| 3979 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 3980 | HandleShift(shr); |
| 3981 | } |
| 3982 | |
| 3983 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 3984 | HandleShift(shr); |
| 3985 | } |
| 3986 | |
| 3987 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 3988 | HandleShift(ushr); |
| 3989 | } |
| 3990 | |
| 3991 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 3992 | HandleShift(ushr); |
| 3993 | } |
| 3994 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3995 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3996 | LocationSummary* locations = |
| 3997 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3998 | InvokeRuntimeCallingConvention calling_convention; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3999 | if (instruction->IsStringAlloc()) { |
| 4000 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4001 | } else { |
| 4002 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4003 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 4004 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4005 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4006 | } |
| 4007 | |
| 4008 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4009 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4010 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4011 | if (instruction->IsStringAlloc()) { |
| 4012 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4013 | CpuRegister temp = instruction->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
| 4014 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86_64WordSize); |
| 4015 | __ gs()->movq(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString), /* no_rip */ true)); |
| 4016 | __ call(Address(temp, code_offset.SizeValue())); |
| 4017 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4018 | } else { |
| 4019 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 4020 | instruction, |
| 4021 | instruction->GetDexPc(), |
| 4022 | nullptr); |
| 4023 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 4024 | DCHECK(!codegen_->IsLeafMethod()); |
| 4025 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4026 | } |
| 4027 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4028 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 4029 | LocationSummary* locations = |
| 4030 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4031 | InvokeRuntimeCallingConvention calling_convention; |
| 4032 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4033 | locations->SetOut(Location::RegisterLocation(RAX)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4034 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4035 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4036 | } |
| 4037 | |
| 4038 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| 4039 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4040 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 4041 | instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4042 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4043 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4044 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 4045 | instruction, |
| 4046 | instruction->GetDexPc(), |
| 4047 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4048 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4049 | |
| 4050 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4051 | } |
| 4052 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4053 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4054 | LocationSummary* locations = |
| 4055 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4056 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4057 | if (location.IsStackSlot()) { |
| 4058 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4059 | } else if (location.IsDoubleStackSlot()) { |
| 4060 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4061 | } |
| 4062 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4063 | } |
| 4064 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4065 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 4066 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4067 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4068 | } |
| 4069 | |
| 4070 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4071 | LocationSummary* locations = |
| 4072 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4073 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4074 | } |
| 4075 | |
| 4076 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 4077 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 4078 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4079 | } |
| 4080 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4081 | void LocationsBuilderX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4082 | LocationSummary* locations = |
| 4083 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4084 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4085 | locations->SetOut(Location::RequiresRegister()); |
| 4086 | } |
| 4087 | |
| 4088 | void InstructionCodeGeneratorX86_64::VisitClassTableGet(HClassTableGet* instruction) { |
| 4089 | LocationSummary* locations = instruction->GetLocations(); |
| 4090 | uint32_t method_offset = 0; |
| 4091 | if (instruction->GetTableKind() == HClassTableGet::kVTable) { |
| 4092 | method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4093 | instruction->GetIndex(), kX86_64PointerSize).SizeValue(); |
| 4094 | } else { |
| 4095 | method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 4096 | instruction->GetIndex() % mirror::Class::kImtSize, kX86_64PointerSize).Uint32Value(); |
| 4097 | } |
| 4098 | __ movq(locations->Out().AsRegister<CpuRegister>(), |
| 4099 | Address(locations->InAt(0).AsRegister<CpuRegister>(), method_offset)); |
| 4100 | } |
| 4101 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4102 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4103 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4104 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4105 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4106 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4107 | } |
| 4108 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4109 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 4110 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4111 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4112 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4113 | Location out = locations->Out(); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4114 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4115 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4116 | __ notl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4117 | break; |
| 4118 | |
| 4119 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4120 | __ notq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4121 | break; |
| 4122 | |
| 4123 | default: |
| 4124 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4125 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4126 | } |
| 4127 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4128 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4129 | LocationSummary* locations = |
| 4130 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4131 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4132 | locations->SetOut(Location::SameAsFirstInput()); |
| 4133 | } |
| 4134 | |
| 4135 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4136 | LocationSummary* locations = bool_not->GetLocations(); |
| 4137 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 4138 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 4139 | Location out = locations->Out(); |
| 4140 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 4141 | } |
| 4142 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4143 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4144 | LocationSummary* locations = |
| 4145 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4146 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 4147 | locations->SetInAt(i, Location::Any()); |
| 4148 | } |
| 4149 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4150 | } |
| 4151 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4152 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4153 | LOG(FATAL) << "Unimplemented"; |
| 4154 | } |
| 4155 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4156 | void CodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4157 | /* |
| 4158 | * 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] | 4159 | * 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] | 4160 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4161 | */ |
| 4162 | switch (kind) { |
| 4163 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4164 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4165 | break; |
| 4166 | } |
| 4167 | case MemBarrierKind::kAnyStore: |
| 4168 | case MemBarrierKind::kLoadAny: |
| 4169 | case MemBarrierKind::kStoreStore: { |
| 4170 | // nop |
| 4171 | break; |
| 4172 | } |
| 4173 | default: |
| 4174 | LOG(FATAL) << "Unexpected memory barier " << kind; |
| 4175 | } |
| 4176 | } |
| 4177 | |
| 4178 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 4179 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4180 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4181 | bool object_field_get_with_read_barrier = |
| 4182 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4183 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4184 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4185 | object_field_get_with_read_barrier ? |
| 4186 | LocationSummary::kCallOnSlowPath : |
| 4187 | LocationSummary::kNoCall); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4188 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4189 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4190 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4191 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4192 | // The output overlaps for an object field get when read barriers |
| 4193 | // are enabled: we do not want the move to overwrite the object's |
| 4194 | // location, as we need it to emit the read barrier. |
| 4195 | locations->SetOut( |
| 4196 | Location::RequiresRegister(), |
| 4197 | object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4198 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4199 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4200 | // We need a temporary register for the read barrier marking slow |
| 4201 | // path in CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier. |
| 4202 | locations->AddTemp(Location::RequiresRegister()); |
| 4203 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4204 | } |
| 4205 | |
| 4206 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 4207 | const FieldInfo& field_info) { |
| 4208 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 4209 | |
| 4210 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4211 | Location base_loc = locations->InAt(0); |
| 4212 | CpuRegister base = base_loc.AsRegister<CpuRegister>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4213 | Location out = locations->Out(); |
| 4214 | bool is_volatile = field_info.IsVolatile(); |
| 4215 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4216 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4217 | |
| 4218 | switch (field_type) { |
| 4219 | case Primitive::kPrimBoolean: { |
| 4220 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4221 | break; |
| 4222 | } |
| 4223 | |
| 4224 | case Primitive::kPrimByte: { |
| 4225 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4226 | break; |
| 4227 | } |
| 4228 | |
| 4229 | case Primitive::kPrimShort: { |
| 4230 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4231 | break; |
| 4232 | } |
| 4233 | |
| 4234 | case Primitive::kPrimChar: { |
| 4235 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4236 | break; |
| 4237 | } |
| 4238 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4239 | case Primitive::kPrimInt: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4240 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4241 | break; |
| 4242 | } |
| 4243 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4244 | case Primitive::kPrimNot: { |
| 4245 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4246 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4247 | Location temp_loc = locations->GetTemp(0); |
| 4248 | // Note that a potential implicit null check is handled in this |
| 4249 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4250 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4251 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4252 | if (is_volatile) { |
| 4253 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4254 | } |
| 4255 | } else { |
| 4256 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4257 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4258 | if (is_volatile) { |
| 4259 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4260 | } |
| 4261 | // If read barriers are enabled, emit read barriers other than |
| 4262 | // Baker's using a slow path (and also unpoison the loaded |
| 4263 | // reference, if heap poisoning is enabled). |
| 4264 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4265 | } |
| 4266 | break; |
| 4267 | } |
| 4268 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4269 | case Primitive::kPrimLong: { |
| 4270 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 4271 | break; |
| 4272 | } |
| 4273 | |
| 4274 | case Primitive::kPrimFloat: { |
| 4275 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4276 | break; |
| 4277 | } |
| 4278 | |
| 4279 | case Primitive::kPrimDouble: { |
| 4280 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 4281 | break; |
| 4282 | } |
| 4283 | |
| 4284 | case Primitive::kPrimVoid: |
| 4285 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4286 | UNREACHABLE(); |
| 4287 | } |
| 4288 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4289 | if (field_type == Primitive::kPrimNot) { |
| 4290 | // Potential implicit null checks, in the case of reference |
| 4291 | // fields, are handled in the previous switch statement. |
| 4292 | } else { |
| 4293 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4294 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4295 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4296 | if (is_volatile) { |
| 4297 | if (field_type == Primitive::kPrimNot) { |
| 4298 | // Memory barriers, in the case of references, are also handled |
| 4299 | // in the previous switch statement. |
| 4300 | } else { |
| 4301 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4302 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4303 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4304 | } |
| 4305 | |
| 4306 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 4307 | const FieldInfo& field_info) { |
| 4308 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4309 | |
| 4310 | LocationSummary* locations = |
| 4311 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4312 | Primitive::Type field_type = field_info.GetFieldType(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4313 | bool is_volatile = field_info.IsVolatile(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4314 | bool needs_write_barrier = |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4315 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4316 | |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4317 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4318 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4319 | if (is_volatile) { |
| 4320 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4321 | locations->SetInAt(1, Location::FpuRegisterOrInt32Constant(instruction->InputAt(1))); |
| 4322 | } else { |
| 4323 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4324 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4325 | } else { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4326 | if (is_volatile) { |
| 4327 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4328 | locations->SetInAt(1, Location::RegisterOrInt32Constant(instruction->InputAt(1))); |
| 4329 | } else { |
| 4330 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4331 | } |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4332 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4333 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4334 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4335 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4336 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4337 | } else if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4338 | // Temporary register for the reference poisoning. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4339 | locations->AddTemp(Location::RequiresRegister()); |
| 4340 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4341 | } |
| 4342 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4343 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4344 | const FieldInfo& field_info, |
| 4345 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4346 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4347 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4348 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4349 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4350 | Location value = locations->InAt(1); |
| 4351 | bool is_volatile = field_info.IsVolatile(); |
| 4352 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4353 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4354 | |
| 4355 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4356 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4357 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4358 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4359 | bool maybe_record_implicit_null_check_done = false; |
| 4360 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4361 | switch (field_type) { |
| 4362 | case Primitive::kPrimBoolean: |
| 4363 | case Primitive::kPrimByte: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4364 | if (value.IsConstant()) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4365 | int8_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4366 | __ movb(Address(base, offset), Immediate(v)); |
| 4367 | } else { |
| 4368 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4369 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4370 | break; |
| 4371 | } |
| 4372 | |
| 4373 | case Primitive::kPrimShort: |
| 4374 | case Primitive::kPrimChar: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4375 | if (value.IsConstant()) { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4376 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4377 | __ movw(Address(base, offset), Immediate(v)); |
| 4378 | } else { |
| 4379 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4380 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4381 | break; |
| 4382 | } |
| 4383 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4384 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4385 | case Primitive::kPrimNot: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4386 | if (value.IsConstant()) { |
| 4387 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4388 | // `field_type == Primitive::kPrimNot` implies `v == 0`. |
| 4389 | DCHECK((field_type != Primitive::kPrimNot) || (v == 0)); |
| 4390 | // Note: if heap poisoning is enabled, no need to poison |
| 4391 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 4392 | __ movl(Address(base, offset), Immediate(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4393 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4394 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 4395 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4396 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4397 | __ PoisonHeapReference(temp); |
| 4398 | __ movl(Address(base, offset), temp); |
| 4399 | } else { |
| 4400 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4401 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4402 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4403 | break; |
| 4404 | } |
| 4405 | |
| 4406 | case Primitive::kPrimLong: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4407 | if (value.IsConstant()) { |
| 4408 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4409 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4410 | Address(base, offset + sizeof(int32_t)), |
| 4411 | v, |
| 4412 | instruction); |
| 4413 | maybe_record_implicit_null_check_done = true; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4414 | } else { |
| 4415 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 4416 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4417 | break; |
| 4418 | } |
| 4419 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4420 | case Primitive::kPrimFloat: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4421 | if (value.IsConstant()) { |
| 4422 | int32_t v = |
| 4423 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 4424 | __ movl(Address(base, offset), Immediate(v)); |
| 4425 | } else { |
| 4426 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4427 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4428 | break; |
| 4429 | } |
| 4430 | |
| 4431 | case Primitive::kPrimDouble: { |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4432 | if (value.IsConstant()) { |
| 4433 | int64_t v = |
| 4434 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 4435 | codegen_->MoveInt64ToAddress(Address(base, offset), |
| 4436 | Address(base, offset + sizeof(int32_t)), |
| 4437 | v, |
| 4438 | instruction); |
| 4439 | maybe_record_implicit_null_check_done = true; |
| 4440 | } else { |
| 4441 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4442 | } |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4443 | break; |
| 4444 | } |
| 4445 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4446 | case Primitive::kPrimVoid: |
| 4447 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4448 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4449 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4450 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4451 | if (!maybe_record_implicit_null_check_done) { |
| 4452 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4453 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4454 | |
| 4455 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4456 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4457 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4458 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4459 | } |
| 4460 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4461 | if (is_volatile) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4462 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4463 | } |
| 4464 | } |
| 4465 | |
| 4466 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4467 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4468 | } |
| 4469 | |
| 4470 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4471 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4472 | } |
| 4473 | |
| 4474 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4475 | HandleFieldGet(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4476 | } |
| 4477 | |
| 4478 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4479 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4480 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4481 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4482 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4483 | HandleFieldGet(instruction); |
| 4484 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4485 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4486 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4487 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4488 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4489 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4490 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4491 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4492 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4493 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4494 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4495 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4496 | } |
| 4497 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4498 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldGet( |
| 4499 | HUnresolvedInstanceFieldGet* instruction) { |
| 4500 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4501 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4502 | instruction, instruction->GetFieldType(), calling_convention); |
| 4503 | } |
| 4504 | |
| 4505 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldGet( |
| 4506 | HUnresolvedInstanceFieldGet* instruction) { |
| 4507 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4508 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4509 | instruction->GetFieldType(), |
| 4510 | instruction->GetFieldIndex(), |
| 4511 | instruction->GetDexPc(), |
| 4512 | calling_convention); |
| 4513 | } |
| 4514 | |
| 4515 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldSet( |
| 4516 | HUnresolvedInstanceFieldSet* instruction) { |
| 4517 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4518 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4519 | instruction, instruction->GetFieldType(), calling_convention); |
| 4520 | } |
| 4521 | |
| 4522 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldSet( |
| 4523 | HUnresolvedInstanceFieldSet* instruction) { |
| 4524 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4525 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4526 | instruction->GetFieldType(), |
| 4527 | instruction->GetFieldIndex(), |
| 4528 | instruction->GetDexPc(), |
| 4529 | calling_convention); |
| 4530 | } |
| 4531 | |
| 4532 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldGet( |
| 4533 | HUnresolvedStaticFieldGet* instruction) { |
| 4534 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4535 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4536 | instruction, instruction->GetFieldType(), calling_convention); |
| 4537 | } |
| 4538 | |
| 4539 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldGet( |
| 4540 | HUnresolvedStaticFieldGet* instruction) { |
| 4541 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4542 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4543 | instruction->GetFieldType(), |
| 4544 | instruction->GetFieldIndex(), |
| 4545 | instruction->GetDexPc(), |
| 4546 | calling_convention); |
| 4547 | } |
| 4548 | |
| 4549 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldSet( |
| 4550 | HUnresolvedStaticFieldSet* instruction) { |
| 4551 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4552 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4553 | instruction, instruction->GetFieldType(), calling_convention); |
| 4554 | } |
| 4555 | |
| 4556 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldSet( |
| 4557 | HUnresolvedStaticFieldSet* instruction) { |
| 4558 | FieldAccessCallingConventionX86_64 calling_convention; |
| 4559 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4560 | instruction->GetFieldType(), |
| 4561 | instruction->GetFieldIndex(), |
| 4562 | instruction->GetDexPc(), |
| 4563 | calling_convention); |
| 4564 | } |
| 4565 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4566 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4567 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4568 | ? LocationSummary::kCallOnSlowPath |
| 4569 | : LocationSummary::kNoCall; |
| 4570 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4571 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4572 | ? Location::RequiresRegister() |
| 4573 | : Location::Any(); |
| 4574 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4575 | if (instruction->HasUses()) { |
| 4576 | locations->SetOut(Location::SameAsFirstInput()); |
| 4577 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4578 | } |
| 4579 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4580 | void InstructionCodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4581 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 4582 | return; |
| 4583 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4584 | LocationSummary* locations = instruction->GetLocations(); |
| 4585 | Location obj = locations->InAt(0); |
| 4586 | |
| 4587 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
| 4588 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4589 | } |
| 4590 | |
| 4591 | void InstructionCodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4592 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4593 | codegen_->AddSlowPath(slow_path); |
| 4594 | |
| 4595 | LocationSummary* locations = instruction->GetLocations(); |
| 4596 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4597 | |
| 4598 | if (obj.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4599 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4600 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4601 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4602 | } else { |
| 4603 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4604 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4605 | __ jmp(slow_path->GetEntryLabel()); |
| 4606 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4607 | } |
| 4608 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4609 | } |
| 4610 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4611 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4612 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4613 | GenerateImplicitNullCheck(instruction); |
| 4614 | } else { |
| 4615 | GenerateExplicitNullCheck(instruction); |
| 4616 | } |
| 4617 | } |
| 4618 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4619 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4620 | bool object_array_get_with_read_barrier = |
| 4621 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4622 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4623 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4624 | object_array_get_with_read_barrier ? |
| 4625 | LocationSummary::kCallOnSlowPath : |
| 4626 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4627 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4628 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4629 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4630 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4631 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4632 | // The output overlaps for an object array get when read barriers |
| 4633 | // are enabled: we do not want the move to overwrite the array's |
| 4634 | // location, as we need it to emit the read barrier. |
| 4635 | locations->SetOut( |
| 4636 | Location::RequiresRegister(), |
| 4637 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4638 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4639 | // We need a temporary register for the read barrier marking slow |
| 4640 | // path in CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier. |
| 4641 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4642 | locations->AddTemp(Location::RequiresRegister()); |
| 4643 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4644 | } |
| 4645 | |
| 4646 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 4647 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4648 | Location obj_loc = locations->InAt(0); |
| 4649 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4650 | Location index = locations->InAt(1); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4651 | Location out_loc = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4652 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4653 | Primitive::Type type = instruction->GetType(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4654 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4655 | case Primitive::kPrimBoolean: { |
| 4656 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4657 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4658 | if (index.IsConstant()) { |
| 4659 | __ movzxb(out, Address(obj, |
| 4660 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4661 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4662 | __ movzxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4663 | } |
| 4664 | break; |
| 4665 | } |
| 4666 | |
| 4667 | case Primitive::kPrimByte: { |
| 4668 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4669 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4670 | if (index.IsConstant()) { |
| 4671 | __ movsxb(out, Address(obj, |
| 4672 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4673 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4674 | __ movsxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4675 | } |
| 4676 | break; |
| 4677 | } |
| 4678 | |
| 4679 | case Primitive::kPrimShort: { |
| 4680 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4681 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4682 | if (index.IsConstant()) { |
| 4683 | __ movsxw(out, Address(obj, |
| 4684 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4685 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4686 | __ movsxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4687 | } |
| 4688 | break; |
| 4689 | } |
| 4690 | |
| 4691 | case Primitive::kPrimChar: { |
| 4692 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4693 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4694 | if (index.IsConstant()) { |
| 4695 | __ movzxw(out, Address(obj, |
| 4696 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4697 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4698 | __ movzxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4699 | } |
| 4700 | break; |
| 4701 | } |
| 4702 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4703 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4704 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4705 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4706 | if (index.IsConstant()) { |
| 4707 | __ movl(out, Address(obj, |
| 4708 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4709 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4710 | __ movl(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4711 | } |
| 4712 | break; |
| 4713 | } |
| 4714 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4715 | case Primitive::kPrimNot: { |
| 4716 | static_assert( |
| 4717 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4718 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 4719 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4720 | // /* HeapReference<Object> */ out = |
| 4721 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4722 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4723 | Location temp = locations->GetTemp(0); |
| 4724 | // Note that a potential implicit null check is handled in this |
| 4725 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 4726 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 4727 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 4728 | } else { |
| 4729 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
| 4730 | if (index.IsConstant()) { |
| 4731 | uint32_t offset = |
| 4732 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4733 | __ movl(out, Address(obj, offset)); |
| 4734 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4735 | // If read barriers are enabled, emit read barriers other than |
| 4736 | // Baker's using a slow path (and also unpoison the loaded |
| 4737 | // reference, if heap poisoning is enabled). |
| 4738 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 4739 | } else { |
| 4740 | __ movl(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
| 4741 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4742 | // If read barriers are enabled, emit read barriers other than |
| 4743 | // Baker's using a slow path (and also unpoison the loaded |
| 4744 | // reference, if heap poisoning is enabled). |
| 4745 | codegen_->MaybeGenerateReadBarrierSlow( |
| 4746 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 4747 | } |
| 4748 | } |
| 4749 | break; |
| 4750 | } |
| 4751 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4752 | case Primitive::kPrimLong: { |
| 4753 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4754 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4755 | if (index.IsConstant()) { |
| 4756 | __ movq(out, Address(obj, |
| 4757 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4758 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4759 | __ movq(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4760 | } |
| 4761 | break; |
| 4762 | } |
| 4763 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4764 | case Primitive::kPrimFloat: { |
| 4765 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4766 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4767 | if (index.IsConstant()) { |
| 4768 | __ movss(out, Address(obj, |
| 4769 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4770 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4771 | __ movss(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4772 | } |
| 4773 | break; |
| 4774 | } |
| 4775 | |
| 4776 | case Primitive::kPrimDouble: { |
| 4777 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4778 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4779 | if (index.IsConstant()) { |
| 4780 | __ movsd(out, Address(obj, |
| 4781 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4782 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4783 | __ movsd(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4784 | } |
| 4785 | break; |
| 4786 | } |
| 4787 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4788 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4789 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4790 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4791 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4792 | |
| 4793 | if (type == Primitive::kPrimNot) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4794 | // Potential implicit null checks, in the case of reference |
| 4795 | // arrays, are handled in the previous switch statement. |
| 4796 | } else { |
| 4797 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4798 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4799 | } |
| 4800 | |
| 4801 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4802 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4803 | |
| 4804 | bool needs_write_barrier = |
| 4805 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4806 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4807 | bool object_array_set_with_read_barrier = |
| 4808 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4809 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4810 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4811 | instruction, |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4812 | (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] | 4813 | LocationSummary::kCallOnSlowPath : |
| 4814 | LocationSummary::kNoCall); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4815 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4816 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 4817 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4818 | if (Primitive::IsFloatingPointType(value_type)) { |
| 4819 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4820 | } else { |
| 4821 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 4822 | } |
| 4823 | |
| 4824 | if (needs_write_barrier) { |
| 4825 | // Temporary registers for the write barrier. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4826 | |
| 4827 | // This first temporary register is possibly used for heap |
| 4828 | // reference poisoning and/or read barrier emission too. |
| 4829 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4830 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4831 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4832 | } |
| 4833 | |
| 4834 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 4835 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4836 | Location array_loc = locations->InAt(0); |
| 4837 | CpuRegister array = array_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4838 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4839 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4840 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4841 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4842 | bool needs_write_barrier = |
| 4843 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4844 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4845 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4846 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4847 | |
| 4848 | switch (value_type) { |
| 4849 | case Primitive::kPrimBoolean: |
| 4850 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4851 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 4852 | Address address = index.IsConstant() |
| 4853 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 4854 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_1, offset); |
| 4855 | if (value.IsRegister()) { |
| 4856 | __ movb(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4857 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4858 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4859 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4860 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4861 | break; |
| 4862 | } |
| 4863 | |
| 4864 | case Primitive::kPrimShort: |
| 4865 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4866 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 4867 | Address address = index.IsConstant() |
| 4868 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 4869 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_2, offset); |
| 4870 | if (value.IsRegister()) { |
| 4871 | __ movw(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4872 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4873 | DCHECK(value.IsConstant()) << value; |
| 4874 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4875 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4876 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4877 | break; |
| 4878 | } |
| 4879 | |
| 4880 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4881 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4882 | Address address = index.IsConstant() |
| 4883 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4884 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4885 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4886 | if (!value.IsRegister()) { |
| 4887 | // Just setting null. |
| 4888 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 4889 | DCHECK(value.IsConstant()) << value; |
| 4890 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4891 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4892 | DCHECK(!needs_write_barrier); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4893 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4894 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4895 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4896 | |
| 4897 | DCHECK(needs_write_barrier); |
| 4898 | CpuRegister register_value = value.AsRegister<CpuRegister>(); |
| 4899 | NearLabel done, not_null, do_put; |
| 4900 | SlowPathCode* slow_path = nullptr; |
| 4901 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4902 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4903 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86_64(instruction); |
| 4904 | codegen_->AddSlowPath(slow_path); |
| 4905 | if (instruction->GetValueCanBeNull()) { |
| 4906 | __ testl(register_value, register_value); |
| 4907 | __ j(kNotEqual, ¬_null); |
| 4908 | __ movl(address, Immediate(0)); |
| 4909 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4910 | __ jmp(&done); |
| 4911 | __ Bind(¬_null); |
| 4912 | } |
| 4913 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4914 | if (kEmitCompilerReadBarrier) { |
| 4915 | // When read barriers are enabled, the type checking |
| 4916 | // instrumentation requires two read barriers: |
| 4917 | // |
| 4918 | // __ movl(temp2, temp); |
| 4919 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 4920 | // __ movl(temp, Address(temp, component_offset)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4921 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4922 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 4923 | // |
| 4924 | // // /* HeapReference<Class> */ temp2 = register_value->klass_ |
| 4925 | // __ movl(temp2, Address(register_value, class_offset)); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 4926 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4927 | // instruction, temp2_loc, temp2_loc, value, class_offset, temp_loc); |
| 4928 | // |
| 4929 | // __ cmpl(temp, temp2); |
| 4930 | // |
| 4931 | // However, the second read barrier may trash `temp`, as it |
| 4932 | // is a temporary register, and as such would not be saved |
| 4933 | // along with live registers before calling the runtime (nor |
| 4934 | // restored afterwards). So in this case, we bail out and |
| 4935 | // delegate the work to the array set slow path. |
| 4936 | // |
| 4937 | // TODO: Extend the register allocator to support a new |
| 4938 | // "(locally) live temp" location so as to avoid always |
| 4939 | // going into the slow path when read barriers are enabled. |
| 4940 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4941 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4942 | // /* HeapReference<Class> */ temp = array->klass_ |
| 4943 | __ movl(temp, Address(array, class_offset)); |
| 4944 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4945 | __ MaybeUnpoisonHeapReference(temp); |
| 4946 | |
| 4947 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 4948 | __ movl(temp, Address(temp, component_offset)); |
| 4949 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 4950 | // nor the object reference in `register_value->klass`, as |
| 4951 | // we are comparing two poisoned references. |
| 4952 | __ cmpl(temp, Address(register_value, class_offset)); |
| 4953 | |
| 4954 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4955 | __ j(kEqual, &do_put); |
| 4956 | // If heap poisoning is enabled, the `temp` reference has |
| 4957 | // not been unpoisoned yet; unpoison it now. |
| 4958 | __ MaybeUnpoisonHeapReference(temp); |
| 4959 | |
| 4960 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 4961 | __ movl(temp, Address(temp, super_offset)); |
| 4962 | // If heap poisoning is enabled, no need to unpoison |
| 4963 | // `temp`, as we are comparing against null below. |
| 4964 | __ testl(temp, temp); |
| 4965 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4966 | __ Bind(&do_put); |
| 4967 | } else { |
| 4968 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4969 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4970 | } |
| 4971 | } |
| 4972 | |
| 4973 | if (kPoisonHeapReferences) { |
| 4974 | __ movl(temp, register_value); |
| 4975 | __ PoisonHeapReference(temp); |
| 4976 | __ movl(address, temp); |
| 4977 | } else { |
| 4978 | __ movl(address, register_value); |
| 4979 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 4980 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4981 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4982 | } |
| 4983 | |
| 4984 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 4985 | codegen_->MarkGCCard( |
| 4986 | temp, card, array, value.AsRegister<CpuRegister>(), instruction->GetValueCanBeNull()); |
| 4987 | __ Bind(&done); |
| 4988 | |
| 4989 | if (slow_path != nullptr) { |
| 4990 | __ Bind(slow_path->GetExitLabel()); |
| 4991 | } |
| 4992 | |
| 4993 | break; |
| 4994 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4995 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4996 | case Primitive::kPrimInt: { |
| 4997 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4998 | Address address = index.IsConstant() |
| 4999 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5000 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
| 5001 | if (value.IsRegister()) { |
| 5002 | __ movl(address, value.AsRegister<CpuRegister>()); |
| 5003 | } else { |
| 5004 | DCHECK(value.IsConstant()) << value; |
| 5005 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5006 | __ movl(address, Immediate(v)); |
| 5007 | } |
| 5008 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5009 | break; |
| 5010 | } |
| 5011 | |
| 5012 | case Primitive::kPrimLong: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5013 | uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| 5014 | Address address = index.IsConstant() |
| 5015 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 5016 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset); |
| 5017 | if (value.IsRegister()) { |
| 5018 | __ movq(address, value.AsRegister<CpuRegister>()); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5019 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5020 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5021 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5022 | Address address_high = index.IsConstant() |
| 5023 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 5024 | offset + sizeof(int32_t)) |
| 5025 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset + sizeof(int32_t)); |
| 5026 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5027 | } |
| 5028 | break; |
| 5029 | } |
| 5030 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5031 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5032 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 5033 | Address address = index.IsConstant() |
| 5034 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5035 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5036 | if (value.IsFpuRegister()) { |
| 5037 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5038 | } else { |
| 5039 | DCHECK(value.IsConstant()); |
| 5040 | int32_t v = |
| 5041 | bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5042 | __ movl(address, Immediate(v)); |
| 5043 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5044 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5045 | break; |
| 5046 | } |
| 5047 | |
| 5048 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5049 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 5050 | Address address = index.IsConstant() |
| 5051 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 5052 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset); |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 5053 | if (value.IsFpuRegister()) { |
| 5054 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5055 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5056 | } else { |
| 5057 | int64_t v = |
| 5058 | bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5059 | Address address_high = index.IsConstant() |
| 5060 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 5061 | offset + sizeof(int32_t)) |
| 5062 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset + sizeof(int32_t)); |
| 5063 | codegen_->MoveInt64ToAddress(address, address_high, v, instruction); |
| 5064 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5065 | break; |
| 5066 | } |
| 5067 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5068 | case Primitive::kPrimVoid: |
| 5069 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5070 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5071 | } |
| 5072 | } |
| 5073 | |
| 5074 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5075 | LocationSummary* locations = |
| 5076 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5077 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5078 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5079 | } |
| 5080 | |
| 5081 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
| 5082 | LocationSummary* locations = instruction->GetLocations(); |
| 5083 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5084 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5085 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5086 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5087 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5088 | } |
| 5089 | |
| 5090 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5091 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 5092 | ? LocationSummary::kCallOnSlowPath |
| 5093 | : LocationSummary::kNoCall; |
| 5094 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5095 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5096 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5097 | if (instruction->HasUses()) { |
| 5098 | locations->SetOut(Location::SameAsFirstInput()); |
| 5099 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5100 | } |
| 5101 | |
| 5102 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5103 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5104 | Location index_loc = locations->InAt(0); |
| 5105 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5106 | SlowPathCode* slow_path = |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5107 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5108 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5109 | if (length_loc.IsConstant()) { |
| 5110 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5111 | if (index_loc.IsConstant()) { |
| 5112 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5113 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5114 | if (index < 0 || index >= length) { |
| 5115 | codegen_->AddSlowPath(slow_path); |
| 5116 | __ jmp(slow_path->GetEntryLabel()); |
| 5117 | } else { |
| 5118 | // Some optimization after BCE may have generated this, and we should not |
| 5119 | // generate a bounds check if it is a valid range. |
| 5120 | } |
| 5121 | return; |
| 5122 | } |
| 5123 | |
| 5124 | // We have to reverse the jump condition because the length is the constant. |
| 5125 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 5126 | __ cmpl(index_reg, Immediate(length)); |
| 5127 | codegen_->AddSlowPath(slow_path); |
| 5128 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5129 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5130 | CpuRegister length = length_loc.AsRegister<CpuRegister>(); |
| 5131 | if (index_loc.IsConstant()) { |
| 5132 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5133 | __ cmpl(length, Immediate(value)); |
| 5134 | } else { |
| 5135 | __ cmpl(length, index_loc.AsRegister<CpuRegister>()); |
| 5136 | } |
| 5137 | codegen_->AddSlowPath(slow_path); |
| 5138 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5139 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5140 | } |
| 5141 | |
| 5142 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 5143 | CpuRegister card, |
| 5144 | CpuRegister object, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5145 | CpuRegister value, |
| 5146 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5147 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5148 | if (value_can_be_null) { |
| 5149 | __ testl(value, value); |
| 5150 | __ j(kEqual, &is_null); |
| 5151 | } |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5152 | __ gs()->movq(card, Address::Absolute(Thread::CardTableOffset<kX86_64WordSize>().Int32Value(), |
| 5153 | /* no_rip */ true)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5154 | __ movq(temp, object); |
| 5155 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5156 | __ movb(Address(temp, card, TIMES_1, 0), card); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5157 | if (value_can_be_null) { |
| 5158 | __ Bind(&is_null); |
| 5159 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5160 | } |
| 5161 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5162 | void LocationsBuilderX86_64::VisitTemporary(HTemporary* temp) { |
| 5163 | temp->SetLocations(nullptr); |
| 5164 | } |
| 5165 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5166 | void InstructionCodeGeneratorX86_64::VisitTemporary(HTemporary* temp ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5167 | // Nothing to do, this is driven by the code generator. |
| 5168 | } |
| 5169 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5170 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5171 | LOG(FATAL) << "Unimplemented"; |
| 5172 | } |
| 5173 | |
| 5174 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5175 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5176 | } |
| 5177 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5178 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 5179 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 5180 | } |
| 5181 | |
| 5182 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5183 | HBasicBlock* block = instruction->GetBlock(); |
| 5184 | if (block->GetLoopInformation() != nullptr) { |
| 5185 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5186 | // The back edge will generate the suspend check. |
| 5187 | return; |
| 5188 | } |
| 5189 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5190 | // The goto will generate the suspend check. |
| 5191 | return; |
| 5192 | } |
| 5193 | GenerateSuspendCheck(instruction, nullptr); |
| 5194 | } |
| 5195 | |
| 5196 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5197 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5198 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5199 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 5200 | if (slow_path == nullptr) { |
| 5201 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
| 5202 | instruction->SetSlowPath(slow_path); |
| 5203 | codegen_->AddSlowPath(slow_path); |
| 5204 | if (successor != nullptr) { |
| 5205 | DCHECK(successor->IsLoopHeader()); |
| 5206 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5207 | } |
| 5208 | } else { |
| 5209 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5210 | } |
| 5211 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5212 | __ gs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86_64WordSize>().Int32Value(), |
| 5213 | /* no_rip */ true), |
| 5214 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5215 | if (successor == nullptr) { |
| 5216 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5217 | __ Bind(slow_path->GetReturnLabel()); |
| 5218 | } else { |
| 5219 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5220 | __ jmp(slow_path->GetEntryLabel()); |
| 5221 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5222 | } |
| 5223 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5224 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 5225 | return codegen_->GetAssembler(); |
| 5226 | } |
| 5227 | |
| 5228 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5229 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5230 | Location source = move->GetSource(); |
| 5231 | Location destination = move->GetDestination(); |
| 5232 | |
| 5233 | if (source.IsRegister()) { |
| 5234 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5235 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5236 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5237 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5238 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5239 | } else { |
| 5240 | DCHECK(destination.IsDoubleStackSlot()); |
| 5241 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5242 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5243 | } |
| 5244 | } else if (source.IsStackSlot()) { |
| 5245 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5246 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5247 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5248 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5249 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5250 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5251 | } else { |
| 5252 | DCHECK(destination.IsStackSlot()); |
| 5253 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5254 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5255 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5256 | } else if (source.IsDoubleStackSlot()) { |
| 5257 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5258 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5259 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5260 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5261 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 5262 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5263 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 5264 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5265 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 5266 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 5267 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5268 | } else if (source.IsConstant()) { |
| 5269 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5270 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 5271 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5272 | if (destination.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5273 | if (value == 0) { |
| 5274 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 5275 | } else { |
| 5276 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 5277 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5278 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5279 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 5280 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5281 | } |
| 5282 | } else if (constant->IsLongConstant()) { |
| 5283 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5284 | if (destination.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5285 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5286 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5287 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5288 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5289 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5290 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5291 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5292 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5293 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame^] | 5294 | codegen_->Load32BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5295 | } else { |
| 5296 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame^] | 5297 | Immediate imm(bit_cast<int32_t, float>(fp_value)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5298 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 5299 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5300 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5301 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5302 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5303 | int64_t value = bit_cast<int64_t, double>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5304 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5305 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame^] | 5306 | codegen_->Load64BitValue(dest, fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5307 | } else { |
| 5308 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5309 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5310 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5311 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5312 | } else if (source.IsFpuRegister()) { |
| 5313 | if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5314 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5315 | } else if (destination.IsStackSlot()) { |
| 5316 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5317 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5318 | } else { |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 5319 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5320 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5321 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5322 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5323 | } |
| 5324 | } |
| 5325 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5326 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5327 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5328 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 5329 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5330 | } |
| 5331 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5332 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5333 | ScratchRegisterScope ensure_scratch( |
| 5334 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 5335 | |
| 5336 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5337 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5338 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 5339 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5340 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5341 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5342 | CpuRegister(ensure_scratch.GetRegister())); |
| 5343 | } |
| 5344 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5345 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 5346 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5347 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 5348 | __ movq(reg, CpuRegister(TMP)); |
| 5349 | } |
| 5350 | |
| 5351 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 5352 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5353 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5354 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5355 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 5356 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 5357 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 5358 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 5359 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 5360 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 5361 | CpuRegister(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5362 | } |
| 5363 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5364 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 5365 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5366 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 5367 | __ movd(reg, CpuRegister(TMP)); |
| 5368 | } |
| 5369 | |
| 5370 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 5371 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 5372 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 5373 | __ movd(reg, CpuRegister(TMP)); |
| 5374 | } |
| 5375 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5376 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5377 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5378 | Location source = move->GetSource(); |
| 5379 | Location destination = move->GetDestination(); |
| 5380 | |
| 5381 | if (source.IsRegister() && destination.IsRegister()) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5382 | __ xchgq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5383 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5384 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5385 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5386 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5387 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5388 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5389 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5390 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5391 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5392 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 5393 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 5394 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5395 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5396 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 5397 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5398 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5399 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5400 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5401 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5402 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5403 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5404 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5405 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5406 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5407 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5408 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 5409 | } |
| 5410 | } |
| 5411 | |
| 5412 | |
| 5413 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 5414 | __ pushq(CpuRegister(reg)); |
| 5415 | } |
| 5416 | |
| 5417 | |
| 5418 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 5419 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5420 | } |
| 5421 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5422 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5423 | SlowPathCode* slow_path, CpuRegister class_reg) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5424 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5425 | Immediate(mirror::Class::kStatusInitialized)); |
| 5426 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5427 | __ Bind(slow_path->GetExitLabel()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5428 | // No need for memory fence, thanks to the x86-64 memory model. |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5429 | } |
| 5430 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5431 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5432 | InvokeRuntimeCallingConvention calling_convention; |
| 5433 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5434 | cls, |
| 5435 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5436 | Location::RegisterLocation(RAX), |
| 5437 | /* code_generator_supports_read_barrier */ true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5438 | } |
| 5439 | |
| 5440 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5441 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5442 | if (cls->NeedsAccessCheck()) { |
| 5443 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 5444 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 5445 | cls, |
| 5446 | cls->GetDexPc(), |
| 5447 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5448 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5449 | return; |
| 5450 | } |
| 5451 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5452 | Location out_loc = locations->Out(); |
| 5453 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5454 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5455 | |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5456 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5457 | DCHECK(!cls->CanCallRuntime()); |
| 5458 | DCHECK(!cls->MustGenerateClinitCheck()); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5459 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5460 | GenerateGcRootFieldLoad( |
| 5461 | cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5462 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5463 | // /* GcRoot<mirror::Class>[] */ out = |
| 5464 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5465 | __ movq(out, Address(current_method, |
| 5466 | ArtMethod::DexCacheResolvedTypesOffset(kX86_64PointerSize).Int32Value())); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5467 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5468 | GenerateGcRootFieldLoad(cls, out_loc, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5469 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5470 | if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { |
| 5471 | DCHECK(cls->CanCallRuntime()); |
| 5472 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 5473 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5474 | codegen_->AddSlowPath(slow_path); |
| 5475 | if (!cls->IsInDexCache()) { |
| 5476 | __ testl(out, out); |
| 5477 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5478 | } |
| 5479 | if (cls->MustGenerateClinitCheck()) { |
| 5480 | GenerateClassInitializationCheck(slow_path, out); |
| 5481 | } else { |
| 5482 | __ Bind(slow_path->GetExitLabel()); |
| 5483 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5484 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5485 | } |
| 5486 | } |
| 5487 | |
| 5488 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 5489 | LocationSummary* locations = |
| 5490 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5491 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5492 | if (check->HasUses()) { |
| 5493 | locations->SetOut(Location::SameAsFirstInput()); |
| 5494 | } |
| 5495 | } |
| 5496 | |
| 5497 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5498 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5499 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5500 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5501 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5502 | GenerateClassInitializationCheck(slow_path, |
| 5503 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5504 | } |
| 5505 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5506 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5507 | LocationSummary::CallKind call_kind = (!load->IsInDexCache() || kEmitCompilerReadBarrier) |
| 5508 | ? LocationSummary::kCallOnSlowPath |
| 5509 | : LocationSummary::kNoCall; |
| 5510 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5511 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5512 | locations->SetOut(Location::RequiresRegister()); |
| 5513 | } |
| 5514 | |
| 5515 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5516 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5517 | Location out_loc = locations->Out(); |
| 5518 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5519 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5520 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5521 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5522 | GenerateGcRootFieldLoad( |
| 5523 | load, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5524 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
| 5525 | __ movq(out, Address(out, mirror::Class::DexCacheStringsOffset().Uint32Value())); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5526 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 5527 | GenerateGcRootFieldLoad( |
| 5528 | load, out_loc, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5529 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5530 | if (!load->IsInDexCache()) { |
| 5531 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86_64(load); |
| 5532 | codegen_->AddSlowPath(slow_path); |
| 5533 | __ testl(out, out); |
| 5534 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5535 | __ Bind(slow_path->GetExitLabel()); |
| 5536 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5537 | } |
| 5538 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5539 | static Address GetExceptionTlsAddress() { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5540 | return Address::Absolute(Thread::ExceptionOffset<kX86_64WordSize>().Int32Value(), |
| 5541 | /* no_rip */ true); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5542 | } |
| 5543 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5544 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 5545 | LocationSummary* locations = |
| 5546 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5547 | locations->SetOut(Location::RequiresRegister()); |
| 5548 | } |
| 5549 | |
| 5550 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5551 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 5552 | } |
| 5553 | |
| 5554 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
| 5555 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5556 | } |
| 5557 | |
| 5558 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5559 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5560 | } |
| 5561 | |
| 5562 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| 5563 | LocationSummary* locations = |
| 5564 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5565 | InvokeRuntimeCallingConvention calling_convention; |
| 5566 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5567 | } |
| 5568 | |
| 5569 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5570 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 5571 | instruction, |
| 5572 | instruction->GetDexPc(), |
| 5573 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5574 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5575 | } |
| 5576 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5577 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5578 | return kEmitCompilerReadBarrier && |
| 5579 | (kUseBakerReadBarrier || |
| 5580 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5581 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5582 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5583 | } |
| 5584 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5585 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5586 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5587 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5588 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5589 | case TypeCheckKind::kExactCheck: |
| 5590 | case TypeCheckKind::kAbstractClassCheck: |
| 5591 | case TypeCheckKind::kClassHierarchyCheck: |
| 5592 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5593 | call_kind = |
| 5594 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5595 | break; |
| 5596 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5597 | case TypeCheckKind::kUnresolvedCheck: |
| 5598 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5599 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5600 | break; |
| 5601 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5602 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5603 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5604 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5605 | locations->SetInAt(1, Location::Any()); |
| 5606 | // Note that TypeCheckSlowPathX86_64 uses this "out" register too. |
| 5607 | locations->SetOut(Location::RequiresRegister()); |
| 5608 | // When read barriers are enabled, we need a temporary register for |
| 5609 | // some cases. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5610 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5611 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5612 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5613 | } |
| 5614 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5615 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5616 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5617 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5618 | Location obj_loc = locations->InAt(0); |
| 5619 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5620 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5621 | Location out_loc = locations->Out(); |
| 5622 | CpuRegister out = out_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5623 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5624 | locations->GetTemp(0) : |
| 5625 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5626 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5627 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5628 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5629 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5630 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5631 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5632 | |
| 5633 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5634 | // Avoid null check if we know obj is not null. |
| 5635 | if (instruction->MustDoNullCheck()) { |
| 5636 | __ testl(obj, obj); |
| 5637 | __ j(kEqual, &zero); |
| 5638 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5639 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5640 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5641 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5642 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5643 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5644 | case TypeCheckKind::kExactCheck: { |
| 5645 | if (cls.IsRegister()) { |
| 5646 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5647 | } else { |
| 5648 | DCHECK(cls.IsStackSlot()) << cls; |
| 5649 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5650 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5651 | if (zero.IsLinked()) { |
| 5652 | // Classes must be equal for the instanceof to succeed. |
| 5653 | __ j(kNotEqual, &zero); |
| 5654 | __ movl(out, Immediate(1)); |
| 5655 | __ jmp(&done); |
| 5656 | } else { |
| 5657 | __ setcc(kEqual, out); |
| 5658 | // setcc only sets the low byte. |
| 5659 | __ andl(out, Immediate(1)); |
| 5660 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5661 | break; |
| 5662 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5663 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5664 | case TypeCheckKind::kAbstractClassCheck: { |
| 5665 | // If the class is abstract, we eagerly fetch the super class of the |
| 5666 | // object to avoid doing a comparison we know will fail. |
| 5667 | NearLabel loop, success; |
| 5668 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5669 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5670 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5671 | __ testl(out, out); |
| 5672 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5673 | __ j(kEqual, &done); |
| 5674 | if (cls.IsRegister()) { |
| 5675 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5676 | } else { |
| 5677 | DCHECK(cls.IsStackSlot()) << cls; |
| 5678 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5679 | } |
| 5680 | __ j(kNotEqual, &loop); |
| 5681 | __ movl(out, Immediate(1)); |
| 5682 | if (zero.IsLinked()) { |
| 5683 | __ jmp(&done); |
| 5684 | } |
| 5685 | break; |
| 5686 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5687 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5688 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5689 | // Walk over the class hierarchy to find a match. |
| 5690 | NearLabel loop, success; |
| 5691 | __ Bind(&loop); |
| 5692 | if (cls.IsRegister()) { |
| 5693 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5694 | } else { |
| 5695 | DCHECK(cls.IsStackSlot()) << cls; |
| 5696 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5697 | } |
| 5698 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5699 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5700 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5701 | __ testl(out, out); |
| 5702 | __ j(kNotEqual, &loop); |
| 5703 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5704 | __ jmp(&done); |
| 5705 | __ Bind(&success); |
| 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 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5713 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5714 | // Do an exact check. |
| 5715 | NearLabel exact_check; |
| 5716 | if (cls.IsRegister()) { |
| 5717 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5718 | } else { |
| 5719 | DCHECK(cls.IsStackSlot()) << cls; |
| 5720 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5721 | } |
| 5722 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5723 | // 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] | 5724 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5725 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5726 | __ testl(out, out); |
| 5727 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5728 | __ j(kEqual, &done); |
| 5729 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5730 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5731 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5732 | __ movl(out, Immediate(1)); |
| 5733 | __ jmp(&done); |
| 5734 | break; |
| 5735 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5736 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5737 | case TypeCheckKind::kArrayCheck: { |
| 5738 | if (cls.IsRegister()) { |
| 5739 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5740 | } else { |
| 5741 | DCHECK(cls.IsStackSlot()) << cls; |
| 5742 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5743 | } |
| 5744 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5745 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5746 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5747 | codegen_->AddSlowPath(slow_path); |
| 5748 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5749 | __ movl(out, Immediate(1)); |
| 5750 | if (zero.IsLinked()) { |
| 5751 | __ jmp(&done); |
| 5752 | } |
| 5753 | break; |
| 5754 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5755 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5756 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5757 | case TypeCheckKind::kInterfaceCheck: { |
| 5758 | // 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] | 5759 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5760 | // cases. |
| 5761 | // |
| 5762 | // We cannot directly call the InstanceofNonTrivial runtime |
| 5763 | // entry point without resorting to a type checking slow path |
| 5764 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 5765 | // require to assign fixed registers for the inputs of this |
| 5766 | // HInstanceOf instruction (following the runtime calling |
| 5767 | // convention), which might be cluttered by the potential first |
| 5768 | // read barrier emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5769 | // |
| 5770 | // TODO: Introduce a new runtime entry point taking the object |
| 5771 | // to test (instead of its class) as argument, and let it deal |
| 5772 | // with the read barrier issues. This will let us refactor this |
| 5773 | // case of the `switch` code as it was previously (with a direct |
| 5774 | // call to the runtime not using a type checking slow path). |
| 5775 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5776 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5777 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5778 | /* is_fatal */ false); |
| 5779 | codegen_->AddSlowPath(slow_path); |
| 5780 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5781 | if (zero.IsLinked()) { |
| 5782 | __ jmp(&done); |
| 5783 | } |
| 5784 | break; |
| 5785 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5786 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5787 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5788 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5789 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5790 | __ xorl(out, out); |
| 5791 | } |
| 5792 | |
| 5793 | if (done.IsLinked()) { |
| 5794 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5795 | } |
| 5796 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5797 | if (slow_path != nullptr) { |
| 5798 | __ Bind(slow_path->GetExitLabel()); |
| 5799 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5800 | } |
| 5801 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5802 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5803 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5804 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5805 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5806 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5807 | case TypeCheckKind::kExactCheck: |
| 5808 | case TypeCheckKind::kAbstractClassCheck: |
| 5809 | case TypeCheckKind::kClassHierarchyCheck: |
| 5810 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5811 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 5812 | LocationSummary::kCallOnSlowPath : |
| 5813 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5814 | break; |
| 5815 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5816 | case TypeCheckKind::kUnresolvedCheck: |
| 5817 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5818 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5819 | break; |
| 5820 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5821 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 5822 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5823 | locations->SetInAt(1, Location::Any()); |
| 5824 | // Note that TypeCheckSlowPathX86_64 uses this "temp" register too. |
| 5825 | locations->AddTemp(Location::RequiresRegister()); |
| 5826 | // When read barriers are enabled, we need an additional temporary |
| 5827 | // register for some cases. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5828 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5829 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5830 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5831 | } |
| 5832 | |
| 5833 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5834 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5835 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5836 | Location obj_loc = locations->InAt(0); |
| 5837 | CpuRegister obj = obj_loc.AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5838 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5839 | Location temp_loc = locations->GetTemp(0); |
| 5840 | CpuRegister temp = temp_loc.AsRegister<CpuRegister>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5841 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 5842 | locations->GetTemp(1) : |
| 5843 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5844 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5845 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5846 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5847 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5848 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5849 | bool is_type_check_slow_path_fatal = |
| 5850 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 5851 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5852 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5853 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 5854 | !instruction->CanThrowIntoCatchBlock(); |
| 5855 | SlowPathCode* type_check_slow_path = |
| 5856 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction, |
| 5857 | is_type_check_slow_path_fatal); |
| 5858 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5859 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 5860 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5861 | // Avoid null check if we know obj is not null. |
| 5862 | if (instruction->MustDoNullCheck()) { |
| 5863 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5864 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5865 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5866 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5867 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5868 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5869 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5870 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5871 | case TypeCheckKind::kExactCheck: |
| 5872 | case TypeCheckKind::kArrayCheck: { |
| 5873 | if (cls.IsRegister()) { |
| 5874 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5875 | } else { |
| 5876 | DCHECK(cls.IsStackSlot()) << cls; |
| 5877 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5878 | } |
| 5879 | // Jump to slow path for throwing the exception or doing a |
| 5880 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5881 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5882 | break; |
| 5883 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5884 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5885 | case TypeCheckKind::kAbstractClassCheck: { |
| 5886 | // If the class is abstract, we eagerly fetch the super class of the |
| 5887 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5888 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5889 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5890 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5891 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5892 | |
| 5893 | // If the class reference currently in `temp` is not null, jump |
| 5894 | // to the `compare_classes` label to compare it with the checked |
| 5895 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5896 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5897 | __ j(kNotEqual, &compare_classes); |
| 5898 | // Otherwise, jump to the slow path to throw the exception. |
| 5899 | // |
| 5900 | // But before, move back the object's class into `temp` before |
| 5901 | // going into the slow path, as it has been overwritten in the |
| 5902 | // meantime. |
| 5903 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5904 | GenerateReferenceLoadTwoRegisters( |
| 5905 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5906 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 5907 | |
| 5908 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5909 | if (cls.IsRegister()) { |
| 5910 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5911 | } else { |
| 5912 | DCHECK(cls.IsStackSlot()) << cls; |
| 5913 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5914 | } |
| 5915 | __ j(kNotEqual, &loop); |
| 5916 | break; |
| 5917 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5918 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5919 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5920 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5921 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5922 | __ Bind(&loop); |
| 5923 | if (cls.IsRegister()) { |
| 5924 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5925 | } else { |
| 5926 | DCHECK(cls.IsStackSlot()) << cls; |
| 5927 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5928 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5929 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5930 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5931 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5932 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5933 | |
| 5934 | // If the class reference currently in `temp` is not null, jump |
| 5935 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5936 | __ testl(temp, temp); |
| 5937 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5938 | // Otherwise, jump to the slow path to throw the exception. |
| 5939 | // |
| 5940 | // But before, move back the object's class into `temp` before |
| 5941 | // going into the slow path, as it has been overwritten in the |
| 5942 | // meantime. |
| 5943 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5944 | GenerateReferenceLoadTwoRegisters( |
| 5945 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5946 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5947 | break; |
| 5948 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5949 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5950 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5951 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5952 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5953 | if (cls.IsRegister()) { |
| 5954 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5955 | } else { |
| 5956 | DCHECK(cls.IsStackSlot()) << cls; |
| 5957 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5958 | } |
| 5959 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5960 | |
| 5961 | // 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] | 5962 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5963 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5964 | |
| 5965 | // If the component type is not null (i.e. the object is indeed |
| 5966 | // an array), jump to label `check_non_primitive_component_type` |
| 5967 | // to further check that this component type is not a primitive |
| 5968 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5969 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5970 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 5971 | // Otherwise, jump to the slow path to throw the exception. |
| 5972 | // |
| 5973 | // But before, move back the object's class into `temp` before |
| 5974 | // going into the slow path, as it has been overwritten in the |
| 5975 | // meantime. |
| 5976 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5977 | GenerateReferenceLoadTwoRegisters( |
| 5978 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5979 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 5980 | |
| 5981 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5982 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5983 | __ j(kEqual, &done); |
| 5984 | // Same comment as above regarding `temp` and the slow path. |
| 5985 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5986 | GenerateReferenceLoadTwoRegisters( |
| 5987 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5988 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5989 | break; |
| 5990 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5991 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5992 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5993 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 5994 | // We always go into the type check slow path for the unresolved |
| 5995 | // and interface check cases. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5996 | // |
| 5997 | // We cannot directly call the CheckCast runtime entry point |
| 5998 | // without resorting to a type checking slow path here (i.e. by |
| 5999 | // calling InvokeRuntime directly), as it would require to |
| 6000 | // assign fixed registers for the inputs of this HInstanceOf |
| 6001 | // instruction (following the runtime calling convention), which |
| 6002 | // might be cluttered by the potential first read barrier |
| 6003 | // emission at the beginning of this method. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6004 | // |
| 6005 | // TODO: Introduce a new runtime entry point taking the object |
| 6006 | // to test (instead of its class) as argument, and let it deal |
| 6007 | // with the read barrier issues. This will let us refactor this |
| 6008 | // case of the `switch` code as it was previously (with a direct |
| 6009 | // call to the runtime not using a type checking slow path). |
| 6010 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6011 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6012 | break; |
| 6013 | } |
| 6014 | __ Bind(&done); |
| 6015 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6016 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6017 | } |
| 6018 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6019 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6020 | LocationSummary* locations = |
| 6021 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 6022 | InvokeRuntimeCallingConvention calling_convention; |
| 6023 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6024 | } |
| 6025 | |
| 6026 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6027 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 6028 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 6029 | instruction, |
| 6030 | instruction->GetDexPc(), |
| 6031 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6032 | if (instruction->IsEnter()) { |
| 6033 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6034 | } else { |
| 6035 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6036 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6037 | } |
| 6038 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6039 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6040 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6041 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6042 | |
| 6043 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6044 | LocationSummary* locations = |
| 6045 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6046 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6047 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6048 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6049 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6050 | locations->SetOut(Location::SameAsFirstInput()); |
| 6051 | } |
| 6052 | |
| 6053 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 6054 | HandleBitwiseOperation(instruction); |
| 6055 | } |
| 6056 | |
| 6057 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 6058 | HandleBitwiseOperation(instruction); |
| 6059 | } |
| 6060 | |
| 6061 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 6062 | HandleBitwiseOperation(instruction); |
| 6063 | } |
| 6064 | |
| 6065 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6066 | LocationSummary* locations = instruction->GetLocations(); |
| 6067 | Location first = locations->InAt(0); |
| 6068 | Location second = locations->InAt(1); |
| 6069 | DCHECK(first.Equals(locations->Out())); |
| 6070 | |
| 6071 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6072 | if (second.IsRegister()) { |
| 6073 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6074 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6075 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6076 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6077 | } else { |
| 6078 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6079 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6080 | } |
| 6081 | } else if (second.IsConstant()) { |
| 6082 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 6083 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6084 | __ andl(first.AsRegister<CpuRegister>(), imm); |
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>(), imm); |
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>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6090 | } |
| 6091 | } else { |
| 6092 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 6093 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6094 | __ andl(first.AsRegister<CpuRegister>(), address); |
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>(), address); |
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>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6100 | } |
| 6101 | } |
| 6102 | } else { |
| 6103 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6104 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 6105 | bool second_is_constant = false; |
| 6106 | int64_t value = 0; |
| 6107 | if (second.IsConstant()) { |
| 6108 | second_is_constant = true; |
| 6109 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6110 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6111 | bool is_int32_value = IsInt<32>(value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6112 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6113 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6114 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6115 | if (is_int32_value) { |
| 6116 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6117 | } else { |
| 6118 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6119 | } |
| 6120 | } else if (second.IsDoubleStackSlot()) { |
| 6121 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6122 | } else { |
| 6123 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 6124 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6125 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6126 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6127 | if (is_int32_value) { |
| 6128 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6129 | } else { |
| 6130 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6131 | } |
| 6132 | } else if (second.IsDoubleStackSlot()) { |
| 6133 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6134 | } else { |
| 6135 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 6136 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6137 | } else { |
| 6138 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6139 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 6140 | if (is_int32_value) { |
| 6141 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 6142 | } else { |
| 6143 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 6144 | } |
| 6145 | } else if (second.IsDoubleStackSlot()) { |
| 6146 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6147 | } else { |
| 6148 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 6149 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6150 | } |
| 6151 | } |
| 6152 | } |
| 6153 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6154 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6155 | Location out, |
| 6156 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6157 | Location maybe_temp) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6158 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6159 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6160 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6161 | if (kUseBakerReadBarrier) { |
| 6162 | // Load with fast path based Baker's read barrier. |
| 6163 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6164 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6165 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6166 | } else { |
| 6167 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6168 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6169 | // in the following move operation, as we will need it for the |
| 6170 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6171 | __ movl(maybe_temp.AsRegister<CpuRegister>(), out_reg); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6172 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6173 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6174 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6175 | } |
| 6176 | } else { |
| 6177 | // Plain load with no read barrier. |
| 6178 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6179 | __ movl(out_reg, Address(out_reg, offset)); |
| 6180 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6181 | } |
| 6182 | } |
| 6183 | |
| 6184 | void InstructionCodeGeneratorX86_64::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6185 | Location out, |
| 6186 | Location obj, |
| 6187 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6188 | Location maybe_temp) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6189 | CpuRegister out_reg = out.AsRegister<CpuRegister>(); |
| 6190 | CpuRegister obj_reg = obj.AsRegister<CpuRegister>(); |
| 6191 | if (kEmitCompilerReadBarrier) { |
| 6192 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6193 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6194 | // Load with fast path based Baker's read barrier. |
| 6195 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6196 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6197 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6198 | } else { |
| 6199 | // Load with slow path based read barrier. |
| 6200 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6201 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6202 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6203 | } |
| 6204 | } else { |
| 6205 | // Plain load with no read barrier. |
| 6206 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6207 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6208 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6209 | } |
| 6210 | } |
| 6211 | |
| 6212 | void InstructionCodeGeneratorX86_64::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6213 | Location root, |
| 6214 | CpuRegister obj, |
| 6215 | uint32_t offset) { |
| 6216 | CpuRegister root_reg = root.AsRegister<CpuRegister>(); |
| 6217 | if (kEmitCompilerReadBarrier) { |
| 6218 | if (kUseBakerReadBarrier) { |
| 6219 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6220 | // Baker's read barrier are used: |
| 6221 | // |
| 6222 | // root = obj.field; |
| 6223 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6224 | // root = ReadBarrier::Mark(root) |
| 6225 | // } |
| 6226 | |
| 6227 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6228 | __ movl(root_reg, Address(obj, offset)); |
| 6229 | static_assert( |
| 6230 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6231 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6232 | "have different sizes."); |
| 6233 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6234 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6235 | "have different sizes."); |
| 6236 | |
| 6237 | // Slow path used to mark the GC root `root`. |
| 6238 | SlowPathCode* slow_path = |
| 6239 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64(instruction, root, root); |
| 6240 | codegen_->AddSlowPath(slow_path); |
| 6241 | |
| 6242 | __ gs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86_64WordSize>().Int32Value(), |
| 6243 | /* no_rip */ true), |
| 6244 | Immediate(0)); |
| 6245 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6246 | __ Bind(slow_path->GetExitLabel()); |
| 6247 | } else { |
| 6248 | // GC root loaded through a slow path for read barriers other |
| 6249 | // than Baker's. |
| 6250 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6251 | __ leaq(root_reg, Address(obj, offset)); |
| 6252 | // /* mirror::Object* */ root = root->Read() |
| 6253 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6254 | } |
| 6255 | } else { |
| 6256 | // Plain GC root load with no read barrier. |
| 6257 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6258 | __ movl(root_reg, Address(obj, offset)); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6259 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6260 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6261 | } |
| 6262 | } |
| 6263 | |
| 6264 | void CodeGeneratorX86_64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6265 | Location ref, |
| 6266 | CpuRegister obj, |
| 6267 | uint32_t offset, |
| 6268 | Location temp, |
| 6269 | bool needs_null_check) { |
| 6270 | DCHECK(kEmitCompilerReadBarrier); |
| 6271 | DCHECK(kUseBakerReadBarrier); |
| 6272 | |
| 6273 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6274 | Address src(obj, offset); |
| 6275 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6276 | } |
| 6277 | |
| 6278 | void CodeGeneratorX86_64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6279 | Location ref, |
| 6280 | CpuRegister obj, |
| 6281 | uint32_t data_offset, |
| 6282 | Location index, |
| 6283 | Location temp, |
| 6284 | bool needs_null_check) { |
| 6285 | DCHECK(kEmitCompilerReadBarrier); |
| 6286 | DCHECK(kUseBakerReadBarrier); |
| 6287 | |
| 6288 | // /* HeapReference<Object> */ ref = |
| 6289 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6290 | Address src = index.IsConstant() ? |
| 6291 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset) : |
| 6292 | Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset); |
| 6293 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6294 | } |
| 6295 | |
| 6296 | void CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6297 | Location ref, |
| 6298 | CpuRegister obj, |
| 6299 | const Address& src, |
| 6300 | Location temp, |
| 6301 | bool needs_null_check) { |
| 6302 | DCHECK(kEmitCompilerReadBarrier); |
| 6303 | DCHECK(kUseBakerReadBarrier); |
| 6304 | |
| 6305 | // In slow path based read barriers, the read barrier call is |
| 6306 | // inserted after the original load. However, in fast path based |
| 6307 | // Baker's read barriers, we need to perform the load of |
| 6308 | // mirror::Object::monitor_ *before* the original reference load. |
| 6309 | // This load-load ordering is required by the read barrier. |
| 6310 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6311 | // |
| 6312 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6313 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6314 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6315 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6316 | // if (is_gray) { |
| 6317 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6318 | // } |
| 6319 | // |
| 6320 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6321 | // slightly more complex as: |
| 6322 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6323 | // the high-bits of rb_state, which are expected to be all zeroes |
| 6324 | // (we use CodeGeneratorX86_64::GenerateMemoryBarrier instead |
| 6325 | // 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] | 6326 | // - it performs additional checks that we do not do here for |
| 6327 | // performance reasons. |
| 6328 | |
| 6329 | CpuRegister ref_reg = ref.AsRegister<CpuRegister>(); |
| 6330 | CpuRegister temp_reg = temp.AsRegister<CpuRegister>(); |
| 6331 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6332 | |
| 6333 | // /* int32_t */ monitor = obj->monitor_ |
| 6334 | __ movl(temp_reg, Address(obj, monitor_offset)); |
| 6335 | if (needs_null_check) { |
| 6336 | MaybeRecordImplicitNullCheck(instruction); |
| 6337 | } |
| 6338 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6339 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6340 | "art::LockWord and int32_t have different sizes."); |
| 6341 | // /* uint32_t */ rb_state = lock_word.ReadBarrierState() |
| 6342 | __ shrl(temp_reg, Immediate(LockWord::kReadBarrierStateShift)); |
| 6343 | __ andl(temp_reg, Immediate(LockWord::kReadBarrierStateMask)); |
| 6344 | static_assert( |
| 6345 | LockWord::kReadBarrierStateMask == ReadBarrier::rb_ptr_mask_, |
| 6346 | "art::LockWord::kReadBarrierStateMask is not equal to art::ReadBarrier::rb_ptr_mask_."); |
| 6347 | |
| 6348 | // Load fence to prevent load-load reordering. |
| 6349 | // Note that this is a no-op, thanks to the x86-64 memory model. |
| 6350 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6351 | |
| 6352 | // The actual reference load. |
| 6353 | // /* HeapReference<Object> */ ref = *src |
| 6354 | __ movl(ref_reg, src); |
| 6355 | |
| 6356 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6357 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6358 | |
| 6359 | // Slow path used to mark the object `ref` when it is gray. |
| 6360 | SlowPathCode* slow_path = |
| 6361 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86_64(instruction, ref, ref); |
| 6362 | AddSlowPath(slow_path); |
| 6363 | |
| 6364 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6365 | // ref = ReadBarrier::Mark(ref); |
| 6366 | __ cmpl(temp_reg, Immediate(ReadBarrier::gray_ptr_)); |
| 6367 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6368 | __ Bind(slow_path->GetExitLabel()); |
| 6369 | } |
| 6370 | |
| 6371 | void CodeGeneratorX86_64::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6372 | Location out, |
| 6373 | Location ref, |
| 6374 | Location obj, |
| 6375 | uint32_t offset, |
| 6376 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6377 | DCHECK(kEmitCompilerReadBarrier); |
| 6378 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6379 | // Insert a slow path based read barrier *after* the reference load. |
| 6380 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6381 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6382 | // reference will be carried out by the runtime within the slow |
| 6383 | // path. |
| 6384 | // |
| 6385 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6386 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6387 | // not used by the artReadBarrierSlow entry point. |
| 6388 | // |
| 6389 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6390 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6391 | ReadBarrierForHeapReferenceSlowPathX86_64(instruction, out, ref, obj, offset, index); |
| 6392 | AddSlowPath(slow_path); |
| 6393 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6394 | __ jmp(slow_path->GetEntryLabel()); |
| 6395 | __ Bind(slow_path->GetExitLabel()); |
| 6396 | } |
| 6397 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6398 | void CodeGeneratorX86_64::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6399 | Location out, |
| 6400 | Location ref, |
| 6401 | Location obj, |
| 6402 | uint32_t offset, |
| 6403 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6404 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6405 | // Baker's read barriers shall be handled by the fast path |
| 6406 | // (CodeGeneratorX86_64::GenerateReferenceLoadWithBakerReadBarrier). |
| 6407 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6408 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6409 | // by the runtime within the slow path. |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6410 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6411 | } else if (kPoisonHeapReferences) { |
| 6412 | __ UnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 6413 | } |
| 6414 | } |
| 6415 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6416 | void CodeGeneratorX86_64::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6417 | Location out, |
| 6418 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6419 | DCHECK(kEmitCompilerReadBarrier); |
| 6420 | |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6421 | // Insert a slow path based read barrier *after* the GC root load. |
| 6422 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6423 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6424 | // not need to do anything special for this here. |
| 6425 | SlowPathCode* slow_path = |
| 6426 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86_64(instruction, out, root); |
| 6427 | AddSlowPath(slow_path); |
| 6428 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6429 | __ jmp(slow_path->GetEntryLabel()); |
| 6430 | __ Bind(slow_path->GetExitLabel()); |
| 6431 | } |
| 6432 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6433 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6434 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6435 | LOG(FATAL) << "Unreachable"; |
| 6436 | } |
| 6437 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6438 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6439 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6440 | LOG(FATAL) << "Unreachable"; |
| 6441 | } |
| 6442 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6443 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6444 | void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6445 | LocationSummary* locations = |
| 6446 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6447 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6448 | locations->AddTemp(Location::RequiresRegister()); |
| 6449 | locations->AddTemp(Location::RequiresRegister()); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6450 | } |
| 6451 | |
| 6452 | void InstructionCodeGeneratorX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6453 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6454 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6455 | LocationSummary* locations = switch_instr->GetLocations(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6456 | CpuRegister value_reg_in = locations->InAt(0).AsRegister<CpuRegister>(); |
| 6457 | CpuRegister temp_reg = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 6458 | CpuRegister base_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6459 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6460 | |
| 6461 | // Should we generate smaller inline compare/jumps? |
| 6462 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 6463 | // Figure out the correct compare values and jump conditions. |
| 6464 | // Handle the first compare/branch as a special case because it might |
| 6465 | // jump to the default case. |
| 6466 | DCHECK_GT(num_entries, 2u); |
| 6467 | Condition first_condition; |
| 6468 | uint32_t index; |
| 6469 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 6470 | if (lower_bound != 0) { |
| 6471 | first_condition = kLess; |
| 6472 | __ cmpl(value_reg_in, Immediate(lower_bound)); |
| 6473 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 6474 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
| 6475 | |
| 6476 | index = 1; |
| 6477 | } else { |
| 6478 | // Handle all the compare/jumps below. |
| 6479 | first_condition = kBelow; |
| 6480 | index = 0; |
| 6481 | } |
| 6482 | |
| 6483 | // Handle the rest of the compare/jumps. |
| 6484 | for (; index + 1 < num_entries; index += 2) { |
| 6485 | int32_t compare_to_value = lower_bound + index + 1; |
| 6486 | __ cmpl(value_reg_in, Immediate(compare_to_value)); |
| 6487 | // Jump to successors[index] if value < case_value[index]. |
| 6488 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 6489 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 6490 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 6491 | } |
| 6492 | |
| 6493 | if (index != num_entries) { |
| 6494 | // There are an odd number of entries. Handle the last one. |
| 6495 | DCHECK_EQ(index + 1, num_entries); |
Nicolas Geoffray | 6ce0173 | 2015-12-30 14:10:13 +0000 | [diff] [blame] | 6496 | __ cmpl(value_reg_in, Immediate(static_cast<int32_t>(lower_bound + index))); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6497 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
| 6498 | } |
| 6499 | |
| 6500 | // And the default for any other value. |
| 6501 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6502 | __ jmp(codegen_->GetLabelOf(default_block)); |
| 6503 | } |
| 6504 | return; |
| 6505 | } |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6506 | |
| 6507 | // Remove the bias, if needed. |
| 6508 | Register value_reg_out = value_reg_in.AsRegister(); |
| 6509 | if (lower_bound != 0) { |
| 6510 | __ leal(temp_reg, Address(value_reg_in, -lower_bound)); |
| 6511 | value_reg_out = temp_reg.AsRegister(); |
| 6512 | } |
| 6513 | CpuRegister value_reg(value_reg_out); |
| 6514 | |
| 6515 | // Is the value in range? |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6516 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 6517 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6518 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6519 | // We are in the range of the table. |
| 6520 | // Load the address of the jump table in the constant area. |
| 6521 | __ leaq(base_reg, codegen_->LiteralCaseTable(switch_instr)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6522 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6523 | // Load the (signed) offset from the jump table. |
| 6524 | __ movsxd(temp_reg, Address(base_reg, value_reg, TIMES_4, 0)); |
| 6525 | |
| 6526 | // Add the offset to the address of the table base. |
| 6527 | __ addq(temp_reg, base_reg); |
| 6528 | |
| 6529 | // And jump. |
| 6530 | __ jmp(temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6531 | } |
| 6532 | |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6533 | void CodeGeneratorX86_64::Load32BitValue(CpuRegister dest, int32_t value) { |
| 6534 | if (value == 0) { |
| 6535 | __ xorl(dest, dest); |
| 6536 | } else { |
| 6537 | __ movl(dest, Immediate(value)); |
| 6538 | } |
| 6539 | } |
| 6540 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6541 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 6542 | if (value == 0) { |
Aart Bik | c5d4754 | 2016-01-27 17:00:35 -0800 | [diff] [blame] | 6543 | // Clears upper bits too. |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 6544 | __ xorl(dest, dest); |
| 6545 | } else if (value > 0 && IsInt<32>(value)) { |
| 6546 | // We can use a 32 bit move, as it will zero-extend and is one byte shorter. |
| 6547 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 6548 | } else { |
| 6549 | __ movq(dest, Immediate(value)); |
| 6550 | } |
| 6551 | } |
| 6552 | |
Mark Mendell | 7c0b44f | 2016-02-01 10:08:35 -0500 | [diff] [blame^] | 6553 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, int32_t value) { |
| 6554 | if (value == 0) { |
| 6555 | __ xorps(dest, dest); |
| 6556 | } else { |
| 6557 | __ movss(dest, LiteralInt32Address(value)); |
| 6558 | } |
| 6559 | } |
| 6560 | |
| 6561 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, int64_t value) { |
| 6562 | if (value == 0) { |
| 6563 | __ xorpd(dest, dest); |
| 6564 | } else { |
| 6565 | __ movsd(dest, LiteralInt64Address(value)); |
| 6566 | } |
| 6567 | } |
| 6568 | |
| 6569 | void CodeGeneratorX86_64::Load32BitValue(XmmRegister dest, float value) { |
| 6570 | Load32BitValue(dest, bit_cast<int32_t, float>(value)); |
| 6571 | } |
| 6572 | |
| 6573 | void CodeGeneratorX86_64::Load64BitValue(XmmRegister dest, double value) { |
| 6574 | Load64BitValue(dest, bit_cast<int64_t, double>(value)); |
| 6575 | } |
| 6576 | |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 6577 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 6578 | DCHECK(dest.IsDoubleStackSlot()); |
| 6579 | if (IsInt<32>(value)) { |
| 6580 | // Can move directly as an int32 constant. |
| 6581 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 6582 | Immediate(static_cast<int32_t>(value))); |
| 6583 | } else { |
| 6584 | Load64BitValue(CpuRegister(TMP), value); |
| 6585 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 6586 | } |
| 6587 | } |
| 6588 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6589 | /** |
| 6590 | * Class to handle late fixup of offsets into constant area. |
| 6591 | */ |
| 6592 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| 6593 | public: |
| 6594 | RIPFixup(CodeGeneratorX86_64& codegen, size_t offset) |
| 6595 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 6596 | |
| 6597 | protected: |
| 6598 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 6599 | |
| 6600 | CodeGeneratorX86_64* codegen_; |
| 6601 | |
| 6602 | private: |
| 6603 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 6604 | // Patch the correct offset for the instruction. We use the address of the |
| 6605 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 6606 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 6607 | int32_t relative_position = constant_offset - pos; |
| 6608 | |
| 6609 | // Patch in the right value. |
| 6610 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 6611 | } |
| 6612 | |
| 6613 | // Location in constant area that the fixup refers to. |
| 6614 | size_t offset_into_constant_area_; |
| 6615 | }; |
| 6616 | |
| 6617 | /** |
| 6618 | t * Class to handle late fixup of offsets to a jump table that will be created in the |
| 6619 | * constant area. |
| 6620 | */ |
| 6621 | class JumpTableRIPFixup : public RIPFixup { |
| 6622 | public: |
| 6623 | JumpTableRIPFixup(CodeGeneratorX86_64& codegen, HPackedSwitch* switch_instr) |
| 6624 | : RIPFixup(codegen, -1), switch_instr_(switch_instr) {} |
| 6625 | |
| 6626 | void CreateJumpTable() { |
| 6627 | X86_64Assembler* assembler = codegen_->GetAssembler(); |
| 6628 | |
| 6629 | // Ensure that the reference to the jump table has the correct offset. |
| 6630 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 6631 | SetOffset(offset_in_constant_table); |
| 6632 | |
| 6633 | // Compute the offset from the start of the function to this jump table. |
| 6634 | const int32_t current_table_offset = assembler->CodeSize() + offset_in_constant_table; |
| 6635 | |
| 6636 | // Populate the jump table with the correct values for the jump table. |
| 6637 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 6638 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 6639 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 6640 | // The value that we want is the target offset - the position of the table. |
| 6641 | for (int32_t i = 0; i < num_entries; i++) { |
| 6642 | HBasicBlock* b = successors[i]; |
| 6643 | Label* l = codegen_->GetLabelOf(b); |
| 6644 | DCHECK(l->IsBound()); |
| 6645 | int32_t offset_to_block = l->Position() - current_table_offset; |
| 6646 | assembler->AppendInt32(offset_to_block); |
| 6647 | } |
| 6648 | } |
| 6649 | |
| 6650 | private: |
| 6651 | const HPackedSwitch* switch_instr_; |
| 6652 | }; |
| 6653 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6654 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 6655 | // Generate the constant area if needed. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 6656 | X86_64Assembler* assembler = GetAssembler(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6657 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 6658 | // 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] | 6659 | assembler->Align(4, 0); |
| 6660 | constant_area_start_ = assembler->CodeSize(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6661 | |
| 6662 | // Populate any jump tables. |
| 6663 | for (auto jump_table : fixups_to_jump_tables_) { |
| 6664 | jump_table->CreateJumpTable(); |
| 6665 | } |
| 6666 | |
| 6667 | // And now add the constant area to the generated code. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 6668 | assembler->AddConstantArea(); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6669 | } |
| 6670 | |
| 6671 | // And finish up. |
| 6672 | CodeGenerator::Finalize(allocator); |
| 6673 | } |
| 6674 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 6675 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
| 6676 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 6677 | return Address::RIP(fixup); |
| 6678 | } |
| 6679 | |
| 6680 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
| 6681 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 6682 | return Address::RIP(fixup); |
| 6683 | } |
| 6684 | |
| 6685 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
| 6686 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 6687 | return Address::RIP(fixup); |
| 6688 | } |
| 6689 | |
| 6690 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
| 6691 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 6692 | return Address::RIP(fixup); |
| 6693 | } |
| 6694 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6695 | // TODO: trg as memory. |
| 6696 | void CodeGeneratorX86_64::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 6697 | if (!trg.IsValid()) { |
Roland Levillain | 1e7f8db | 2015-12-15 10:54:19 +0000 | [diff] [blame] | 6698 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6699 | return; |
| 6700 | } |
| 6701 | |
| 6702 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 6703 | |
| 6704 | Location return_loc = InvokeDexCallingConventionVisitorX86_64().GetReturnLocation(type); |
| 6705 | if (trg.Equals(return_loc)) { |
| 6706 | return; |
| 6707 | } |
| 6708 | |
| 6709 | // Let the parallel move resolver take care of all of this. |
| 6710 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 6711 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 6712 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 6713 | } |
| 6714 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame] | 6715 | Address CodeGeneratorX86_64::LiteralCaseTable(HPackedSwitch* switch_instr) { |
| 6716 | // Create a fixup to be used to create and address the jump table. |
| 6717 | JumpTableRIPFixup* table_fixup = |
| 6718 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 6719 | |
| 6720 | // We have to populate the jump tables. |
| 6721 | fixups_to_jump_tables_.push_back(table_fixup); |
| 6722 | return Address::RIP(table_fixup); |
| 6723 | } |
| 6724 | |
Mark Mendell | ea5af68 | 2015-10-22 17:35:49 -0400 | [diff] [blame] | 6725 | void CodeGeneratorX86_64::MoveInt64ToAddress(const Address& addr_low, |
| 6726 | const Address& addr_high, |
| 6727 | int64_t v, |
| 6728 | HInstruction* instruction) { |
| 6729 | if (IsInt<32>(v)) { |
| 6730 | int32_t v_32 = v; |
| 6731 | __ movq(addr_low, Immediate(v_32)); |
| 6732 | MaybeRecordImplicitNullCheck(instruction); |
| 6733 | } else { |
| 6734 | // Didn't fit in a register. Do it in pieces. |
| 6735 | int32_t low_v = Low32Bits(v); |
| 6736 | int32_t high_v = High32Bits(v); |
| 6737 | __ movl(addr_low, Immediate(low_v)); |
| 6738 | MaybeRecordImplicitNullCheck(instruction); |
| 6739 | __ movl(addr_high, Immediate(high_v)); |
| 6740 | } |
| 6741 | } |
| 6742 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6743 | #undef __ |
| 6744 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 6745 | } // namespace x86_64 |
| 6746 | } // namespace art |