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 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 37 | namespace x86_64 { |
| 38 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 39 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 40 | static constexpr Register kMethodRegisterArgument = RDI; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 41 | |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 42 | static constexpr Register kCoreCalleeSaves[] = { RBX, RBP, R12, R13, R14, R15 }; |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 43 | static constexpr FloatRegister kFpuCalleeSaves[] = { XMM12, XMM13, XMM14, XMM15 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 44 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 45 | static constexpr int kC2ConditionMask = 0x400; |
| 46 | |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 47 | #define __ down_cast<X86_64Assembler*>(codegen->GetAssembler())-> |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 48 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 49 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 50 | class NullCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 51 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 52 | explicit NullCheckSlowPathX86_64(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 53 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 54 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 55 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 56 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 57 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 58 | // Live registers will be restored in the catch block if caught. |
| 59 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 60 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 61 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), |
| 62 | instruction_, |
| 63 | instruction_->GetDexPc(), |
| 64 | this); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 65 | } |
| 66 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 67 | bool IsFatal() const OVERRIDE { return true; } |
| 68 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 69 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86_64"; } |
| 70 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 71 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 72 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 73 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86_64); |
| 74 | }; |
| 75 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 76 | class DivZeroCheckSlowPathX86_64 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 77 | public: |
| 78 | explicit DivZeroCheckSlowPathX86_64(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 79 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 80 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 81 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 82 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 83 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 84 | // Live registers will be restored in the catch block if caught. |
| 85 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 86 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 87 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), |
| 88 | instruction_, |
| 89 | instruction_->GetDexPc(), |
| 90 | this); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 93 | bool IsFatal() const OVERRIDE { return true; } |
| 94 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 95 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86_64"; } |
| 96 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 97 | private: |
| 98 | HDivZeroCheck* const instruction_; |
| 99 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86_64); |
| 100 | }; |
| 101 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 102 | class DivRemMinusOneSlowPathX86_64 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 103 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 104 | DivRemMinusOneSlowPathX86_64(Register reg, Primitive::Type type, bool is_div) |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 105 | : cpu_reg_(CpuRegister(reg)), type_(type), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 106 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 107 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 108 | __ Bind(GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 109 | if (type_ == Primitive::kPrimInt) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 110 | if (is_div_) { |
| 111 | __ negl(cpu_reg_); |
| 112 | } else { |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 113 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 114 | } |
| 115 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 116 | } else { |
| 117 | DCHECK_EQ(Primitive::kPrimLong, type_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 118 | if (is_div_) { |
| 119 | __ negq(cpu_reg_); |
| 120 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 121 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 122 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 123 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 124 | __ jmp(GetExitLabel()); |
| 125 | } |
| 126 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 127 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86_64"; } |
| 128 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 129 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 130 | const CpuRegister cpu_reg_; |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 131 | const Primitive::Type type_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 132 | const bool is_div_; |
| 133 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86_64); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 134 | }; |
| 135 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 136 | class SuspendCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 137 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 138 | SuspendCheckSlowPathX86_64(HSuspendCheck* instruction, HBasicBlock* successor) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 139 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 140 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 141 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 142 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 143 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 144 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 145 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), |
| 146 | instruction_, |
| 147 | instruction_->GetDexPc(), |
| 148 | this); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 149 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 150 | if (successor_ == nullptr) { |
| 151 | __ jmp(GetReturnLabel()); |
| 152 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 153 | __ jmp(x64_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 154 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 157 | Label* GetReturnLabel() { |
| 158 | DCHECK(successor_ == nullptr); |
| 159 | return &return_label_; |
| 160 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 161 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 162 | HBasicBlock* GetSuccessor() const { |
| 163 | return successor_; |
| 164 | } |
| 165 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 166 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86_64"; } |
| 167 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 168 | private: |
| 169 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 170 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 171 | Label return_label_; |
| 172 | |
| 173 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64); |
| 174 | }; |
| 175 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 176 | class BoundsCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 177 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 178 | explicit BoundsCheckSlowPathX86_64(HBoundsCheck* instruction) |
| 179 | : instruction_(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 180 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 181 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 182 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 183 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 184 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 185 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 186 | // Live registers will be restored in the catch block if caught. |
| 187 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 188 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 189 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 190 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 191 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 192 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 193 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 194 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 195 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 196 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 197 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 198 | Primitive::kPrimInt); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 199 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds), |
| 200 | instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 201 | } |
| 202 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 203 | bool IsFatal() const OVERRIDE { return true; } |
| 204 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 205 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86_64"; } |
| 206 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 207 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 208 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 209 | |
| 210 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 211 | }; |
| 212 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 213 | class LoadClassSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 214 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 215 | LoadClassSlowPathX86_64(HLoadClass* cls, |
| 216 | HInstruction* at, |
| 217 | uint32_t dex_pc, |
| 218 | bool do_clinit) |
| 219 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 220 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 221 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 222 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 223 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 224 | LocationSummary* locations = at_->GetLocations(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 225 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 226 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 227 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 228 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 229 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 230 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 231 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(cls_->GetTypeIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 232 | x64_codegen->InvokeRuntime(do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 233 | : QUICK_ENTRY_POINT(pInitializeType), |
| 234 | at_, dex_pc_, this); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 235 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 236 | Location out = locations->Out(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 237 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 238 | if (out.IsValid()) { |
| 239 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 240 | x64_codegen->Move(out, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 241 | } |
| 242 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 243 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 244 | __ jmp(GetExitLabel()); |
| 245 | } |
| 246 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 247 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86_64"; } |
| 248 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 249 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 250 | // The class this slow path will load. |
| 251 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 252 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 253 | // The instruction where this slow path is happening. |
| 254 | // (Might be the load class or an initialization check). |
| 255 | HInstruction* const at_; |
| 256 | |
| 257 | // The dex PC of `at_`. |
| 258 | const uint32_t dex_pc_; |
| 259 | |
| 260 | // Whether to initialize the class. |
| 261 | const bool do_clinit_; |
| 262 | |
| 263 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86_64); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 264 | }; |
| 265 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 266 | class LoadStringSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 267 | public: |
| 268 | explicit LoadStringSlowPathX86_64(HLoadString* instruction) : instruction_(instruction) {} |
| 269 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 270 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 271 | LocationSummary* locations = instruction_->GetLocations(); |
| 272 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 273 | |
| 274 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 275 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 276 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 277 | |
| 278 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 279 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 280 | Immediate(instruction_->GetStringIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 281 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), |
| 282 | instruction_, |
| 283 | instruction_->GetDexPc(), |
| 284 | this); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 285 | x64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 286 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 287 | __ jmp(GetExitLabel()); |
| 288 | } |
| 289 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 290 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86_64"; } |
| 291 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 292 | private: |
| 293 | HLoadString* const instruction_; |
| 294 | |
| 295 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86_64); |
| 296 | }; |
| 297 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 298 | class TypeCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 299 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 300 | TypeCheckSlowPathX86_64(HInstruction* instruction, bool is_fatal) |
| 301 | : instruction_(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 302 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 303 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 304 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 305 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 306 | : locations->Out(); |
| 307 | uint32_t dex_pc = instruction_->GetDexPc(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 308 | DCHECK(instruction_->IsCheckCast() |
| 309 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 310 | |
| 311 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 312 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 313 | |
| 314 | if (instruction_->IsCheckCast()) { |
| 315 | // The codegen for the instruction overwrites `temp`, so put it back in place. |
| 316 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 317 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 318 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 319 | __ movl(temp, Address(obj, class_offset)); |
| 320 | __ MaybeUnpoisonHeapReference(temp); |
| 321 | } |
| 322 | |
| 323 | if (!is_fatal_) { |
| 324 | SaveLiveRegisters(codegen, locations); |
| 325 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 326 | |
| 327 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 328 | // move resolver. |
| 329 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 330 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 331 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 332 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 333 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 334 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 335 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 336 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 337 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 338 | if (instruction_->IsInstanceOf()) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 339 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 340 | instruction_, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 341 | dex_pc, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 342 | this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 343 | } else { |
| 344 | DCHECK(instruction_->IsCheckCast()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 345 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 346 | instruction_, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 347 | dex_pc, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 348 | this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 349 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 350 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 351 | if (!is_fatal_) { |
| 352 | if (instruction_->IsInstanceOf()) { |
| 353 | x64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
| 354 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 355 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 356 | RestoreLiveRegisters(codegen, locations); |
| 357 | __ jmp(GetExitLabel()); |
| 358 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 359 | } |
| 360 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 361 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86_64"; } |
| 362 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 363 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 364 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 365 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 366 | HInstruction* const instruction_; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 367 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 368 | |
| 369 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86_64); |
| 370 | }; |
| 371 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 372 | class DeoptimizationSlowPathX86_64 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 373 | public: |
| 374 | explicit DeoptimizationSlowPathX86_64(HInstruction* instruction) |
| 375 | : instruction_(instruction) {} |
| 376 | |
| 377 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 378 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 379 | __ Bind(GetEntryLabel()); |
| 380 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 381 | DCHECK(instruction_->IsDeoptimize()); |
| 382 | HDeoptimize* deoptimize = instruction_->AsDeoptimize(); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 383 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 384 | deoptimize, |
| 385 | deoptimize->GetDexPc(), |
| 386 | this); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 389 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86_64"; } |
| 390 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 391 | private: |
| 392 | HInstruction* const instruction_; |
| 393 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86_64); |
| 394 | }; |
| 395 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 396 | class ArraySetSlowPathX86_64 : public SlowPathCode { |
| 397 | public: |
| 398 | explicit ArraySetSlowPathX86_64(HInstruction* instruction) : instruction_(instruction) {} |
| 399 | |
| 400 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 401 | LocationSummary* locations = instruction_->GetLocations(); |
| 402 | __ Bind(GetEntryLabel()); |
| 403 | SaveLiveRegisters(codegen, locations); |
| 404 | |
| 405 | InvokeRuntimeCallingConvention calling_convention; |
| 406 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 407 | parallel_move.AddMove( |
| 408 | locations->InAt(0), |
| 409 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 410 | Primitive::kPrimNot, |
| 411 | nullptr); |
| 412 | parallel_move.AddMove( |
| 413 | locations->InAt(1), |
| 414 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 415 | Primitive::kPrimInt, |
| 416 | nullptr); |
| 417 | parallel_move.AddMove( |
| 418 | locations->InAt(2), |
| 419 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 420 | Primitive::kPrimNot, |
| 421 | nullptr); |
| 422 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 423 | |
| 424 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 425 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 426 | instruction_, |
| 427 | instruction_->GetDexPc(), |
| 428 | this); |
| 429 | RestoreLiveRegisters(codegen, locations); |
| 430 | __ jmp(GetExitLabel()); |
| 431 | } |
| 432 | |
| 433 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86_64"; } |
| 434 | |
| 435 | private: |
| 436 | HInstruction* const instruction_; |
| 437 | |
| 438 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86_64); |
| 439 | }; |
| 440 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 441 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 442 | #define __ down_cast<X86_64Assembler*>(GetAssembler())-> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 443 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 444 | inline Condition X86_64IntegerCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 445 | switch (cond) { |
| 446 | case kCondEQ: return kEqual; |
| 447 | case kCondNE: return kNotEqual; |
| 448 | case kCondLT: return kLess; |
| 449 | case kCondLE: return kLessEqual; |
| 450 | case kCondGT: return kGreater; |
| 451 | case kCondGE: return kGreaterEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 452 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 453 | LOG(FATAL) << "Unreachable"; |
| 454 | UNREACHABLE(); |
| 455 | } |
| 456 | |
| 457 | inline Condition X86_64FPCondition(IfCondition cond) { |
| 458 | switch (cond) { |
| 459 | case kCondEQ: return kEqual; |
| 460 | case kCondNE: return kNotEqual; |
| 461 | case kCondLT: return kBelow; |
| 462 | case kCondLE: return kBelowEqual; |
| 463 | case kCondGT: return kAbove; |
| 464 | case kCondGE: return kAboveEqual; |
| 465 | }; |
| 466 | LOG(FATAL) << "Unreachable"; |
| 467 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 468 | } |
| 469 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 470 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 471 | Location temp) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 472 | // All registers are assumed to be correctly set up. |
| 473 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 474 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 475 | switch (invoke->GetMethodLoadKind()) { |
| 476 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 477 | // temp = thread->string_init_entrypoint |
| 478 | __ gs()->movl(temp.AsRegister<CpuRegister>(), |
| 479 | Address::Absolute(invoke->GetStringInitOffset(), true)); |
| 480 | break; |
| 481 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 482 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 483 | break; |
| 484 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 485 | __ movq(temp.AsRegister<CpuRegister>(), Immediate(invoke->GetMethodAddress())); |
| 486 | break; |
| 487 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 488 | __ movl(temp.AsRegister<CpuRegister>(), Immediate(0)); // Placeholder. |
| 489 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 490 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 491 | break; |
| 492 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
| 493 | pc_rel_dex_cache_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 494 | invoke->GetDexCacheArrayOffset()); |
| 495 | __ movq(temp.AsRegister<CpuRegister>(), |
| 496 | Address::Absolute(kDummy32BitOffset, false /* no_rip */)); |
| 497 | // Bind the label at the end of the "movl" insn. |
| 498 | __ Bind(&pc_rel_dex_cache_patches_.back().label); |
| 499 | break; |
| 500 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
| 501 | Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 502 | Register method_reg; |
| 503 | CpuRegister reg = temp.AsRegister<CpuRegister>(); |
| 504 | if (current_method.IsRegister()) { |
| 505 | method_reg = current_method.AsRegister<Register>(); |
| 506 | } else { |
| 507 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 508 | DCHECK(!current_method.IsValid()); |
| 509 | method_reg = reg.AsRegister(); |
| 510 | __ movq(reg, Address(CpuRegister(RSP), kCurrentMethodStackOffset)); |
| 511 | } |
| 512 | // temp = temp->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 513 | __ movq(reg, |
| 514 | Address(CpuRegister(method_reg), |
| 515 | ArtMethod::DexCacheResolvedMethodsOffset(kX86_64PointerSize).SizeValue())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 516 | // temp = temp[index_in_cache] |
| 517 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 518 | __ movq(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 519 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 520 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | switch (invoke->GetCodePtrLocation()) { |
| 524 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 525 | __ call(&frame_entry_label_); |
| 526 | break; |
| 527 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 528 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 529 | Label* label = &relative_call_patches_.back().label; |
| 530 | __ call(label); // Bind to the patch label, override at link time. |
| 531 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 532 | break; |
| 533 | } |
| 534 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 535 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 536 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 537 | FALLTHROUGH_INTENDED; |
| 538 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 539 | // (callee_method + offset_of_quick_compiled_code)() |
| 540 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 541 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 542 | kX86_64WordSize).SizeValue())); |
| 543 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 544 | } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 545 | |
| 546 | DCHECK(!IsLeafMethod()); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 547 | } |
| 548 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 549 | void CodeGeneratorX86_64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 550 | CpuRegister temp = temp_in.AsRegister<CpuRegister>(); |
| 551 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 552 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
| 553 | LocationSummary* locations = invoke->GetLocations(); |
| 554 | Location receiver = locations->InAt(0); |
| 555 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 556 | // temp = object->GetClass(); |
| 557 | DCHECK(receiver.IsRegister()); |
| 558 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
| 559 | MaybeRecordImplicitNullCheck(invoke); |
| 560 | __ MaybeUnpoisonHeapReference(temp); |
| 561 | // temp = temp->GetMethodAt(method_offset); |
| 562 | __ movq(temp, Address(temp, method_offset)); |
| 563 | // call temp->GetEntryPoint(); |
| 564 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 565 | kX86_64WordSize).SizeValue())); |
| 566 | } |
| 567 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 568 | void CodeGeneratorX86_64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 569 | DCHECK(linker_patches->empty()); |
| 570 | size_t size = |
| 571 | method_patches_.size() + relative_call_patches_.size() + pc_rel_dex_cache_patches_.size(); |
| 572 | linker_patches->reserve(size); |
| 573 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
| 574 | // The label points to the end of the "movl" instruction but the literal offset for method |
| 575 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 576 | uint32_t literal_offset = info.label.Position() - 4; |
| 577 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 578 | info.target_method.dex_file, |
| 579 | info.target_method.dex_method_index)); |
| 580 | } |
| 581 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
| 582 | // The label points to the end of the "call" instruction but the literal offset for method |
| 583 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 584 | uint32_t literal_offset = info.label.Position() - 4; |
| 585 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 586 | info.target_method.dex_file, |
| 587 | info.target_method.dex_method_index)); |
| 588 | } |
| 589 | for (const PcRelativeDexCacheAccessInfo& info : pc_rel_dex_cache_patches_) { |
| 590 | // The label points to the end of the "mov" instruction but the literal offset for method |
| 591 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 592 | uint32_t literal_offset = info.label.Position() - 4; |
| 593 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 594 | &info.target_dex_file, |
| 595 | info.label.Position(), |
| 596 | info.element_offset)); |
| 597 | } |
| 598 | } |
| 599 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 600 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 601 | stream << Register(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 605 | stream << FloatRegister(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 606 | } |
| 607 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 608 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 609 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 610 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 611 | } |
| 612 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 613 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 614 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 615 | return kX86_64WordSize; |
| 616 | } |
| 617 | |
| 618 | size_t CodeGeneratorX86_64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 619 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 620 | return kX86_64WordSize; |
| 621 | } |
| 622 | |
| 623 | size_t CodeGeneratorX86_64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 624 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 625 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 626 | } |
| 627 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 628 | void CodeGeneratorX86_64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 629 | HInstruction* instruction, |
| 630 | uint32_t dex_pc, |
| 631 | SlowPathCode* slow_path) { |
| 632 | InvokeRuntime(GetThreadOffset<kX86_64WordSize>(entrypoint).Int32Value(), |
| 633 | instruction, |
| 634 | dex_pc, |
| 635 | slow_path); |
| 636 | } |
| 637 | |
| 638 | void CodeGeneratorX86_64::InvokeRuntime(int32_t entry_point_offset, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 639 | HInstruction* instruction, |
| 640 | uint32_t dex_pc, |
| 641 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 642 | ValidateInvokeRuntime(instruction, slow_path); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 643 | __ gs()->call(Address::Absolute(entry_point_offset, true)); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 644 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 645 | } |
| 646 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 647 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 648 | // Use a fake return address register to mimic Quick. |
| 649 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 650 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
| 651 | const X86_64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 652 | const CompilerOptions& compiler_options, |
| 653 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 654 | : CodeGenerator(graph, |
| 655 | kNumberOfCpuRegisters, |
| 656 | kNumberOfFloatRegisters, |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 657 | kNumberOfCpuRegisterPairs, |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 658 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 659 | arraysize(kCoreCalleeSaves)) |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 660 | | (1 << kFakeReturnRegister), |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 661 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 662 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 663 | compiler_options, |
| 664 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 665 | block_labels_(nullptr), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 666 | location_builder_(graph, this), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 667 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 668 | move_resolver_(graph->GetArena(), this), |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 669 | isa_features_(isa_features), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 670 | constant_area_start_(0), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 671 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 672 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame^] | 673 | pc_rel_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 674 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 675 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 676 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 677 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 678 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 679 | CodeGeneratorX86_64* codegen) |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 680 | : HGraphVisitor(graph), |
| 681 | assembler_(codegen->GetAssembler()), |
| 682 | codegen_(codegen) {} |
| 683 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 684 | Location CodeGeneratorX86_64::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 685 | switch (type) { |
| 686 | case Primitive::kPrimLong: |
| 687 | case Primitive::kPrimByte: |
| 688 | case Primitive::kPrimBoolean: |
| 689 | case Primitive::kPrimChar: |
| 690 | case Primitive::kPrimShort: |
| 691 | case Primitive::kPrimInt: |
| 692 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 693 | size_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfCpuRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 694 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 698 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 699 | size_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfFloatRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 700 | return Location::FpuRegisterLocation(reg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 701 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 702 | |
| 703 | case Primitive::kPrimVoid: |
| 704 | LOG(FATAL) << "Unreachable type " << type; |
| 705 | } |
| 706 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 707 | return Location(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 708 | } |
| 709 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 710 | void CodeGeneratorX86_64::SetupBlockedRegisters(bool is_baseline) const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 711 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 712 | blocked_core_registers_[RSP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 713 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 714 | // Block the register used as TMP. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 715 | blocked_core_registers_[TMP] = true; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 716 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 717 | if (is_baseline) { |
| 718 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 719 | blocked_core_registers_[kCoreCalleeSaves[i]] = true; |
| 720 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 721 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 722 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 723 | } |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 724 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 725 | } |
| 726 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 727 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 728 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 729 | } |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 730 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 731 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 732 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 733 | } |
| 734 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 735 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 736 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 737 | __ Bind(&frame_entry_label_); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 738 | bool skip_overflow_check = IsLeafMethod() |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 739 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 740 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 741 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 742 | if (!skip_overflow_check) { |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 743 | __ testq(CpuRegister(RAX), Address( |
| 744 | CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 745 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 746 | } |
Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 747 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 748 | if (HasEmptyFrame()) { |
| 749 | return; |
| 750 | } |
| 751 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 752 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 753 | Register reg = kCoreCalleeSaves[i]; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 754 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 755 | __ pushq(CpuRegister(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 756 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 757 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 758 | } |
| 759 | } |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 760 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 761 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 762 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 763 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 764 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 765 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 766 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 767 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 768 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 769 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 770 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 771 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 772 | } |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 773 | } |
| 774 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 775 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 776 | CpuRegister(kMethodRegisterArgument)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | void CodeGeneratorX86_64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 780 | __ cfi().RememberState(); |
| 781 | if (!HasEmptyFrame()) { |
| 782 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 783 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| 784 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 785 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 786 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 787 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 788 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 793 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 794 | __ cfi().AdjustCFAOffset(-adjust); |
| 795 | |
| 796 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 797 | Register reg = kCoreCalleeSaves[i]; |
| 798 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 799 | __ popq(CpuRegister(reg)); |
| 800 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 801 | __ cfi().Restore(DWARFReg(reg)); |
| 802 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 803 | } |
| 804 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 805 | __ ret(); |
| 806 | __ cfi().RestoreState(); |
| 807 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 808 | } |
| 809 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 810 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 811 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 812 | } |
| 813 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 814 | Location CodeGeneratorX86_64::GetStackLocation(HLoadLocal* load) const { |
| 815 | switch (load->GetType()) { |
| 816 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 817 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 818 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 819 | |
| 820 | case Primitive::kPrimInt: |
| 821 | case Primitive::kPrimNot: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 822 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 823 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 824 | |
| 825 | case Primitive::kPrimBoolean: |
| 826 | case Primitive::kPrimByte: |
| 827 | case Primitive::kPrimChar: |
| 828 | case Primitive::kPrimShort: |
| 829 | case Primitive::kPrimVoid: |
| 830 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 831 | UNREACHABLE(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 835 | UNREACHABLE(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 839 | if (source.Equals(destination)) { |
| 840 | return; |
| 841 | } |
| 842 | if (destination.IsRegister()) { |
| 843 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 844 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 845 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 846 | __ movd(destination.AsRegister<CpuRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 847 | } else if (source.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 848 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 849 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 850 | } else { |
| 851 | DCHECK(source.IsDoubleStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 852 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 853 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 854 | } |
| 855 | } else if (destination.IsFpuRegister()) { |
| 856 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 857 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 858 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 859 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 860 | } else if (source.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 861 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 862 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 863 | } else { |
| 864 | DCHECK(source.IsDoubleStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 865 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 866 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 867 | } |
| 868 | } else if (destination.IsStackSlot()) { |
| 869 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 870 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 871 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 872 | } else if (source.IsFpuRegister()) { |
| 873 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 874 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 875 | } else if (source.IsConstant()) { |
| 876 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 877 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 878 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 879 | } else { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 880 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 881 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 882 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 883 | } |
| 884 | } else { |
| 885 | DCHECK(destination.IsDoubleStackSlot()); |
| 886 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 887 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 888 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 889 | } else if (source.IsFpuRegister()) { |
| 890 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 891 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 892 | } else if (source.IsConstant()) { |
| 893 | HConstant* constant = source.GetConstant(); |
Zheng Xu | 12bca97 | 2015-03-30 19:35:50 +0800 | [diff] [blame] | 894 | int64_t value; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 895 | if (constant->IsDoubleConstant()) { |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 896 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 897 | } else { |
| 898 | DCHECK(constant->IsLongConstant()); |
| 899 | value = constant->AsLongConstant()->GetValue(); |
| 900 | } |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 901 | Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 902 | } else { |
| 903 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 904 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 905 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 906 | } |
| 907 | } |
| 908 | } |
| 909 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 910 | void CodeGeneratorX86_64::Move(HInstruction* instruction, |
| 911 | Location location, |
| 912 | HInstruction* move_for) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 913 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 914 | if (instruction->IsCurrentMethod()) { |
Mathieu Chartier | e3b034a | 2015-05-31 14:29:23 -0700 | [diff] [blame] | 915 | Move(location, Location::DoubleStackSlot(kCurrentMethodStackOffset)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 916 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 917 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 918 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 919 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 920 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 921 | Immediate imm(GetInt32ValueOf(const_to_move)); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 922 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 923 | __ movl(location.AsRegister<CpuRegister>(), imm); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 924 | } else if (location.IsStackSlot()) { |
| 925 | __ movl(Address(CpuRegister(RSP), location.GetStackIndex()), imm); |
| 926 | } else { |
| 927 | DCHECK(location.IsConstant()); |
| 928 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 929 | } |
| 930 | } else if (const_to_move->IsLongConstant()) { |
| 931 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 932 | if (location.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 933 | Load64BitValue(location.AsRegister<CpuRegister>(), value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 934 | } else if (location.IsDoubleStackSlot()) { |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 935 | Store64BitValueToStack(location, value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 936 | } else { |
| 937 | DCHECK(location.IsConstant()); |
| 938 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 939 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 940 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 941 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 942 | switch (instruction->GetType()) { |
| 943 | case Primitive::kPrimBoolean: |
| 944 | case Primitive::kPrimByte: |
| 945 | case Primitive::kPrimChar: |
| 946 | case Primitive::kPrimShort: |
| 947 | case Primitive::kPrimInt: |
| 948 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 949 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 950 | Move(location, Location::StackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
| 951 | break; |
| 952 | |
| 953 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 954 | case Primitive::kPrimDouble: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 955 | Move(location, |
| 956 | Location::DoubleStackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 957 | break; |
| 958 | |
| 959 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 960 | LOG(FATAL) << "Unexpected local type " << instruction->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 961 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 962 | } else if (instruction->IsTemporary()) { |
| 963 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
| 964 | Move(location, temp_location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 965 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 966 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 967 | switch (instruction->GetType()) { |
| 968 | case Primitive::kPrimBoolean: |
| 969 | case Primitive::kPrimByte: |
| 970 | case Primitive::kPrimChar: |
| 971 | case Primitive::kPrimShort: |
| 972 | case Primitive::kPrimInt: |
| 973 | case Primitive::kPrimNot: |
| 974 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 975 | case Primitive::kPrimFloat: |
| 976 | case Primitive::kPrimDouble: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 977 | Move(location, locations->Out()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 978 | break; |
| 979 | |
| 980 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 981 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 982 | } |
| 983 | } |
| 984 | } |
| 985 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 986 | void CodeGeneratorX86_64::MoveConstant(Location location, int32_t value) { |
| 987 | DCHECK(location.IsRegister()); |
| 988 | Load64BitValue(location.AsRegister<CpuRegister>(), static_cast<int64_t>(value)); |
| 989 | } |
| 990 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 991 | void CodeGeneratorX86_64::MoveLocation( |
| 992 | Location dst, Location src, Primitive::Type dst_type ATTRIBUTE_UNUSED) { |
| 993 | Move(dst, src); |
| 994 | } |
| 995 | |
| 996 | void CodeGeneratorX86_64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 997 | if (location.IsRegister()) { |
| 998 | locations->AddTemp(location); |
| 999 | } else { |
| 1000 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1001 | } |
| 1002 | } |
| 1003 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1004 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1005 | DCHECK(!successor->IsExitBlock()); |
| 1006 | |
| 1007 | HBasicBlock* block = got->GetBlock(); |
| 1008 | HInstruction* previous = got->GetPrevious(); |
| 1009 | |
| 1010 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1011 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1012 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1013 | return; |
| 1014 | } |
| 1015 | |
| 1016 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1017 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1018 | } |
| 1019 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1020 | __ jmp(codegen_->GetLabelOf(successor)); |
| 1021 | } |
| 1022 | } |
| 1023 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1024 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 1025 | got->SetLocations(nullptr); |
| 1026 | } |
| 1027 | |
| 1028 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 1029 | HandleGoto(got, got->GetSuccessor()); |
| 1030 | } |
| 1031 | |
| 1032 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1033 | try_boundary->SetLocations(nullptr); |
| 1034 | } |
| 1035 | |
| 1036 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1037 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1038 | if (!successor->IsExitBlock()) { |
| 1039 | HandleGoto(try_boundary, successor); |
| 1040 | } |
| 1041 | } |
| 1042 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1043 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 1044 | exit->SetLocations(nullptr); |
| 1045 | } |
| 1046 | |
| 1047 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1048 | UNUSED(exit); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1049 | } |
| 1050 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1051 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
| 1052 | Label* true_label, |
| 1053 | Label* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1054 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1055 | __ j(kUnordered, true_label); |
| 1056 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1057 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1058 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1059 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HIf* if_instr, |
| 1063 | HCondition* condition, |
| 1064 | Label* true_target, |
| 1065 | Label* false_target, |
| 1066 | Label* always_true_target) { |
| 1067 | LocationSummary* locations = condition->GetLocations(); |
| 1068 | Location left = locations->InAt(0); |
| 1069 | Location right = locations->InAt(1); |
| 1070 | |
| 1071 | // We don't want true_target as a nullptr. |
| 1072 | if (true_target == nullptr) { |
| 1073 | true_target = always_true_target; |
| 1074 | } |
| 1075 | bool falls_through = (false_target == nullptr); |
| 1076 | |
| 1077 | // FP compares don't like null false_targets. |
| 1078 | if (false_target == nullptr) { |
| 1079 | false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1080 | } |
| 1081 | |
| 1082 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1083 | switch (type) { |
| 1084 | case Primitive::kPrimLong: { |
| 1085 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1086 | if (right.IsConstant()) { |
| 1087 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 1088 | if (IsInt<32>(value)) { |
| 1089 | if (value == 0) { |
| 1090 | __ testq(left_reg, left_reg); |
| 1091 | } else { |
| 1092 | __ cmpq(left_reg, Immediate(static_cast<int32_t>(value))); |
| 1093 | } |
| 1094 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1095 | // Value won't fit in a 32-bit integer. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1096 | __ cmpq(left_reg, codegen_->LiteralInt64Address(value)); |
| 1097 | } |
| 1098 | } else if (right.IsDoubleStackSlot()) { |
| 1099 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1100 | } else { |
| 1101 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1102 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1103 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1104 | break; |
| 1105 | } |
| 1106 | case Primitive::kPrimFloat: { |
| 1107 | if (right.IsFpuRegister()) { |
| 1108 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1109 | } else if (right.IsConstant()) { |
| 1110 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1111 | codegen_->LiteralFloatAddress( |
| 1112 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1113 | } else { |
| 1114 | DCHECK(right.IsStackSlot()); |
| 1115 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1116 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1117 | } |
| 1118 | GenerateFPJumps(condition, true_target, false_target); |
| 1119 | break; |
| 1120 | } |
| 1121 | case Primitive::kPrimDouble: { |
| 1122 | if (right.IsFpuRegister()) { |
| 1123 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1124 | } else if (right.IsConstant()) { |
| 1125 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1126 | codegen_->LiteralDoubleAddress( |
| 1127 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1128 | } else { |
| 1129 | DCHECK(right.IsDoubleStackSlot()); |
| 1130 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1131 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1132 | } |
| 1133 | GenerateFPJumps(condition, true_target, false_target); |
| 1134 | break; |
| 1135 | } |
| 1136 | default: |
| 1137 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1138 | } |
| 1139 | |
| 1140 | if (!falls_through) { |
| 1141 | __ jmp(false_target); |
| 1142 | } |
| 1143 | } |
| 1144 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1145 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
| 1146 | Label* true_target, |
| 1147 | Label* false_target, |
| 1148 | Label* always_true_target) { |
| 1149 | HInstruction* cond = instruction->InputAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1150 | if (cond->IsIntConstant()) { |
| 1151 | // Constant condition, statically compared against 1. |
| 1152 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 1153 | if (cond_value == 1) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1154 | if (always_true_target != nullptr) { |
| 1155 | __ jmp(always_true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1156 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1157 | return; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1158 | } else { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1159 | DCHECK_EQ(cond_value, 0); |
| 1160 | } |
| 1161 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1162 | bool is_materialized = |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1163 | !cond->IsCondition() || cond->AsCondition()->NeedsMaterialization(); |
| 1164 | // Moves do not affect the eflags register, so if the condition is |
| 1165 | // evaluated just before the if, we don't need to evaluate it |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1166 | // again. We can't use the eflags on FP conditions if they are |
| 1167 | // materialized due to the complex branching. |
| 1168 | Primitive::Type type = cond->IsCondition() ? cond->InputAt(0)->GetType() : Primitive::kPrimInt; |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1169 | bool eflags_set = cond->IsCondition() |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1170 | && cond->AsCondition()->IsBeforeWhenDisregardMoves(instruction) |
| 1171 | && !Primitive::IsFloatingPointType(type); |
| 1172 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1173 | if (is_materialized) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1174 | if (!eflags_set) { |
| 1175 | // Materialized condition, compare against 0. |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1176 | Location lhs = instruction->GetLocations()->InAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1177 | if (lhs.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 1178 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1179 | } else { |
| 1180 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), |
| 1181 | Immediate(0)); |
| 1182 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1183 | __ j(kNotEqual, true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1184 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1185 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1186 | } |
| 1187 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1188 | // Condition has not been materialized, use its inputs as the |
| 1189 | // comparison and its condition as the branch condition. |
| 1190 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1191 | // Is this a long or FP comparison that has been folded into the HCondition? |
| 1192 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1193 | // Generate the comparison directly. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1194 | GenerateCompareTestAndBranch(instruction->AsIf(), cond->AsCondition(), |
| 1195 | true_target, false_target, always_true_target); |
| 1196 | return; |
| 1197 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1198 | |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1199 | Location lhs = cond->GetLocations()->InAt(0); |
| 1200 | Location rhs = cond->GetLocations()->InAt(1); |
| 1201 | if (rhs.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1202 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1203 | } else if (rhs.IsConstant()) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1204 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 1205 | if (constant == 0) { |
| 1206 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1207 | } else { |
| 1208 | __ cmpl(lhs.AsRegister<CpuRegister>(), Immediate(constant)); |
| 1209 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1210 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1211 | __ cmpl(lhs.AsRegister<CpuRegister>(), |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1212 | Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1213 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1214 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1215 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1216 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1217 | if (false_target != nullptr) { |
| 1218 | __ jmp(false_target); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1219 | } |
| 1220 | } |
| 1221 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1222 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
| 1223 | LocationSummary* locations = |
| 1224 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
| 1225 | HInstruction* cond = if_instr->InputAt(0); |
| 1226 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 1227 | locations->SetInAt(0, Location::Any()); |
| 1228 | } |
| 1229 | } |
| 1230 | |
| 1231 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
| 1232 | Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor()); |
| 1233 | Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1234 | Label* always_true_target = true_target; |
| 1235 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1236 | if_instr->IfTrueSuccessor())) { |
| 1237 | always_true_target = nullptr; |
| 1238 | } |
| 1239 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1240 | if_instr->IfFalseSuccessor())) { |
| 1241 | false_target = nullptr; |
| 1242 | } |
| 1243 | GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target); |
| 1244 | } |
| 1245 | |
| 1246 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1247 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1248 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| 1249 | HInstruction* cond = deoptimize->InputAt(0); |
| 1250 | DCHECK(cond->IsCondition()); |
| 1251 | if (cond->AsCondition()->NeedsMaterialization()) { |
| 1252 | locations->SetInAt(0, Location::Any()); |
| 1253 | } |
| 1254 | } |
| 1255 | |
| 1256 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 1257 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1258 | DeoptimizationSlowPathX86_64(deoptimize); |
| 1259 | codegen_->AddSlowPath(slow_path); |
| 1260 | Label* slow_path_entry = slow_path->GetEntryLabel(); |
| 1261 | GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry); |
| 1262 | } |
| 1263 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1264 | void LocationsBuilderX86_64::VisitLocal(HLocal* local) { |
| 1265 | local->SetLocations(nullptr); |
| 1266 | } |
| 1267 | |
| 1268 | void InstructionCodeGeneratorX86_64::VisitLocal(HLocal* local) { |
| 1269 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
| 1270 | } |
| 1271 | |
| 1272 | void LocationsBuilderX86_64::VisitLoadLocal(HLoadLocal* local) { |
| 1273 | local->SetLocations(nullptr); |
| 1274 | } |
| 1275 | |
| 1276 | void InstructionCodeGeneratorX86_64::VisitLoadLocal(HLoadLocal* load) { |
| 1277 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1278 | UNUSED(load); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | void LocationsBuilderX86_64::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1282 | LocationSummary* locations = |
| 1283 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1284 | switch (store->InputAt(1)->GetType()) { |
| 1285 | case Primitive::kPrimBoolean: |
| 1286 | case Primitive::kPrimByte: |
| 1287 | case Primitive::kPrimChar: |
| 1288 | case Primitive::kPrimShort: |
| 1289 | case Primitive::kPrimInt: |
| 1290 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1291 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1292 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1293 | break; |
| 1294 | |
| 1295 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1296 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1297 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1298 | break; |
| 1299 | |
| 1300 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1301 | LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1302 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | void InstructionCodeGeneratorX86_64::VisitStoreLocal(HStoreLocal* store) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1306 | UNUSED(store); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1307 | } |
| 1308 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1309 | void LocationsBuilderX86_64::VisitCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1310 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1311 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1312 | // Handle the long/FP comparisons made in instruction simplification. |
| 1313 | switch (cond->InputAt(0)->GetType()) { |
| 1314 | case Primitive::kPrimLong: |
| 1315 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1316 | locations->SetInAt(1, Location::Any()); |
| 1317 | break; |
| 1318 | case Primitive::kPrimFloat: |
| 1319 | case Primitive::kPrimDouble: |
| 1320 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1321 | locations->SetInAt(1, Location::Any()); |
| 1322 | break; |
| 1323 | default: |
| 1324 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1325 | locations->SetInAt(1, Location::Any()); |
| 1326 | break; |
| 1327 | } |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1328 | if (cond->NeedsMaterialization()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1329 | locations->SetOut(Location::RequiresRegister()); |
| 1330 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1331 | } |
| 1332 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1333 | void InstructionCodeGeneratorX86_64::VisitCondition(HCondition* cond) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1334 | if (!cond->NeedsMaterialization()) { |
| 1335 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1336 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1337 | |
| 1338 | LocationSummary* locations = cond->GetLocations(); |
| 1339 | Location lhs = locations->InAt(0); |
| 1340 | Location rhs = locations->InAt(1); |
| 1341 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
| 1342 | Label true_label, false_label; |
| 1343 | |
| 1344 | switch (cond->InputAt(0)->GetType()) { |
| 1345 | default: |
| 1346 | // Integer case. |
| 1347 | |
| 1348 | // Clear output register: setcc only sets the low byte. |
| 1349 | __ xorl(reg, reg); |
| 1350 | |
| 1351 | if (rhs.IsRegister()) { |
| 1352 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1353 | } else if (rhs.IsConstant()) { |
| 1354 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1355 | if (constant == 0) { |
| 1356 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1357 | } else { |
| 1358 | __ cmpl(lhs.AsRegister<CpuRegister>(), Immediate(constant)); |
| 1359 | } |
| 1360 | } else { |
| 1361 | __ cmpl(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1362 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1363 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1364 | return; |
| 1365 | case Primitive::kPrimLong: |
| 1366 | // Clear output register: setcc only sets the low byte. |
| 1367 | __ xorl(reg, reg); |
| 1368 | |
| 1369 | if (rhs.IsRegister()) { |
| 1370 | __ cmpq(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1371 | } else if (rhs.IsConstant()) { |
| 1372 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
| 1373 | if (IsInt<32>(value)) { |
| 1374 | if (value == 0) { |
| 1375 | __ testq(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1376 | } else { |
| 1377 | __ cmpq(lhs.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 1378 | } |
| 1379 | } else { |
| 1380 | // Value won't fit in an int. |
| 1381 | __ cmpq(lhs.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 1382 | } |
| 1383 | } else { |
| 1384 | __ cmpq(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1385 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1386 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1387 | return; |
| 1388 | case Primitive::kPrimFloat: { |
| 1389 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1390 | if (rhs.IsConstant()) { |
| 1391 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 1392 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 1393 | } else if (rhs.IsStackSlot()) { |
| 1394 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1395 | } else { |
| 1396 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1397 | } |
| 1398 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1399 | break; |
| 1400 | } |
| 1401 | case Primitive::kPrimDouble: { |
| 1402 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1403 | if (rhs.IsConstant()) { |
| 1404 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1405 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 1406 | } else if (rhs.IsDoubleStackSlot()) { |
| 1407 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1408 | } else { |
| 1409 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1410 | } |
| 1411 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1412 | break; |
| 1413 | } |
| 1414 | } |
| 1415 | |
| 1416 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1417 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1418 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1419 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1420 | __ Bind(&false_label); |
| 1421 | __ xorl(reg, reg); |
| 1422 | __ jmp(&done_label); |
| 1423 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1424 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1425 | __ Bind(&true_label); |
| 1426 | __ movl(reg, Immediate(1)); |
| 1427 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
| 1431 | VisitCondition(comp); |
| 1432 | } |
| 1433 | |
| 1434 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
| 1435 | VisitCondition(comp); |
| 1436 | } |
| 1437 | |
| 1438 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
| 1439 | VisitCondition(comp); |
| 1440 | } |
| 1441 | |
| 1442 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
| 1443 | VisitCondition(comp); |
| 1444 | } |
| 1445 | |
| 1446 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
| 1447 | VisitCondition(comp); |
| 1448 | } |
| 1449 | |
| 1450 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
| 1451 | VisitCondition(comp); |
| 1452 | } |
| 1453 | |
| 1454 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1455 | VisitCondition(comp); |
| 1456 | } |
| 1457 | |
| 1458 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1459 | VisitCondition(comp); |
| 1460 | } |
| 1461 | |
| 1462 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| 1463 | VisitCondition(comp); |
| 1464 | } |
| 1465 | |
| 1466 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| 1467 | VisitCondition(comp); |
| 1468 | } |
| 1469 | |
| 1470 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1471 | VisitCondition(comp); |
| 1472 | } |
| 1473 | |
| 1474 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1475 | VisitCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1476 | } |
| 1477 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1478 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1479 | LocationSummary* locations = |
| 1480 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1481 | switch (compare->InputAt(0)->GetType()) { |
| 1482 | case Primitive::kPrimLong: { |
| 1483 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1484 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1485 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1486 | break; |
| 1487 | } |
| 1488 | case Primitive::kPrimFloat: |
| 1489 | case Primitive::kPrimDouble: { |
| 1490 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1491 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1492 | locations->SetOut(Location::RequiresRegister()); |
| 1493 | break; |
| 1494 | } |
| 1495 | default: |
| 1496 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 1497 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1498 | } |
| 1499 | |
| 1500 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1501 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1502 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1503 | Location left = locations->InAt(0); |
| 1504 | Location right = locations->InAt(1); |
| 1505 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1506 | NearLabel less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1507 | Primitive::Type type = compare->InputAt(0)->GetType(); |
| 1508 | switch (type) { |
| 1509 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1510 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1511 | if (right.IsConstant()) { |
| 1512 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1513 | if (IsInt<32>(value)) { |
| 1514 | if (value == 0) { |
| 1515 | __ testq(left_reg, left_reg); |
| 1516 | } else { |
| 1517 | __ cmpq(left_reg, Immediate(static_cast<int32_t>(value))); |
| 1518 | } |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1519 | } else { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1520 | // Value won't fit in an int. |
| 1521 | __ cmpq(left_reg, codegen_->LiteralInt64Address(value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1522 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1523 | } else if (right.IsDoubleStackSlot()) { |
| 1524 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1525 | } else { |
| 1526 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1527 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1528 | break; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1529 | } |
| 1530 | case Primitive::kPrimFloat: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1531 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1532 | if (right.IsConstant()) { |
| 1533 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 1534 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 1535 | } else if (right.IsStackSlot()) { |
| 1536 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1537 | } else { |
| 1538 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1539 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1540 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 1541 | break; |
| 1542 | } |
| 1543 | case Primitive::kPrimDouble: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1544 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1545 | if (right.IsConstant()) { |
| 1546 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1547 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 1548 | } else if (right.IsDoubleStackSlot()) { |
| 1549 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1550 | } else { |
| 1551 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1552 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1553 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 1554 | break; |
| 1555 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1556 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1557 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1558 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1559 | __ movl(out, Immediate(0)); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1560 | __ j(kEqual, &done); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1561 | __ 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] | 1562 | |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1563 | __ Bind(&greater); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1564 | __ movl(out, Immediate(1)); |
| 1565 | __ jmp(&done); |
| 1566 | |
| 1567 | __ Bind(&less); |
| 1568 | __ movl(out, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1569 | |
| 1570 | __ Bind(&done); |
| 1571 | } |
| 1572 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1573 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1574 | LocationSummary* locations = |
| 1575 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1576 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1580 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1581 | UNUSED(constant); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1582 | } |
| 1583 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1584 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 1585 | LocationSummary* locations = |
| 1586 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1587 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1588 | } |
| 1589 | |
| 1590 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant) { |
| 1591 | // Will be generated at use site. |
| 1592 | UNUSED(constant); |
| 1593 | } |
| 1594 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1595 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1596 | LocationSummary* locations = |
| 1597 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1598 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1599 | } |
| 1600 | |
| 1601 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1602 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1603 | UNUSED(constant); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1604 | } |
| 1605 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1606 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 1607 | LocationSummary* locations = |
| 1608 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1609 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1610 | } |
| 1611 | |
| 1612 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 1613 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1614 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1615 | } |
| 1616 | |
| 1617 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1618 | LocationSummary* locations = |
| 1619 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1620 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1621 | } |
| 1622 | |
| 1623 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1624 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1625 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1626 | } |
| 1627 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1628 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1629 | memory_barrier->SetLocations(nullptr); |
| 1630 | } |
| 1631 | |
| 1632 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1633 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 1634 | } |
| 1635 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1636 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 1637 | ret->SetLocations(nullptr); |
| 1638 | } |
| 1639 | |
| 1640 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1641 | UNUSED(ret); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1642 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1643 | } |
| 1644 | |
| 1645 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1646 | LocationSummary* locations = |
| 1647 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1648 | switch (ret->InputAt(0)->GetType()) { |
| 1649 | case Primitive::kPrimBoolean: |
| 1650 | case Primitive::kPrimByte: |
| 1651 | case Primitive::kPrimChar: |
| 1652 | case Primitive::kPrimShort: |
| 1653 | case Primitive::kPrimInt: |
| 1654 | case Primitive::kPrimNot: |
| 1655 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1656 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1657 | break; |
| 1658 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1659 | case Primitive::kPrimFloat: |
| 1660 | case Primitive::kPrimDouble: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1661 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1662 | break; |
| 1663 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1664 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1665 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1666 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1667 | } |
| 1668 | |
| 1669 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 1670 | if (kIsDebugBuild) { |
| 1671 | switch (ret->InputAt(0)->GetType()) { |
| 1672 | case Primitive::kPrimBoolean: |
| 1673 | case Primitive::kPrimByte: |
| 1674 | case Primitive::kPrimChar: |
| 1675 | case Primitive::kPrimShort: |
| 1676 | case Primitive::kPrimInt: |
| 1677 | case Primitive::kPrimNot: |
| 1678 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1679 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1680 | break; |
| 1681 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1682 | case Primitive::kPrimFloat: |
| 1683 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1684 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1685 | XMM0); |
| 1686 | break; |
| 1687 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1688 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1689 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1690 | } |
| 1691 | } |
| 1692 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1693 | } |
| 1694 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1695 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(Primitive::Type type) const { |
| 1696 | switch (type) { |
| 1697 | case Primitive::kPrimBoolean: |
| 1698 | case Primitive::kPrimByte: |
| 1699 | case Primitive::kPrimChar: |
| 1700 | case Primitive::kPrimShort: |
| 1701 | case Primitive::kPrimInt: |
| 1702 | case Primitive::kPrimNot: |
| 1703 | case Primitive::kPrimLong: |
| 1704 | return Location::RegisterLocation(RAX); |
| 1705 | |
| 1706 | case Primitive::kPrimVoid: |
| 1707 | return Location::NoLocation(); |
| 1708 | |
| 1709 | case Primitive::kPrimDouble: |
| 1710 | case Primitive::kPrimFloat: |
| 1711 | return Location::FpuRegisterLocation(XMM0); |
| 1712 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1713 | |
| 1714 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 1718 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1719 | } |
| 1720 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1721 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1722 | switch (type) { |
| 1723 | case Primitive::kPrimBoolean: |
| 1724 | case Primitive::kPrimByte: |
| 1725 | case Primitive::kPrimChar: |
| 1726 | case Primitive::kPrimShort: |
| 1727 | case Primitive::kPrimInt: |
| 1728 | case Primitive::kPrimNot: { |
| 1729 | uint32_t index = gp_index_++; |
| 1730 | stack_index_++; |
| 1731 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1732 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1733 | } else { |
| 1734 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1735 | } |
| 1736 | } |
| 1737 | |
| 1738 | case Primitive::kPrimLong: { |
| 1739 | uint32_t index = gp_index_; |
| 1740 | stack_index_ += 2; |
| 1741 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 1742 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1743 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1744 | } else { |
| 1745 | gp_index_ += 2; |
| 1746 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1747 | } |
| 1748 | } |
| 1749 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1750 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1751 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1752 | stack_index_++; |
| 1753 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1754 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1755 | } else { |
| 1756 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1757 | } |
| 1758 | } |
| 1759 | |
| 1760 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1761 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1762 | stack_index_ += 2; |
| 1763 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1764 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1765 | } else { |
| 1766 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1767 | } |
| 1768 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1769 | |
| 1770 | case Primitive::kPrimVoid: |
| 1771 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1772 | break; |
| 1773 | } |
| 1774 | return Location(); |
| 1775 | } |
| 1776 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1777 | void LocationsBuilderX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1778 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1779 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1780 | // the method_idx. |
| 1781 | HandleInvoke(invoke); |
| 1782 | } |
| 1783 | |
| 1784 | void InstructionCodeGeneratorX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1785 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1786 | } |
| 1787 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1788 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1789 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1790 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1791 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1792 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1793 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1794 | if (intrinsic.TryDispatch(invoke)) { |
| 1795 | return; |
| 1796 | } |
| 1797 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1798 | HandleInvoke(invoke); |
| 1799 | } |
| 1800 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1801 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 1802 | if (invoke->GetLocations()->Intrinsified()) { |
| 1803 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 1804 | intrinsic.Dispatch(invoke); |
| 1805 | return true; |
| 1806 | } |
| 1807 | return false; |
| 1808 | } |
| 1809 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1810 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1811 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1812 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1813 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1814 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1815 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1816 | return; |
| 1817 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1818 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1819 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1820 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1821 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 1822 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1823 | } |
| 1824 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1825 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1826 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1827 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1828 | } |
| 1829 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1830 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1831 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1832 | if (intrinsic.TryDispatch(invoke)) { |
| 1833 | return; |
| 1834 | } |
| 1835 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1836 | HandleInvoke(invoke); |
| 1837 | } |
| 1838 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1839 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1840 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1841 | return; |
| 1842 | } |
| 1843 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1844 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1845 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1846 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1847 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1848 | } |
| 1849 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1850 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1851 | HandleInvoke(invoke); |
| 1852 | // Add the hidden argument. |
| 1853 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 1854 | } |
| 1855 | |
| 1856 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1857 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1858 | CpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1859 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 1860 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86_64PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1861 | LocationSummary* locations = invoke->GetLocations(); |
| 1862 | Location receiver = locations->InAt(0); |
| 1863 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 1864 | |
| 1865 | // Set the hidden argument. |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 1866 | CpuRegister hidden_reg = invoke->GetLocations()->GetTemp(1).AsRegister<CpuRegister>(); |
| 1867 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1868 | |
| 1869 | // temp = object->GetClass(); |
| 1870 | if (receiver.IsStackSlot()) { |
| 1871 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
| 1872 | __ movl(temp, Address(temp, class_offset)); |
| 1873 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1874 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1875 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1876 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1877 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1878 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1879 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1880 | // call temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1881 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1882 | kX86_64WordSize).SizeValue())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1883 | |
| 1884 | DCHECK(!codegen_->IsLeafMethod()); |
| 1885 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1886 | } |
| 1887 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1888 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 1889 | LocationSummary* locations = |
| 1890 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1891 | switch (neg->GetResultType()) { |
| 1892 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1893 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1894 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1895 | locations->SetOut(Location::SameAsFirstInput()); |
| 1896 | break; |
| 1897 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1898 | case Primitive::kPrimFloat: |
| 1899 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1900 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1901 | locations->SetOut(Location::SameAsFirstInput()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1902 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1903 | break; |
| 1904 | |
| 1905 | default: |
| 1906 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1907 | } |
| 1908 | } |
| 1909 | |
| 1910 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 1911 | LocationSummary* locations = neg->GetLocations(); |
| 1912 | Location out = locations->Out(); |
| 1913 | Location in = locations->InAt(0); |
| 1914 | switch (neg->GetResultType()) { |
| 1915 | case Primitive::kPrimInt: |
| 1916 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1917 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1918 | __ negl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1919 | break; |
| 1920 | |
| 1921 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1922 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1923 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1924 | __ negq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1925 | break; |
| 1926 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1927 | case Primitive::kPrimFloat: { |
| 1928 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1929 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1930 | // Implement float negation with an exclusive or with value |
| 1931 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 1932 | // single-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1933 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1934 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1935 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1936 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1937 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1938 | case Primitive::kPrimDouble: { |
| 1939 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1940 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1941 | // Implement double negation with an exclusive or with value |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1942 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1943 | // a double-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1944 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1945 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1946 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1947 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1948 | |
| 1949 | default: |
| 1950 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1951 | } |
| 1952 | } |
| 1953 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1954 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 1955 | LocationSummary* locations = |
| 1956 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 1957 | Primitive::Type result_type = conversion->GetResultType(); |
| 1958 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1959 | DCHECK_NE(result_type, input_type); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1960 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1961 | // The Java language does not allow treating boolean as an integral type but |
| 1962 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1963 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1964 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1965 | case Primitive::kPrimByte: |
| 1966 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1967 | case Primitive::kPrimBoolean: |
| 1968 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1969 | case Primitive::kPrimShort: |
| 1970 | case Primitive::kPrimInt: |
| 1971 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1972 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1973 | locations->SetInAt(0, Location::Any()); |
| 1974 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1975 | break; |
| 1976 | |
| 1977 | default: |
| 1978 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1979 | << " to " << result_type; |
| 1980 | } |
| 1981 | break; |
| 1982 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1983 | case Primitive::kPrimShort: |
| 1984 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1985 | case Primitive::kPrimBoolean: |
| 1986 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1987 | case Primitive::kPrimByte: |
| 1988 | case Primitive::kPrimInt: |
| 1989 | case Primitive::kPrimChar: |
| 1990 | // Processing a Dex `int-to-short' instruction. |
| 1991 | locations->SetInAt(0, Location::Any()); |
| 1992 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1993 | break; |
| 1994 | |
| 1995 | default: |
| 1996 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1997 | << " to " << result_type; |
| 1998 | } |
| 1999 | break; |
| 2000 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2001 | case Primitive::kPrimInt: |
| 2002 | switch (input_type) { |
| 2003 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2004 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2005 | locations->SetInAt(0, Location::Any()); |
| 2006 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2007 | break; |
| 2008 | |
| 2009 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2010 | // Processing a Dex `float-to-int' instruction. |
| 2011 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2012 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2013 | break; |
| 2014 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2015 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2016 | // Processing a Dex `double-to-int' instruction. |
| 2017 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2018 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2019 | break; |
| 2020 | |
| 2021 | default: |
| 2022 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2023 | << " to " << result_type; |
| 2024 | } |
| 2025 | break; |
| 2026 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2027 | case Primitive::kPrimLong: |
| 2028 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2029 | case Primitive::kPrimBoolean: |
| 2030 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2031 | case Primitive::kPrimByte: |
| 2032 | case Primitive::kPrimShort: |
| 2033 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2034 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2035 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2036 | // TODO: We would benefit from a (to-be-implemented) |
| 2037 | // Location::RegisterOrStackSlot requirement for this input. |
| 2038 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2039 | locations->SetOut(Location::RequiresRegister()); |
| 2040 | break; |
| 2041 | |
| 2042 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2043 | // Processing a Dex `float-to-long' instruction. |
| 2044 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2045 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2046 | break; |
| 2047 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2048 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2049 | // Processing a Dex `double-to-long' instruction. |
| 2050 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2051 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2052 | break; |
| 2053 | |
| 2054 | default: |
| 2055 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2056 | << " to " << result_type; |
| 2057 | } |
| 2058 | break; |
| 2059 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2060 | case Primitive::kPrimChar: |
| 2061 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2062 | case Primitive::kPrimBoolean: |
| 2063 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2064 | case Primitive::kPrimByte: |
| 2065 | case Primitive::kPrimShort: |
| 2066 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2067 | // Processing a Dex `int-to-char' instruction. |
| 2068 | locations->SetInAt(0, Location::Any()); |
| 2069 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2070 | break; |
| 2071 | |
| 2072 | default: |
| 2073 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2074 | << " to " << result_type; |
| 2075 | } |
| 2076 | break; |
| 2077 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2078 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2079 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2080 | case Primitive::kPrimBoolean: |
| 2081 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2082 | case Primitive::kPrimByte: |
| 2083 | case Primitive::kPrimShort: |
| 2084 | case Primitive::kPrimInt: |
| 2085 | case Primitive::kPrimChar: |
| 2086 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2087 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2088 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2089 | break; |
| 2090 | |
| 2091 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2092 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2093 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2094 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2095 | break; |
| 2096 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2097 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2098 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2099 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2100 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2101 | break; |
| 2102 | |
| 2103 | default: |
| 2104 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2105 | << " to " << result_type; |
| 2106 | }; |
| 2107 | break; |
| 2108 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2109 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2110 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2111 | case Primitive::kPrimBoolean: |
| 2112 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2113 | case Primitive::kPrimByte: |
| 2114 | case Primitive::kPrimShort: |
| 2115 | case Primitive::kPrimInt: |
| 2116 | case Primitive::kPrimChar: |
| 2117 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2118 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2119 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2120 | break; |
| 2121 | |
| 2122 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2123 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2124 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2125 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2126 | break; |
| 2127 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2128 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2129 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2130 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2131 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2132 | break; |
| 2133 | |
| 2134 | default: |
| 2135 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2136 | << " to " << result_type; |
| 2137 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2138 | break; |
| 2139 | |
| 2140 | default: |
| 2141 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2142 | << " to " << result_type; |
| 2143 | } |
| 2144 | } |
| 2145 | |
| 2146 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2147 | LocationSummary* locations = conversion->GetLocations(); |
| 2148 | Location out = locations->Out(); |
| 2149 | Location in = locations->InAt(0); |
| 2150 | Primitive::Type result_type = conversion->GetResultType(); |
| 2151 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2152 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2153 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2154 | case Primitive::kPrimByte: |
| 2155 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2156 | case Primitive::kPrimBoolean: |
| 2157 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2158 | case Primitive::kPrimShort: |
| 2159 | case Primitive::kPrimInt: |
| 2160 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2161 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2162 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2163 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2164 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2165 | __ movsxb(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2166 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2167 | } else { |
| 2168 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2169 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2170 | Immediate(static_cast<int8_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2171 | } |
| 2172 | break; |
| 2173 | |
| 2174 | default: |
| 2175 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2176 | << " to " << result_type; |
| 2177 | } |
| 2178 | break; |
| 2179 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2180 | case Primitive::kPrimShort: |
| 2181 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2182 | case Primitive::kPrimBoolean: |
| 2183 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2184 | case Primitive::kPrimByte: |
| 2185 | case Primitive::kPrimInt: |
| 2186 | case Primitive::kPrimChar: |
| 2187 | // Processing a Dex `int-to-short' instruction. |
| 2188 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2189 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2190 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2191 | __ movsxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2192 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2193 | } else { |
| 2194 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2195 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2196 | Immediate(static_cast<int16_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2197 | } |
| 2198 | break; |
| 2199 | |
| 2200 | default: |
| 2201 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2202 | << " to " << result_type; |
| 2203 | } |
| 2204 | break; |
| 2205 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2206 | case Primitive::kPrimInt: |
| 2207 | switch (input_type) { |
| 2208 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2209 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2210 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2211 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2212 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2213 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2214 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2215 | } else { |
| 2216 | DCHECK(in.IsConstant()); |
| 2217 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2218 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2219 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2220 | } |
| 2221 | break; |
| 2222 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2223 | case Primitive::kPrimFloat: { |
| 2224 | // Processing a Dex `float-to-int' instruction. |
| 2225 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2226 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2227 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2228 | |
| 2229 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2230 | // if input >= (float)INT_MAX goto done |
| 2231 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimIntMax)); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2232 | __ j(kAboveEqual, &done); |
| 2233 | // if input == NaN goto nan |
| 2234 | __ j(kUnordered, &nan); |
| 2235 | // output = float-to-int-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2236 | __ cvttss2si(output, input, false); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2237 | __ jmp(&done); |
| 2238 | __ Bind(&nan); |
| 2239 | // output = 0 |
| 2240 | __ xorl(output, output); |
| 2241 | __ Bind(&done); |
| 2242 | break; |
| 2243 | } |
| 2244 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2245 | case Primitive::kPrimDouble: { |
| 2246 | // Processing a Dex `double-to-int' instruction. |
| 2247 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2248 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2249 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2250 | |
| 2251 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2252 | // if input >= (double)INT_MAX goto done |
| 2253 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2254 | __ j(kAboveEqual, &done); |
| 2255 | // if input == NaN goto nan |
| 2256 | __ j(kUnordered, &nan); |
| 2257 | // output = double-to-int-truncate(input) |
| 2258 | __ cvttsd2si(output, input); |
| 2259 | __ jmp(&done); |
| 2260 | __ Bind(&nan); |
| 2261 | // output = 0 |
| 2262 | __ xorl(output, output); |
| 2263 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2264 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2265 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2266 | |
| 2267 | default: |
| 2268 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2269 | << " to " << result_type; |
| 2270 | } |
| 2271 | break; |
| 2272 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2273 | case Primitive::kPrimLong: |
| 2274 | switch (input_type) { |
| 2275 | DCHECK(out.IsRegister()); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2276 | case Primitive::kPrimBoolean: |
| 2277 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2278 | case Primitive::kPrimByte: |
| 2279 | case Primitive::kPrimShort: |
| 2280 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2281 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2282 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2283 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2284 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2285 | break; |
| 2286 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2287 | case Primitive::kPrimFloat: { |
| 2288 | // Processing a Dex `float-to-long' instruction. |
| 2289 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2290 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2291 | NearLabel done, nan; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2292 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2293 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2294 | // if input >= (float)LONG_MAX goto done |
| 2295 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimLongMax)); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2296 | __ j(kAboveEqual, &done); |
| 2297 | // if input == NaN goto nan |
| 2298 | __ j(kUnordered, &nan); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2299 | // output = float-to-long-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2300 | __ cvttss2si(output, input, true); |
| 2301 | __ jmp(&done); |
| 2302 | __ Bind(&nan); |
| 2303 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2304 | __ xorl(output, output); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2305 | __ Bind(&done); |
| 2306 | break; |
| 2307 | } |
| 2308 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2309 | case Primitive::kPrimDouble: { |
| 2310 | // Processing a Dex `double-to-long' instruction. |
| 2311 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2312 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2313 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2314 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2315 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2316 | // if input >= (double)LONG_MAX goto done |
| 2317 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimLongMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2318 | __ j(kAboveEqual, &done); |
| 2319 | // if input == NaN goto nan |
| 2320 | __ j(kUnordered, &nan); |
| 2321 | // output = double-to-long-truncate(input) |
| 2322 | __ cvttsd2si(output, input, true); |
| 2323 | __ jmp(&done); |
| 2324 | __ Bind(&nan); |
| 2325 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2326 | __ xorl(output, output); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2327 | __ Bind(&done); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2328 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2329 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2330 | |
| 2331 | default: |
| 2332 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2333 | << " to " << result_type; |
| 2334 | } |
| 2335 | break; |
| 2336 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2337 | case Primitive::kPrimChar: |
| 2338 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2339 | case Primitive::kPrimBoolean: |
| 2340 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2341 | case Primitive::kPrimByte: |
| 2342 | case Primitive::kPrimShort: |
| 2343 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2344 | // Processing a Dex `int-to-char' instruction. |
| 2345 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2346 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2347 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2348 | __ movzxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2349 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2350 | } else { |
| 2351 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2352 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2353 | Immediate(static_cast<uint16_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2354 | } |
| 2355 | break; |
| 2356 | |
| 2357 | default: |
| 2358 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2359 | << " to " << result_type; |
| 2360 | } |
| 2361 | break; |
| 2362 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2363 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2364 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2365 | case Primitive::kPrimBoolean: |
| 2366 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2367 | case Primitive::kPrimByte: |
| 2368 | case Primitive::kPrimShort: |
| 2369 | case Primitive::kPrimInt: |
| 2370 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2371 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2372 | if (in.IsRegister()) { |
| 2373 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2374 | } else if (in.IsConstant()) { |
| 2375 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2376 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2377 | if (v == 0) { |
| 2378 | __ xorps(dest, dest); |
| 2379 | } else { |
| 2380 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2381 | } |
| 2382 | } else { |
| 2383 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2384 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2385 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2386 | break; |
| 2387 | |
| 2388 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2389 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2390 | if (in.IsRegister()) { |
| 2391 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2392 | } else if (in.IsConstant()) { |
| 2393 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2394 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2395 | if (v == 0) { |
| 2396 | __ xorps(dest, dest); |
| 2397 | } else { |
| 2398 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2399 | } |
| 2400 | } else { |
| 2401 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2402 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2403 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2404 | break; |
| 2405 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2406 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2407 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2408 | if (in.IsFpuRegister()) { |
| 2409 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2410 | } else if (in.IsConstant()) { |
| 2411 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2412 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2413 | if (bit_cast<int64_t, double>(v) == 0) { |
| 2414 | __ xorps(dest, dest); |
| 2415 | } else { |
| 2416 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2417 | } |
| 2418 | } else { |
| 2419 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 2420 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2421 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2422 | break; |
| 2423 | |
| 2424 | default: |
| 2425 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2426 | << " to " << result_type; |
| 2427 | }; |
| 2428 | break; |
| 2429 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2430 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2431 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2432 | case Primitive::kPrimBoolean: |
| 2433 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2434 | case Primitive::kPrimByte: |
| 2435 | case Primitive::kPrimShort: |
| 2436 | case Primitive::kPrimInt: |
| 2437 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2438 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2439 | if (in.IsRegister()) { |
| 2440 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2441 | } else if (in.IsConstant()) { |
| 2442 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2443 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2444 | if (v == 0) { |
| 2445 | __ xorpd(dest, dest); |
| 2446 | } else { |
| 2447 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2448 | } |
| 2449 | } else { |
| 2450 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2451 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2452 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2453 | break; |
| 2454 | |
| 2455 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2456 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2457 | if (in.IsRegister()) { |
| 2458 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2459 | } else if (in.IsConstant()) { |
| 2460 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2461 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2462 | if (v == 0) { |
| 2463 | __ xorpd(dest, dest); |
| 2464 | } else { |
| 2465 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2466 | } |
| 2467 | } else { |
| 2468 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2469 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2470 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2471 | break; |
| 2472 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2473 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2474 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2475 | if (in.IsFpuRegister()) { |
| 2476 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2477 | } else if (in.IsConstant()) { |
| 2478 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 2479 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2480 | if (bit_cast<int32_t, float>(v) == 0) { |
| 2481 | __ xorpd(dest, dest); |
| 2482 | } else { |
| 2483 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2484 | } |
| 2485 | } else { |
| 2486 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 2487 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2488 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2489 | break; |
| 2490 | |
| 2491 | default: |
| 2492 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2493 | << " to " << result_type; |
| 2494 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2495 | break; |
| 2496 | |
| 2497 | default: |
| 2498 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2499 | << " to " << result_type; |
| 2500 | } |
| 2501 | } |
| 2502 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2503 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2504 | LocationSummary* locations = |
| 2505 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2506 | switch (add->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2507 | case Primitive::kPrimInt: { |
| 2508 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2509 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2510 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2511 | break; |
| 2512 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2513 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2514 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2515 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2516 | // We can use a leaq or addq if the constant can fit in an immediate. |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2517 | locations->SetInAt(1, Location::RegisterOrInt32LongConstant(add->InputAt(1))); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2518 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2519 | break; |
| 2520 | } |
| 2521 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2522 | case Primitive::kPrimDouble: |
| 2523 | case Primitive::kPrimFloat: { |
| 2524 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2525 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2526 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2527 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2528 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2529 | |
| 2530 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2531 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2532 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2533 | } |
| 2534 | |
| 2535 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 2536 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2537 | Location first = locations->InAt(0); |
| 2538 | Location second = locations->InAt(1); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2539 | Location out = locations->Out(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2540 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2541 | switch (add->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2542 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2543 | if (second.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2544 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2545 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2546 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2547 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2548 | } else { |
| 2549 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2550 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2551 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2552 | } else if (second.IsConstant()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2553 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2554 | __ addl(out.AsRegister<CpuRegister>(), |
| 2555 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 2556 | } else { |
| 2557 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2558 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 2559 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2560 | } else { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2561 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2562 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2563 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2564 | break; |
| 2565 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2566 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2567 | case Primitive::kPrimLong: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2568 | if (second.IsRegister()) { |
| 2569 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2570 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2571 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2572 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2573 | } else { |
| 2574 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2575 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2576 | } |
| 2577 | } else { |
| 2578 | DCHECK(second.IsConstant()); |
| 2579 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2580 | int32_t int32_value = Low32Bits(value); |
| 2581 | DCHECK_EQ(int32_value, value); |
| 2582 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2583 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 2584 | } else { |
| 2585 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2586 | first.AsRegister<CpuRegister>(), int32_value)); |
| 2587 | } |
| 2588 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2589 | break; |
| 2590 | } |
| 2591 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2592 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2593 | if (second.IsFpuRegister()) { |
| 2594 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2595 | } else if (second.IsConstant()) { |
| 2596 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2597 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 2598 | } else { |
| 2599 | DCHECK(second.IsStackSlot()); |
| 2600 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2601 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2602 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2603 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2604 | } |
| 2605 | |
| 2606 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2607 | if (second.IsFpuRegister()) { |
| 2608 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2609 | } else if (second.IsConstant()) { |
| 2610 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2611 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 2612 | } else { |
| 2613 | DCHECK(second.IsDoubleStackSlot()); |
| 2614 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2615 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2616 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2617 | break; |
| 2618 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2619 | |
| 2620 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2621 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2622 | } |
| 2623 | } |
| 2624 | |
| 2625 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2626 | LocationSummary* locations = |
| 2627 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2628 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2629 | case Primitive::kPrimInt: { |
| 2630 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2631 | locations->SetInAt(1, Location::Any()); |
| 2632 | locations->SetOut(Location::SameAsFirstInput()); |
| 2633 | break; |
| 2634 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2635 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2636 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2637 | locations->SetInAt(1, Location::RegisterOrInt32LongConstant(sub->InputAt(1))); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2638 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2639 | break; |
| 2640 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2641 | case Primitive::kPrimFloat: |
| 2642 | case Primitive::kPrimDouble: { |
| 2643 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2644 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2645 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2646 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2647 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2648 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2649 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2650 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2651 | } |
| 2652 | |
| 2653 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 2654 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2655 | Location first = locations->InAt(0); |
| 2656 | Location second = locations->InAt(1); |
| 2657 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2658 | switch (sub->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2659 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2660 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2661 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2662 | } else if (second.IsConstant()) { |
| 2663 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2664 | __ subl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2665 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2666 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2667 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2668 | break; |
| 2669 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2670 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2671 | if (second.IsConstant()) { |
| 2672 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2673 | DCHECK(IsInt<32>(value)); |
| 2674 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 2675 | } else { |
| 2676 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 2677 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2678 | break; |
| 2679 | } |
| 2680 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2681 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2682 | if (second.IsFpuRegister()) { |
| 2683 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2684 | } else if (second.IsConstant()) { |
| 2685 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2686 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 2687 | } else { |
| 2688 | DCHECK(second.IsStackSlot()); |
| 2689 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2690 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2691 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2692 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2693 | } |
| 2694 | |
| 2695 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2696 | if (second.IsFpuRegister()) { |
| 2697 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2698 | } else if (second.IsConstant()) { |
| 2699 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2700 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 2701 | } else { |
| 2702 | DCHECK(second.IsDoubleStackSlot()); |
| 2703 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2704 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2705 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2706 | break; |
| 2707 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2708 | |
| 2709 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2710 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2711 | } |
| 2712 | } |
| 2713 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2714 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 2715 | LocationSummary* locations = |
| 2716 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2717 | switch (mul->GetResultType()) { |
| 2718 | case Primitive::kPrimInt: { |
| 2719 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2720 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2721 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2722 | // Can use 3 operand multiply. |
| 2723 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2724 | } else { |
| 2725 | locations->SetOut(Location::SameAsFirstInput()); |
| 2726 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2727 | break; |
| 2728 | } |
| 2729 | case Primitive::kPrimLong: { |
| 2730 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2731 | locations->SetInAt(1, Location::Any()); |
| 2732 | if (mul->InputAt(1)->IsLongConstant() && |
| 2733 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2734 | // Can use 3 operand multiply. |
| 2735 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2736 | } else { |
| 2737 | locations->SetOut(Location::SameAsFirstInput()); |
| 2738 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2739 | break; |
| 2740 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2741 | case Primitive::kPrimFloat: |
| 2742 | case Primitive::kPrimDouble: { |
| 2743 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2744 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2745 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2746 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2747 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2748 | |
| 2749 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2750 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2751 | } |
| 2752 | } |
| 2753 | |
| 2754 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 2755 | LocationSummary* locations = mul->GetLocations(); |
| 2756 | Location first = locations->InAt(0); |
| 2757 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2758 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2759 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2760 | case Primitive::kPrimInt: |
| 2761 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2762 | // problems where the output may not be the same as the first operand. |
| 2763 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2764 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 2765 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 2766 | } else if (second.IsRegister()) { |
| 2767 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2768 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2769 | } else { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2770 | DCHECK(first.Equals(out)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2771 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2772 | __ imull(first.AsRegister<CpuRegister>(), |
| 2773 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2774 | } |
| 2775 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2776 | case Primitive::kPrimLong: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2777 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2778 | // problems where the output may not be the same as the first operand. |
| 2779 | if (mul->InputAt(1)->IsLongConstant()) { |
| 2780 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 2781 | if (IsInt<32>(value)) { |
| 2782 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 2783 | Immediate(static_cast<int32_t>(value))); |
| 2784 | } else { |
| 2785 | // Have to use the constant area. |
| 2786 | DCHECK(first.Equals(out)); |
| 2787 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 2788 | } |
| 2789 | } else if (second.IsRegister()) { |
| 2790 | DCHECK(first.Equals(out)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2791 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2792 | } else { |
| 2793 | DCHECK(second.IsDoubleStackSlot()); |
| 2794 | DCHECK(first.Equals(out)); |
| 2795 | __ imulq(first.AsRegister<CpuRegister>(), |
| 2796 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2797 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2798 | break; |
| 2799 | } |
| 2800 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2801 | case Primitive::kPrimFloat: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2802 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2803 | if (second.IsFpuRegister()) { |
| 2804 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2805 | } else if (second.IsConstant()) { |
| 2806 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 2807 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 2808 | } else { |
| 2809 | DCHECK(second.IsStackSlot()); |
| 2810 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 2811 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2812 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2813 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2814 | } |
| 2815 | |
| 2816 | case Primitive::kPrimDouble: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2817 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2818 | if (second.IsFpuRegister()) { |
| 2819 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2820 | } else if (second.IsConstant()) { |
| 2821 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 2822 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 2823 | } else { |
| 2824 | DCHECK(second.IsDoubleStackSlot()); |
| 2825 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 2826 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2827 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2828 | break; |
| 2829 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2830 | |
| 2831 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2832 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2833 | } |
| 2834 | } |
| 2835 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2836 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 2837 | uint32_t stack_adjustment, bool is_float) { |
| 2838 | if (source.IsStackSlot()) { |
| 2839 | DCHECK(is_float); |
| 2840 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 2841 | } else if (source.IsDoubleStackSlot()) { |
| 2842 | DCHECK(!is_float); |
| 2843 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 2844 | } else { |
| 2845 | // Write the value to the temporary location on the stack and load to FP stack. |
| 2846 | if (is_float) { |
| 2847 | Location stack_temp = Location::StackSlot(temp_offset); |
| 2848 | codegen_->Move(stack_temp, source); |
| 2849 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 2850 | } else { |
| 2851 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 2852 | codegen_->Move(stack_temp, source); |
| 2853 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 2854 | } |
| 2855 | } |
| 2856 | } |
| 2857 | |
| 2858 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| 2859 | Primitive::Type type = rem->GetResultType(); |
| 2860 | bool is_float = type == Primitive::kPrimFloat; |
| 2861 | size_t elem_size = Primitive::ComponentSize(type); |
| 2862 | LocationSummary* locations = rem->GetLocations(); |
| 2863 | Location first = locations->InAt(0); |
| 2864 | Location second = locations->InAt(1); |
| 2865 | Location out = locations->Out(); |
| 2866 | |
| 2867 | // Create stack space for 2 elements. |
| 2868 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2869 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 2870 | |
| 2871 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 2872 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 2873 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 2874 | |
| 2875 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2876 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2877 | __ Bind(&retry); |
| 2878 | __ fprem(); |
| 2879 | |
| 2880 | // Move FP status to AX. |
| 2881 | __ fstsw(); |
| 2882 | |
| 2883 | // And see if the argument reduction is complete. This is signaled by the |
| 2884 | // C2 FPU flag bit set to 0. |
| 2885 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 2886 | __ j(kNotEqual, &retry); |
| 2887 | |
| 2888 | // We have settled on the final value. Retrieve it into an XMM register. |
| 2889 | // Store FP top of stack to real stack. |
| 2890 | if (is_float) { |
| 2891 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 2892 | } else { |
| 2893 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 2894 | } |
| 2895 | |
| 2896 | // Pop the 2 items from the FP stack. |
| 2897 | __ fucompp(); |
| 2898 | |
| 2899 | // Load the value from the stack into an XMM register. |
| 2900 | DCHECK(out.IsFpuRegister()) << out; |
| 2901 | if (is_float) { |
| 2902 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 2903 | } else { |
| 2904 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 2905 | } |
| 2906 | |
| 2907 | // And remove the temporary stack space we allocated. |
| 2908 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 2909 | } |
| 2910 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2911 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2912 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2913 | |
| 2914 | LocationSummary* locations = instruction->GetLocations(); |
| 2915 | Location second = locations->InAt(1); |
| 2916 | DCHECK(second.IsConstant()); |
| 2917 | |
| 2918 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 2919 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2920 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2921 | |
| 2922 | DCHECK(imm == 1 || imm == -1); |
| 2923 | |
| 2924 | switch (instruction->GetResultType()) { |
| 2925 | case Primitive::kPrimInt: { |
| 2926 | if (instruction->IsRem()) { |
| 2927 | __ xorl(output_register, output_register); |
| 2928 | } else { |
| 2929 | __ movl(output_register, input_register); |
| 2930 | if (imm == -1) { |
| 2931 | __ negl(output_register); |
| 2932 | } |
| 2933 | } |
| 2934 | break; |
| 2935 | } |
| 2936 | |
| 2937 | case Primitive::kPrimLong: { |
| 2938 | if (instruction->IsRem()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2939 | __ xorl(output_register, output_register); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2940 | } else { |
| 2941 | __ movq(output_register, input_register); |
| 2942 | if (imm == -1) { |
| 2943 | __ negq(output_register); |
| 2944 | } |
| 2945 | } |
| 2946 | break; |
| 2947 | } |
| 2948 | |
| 2949 | default: |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2950 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2951 | } |
| 2952 | } |
| 2953 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2954 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2955 | LocationSummary* locations = instruction->GetLocations(); |
| 2956 | Location second = locations->InAt(1); |
| 2957 | |
| 2958 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 2959 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 2960 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2961 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2962 | |
| 2963 | DCHECK(IsPowerOfTwo(std::abs(imm))); |
| 2964 | |
| 2965 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2966 | |
| 2967 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 2968 | __ leal(tmp, Address(numerator, std::abs(imm) - 1)); |
| 2969 | __ testl(numerator, numerator); |
| 2970 | __ cmov(kGreaterEqual, tmp, numerator); |
| 2971 | int shift = CTZ(imm); |
| 2972 | __ sarl(tmp, Immediate(shift)); |
| 2973 | |
| 2974 | if (imm < 0) { |
| 2975 | __ negl(tmp); |
| 2976 | } |
| 2977 | |
| 2978 | __ movl(output_register, tmp); |
| 2979 | } else { |
| 2980 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 2981 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2982 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2983 | codegen_->Load64BitValue(rdx, std::abs(imm) - 1); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2984 | __ addq(rdx, numerator); |
| 2985 | __ testq(numerator, numerator); |
| 2986 | __ cmov(kGreaterEqual, rdx, numerator); |
| 2987 | int shift = CTZ(imm); |
| 2988 | __ sarq(rdx, Immediate(shift)); |
| 2989 | |
| 2990 | if (imm < 0) { |
| 2991 | __ negq(rdx); |
| 2992 | } |
| 2993 | |
| 2994 | __ movq(output_register, rdx); |
| 2995 | } |
| 2996 | } |
| 2997 | |
| 2998 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2999 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3000 | |
| 3001 | LocationSummary* locations = instruction->GetLocations(); |
| 3002 | Location second = locations->InAt(1); |
| 3003 | |
| 3004 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 3005 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3006 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3007 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 3008 | : locations->Out().AsRegister<CpuRegister>(); |
| 3009 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3010 | |
| 3011 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 3012 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 3013 | if (instruction->IsDiv()) { |
| 3014 | DCHECK_EQ(RAX, out.AsRegister()); |
| 3015 | } else { |
| 3016 | DCHECK_EQ(RDX, out.AsRegister()); |
| 3017 | } |
| 3018 | |
| 3019 | int64_t magic; |
| 3020 | int shift; |
| 3021 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3022 | // TODO: can these branches be written as one? |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3023 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 3024 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3025 | |
| 3026 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3027 | |
| 3028 | __ movl(numerator, eax); |
| 3029 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3030 | NearLabel no_div; |
| 3031 | NearLabel end; |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3032 | __ testl(eax, eax); |
| 3033 | __ j(kNotEqual, &no_div); |
| 3034 | |
| 3035 | __ xorl(out, out); |
| 3036 | __ jmp(&end); |
| 3037 | |
| 3038 | __ Bind(&no_div); |
| 3039 | |
| 3040 | __ movl(eax, Immediate(magic)); |
| 3041 | __ imull(numerator); |
| 3042 | |
| 3043 | if (imm > 0 && magic < 0) { |
| 3044 | __ addl(edx, numerator); |
| 3045 | } else if (imm < 0 && magic > 0) { |
| 3046 | __ subl(edx, numerator); |
| 3047 | } |
| 3048 | |
| 3049 | if (shift != 0) { |
| 3050 | __ sarl(edx, Immediate(shift)); |
| 3051 | } |
| 3052 | |
| 3053 | __ movl(eax, edx); |
| 3054 | __ shrl(edx, Immediate(31)); |
| 3055 | __ addl(edx, eax); |
| 3056 | |
| 3057 | if (instruction->IsRem()) { |
| 3058 | __ movl(eax, numerator); |
| 3059 | __ imull(edx, Immediate(imm)); |
| 3060 | __ subl(eax, edx); |
| 3061 | __ movl(edx, eax); |
| 3062 | } else { |
| 3063 | __ movl(eax, edx); |
| 3064 | } |
| 3065 | __ Bind(&end); |
| 3066 | } else { |
| 3067 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3068 | |
| 3069 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3070 | |
| 3071 | CpuRegister rax = eax; |
| 3072 | CpuRegister rdx = edx; |
| 3073 | |
| 3074 | CalculateMagicAndShiftForDivRem(imm, true /* is_long */, &magic, &shift); |
| 3075 | |
| 3076 | // Save the numerator. |
| 3077 | __ movq(numerator, rax); |
| 3078 | |
| 3079 | // RAX = magic |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3080 | codegen_->Load64BitValue(rax, magic); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3081 | |
| 3082 | // RDX:RAX = magic * numerator |
| 3083 | __ imulq(numerator); |
| 3084 | |
| 3085 | if (imm > 0 && magic < 0) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3086 | // RDX += numerator |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3087 | __ addq(rdx, numerator); |
| 3088 | } else if (imm < 0 && magic > 0) { |
| 3089 | // RDX -= numerator |
| 3090 | __ subq(rdx, numerator); |
| 3091 | } |
| 3092 | |
| 3093 | // Shift if needed. |
| 3094 | if (shift != 0) { |
| 3095 | __ sarq(rdx, Immediate(shift)); |
| 3096 | } |
| 3097 | |
| 3098 | // RDX += 1 if RDX < 0 |
| 3099 | __ movq(rax, rdx); |
| 3100 | __ shrq(rdx, Immediate(63)); |
| 3101 | __ addq(rdx, rax); |
| 3102 | |
| 3103 | if (instruction->IsRem()) { |
| 3104 | __ movq(rax, numerator); |
| 3105 | |
| 3106 | if (IsInt<32>(imm)) { |
| 3107 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 3108 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3109 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3110 | } |
| 3111 | |
| 3112 | __ subq(rax, rdx); |
| 3113 | __ movq(rdx, rax); |
| 3114 | } else { |
| 3115 | __ movq(rax, rdx); |
| 3116 | } |
| 3117 | } |
| 3118 | } |
| 3119 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3120 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3121 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3122 | Primitive::Type type = instruction->GetResultType(); |
| 3123 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 3124 | |
| 3125 | bool is_div = instruction->IsDiv(); |
| 3126 | LocationSummary* locations = instruction->GetLocations(); |
| 3127 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3128 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3129 | Location second = locations->InAt(1); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3130 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3131 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3132 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3133 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3134 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3135 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3136 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3137 | if (imm == 0) { |
| 3138 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3139 | } else if (imm == 1 || imm == -1) { |
| 3140 | DivRemOneOrMinusOne(instruction); |
| 3141 | } else if (instruction->IsDiv() && IsPowerOfTwo(std::abs(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3142 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3143 | } else { |
| 3144 | DCHECK(imm <= -2 || imm >= 2); |
| 3145 | GenerateDivRemWithAnyConstant(instruction); |
| 3146 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3147 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3148 | SlowPathCode* slow_path = |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3149 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86_64( |
| 3150 | out.AsRegister(), type, is_div); |
| 3151 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3152 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3153 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3154 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3155 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3156 | // so it's safe to just use negl instead of more complex comparisons. |
| 3157 | if (type == Primitive::kPrimInt) { |
| 3158 | __ cmpl(second_reg, Immediate(-1)); |
| 3159 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3160 | // edx:eax <- sign-extended of eax |
| 3161 | __ cdq(); |
| 3162 | // eax = quotient, edx = remainder |
| 3163 | __ idivl(second_reg); |
| 3164 | } else { |
| 3165 | __ cmpq(second_reg, Immediate(-1)); |
| 3166 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3167 | // rdx:rax <- sign-extended of rax |
| 3168 | __ cqo(); |
| 3169 | // rax = quotient, rdx = remainder |
| 3170 | __ idivq(second_reg); |
| 3171 | } |
| 3172 | __ Bind(slow_path->GetExitLabel()); |
| 3173 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3174 | } |
| 3175 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3176 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3177 | LocationSummary* locations = |
| 3178 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3179 | switch (div->GetResultType()) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3180 | case Primitive::kPrimInt: |
| 3181 | case Primitive::kPrimLong: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3182 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3183 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3184 | locations->SetOut(Location::SameAsFirstInput()); |
| 3185 | // Intel uses edx:eax as the dividend. |
| 3186 | locations->AddTemp(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3187 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3188 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3189 | // output and request another temp. |
| 3190 | if (div->InputAt(1)->IsConstant()) { |
| 3191 | locations->AddTemp(Location::RequiresRegister()); |
| 3192 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3193 | break; |
| 3194 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3195 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3196 | case Primitive::kPrimFloat: |
| 3197 | case Primitive::kPrimDouble: { |
| 3198 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3199 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3200 | locations->SetOut(Location::SameAsFirstInput()); |
| 3201 | break; |
| 3202 | } |
| 3203 | |
| 3204 | default: |
| 3205 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3206 | } |
| 3207 | } |
| 3208 | |
| 3209 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3210 | LocationSummary* locations = div->GetLocations(); |
| 3211 | Location first = locations->InAt(0); |
| 3212 | Location second = locations->InAt(1); |
| 3213 | DCHECK(first.Equals(locations->Out())); |
| 3214 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3215 | Primitive::Type type = div->GetResultType(); |
| 3216 | switch (type) { |
| 3217 | case Primitive::kPrimInt: |
| 3218 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3219 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3220 | break; |
| 3221 | } |
| 3222 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3223 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3224 | if (second.IsFpuRegister()) { |
| 3225 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3226 | } else if (second.IsConstant()) { |
| 3227 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3228 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 3229 | } else { |
| 3230 | DCHECK(second.IsStackSlot()); |
| 3231 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3232 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3233 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3234 | break; |
| 3235 | } |
| 3236 | |
| 3237 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3238 | if (second.IsFpuRegister()) { |
| 3239 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3240 | } else if (second.IsConstant()) { |
| 3241 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3242 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 3243 | } else { |
| 3244 | DCHECK(second.IsDoubleStackSlot()); |
| 3245 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3246 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3247 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3248 | break; |
| 3249 | } |
| 3250 | |
| 3251 | default: |
| 3252 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3253 | } |
| 3254 | } |
| 3255 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3256 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3257 | Primitive::Type type = rem->GetResultType(); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3258 | LocationSummary* locations = |
| 3259 | new (GetGraph()->GetArena()) LocationSummary(rem, LocationSummary::kNoCall); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3260 | |
| 3261 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3262 | case Primitive::kPrimInt: |
| 3263 | case Primitive::kPrimLong: { |
| 3264 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3265 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3266 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3267 | locations->SetOut(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3268 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3269 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3270 | // output and request another temp. |
| 3271 | if (rem->InputAt(1)->IsConstant()) { |
| 3272 | locations->AddTemp(Location::RequiresRegister()); |
| 3273 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3274 | break; |
| 3275 | } |
| 3276 | |
| 3277 | case Primitive::kPrimFloat: |
| 3278 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3279 | locations->SetInAt(0, Location::Any()); |
| 3280 | locations->SetInAt(1, Location::Any()); |
| 3281 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3282 | locations->AddTemp(Location::RegisterLocation(RAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3283 | break; |
| 3284 | } |
| 3285 | |
| 3286 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3287 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3288 | } |
| 3289 | } |
| 3290 | |
| 3291 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| 3292 | Primitive::Type type = rem->GetResultType(); |
| 3293 | switch (type) { |
| 3294 | case Primitive::kPrimInt: |
| 3295 | case Primitive::kPrimLong: { |
| 3296 | GenerateDivRemIntegral(rem); |
| 3297 | break; |
| 3298 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3299 | case Primitive::kPrimFloat: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3300 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3301 | GenerateRemFP(rem); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3302 | break; |
| 3303 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3304 | default: |
| 3305 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3306 | } |
| 3307 | } |
| 3308 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3309 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3310 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3311 | ? LocationSummary::kCallOnSlowPath |
| 3312 | : LocationSummary::kNoCall; |
| 3313 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3314 | locations->SetInAt(0, Location::Any()); |
| 3315 | if (instruction->HasUses()) { |
| 3316 | locations->SetOut(Location::SameAsFirstInput()); |
| 3317 | } |
| 3318 | } |
| 3319 | |
| 3320 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3321 | SlowPathCode* slow_path = |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3322 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction); |
| 3323 | codegen_->AddSlowPath(slow_path); |
| 3324 | |
| 3325 | LocationSummary* locations = instruction->GetLocations(); |
| 3326 | Location value = locations->InAt(0); |
| 3327 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3328 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3329 | case Primitive::kPrimByte: |
| 3330 | case Primitive::kPrimChar: |
| 3331 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3332 | case Primitive::kPrimInt: { |
| 3333 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3334 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3335 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3336 | } else if (value.IsStackSlot()) { |
| 3337 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3338 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3339 | } else { |
| 3340 | DCHECK(value.IsConstant()) << value; |
| 3341 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3342 | __ jmp(slow_path->GetEntryLabel()); |
| 3343 | } |
| 3344 | } |
| 3345 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3346 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3347 | case Primitive::kPrimLong: { |
| 3348 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3349 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3350 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3351 | } else if (value.IsDoubleStackSlot()) { |
| 3352 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3353 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3354 | } else { |
| 3355 | DCHECK(value.IsConstant()) << value; |
| 3356 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3357 | __ jmp(slow_path->GetEntryLabel()); |
| 3358 | } |
| 3359 | } |
| 3360 | break; |
| 3361 | } |
| 3362 | default: |
| 3363 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3364 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3365 | } |
| 3366 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3367 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 3368 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3369 | |
| 3370 | LocationSummary* locations = |
| 3371 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3372 | |
| 3373 | switch (op->GetResultType()) { |
| 3374 | case Primitive::kPrimInt: |
| 3375 | case Primitive::kPrimLong: { |
| 3376 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3377 | // The shift count needs to be in CL. |
| 3378 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 3379 | locations->SetOut(Location::SameAsFirstInput()); |
| 3380 | break; |
| 3381 | } |
| 3382 | default: |
| 3383 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3384 | } |
| 3385 | } |
| 3386 | |
| 3387 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 3388 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3389 | |
| 3390 | LocationSummary* locations = op->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3391 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3392 | Location second = locations->InAt(1); |
| 3393 | |
| 3394 | switch (op->GetResultType()) { |
| 3395 | case Primitive::kPrimInt: { |
| 3396 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3397 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3398 | if (op->IsShl()) { |
| 3399 | __ shll(first_reg, second_reg); |
| 3400 | } else if (op->IsShr()) { |
| 3401 | __ sarl(first_reg, second_reg); |
| 3402 | } else { |
| 3403 | __ shrl(first_reg, second_reg); |
| 3404 | } |
| 3405 | } else { |
Nicolas Geoffray | 486cc19 | 2014-12-08 18:00:55 +0000 | [diff] [blame] | 3406 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3407 | if (op->IsShl()) { |
| 3408 | __ shll(first_reg, imm); |
| 3409 | } else if (op->IsShr()) { |
| 3410 | __ sarl(first_reg, imm); |
| 3411 | } else { |
| 3412 | __ shrl(first_reg, imm); |
| 3413 | } |
| 3414 | } |
| 3415 | break; |
| 3416 | } |
| 3417 | case Primitive::kPrimLong: { |
| 3418 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3419 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3420 | if (op->IsShl()) { |
| 3421 | __ shlq(first_reg, second_reg); |
| 3422 | } else if (op->IsShr()) { |
| 3423 | __ sarq(first_reg, second_reg); |
| 3424 | } else { |
| 3425 | __ shrq(first_reg, second_reg); |
| 3426 | } |
| 3427 | } else { |
Nicolas Geoffray | 486cc19 | 2014-12-08 18:00:55 +0000 | [diff] [blame] | 3428 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3429 | if (op->IsShl()) { |
| 3430 | __ shlq(first_reg, imm); |
| 3431 | } else if (op->IsShr()) { |
| 3432 | __ sarq(first_reg, imm); |
| 3433 | } else { |
| 3434 | __ shrq(first_reg, imm); |
| 3435 | } |
| 3436 | } |
| 3437 | break; |
| 3438 | } |
| 3439 | default: |
| 3440 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3441 | } |
| 3442 | } |
| 3443 | |
| 3444 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 3445 | HandleShift(shl); |
| 3446 | } |
| 3447 | |
| 3448 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 3449 | HandleShift(shl); |
| 3450 | } |
| 3451 | |
| 3452 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 3453 | HandleShift(shr); |
| 3454 | } |
| 3455 | |
| 3456 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 3457 | HandleShift(shr); |
| 3458 | } |
| 3459 | |
| 3460 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 3461 | HandleShift(ushr); |
| 3462 | } |
| 3463 | |
| 3464 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 3465 | HandleShift(ushr); |
| 3466 | } |
| 3467 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3468 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3469 | LocationSummary* locations = |
| 3470 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3471 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3472 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3473 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3474 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3475 | } |
| 3476 | |
| 3477 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
| 3478 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3479 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 3480 | instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3481 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3482 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3483 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3484 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3485 | instruction, |
| 3486 | instruction->GetDexPc(), |
| 3487 | nullptr); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3488 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 3489 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3490 | } |
| 3491 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3492 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 3493 | LocationSummary* locations = |
| 3494 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3495 | InvokeRuntimeCallingConvention calling_convention; |
| 3496 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3497 | locations->SetOut(Location::RegisterLocation(RAX)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3498 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3499 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3500 | } |
| 3501 | |
| 3502 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| 3503 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3504 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 3505 | instruction->GetTypeIndex()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3506 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3507 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3508 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3509 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3510 | instruction, |
| 3511 | instruction->GetDexPc(), |
| 3512 | nullptr); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3513 | |
| 3514 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3515 | } |
| 3516 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3517 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3518 | LocationSummary* locations = |
| 3519 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3520 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3521 | if (location.IsStackSlot()) { |
| 3522 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3523 | } else if (location.IsDoubleStackSlot()) { |
| 3524 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3525 | } |
| 3526 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3527 | } |
| 3528 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3529 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 3530 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3531 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3532 | } |
| 3533 | |
| 3534 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3535 | LocationSummary* locations = |
| 3536 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3537 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3538 | } |
| 3539 | |
| 3540 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 3541 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3542 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3543 | } |
| 3544 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3545 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3546 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3547 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3548 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3549 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3550 | } |
| 3551 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3552 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 3553 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3554 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 3555 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3556 | Location out = locations->Out(); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3557 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3558 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3559 | __ notl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3560 | break; |
| 3561 | |
| 3562 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3563 | __ notq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3564 | break; |
| 3565 | |
| 3566 | default: |
| 3567 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3568 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3569 | } |
| 3570 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3571 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3572 | LocationSummary* locations = |
| 3573 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3574 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3575 | locations->SetOut(Location::SameAsFirstInput()); |
| 3576 | } |
| 3577 | |
| 3578 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3579 | LocationSummary* locations = bool_not->GetLocations(); |
| 3580 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 3581 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 3582 | Location out = locations->Out(); |
| 3583 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 3584 | } |
| 3585 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3586 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3587 | LocationSummary* locations = |
| 3588 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3589 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 3590 | locations->SetInAt(i, Location::Any()); |
| 3591 | } |
| 3592 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3593 | } |
| 3594 | |
| 3595 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3596 | UNUSED(instruction); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3597 | LOG(FATAL) << "Unimplemented"; |
| 3598 | } |
| 3599 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3600 | void InstructionCodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3601 | /* |
| 3602 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 3603 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 3604 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 3605 | */ |
| 3606 | switch (kind) { |
| 3607 | case MemBarrierKind::kAnyAny: { |
| 3608 | __ mfence(); |
| 3609 | break; |
| 3610 | } |
| 3611 | case MemBarrierKind::kAnyStore: |
| 3612 | case MemBarrierKind::kLoadAny: |
| 3613 | case MemBarrierKind::kStoreStore: { |
| 3614 | // nop |
| 3615 | break; |
| 3616 | } |
| 3617 | default: |
| 3618 | LOG(FATAL) << "Unexpected memory barier " << kind; |
| 3619 | } |
| 3620 | } |
| 3621 | |
| 3622 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 3623 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 3624 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3625 | LocationSummary* locations = |
| 3626 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3627 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3628 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3629 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3630 | } else { |
| 3631 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3632 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3633 | } |
| 3634 | |
| 3635 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 3636 | const FieldInfo& field_info) { |
| 3637 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 3638 | |
| 3639 | LocationSummary* locations = instruction->GetLocations(); |
| 3640 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3641 | Location out = locations->Out(); |
| 3642 | bool is_volatile = field_info.IsVolatile(); |
| 3643 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3644 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3645 | |
| 3646 | switch (field_type) { |
| 3647 | case Primitive::kPrimBoolean: { |
| 3648 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3649 | break; |
| 3650 | } |
| 3651 | |
| 3652 | case Primitive::kPrimByte: { |
| 3653 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3654 | break; |
| 3655 | } |
| 3656 | |
| 3657 | case Primitive::kPrimShort: { |
| 3658 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3659 | break; |
| 3660 | } |
| 3661 | |
| 3662 | case Primitive::kPrimChar: { |
| 3663 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3664 | break; |
| 3665 | } |
| 3666 | |
| 3667 | case Primitive::kPrimInt: |
| 3668 | case Primitive::kPrimNot: { |
| 3669 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3670 | break; |
| 3671 | } |
| 3672 | |
| 3673 | case Primitive::kPrimLong: { |
| 3674 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3675 | break; |
| 3676 | } |
| 3677 | |
| 3678 | case Primitive::kPrimFloat: { |
| 3679 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 3680 | break; |
| 3681 | } |
| 3682 | |
| 3683 | case Primitive::kPrimDouble: { |
| 3684 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 3685 | break; |
| 3686 | } |
| 3687 | |
| 3688 | case Primitive::kPrimVoid: |
| 3689 | LOG(FATAL) << "Unreachable type " << field_type; |
| 3690 | UNREACHABLE(); |
| 3691 | } |
| 3692 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3693 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3694 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3695 | if (is_volatile) { |
| 3696 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 3697 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3698 | |
| 3699 | if (field_type == Primitive::kPrimNot) { |
| 3700 | __ MaybeUnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 3701 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3702 | } |
| 3703 | |
| 3704 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 3705 | const FieldInfo& field_info) { |
| 3706 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3707 | |
| 3708 | LocationSummary* locations = |
| 3709 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3710 | Primitive::Type field_type = field_info.GetFieldType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3711 | bool needs_write_barrier = |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3712 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3713 | |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3714 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3715 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
| 3716 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3717 | } else { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3718 | locations->SetInAt(1, Location::RegisterOrInt32LongConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3719 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3720 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3721 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3722 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3723 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3724 | } else if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 3725 | // Temporary register for the reference poisoning. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3726 | locations->AddTemp(Location::RequiresRegister()); |
| 3727 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3728 | } |
| 3729 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3730 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3731 | const FieldInfo& field_info, |
| 3732 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3733 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3734 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3735 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3736 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3737 | Location value = locations->InAt(1); |
| 3738 | bool is_volatile = field_info.IsVolatile(); |
| 3739 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3740 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3741 | |
| 3742 | if (is_volatile) { |
| 3743 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 3744 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3745 | |
| 3746 | switch (field_type) { |
| 3747 | case Primitive::kPrimBoolean: |
| 3748 | case Primitive::kPrimByte: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3749 | if (value.IsConstant()) { |
| 3750 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 3751 | __ movb(Address(base, offset), Immediate(v)); |
| 3752 | } else { |
| 3753 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3754 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3755 | break; |
| 3756 | } |
| 3757 | |
| 3758 | case Primitive::kPrimShort: |
| 3759 | case Primitive::kPrimChar: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3760 | if (value.IsConstant()) { |
| 3761 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 3762 | __ movw(Address(base, offset), Immediate(v)); |
| 3763 | } else { |
| 3764 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3765 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3766 | break; |
| 3767 | } |
| 3768 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3769 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3770 | case Primitive::kPrimNot: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3771 | if (value.IsConstant()) { |
| 3772 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3773 | // `field_type == Primitive::kPrimNot` implies `v == 0`. |
| 3774 | DCHECK((field_type != Primitive::kPrimNot) || (v == 0)); |
| 3775 | // Note: if heap poisoning is enabled, no need to poison |
| 3776 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 3777 | __ movl(Address(base, offset), Immediate(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3778 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3779 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 3780 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3781 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 3782 | __ PoisonHeapReference(temp); |
| 3783 | __ movl(Address(base, offset), temp); |
| 3784 | } else { |
| 3785 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3786 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3787 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3788 | break; |
| 3789 | } |
| 3790 | |
| 3791 | case Primitive::kPrimLong: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3792 | if (value.IsConstant()) { |
| 3793 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| 3794 | DCHECK(IsInt<32>(v)); |
| 3795 | int32_t v_32 = v; |
| 3796 | __ movq(Address(base, offset), Immediate(v_32)); |
| 3797 | } else { |
| 3798 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3799 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3800 | break; |
| 3801 | } |
| 3802 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3803 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3804 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3805 | break; |
| 3806 | } |
| 3807 | |
| 3808 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3809 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3810 | break; |
| 3811 | } |
| 3812 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3813 | case Primitive::kPrimVoid: |
| 3814 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3815 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3816 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3817 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3818 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3819 | |
| 3820 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 3821 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3822 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3823 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3824 | } |
| 3825 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3826 | if (is_volatile) { |
| 3827 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 3828 | } |
| 3829 | } |
| 3830 | |
| 3831 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 3832 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3833 | } |
| 3834 | |
| 3835 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3836 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3837 | } |
| 3838 | |
| 3839 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3840 | HandleFieldGet(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3841 | } |
| 3842 | |
| 3843 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3844 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3845 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3846 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3847 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3848 | HandleFieldGet(instruction); |
| 3849 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3850 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3851 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3852 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3853 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3854 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3855 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3856 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3857 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3858 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3859 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3860 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3861 | } |
| 3862 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 3863 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldGet( |
| 3864 | HUnresolvedInstanceFieldGet* instruction) { |
| 3865 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3866 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3867 | instruction, instruction->GetFieldType(), calling_convention); |
| 3868 | } |
| 3869 | |
| 3870 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldGet( |
| 3871 | HUnresolvedInstanceFieldGet* instruction) { |
| 3872 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3873 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3874 | instruction->GetFieldType(), |
| 3875 | instruction->GetFieldIndex(), |
| 3876 | instruction->GetDexPc(), |
| 3877 | calling_convention); |
| 3878 | } |
| 3879 | |
| 3880 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldSet( |
| 3881 | HUnresolvedInstanceFieldSet* instruction) { |
| 3882 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3883 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3884 | instruction, instruction->GetFieldType(), calling_convention); |
| 3885 | } |
| 3886 | |
| 3887 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldSet( |
| 3888 | HUnresolvedInstanceFieldSet* instruction) { |
| 3889 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3890 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3891 | instruction->GetFieldType(), |
| 3892 | instruction->GetFieldIndex(), |
| 3893 | instruction->GetDexPc(), |
| 3894 | calling_convention); |
| 3895 | } |
| 3896 | |
| 3897 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldGet( |
| 3898 | HUnresolvedStaticFieldGet* instruction) { |
| 3899 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3900 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3901 | instruction, instruction->GetFieldType(), calling_convention); |
| 3902 | } |
| 3903 | |
| 3904 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldGet( |
| 3905 | HUnresolvedStaticFieldGet* instruction) { |
| 3906 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3907 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3908 | instruction->GetFieldType(), |
| 3909 | instruction->GetFieldIndex(), |
| 3910 | instruction->GetDexPc(), |
| 3911 | calling_convention); |
| 3912 | } |
| 3913 | |
| 3914 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldSet( |
| 3915 | HUnresolvedStaticFieldSet* instruction) { |
| 3916 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3917 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3918 | instruction, instruction->GetFieldType(), calling_convention); |
| 3919 | } |
| 3920 | |
| 3921 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldSet( |
| 3922 | HUnresolvedStaticFieldSet* instruction) { |
| 3923 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3924 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3925 | instruction->GetFieldType(), |
| 3926 | instruction->GetFieldIndex(), |
| 3927 | instruction->GetDexPc(), |
| 3928 | calling_convention); |
| 3929 | } |
| 3930 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3931 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3932 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3933 | ? LocationSummary::kCallOnSlowPath |
| 3934 | : LocationSummary::kNoCall; |
| 3935 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 3936 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3937 | ? Location::RequiresRegister() |
| 3938 | : Location::Any(); |
| 3939 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3940 | if (instruction->HasUses()) { |
| 3941 | locations->SetOut(Location::SameAsFirstInput()); |
| 3942 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3943 | } |
| 3944 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3945 | void InstructionCodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3946 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 3947 | return; |
| 3948 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3949 | LocationSummary* locations = instruction->GetLocations(); |
| 3950 | Location obj = locations->InAt(0); |
| 3951 | |
| 3952 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
| 3953 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3954 | } |
| 3955 | |
| 3956 | void InstructionCodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3957 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3958 | codegen_->AddSlowPath(slow_path); |
| 3959 | |
| 3960 | LocationSummary* locations = instruction->GetLocations(); |
| 3961 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3962 | |
| 3963 | if (obj.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3964 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3965 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3966 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3967 | } else { |
| 3968 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3969 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3970 | __ jmp(slow_path->GetEntryLabel()); |
| 3971 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3972 | } |
| 3973 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3974 | } |
| 3975 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3976 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3977 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3978 | GenerateImplicitNullCheck(instruction); |
| 3979 | } else { |
| 3980 | GenerateExplicitNullCheck(instruction); |
| 3981 | } |
| 3982 | } |
| 3983 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3984 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3985 | LocationSummary* locations = |
| 3986 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3987 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3988 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3989 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3990 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3991 | } else { |
| 3992 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3993 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3994 | } |
| 3995 | |
| 3996 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 3997 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3998 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3999 | Location index = locations->InAt(1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4000 | Primitive::Type type = instruction->GetType(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4001 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4002 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4003 | case Primitive::kPrimBoolean: { |
| 4004 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4005 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4006 | if (index.IsConstant()) { |
| 4007 | __ movzxb(out, Address(obj, |
| 4008 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4009 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4010 | __ movzxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4011 | } |
| 4012 | break; |
| 4013 | } |
| 4014 | |
| 4015 | case Primitive::kPrimByte: { |
| 4016 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4017 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4018 | if (index.IsConstant()) { |
| 4019 | __ movsxb(out, Address(obj, |
| 4020 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4021 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4022 | __ movsxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4023 | } |
| 4024 | break; |
| 4025 | } |
| 4026 | |
| 4027 | case Primitive::kPrimShort: { |
| 4028 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4029 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4030 | if (index.IsConstant()) { |
| 4031 | __ movsxw(out, Address(obj, |
| 4032 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4033 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4034 | __ movsxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4035 | } |
| 4036 | break; |
| 4037 | } |
| 4038 | |
| 4039 | case Primitive::kPrimChar: { |
| 4040 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4041 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4042 | if (index.IsConstant()) { |
| 4043 | __ movzxw(out, Address(obj, |
| 4044 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4045 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4046 | __ movzxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4047 | } |
| 4048 | break; |
| 4049 | } |
| 4050 | |
| 4051 | case Primitive::kPrimInt: |
| 4052 | case Primitive::kPrimNot: { |
Roland Levillain | 33d6903 | 2015-06-18 18:20:59 +0100 | [diff] [blame] | 4053 | static_assert(sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4054 | "art::mirror::HeapReference<mirror::Object> and int32_t have different sizes."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4055 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4056 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4057 | if (index.IsConstant()) { |
| 4058 | __ movl(out, Address(obj, |
| 4059 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4060 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4061 | __ movl(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4062 | } |
| 4063 | break; |
| 4064 | } |
| 4065 | |
| 4066 | case Primitive::kPrimLong: { |
| 4067 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4068 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4069 | if (index.IsConstant()) { |
| 4070 | __ movq(out, Address(obj, |
| 4071 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4072 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4073 | __ movq(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4074 | } |
| 4075 | break; |
| 4076 | } |
| 4077 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4078 | case Primitive::kPrimFloat: { |
| 4079 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4080 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4081 | if (index.IsConstant()) { |
| 4082 | __ movss(out, Address(obj, |
| 4083 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4084 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4085 | __ movss(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4086 | } |
| 4087 | break; |
| 4088 | } |
| 4089 | |
| 4090 | case Primitive::kPrimDouble: { |
| 4091 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4092 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4093 | if (index.IsConstant()) { |
| 4094 | __ movsd(out, Address(obj, |
| 4095 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4096 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4097 | __ movsd(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4098 | } |
| 4099 | break; |
| 4100 | } |
| 4101 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4102 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4103 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4104 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4105 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4106 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4107 | |
| 4108 | if (type == Primitive::kPrimNot) { |
| 4109 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4110 | __ MaybeUnpoisonHeapReference(out); |
| 4111 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4112 | } |
| 4113 | |
| 4114 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4115 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4116 | |
| 4117 | bool needs_write_barrier = |
| 4118 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4119 | bool may_need_runtime_call = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4120 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4121 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4122 | instruction, |
| 4123 | may_need_runtime_call ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4124 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4125 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4126 | locations->SetInAt( |
| 4127 | 1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4128 | locations->SetInAt(2, Location::RequiresRegister()); |
| 4129 | if (value_type == Primitive::kPrimLong) { |
| 4130 | locations->SetInAt(2, Location::RegisterOrInt32LongConstant(instruction->InputAt(2))); |
| 4131 | } else if (value_type == Primitive::kPrimFloat || value_type == Primitive::kPrimDouble) { |
| 4132 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| 4133 | } else { |
| 4134 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 4135 | } |
| 4136 | |
| 4137 | if (needs_write_barrier) { |
| 4138 | // Temporary registers for the write barrier. |
| 4139 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 4140 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4141 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4142 | } |
| 4143 | |
| 4144 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 4145 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4146 | CpuRegister array = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4147 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4148 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4149 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4150 | bool may_need_runtime_call = locations->CanCall(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4151 | bool needs_write_barrier = |
| 4152 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4153 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4154 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4155 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4156 | |
| 4157 | switch (value_type) { |
| 4158 | case Primitive::kPrimBoolean: |
| 4159 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4160 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 4161 | Address address = index.IsConstant() |
| 4162 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 4163 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_1, offset); |
| 4164 | if (value.IsRegister()) { |
| 4165 | __ movb(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4166 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4167 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4168 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4169 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4170 | break; |
| 4171 | } |
| 4172 | |
| 4173 | case Primitive::kPrimShort: |
| 4174 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4175 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 4176 | Address address = index.IsConstant() |
| 4177 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 4178 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_2, offset); |
| 4179 | if (value.IsRegister()) { |
| 4180 | __ movw(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4181 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4182 | DCHECK(value.IsConstant()) << value; |
| 4183 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4184 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4185 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4186 | break; |
| 4187 | } |
| 4188 | |
| 4189 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4190 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4191 | Address address = index.IsConstant() |
| 4192 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4193 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
| 4194 | if (!value.IsRegister()) { |
| 4195 | // Just setting null. |
| 4196 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 4197 | DCHECK(value.IsConstant()) << value; |
| 4198 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4199 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4200 | DCHECK(!needs_write_barrier); |
| 4201 | DCHECK(!may_need_runtime_call); |
| 4202 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4203 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4204 | |
| 4205 | DCHECK(needs_write_barrier); |
| 4206 | CpuRegister register_value = value.AsRegister<CpuRegister>(); |
| 4207 | NearLabel done, not_null, do_put; |
| 4208 | SlowPathCode* slow_path = nullptr; |
| 4209 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4210 | if (may_need_runtime_call) { |
| 4211 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86_64(instruction); |
| 4212 | codegen_->AddSlowPath(slow_path); |
| 4213 | if (instruction->GetValueCanBeNull()) { |
| 4214 | __ testl(register_value, register_value); |
| 4215 | __ j(kNotEqual, ¬_null); |
| 4216 | __ movl(address, Immediate(0)); |
| 4217 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4218 | __ jmp(&done); |
| 4219 | __ Bind(¬_null); |
| 4220 | } |
| 4221 | |
| 4222 | __ movl(temp, Address(array, class_offset)); |
| 4223 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4224 | __ MaybeUnpoisonHeapReference(temp); |
| 4225 | __ movl(temp, Address(temp, component_offset)); |
| 4226 | // No need to poison/unpoison, we're comparing two poisoned references. |
| 4227 | __ cmpl(temp, Address(register_value, class_offset)); |
| 4228 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4229 | __ j(kEqual, &do_put); |
| 4230 | __ MaybeUnpoisonHeapReference(temp); |
| 4231 | __ movl(temp, Address(temp, super_offset)); |
| 4232 | // No need to unpoison the result, we're comparing against null. |
| 4233 | __ testl(temp, temp); |
| 4234 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4235 | __ Bind(&do_put); |
| 4236 | } else { |
| 4237 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4238 | } |
| 4239 | } |
| 4240 | |
| 4241 | if (kPoisonHeapReferences) { |
| 4242 | __ movl(temp, register_value); |
| 4243 | __ PoisonHeapReference(temp); |
| 4244 | __ movl(address, temp); |
| 4245 | } else { |
| 4246 | __ movl(address, register_value); |
| 4247 | } |
| 4248 | if (!may_need_runtime_call) { |
| 4249 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4250 | } |
| 4251 | |
| 4252 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 4253 | codegen_->MarkGCCard( |
| 4254 | temp, card, array, value.AsRegister<CpuRegister>(), instruction->GetValueCanBeNull()); |
| 4255 | __ Bind(&done); |
| 4256 | |
| 4257 | if (slow_path != nullptr) { |
| 4258 | __ Bind(slow_path->GetExitLabel()); |
| 4259 | } |
| 4260 | |
| 4261 | break; |
| 4262 | } |
| 4263 | case Primitive::kPrimInt: { |
| 4264 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4265 | Address address = index.IsConstant() |
| 4266 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4267 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
| 4268 | if (value.IsRegister()) { |
| 4269 | __ movl(address, value.AsRegister<CpuRegister>()); |
| 4270 | } else { |
| 4271 | DCHECK(value.IsConstant()) << value; |
| 4272 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4273 | __ movl(address, Immediate(v)); |
| 4274 | } |
| 4275 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4276 | break; |
| 4277 | } |
| 4278 | |
| 4279 | case Primitive::kPrimLong: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4280 | uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| 4281 | Address address = index.IsConstant() |
| 4282 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 4283 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset); |
| 4284 | if (value.IsRegister()) { |
| 4285 | __ movq(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4286 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4287 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| 4288 | DCHECK(IsInt<32>(v)); |
| 4289 | int32_t v_32 = v; |
| 4290 | __ movq(address, Immediate(v_32)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4291 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4292 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4293 | break; |
| 4294 | } |
| 4295 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4296 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4297 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4298 | Address address = index.IsConstant() |
| 4299 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4300 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
| 4301 | DCHECK(value.IsFpuRegister()); |
| 4302 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4303 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4304 | break; |
| 4305 | } |
| 4306 | |
| 4307 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4308 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4309 | Address address = index.IsConstant() |
| 4310 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 4311 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset); |
| 4312 | DCHECK(value.IsFpuRegister()); |
| 4313 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4314 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4315 | break; |
| 4316 | } |
| 4317 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4318 | case Primitive::kPrimVoid: |
| 4319 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4320 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4321 | } |
| 4322 | } |
| 4323 | |
| 4324 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4325 | LocationSummary* locations = |
| 4326 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4327 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4328 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4329 | } |
| 4330 | |
| 4331 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
| 4332 | LocationSummary* locations = instruction->GetLocations(); |
| 4333 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4334 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4335 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4336 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4337 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4338 | } |
| 4339 | |
| 4340 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4341 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4342 | ? LocationSummary::kCallOnSlowPath |
| 4343 | : LocationSummary::kNoCall; |
| 4344 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4345 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4346 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4347 | if (instruction->HasUses()) { |
| 4348 | locations->SetOut(Location::SameAsFirstInput()); |
| 4349 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4350 | } |
| 4351 | |
| 4352 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4353 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4354 | Location index_loc = locations->InAt(0); |
| 4355 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4356 | SlowPathCode* slow_path = |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4357 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4358 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4359 | if (length_loc.IsConstant()) { |
| 4360 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 4361 | if (index_loc.IsConstant()) { |
| 4362 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 4363 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4364 | if (index < 0 || index >= length) { |
| 4365 | codegen_->AddSlowPath(slow_path); |
| 4366 | __ jmp(slow_path->GetEntryLabel()); |
| 4367 | } else { |
| 4368 | // Some optimization after BCE may have generated this, and we should not |
| 4369 | // generate a bounds check if it is a valid range. |
| 4370 | } |
| 4371 | return; |
| 4372 | } |
| 4373 | |
| 4374 | // We have to reverse the jump condition because the length is the constant. |
| 4375 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 4376 | __ cmpl(index_reg, Immediate(length)); |
| 4377 | codegen_->AddSlowPath(slow_path); |
| 4378 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4379 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4380 | CpuRegister length = length_loc.AsRegister<CpuRegister>(); |
| 4381 | if (index_loc.IsConstant()) { |
| 4382 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4383 | __ cmpl(length, Immediate(value)); |
| 4384 | } else { |
| 4385 | __ cmpl(length, index_loc.AsRegister<CpuRegister>()); |
| 4386 | } |
| 4387 | codegen_->AddSlowPath(slow_path); |
| 4388 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4389 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4390 | } |
| 4391 | |
| 4392 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 4393 | CpuRegister card, |
| 4394 | CpuRegister object, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4395 | CpuRegister value, |
| 4396 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4397 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4398 | if (value_can_be_null) { |
| 4399 | __ testl(value, value); |
| 4400 | __ j(kEqual, &is_null); |
| 4401 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4402 | __ gs()->movq(card, Address::Absolute( |
| 4403 | Thread::CardTableOffset<kX86_64WordSize>().Int32Value(), true)); |
| 4404 | __ movq(temp, object); |
| 4405 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4406 | __ movb(Address(temp, card, TIMES_1, 0), card); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4407 | if (value_can_be_null) { |
| 4408 | __ Bind(&is_null); |
| 4409 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4410 | } |
| 4411 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4412 | void LocationsBuilderX86_64::VisitTemporary(HTemporary* temp) { |
| 4413 | temp->SetLocations(nullptr); |
| 4414 | } |
| 4415 | |
| 4416 | void InstructionCodeGeneratorX86_64::VisitTemporary(HTemporary* temp) { |
| 4417 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4418 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4419 | } |
| 4420 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4421 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4422 | UNUSED(instruction); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4423 | LOG(FATAL) << "Unimplemented"; |
| 4424 | } |
| 4425 | |
| 4426 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4427 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4428 | } |
| 4429 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4430 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4431 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4432 | } |
| 4433 | |
| 4434 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4435 | HBasicBlock* block = instruction->GetBlock(); |
| 4436 | if (block->GetLoopInformation() != nullptr) { |
| 4437 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4438 | // The back edge will generate the suspend check. |
| 4439 | return; |
| 4440 | } |
| 4441 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4442 | // The goto will generate the suspend check. |
| 4443 | return; |
| 4444 | } |
| 4445 | GenerateSuspendCheck(instruction, nullptr); |
| 4446 | } |
| 4447 | |
| 4448 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 4449 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4450 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4451 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 4452 | if (slow_path == nullptr) { |
| 4453 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
| 4454 | instruction->SetSlowPath(slow_path); |
| 4455 | codegen_->AddSlowPath(slow_path); |
| 4456 | if (successor != nullptr) { |
| 4457 | DCHECK(successor->IsLoopHeader()); |
| 4458 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 4459 | } |
| 4460 | } else { |
| 4461 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 4462 | } |
| 4463 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4464 | __ gs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4465 | Thread::ThreadFlagsOffset<kX86_64WordSize>().Int32Value(), true), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4466 | if (successor == nullptr) { |
| 4467 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4468 | __ Bind(slow_path->GetReturnLabel()); |
| 4469 | } else { |
| 4470 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 4471 | __ jmp(slow_path->GetEntryLabel()); |
| 4472 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4473 | } |
| 4474 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4475 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 4476 | return codegen_->GetAssembler(); |
| 4477 | } |
| 4478 | |
| 4479 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 4480 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4481 | Location source = move->GetSource(); |
| 4482 | Location destination = move->GetDestination(); |
| 4483 | |
| 4484 | if (source.IsRegister()) { |
| 4485 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4486 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4487 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4488 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4489 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4490 | } else { |
| 4491 | DCHECK(destination.IsDoubleStackSlot()); |
| 4492 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4493 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4494 | } |
| 4495 | } else if (source.IsStackSlot()) { |
| 4496 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4497 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4498 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4499 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4500 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4501 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4502 | } else { |
| 4503 | DCHECK(destination.IsStackSlot()); |
| 4504 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 4505 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 4506 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4507 | } else if (source.IsDoubleStackSlot()) { |
| 4508 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4509 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4510 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4511 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4512 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 4513 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4514 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 4515 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4516 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 4517 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 4518 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4519 | } else if (source.IsConstant()) { |
| 4520 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4521 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 4522 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4523 | if (destination.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4524 | if (value == 0) { |
| 4525 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 4526 | } else { |
| 4527 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 4528 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4529 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4530 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4531 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4532 | } |
| 4533 | } else if (constant->IsLongConstant()) { |
| 4534 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 4535 | if (destination.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4536 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4537 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4538 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 4539 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4540 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4541 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4542 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4543 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4544 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4545 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4546 | if (value == 0) { |
| 4547 | // easy FP 0.0. |
| 4548 | __ xorps(dest, dest); |
| 4549 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4550 | __ movss(dest, codegen_->LiteralFloatAddress(fp_value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4551 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4552 | } else { |
| 4553 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4554 | Immediate imm(value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4555 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 4556 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4557 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4558 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4559 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4560 | int64_t value = bit_cast<int64_t, double>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4561 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4562 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4563 | if (value == 0) { |
| 4564 | __ xorpd(dest, dest); |
| 4565 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4566 | __ movsd(dest, codegen_->LiteralDoubleAddress(fp_value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4567 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4568 | } else { |
| 4569 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 4570 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4571 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4572 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4573 | } else if (source.IsFpuRegister()) { |
| 4574 | if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4575 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4576 | } else if (destination.IsStackSlot()) { |
| 4577 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4578 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4579 | } else { |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 4580 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4581 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4582 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4583 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4584 | } |
| 4585 | } |
| 4586 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4587 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4588 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4589 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 4590 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4591 | } |
| 4592 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4593 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4594 | ScratchRegisterScope ensure_scratch( |
| 4595 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 4596 | |
| 4597 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 4598 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 4599 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 4600 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 4601 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 4602 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 4603 | CpuRegister(ensure_scratch.GetRegister())); |
| 4604 | } |
| 4605 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4606 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 4607 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 4608 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 4609 | __ movq(reg, CpuRegister(TMP)); |
| 4610 | } |
| 4611 | |
| 4612 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 4613 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4614 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4615 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4616 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 4617 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 4618 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 4619 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 4620 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 4621 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 4622 | CpuRegister(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4623 | } |
| 4624 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4625 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 4626 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 4627 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 4628 | __ movd(reg, CpuRegister(TMP)); |
| 4629 | } |
| 4630 | |
| 4631 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 4632 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 4633 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 4634 | __ movd(reg, CpuRegister(TMP)); |
| 4635 | } |
| 4636 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4637 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 4638 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4639 | Location source = move->GetSource(); |
| 4640 | Location destination = move->GetDestination(); |
| 4641 | |
| 4642 | if (source.IsRegister() && destination.IsRegister()) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4643 | __ xchgq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4644 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4645 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4646 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4647 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4648 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4649 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 4650 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4651 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4652 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4653 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4654 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 4655 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4656 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4657 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 4658 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 4659 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4660 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4661 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4662 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4663 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4664 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4665 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4666 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4667 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4668 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4669 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4670 | } |
| 4671 | } |
| 4672 | |
| 4673 | |
| 4674 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 4675 | __ pushq(CpuRegister(reg)); |
| 4676 | } |
| 4677 | |
| 4678 | |
| 4679 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 4680 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4681 | } |
| 4682 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4683 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4684 | SlowPathCode* slow_path, CpuRegister class_reg) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4685 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 4686 | Immediate(mirror::Class::kStatusInitialized)); |
| 4687 | __ j(kLess, slow_path->GetEntryLabel()); |
| 4688 | __ Bind(slow_path->GetExitLabel()); |
| 4689 | // No need for memory fence, thanks to the X86_64 memory model. |
| 4690 | } |
| 4691 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4692 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4693 | InvokeRuntimeCallingConvention calling_convention; |
| 4694 | CodeGenerator::CreateLoadClassLocationSummary( |
| 4695 | cls, |
| 4696 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 4697 | Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4698 | } |
| 4699 | |
| 4700 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4701 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4702 | if (cls->NeedsAccessCheck()) { |
| 4703 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 4704 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 4705 | cls, |
| 4706 | cls->GetDexPc(), |
| 4707 | nullptr); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4708 | return; |
| 4709 | } |
| 4710 | |
| 4711 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4712 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4713 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4714 | DCHECK(!cls->CanCallRuntime()); |
| 4715 | DCHECK(!cls->MustGenerateClinitCheck()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4716 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4717 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4718 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4719 | __ movq(out, Address( |
| 4720 | current_method, ArtMethod::DexCacheResolvedTypesOffset(kX86_64PointerSize).Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4721 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4722 | // TODO: We will need a read barrier here. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4723 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4724 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4725 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 4726 | codegen_->AddSlowPath(slow_path); |
| 4727 | __ testl(out, out); |
| 4728 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4729 | if (cls->MustGenerateClinitCheck()) { |
| 4730 | GenerateClassInitializationCheck(slow_path, out); |
| 4731 | } else { |
| 4732 | __ Bind(slow_path->GetExitLabel()); |
| 4733 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4734 | } |
| 4735 | } |
| 4736 | |
| 4737 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 4738 | LocationSummary* locations = |
| 4739 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 4740 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4741 | if (check->HasUses()) { |
| 4742 | locations->SetOut(Location::SameAsFirstInput()); |
| 4743 | } |
| 4744 | } |
| 4745 | |
| 4746 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4747 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4748 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4749 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4750 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4751 | GenerateClassInitializationCheck(slow_path, |
| 4752 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4753 | } |
| 4754 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4755 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
| 4756 | LocationSummary* locations = |
| 4757 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4758 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4759 | locations->SetOut(Location::RequiresRegister()); |
| 4760 | } |
| 4761 | |
| 4762 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4763 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86_64(load); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4764 | codegen_->AddSlowPath(slow_path); |
| 4765 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4766 | LocationSummary* locations = load->GetLocations(); |
| 4767 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4768 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4769 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4770 | __ movq(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4771 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4772 | // TODO: We will need a read barrier here. |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4773 | __ testl(out, out); |
| 4774 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4775 | __ Bind(slow_path->GetExitLabel()); |
| 4776 | } |
| 4777 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4778 | static Address GetExceptionTlsAddress() { |
| 4779 | return Address::Absolute(Thread::ExceptionOffset<kX86_64WordSize>().Int32Value(), true); |
| 4780 | } |
| 4781 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4782 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 4783 | LocationSummary* locations = |
| 4784 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 4785 | locations->SetOut(Location::RequiresRegister()); |
| 4786 | } |
| 4787 | |
| 4788 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4789 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 4790 | } |
| 4791 | |
| 4792 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
| 4793 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 4794 | } |
| 4795 | |
| 4796 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 4797 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4798 | } |
| 4799 | |
| 4800 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| 4801 | LocationSummary* locations = |
| 4802 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4803 | InvokeRuntimeCallingConvention calling_convention; |
| 4804 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4805 | } |
| 4806 | |
| 4807 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 4808 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 4809 | instruction, |
| 4810 | instruction->GetDexPc(), |
| 4811 | nullptr); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4812 | } |
| 4813 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4814 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4815 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 4816 | switch (instruction->GetTypeCheckKind()) { |
| 4817 | case TypeCheckKind::kExactCheck: |
| 4818 | case TypeCheckKind::kAbstractClassCheck: |
| 4819 | case TypeCheckKind::kClassHierarchyCheck: |
| 4820 | case TypeCheckKind::kArrayObjectCheck: |
| 4821 | call_kind = LocationSummary::kNoCall; |
| 4822 | break; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4823 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4824 | case TypeCheckKind::kInterfaceCheck: |
| 4825 | call_kind = LocationSummary::kCall; |
| 4826 | break; |
| 4827 | case TypeCheckKind::kArrayCheck: |
| 4828 | call_kind = LocationSummary::kCallOnSlowPath; |
| 4829 | break; |
| 4830 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4831 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4832 | if (call_kind != LocationSummary::kCall) { |
| 4833 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4834 | locations->SetInAt(1, Location::Any()); |
| 4835 | // Note that TypeCheckSlowPathX86_64 uses this register too. |
| 4836 | locations->SetOut(Location::RequiresRegister()); |
| 4837 | } else { |
| 4838 | InvokeRuntimeCallingConvention calling_convention; |
| 4839 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4840 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 4841 | locations->SetOut(Location::RegisterLocation(RAX)); |
| 4842 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4843 | } |
| 4844 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4845 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4846 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4847 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4848 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4849 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4850 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4851 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4852 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4853 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4854 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4855 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4856 | |
| 4857 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4858 | // Avoid null check if we know obj is not null. |
| 4859 | if (instruction->MustDoNullCheck()) { |
| 4860 | __ testl(obj, obj); |
| 4861 | __ j(kEqual, &zero); |
| 4862 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4863 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4864 | // In case of an interface/unresolved check, we put the object class into the object register. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4865 | // This is safe, as the register is caller-save, and the object must be in another |
| 4866 | // register if it survives the runtime call. |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4867 | CpuRegister target = (instruction->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck) || |
| 4868 | (instruction->GetTypeCheckKind() == TypeCheckKind::kUnresolvedCheck) |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4869 | ? obj |
| 4870 | : out; |
| 4871 | __ movl(target, Address(obj, class_offset)); |
| 4872 | __ MaybeUnpoisonHeapReference(target); |
| 4873 | |
| 4874 | switch (instruction->GetTypeCheckKind()) { |
| 4875 | case TypeCheckKind::kExactCheck: { |
| 4876 | if (cls.IsRegister()) { |
| 4877 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 4878 | } else { |
| 4879 | DCHECK(cls.IsStackSlot()) << cls; |
| 4880 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 4881 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4882 | if (zero.IsLinked()) { |
| 4883 | // Classes must be equal for the instanceof to succeed. |
| 4884 | __ j(kNotEqual, &zero); |
| 4885 | __ movl(out, Immediate(1)); |
| 4886 | __ jmp(&done); |
| 4887 | } else { |
| 4888 | __ setcc(kEqual, out); |
| 4889 | // setcc only sets the low byte. |
| 4890 | __ andl(out, Immediate(1)); |
| 4891 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4892 | break; |
| 4893 | } |
| 4894 | case TypeCheckKind::kAbstractClassCheck: { |
| 4895 | // If the class is abstract, we eagerly fetch the super class of the |
| 4896 | // object to avoid doing a comparison we know will fail. |
| 4897 | NearLabel loop, success; |
| 4898 | __ Bind(&loop); |
| 4899 | __ movl(out, Address(out, super_offset)); |
| 4900 | __ MaybeUnpoisonHeapReference(out); |
| 4901 | __ testl(out, out); |
| 4902 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4903 | __ j(kEqual, &done); |
| 4904 | if (cls.IsRegister()) { |
| 4905 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 4906 | } else { |
| 4907 | DCHECK(cls.IsStackSlot()) << cls; |
| 4908 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 4909 | } |
| 4910 | __ j(kNotEqual, &loop); |
| 4911 | __ movl(out, Immediate(1)); |
| 4912 | if (zero.IsLinked()) { |
| 4913 | __ jmp(&done); |
| 4914 | } |
| 4915 | break; |
| 4916 | } |
| 4917 | case TypeCheckKind::kClassHierarchyCheck: { |
| 4918 | // Walk over the class hierarchy to find a match. |
| 4919 | NearLabel loop, success; |
| 4920 | __ Bind(&loop); |
| 4921 | if (cls.IsRegister()) { |
| 4922 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 4923 | } else { |
| 4924 | DCHECK(cls.IsStackSlot()) << cls; |
| 4925 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 4926 | } |
| 4927 | __ j(kEqual, &success); |
| 4928 | __ movl(out, Address(out, super_offset)); |
| 4929 | __ MaybeUnpoisonHeapReference(out); |
| 4930 | __ testl(out, out); |
| 4931 | __ j(kNotEqual, &loop); |
| 4932 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4933 | __ jmp(&done); |
| 4934 | __ Bind(&success); |
| 4935 | __ movl(out, Immediate(1)); |
| 4936 | if (zero.IsLinked()) { |
| 4937 | __ jmp(&done); |
| 4938 | } |
| 4939 | break; |
| 4940 | } |
| 4941 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4942 | // Do an exact check. |
| 4943 | NearLabel exact_check; |
| 4944 | if (cls.IsRegister()) { |
| 4945 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 4946 | } else { |
| 4947 | DCHECK(cls.IsStackSlot()) << cls; |
| 4948 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 4949 | } |
| 4950 | __ j(kEqual, &exact_check); |
| 4951 | // Otherwise, we need to check that the object's class is a non primitive array. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4952 | __ movl(out, Address(out, component_offset)); |
| 4953 | __ MaybeUnpoisonHeapReference(out); |
| 4954 | __ testl(out, out); |
| 4955 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4956 | __ j(kEqual, &done); |
| 4957 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 4958 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4959 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4960 | __ movl(out, Immediate(1)); |
| 4961 | __ jmp(&done); |
| 4962 | break; |
| 4963 | } |
| 4964 | case TypeCheckKind::kArrayCheck: { |
| 4965 | if (cls.IsRegister()) { |
| 4966 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 4967 | } else { |
| 4968 | DCHECK(cls.IsStackSlot()) << cls; |
| 4969 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 4970 | } |
| 4971 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 4972 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64( |
| 4973 | instruction, /* is_fatal */ false); |
| 4974 | codegen_->AddSlowPath(slow_path); |
| 4975 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4976 | __ movl(out, Immediate(1)); |
| 4977 | if (zero.IsLinked()) { |
| 4978 | __ jmp(&done); |
| 4979 | } |
| 4980 | break; |
| 4981 | } |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4982 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4983 | case TypeCheckKind::kInterfaceCheck: |
| 4984 | default: { |
| 4985 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 4986 | instruction, |
| 4987 | instruction->GetDexPc(), |
| 4988 | nullptr); |
| 4989 | if (zero.IsLinked()) { |
| 4990 | __ jmp(&done); |
| 4991 | } |
| 4992 | break; |
| 4993 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4994 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4995 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4996 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4997 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4998 | __ xorl(out, out); |
| 4999 | } |
| 5000 | |
| 5001 | if (done.IsLinked()) { |
| 5002 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5003 | } |
| 5004 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5005 | if (slow_path != nullptr) { |
| 5006 | __ Bind(slow_path->GetExitLabel()); |
| 5007 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5008 | } |
| 5009 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5010 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5011 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5012 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 5013 | |
| 5014 | switch (instruction->GetTypeCheckKind()) { |
| 5015 | case TypeCheckKind::kExactCheck: |
| 5016 | case TypeCheckKind::kAbstractClassCheck: |
| 5017 | case TypeCheckKind::kClassHierarchyCheck: |
| 5018 | case TypeCheckKind::kArrayObjectCheck: |
| 5019 | call_kind = throws_into_catch |
| 5020 | ? LocationSummary::kCallOnSlowPath |
| 5021 | : LocationSummary::kNoCall; |
| 5022 | break; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5023 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5024 | case TypeCheckKind::kInterfaceCheck: |
| 5025 | call_kind = LocationSummary::kCall; |
| 5026 | break; |
| 5027 | case TypeCheckKind::kArrayCheck: |
| 5028 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5029 | break; |
| 5030 | } |
| 5031 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5032 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5033 | instruction, call_kind); |
| 5034 | if (call_kind != LocationSummary::kCall) { |
| 5035 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5036 | locations->SetInAt(1, Location::Any()); |
| 5037 | // Note that TypeCheckSlowPathX86_64 uses this register too. |
| 5038 | locations->AddTemp(Location::RequiresRegister()); |
| 5039 | } else { |
| 5040 | InvokeRuntimeCallingConvention calling_convention; |
| 5041 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5042 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5043 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5044 | } |
| 5045 | |
| 5046 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
| 5047 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5048 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5049 | Location cls = locations->InAt(1); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5050 | CpuRegister temp = locations->WillCall() |
| 5051 | ? CpuRegister(kNoRegister) |
| 5052 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame] | 5053 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5054 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5055 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5056 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5057 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 5058 | SlowPathCode* slow_path = nullptr; |
| 5059 | |
| 5060 | if (!locations->WillCall()) { |
| 5061 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64( |
| 5062 | instruction, !locations->CanCall()); |
| 5063 | codegen_->AddSlowPath(slow_path); |
| 5064 | } |
| 5065 | |
| 5066 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5067 | // Avoid null check if we know obj is not null. |
| 5068 | if (instruction->MustDoNullCheck()) { |
| 5069 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5070 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5071 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5072 | |
| 5073 | if (locations->WillCall()) { |
| 5074 | __ movl(obj, Address(obj, class_offset)); |
| 5075 | __ MaybeUnpoisonHeapReference(obj); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5076 | } else { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5077 | __ movl(temp, Address(obj, class_offset)); |
| 5078 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5079 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5080 | |
| 5081 | switch (instruction->GetTypeCheckKind()) { |
| 5082 | case TypeCheckKind::kExactCheck: |
| 5083 | case TypeCheckKind::kArrayCheck: { |
| 5084 | if (cls.IsRegister()) { |
| 5085 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5086 | } else { |
| 5087 | DCHECK(cls.IsStackSlot()) << cls; |
| 5088 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5089 | } |
| 5090 | // Jump to slow path for throwing the exception or doing a |
| 5091 | // more involved array check. |
| 5092 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5093 | break; |
| 5094 | } |
| 5095 | case TypeCheckKind::kAbstractClassCheck: { |
| 5096 | // If the class is abstract, we eagerly fetch the super class of the |
| 5097 | // object to avoid doing a comparison we know will fail. |
| 5098 | NearLabel loop; |
| 5099 | __ Bind(&loop); |
| 5100 | __ movl(temp, Address(temp, super_offset)); |
| 5101 | __ MaybeUnpoisonHeapReference(temp); |
| 5102 | __ testl(temp, temp); |
| 5103 | // Jump to the slow path to throw the exception. |
| 5104 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5105 | if (cls.IsRegister()) { |
| 5106 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5107 | } else { |
| 5108 | DCHECK(cls.IsStackSlot()) << cls; |
| 5109 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5110 | } |
| 5111 | __ j(kNotEqual, &loop); |
| 5112 | break; |
| 5113 | } |
| 5114 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5115 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5116 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5117 | __ Bind(&loop); |
| 5118 | if (cls.IsRegister()) { |
| 5119 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5120 | } else { |
| 5121 | DCHECK(cls.IsStackSlot()) << cls; |
| 5122 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5123 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5124 | __ j(kEqual, &done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5125 | __ movl(temp, Address(temp, super_offset)); |
| 5126 | __ MaybeUnpoisonHeapReference(temp); |
| 5127 | __ testl(temp, temp); |
| 5128 | __ j(kNotEqual, &loop); |
| 5129 | // Jump to the slow path to throw the exception. |
| 5130 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5131 | break; |
| 5132 | } |
| 5133 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5134 | // Do an exact check. |
| 5135 | if (cls.IsRegister()) { |
| 5136 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5137 | } else { |
| 5138 | DCHECK(cls.IsStackSlot()) << cls; |
| 5139 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5140 | } |
| 5141 | __ j(kEqual, &done); |
| 5142 | // Otherwise, we need to check that the object's class is a non primitive array. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5143 | __ movl(temp, Address(temp, component_offset)); |
| 5144 | __ MaybeUnpoisonHeapReference(temp); |
| 5145 | __ testl(temp, temp); |
| 5146 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5147 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5148 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5149 | break; |
| 5150 | } |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5151 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5152 | case TypeCheckKind::kInterfaceCheck: |
| 5153 | default: |
| 5154 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 5155 | instruction, |
| 5156 | instruction->GetDexPc(), |
| 5157 | nullptr); |
| 5158 | break; |
| 5159 | } |
| 5160 | __ Bind(&done); |
| 5161 | |
| 5162 | if (slow_path != nullptr) { |
| 5163 | __ Bind(slow_path->GetExitLabel()); |
| 5164 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5165 | } |
| 5166 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5167 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5168 | LocationSummary* locations = |
| 5169 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5170 | InvokeRuntimeCallingConvention calling_convention; |
| 5171 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5172 | } |
| 5173 | |
| 5174 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5175 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 5176 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 5177 | instruction, |
| 5178 | instruction->GetDexPc(), |
| 5179 | nullptr); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5180 | } |
| 5181 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5182 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 5183 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 5184 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 5185 | |
| 5186 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5187 | LocationSummary* locations = |
| 5188 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5189 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 5190 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 5191 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5192 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5193 | locations->SetOut(Location::SameAsFirstInput()); |
| 5194 | } |
| 5195 | |
| 5196 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 5197 | HandleBitwiseOperation(instruction); |
| 5198 | } |
| 5199 | |
| 5200 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 5201 | HandleBitwiseOperation(instruction); |
| 5202 | } |
| 5203 | |
| 5204 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 5205 | HandleBitwiseOperation(instruction); |
| 5206 | } |
| 5207 | |
| 5208 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5209 | LocationSummary* locations = instruction->GetLocations(); |
| 5210 | Location first = locations->InAt(0); |
| 5211 | Location second = locations->InAt(1); |
| 5212 | DCHECK(first.Equals(locations->Out())); |
| 5213 | |
| 5214 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 5215 | if (second.IsRegister()) { |
| 5216 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5217 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5218 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5219 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5220 | } else { |
| 5221 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5222 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5223 | } |
| 5224 | } else if (second.IsConstant()) { |
| 5225 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 5226 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5227 | __ andl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5228 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5229 | __ orl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5230 | } else { |
| 5231 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5232 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5233 | } |
| 5234 | } else { |
| 5235 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 5236 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5237 | __ andl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5238 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5239 | __ orl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5240 | } else { |
| 5241 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5242 | __ xorl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5243 | } |
| 5244 | } |
| 5245 | } else { |
| 5246 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5247 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 5248 | bool second_is_constant = false; |
| 5249 | int64_t value = 0; |
| 5250 | if (second.IsConstant()) { |
| 5251 | second_is_constant = true; |
| 5252 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5253 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5254 | bool is_int32_value = IsInt<32>(value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5255 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5256 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5257 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5258 | if (is_int32_value) { |
| 5259 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 5260 | } else { |
| 5261 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 5262 | } |
| 5263 | } else if (second.IsDoubleStackSlot()) { |
| 5264 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5265 | } else { |
| 5266 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 5267 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5268 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5269 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5270 | if (is_int32_value) { |
| 5271 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 5272 | } else { |
| 5273 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 5274 | } |
| 5275 | } else if (second.IsDoubleStackSlot()) { |
| 5276 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5277 | } else { |
| 5278 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 5279 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5280 | } else { |
| 5281 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5282 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5283 | if (is_int32_value) { |
| 5284 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 5285 | } else { |
| 5286 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 5287 | } |
| 5288 | } else if (second.IsDoubleStackSlot()) { |
| 5289 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5290 | } else { |
| 5291 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 5292 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5293 | } |
| 5294 | } |
| 5295 | } |
| 5296 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5297 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction) { |
| 5298 | // Nothing to do, this should be removed during prepare for register allocator. |
| 5299 | UNUSED(instruction); |
| 5300 | LOG(FATAL) << "Unreachable"; |
| 5301 | } |
| 5302 | |
| 5303 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction) { |
| 5304 | // Nothing to do, this should be removed during prepare for register allocator. |
| 5305 | UNUSED(instruction); |
| 5306 | LOG(FATAL) << "Unreachable"; |
| 5307 | } |
| 5308 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5309 | void LocationsBuilderX86_64::VisitFakeString(HFakeString* instruction) { |
| 5310 | DCHECK(codegen_->IsBaseline()); |
| 5311 | LocationSummary* locations = |
| 5312 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5313 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); |
| 5314 | } |
| 5315 | |
| 5316 | void InstructionCodeGeneratorX86_64::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { |
| 5317 | DCHECK(codegen_->IsBaseline()); |
| 5318 | // Will be generated at use site. |
| 5319 | } |
| 5320 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5321 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 5322 | void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5323 | LocationSummary* locations = |
| 5324 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 5325 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame^] | 5326 | locations->AddTemp(Location::RequiresRegister()); |
| 5327 | locations->AddTemp(Location::RequiresRegister()); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5328 | } |
| 5329 | |
| 5330 | void InstructionCodeGeneratorX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5331 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 5332 | int32_t num_entries = switch_instr->GetNumEntries(); |
| 5333 | LocationSummary* locations = switch_instr->GetLocations(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame^] | 5334 | CpuRegister value_reg_in = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5335 | CpuRegister temp_reg = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 5336 | CpuRegister base_reg = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 5337 | |
| 5338 | // Remove the bias, if needed. |
| 5339 | Register value_reg_out = value_reg_in.AsRegister(); |
| 5340 | if (lower_bound != 0) { |
| 5341 | __ leal(temp_reg, Address(value_reg_in, -lower_bound)); |
| 5342 | value_reg_out = temp_reg.AsRegister(); |
| 5343 | } |
| 5344 | CpuRegister value_reg(value_reg_out); |
| 5345 | |
| 5346 | // Is the value in range? |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5347 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame^] | 5348 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 5349 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5350 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame^] | 5351 | // We are in the range of the table. |
| 5352 | // Load the address of the jump table in the constant area. |
| 5353 | __ leaq(base_reg, codegen_->LiteralCaseTable(switch_instr)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5354 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame^] | 5355 | // Load the (signed) offset from the jump table. |
| 5356 | __ movsxd(temp_reg, Address(base_reg, value_reg, TIMES_4, 0)); |
| 5357 | |
| 5358 | // Add the offset to the address of the table base. |
| 5359 | __ addq(temp_reg, base_reg); |
| 5360 | |
| 5361 | // And jump. |
| 5362 | __ jmp(temp_reg); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5363 | } |
| 5364 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5365 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 5366 | if (value == 0) { |
| 5367 | __ xorl(dest, dest); |
| 5368 | } else if (value > 0 && IsInt<32>(value)) { |
| 5369 | // We can use a 32 bit move, as it will zero-extend and is one byte shorter. |
| 5370 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 5371 | } else { |
| 5372 | __ movq(dest, Immediate(value)); |
| 5373 | } |
| 5374 | } |
| 5375 | |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5376 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 5377 | DCHECK(dest.IsDoubleStackSlot()); |
| 5378 | if (IsInt<32>(value)) { |
| 5379 | // Can move directly as an int32 constant. |
| 5380 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 5381 | Immediate(static_cast<int32_t>(value))); |
| 5382 | } else { |
| 5383 | Load64BitValue(CpuRegister(TMP), value); |
| 5384 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 5385 | } |
| 5386 | } |
| 5387 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame^] | 5388 | /** |
| 5389 | * Class to handle late fixup of offsets into constant area. |
| 5390 | */ |
| 5391 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
| 5392 | public: |
| 5393 | RIPFixup(CodeGeneratorX86_64& codegen, size_t offset) |
| 5394 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 5395 | |
| 5396 | protected: |
| 5397 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 5398 | |
| 5399 | CodeGeneratorX86_64* codegen_; |
| 5400 | |
| 5401 | private: |
| 5402 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 5403 | // Patch the correct offset for the instruction. We use the address of the |
| 5404 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 5405 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 5406 | int32_t relative_position = constant_offset - pos; |
| 5407 | |
| 5408 | // Patch in the right value. |
| 5409 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 5410 | } |
| 5411 | |
| 5412 | // Location in constant area that the fixup refers to. |
| 5413 | size_t offset_into_constant_area_; |
| 5414 | }; |
| 5415 | |
| 5416 | /** |
| 5417 | t * Class to handle late fixup of offsets to a jump table that will be created in the |
| 5418 | * constant area. |
| 5419 | */ |
| 5420 | class JumpTableRIPFixup : public RIPFixup { |
| 5421 | public: |
| 5422 | JumpTableRIPFixup(CodeGeneratorX86_64& codegen, HPackedSwitch* switch_instr) |
| 5423 | : RIPFixup(codegen, -1), switch_instr_(switch_instr) {} |
| 5424 | |
| 5425 | void CreateJumpTable() { |
| 5426 | X86_64Assembler* assembler = codegen_->GetAssembler(); |
| 5427 | |
| 5428 | // Ensure that the reference to the jump table has the correct offset. |
| 5429 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 5430 | SetOffset(offset_in_constant_table); |
| 5431 | |
| 5432 | // Compute the offset from the start of the function to this jump table. |
| 5433 | const int32_t current_table_offset = assembler->CodeSize() + offset_in_constant_table; |
| 5434 | |
| 5435 | // Populate the jump table with the correct values for the jump table. |
| 5436 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 5437 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 5438 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 5439 | // The value that we want is the target offset - the position of the table. |
| 5440 | for (int32_t i = 0; i < num_entries; i++) { |
| 5441 | HBasicBlock* b = successors[i]; |
| 5442 | Label* l = codegen_->GetLabelOf(b); |
| 5443 | DCHECK(l->IsBound()); |
| 5444 | int32_t offset_to_block = l->Position() - current_table_offset; |
| 5445 | assembler->AppendInt32(offset_to_block); |
| 5446 | } |
| 5447 | } |
| 5448 | |
| 5449 | private: |
| 5450 | const HPackedSwitch* switch_instr_; |
| 5451 | }; |
| 5452 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 5453 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 5454 | // Generate the constant area if needed. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 5455 | X86_64Assembler* assembler = GetAssembler(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame^] | 5456 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 5457 | // 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] | 5458 | assembler->Align(4, 0); |
| 5459 | constant_area_start_ = assembler->CodeSize(); |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame^] | 5460 | |
| 5461 | // Populate any jump tables. |
| 5462 | for (auto jump_table : fixups_to_jump_tables_) { |
| 5463 | jump_table->CreateJumpTable(); |
| 5464 | } |
| 5465 | |
| 5466 | // And now add the constant area to the generated code. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 5467 | assembler->AddConstantArea(); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 5468 | } |
| 5469 | |
| 5470 | // And finish up. |
| 5471 | CodeGenerator::Finalize(allocator); |
| 5472 | } |
| 5473 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 5474 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
| 5475 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 5476 | return Address::RIP(fixup); |
| 5477 | } |
| 5478 | |
| 5479 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
| 5480 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 5481 | return Address::RIP(fixup); |
| 5482 | } |
| 5483 | |
| 5484 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
| 5485 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 5486 | return Address::RIP(fixup); |
| 5487 | } |
| 5488 | |
| 5489 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
| 5490 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 5491 | return Address::RIP(fixup); |
| 5492 | } |
| 5493 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5494 | // TODO: trg as memory. |
| 5495 | void CodeGeneratorX86_64::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 5496 | if (!trg.IsValid()) { |
| 5497 | DCHECK(type == Primitive::kPrimVoid); |
| 5498 | return; |
| 5499 | } |
| 5500 | |
| 5501 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 5502 | |
| 5503 | Location return_loc = InvokeDexCallingConventionVisitorX86_64().GetReturnLocation(type); |
| 5504 | if (trg.Equals(return_loc)) { |
| 5505 | return; |
| 5506 | } |
| 5507 | |
| 5508 | // Let the parallel move resolver take care of all of this. |
| 5509 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 5510 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 5511 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 5512 | } |
| 5513 | |
Mark Mendell | 9c86b48 | 2015-09-18 13:36:07 -0400 | [diff] [blame^] | 5514 | Address CodeGeneratorX86_64::LiteralCaseTable(HPackedSwitch* switch_instr) { |
| 5515 | // Create a fixup to be used to create and address the jump table. |
| 5516 | JumpTableRIPFixup* table_fixup = |
| 5517 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 5518 | |
| 5519 | // We have to populate the jump tables. |
| 5520 | fixups_to_jump_tables_.push_back(table_fixup); |
| 5521 | return Address::RIP(table_fixup); |
| 5522 | } |
| 5523 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5524 | #undef __ |
| 5525 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5526 | } // namespace x86_64 |
| 5527 | } // namespace art |