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 | // Some x86_64 instructions require a register to be available as temp. |
| 40 | static constexpr Register TMP = R11; |
| 41 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 42 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 43 | static constexpr Register kMethodRegisterArgument = RDI; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 44 | |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 45 | static constexpr Register kCoreCalleeSaves[] = { RBX, RBP, R12, R13, R14, R15 }; |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 46 | static constexpr FloatRegister kFpuCalleeSaves[] = { XMM12, XMM13, XMM14, XMM15 }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 47 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 48 | static constexpr int kC2ConditionMask = 0x400; |
| 49 | |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 50 | #define __ down_cast<X86_64Assembler*>(codegen->GetAssembler())-> |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 51 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 52 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 53 | class NullCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 54 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 55 | explicit NullCheckSlowPathX86_64(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 56 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 57 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 58 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 59 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 60 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 61 | // Live registers will be restored in the catch block if caught. |
| 62 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 63 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 64 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), |
| 65 | instruction_, |
| 66 | instruction_->GetDexPc(), |
| 67 | this); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 68 | } |
| 69 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 70 | bool IsFatal() const OVERRIDE { return true; } |
| 71 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 72 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86_64"; } |
| 73 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 74 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 75 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 76 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86_64); |
| 77 | }; |
| 78 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 79 | class DivZeroCheckSlowPathX86_64 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 80 | public: |
| 81 | explicit DivZeroCheckSlowPathX86_64(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 82 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 83 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 84 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 85 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 86 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 87 | // Live registers will be restored in the catch block if caught. |
| 88 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 89 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 90 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), |
| 91 | instruction_, |
| 92 | instruction_->GetDexPc(), |
| 93 | this); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 96 | bool IsFatal() const OVERRIDE { return true; } |
| 97 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 98 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86_64"; } |
| 99 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 100 | private: |
| 101 | HDivZeroCheck* const instruction_; |
| 102 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86_64); |
| 103 | }; |
| 104 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 105 | class DivRemMinusOneSlowPathX86_64 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 106 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 107 | DivRemMinusOneSlowPathX86_64(Register reg, Primitive::Type type, bool is_div) |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 108 | : cpu_reg_(CpuRegister(reg)), type_(type), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 109 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 110 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 111 | __ Bind(GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 112 | if (type_ == Primitive::kPrimInt) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 113 | if (is_div_) { |
| 114 | __ negl(cpu_reg_); |
| 115 | } else { |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 116 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 119 | } else { |
| 120 | DCHECK_EQ(Primitive::kPrimLong, type_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 121 | if (is_div_) { |
| 122 | __ negq(cpu_reg_); |
| 123 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 124 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 125 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 126 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 127 | __ jmp(GetExitLabel()); |
| 128 | } |
| 129 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 130 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86_64"; } |
| 131 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 132 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 133 | const CpuRegister cpu_reg_; |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 134 | const Primitive::Type type_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 135 | const bool is_div_; |
| 136 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86_64); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 137 | }; |
| 138 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 139 | class SuspendCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 140 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 141 | SuspendCheckSlowPathX86_64(HSuspendCheck* instruction, HBasicBlock* successor) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 142 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 143 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 144 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 145 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 146 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 147 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 148 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), |
| 149 | instruction_, |
| 150 | instruction_->GetDexPc(), |
| 151 | this); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 152 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 153 | if (successor_ == nullptr) { |
| 154 | __ jmp(GetReturnLabel()); |
| 155 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 156 | __ jmp(x64_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 157 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 160 | Label* GetReturnLabel() { |
| 161 | DCHECK(successor_ == nullptr); |
| 162 | return &return_label_; |
| 163 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 164 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 165 | HBasicBlock* GetSuccessor() const { |
| 166 | return successor_; |
| 167 | } |
| 168 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 169 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86_64"; } |
| 170 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 171 | private: |
| 172 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 173 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 174 | Label return_label_; |
| 175 | |
| 176 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64); |
| 177 | }; |
| 178 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 179 | class BoundsCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 180 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 181 | explicit BoundsCheckSlowPathX86_64(HBoundsCheck* instruction) |
| 182 | : instruction_(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 183 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 184 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 185 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 186 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 187 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 188 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 189 | // Live registers will be restored in the catch block if caught. |
| 190 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 191 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 192 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 193 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 194 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 195 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 196 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 197 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 198 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 199 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 200 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 201 | Primitive::kPrimInt); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 202 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds), |
| 203 | instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 204 | } |
| 205 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 206 | bool IsFatal() const OVERRIDE { return true; } |
| 207 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 208 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86_64"; } |
| 209 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 210 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 211 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 212 | |
| 213 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 214 | }; |
| 215 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 216 | class LoadClassSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 217 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 218 | LoadClassSlowPathX86_64(HLoadClass* cls, |
| 219 | HInstruction* at, |
| 220 | uint32_t dex_pc, |
| 221 | bool do_clinit) |
| 222 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 223 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 224 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 225 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 226 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 227 | LocationSummary* locations = at_->GetLocations(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 228 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 229 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 230 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 231 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 232 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 233 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 234 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(cls_->GetTypeIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 235 | x64_codegen->InvokeRuntime(do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 236 | : QUICK_ENTRY_POINT(pInitializeType), |
| 237 | at_, dex_pc_, this); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 238 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 239 | Location out = locations->Out(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 240 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 241 | if (out.IsValid()) { |
| 242 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 243 | x64_codegen->Move(out, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 244 | } |
| 245 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 246 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 247 | __ jmp(GetExitLabel()); |
| 248 | } |
| 249 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 250 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86_64"; } |
| 251 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 252 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 253 | // The class this slow path will load. |
| 254 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 255 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 256 | // The instruction where this slow path is happening. |
| 257 | // (Might be the load class or an initialization check). |
| 258 | HInstruction* const at_; |
| 259 | |
| 260 | // The dex PC of `at_`. |
| 261 | const uint32_t dex_pc_; |
| 262 | |
| 263 | // Whether to initialize the class. |
| 264 | const bool do_clinit_; |
| 265 | |
| 266 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86_64); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 267 | }; |
| 268 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 269 | class LoadStringSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 270 | public: |
| 271 | explicit LoadStringSlowPathX86_64(HLoadString* instruction) : instruction_(instruction) {} |
| 272 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 273 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 274 | LocationSummary* locations = instruction_->GetLocations(); |
| 275 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 276 | |
| 277 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 278 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 279 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 280 | |
| 281 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 282 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 283 | Immediate(instruction_->GetStringIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 284 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), |
| 285 | instruction_, |
| 286 | instruction_->GetDexPc(), |
| 287 | this); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 288 | x64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 289 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 290 | __ jmp(GetExitLabel()); |
| 291 | } |
| 292 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 293 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86_64"; } |
| 294 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 295 | private: |
| 296 | HLoadString* const instruction_; |
| 297 | |
| 298 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86_64); |
| 299 | }; |
| 300 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 301 | class TypeCheckSlowPathX86_64 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 302 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 303 | TypeCheckSlowPathX86_64(HInstruction* instruction, bool is_fatal) |
| 304 | : instruction_(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 305 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 306 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 307 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 308 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 309 | : locations->Out(); |
| 310 | uint32_t dex_pc = instruction_->GetDexPc(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 311 | DCHECK(instruction_->IsCheckCast() |
| 312 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 313 | |
| 314 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 315 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 316 | |
| 317 | if (instruction_->IsCheckCast()) { |
| 318 | // The codegen for the instruction overwrites `temp`, so put it back in place. |
| 319 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 320 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 321 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 322 | __ movl(temp, Address(obj, class_offset)); |
| 323 | __ MaybeUnpoisonHeapReference(temp); |
| 324 | } |
| 325 | |
| 326 | if (!is_fatal_) { |
| 327 | SaveLiveRegisters(codegen, locations); |
| 328 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 329 | |
| 330 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 331 | // move resolver. |
| 332 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 333 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 334 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 335 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 336 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 337 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 338 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 339 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 340 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 341 | if (instruction_->IsInstanceOf()) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 342 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 343 | instruction_, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 344 | dex_pc, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 345 | this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 346 | } else { |
| 347 | DCHECK(instruction_->IsCheckCast()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 348 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 349 | instruction_, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 350 | dex_pc, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 351 | this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 352 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 353 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 354 | if (!is_fatal_) { |
| 355 | if (instruction_->IsInstanceOf()) { |
| 356 | x64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
| 357 | } |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 358 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 359 | RestoreLiveRegisters(codegen, locations); |
| 360 | __ jmp(GetExitLabel()); |
| 361 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 362 | } |
| 363 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 364 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86_64"; } |
| 365 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 366 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
| 367 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 368 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 369 | HInstruction* const instruction_; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 370 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 371 | |
| 372 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86_64); |
| 373 | }; |
| 374 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 375 | class DeoptimizationSlowPathX86_64 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 376 | public: |
| 377 | explicit DeoptimizationSlowPathX86_64(HInstruction* instruction) |
| 378 | : instruction_(instruction) {} |
| 379 | |
| 380 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 381 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 382 | __ Bind(GetEntryLabel()); |
| 383 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 384 | DCHECK(instruction_->IsDeoptimize()); |
| 385 | HDeoptimize* deoptimize = instruction_->AsDeoptimize(); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 386 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 387 | deoptimize, |
| 388 | deoptimize->GetDexPc(), |
| 389 | this); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 392 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86_64"; } |
| 393 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 394 | private: |
| 395 | HInstruction* const instruction_; |
| 396 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86_64); |
| 397 | }; |
| 398 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 399 | class ArraySetSlowPathX86_64 : public SlowPathCode { |
| 400 | public: |
| 401 | explicit ArraySetSlowPathX86_64(HInstruction* instruction) : instruction_(instruction) {} |
| 402 | |
| 403 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 404 | LocationSummary* locations = instruction_->GetLocations(); |
| 405 | __ Bind(GetEntryLabel()); |
| 406 | SaveLiveRegisters(codegen, locations); |
| 407 | |
| 408 | InvokeRuntimeCallingConvention calling_convention; |
| 409 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 410 | parallel_move.AddMove( |
| 411 | locations->InAt(0), |
| 412 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 413 | Primitive::kPrimNot, |
| 414 | nullptr); |
| 415 | parallel_move.AddMove( |
| 416 | locations->InAt(1), |
| 417 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 418 | Primitive::kPrimInt, |
| 419 | nullptr); |
| 420 | parallel_move.AddMove( |
| 421 | locations->InAt(2), |
| 422 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 423 | Primitive::kPrimNot, |
| 424 | nullptr); |
| 425 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 426 | |
| 427 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 428 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 429 | instruction_, |
| 430 | instruction_->GetDexPc(), |
| 431 | this); |
| 432 | RestoreLiveRegisters(codegen, locations); |
| 433 | __ jmp(GetExitLabel()); |
| 434 | } |
| 435 | |
| 436 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86_64"; } |
| 437 | |
| 438 | private: |
| 439 | HInstruction* const instruction_; |
| 440 | |
| 441 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86_64); |
| 442 | }; |
| 443 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 444 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 445 | #define __ down_cast<X86_64Assembler*>(GetAssembler())-> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 446 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 447 | inline Condition X86_64IntegerCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 448 | switch (cond) { |
| 449 | case kCondEQ: return kEqual; |
| 450 | case kCondNE: return kNotEqual; |
| 451 | case kCondLT: return kLess; |
| 452 | case kCondLE: return kLessEqual; |
| 453 | case kCondGT: return kGreater; |
| 454 | case kCondGE: return kGreaterEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 455 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 456 | LOG(FATAL) << "Unreachable"; |
| 457 | UNREACHABLE(); |
| 458 | } |
| 459 | |
| 460 | inline Condition X86_64FPCondition(IfCondition cond) { |
| 461 | switch (cond) { |
| 462 | case kCondEQ: return kEqual; |
| 463 | case kCondNE: return kNotEqual; |
| 464 | case kCondLT: return kBelow; |
| 465 | case kCondLE: return kBelowEqual; |
| 466 | case kCondGT: return kAbove; |
| 467 | case kCondGE: return kAboveEqual; |
| 468 | }; |
| 469 | LOG(FATAL) << "Unreachable"; |
| 470 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 471 | } |
| 472 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 473 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 474 | Location temp) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 475 | // All registers are assumed to be correctly set up. |
| 476 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 477 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 478 | switch (invoke->GetMethodLoadKind()) { |
| 479 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 480 | // temp = thread->string_init_entrypoint |
| 481 | __ gs()->movl(temp.AsRegister<CpuRegister>(), |
| 482 | Address::Absolute(invoke->GetStringInitOffset(), true)); |
| 483 | break; |
| 484 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 485 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 486 | break; |
| 487 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 488 | __ movq(temp.AsRegister<CpuRegister>(), Immediate(invoke->GetMethodAddress())); |
| 489 | break; |
| 490 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 491 | __ movl(temp.AsRegister<CpuRegister>(), Immediate(0)); // Placeholder. |
| 492 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 493 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 494 | break; |
| 495 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
| 496 | pc_rel_dex_cache_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 497 | invoke->GetDexCacheArrayOffset()); |
| 498 | __ movq(temp.AsRegister<CpuRegister>(), |
| 499 | Address::Absolute(kDummy32BitOffset, false /* no_rip */)); |
| 500 | // Bind the label at the end of the "movl" insn. |
| 501 | __ Bind(&pc_rel_dex_cache_patches_.back().label); |
| 502 | break; |
| 503 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
| 504 | Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 505 | Register method_reg; |
| 506 | CpuRegister reg = temp.AsRegister<CpuRegister>(); |
| 507 | if (current_method.IsRegister()) { |
| 508 | method_reg = current_method.AsRegister<Register>(); |
| 509 | } else { |
| 510 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 511 | DCHECK(!current_method.IsValid()); |
| 512 | method_reg = reg.AsRegister(); |
| 513 | __ movq(reg, Address(CpuRegister(RSP), kCurrentMethodStackOffset)); |
| 514 | } |
| 515 | // temp = temp->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 516 | __ movq(reg, |
| 517 | Address(CpuRegister(method_reg), |
| 518 | ArtMethod::DexCacheResolvedMethodsOffset(kX86_64PointerSize).SizeValue())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 519 | // temp = temp[index_in_cache] |
| 520 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 521 | __ movq(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 522 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 523 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | switch (invoke->GetCodePtrLocation()) { |
| 527 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 528 | __ call(&frame_entry_label_); |
| 529 | break; |
| 530 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 531 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 532 | Label* label = &relative_call_patches_.back().label; |
| 533 | __ call(label); // Bind to the patch label, override at link time. |
| 534 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 535 | break; |
| 536 | } |
| 537 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 538 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 539 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 540 | FALLTHROUGH_INTENDED; |
| 541 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 542 | // (callee_method + offset_of_quick_compiled_code)() |
| 543 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 544 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 545 | kX86_64WordSize).SizeValue())); |
| 546 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 547 | } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 548 | |
| 549 | DCHECK(!IsLeafMethod()); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 550 | } |
| 551 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 552 | void CodeGeneratorX86_64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 553 | CpuRegister temp = temp_in.AsRegister<CpuRegister>(); |
| 554 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 555 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
| 556 | LocationSummary* locations = invoke->GetLocations(); |
| 557 | Location receiver = locations->InAt(0); |
| 558 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 559 | // temp = object->GetClass(); |
| 560 | DCHECK(receiver.IsRegister()); |
| 561 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
| 562 | MaybeRecordImplicitNullCheck(invoke); |
| 563 | __ MaybeUnpoisonHeapReference(temp); |
| 564 | // temp = temp->GetMethodAt(method_offset); |
| 565 | __ movq(temp, Address(temp, method_offset)); |
| 566 | // call temp->GetEntryPoint(); |
| 567 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 568 | kX86_64WordSize).SizeValue())); |
| 569 | } |
| 570 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 571 | void CodeGeneratorX86_64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 572 | DCHECK(linker_patches->empty()); |
| 573 | size_t size = |
| 574 | method_patches_.size() + relative_call_patches_.size() + pc_rel_dex_cache_patches_.size(); |
| 575 | linker_patches->reserve(size); |
| 576 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
| 577 | // The label points to the end of the "movl" instruction but the literal offset for method |
| 578 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 579 | uint32_t literal_offset = info.label.Position() - 4; |
| 580 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 581 | info.target_method.dex_file, |
| 582 | info.target_method.dex_method_index)); |
| 583 | } |
| 584 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
| 585 | // The label points to the end of the "call" instruction but the literal offset for method |
| 586 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 587 | uint32_t literal_offset = info.label.Position() - 4; |
| 588 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 589 | info.target_method.dex_file, |
| 590 | info.target_method.dex_method_index)); |
| 591 | } |
| 592 | for (const PcRelativeDexCacheAccessInfo& info : pc_rel_dex_cache_patches_) { |
| 593 | // The label points to the end of the "mov" instruction but the literal offset for method |
| 594 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 595 | uint32_t literal_offset = info.label.Position() - 4; |
| 596 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 597 | &info.target_dex_file, |
| 598 | info.label.Position(), |
| 599 | info.element_offset)); |
| 600 | } |
| 601 | } |
| 602 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 603 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 604 | stream << Register(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 608 | stream << FloatRegister(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 609 | } |
| 610 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 611 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 612 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 613 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 614 | } |
| 615 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 616 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 617 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 618 | return kX86_64WordSize; |
| 619 | } |
| 620 | |
| 621 | size_t CodeGeneratorX86_64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 622 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 623 | return kX86_64WordSize; |
| 624 | } |
| 625 | |
| 626 | size_t CodeGeneratorX86_64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 627 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 628 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 629 | } |
| 630 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 631 | void CodeGeneratorX86_64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 632 | HInstruction* instruction, |
| 633 | uint32_t dex_pc, |
| 634 | SlowPathCode* slow_path) { |
| 635 | InvokeRuntime(GetThreadOffset<kX86_64WordSize>(entrypoint).Int32Value(), |
| 636 | instruction, |
| 637 | dex_pc, |
| 638 | slow_path); |
| 639 | } |
| 640 | |
| 641 | void CodeGeneratorX86_64::InvokeRuntime(int32_t entry_point_offset, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 642 | HInstruction* instruction, |
| 643 | uint32_t dex_pc, |
| 644 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 645 | ValidateInvokeRuntime(instruction, slow_path); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 646 | __ gs()->call(Address::Absolute(entry_point_offset, true)); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 647 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 648 | } |
| 649 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 650 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 651 | // Use a fake return address register to mimic Quick. |
| 652 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 653 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
| 654 | const X86_64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 655 | const CompilerOptions& compiler_options, |
| 656 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 657 | : CodeGenerator(graph, |
| 658 | kNumberOfCpuRegisters, |
| 659 | kNumberOfFloatRegisters, |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 660 | kNumberOfCpuRegisterPairs, |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 661 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 662 | arraysize(kCoreCalleeSaves)) |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 663 | | (1 << kFakeReturnRegister), |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 664 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 665 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 666 | compiler_options, |
| 667 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 668 | block_labels_(nullptr), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 669 | location_builder_(graph, this), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 670 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 671 | move_resolver_(graph->GetArena(), this), |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 672 | isa_features_(isa_features), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 673 | constant_area_start_(0), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 674 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 675 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 676 | pc_rel_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 677 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 678 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 679 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 680 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 681 | CodeGeneratorX86_64* codegen) |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 682 | : HGraphVisitor(graph), |
| 683 | assembler_(codegen->GetAssembler()), |
| 684 | codegen_(codegen) {} |
| 685 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 686 | Location CodeGeneratorX86_64::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 687 | switch (type) { |
| 688 | case Primitive::kPrimLong: |
| 689 | case Primitive::kPrimByte: |
| 690 | case Primitive::kPrimBoolean: |
| 691 | case Primitive::kPrimChar: |
| 692 | case Primitive::kPrimShort: |
| 693 | case Primitive::kPrimInt: |
| 694 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 695 | size_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfCpuRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 696 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 700 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 701 | size_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfFloatRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 702 | return Location::FpuRegisterLocation(reg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 703 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 704 | |
| 705 | case Primitive::kPrimVoid: |
| 706 | LOG(FATAL) << "Unreachable type " << type; |
| 707 | } |
| 708 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 709 | return Location(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 710 | } |
| 711 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 712 | void CodeGeneratorX86_64::SetupBlockedRegisters(bool is_baseline) const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 713 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 714 | blocked_core_registers_[RSP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 715 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 716 | // Block the register used as TMP. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 717 | blocked_core_registers_[TMP] = true; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 718 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 719 | if (is_baseline) { |
| 720 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 721 | blocked_core_registers_[kCoreCalleeSaves[i]] = true; |
| 722 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 723 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 724 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 725 | } |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 726 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 727 | } |
| 728 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 729 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 730 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 731 | } |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 732 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 733 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 734 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 735 | } |
| 736 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 737 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 738 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 739 | __ Bind(&frame_entry_label_); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 740 | bool skip_overflow_check = IsLeafMethod() |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 741 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 742 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 743 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 744 | if (!skip_overflow_check) { |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 745 | __ testq(CpuRegister(RAX), Address( |
| 746 | CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 747 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 748 | } |
Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 749 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 750 | if (HasEmptyFrame()) { |
| 751 | return; |
| 752 | } |
| 753 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 754 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 755 | Register reg = kCoreCalleeSaves[i]; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 756 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 757 | __ pushq(CpuRegister(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 758 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 759 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 760 | } |
| 761 | } |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 762 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 763 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 764 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 765 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 766 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 767 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 768 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 769 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 770 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 771 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 772 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 773 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 774 | } |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 775 | } |
| 776 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 777 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 778 | CpuRegister(kMethodRegisterArgument)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | void CodeGeneratorX86_64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 782 | __ cfi().RememberState(); |
| 783 | if (!HasEmptyFrame()) { |
| 784 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 785 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| 786 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 787 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 788 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 789 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 790 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 795 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 796 | __ cfi().AdjustCFAOffset(-adjust); |
| 797 | |
| 798 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 799 | Register reg = kCoreCalleeSaves[i]; |
| 800 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 801 | __ popq(CpuRegister(reg)); |
| 802 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 803 | __ cfi().Restore(DWARFReg(reg)); |
| 804 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 805 | } |
| 806 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 807 | __ ret(); |
| 808 | __ cfi().RestoreState(); |
| 809 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 810 | } |
| 811 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 812 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 813 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 814 | } |
| 815 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 816 | Location CodeGeneratorX86_64::GetStackLocation(HLoadLocal* load) const { |
| 817 | switch (load->GetType()) { |
| 818 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 819 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 820 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 821 | |
| 822 | case Primitive::kPrimInt: |
| 823 | case Primitive::kPrimNot: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 824 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 825 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 826 | |
| 827 | case Primitive::kPrimBoolean: |
| 828 | case Primitive::kPrimByte: |
| 829 | case Primitive::kPrimChar: |
| 830 | case Primitive::kPrimShort: |
| 831 | case Primitive::kPrimVoid: |
| 832 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 833 | UNREACHABLE(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 837 | UNREACHABLE(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 841 | if (source.Equals(destination)) { |
| 842 | return; |
| 843 | } |
| 844 | if (destination.IsRegister()) { |
| 845 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 846 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 847 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 848 | __ movd(destination.AsRegister<CpuRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 849 | } else if (source.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 850 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 851 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 852 | } else { |
| 853 | DCHECK(source.IsDoubleStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 854 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 855 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 856 | } |
| 857 | } else if (destination.IsFpuRegister()) { |
| 858 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 859 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 860 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 861 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 862 | } else if (source.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 863 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 864 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 865 | } else { |
| 866 | DCHECK(source.IsDoubleStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 867 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 868 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 869 | } |
| 870 | } else if (destination.IsStackSlot()) { |
| 871 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 872 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 873 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 874 | } else if (source.IsFpuRegister()) { |
| 875 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 876 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 877 | } else if (source.IsConstant()) { |
| 878 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 879 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 880 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 881 | } else { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 882 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 883 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 884 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 885 | } |
| 886 | } else { |
| 887 | DCHECK(destination.IsDoubleStackSlot()); |
| 888 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 889 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 890 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 891 | } else if (source.IsFpuRegister()) { |
| 892 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 893 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 894 | } else if (source.IsConstant()) { |
| 895 | HConstant* constant = source.GetConstant(); |
Zheng Xu | 12bca97 | 2015-03-30 19:35:50 +0800 | [diff] [blame] | 896 | int64_t value; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 897 | if (constant->IsDoubleConstant()) { |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 898 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 899 | } else { |
| 900 | DCHECK(constant->IsLongConstant()); |
| 901 | value = constant->AsLongConstant()->GetValue(); |
| 902 | } |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 903 | Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 904 | } else { |
| 905 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 906 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 907 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 908 | } |
| 909 | } |
| 910 | } |
| 911 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 912 | void CodeGeneratorX86_64::Move(HInstruction* instruction, |
| 913 | Location location, |
| 914 | HInstruction* move_for) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 915 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 916 | if (instruction->IsCurrentMethod()) { |
Mathieu Chartier | e3b034a | 2015-05-31 14:29:23 -0700 | [diff] [blame] | 917 | Move(location, Location::DoubleStackSlot(kCurrentMethodStackOffset)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 918 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 919 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 920 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 921 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 922 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 923 | Immediate imm(GetInt32ValueOf(const_to_move)); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 924 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 925 | __ movl(location.AsRegister<CpuRegister>(), imm); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 926 | } else if (location.IsStackSlot()) { |
| 927 | __ movl(Address(CpuRegister(RSP), location.GetStackIndex()), imm); |
| 928 | } else { |
| 929 | DCHECK(location.IsConstant()); |
| 930 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 931 | } |
| 932 | } else if (const_to_move->IsLongConstant()) { |
| 933 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 934 | if (location.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 935 | Load64BitValue(location.AsRegister<CpuRegister>(), value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 936 | } else if (location.IsDoubleStackSlot()) { |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 937 | Store64BitValueToStack(location, value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 938 | } else { |
| 939 | DCHECK(location.IsConstant()); |
| 940 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 941 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 942 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 943 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 944 | switch (instruction->GetType()) { |
| 945 | case Primitive::kPrimBoolean: |
| 946 | case Primitive::kPrimByte: |
| 947 | case Primitive::kPrimChar: |
| 948 | case Primitive::kPrimShort: |
| 949 | case Primitive::kPrimInt: |
| 950 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 951 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 952 | Move(location, Location::StackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
| 953 | break; |
| 954 | |
| 955 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 956 | case Primitive::kPrimDouble: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 957 | Move(location, |
| 958 | Location::DoubleStackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 959 | break; |
| 960 | |
| 961 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 962 | LOG(FATAL) << "Unexpected local type " << instruction->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 963 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 964 | } else if (instruction->IsTemporary()) { |
| 965 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
| 966 | Move(location, temp_location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 967 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 968 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 969 | switch (instruction->GetType()) { |
| 970 | case Primitive::kPrimBoolean: |
| 971 | case Primitive::kPrimByte: |
| 972 | case Primitive::kPrimChar: |
| 973 | case Primitive::kPrimShort: |
| 974 | case Primitive::kPrimInt: |
| 975 | case Primitive::kPrimNot: |
| 976 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 977 | case Primitive::kPrimFloat: |
| 978 | case Primitive::kPrimDouble: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 979 | Move(location, locations->Out()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 980 | break; |
| 981 | |
| 982 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 983 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 984 | } |
| 985 | } |
| 986 | } |
| 987 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 988 | void CodeGeneratorX86_64::MoveConstant(Location location, int32_t value) { |
| 989 | DCHECK(location.IsRegister()); |
| 990 | Load64BitValue(location.AsRegister<CpuRegister>(), static_cast<int64_t>(value)); |
| 991 | } |
| 992 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame^] | 993 | void CodeGeneratorX86_64::MoveLocation( |
| 994 | Location dst, Location src, Primitive::Type dst_type ATTRIBUTE_UNUSED) { |
| 995 | Move(dst, src); |
| 996 | } |
| 997 | |
| 998 | void CodeGeneratorX86_64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 999 | if (location.IsRegister()) { |
| 1000 | locations->AddTemp(location); |
| 1001 | } else { |
| 1002 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1003 | } |
| 1004 | } |
| 1005 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1006 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1007 | DCHECK(!successor->IsExitBlock()); |
| 1008 | |
| 1009 | HBasicBlock* block = got->GetBlock(); |
| 1010 | HInstruction* previous = got->GetPrevious(); |
| 1011 | |
| 1012 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1013 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1014 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1015 | return; |
| 1016 | } |
| 1017 | |
| 1018 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1019 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1020 | } |
| 1021 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1022 | __ jmp(codegen_->GetLabelOf(successor)); |
| 1023 | } |
| 1024 | } |
| 1025 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1026 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 1027 | got->SetLocations(nullptr); |
| 1028 | } |
| 1029 | |
| 1030 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 1031 | HandleGoto(got, got->GetSuccessor()); |
| 1032 | } |
| 1033 | |
| 1034 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1035 | try_boundary->SetLocations(nullptr); |
| 1036 | } |
| 1037 | |
| 1038 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1039 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1040 | if (!successor->IsExitBlock()) { |
| 1041 | HandleGoto(try_boundary, successor); |
| 1042 | } |
| 1043 | } |
| 1044 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1045 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 1046 | exit->SetLocations(nullptr); |
| 1047 | } |
| 1048 | |
| 1049 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1050 | UNUSED(exit); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1051 | } |
| 1052 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1053 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
| 1054 | Label* true_label, |
| 1055 | Label* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1056 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1057 | __ j(kUnordered, true_label); |
| 1058 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1059 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1060 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1061 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HIf* if_instr, |
| 1065 | HCondition* condition, |
| 1066 | Label* true_target, |
| 1067 | Label* false_target, |
| 1068 | Label* always_true_target) { |
| 1069 | LocationSummary* locations = condition->GetLocations(); |
| 1070 | Location left = locations->InAt(0); |
| 1071 | Location right = locations->InAt(1); |
| 1072 | |
| 1073 | // We don't want true_target as a nullptr. |
| 1074 | if (true_target == nullptr) { |
| 1075 | true_target = always_true_target; |
| 1076 | } |
| 1077 | bool falls_through = (false_target == nullptr); |
| 1078 | |
| 1079 | // FP compares don't like null false_targets. |
| 1080 | if (false_target == nullptr) { |
| 1081 | false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1082 | } |
| 1083 | |
| 1084 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1085 | switch (type) { |
| 1086 | case Primitive::kPrimLong: { |
| 1087 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1088 | if (right.IsConstant()) { |
| 1089 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 1090 | if (IsInt<32>(value)) { |
| 1091 | if (value == 0) { |
| 1092 | __ testq(left_reg, left_reg); |
| 1093 | } else { |
| 1094 | __ cmpq(left_reg, Immediate(static_cast<int32_t>(value))); |
| 1095 | } |
| 1096 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1097 | // Value won't fit in a 32-bit integer. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1098 | __ cmpq(left_reg, codegen_->LiteralInt64Address(value)); |
| 1099 | } |
| 1100 | } else if (right.IsDoubleStackSlot()) { |
| 1101 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1102 | } else { |
| 1103 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1104 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1105 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1106 | break; |
| 1107 | } |
| 1108 | case Primitive::kPrimFloat: { |
| 1109 | if (right.IsFpuRegister()) { |
| 1110 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1111 | } else if (right.IsConstant()) { |
| 1112 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1113 | codegen_->LiteralFloatAddress( |
| 1114 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1115 | } else { |
| 1116 | DCHECK(right.IsStackSlot()); |
| 1117 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1118 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1119 | } |
| 1120 | GenerateFPJumps(condition, true_target, false_target); |
| 1121 | break; |
| 1122 | } |
| 1123 | case Primitive::kPrimDouble: { |
| 1124 | if (right.IsFpuRegister()) { |
| 1125 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1126 | } else if (right.IsConstant()) { |
| 1127 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1128 | codegen_->LiteralDoubleAddress( |
| 1129 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1130 | } else { |
| 1131 | DCHECK(right.IsDoubleStackSlot()); |
| 1132 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1133 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1134 | } |
| 1135 | GenerateFPJumps(condition, true_target, false_target); |
| 1136 | break; |
| 1137 | } |
| 1138 | default: |
| 1139 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1140 | } |
| 1141 | |
| 1142 | if (!falls_through) { |
| 1143 | __ jmp(false_target); |
| 1144 | } |
| 1145 | } |
| 1146 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1147 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
| 1148 | Label* true_target, |
| 1149 | Label* false_target, |
| 1150 | Label* always_true_target) { |
| 1151 | HInstruction* cond = instruction->InputAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1152 | if (cond->IsIntConstant()) { |
| 1153 | // Constant condition, statically compared against 1. |
| 1154 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 1155 | if (cond_value == 1) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1156 | if (always_true_target != nullptr) { |
| 1157 | __ jmp(always_true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1158 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1159 | return; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1160 | } else { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1161 | DCHECK_EQ(cond_value, 0); |
| 1162 | } |
| 1163 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1164 | bool is_materialized = |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1165 | !cond->IsCondition() || cond->AsCondition()->NeedsMaterialization(); |
| 1166 | // Moves do not affect the eflags register, so if the condition is |
| 1167 | // evaluated just before the if, we don't need to evaluate it |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1168 | // again. We can't use the eflags on FP conditions if they are |
| 1169 | // materialized due to the complex branching. |
| 1170 | Primitive::Type type = cond->IsCondition() ? cond->InputAt(0)->GetType() : Primitive::kPrimInt; |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1171 | bool eflags_set = cond->IsCondition() |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1172 | && cond->AsCondition()->IsBeforeWhenDisregardMoves(instruction) |
| 1173 | && !Primitive::IsFloatingPointType(type); |
| 1174 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1175 | if (is_materialized) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1176 | if (!eflags_set) { |
| 1177 | // Materialized condition, compare against 0. |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1178 | Location lhs = instruction->GetLocations()->InAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1179 | if (lhs.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 1180 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1181 | } else { |
| 1182 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), |
| 1183 | Immediate(0)); |
| 1184 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1185 | __ j(kNotEqual, true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1186 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1187 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1188 | } |
| 1189 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1190 | // Condition has not been materialized, use its inputs as the |
| 1191 | // comparison and its condition as the branch condition. |
| 1192 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1193 | // Is this a long or FP comparison that has been folded into the HCondition? |
| 1194 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1195 | // Generate the comparison directly. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1196 | GenerateCompareTestAndBranch(instruction->AsIf(), cond->AsCondition(), |
| 1197 | true_target, false_target, always_true_target); |
| 1198 | return; |
| 1199 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1200 | |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1201 | Location lhs = cond->GetLocations()->InAt(0); |
| 1202 | Location rhs = cond->GetLocations()->InAt(1); |
| 1203 | if (rhs.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1204 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1205 | } else if (rhs.IsConstant()) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1206 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 1207 | if (constant == 0) { |
| 1208 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1209 | } else { |
| 1210 | __ cmpl(lhs.AsRegister<CpuRegister>(), Immediate(constant)); |
| 1211 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1212 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1213 | __ cmpl(lhs.AsRegister<CpuRegister>(), |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1214 | Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1215 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1216 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1217 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1218 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1219 | if (false_target != nullptr) { |
| 1220 | __ jmp(false_target); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1221 | } |
| 1222 | } |
| 1223 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1224 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
| 1225 | LocationSummary* locations = |
| 1226 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
| 1227 | HInstruction* cond = if_instr->InputAt(0); |
| 1228 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 1229 | locations->SetInAt(0, Location::Any()); |
| 1230 | } |
| 1231 | } |
| 1232 | |
| 1233 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
| 1234 | Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor()); |
| 1235 | Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1236 | Label* always_true_target = true_target; |
| 1237 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1238 | if_instr->IfTrueSuccessor())) { |
| 1239 | always_true_target = nullptr; |
| 1240 | } |
| 1241 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1242 | if_instr->IfFalseSuccessor())) { |
| 1243 | false_target = nullptr; |
| 1244 | } |
| 1245 | GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target); |
| 1246 | } |
| 1247 | |
| 1248 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1249 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1250 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| 1251 | HInstruction* cond = deoptimize->InputAt(0); |
| 1252 | DCHECK(cond->IsCondition()); |
| 1253 | if (cond->AsCondition()->NeedsMaterialization()) { |
| 1254 | locations->SetInAt(0, Location::Any()); |
| 1255 | } |
| 1256 | } |
| 1257 | |
| 1258 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 1259 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1260 | DeoptimizationSlowPathX86_64(deoptimize); |
| 1261 | codegen_->AddSlowPath(slow_path); |
| 1262 | Label* slow_path_entry = slow_path->GetEntryLabel(); |
| 1263 | GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry); |
| 1264 | } |
| 1265 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1266 | void LocationsBuilderX86_64::VisitLocal(HLocal* local) { |
| 1267 | local->SetLocations(nullptr); |
| 1268 | } |
| 1269 | |
| 1270 | void InstructionCodeGeneratorX86_64::VisitLocal(HLocal* local) { |
| 1271 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
| 1272 | } |
| 1273 | |
| 1274 | void LocationsBuilderX86_64::VisitLoadLocal(HLoadLocal* local) { |
| 1275 | local->SetLocations(nullptr); |
| 1276 | } |
| 1277 | |
| 1278 | void InstructionCodeGeneratorX86_64::VisitLoadLocal(HLoadLocal* load) { |
| 1279 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1280 | UNUSED(load); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1281 | } |
| 1282 | |
| 1283 | void LocationsBuilderX86_64::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1284 | LocationSummary* locations = |
| 1285 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1286 | switch (store->InputAt(1)->GetType()) { |
| 1287 | case Primitive::kPrimBoolean: |
| 1288 | case Primitive::kPrimByte: |
| 1289 | case Primitive::kPrimChar: |
| 1290 | case Primitive::kPrimShort: |
| 1291 | case Primitive::kPrimInt: |
| 1292 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1293 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1294 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1295 | break; |
| 1296 | |
| 1297 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1298 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1299 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1300 | break; |
| 1301 | |
| 1302 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1303 | LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1304 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1305 | } |
| 1306 | |
| 1307 | void InstructionCodeGeneratorX86_64::VisitStoreLocal(HStoreLocal* store) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1308 | UNUSED(store); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1309 | } |
| 1310 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1311 | void LocationsBuilderX86_64::VisitCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1312 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1313 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1314 | // Handle the long/FP comparisons made in instruction simplification. |
| 1315 | switch (cond->InputAt(0)->GetType()) { |
| 1316 | case Primitive::kPrimLong: |
| 1317 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1318 | locations->SetInAt(1, Location::Any()); |
| 1319 | break; |
| 1320 | case Primitive::kPrimFloat: |
| 1321 | case Primitive::kPrimDouble: |
| 1322 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1323 | locations->SetInAt(1, Location::Any()); |
| 1324 | break; |
| 1325 | default: |
| 1326 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1327 | locations->SetInAt(1, Location::Any()); |
| 1328 | break; |
| 1329 | } |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1330 | if (cond->NeedsMaterialization()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1331 | locations->SetOut(Location::RequiresRegister()); |
| 1332 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1333 | } |
| 1334 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1335 | void InstructionCodeGeneratorX86_64::VisitCondition(HCondition* cond) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1336 | if (!cond->NeedsMaterialization()) { |
| 1337 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1338 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1339 | |
| 1340 | LocationSummary* locations = cond->GetLocations(); |
| 1341 | Location lhs = locations->InAt(0); |
| 1342 | Location rhs = locations->InAt(1); |
| 1343 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
| 1344 | Label true_label, false_label; |
| 1345 | |
| 1346 | switch (cond->InputAt(0)->GetType()) { |
| 1347 | default: |
| 1348 | // Integer case. |
| 1349 | |
| 1350 | // Clear output register: setcc only sets the low byte. |
| 1351 | __ xorl(reg, reg); |
| 1352 | |
| 1353 | if (rhs.IsRegister()) { |
| 1354 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1355 | } else if (rhs.IsConstant()) { |
| 1356 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1357 | if (constant == 0) { |
| 1358 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1359 | } else { |
| 1360 | __ cmpl(lhs.AsRegister<CpuRegister>(), Immediate(constant)); |
| 1361 | } |
| 1362 | } else { |
| 1363 | __ cmpl(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1364 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1365 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1366 | return; |
| 1367 | case Primitive::kPrimLong: |
| 1368 | // Clear output register: setcc only sets the low byte. |
| 1369 | __ xorl(reg, reg); |
| 1370 | |
| 1371 | if (rhs.IsRegister()) { |
| 1372 | __ cmpq(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1373 | } else if (rhs.IsConstant()) { |
| 1374 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
| 1375 | if (IsInt<32>(value)) { |
| 1376 | if (value == 0) { |
| 1377 | __ testq(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1378 | } else { |
| 1379 | __ cmpq(lhs.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 1380 | } |
| 1381 | } else { |
| 1382 | // Value won't fit in an int. |
| 1383 | __ cmpq(lhs.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 1384 | } |
| 1385 | } else { |
| 1386 | __ cmpq(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1387 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1388 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1389 | return; |
| 1390 | case Primitive::kPrimFloat: { |
| 1391 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1392 | if (rhs.IsConstant()) { |
| 1393 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 1394 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 1395 | } else if (rhs.IsStackSlot()) { |
| 1396 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1397 | } else { |
| 1398 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1399 | } |
| 1400 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1401 | break; |
| 1402 | } |
| 1403 | case Primitive::kPrimDouble: { |
| 1404 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1405 | if (rhs.IsConstant()) { |
| 1406 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1407 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 1408 | } else if (rhs.IsDoubleStackSlot()) { |
| 1409 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1410 | } else { |
| 1411 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1412 | } |
| 1413 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1414 | break; |
| 1415 | } |
| 1416 | } |
| 1417 | |
| 1418 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1419 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1420 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1421 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1422 | __ Bind(&false_label); |
| 1423 | __ xorl(reg, reg); |
| 1424 | __ jmp(&done_label); |
| 1425 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1426 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1427 | __ Bind(&true_label); |
| 1428 | __ movl(reg, Immediate(1)); |
| 1429 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
| 1433 | VisitCondition(comp); |
| 1434 | } |
| 1435 | |
| 1436 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
| 1437 | VisitCondition(comp); |
| 1438 | } |
| 1439 | |
| 1440 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
| 1441 | VisitCondition(comp); |
| 1442 | } |
| 1443 | |
| 1444 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
| 1445 | VisitCondition(comp); |
| 1446 | } |
| 1447 | |
| 1448 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
| 1449 | VisitCondition(comp); |
| 1450 | } |
| 1451 | |
| 1452 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
| 1453 | VisitCondition(comp); |
| 1454 | } |
| 1455 | |
| 1456 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1457 | VisitCondition(comp); |
| 1458 | } |
| 1459 | |
| 1460 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1461 | VisitCondition(comp); |
| 1462 | } |
| 1463 | |
| 1464 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| 1465 | VisitCondition(comp); |
| 1466 | } |
| 1467 | |
| 1468 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| 1469 | VisitCondition(comp); |
| 1470 | } |
| 1471 | |
| 1472 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1473 | VisitCondition(comp); |
| 1474 | } |
| 1475 | |
| 1476 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1477 | VisitCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1478 | } |
| 1479 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1480 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1481 | LocationSummary* locations = |
| 1482 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1483 | switch (compare->InputAt(0)->GetType()) { |
| 1484 | case Primitive::kPrimLong: { |
| 1485 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1486 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1487 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1488 | break; |
| 1489 | } |
| 1490 | case Primitive::kPrimFloat: |
| 1491 | case Primitive::kPrimDouble: { |
| 1492 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1493 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1494 | locations->SetOut(Location::RequiresRegister()); |
| 1495 | break; |
| 1496 | } |
| 1497 | default: |
| 1498 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 1499 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1503 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1504 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1505 | Location left = locations->InAt(0); |
| 1506 | Location right = locations->InAt(1); |
| 1507 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1508 | NearLabel less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1509 | Primitive::Type type = compare->InputAt(0)->GetType(); |
| 1510 | switch (type) { |
| 1511 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1512 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1513 | if (right.IsConstant()) { |
| 1514 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1515 | if (IsInt<32>(value)) { |
| 1516 | if (value == 0) { |
| 1517 | __ testq(left_reg, left_reg); |
| 1518 | } else { |
| 1519 | __ cmpq(left_reg, Immediate(static_cast<int32_t>(value))); |
| 1520 | } |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1521 | } else { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1522 | // Value won't fit in an int. |
| 1523 | __ cmpq(left_reg, codegen_->LiteralInt64Address(value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1524 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1525 | } else if (right.IsDoubleStackSlot()) { |
| 1526 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1527 | } else { |
| 1528 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1529 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1530 | break; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1531 | } |
| 1532 | case Primitive::kPrimFloat: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1533 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1534 | if (right.IsConstant()) { |
| 1535 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 1536 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 1537 | } else if (right.IsStackSlot()) { |
| 1538 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1539 | } else { |
| 1540 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1541 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1542 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 1543 | break; |
| 1544 | } |
| 1545 | case Primitive::kPrimDouble: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1546 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1547 | if (right.IsConstant()) { |
| 1548 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1549 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 1550 | } else if (right.IsDoubleStackSlot()) { |
| 1551 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1552 | } else { |
| 1553 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1554 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1555 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 1556 | break; |
| 1557 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1558 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1559 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1560 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1561 | __ movl(out, Immediate(0)); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1562 | __ j(kEqual, &done); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1563 | __ 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] | 1564 | |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1565 | __ Bind(&greater); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1566 | __ movl(out, Immediate(1)); |
| 1567 | __ jmp(&done); |
| 1568 | |
| 1569 | __ Bind(&less); |
| 1570 | __ movl(out, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1571 | |
| 1572 | __ Bind(&done); |
| 1573 | } |
| 1574 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1575 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1576 | LocationSummary* locations = |
| 1577 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1578 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1582 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1583 | UNUSED(constant); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1584 | } |
| 1585 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1586 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 1587 | LocationSummary* locations = |
| 1588 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1589 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1590 | } |
| 1591 | |
| 1592 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant) { |
| 1593 | // Will be generated at use site. |
| 1594 | UNUSED(constant); |
| 1595 | } |
| 1596 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1597 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1598 | LocationSummary* locations = |
| 1599 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1600 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1601 | } |
| 1602 | |
| 1603 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1604 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1605 | UNUSED(constant); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1606 | } |
| 1607 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1608 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 1609 | LocationSummary* locations = |
| 1610 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1611 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1612 | } |
| 1613 | |
| 1614 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 1615 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1616 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1617 | } |
| 1618 | |
| 1619 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1620 | LocationSummary* locations = |
| 1621 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1622 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1623 | } |
| 1624 | |
| 1625 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1626 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1627 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1628 | } |
| 1629 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1630 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1631 | memory_barrier->SetLocations(nullptr); |
| 1632 | } |
| 1633 | |
| 1634 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1635 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 1636 | } |
| 1637 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1638 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 1639 | ret->SetLocations(nullptr); |
| 1640 | } |
| 1641 | |
| 1642 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1643 | UNUSED(ret); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1644 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1645 | } |
| 1646 | |
| 1647 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1648 | LocationSummary* locations = |
| 1649 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1650 | switch (ret->InputAt(0)->GetType()) { |
| 1651 | case Primitive::kPrimBoolean: |
| 1652 | case Primitive::kPrimByte: |
| 1653 | case Primitive::kPrimChar: |
| 1654 | case Primitive::kPrimShort: |
| 1655 | case Primitive::kPrimInt: |
| 1656 | case Primitive::kPrimNot: |
| 1657 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1658 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1659 | break; |
| 1660 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1661 | case Primitive::kPrimFloat: |
| 1662 | case Primitive::kPrimDouble: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1663 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1664 | break; |
| 1665 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1666 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1667 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1668 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1669 | } |
| 1670 | |
| 1671 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 1672 | if (kIsDebugBuild) { |
| 1673 | switch (ret->InputAt(0)->GetType()) { |
| 1674 | case Primitive::kPrimBoolean: |
| 1675 | case Primitive::kPrimByte: |
| 1676 | case Primitive::kPrimChar: |
| 1677 | case Primitive::kPrimShort: |
| 1678 | case Primitive::kPrimInt: |
| 1679 | case Primitive::kPrimNot: |
| 1680 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1681 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1682 | break; |
| 1683 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1684 | case Primitive::kPrimFloat: |
| 1685 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1686 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1687 | XMM0); |
| 1688 | break; |
| 1689 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1690 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1691 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1692 | } |
| 1693 | } |
| 1694 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1695 | } |
| 1696 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1697 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(Primitive::Type type) const { |
| 1698 | switch (type) { |
| 1699 | case Primitive::kPrimBoolean: |
| 1700 | case Primitive::kPrimByte: |
| 1701 | case Primitive::kPrimChar: |
| 1702 | case Primitive::kPrimShort: |
| 1703 | case Primitive::kPrimInt: |
| 1704 | case Primitive::kPrimNot: |
| 1705 | case Primitive::kPrimLong: |
| 1706 | return Location::RegisterLocation(RAX); |
| 1707 | |
| 1708 | case Primitive::kPrimVoid: |
| 1709 | return Location::NoLocation(); |
| 1710 | |
| 1711 | case Primitive::kPrimDouble: |
| 1712 | case Primitive::kPrimFloat: |
| 1713 | return Location::FpuRegisterLocation(XMM0); |
| 1714 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1715 | |
| 1716 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1717 | } |
| 1718 | |
| 1719 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 1720 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1721 | } |
| 1722 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1723 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1724 | switch (type) { |
| 1725 | case Primitive::kPrimBoolean: |
| 1726 | case Primitive::kPrimByte: |
| 1727 | case Primitive::kPrimChar: |
| 1728 | case Primitive::kPrimShort: |
| 1729 | case Primitive::kPrimInt: |
| 1730 | case Primitive::kPrimNot: { |
| 1731 | uint32_t index = gp_index_++; |
| 1732 | stack_index_++; |
| 1733 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1734 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1735 | } else { |
| 1736 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1737 | } |
| 1738 | } |
| 1739 | |
| 1740 | case Primitive::kPrimLong: { |
| 1741 | uint32_t index = gp_index_; |
| 1742 | stack_index_ += 2; |
| 1743 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 1744 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1745 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1746 | } else { |
| 1747 | gp_index_ += 2; |
| 1748 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1749 | } |
| 1750 | } |
| 1751 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1752 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1753 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1754 | stack_index_++; |
| 1755 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1756 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1757 | } else { |
| 1758 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1759 | } |
| 1760 | } |
| 1761 | |
| 1762 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1763 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1764 | stack_index_ += 2; |
| 1765 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1766 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1767 | } else { |
| 1768 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1769 | } |
| 1770 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1771 | |
| 1772 | case Primitive::kPrimVoid: |
| 1773 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1774 | break; |
| 1775 | } |
| 1776 | return Location(); |
| 1777 | } |
| 1778 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1779 | void LocationsBuilderX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1780 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1781 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1782 | // the method_idx. |
| 1783 | HandleInvoke(invoke); |
| 1784 | } |
| 1785 | |
| 1786 | void InstructionCodeGeneratorX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1787 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1788 | } |
| 1789 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1790 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1791 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1792 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1793 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1794 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1795 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1796 | if (intrinsic.TryDispatch(invoke)) { |
| 1797 | return; |
| 1798 | } |
| 1799 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1800 | HandleInvoke(invoke); |
| 1801 | } |
| 1802 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1803 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 1804 | if (invoke->GetLocations()->Intrinsified()) { |
| 1805 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 1806 | intrinsic.Dispatch(invoke); |
| 1807 | return true; |
| 1808 | } |
| 1809 | return false; |
| 1810 | } |
| 1811 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1812 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1813 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1814 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1815 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1816 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1817 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1818 | return; |
| 1819 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1820 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1821 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1822 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1823 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 1824 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1825 | } |
| 1826 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1827 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1828 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1829 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1830 | } |
| 1831 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1832 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1833 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1834 | if (intrinsic.TryDispatch(invoke)) { |
| 1835 | return; |
| 1836 | } |
| 1837 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1838 | HandleInvoke(invoke); |
| 1839 | } |
| 1840 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1841 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1842 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1843 | return; |
| 1844 | } |
| 1845 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1846 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1847 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1848 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1849 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1850 | } |
| 1851 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1852 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1853 | HandleInvoke(invoke); |
| 1854 | // Add the hidden argument. |
| 1855 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 1856 | } |
| 1857 | |
| 1858 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1859 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1860 | CpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1861 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 1862 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86_64PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1863 | LocationSummary* locations = invoke->GetLocations(); |
| 1864 | Location receiver = locations->InAt(0); |
| 1865 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 1866 | |
| 1867 | // Set the hidden argument. |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 1868 | CpuRegister hidden_reg = invoke->GetLocations()->GetTemp(1).AsRegister<CpuRegister>(); |
| 1869 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1870 | |
| 1871 | // temp = object->GetClass(); |
| 1872 | if (receiver.IsStackSlot()) { |
| 1873 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
| 1874 | __ movl(temp, Address(temp, class_offset)); |
| 1875 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1876 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1877 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1878 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1879 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1880 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1881 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1882 | // call temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1883 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1884 | kX86_64WordSize).SizeValue())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1885 | |
| 1886 | DCHECK(!codegen_->IsLeafMethod()); |
| 1887 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1888 | } |
| 1889 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1890 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 1891 | LocationSummary* locations = |
| 1892 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1893 | switch (neg->GetResultType()) { |
| 1894 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1895 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1896 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1897 | locations->SetOut(Location::SameAsFirstInput()); |
| 1898 | break; |
| 1899 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1900 | case Primitive::kPrimFloat: |
| 1901 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1902 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1903 | locations->SetOut(Location::SameAsFirstInput()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1904 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1905 | break; |
| 1906 | |
| 1907 | default: |
| 1908 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1909 | } |
| 1910 | } |
| 1911 | |
| 1912 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 1913 | LocationSummary* locations = neg->GetLocations(); |
| 1914 | Location out = locations->Out(); |
| 1915 | Location in = locations->InAt(0); |
| 1916 | switch (neg->GetResultType()) { |
| 1917 | case Primitive::kPrimInt: |
| 1918 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1919 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1920 | __ negl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1921 | break; |
| 1922 | |
| 1923 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1924 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1925 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1926 | __ negq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1927 | break; |
| 1928 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1929 | case Primitive::kPrimFloat: { |
| 1930 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1931 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1932 | // Implement float negation with an exclusive or with value |
| 1933 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 1934 | // single-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1935 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1936 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1937 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1938 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1939 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1940 | case Primitive::kPrimDouble: { |
| 1941 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1942 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1943 | // Implement double negation with an exclusive or with value |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1944 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1945 | // a double-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1946 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1947 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1948 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1949 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1950 | |
| 1951 | default: |
| 1952 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1953 | } |
| 1954 | } |
| 1955 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1956 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 1957 | LocationSummary* locations = |
| 1958 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 1959 | Primitive::Type result_type = conversion->GetResultType(); |
| 1960 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1961 | DCHECK_NE(result_type, input_type); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1962 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1963 | // The Java language does not allow treating boolean as an integral type but |
| 1964 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1965 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1966 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1967 | case Primitive::kPrimByte: |
| 1968 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1969 | case Primitive::kPrimBoolean: |
| 1970 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1971 | case Primitive::kPrimShort: |
| 1972 | case Primitive::kPrimInt: |
| 1973 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1974 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1975 | locations->SetInAt(0, Location::Any()); |
| 1976 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1977 | break; |
| 1978 | |
| 1979 | default: |
| 1980 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1981 | << " to " << result_type; |
| 1982 | } |
| 1983 | break; |
| 1984 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1985 | case Primitive::kPrimShort: |
| 1986 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1987 | case Primitive::kPrimBoolean: |
| 1988 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1989 | case Primitive::kPrimByte: |
| 1990 | case Primitive::kPrimInt: |
| 1991 | case Primitive::kPrimChar: |
| 1992 | // Processing a Dex `int-to-short' instruction. |
| 1993 | locations->SetInAt(0, Location::Any()); |
| 1994 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1995 | break; |
| 1996 | |
| 1997 | default: |
| 1998 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1999 | << " to " << result_type; |
| 2000 | } |
| 2001 | break; |
| 2002 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2003 | case Primitive::kPrimInt: |
| 2004 | switch (input_type) { |
| 2005 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2006 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2007 | locations->SetInAt(0, Location::Any()); |
| 2008 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2009 | break; |
| 2010 | |
| 2011 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2012 | // Processing a Dex `float-to-int' instruction. |
| 2013 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2014 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2015 | break; |
| 2016 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2017 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2018 | // Processing a Dex `double-to-int' instruction. |
| 2019 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2020 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2021 | break; |
| 2022 | |
| 2023 | default: |
| 2024 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2025 | << " to " << result_type; |
| 2026 | } |
| 2027 | break; |
| 2028 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2029 | case Primitive::kPrimLong: |
| 2030 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2031 | case Primitive::kPrimBoolean: |
| 2032 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2033 | case Primitive::kPrimByte: |
| 2034 | case Primitive::kPrimShort: |
| 2035 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2036 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2037 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2038 | // TODO: We would benefit from a (to-be-implemented) |
| 2039 | // Location::RegisterOrStackSlot requirement for this input. |
| 2040 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2041 | locations->SetOut(Location::RequiresRegister()); |
| 2042 | break; |
| 2043 | |
| 2044 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2045 | // Processing a Dex `float-to-long' instruction. |
| 2046 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2047 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2048 | break; |
| 2049 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2050 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2051 | // Processing a Dex `double-to-long' instruction. |
| 2052 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2053 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2054 | break; |
| 2055 | |
| 2056 | default: |
| 2057 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2058 | << " to " << result_type; |
| 2059 | } |
| 2060 | break; |
| 2061 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2062 | case Primitive::kPrimChar: |
| 2063 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2064 | case Primitive::kPrimBoolean: |
| 2065 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2066 | case Primitive::kPrimByte: |
| 2067 | case Primitive::kPrimShort: |
| 2068 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2069 | // Processing a Dex `int-to-char' instruction. |
| 2070 | locations->SetInAt(0, Location::Any()); |
| 2071 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2072 | break; |
| 2073 | |
| 2074 | default: |
| 2075 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2076 | << " to " << result_type; |
| 2077 | } |
| 2078 | break; |
| 2079 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2080 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2081 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2082 | case Primitive::kPrimBoolean: |
| 2083 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2084 | case Primitive::kPrimByte: |
| 2085 | case Primitive::kPrimShort: |
| 2086 | case Primitive::kPrimInt: |
| 2087 | case Primitive::kPrimChar: |
| 2088 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2089 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2090 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2091 | break; |
| 2092 | |
| 2093 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2094 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2095 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2096 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2097 | break; |
| 2098 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2099 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2100 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2101 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2102 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2103 | break; |
| 2104 | |
| 2105 | default: |
| 2106 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2107 | << " to " << result_type; |
| 2108 | }; |
| 2109 | break; |
| 2110 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2111 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2112 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2113 | case Primitive::kPrimBoolean: |
| 2114 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2115 | case Primitive::kPrimByte: |
| 2116 | case Primitive::kPrimShort: |
| 2117 | case Primitive::kPrimInt: |
| 2118 | case Primitive::kPrimChar: |
| 2119 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2120 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2121 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2122 | break; |
| 2123 | |
| 2124 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2125 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2126 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2127 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2128 | break; |
| 2129 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2130 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2131 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2132 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2133 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2134 | break; |
| 2135 | |
| 2136 | default: |
| 2137 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2138 | << " to " << result_type; |
| 2139 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2140 | break; |
| 2141 | |
| 2142 | default: |
| 2143 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2144 | << " to " << result_type; |
| 2145 | } |
| 2146 | } |
| 2147 | |
| 2148 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2149 | LocationSummary* locations = conversion->GetLocations(); |
| 2150 | Location out = locations->Out(); |
| 2151 | Location in = locations->InAt(0); |
| 2152 | Primitive::Type result_type = conversion->GetResultType(); |
| 2153 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2154 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2155 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2156 | case Primitive::kPrimByte: |
| 2157 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2158 | case Primitive::kPrimBoolean: |
| 2159 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2160 | case Primitive::kPrimShort: |
| 2161 | case Primitive::kPrimInt: |
| 2162 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2163 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2164 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2165 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2166 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2167 | __ movsxb(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2168 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2169 | } else { |
| 2170 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2171 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2172 | Immediate(static_cast<int8_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2173 | } |
| 2174 | break; |
| 2175 | |
| 2176 | default: |
| 2177 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2178 | << " to " << result_type; |
| 2179 | } |
| 2180 | break; |
| 2181 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2182 | case Primitive::kPrimShort: |
| 2183 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2184 | case Primitive::kPrimBoolean: |
| 2185 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2186 | case Primitive::kPrimByte: |
| 2187 | case Primitive::kPrimInt: |
| 2188 | case Primitive::kPrimChar: |
| 2189 | // Processing a Dex `int-to-short' instruction. |
| 2190 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2191 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2192 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2193 | __ movsxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2194 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2195 | } else { |
| 2196 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2197 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2198 | Immediate(static_cast<int16_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2199 | } |
| 2200 | break; |
| 2201 | |
| 2202 | default: |
| 2203 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2204 | << " to " << result_type; |
| 2205 | } |
| 2206 | break; |
| 2207 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2208 | case Primitive::kPrimInt: |
| 2209 | switch (input_type) { |
| 2210 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2211 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2212 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2213 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2214 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2215 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2216 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2217 | } else { |
| 2218 | DCHECK(in.IsConstant()); |
| 2219 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2220 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2221 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2222 | } |
| 2223 | break; |
| 2224 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2225 | case Primitive::kPrimFloat: { |
| 2226 | // Processing a Dex `float-to-int' instruction. |
| 2227 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2228 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2229 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2230 | |
| 2231 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2232 | // if input >= (float)INT_MAX goto done |
| 2233 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimIntMax)); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2234 | __ j(kAboveEqual, &done); |
| 2235 | // if input == NaN goto nan |
| 2236 | __ j(kUnordered, &nan); |
| 2237 | // output = float-to-int-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2238 | __ cvttss2si(output, input, false); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2239 | __ jmp(&done); |
| 2240 | __ Bind(&nan); |
| 2241 | // output = 0 |
| 2242 | __ xorl(output, output); |
| 2243 | __ Bind(&done); |
| 2244 | break; |
| 2245 | } |
| 2246 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2247 | case Primitive::kPrimDouble: { |
| 2248 | // Processing a Dex `double-to-int' instruction. |
| 2249 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2250 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2251 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2252 | |
| 2253 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2254 | // if input >= (double)INT_MAX goto done |
| 2255 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2256 | __ j(kAboveEqual, &done); |
| 2257 | // if input == NaN goto nan |
| 2258 | __ j(kUnordered, &nan); |
| 2259 | // output = double-to-int-truncate(input) |
| 2260 | __ cvttsd2si(output, input); |
| 2261 | __ jmp(&done); |
| 2262 | __ Bind(&nan); |
| 2263 | // output = 0 |
| 2264 | __ xorl(output, output); |
| 2265 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2266 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2267 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2268 | |
| 2269 | default: |
| 2270 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2271 | << " to " << result_type; |
| 2272 | } |
| 2273 | break; |
| 2274 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2275 | case Primitive::kPrimLong: |
| 2276 | switch (input_type) { |
| 2277 | DCHECK(out.IsRegister()); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2278 | case Primitive::kPrimBoolean: |
| 2279 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2280 | case Primitive::kPrimByte: |
| 2281 | case Primitive::kPrimShort: |
| 2282 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2283 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2284 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2285 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2286 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2287 | break; |
| 2288 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2289 | case Primitive::kPrimFloat: { |
| 2290 | // Processing a Dex `float-to-long' instruction. |
| 2291 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2292 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2293 | NearLabel done, nan; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2294 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2295 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2296 | // if input >= (float)LONG_MAX goto done |
| 2297 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimLongMax)); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2298 | __ j(kAboveEqual, &done); |
| 2299 | // if input == NaN goto nan |
| 2300 | __ j(kUnordered, &nan); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2301 | // output = float-to-long-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2302 | __ cvttss2si(output, input, true); |
| 2303 | __ jmp(&done); |
| 2304 | __ Bind(&nan); |
| 2305 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2306 | __ xorl(output, output); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2307 | __ Bind(&done); |
| 2308 | break; |
| 2309 | } |
| 2310 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2311 | case Primitive::kPrimDouble: { |
| 2312 | // Processing a Dex `double-to-long' instruction. |
| 2313 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2314 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2315 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2316 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2317 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2318 | // if input >= (double)LONG_MAX goto done |
| 2319 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimLongMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2320 | __ j(kAboveEqual, &done); |
| 2321 | // if input == NaN goto nan |
| 2322 | __ j(kUnordered, &nan); |
| 2323 | // output = double-to-long-truncate(input) |
| 2324 | __ cvttsd2si(output, input, true); |
| 2325 | __ jmp(&done); |
| 2326 | __ Bind(&nan); |
| 2327 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2328 | __ xorl(output, output); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2329 | __ Bind(&done); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2330 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2331 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2332 | |
| 2333 | default: |
| 2334 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2335 | << " to " << result_type; |
| 2336 | } |
| 2337 | break; |
| 2338 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2339 | case Primitive::kPrimChar: |
| 2340 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2341 | case Primitive::kPrimBoolean: |
| 2342 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2343 | case Primitive::kPrimByte: |
| 2344 | case Primitive::kPrimShort: |
| 2345 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2346 | // Processing a Dex `int-to-char' instruction. |
| 2347 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2348 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2349 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2350 | __ movzxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2351 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2352 | } else { |
| 2353 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2354 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2355 | Immediate(static_cast<uint16_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2356 | } |
| 2357 | break; |
| 2358 | |
| 2359 | default: |
| 2360 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2361 | << " to " << result_type; |
| 2362 | } |
| 2363 | break; |
| 2364 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2365 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2366 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2367 | case Primitive::kPrimBoolean: |
| 2368 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2369 | case Primitive::kPrimByte: |
| 2370 | case Primitive::kPrimShort: |
| 2371 | case Primitive::kPrimInt: |
| 2372 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2373 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2374 | if (in.IsRegister()) { |
| 2375 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2376 | } else if (in.IsConstant()) { |
| 2377 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2378 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2379 | if (v == 0) { |
| 2380 | __ xorps(dest, dest); |
| 2381 | } else { |
| 2382 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2383 | } |
| 2384 | } else { |
| 2385 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2386 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2387 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2388 | break; |
| 2389 | |
| 2390 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2391 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2392 | if (in.IsRegister()) { |
| 2393 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2394 | } else if (in.IsConstant()) { |
| 2395 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2396 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2397 | if (v == 0) { |
| 2398 | __ xorps(dest, dest); |
| 2399 | } else { |
| 2400 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2401 | } |
| 2402 | } else { |
| 2403 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2404 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2405 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2406 | break; |
| 2407 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2408 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2409 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2410 | if (in.IsFpuRegister()) { |
| 2411 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2412 | } else if (in.IsConstant()) { |
| 2413 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2414 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2415 | if (bit_cast<int64_t, double>(v) == 0) { |
| 2416 | __ xorps(dest, dest); |
| 2417 | } else { |
| 2418 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2419 | } |
| 2420 | } else { |
| 2421 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 2422 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2423 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2424 | break; |
| 2425 | |
| 2426 | default: |
| 2427 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2428 | << " to " << result_type; |
| 2429 | }; |
| 2430 | break; |
| 2431 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2432 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2433 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2434 | case Primitive::kPrimBoolean: |
| 2435 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2436 | case Primitive::kPrimByte: |
| 2437 | case Primitive::kPrimShort: |
| 2438 | case Primitive::kPrimInt: |
| 2439 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2440 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2441 | if (in.IsRegister()) { |
| 2442 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2443 | } else if (in.IsConstant()) { |
| 2444 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2445 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2446 | if (v == 0) { |
| 2447 | __ xorpd(dest, dest); |
| 2448 | } else { |
| 2449 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2450 | } |
| 2451 | } else { |
| 2452 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2453 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2454 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2455 | break; |
| 2456 | |
| 2457 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2458 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2459 | if (in.IsRegister()) { |
| 2460 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2461 | } else if (in.IsConstant()) { |
| 2462 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2463 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2464 | if (v == 0) { |
| 2465 | __ xorpd(dest, dest); |
| 2466 | } else { |
| 2467 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2468 | } |
| 2469 | } else { |
| 2470 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2471 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2472 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2473 | break; |
| 2474 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2475 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2476 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2477 | if (in.IsFpuRegister()) { |
| 2478 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2479 | } else if (in.IsConstant()) { |
| 2480 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 2481 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2482 | if (bit_cast<int32_t, float>(v) == 0) { |
| 2483 | __ xorpd(dest, dest); |
| 2484 | } else { |
| 2485 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2486 | } |
| 2487 | } else { |
| 2488 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 2489 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2490 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2491 | break; |
| 2492 | |
| 2493 | default: |
| 2494 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2495 | << " to " << result_type; |
| 2496 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2497 | break; |
| 2498 | |
| 2499 | default: |
| 2500 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2501 | << " to " << result_type; |
| 2502 | } |
| 2503 | } |
| 2504 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2505 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2506 | LocationSummary* locations = |
| 2507 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2508 | switch (add->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2509 | case Primitive::kPrimInt: { |
| 2510 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2511 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2512 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2513 | break; |
| 2514 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2515 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2516 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2517 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2518 | // 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] | 2519 | locations->SetInAt(1, Location::RegisterOrInt32LongConstant(add->InputAt(1))); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2520 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2521 | break; |
| 2522 | } |
| 2523 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2524 | case Primitive::kPrimDouble: |
| 2525 | case Primitive::kPrimFloat: { |
| 2526 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2527 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2528 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2529 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2530 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2531 | |
| 2532 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2533 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2534 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2535 | } |
| 2536 | |
| 2537 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 2538 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2539 | Location first = locations->InAt(0); |
| 2540 | Location second = locations->InAt(1); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2541 | Location out = locations->Out(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2542 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2543 | switch (add->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2544 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2545 | if (second.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2546 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2547 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2548 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2549 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2550 | } else { |
| 2551 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2552 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2553 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2554 | } else if (second.IsConstant()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2555 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2556 | __ addl(out.AsRegister<CpuRegister>(), |
| 2557 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 2558 | } else { |
| 2559 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2560 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 2561 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2562 | } else { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2563 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2564 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2565 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2566 | break; |
| 2567 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2568 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2569 | case Primitive::kPrimLong: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2570 | if (second.IsRegister()) { |
| 2571 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2572 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2573 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2574 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2575 | } else { |
| 2576 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2577 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2578 | } |
| 2579 | } else { |
| 2580 | DCHECK(second.IsConstant()); |
| 2581 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2582 | int32_t int32_value = Low32Bits(value); |
| 2583 | DCHECK_EQ(int32_value, value); |
| 2584 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2585 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 2586 | } else { |
| 2587 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2588 | first.AsRegister<CpuRegister>(), int32_value)); |
| 2589 | } |
| 2590 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2591 | break; |
| 2592 | } |
| 2593 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2594 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2595 | if (second.IsFpuRegister()) { |
| 2596 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2597 | } else if (second.IsConstant()) { |
| 2598 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2599 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 2600 | } else { |
| 2601 | DCHECK(second.IsStackSlot()); |
| 2602 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2603 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2604 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2605 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2606 | } |
| 2607 | |
| 2608 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2609 | if (second.IsFpuRegister()) { |
| 2610 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2611 | } else if (second.IsConstant()) { |
| 2612 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2613 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 2614 | } else { |
| 2615 | DCHECK(second.IsDoubleStackSlot()); |
| 2616 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2617 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2618 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2619 | break; |
| 2620 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2621 | |
| 2622 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2623 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2624 | } |
| 2625 | } |
| 2626 | |
| 2627 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2628 | LocationSummary* locations = |
| 2629 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2630 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2631 | case Primitive::kPrimInt: { |
| 2632 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2633 | locations->SetInAt(1, Location::Any()); |
| 2634 | locations->SetOut(Location::SameAsFirstInput()); |
| 2635 | break; |
| 2636 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2637 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2638 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2639 | locations->SetInAt(1, Location::RegisterOrInt32LongConstant(sub->InputAt(1))); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2640 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2641 | break; |
| 2642 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2643 | case Primitive::kPrimFloat: |
| 2644 | case Primitive::kPrimDouble: { |
| 2645 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2646 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2647 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2648 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2649 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2650 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2651 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2652 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2653 | } |
| 2654 | |
| 2655 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 2656 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2657 | Location first = locations->InAt(0); |
| 2658 | Location second = locations->InAt(1); |
| 2659 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2660 | switch (sub->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2661 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2662 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2663 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2664 | } else if (second.IsConstant()) { |
| 2665 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2666 | __ subl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2667 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2668 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2669 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2670 | break; |
| 2671 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2672 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2673 | if (second.IsConstant()) { |
| 2674 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2675 | DCHECK(IsInt<32>(value)); |
| 2676 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 2677 | } else { |
| 2678 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 2679 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2680 | break; |
| 2681 | } |
| 2682 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2683 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2684 | if (second.IsFpuRegister()) { |
| 2685 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2686 | } else if (second.IsConstant()) { |
| 2687 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2688 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 2689 | } else { |
| 2690 | DCHECK(second.IsStackSlot()); |
| 2691 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2692 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2693 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2694 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2695 | } |
| 2696 | |
| 2697 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2698 | if (second.IsFpuRegister()) { |
| 2699 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2700 | } else if (second.IsConstant()) { |
| 2701 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2702 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 2703 | } else { |
| 2704 | DCHECK(second.IsDoubleStackSlot()); |
| 2705 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2706 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2707 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2708 | break; |
| 2709 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2710 | |
| 2711 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2712 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2713 | } |
| 2714 | } |
| 2715 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2716 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 2717 | LocationSummary* locations = |
| 2718 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2719 | switch (mul->GetResultType()) { |
| 2720 | case Primitive::kPrimInt: { |
| 2721 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2722 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2723 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2724 | // Can use 3 operand multiply. |
| 2725 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2726 | } else { |
| 2727 | locations->SetOut(Location::SameAsFirstInput()); |
| 2728 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2729 | break; |
| 2730 | } |
| 2731 | case Primitive::kPrimLong: { |
| 2732 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2733 | locations->SetInAt(1, Location::Any()); |
| 2734 | if (mul->InputAt(1)->IsLongConstant() && |
| 2735 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2736 | // Can use 3 operand multiply. |
| 2737 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2738 | } else { |
| 2739 | locations->SetOut(Location::SameAsFirstInput()); |
| 2740 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2741 | break; |
| 2742 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2743 | case Primitive::kPrimFloat: |
| 2744 | case Primitive::kPrimDouble: { |
| 2745 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2746 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2747 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2748 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2749 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2750 | |
| 2751 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2752 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2753 | } |
| 2754 | } |
| 2755 | |
| 2756 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 2757 | LocationSummary* locations = mul->GetLocations(); |
| 2758 | Location first = locations->InAt(0); |
| 2759 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2760 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2761 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2762 | case Primitive::kPrimInt: |
| 2763 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2764 | // problems where the output may not be the same as the first operand. |
| 2765 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2766 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 2767 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 2768 | } else if (second.IsRegister()) { |
| 2769 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2770 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2771 | } else { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2772 | DCHECK(first.Equals(out)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2773 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2774 | __ imull(first.AsRegister<CpuRegister>(), |
| 2775 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2776 | } |
| 2777 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2778 | case Primitive::kPrimLong: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2779 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2780 | // problems where the output may not be the same as the first operand. |
| 2781 | if (mul->InputAt(1)->IsLongConstant()) { |
| 2782 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 2783 | if (IsInt<32>(value)) { |
| 2784 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 2785 | Immediate(static_cast<int32_t>(value))); |
| 2786 | } else { |
| 2787 | // Have to use the constant area. |
| 2788 | DCHECK(first.Equals(out)); |
| 2789 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 2790 | } |
| 2791 | } else if (second.IsRegister()) { |
| 2792 | DCHECK(first.Equals(out)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2793 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2794 | } else { |
| 2795 | DCHECK(second.IsDoubleStackSlot()); |
| 2796 | DCHECK(first.Equals(out)); |
| 2797 | __ imulq(first.AsRegister<CpuRegister>(), |
| 2798 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2799 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2800 | break; |
| 2801 | } |
| 2802 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2803 | case Primitive::kPrimFloat: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2804 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2805 | if (second.IsFpuRegister()) { |
| 2806 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2807 | } else if (second.IsConstant()) { |
| 2808 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 2809 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 2810 | } else { |
| 2811 | DCHECK(second.IsStackSlot()); |
| 2812 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 2813 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2814 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2815 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2816 | } |
| 2817 | |
| 2818 | case Primitive::kPrimDouble: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2819 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2820 | if (second.IsFpuRegister()) { |
| 2821 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2822 | } else if (second.IsConstant()) { |
| 2823 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 2824 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 2825 | } else { |
| 2826 | DCHECK(second.IsDoubleStackSlot()); |
| 2827 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 2828 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2829 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2830 | break; |
| 2831 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2832 | |
| 2833 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2834 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2835 | } |
| 2836 | } |
| 2837 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2838 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 2839 | uint32_t stack_adjustment, bool is_float) { |
| 2840 | if (source.IsStackSlot()) { |
| 2841 | DCHECK(is_float); |
| 2842 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 2843 | } else if (source.IsDoubleStackSlot()) { |
| 2844 | DCHECK(!is_float); |
| 2845 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 2846 | } else { |
| 2847 | // Write the value to the temporary location on the stack and load to FP stack. |
| 2848 | if (is_float) { |
| 2849 | Location stack_temp = Location::StackSlot(temp_offset); |
| 2850 | codegen_->Move(stack_temp, source); |
| 2851 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 2852 | } else { |
| 2853 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 2854 | codegen_->Move(stack_temp, source); |
| 2855 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 2856 | } |
| 2857 | } |
| 2858 | } |
| 2859 | |
| 2860 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| 2861 | Primitive::Type type = rem->GetResultType(); |
| 2862 | bool is_float = type == Primitive::kPrimFloat; |
| 2863 | size_t elem_size = Primitive::ComponentSize(type); |
| 2864 | LocationSummary* locations = rem->GetLocations(); |
| 2865 | Location first = locations->InAt(0); |
| 2866 | Location second = locations->InAt(1); |
| 2867 | Location out = locations->Out(); |
| 2868 | |
| 2869 | // Create stack space for 2 elements. |
| 2870 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2871 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 2872 | |
| 2873 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 2874 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 2875 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 2876 | |
| 2877 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2878 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2879 | __ Bind(&retry); |
| 2880 | __ fprem(); |
| 2881 | |
| 2882 | // Move FP status to AX. |
| 2883 | __ fstsw(); |
| 2884 | |
| 2885 | // And see if the argument reduction is complete. This is signaled by the |
| 2886 | // C2 FPU flag bit set to 0. |
| 2887 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 2888 | __ j(kNotEqual, &retry); |
| 2889 | |
| 2890 | // We have settled on the final value. Retrieve it into an XMM register. |
| 2891 | // Store FP top of stack to real stack. |
| 2892 | if (is_float) { |
| 2893 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 2894 | } else { |
| 2895 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 2896 | } |
| 2897 | |
| 2898 | // Pop the 2 items from the FP stack. |
| 2899 | __ fucompp(); |
| 2900 | |
| 2901 | // Load the value from the stack into an XMM register. |
| 2902 | DCHECK(out.IsFpuRegister()) << out; |
| 2903 | if (is_float) { |
| 2904 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 2905 | } else { |
| 2906 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 2907 | } |
| 2908 | |
| 2909 | // And remove the temporary stack space we allocated. |
| 2910 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 2911 | } |
| 2912 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2913 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2914 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2915 | |
| 2916 | LocationSummary* locations = instruction->GetLocations(); |
| 2917 | Location second = locations->InAt(1); |
| 2918 | DCHECK(second.IsConstant()); |
| 2919 | |
| 2920 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 2921 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2922 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2923 | |
| 2924 | DCHECK(imm == 1 || imm == -1); |
| 2925 | |
| 2926 | switch (instruction->GetResultType()) { |
| 2927 | case Primitive::kPrimInt: { |
| 2928 | if (instruction->IsRem()) { |
| 2929 | __ xorl(output_register, output_register); |
| 2930 | } else { |
| 2931 | __ movl(output_register, input_register); |
| 2932 | if (imm == -1) { |
| 2933 | __ negl(output_register); |
| 2934 | } |
| 2935 | } |
| 2936 | break; |
| 2937 | } |
| 2938 | |
| 2939 | case Primitive::kPrimLong: { |
| 2940 | if (instruction->IsRem()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2941 | __ xorl(output_register, output_register); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2942 | } else { |
| 2943 | __ movq(output_register, input_register); |
| 2944 | if (imm == -1) { |
| 2945 | __ negq(output_register); |
| 2946 | } |
| 2947 | } |
| 2948 | break; |
| 2949 | } |
| 2950 | |
| 2951 | default: |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2952 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2953 | } |
| 2954 | } |
| 2955 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2956 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2957 | LocationSummary* locations = instruction->GetLocations(); |
| 2958 | Location second = locations->InAt(1); |
| 2959 | |
| 2960 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 2961 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 2962 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2963 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2964 | |
| 2965 | DCHECK(IsPowerOfTwo(std::abs(imm))); |
| 2966 | |
| 2967 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2968 | |
| 2969 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 2970 | __ leal(tmp, Address(numerator, std::abs(imm) - 1)); |
| 2971 | __ testl(numerator, numerator); |
| 2972 | __ cmov(kGreaterEqual, tmp, numerator); |
| 2973 | int shift = CTZ(imm); |
| 2974 | __ sarl(tmp, Immediate(shift)); |
| 2975 | |
| 2976 | if (imm < 0) { |
| 2977 | __ negl(tmp); |
| 2978 | } |
| 2979 | |
| 2980 | __ movl(output_register, tmp); |
| 2981 | } else { |
| 2982 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 2983 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2984 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2985 | codegen_->Load64BitValue(rdx, std::abs(imm) - 1); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2986 | __ addq(rdx, numerator); |
| 2987 | __ testq(numerator, numerator); |
| 2988 | __ cmov(kGreaterEqual, rdx, numerator); |
| 2989 | int shift = CTZ(imm); |
| 2990 | __ sarq(rdx, Immediate(shift)); |
| 2991 | |
| 2992 | if (imm < 0) { |
| 2993 | __ negq(rdx); |
| 2994 | } |
| 2995 | |
| 2996 | __ movq(output_register, rdx); |
| 2997 | } |
| 2998 | } |
| 2999 | |
| 3000 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3001 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3002 | |
| 3003 | LocationSummary* locations = instruction->GetLocations(); |
| 3004 | Location second = locations->InAt(1); |
| 3005 | |
| 3006 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 3007 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3008 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3009 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 3010 | : locations->Out().AsRegister<CpuRegister>(); |
| 3011 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3012 | |
| 3013 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 3014 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 3015 | if (instruction->IsDiv()) { |
| 3016 | DCHECK_EQ(RAX, out.AsRegister()); |
| 3017 | } else { |
| 3018 | DCHECK_EQ(RDX, out.AsRegister()); |
| 3019 | } |
| 3020 | |
| 3021 | int64_t magic; |
| 3022 | int shift; |
| 3023 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3024 | // TODO: can these branches be written as one? |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3025 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 3026 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3027 | |
| 3028 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3029 | |
| 3030 | __ movl(numerator, eax); |
| 3031 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3032 | NearLabel no_div; |
| 3033 | NearLabel end; |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3034 | __ testl(eax, eax); |
| 3035 | __ j(kNotEqual, &no_div); |
| 3036 | |
| 3037 | __ xorl(out, out); |
| 3038 | __ jmp(&end); |
| 3039 | |
| 3040 | __ Bind(&no_div); |
| 3041 | |
| 3042 | __ movl(eax, Immediate(magic)); |
| 3043 | __ imull(numerator); |
| 3044 | |
| 3045 | if (imm > 0 && magic < 0) { |
| 3046 | __ addl(edx, numerator); |
| 3047 | } else if (imm < 0 && magic > 0) { |
| 3048 | __ subl(edx, numerator); |
| 3049 | } |
| 3050 | |
| 3051 | if (shift != 0) { |
| 3052 | __ sarl(edx, Immediate(shift)); |
| 3053 | } |
| 3054 | |
| 3055 | __ movl(eax, edx); |
| 3056 | __ shrl(edx, Immediate(31)); |
| 3057 | __ addl(edx, eax); |
| 3058 | |
| 3059 | if (instruction->IsRem()) { |
| 3060 | __ movl(eax, numerator); |
| 3061 | __ imull(edx, Immediate(imm)); |
| 3062 | __ subl(eax, edx); |
| 3063 | __ movl(edx, eax); |
| 3064 | } else { |
| 3065 | __ movl(eax, edx); |
| 3066 | } |
| 3067 | __ Bind(&end); |
| 3068 | } else { |
| 3069 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3070 | |
| 3071 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3072 | |
| 3073 | CpuRegister rax = eax; |
| 3074 | CpuRegister rdx = edx; |
| 3075 | |
| 3076 | CalculateMagicAndShiftForDivRem(imm, true /* is_long */, &magic, &shift); |
| 3077 | |
| 3078 | // Save the numerator. |
| 3079 | __ movq(numerator, rax); |
| 3080 | |
| 3081 | // RAX = magic |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3082 | codegen_->Load64BitValue(rax, magic); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3083 | |
| 3084 | // RDX:RAX = magic * numerator |
| 3085 | __ imulq(numerator); |
| 3086 | |
| 3087 | if (imm > 0 && magic < 0) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3088 | // RDX += numerator |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3089 | __ addq(rdx, numerator); |
| 3090 | } else if (imm < 0 && magic > 0) { |
| 3091 | // RDX -= numerator |
| 3092 | __ subq(rdx, numerator); |
| 3093 | } |
| 3094 | |
| 3095 | // Shift if needed. |
| 3096 | if (shift != 0) { |
| 3097 | __ sarq(rdx, Immediate(shift)); |
| 3098 | } |
| 3099 | |
| 3100 | // RDX += 1 if RDX < 0 |
| 3101 | __ movq(rax, rdx); |
| 3102 | __ shrq(rdx, Immediate(63)); |
| 3103 | __ addq(rdx, rax); |
| 3104 | |
| 3105 | if (instruction->IsRem()) { |
| 3106 | __ movq(rax, numerator); |
| 3107 | |
| 3108 | if (IsInt<32>(imm)) { |
| 3109 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 3110 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3111 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3112 | } |
| 3113 | |
| 3114 | __ subq(rax, rdx); |
| 3115 | __ movq(rdx, rax); |
| 3116 | } else { |
| 3117 | __ movq(rax, rdx); |
| 3118 | } |
| 3119 | } |
| 3120 | } |
| 3121 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3122 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3123 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3124 | Primitive::Type type = instruction->GetResultType(); |
| 3125 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 3126 | |
| 3127 | bool is_div = instruction->IsDiv(); |
| 3128 | LocationSummary* locations = instruction->GetLocations(); |
| 3129 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3130 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3131 | Location second = locations->InAt(1); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3132 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3133 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3134 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3135 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3136 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3137 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3138 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3139 | if (imm == 0) { |
| 3140 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3141 | } else if (imm == 1 || imm == -1) { |
| 3142 | DivRemOneOrMinusOne(instruction); |
| 3143 | } else if (instruction->IsDiv() && IsPowerOfTwo(std::abs(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3144 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3145 | } else { |
| 3146 | DCHECK(imm <= -2 || imm >= 2); |
| 3147 | GenerateDivRemWithAnyConstant(instruction); |
| 3148 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3149 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3150 | SlowPathCode* slow_path = |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3151 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86_64( |
| 3152 | out.AsRegister(), type, is_div); |
| 3153 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3154 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3155 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3156 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3157 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3158 | // so it's safe to just use negl instead of more complex comparisons. |
| 3159 | if (type == Primitive::kPrimInt) { |
| 3160 | __ cmpl(second_reg, Immediate(-1)); |
| 3161 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3162 | // edx:eax <- sign-extended of eax |
| 3163 | __ cdq(); |
| 3164 | // eax = quotient, edx = remainder |
| 3165 | __ idivl(second_reg); |
| 3166 | } else { |
| 3167 | __ cmpq(second_reg, Immediate(-1)); |
| 3168 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3169 | // rdx:rax <- sign-extended of rax |
| 3170 | __ cqo(); |
| 3171 | // rax = quotient, rdx = remainder |
| 3172 | __ idivq(second_reg); |
| 3173 | } |
| 3174 | __ Bind(slow_path->GetExitLabel()); |
| 3175 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3176 | } |
| 3177 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3178 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3179 | LocationSummary* locations = |
| 3180 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3181 | switch (div->GetResultType()) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3182 | case Primitive::kPrimInt: |
| 3183 | case Primitive::kPrimLong: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3184 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3185 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3186 | locations->SetOut(Location::SameAsFirstInput()); |
| 3187 | // Intel uses edx:eax as the dividend. |
| 3188 | locations->AddTemp(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3189 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3190 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3191 | // output and request another temp. |
| 3192 | if (div->InputAt(1)->IsConstant()) { |
| 3193 | locations->AddTemp(Location::RequiresRegister()); |
| 3194 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3195 | break; |
| 3196 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3197 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3198 | case Primitive::kPrimFloat: |
| 3199 | case Primitive::kPrimDouble: { |
| 3200 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3201 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3202 | locations->SetOut(Location::SameAsFirstInput()); |
| 3203 | break; |
| 3204 | } |
| 3205 | |
| 3206 | default: |
| 3207 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3208 | } |
| 3209 | } |
| 3210 | |
| 3211 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3212 | LocationSummary* locations = div->GetLocations(); |
| 3213 | Location first = locations->InAt(0); |
| 3214 | Location second = locations->InAt(1); |
| 3215 | DCHECK(first.Equals(locations->Out())); |
| 3216 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3217 | Primitive::Type type = div->GetResultType(); |
| 3218 | switch (type) { |
| 3219 | case Primitive::kPrimInt: |
| 3220 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3221 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3222 | break; |
| 3223 | } |
| 3224 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3225 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3226 | if (second.IsFpuRegister()) { |
| 3227 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3228 | } else if (second.IsConstant()) { |
| 3229 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3230 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 3231 | } else { |
| 3232 | DCHECK(second.IsStackSlot()); |
| 3233 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3234 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3235 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3236 | break; |
| 3237 | } |
| 3238 | |
| 3239 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3240 | if (second.IsFpuRegister()) { |
| 3241 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3242 | } else if (second.IsConstant()) { |
| 3243 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3244 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 3245 | } else { |
| 3246 | DCHECK(second.IsDoubleStackSlot()); |
| 3247 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3248 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3249 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3250 | break; |
| 3251 | } |
| 3252 | |
| 3253 | default: |
| 3254 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3255 | } |
| 3256 | } |
| 3257 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3258 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3259 | Primitive::Type type = rem->GetResultType(); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3260 | LocationSummary* locations = |
| 3261 | new (GetGraph()->GetArena()) LocationSummary(rem, LocationSummary::kNoCall); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3262 | |
| 3263 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3264 | case Primitive::kPrimInt: |
| 3265 | case Primitive::kPrimLong: { |
| 3266 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3267 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3268 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3269 | locations->SetOut(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3270 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3271 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3272 | // output and request another temp. |
| 3273 | if (rem->InputAt(1)->IsConstant()) { |
| 3274 | locations->AddTemp(Location::RequiresRegister()); |
| 3275 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3276 | break; |
| 3277 | } |
| 3278 | |
| 3279 | case Primitive::kPrimFloat: |
| 3280 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3281 | locations->SetInAt(0, Location::Any()); |
| 3282 | locations->SetInAt(1, Location::Any()); |
| 3283 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3284 | locations->AddTemp(Location::RegisterLocation(RAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3285 | break; |
| 3286 | } |
| 3287 | |
| 3288 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3289 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3290 | } |
| 3291 | } |
| 3292 | |
| 3293 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| 3294 | Primitive::Type type = rem->GetResultType(); |
| 3295 | switch (type) { |
| 3296 | case Primitive::kPrimInt: |
| 3297 | case Primitive::kPrimLong: { |
| 3298 | GenerateDivRemIntegral(rem); |
| 3299 | break; |
| 3300 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3301 | case Primitive::kPrimFloat: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3302 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3303 | GenerateRemFP(rem); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3304 | break; |
| 3305 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3306 | default: |
| 3307 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3308 | } |
| 3309 | } |
| 3310 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3311 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3312 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3313 | ? LocationSummary::kCallOnSlowPath |
| 3314 | : LocationSummary::kNoCall; |
| 3315 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3316 | locations->SetInAt(0, Location::Any()); |
| 3317 | if (instruction->HasUses()) { |
| 3318 | locations->SetOut(Location::SameAsFirstInput()); |
| 3319 | } |
| 3320 | } |
| 3321 | |
| 3322 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3323 | SlowPathCode* slow_path = |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3324 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction); |
| 3325 | codegen_->AddSlowPath(slow_path); |
| 3326 | |
| 3327 | LocationSummary* locations = instruction->GetLocations(); |
| 3328 | Location value = locations->InAt(0); |
| 3329 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3330 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3331 | case Primitive::kPrimByte: |
| 3332 | case Primitive::kPrimChar: |
| 3333 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3334 | case Primitive::kPrimInt: { |
| 3335 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3336 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3337 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3338 | } else if (value.IsStackSlot()) { |
| 3339 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3340 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3341 | } else { |
| 3342 | DCHECK(value.IsConstant()) << value; |
| 3343 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3344 | __ jmp(slow_path->GetEntryLabel()); |
| 3345 | } |
| 3346 | } |
| 3347 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3348 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3349 | case Primitive::kPrimLong: { |
| 3350 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3351 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3352 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3353 | } else if (value.IsDoubleStackSlot()) { |
| 3354 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3355 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3356 | } else { |
| 3357 | DCHECK(value.IsConstant()) << value; |
| 3358 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3359 | __ jmp(slow_path->GetEntryLabel()); |
| 3360 | } |
| 3361 | } |
| 3362 | break; |
| 3363 | } |
| 3364 | default: |
| 3365 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3366 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3367 | } |
| 3368 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3369 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 3370 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3371 | |
| 3372 | LocationSummary* locations = |
| 3373 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3374 | |
| 3375 | switch (op->GetResultType()) { |
| 3376 | case Primitive::kPrimInt: |
| 3377 | case Primitive::kPrimLong: { |
| 3378 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3379 | // The shift count needs to be in CL. |
| 3380 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 3381 | locations->SetOut(Location::SameAsFirstInput()); |
| 3382 | break; |
| 3383 | } |
| 3384 | default: |
| 3385 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3386 | } |
| 3387 | } |
| 3388 | |
| 3389 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 3390 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3391 | |
| 3392 | LocationSummary* locations = op->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3393 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3394 | Location second = locations->InAt(1); |
| 3395 | |
| 3396 | switch (op->GetResultType()) { |
| 3397 | case Primitive::kPrimInt: { |
| 3398 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3399 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3400 | if (op->IsShl()) { |
| 3401 | __ shll(first_reg, second_reg); |
| 3402 | } else if (op->IsShr()) { |
| 3403 | __ sarl(first_reg, second_reg); |
| 3404 | } else { |
| 3405 | __ shrl(first_reg, second_reg); |
| 3406 | } |
| 3407 | } else { |
Nicolas Geoffray | 486cc19 | 2014-12-08 18:00:55 +0000 | [diff] [blame] | 3408 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3409 | if (op->IsShl()) { |
| 3410 | __ shll(first_reg, imm); |
| 3411 | } else if (op->IsShr()) { |
| 3412 | __ sarl(first_reg, imm); |
| 3413 | } else { |
| 3414 | __ shrl(first_reg, imm); |
| 3415 | } |
| 3416 | } |
| 3417 | break; |
| 3418 | } |
| 3419 | case Primitive::kPrimLong: { |
| 3420 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3421 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3422 | if (op->IsShl()) { |
| 3423 | __ shlq(first_reg, second_reg); |
| 3424 | } else if (op->IsShr()) { |
| 3425 | __ sarq(first_reg, second_reg); |
| 3426 | } else { |
| 3427 | __ shrq(first_reg, second_reg); |
| 3428 | } |
| 3429 | } else { |
Nicolas Geoffray | 486cc19 | 2014-12-08 18:00:55 +0000 | [diff] [blame] | 3430 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3431 | if (op->IsShl()) { |
| 3432 | __ shlq(first_reg, imm); |
| 3433 | } else if (op->IsShr()) { |
| 3434 | __ sarq(first_reg, imm); |
| 3435 | } else { |
| 3436 | __ shrq(first_reg, imm); |
| 3437 | } |
| 3438 | } |
| 3439 | break; |
| 3440 | } |
| 3441 | default: |
| 3442 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3443 | } |
| 3444 | } |
| 3445 | |
| 3446 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 3447 | HandleShift(shl); |
| 3448 | } |
| 3449 | |
| 3450 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 3451 | HandleShift(shl); |
| 3452 | } |
| 3453 | |
| 3454 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 3455 | HandleShift(shr); |
| 3456 | } |
| 3457 | |
| 3458 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 3459 | HandleShift(shr); |
| 3460 | } |
| 3461 | |
| 3462 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 3463 | HandleShift(ushr); |
| 3464 | } |
| 3465 | |
| 3466 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 3467 | HandleShift(ushr); |
| 3468 | } |
| 3469 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3470 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3471 | LocationSummary* locations = |
| 3472 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3473 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3474 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3475 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3476 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3477 | } |
| 3478 | |
| 3479 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
| 3480 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3481 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 3482 | instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3483 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3484 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3485 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3486 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3487 | instruction, |
| 3488 | instruction->GetDexPc(), |
| 3489 | nullptr); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3490 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 3491 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3492 | } |
| 3493 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3494 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 3495 | LocationSummary* locations = |
| 3496 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3497 | InvokeRuntimeCallingConvention calling_convention; |
| 3498 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3499 | locations->SetOut(Location::RegisterLocation(RAX)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3500 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3501 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3502 | } |
| 3503 | |
| 3504 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| 3505 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3506 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 3507 | instruction->GetTypeIndex()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3508 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3509 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3510 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3511 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3512 | instruction, |
| 3513 | instruction->GetDexPc(), |
| 3514 | nullptr); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3515 | |
| 3516 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3517 | } |
| 3518 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3519 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3520 | LocationSummary* locations = |
| 3521 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3522 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3523 | if (location.IsStackSlot()) { |
| 3524 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3525 | } else if (location.IsDoubleStackSlot()) { |
| 3526 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3527 | } |
| 3528 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3529 | } |
| 3530 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3531 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 3532 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3533 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3534 | } |
| 3535 | |
| 3536 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3537 | LocationSummary* locations = |
| 3538 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3539 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3540 | } |
| 3541 | |
| 3542 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 3543 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3544 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3545 | } |
| 3546 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3547 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3548 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3549 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3550 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3551 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3552 | } |
| 3553 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3554 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 3555 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3556 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 3557 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3558 | Location out = locations->Out(); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3559 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3560 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3561 | __ notl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3562 | break; |
| 3563 | |
| 3564 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3565 | __ notq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3566 | break; |
| 3567 | |
| 3568 | default: |
| 3569 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3570 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3571 | } |
| 3572 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3573 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3574 | LocationSummary* locations = |
| 3575 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3576 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3577 | locations->SetOut(Location::SameAsFirstInput()); |
| 3578 | } |
| 3579 | |
| 3580 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3581 | LocationSummary* locations = bool_not->GetLocations(); |
| 3582 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 3583 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 3584 | Location out = locations->Out(); |
| 3585 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 3586 | } |
| 3587 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3588 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3589 | LocationSummary* locations = |
| 3590 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3591 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 3592 | locations->SetInAt(i, Location::Any()); |
| 3593 | } |
| 3594 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3595 | } |
| 3596 | |
| 3597 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3598 | UNUSED(instruction); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3599 | LOG(FATAL) << "Unimplemented"; |
| 3600 | } |
| 3601 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3602 | void InstructionCodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3603 | /* |
| 3604 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 3605 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 3606 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 3607 | */ |
| 3608 | switch (kind) { |
| 3609 | case MemBarrierKind::kAnyAny: { |
| 3610 | __ mfence(); |
| 3611 | break; |
| 3612 | } |
| 3613 | case MemBarrierKind::kAnyStore: |
| 3614 | case MemBarrierKind::kLoadAny: |
| 3615 | case MemBarrierKind::kStoreStore: { |
| 3616 | // nop |
| 3617 | break; |
| 3618 | } |
| 3619 | default: |
| 3620 | LOG(FATAL) << "Unexpected memory barier " << kind; |
| 3621 | } |
| 3622 | } |
| 3623 | |
| 3624 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 3625 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 3626 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3627 | LocationSummary* locations = |
| 3628 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3629 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3630 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3631 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3632 | } else { |
| 3633 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3634 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3635 | } |
| 3636 | |
| 3637 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 3638 | const FieldInfo& field_info) { |
| 3639 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 3640 | |
| 3641 | LocationSummary* locations = instruction->GetLocations(); |
| 3642 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3643 | Location out = locations->Out(); |
| 3644 | bool is_volatile = field_info.IsVolatile(); |
| 3645 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3646 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3647 | |
| 3648 | switch (field_type) { |
| 3649 | case Primitive::kPrimBoolean: { |
| 3650 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3651 | break; |
| 3652 | } |
| 3653 | |
| 3654 | case Primitive::kPrimByte: { |
| 3655 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3656 | break; |
| 3657 | } |
| 3658 | |
| 3659 | case Primitive::kPrimShort: { |
| 3660 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3661 | break; |
| 3662 | } |
| 3663 | |
| 3664 | case Primitive::kPrimChar: { |
| 3665 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3666 | break; |
| 3667 | } |
| 3668 | |
| 3669 | case Primitive::kPrimInt: |
| 3670 | case Primitive::kPrimNot: { |
| 3671 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3672 | break; |
| 3673 | } |
| 3674 | |
| 3675 | case Primitive::kPrimLong: { |
| 3676 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3677 | break; |
| 3678 | } |
| 3679 | |
| 3680 | case Primitive::kPrimFloat: { |
| 3681 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 3682 | break; |
| 3683 | } |
| 3684 | |
| 3685 | case Primitive::kPrimDouble: { |
| 3686 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 3687 | break; |
| 3688 | } |
| 3689 | |
| 3690 | case Primitive::kPrimVoid: |
| 3691 | LOG(FATAL) << "Unreachable type " << field_type; |
| 3692 | UNREACHABLE(); |
| 3693 | } |
| 3694 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3695 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3696 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3697 | if (is_volatile) { |
| 3698 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 3699 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3700 | |
| 3701 | if (field_type == Primitive::kPrimNot) { |
| 3702 | __ MaybeUnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 3703 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3704 | } |
| 3705 | |
| 3706 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 3707 | const FieldInfo& field_info) { |
| 3708 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3709 | |
| 3710 | LocationSummary* locations = |
| 3711 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3712 | Primitive::Type field_type = field_info.GetFieldType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3713 | bool needs_write_barrier = |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3714 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3715 | |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3716 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3717 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
| 3718 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3719 | } else { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3720 | locations->SetInAt(1, Location::RegisterOrInt32LongConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3721 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3722 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3723 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3724 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3725 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3726 | } else if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 3727 | // Temporary register for the reference poisoning. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3728 | locations->AddTemp(Location::RequiresRegister()); |
| 3729 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3730 | } |
| 3731 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3732 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3733 | const FieldInfo& field_info, |
| 3734 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3735 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3736 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3737 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3738 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3739 | Location value = locations->InAt(1); |
| 3740 | bool is_volatile = field_info.IsVolatile(); |
| 3741 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3742 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3743 | |
| 3744 | if (is_volatile) { |
| 3745 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 3746 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3747 | |
| 3748 | switch (field_type) { |
| 3749 | case Primitive::kPrimBoolean: |
| 3750 | case Primitive::kPrimByte: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3751 | if (value.IsConstant()) { |
| 3752 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 3753 | __ movb(Address(base, offset), Immediate(v)); |
| 3754 | } else { |
| 3755 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3756 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3757 | break; |
| 3758 | } |
| 3759 | |
| 3760 | case Primitive::kPrimShort: |
| 3761 | case Primitive::kPrimChar: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3762 | if (value.IsConstant()) { |
| 3763 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 3764 | __ movw(Address(base, offset), Immediate(v)); |
| 3765 | } else { |
| 3766 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3767 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3768 | break; |
| 3769 | } |
| 3770 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3771 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3772 | case Primitive::kPrimNot: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3773 | if (value.IsConstant()) { |
| 3774 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3775 | // `field_type == Primitive::kPrimNot` implies `v == 0`. |
| 3776 | DCHECK((field_type != Primitive::kPrimNot) || (v == 0)); |
| 3777 | // Note: if heap poisoning is enabled, no need to poison |
| 3778 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 3779 | __ movl(Address(base, offset), Immediate(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3780 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3781 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 3782 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3783 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 3784 | __ PoisonHeapReference(temp); |
| 3785 | __ movl(Address(base, offset), temp); |
| 3786 | } else { |
| 3787 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3788 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3789 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3790 | break; |
| 3791 | } |
| 3792 | |
| 3793 | case Primitive::kPrimLong: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3794 | if (value.IsConstant()) { |
| 3795 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| 3796 | DCHECK(IsInt<32>(v)); |
| 3797 | int32_t v_32 = v; |
| 3798 | __ movq(Address(base, offset), Immediate(v_32)); |
| 3799 | } else { |
| 3800 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3801 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3802 | break; |
| 3803 | } |
| 3804 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3805 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3806 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3807 | break; |
| 3808 | } |
| 3809 | |
| 3810 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3811 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3812 | break; |
| 3813 | } |
| 3814 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3815 | case Primitive::kPrimVoid: |
| 3816 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3817 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3818 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3819 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3820 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3821 | |
| 3822 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 3823 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3824 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3825 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3826 | } |
| 3827 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3828 | if (is_volatile) { |
| 3829 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 3830 | } |
| 3831 | } |
| 3832 | |
| 3833 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 3834 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3835 | } |
| 3836 | |
| 3837 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3838 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3839 | } |
| 3840 | |
| 3841 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3842 | HandleFieldGet(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3843 | } |
| 3844 | |
| 3845 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3846 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3847 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3848 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3849 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3850 | HandleFieldGet(instruction); |
| 3851 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3852 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3853 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3854 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3855 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3856 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3857 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3858 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3859 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3860 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3861 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3862 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3863 | } |
| 3864 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame^] | 3865 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldGet( |
| 3866 | HUnresolvedInstanceFieldGet* instruction) { |
| 3867 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3868 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3869 | instruction, instruction->GetFieldType(), calling_convention); |
| 3870 | } |
| 3871 | |
| 3872 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldGet( |
| 3873 | HUnresolvedInstanceFieldGet* instruction) { |
| 3874 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3875 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3876 | instruction->GetFieldType(), |
| 3877 | instruction->GetFieldIndex(), |
| 3878 | instruction->GetDexPc(), |
| 3879 | calling_convention); |
| 3880 | } |
| 3881 | |
| 3882 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldSet( |
| 3883 | HUnresolvedInstanceFieldSet* instruction) { |
| 3884 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3885 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3886 | instruction, instruction->GetFieldType(), calling_convention); |
| 3887 | } |
| 3888 | |
| 3889 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldSet( |
| 3890 | HUnresolvedInstanceFieldSet* instruction) { |
| 3891 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3892 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3893 | instruction->GetFieldType(), |
| 3894 | instruction->GetFieldIndex(), |
| 3895 | instruction->GetDexPc(), |
| 3896 | calling_convention); |
| 3897 | } |
| 3898 | |
| 3899 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldGet( |
| 3900 | HUnresolvedStaticFieldGet* instruction) { |
| 3901 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3902 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3903 | instruction, instruction->GetFieldType(), calling_convention); |
| 3904 | } |
| 3905 | |
| 3906 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldGet( |
| 3907 | HUnresolvedStaticFieldGet* instruction) { |
| 3908 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3909 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3910 | instruction->GetFieldType(), |
| 3911 | instruction->GetFieldIndex(), |
| 3912 | instruction->GetDexPc(), |
| 3913 | calling_convention); |
| 3914 | } |
| 3915 | |
| 3916 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldSet( |
| 3917 | HUnresolvedStaticFieldSet* instruction) { |
| 3918 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3919 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3920 | instruction, instruction->GetFieldType(), calling_convention); |
| 3921 | } |
| 3922 | |
| 3923 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldSet( |
| 3924 | HUnresolvedStaticFieldSet* instruction) { |
| 3925 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3926 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3927 | instruction->GetFieldType(), |
| 3928 | instruction->GetFieldIndex(), |
| 3929 | instruction->GetDexPc(), |
| 3930 | calling_convention); |
| 3931 | } |
| 3932 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3933 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3934 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3935 | ? LocationSummary::kCallOnSlowPath |
| 3936 | : LocationSummary::kNoCall; |
| 3937 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 3938 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3939 | ? Location::RequiresRegister() |
| 3940 | : Location::Any(); |
| 3941 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3942 | if (instruction->HasUses()) { |
| 3943 | locations->SetOut(Location::SameAsFirstInput()); |
| 3944 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3945 | } |
| 3946 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3947 | void InstructionCodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3948 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 3949 | return; |
| 3950 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3951 | LocationSummary* locations = instruction->GetLocations(); |
| 3952 | Location obj = locations->InAt(0); |
| 3953 | |
| 3954 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
| 3955 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3956 | } |
| 3957 | |
| 3958 | void InstructionCodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3959 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3960 | codegen_->AddSlowPath(slow_path); |
| 3961 | |
| 3962 | LocationSummary* locations = instruction->GetLocations(); |
| 3963 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3964 | |
| 3965 | if (obj.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3966 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3967 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3968 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3969 | } else { |
| 3970 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3971 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3972 | __ jmp(slow_path->GetEntryLabel()); |
| 3973 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3974 | } |
| 3975 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3976 | } |
| 3977 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3978 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3979 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3980 | GenerateImplicitNullCheck(instruction); |
| 3981 | } else { |
| 3982 | GenerateExplicitNullCheck(instruction); |
| 3983 | } |
| 3984 | } |
| 3985 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3986 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3987 | LocationSummary* locations = |
| 3988 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3989 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3990 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3991 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3992 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3993 | } else { |
| 3994 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3995 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3996 | } |
| 3997 | |
| 3998 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 3999 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4000 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4001 | Location index = locations->InAt(1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4002 | Primitive::Type type = instruction->GetType(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4003 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4004 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4005 | case Primitive::kPrimBoolean: { |
| 4006 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4007 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4008 | if (index.IsConstant()) { |
| 4009 | __ movzxb(out, Address(obj, |
| 4010 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4011 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4012 | __ movzxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4013 | } |
| 4014 | break; |
| 4015 | } |
| 4016 | |
| 4017 | case Primitive::kPrimByte: { |
| 4018 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4019 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4020 | if (index.IsConstant()) { |
| 4021 | __ movsxb(out, Address(obj, |
| 4022 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4023 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4024 | __ movsxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4025 | } |
| 4026 | break; |
| 4027 | } |
| 4028 | |
| 4029 | case Primitive::kPrimShort: { |
| 4030 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4031 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4032 | if (index.IsConstant()) { |
| 4033 | __ movsxw(out, Address(obj, |
| 4034 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4035 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4036 | __ movsxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4037 | } |
| 4038 | break; |
| 4039 | } |
| 4040 | |
| 4041 | case Primitive::kPrimChar: { |
| 4042 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4043 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4044 | if (index.IsConstant()) { |
| 4045 | __ movzxw(out, Address(obj, |
| 4046 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4047 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4048 | __ movzxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4049 | } |
| 4050 | break; |
| 4051 | } |
| 4052 | |
| 4053 | case Primitive::kPrimInt: |
| 4054 | case Primitive::kPrimNot: { |
Roland Levillain | 33d6903 | 2015-06-18 18:20:59 +0100 | [diff] [blame] | 4055 | static_assert(sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4056 | "art::mirror::HeapReference<mirror::Object> and int32_t have different sizes."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4057 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4058 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4059 | if (index.IsConstant()) { |
| 4060 | __ movl(out, Address(obj, |
| 4061 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4062 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4063 | __ movl(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4064 | } |
| 4065 | break; |
| 4066 | } |
| 4067 | |
| 4068 | case Primitive::kPrimLong: { |
| 4069 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4070 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4071 | if (index.IsConstant()) { |
| 4072 | __ movq(out, Address(obj, |
| 4073 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4074 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4075 | __ movq(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4076 | } |
| 4077 | break; |
| 4078 | } |
| 4079 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4080 | case Primitive::kPrimFloat: { |
| 4081 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4082 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4083 | if (index.IsConstant()) { |
| 4084 | __ movss(out, Address(obj, |
| 4085 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4086 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4087 | __ movss(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4088 | } |
| 4089 | break; |
| 4090 | } |
| 4091 | |
| 4092 | case Primitive::kPrimDouble: { |
| 4093 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4094 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4095 | if (index.IsConstant()) { |
| 4096 | __ movsd(out, Address(obj, |
| 4097 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4098 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4099 | __ movsd(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4100 | } |
| 4101 | break; |
| 4102 | } |
| 4103 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4104 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4105 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4106 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4107 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4108 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4109 | |
| 4110 | if (type == Primitive::kPrimNot) { |
| 4111 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4112 | __ MaybeUnpoisonHeapReference(out); |
| 4113 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4114 | } |
| 4115 | |
| 4116 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4117 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4118 | |
| 4119 | bool needs_write_barrier = |
| 4120 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4121 | bool may_need_runtime_call = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4122 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4123 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4124 | instruction, |
| 4125 | may_need_runtime_call ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4126 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4127 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4128 | locations->SetInAt( |
| 4129 | 1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4130 | locations->SetInAt(2, Location::RequiresRegister()); |
| 4131 | if (value_type == Primitive::kPrimLong) { |
| 4132 | locations->SetInAt(2, Location::RegisterOrInt32LongConstant(instruction->InputAt(2))); |
| 4133 | } else if (value_type == Primitive::kPrimFloat || value_type == Primitive::kPrimDouble) { |
| 4134 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| 4135 | } else { |
| 4136 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 4137 | } |
| 4138 | |
| 4139 | if (needs_write_barrier) { |
| 4140 | // Temporary registers for the write barrier. |
| 4141 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 4142 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4143 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4144 | } |
| 4145 | |
| 4146 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 4147 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4148 | CpuRegister array = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4149 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4150 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4151 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4152 | bool may_need_runtime_call = locations->CanCall(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4153 | bool needs_write_barrier = |
| 4154 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4155 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4156 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4157 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4158 | |
| 4159 | switch (value_type) { |
| 4160 | case Primitive::kPrimBoolean: |
| 4161 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4162 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 4163 | Address address = index.IsConstant() |
| 4164 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 4165 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_1, offset); |
| 4166 | if (value.IsRegister()) { |
| 4167 | __ movb(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4168 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4169 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4170 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4171 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4172 | break; |
| 4173 | } |
| 4174 | |
| 4175 | case Primitive::kPrimShort: |
| 4176 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4177 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 4178 | Address address = index.IsConstant() |
| 4179 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 4180 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_2, offset); |
| 4181 | if (value.IsRegister()) { |
| 4182 | __ movw(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4183 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4184 | DCHECK(value.IsConstant()) << value; |
| 4185 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4186 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4187 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4188 | break; |
| 4189 | } |
| 4190 | |
| 4191 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4192 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4193 | Address address = index.IsConstant() |
| 4194 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4195 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
| 4196 | if (!value.IsRegister()) { |
| 4197 | // Just setting null. |
| 4198 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 4199 | DCHECK(value.IsConstant()) << value; |
| 4200 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4201 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4202 | DCHECK(!needs_write_barrier); |
| 4203 | DCHECK(!may_need_runtime_call); |
| 4204 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4205 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4206 | |
| 4207 | DCHECK(needs_write_barrier); |
| 4208 | CpuRegister register_value = value.AsRegister<CpuRegister>(); |
| 4209 | NearLabel done, not_null, do_put; |
| 4210 | SlowPathCode* slow_path = nullptr; |
| 4211 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4212 | if (may_need_runtime_call) { |
| 4213 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86_64(instruction); |
| 4214 | codegen_->AddSlowPath(slow_path); |
| 4215 | if (instruction->GetValueCanBeNull()) { |
| 4216 | __ testl(register_value, register_value); |
| 4217 | __ j(kNotEqual, ¬_null); |
| 4218 | __ movl(address, Immediate(0)); |
| 4219 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4220 | __ jmp(&done); |
| 4221 | __ Bind(¬_null); |
| 4222 | } |
| 4223 | |
| 4224 | __ movl(temp, Address(array, class_offset)); |
| 4225 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4226 | __ MaybeUnpoisonHeapReference(temp); |
| 4227 | __ movl(temp, Address(temp, component_offset)); |
| 4228 | // No need to poison/unpoison, we're comparing two poisoned references. |
| 4229 | __ cmpl(temp, Address(register_value, class_offset)); |
| 4230 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4231 | __ j(kEqual, &do_put); |
| 4232 | __ MaybeUnpoisonHeapReference(temp); |
| 4233 | __ movl(temp, Address(temp, super_offset)); |
| 4234 | // No need to unpoison the result, we're comparing against null. |
| 4235 | __ testl(temp, temp); |
| 4236 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4237 | __ Bind(&do_put); |
| 4238 | } else { |
| 4239 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4240 | } |
| 4241 | } |
| 4242 | |
| 4243 | if (kPoisonHeapReferences) { |
| 4244 | __ movl(temp, register_value); |
| 4245 | __ PoisonHeapReference(temp); |
| 4246 | __ movl(address, temp); |
| 4247 | } else { |
| 4248 | __ movl(address, register_value); |
| 4249 | } |
| 4250 | if (!may_need_runtime_call) { |
| 4251 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4252 | } |
| 4253 | |
| 4254 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 4255 | codegen_->MarkGCCard( |
| 4256 | temp, card, array, value.AsRegister<CpuRegister>(), instruction->GetValueCanBeNull()); |
| 4257 | __ Bind(&done); |
| 4258 | |
| 4259 | if (slow_path != nullptr) { |
| 4260 | __ Bind(slow_path->GetExitLabel()); |
| 4261 | } |
| 4262 | |
| 4263 | break; |
| 4264 | } |
| 4265 | case Primitive::kPrimInt: { |
| 4266 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4267 | Address address = index.IsConstant() |
| 4268 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4269 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
| 4270 | if (value.IsRegister()) { |
| 4271 | __ movl(address, value.AsRegister<CpuRegister>()); |
| 4272 | } else { |
| 4273 | DCHECK(value.IsConstant()) << value; |
| 4274 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4275 | __ movl(address, Immediate(v)); |
| 4276 | } |
| 4277 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4278 | break; |
| 4279 | } |
| 4280 | |
| 4281 | case Primitive::kPrimLong: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4282 | uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| 4283 | Address address = index.IsConstant() |
| 4284 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 4285 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset); |
| 4286 | if (value.IsRegister()) { |
| 4287 | __ movq(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4288 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4289 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| 4290 | DCHECK(IsInt<32>(v)); |
| 4291 | int32_t v_32 = v; |
| 4292 | __ movq(address, Immediate(v_32)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4293 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4294 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4295 | break; |
| 4296 | } |
| 4297 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4298 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4299 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4300 | Address address = index.IsConstant() |
| 4301 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4302 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
| 4303 | DCHECK(value.IsFpuRegister()); |
| 4304 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4305 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4306 | break; |
| 4307 | } |
| 4308 | |
| 4309 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4310 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4311 | Address address = index.IsConstant() |
| 4312 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 4313 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset); |
| 4314 | DCHECK(value.IsFpuRegister()); |
| 4315 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4316 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4317 | break; |
| 4318 | } |
| 4319 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4320 | case Primitive::kPrimVoid: |
| 4321 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4322 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4323 | } |
| 4324 | } |
| 4325 | |
| 4326 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4327 | LocationSummary* locations = |
| 4328 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4329 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4330 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4331 | } |
| 4332 | |
| 4333 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
| 4334 | LocationSummary* locations = instruction->GetLocations(); |
| 4335 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4336 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4337 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4338 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4339 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4340 | } |
| 4341 | |
| 4342 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4343 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4344 | ? LocationSummary::kCallOnSlowPath |
| 4345 | : LocationSummary::kNoCall; |
| 4346 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4347 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4348 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4349 | if (instruction->HasUses()) { |
| 4350 | locations->SetOut(Location::SameAsFirstInput()); |
| 4351 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4352 | } |
| 4353 | |
| 4354 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4355 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4356 | Location index_loc = locations->InAt(0); |
| 4357 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4358 | SlowPathCode* slow_path = |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4359 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4360 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4361 | if (length_loc.IsConstant()) { |
| 4362 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 4363 | if (index_loc.IsConstant()) { |
| 4364 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 4365 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4366 | if (index < 0 || index >= length) { |
| 4367 | codegen_->AddSlowPath(slow_path); |
| 4368 | __ jmp(slow_path->GetEntryLabel()); |
| 4369 | } else { |
| 4370 | // Some optimization after BCE may have generated this, and we should not |
| 4371 | // generate a bounds check if it is a valid range. |
| 4372 | } |
| 4373 | return; |
| 4374 | } |
| 4375 | |
| 4376 | // We have to reverse the jump condition because the length is the constant. |
| 4377 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 4378 | __ cmpl(index_reg, Immediate(length)); |
| 4379 | codegen_->AddSlowPath(slow_path); |
| 4380 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4381 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4382 | CpuRegister length = length_loc.AsRegister<CpuRegister>(); |
| 4383 | if (index_loc.IsConstant()) { |
| 4384 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4385 | __ cmpl(length, Immediate(value)); |
| 4386 | } else { |
| 4387 | __ cmpl(length, index_loc.AsRegister<CpuRegister>()); |
| 4388 | } |
| 4389 | codegen_->AddSlowPath(slow_path); |
| 4390 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4391 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4392 | } |
| 4393 | |
| 4394 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 4395 | CpuRegister card, |
| 4396 | CpuRegister object, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4397 | CpuRegister value, |
| 4398 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4399 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4400 | if (value_can_be_null) { |
| 4401 | __ testl(value, value); |
| 4402 | __ j(kEqual, &is_null); |
| 4403 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4404 | __ gs()->movq(card, Address::Absolute( |
| 4405 | Thread::CardTableOffset<kX86_64WordSize>().Int32Value(), true)); |
| 4406 | __ movq(temp, object); |
| 4407 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4408 | __ movb(Address(temp, card, TIMES_1, 0), card); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4409 | if (value_can_be_null) { |
| 4410 | __ Bind(&is_null); |
| 4411 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4412 | } |
| 4413 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4414 | void LocationsBuilderX86_64::VisitTemporary(HTemporary* temp) { |
| 4415 | temp->SetLocations(nullptr); |
| 4416 | } |
| 4417 | |
| 4418 | void InstructionCodeGeneratorX86_64::VisitTemporary(HTemporary* temp) { |
| 4419 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4420 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4421 | } |
| 4422 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4423 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4424 | UNUSED(instruction); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4425 | LOG(FATAL) << "Unimplemented"; |
| 4426 | } |
| 4427 | |
| 4428 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4429 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4430 | } |
| 4431 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4432 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4433 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4434 | } |
| 4435 | |
| 4436 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4437 | HBasicBlock* block = instruction->GetBlock(); |
| 4438 | if (block->GetLoopInformation() != nullptr) { |
| 4439 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4440 | // The back edge will generate the suspend check. |
| 4441 | return; |
| 4442 | } |
| 4443 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4444 | // The goto will generate the suspend check. |
| 4445 | return; |
| 4446 | } |
| 4447 | GenerateSuspendCheck(instruction, nullptr); |
| 4448 | } |
| 4449 | |
| 4450 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 4451 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4452 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4453 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 4454 | if (slow_path == nullptr) { |
| 4455 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
| 4456 | instruction->SetSlowPath(slow_path); |
| 4457 | codegen_->AddSlowPath(slow_path); |
| 4458 | if (successor != nullptr) { |
| 4459 | DCHECK(successor->IsLoopHeader()); |
| 4460 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 4461 | } |
| 4462 | } else { |
| 4463 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 4464 | } |
| 4465 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4466 | __ gs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4467 | Thread::ThreadFlagsOffset<kX86_64WordSize>().Int32Value(), true), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4468 | if (successor == nullptr) { |
| 4469 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4470 | __ Bind(slow_path->GetReturnLabel()); |
| 4471 | } else { |
| 4472 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 4473 | __ jmp(slow_path->GetEntryLabel()); |
| 4474 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4475 | } |
| 4476 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4477 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 4478 | return codegen_->GetAssembler(); |
| 4479 | } |
| 4480 | |
| 4481 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 4482 | DCHECK_LT(index, moves_.size()); |
| 4483 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4484 | Location source = move->GetSource(); |
| 4485 | Location destination = move->GetDestination(); |
| 4486 | |
| 4487 | if (source.IsRegister()) { |
| 4488 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4489 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4490 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4491 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4492 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4493 | } else { |
| 4494 | DCHECK(destination.IsDoubleStackSlot()); |
| 4495 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4496 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4497 | } |
| 4498 | } else if (source.IsStackSlot()) { |
| 4499 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4500 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4501 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4502 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4503 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4504 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4505 | } else { |
| 4506 | DCHECK(destination.IsStackSlot()); |
| 4507 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 4508 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 4509 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4510 | } else if (source.IsDoubleStackSlot()) { |
| 4511 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4512 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4513 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4514 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4515 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 4516 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4517 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 4518 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4519 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 4520 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 4521 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4522 | } else if (source.IsConstant()) { |
| 4523 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4524 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 4525 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4526 | if (destination.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4527 | if (value == 0) { |
| 4528 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 4529 | } else { |
| 4530 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 4531 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4532 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4533 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4534 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4535 | } |
| 4536 | } else if (constant->IsLongConstant()) { |
| 4537 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 4538 | if (destination.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4539 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4540 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4541 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 4542 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4543 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4544 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4545 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4546 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4547 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4548 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4549 | if (value == 0) { |
| 4550 | // easy FP 0.0. |
| 4551 | __ xorps(dest, dest); |
| 4552 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4553 | __ movss(dest, codegen_->LiteralFloatAddress(fp_value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4554 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4555 | } else { |
| 4556 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4557 | Immediate imm(value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4558 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 4559 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4560 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4561 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4562 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4563 | int64_t value = bit_cast<int64_t, double>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4564 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4565 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4566 | if (value == 0) { |
| 4567 | __ xorpd(dest, dest); |
| 4568 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4569 | __ movsd(dest, codegen_->LiteralDoubleAddress(fp_value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4570 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4571 | } else { |
| 4572 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 4573 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4574 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4575 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4576 | } else if (source.IsFpuRegister()) { |
| 4577 | if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4578 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4579 | } else if (destination.IsStackSlot()) { |
| 4580 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4581 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4582 | } else { |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 4583 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4584 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4585 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4586 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4587 | } |
| 4588 | } |
| 4589 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4590 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4591 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4592 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 4593 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4594 | } |
| 4595 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4596 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4597 | ScratchRegisterScope ensure_scratch( |
| 4598 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 4599 | |
| 4600 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 4601 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 4602 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 4603 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 4604 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 4605 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 4606 | CpuRegister(ensure_scratch.GetRegister())); |
| 4607 | } |
| 4608 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4609 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 4610 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 4611 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 4612 | __ movq(reg, CpuRegister(TMP)); |
| 4613 | } |
| 4614 | |
| 4615 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 4616 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4617 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4618 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4619 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 4620 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 4621 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 4622 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 4623 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 4624 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 4625 | CpuRegister(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4626 | } |
| 4627 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4628 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 4629 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 4630 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 4631 | __ movd(reg, CpuRegister(TMP)); |
| 4632 | } |
| 4633 | |
| 4634 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 4635 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 4636 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 4637 | __ movd(reg, CpuRegister(TMP)); |
| 4638 | } |
| 4639 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4640 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 4641 | DCHECK_LT(index, moves_.size()); |
| 4642 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4643 | Location source = move->GetSource(); |
| 4644 | Location destination = move->GetDestination(); |
| 4645 | |
| 4646 | if (source.IsRegister() && destination.IsRegister()) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4647 | __ xchgq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4648 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4649 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4650 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4651 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4652 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4653 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 4654 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4655 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4656 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4657 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4658 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 4659 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4660 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4661 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 4662 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 4663 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4664 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4665 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4666 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4667 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4668 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4669 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4670 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4671 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4672 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4673 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4674 | } |
| 4675 | } |
| 4676 | |
| 4677 | |
| 4678 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 4679 | __ pushq(CpuRegister(reg)); |
| 4680 | } |
| 4681 | |
| 4682 | |
| 4683 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 4684 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4685 | } |
| 4686 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4687 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4688 | SlowPathCode* slow_path, CpuRegister class_reg) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4689 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 4690 | Immediate(mirror::Class::kStatusInitialized)); |
| 4691 | __ j(kLess, slow_path->GetEntryLabel()); |
| 4692 | __ Bind(slow_path->GetExitLabel()); |
| 4693 | // No need for memory fence, thanks to the X86_64 memory model. |
| 4694 | } |
| 4695 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4696 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4697 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() |
| 4698 | ? LocationSummary::kCallOnSlowPath |
| 4699 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4700 | LocationSummary* locations = |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4701 | new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4702 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4703 | locations->SetOut(Location::RequiresRegister()); |
| 4704 | } |
| 4705 | |
| 4706 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4707 | LocationSummary* locations = cls->GetLocations(); |
| 4708 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4709 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4710 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4711 | DCHECK(!cls->CanCallRuntime()); |
| 4712 | DCHECK(!cls->MustGenerateClinitCheck()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4713 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4714 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4715 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4716 | __ movq(out, Address( |
| 4717 | current_method, ArtMethod::DexCacheResolvedTypesOffset(kX86_64PointerSize).Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4718 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4719 | // TODO: We will need a read barrier here. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4720 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4721 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4722 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 4723 | codegen_->AddSlowPath(slow_path); |
| 4724 | __ testl(out, out); |
| 4725 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4726 | if (cls->MustGenerateClinitCheck()) { |
| 4727 | GenerateClassInitializationCheck(slow_path, out); |
| 4728 | } else { |
| 4729 | __ Bind(slow_path->GetExitLabel()); |
| 4730 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4731 | } |
| 4732 | } |
| 4733 | |
| 4734 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 4735 | LocationSummary* locations = |
| 4736 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 4737 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4738 | if (check->HasUses()) { |
| 4739 | locations->SetOut(Location::SameAsFirstInput()); |
| 4740 | } |
| 4741 | } |
| 4742 | |
| 4743 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4744 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4745 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4746 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4747 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4748 | GenerateClassInitializationCheck(slow_path, |
| 4749 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4750 | } |
| 4751 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4752 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
| 4753 | LocationSummary* locations = |
| 4754 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4755 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4756 | locations->SetOut(Location::RequiresRegister()); |
| 4757 | } |
| 4758 | |
| 4759 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4760 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86_64(load); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4761 | codegen_->AddSlowPath(slow_path); |
| 4762 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4763 | LocationSummary* locations = load->GetLocations(); |
| 4764 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4765 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4766 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4767 | __ movq(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4768 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4769 | // TODO: We will need a read barrier here. |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4770 | __ testl(out, out); |
| 4771 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4772 | __ Bind(slow_path->GetExitLabel()); |
| 4773 | } |
| 4774 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4775 | static Address GetExceptionTlsAddress() { |
| 4776 | return Address::Absolute(Thread::ExceptionOffset<kX86_64WordSize>().Int32Value(), true); |
| 4777 | } |
| 4778 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4779 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 4780 | LocationSummary* locations = |
| 4781 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 4782 | locations->SetOut(Location::RequiresRegister()); |
| 4783 | } |
| 4784 | |
| 4785 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4786 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 4787 | } |
| 4788 | |
| 4789 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
| 4790 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 4791 | } |
| 4792 | |
| 4793 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 4794 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4795 | } |
| 4796 | |
| 4797 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| 4798 | LocationSummary* locations = |
| 4799 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4800 | InvokeRuntimeCallingConvention calling_convention; |
| 4801 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4802 | } |
| 4803 | |
| 4804 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 4805 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 4806 | instruction, |
| 4807 | instruction->GetDexPc(), |
| 4808 | nullptr); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4809 | } |
| 4810 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4811 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4812 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 4813 | switch (instruction->GetTypeCheckKind()) { |
| 4814 | case TypeCheckKind::kExactCheck: |
| 4815 | case TypeCheckKind::kAbstractClassCheck: |
| 4816 | case TypeCheckKind::kClassHierarchyCheck: |
| 4817 | case TypeCheckKind::kArrayObjectCheck: |
| 4818 | call_kind = LocationSummary::kNoCall; |
| 4819 | break; |
| 4820 | case TypeCheckKind::kInterfaceCheck: |
| 4821 | call_kind = LocationSummary::kCall; |
| 4822 | break; |
| 4823 | case TypeCheckKind::kArrayCheck: |
| 4824 | call_kind = LocationSummary::kCallOnSlowPath; |
| 4825 | break; |
| 4826 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4827 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4828 | if (call_kind != LocationSummary::kCall) { |
| 4829 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4830 | locations->SetInAt(1, Location::Any()); |
| 4831 | // Note that TypeCheckSlowPathX86_64 uses this register too. |
| 4832 | locations->SetOut(Location::RequiresRegister()); |
| 4833 | } else { |
| 4834 | InvokeRuntimeCallingConvention calling_convention; |
| 4835 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4836 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 4837 | locations->SetOut(Location::RegisterLocation(RAX)); |
| 4838 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4839 | } |
| 4840 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4841 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4842 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4843 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4844 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4845 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4846 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4847 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4848 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4849 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4850 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4851 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4852 | |
| 4853 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4854 | // Avoid null check if we know obj is not null. |
| 4855 | if (instruction->MustDoNullCheck()) { |
| 4856 | __ testl(obj, obj); |
| 4857 | __ j(kEqual, &zero); |
| 4858 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4859 | |
| 4860 | // In case of an interface check, we put the object class into the object register. |
| 4861 | // This is safe, as the register is caller-save, and the object must be in another |
| 4862 | // register if it survives the runtime call. |
| 4863 | CpuRegister target = (instruction->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck) |
| 4864 | ? obj |
| 4865 | : out; |
| 4866 | __ movl(target, Address(obj, class_offset)); |
| 4867 | __ MaybeUnpoisonHeapReference(target); |
| 4868 | |
| 4869 | switch (instruction->GetTypeCheckKind()) { |
| 4870 | case TypeCheckKind::kExactCheck: { |
| 4871 | if (cls.IsRegister()) { |
| 4872 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 4873 | } else { |
| 4874 | DCHECK(cls.IsStackSlot()) << cls; |
| 4875 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 4876 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4877 | if (zero.IsLinked()) { |
| 4878 | // Classes must be equal for the instanceof to succeed. |
| 4879 | __ j(kNotEqual, &zero); |
| 4880 | __ movl(out, Immediate(1)); |
| 4881 | __ jmp(&done); |
| 4882 | } else { |
| 4883 | __ setcc(kEqual, out); |
| 4884 | // setcc only sets the low byte. |
| 4885 | __ andl(out, Immediate(1)); |
| 4886 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4887 | break; |
| 4888 | } |
| 4889 | case TypeCheckKind::kAbstractClassCheck: { |
| 4890 | // If the class is abstract, we eagerly fetch the super class of the |
| 4891 | // object to avoid doing a comparison we know will fail. |
| 4892 | NearLabel loop, success; |
| 4893 | __ Bind(&loop); |
| 4894 | __ movl(out, Address(out, super_offset)); |
| 4895 | __ MaybeUnpoisonHeapReference(out); |
| 4896 | __ testl(out, out); |
| 4897 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4898 | __ j(kEqual, &done); |
| 4899 | if (cls.IsRegister()) { |
| 4900 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 4901 | } else { |
| 4902 | DCHECK(cls.IsStackSlot()) << cls; |
| 4903 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 4904 | } |
| 4905 | __ j(kNotEqual, &loop); |
| 4906 | __ movl(out, Immediate(1)); |
| 4907 | if (zero.IsLinked()) { |
| 4908 | __ jmp(&done); |
| 4909 | } |
| 4910 | break; |
| 4911 | } |
| 4912 | case TypeCheckKind::kClassHierarchyCheck: { |
| 4913 | // Walk over the class hierarchy to find a match. |
| 4914 | NearLabel loop, success; |
| 4915 | __ Bind(&loop); |
| 4916 | if (cls.IsRegister()) { |
| 4917 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 4918 | } else { |
| 4919 | DCHECK(cls.IsStackSlot()) << cls; |
| 4920 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 4921 | } |
| 4922 | __ j(kEqual, &success); |
| 4923 | __ movl(out, Address(out, super_offset)); |
| 4924 | __ MaybeUnpoisonHeapReference(out); |
| 4925 | __ testl(out, out); |
| 4926 | __ j(kNotEqual, &loop); |
| 4927 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4928 | __ jmp(&done); |
| 4929 | __ Bind(&success); |
| 4930 | __ movl(out, Immediate(1)); |
| 4931 | if (zero.IsLinked()) { |
| 4932 | __ jmp(&done); |
| 4933 | } |
| 4934 | break; |
| 4935 | } |
| 4936 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4937 | // Do an exact check. |
| 4938 | NearLabel exact_check; |
| 4939 | if (cls.IsRegister()) { |
| 4940 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 4941 | } else { |
| 4942 | DCHECK(cls.IsStackSlot()) << cls; |
| 4943 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 4944 | } |
| 4945 | __ j(kEqual, &exact_check); |
| 4946 | // 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] | 4947 | __ movl(out, Address(out, component_offset)); |
| 4948 | __ MaybeUnpoisonHeapReference(out); |
| 4949 | __ testl(out, out); |
| 4950 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4951 | __ j(kEqual, &done); |
| 4952 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 4953 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4954 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4955 | __ movl(out, Immediate(1)); |
| 4956 | __ jmp(&done); |
| 4957 | break; |
| 4958 | } |
| 4959 | case TypeCheckKind::kArrayCheck: { |
| 4960 | if (cls.IsRegister()) { |
| 4961 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 4962 | } else { |
| 4963 | DCHECK(cls.IsStackSlot()) << cls; |
| 4964 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 4965 | } |
| 4966 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 4967 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64( |
| 4968 | instruction, /* is_fatal */ false); |
| 4969 | codegen_->AddSlowPath(slow_path); |
| 4970 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4971 | __ movl(out, Immediate(1)); |
| 4972 | if (zero.IsLinked()) { |
| 4973 | __ jmp(&done); |
| 4974 | } |
| 4975 | break; |
| 4976 | } |
| 4977 | |
| 4978 | case TypeCheckKind::kInterfaceCheck: |
| 4979 | default: { |
| 4980 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 4981 | instruction, |
| 4982 | instruction->GetDexPc(), |
| 4983 | nullptr); |
| 4984 | if (zero.IsLinked()) { |
| 4985 | __ jmp(&done); |
| 4986 | } |
| 4987 | break; |
| 4988 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4989 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4990 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4991 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4992 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4993 | __ xorl(out, out); |
| 4994 | } |
| 4995 | |
| 4996 | if (done.IsLinked()) { |
| 4997 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4998 | } |
| 4999 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5000 | if (slow_path != nullptr) { |
| 5001 | __ Bind(slow_path->GetExitLabel()); |
| 5002 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5003 | } |
| 5004 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5005 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5006 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5007 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 5008 | |
| 5009 | switch (instruction->GetTypeCheckKind()) { |
| 5010 | case TypeCheckKind::kExactCheck: |
| 5011 | case TypeCheckKind::kAbstractClassCheck: |
| 5012 | case TypeCheckKind::kClassHierarchyCheck: |
| 5013 | case TypeCheckKind::kArrayObjectCheck: |
| 5014 | call_kind = throws_into_catch |
| 5015 | ? LocationSummary::kCallOnSlowPath |
| 5016 | : LocationSummary::kNoCall; |
| 5017 | break; |
| 5018 | case TypeCheckKind::kInterfaceCheck: |
| 5019 | call_kind = LocationSummary::kCall; |
| 5020 | break; |
| 5021 | case TypeCheckKind::kArrayCheck: |
| 5022 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5023 | break; |
| 5024 | } |
| 5025 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5026 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5027 | instruction, call_kind); |
| 5028 | if (call_kind != LocationSummary::kCall) { |
| 5029 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5030 | locations->SetInAt(1, Location::Any()); |
| 5031 | // Note that TypeCheckSlowPathX86_64 uses this register too. |
| 5032 | locations->AddTemp(Location::RequiresRegister()); |
| 5033 | } else { |
| 5034 | InvokeRuntimeCallingConvention calling_convention; |
| 5035 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5036 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5037 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5038 | } |
| 5039 | |
| 5040 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
| 5041 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5042 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5043 | Location cls = locations->InAt(1); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5044 | CpuRegister temp = locations->WillCall() |
| 5045 | ? CpuRegister(kNoRegister) |
| 5046 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame] | 5047 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5048 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5049 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5050 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5051 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 5052 | SlowPathCode* slow_path = nullptr; |
| 5053 | |
| 5054 | if (!locations->WillCall()) { |
| 5055 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64( |
| 5056 | instruction, !locations->CanCall()); |
| 5057 | codegen_->AddSlowPath(slow_path); |
| 5058 | } |
| 5059 | |
| 5060 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5061 | // Avoid null check if we know obj is not null. |
| 5062 | if (instruction->MustDoNullCheck()) { |
| 5063 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5064 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5065 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5066 | |
| 5067 | if (locations->WillCall()) { |
| 5068 | __ movl(obj, Address(obj, class_offset)); |
| 5069 | __ MaybeUnpoisonHeapReference(obj); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5070 | } else { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5071 | __ movl(temp, Address(obj, class_offset)); |
| 5072 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5073 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5074 | |
| 5075 | switch (instruction->GetTypeCheckKind()) { |
| 5076 | case TypeCheckKind::kExactCheck: |
| 5077 | case TypeCheckKind::kArrayCheck: { |
| 5078 | if (cls.IsRegister()) { |
| 5079 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5080 | } else { |
| 5081 | DCHECK(cls.IsStackSlot()) << cls; |
| 5082 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5083 | } |
| 5084 | // Jump to slow path for throwing the exception or doing a |
| 5085 | // more involved array check. |
| 5086 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5087 | break; |
| 5088 | } |
| 5089 | case TypeCheckKind::kAbstractClassCheck: { |
| 5090 | // If the class is abstract, we eagerly fetch the super class of the |
| 5091 | // object to avoid doing a comparison we know will fail. |
| 5092 | NearLabel loop; |
| 5093 | __ Bind(&loop); |
| 5094 | __ movl(temp, Address(temp, super_offset)); |
| 5095 | __ MaybeUnpoisonHeapReference(temp); |
| 5096 | __ testl(temp, temp); |
| 5097 | // Jump to the slow path to throw the exception. |
| 5098 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5099 | if (cls.IsRegister()) { |
| 5100 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5101 | } else { |
| 5102 | DCHECK(cls.IsStackSlot()) << cls; |
| 5103 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5104 | } |
| 5105 | __ j(kNotEqual, &loop); |
| 5106 | break; |
| 5107 | } |
| 5108 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5109 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5110 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5111 | __ Bind(&loop); |
| 5112 | if (cls.IsRegister()) { |
| 5113 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5114 | } else { |
| 5115 | DCHECK(cls.IsStackSlot()) << cls; |
| 5116 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5117 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5118 | __ j(kEqual, &done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5119 | __ movl(temp, Address(temp, super_offset)); |
| 5120 | __ MaybeUnpoisonHeapReference(temp); |
| 5121 | __ testl(temp, temp); |
| 5122 | __ j(kNotEqual, &loop); |
| 5123 | // Jump to the slow path to throw the exception. |
| 5124 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5125 | break; |
| 5126 | } |
| 5127 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5128 | // Do an exact check. |
| 5129 | if (cls.IsRegister()) { |
| 5130 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5131 | } else { |
| 5132 | DCHECK(cls.IsStackSlot()) << cls; |
| 5133 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5134 | } |
| 5135 | __ j(kEqual, &done); |
| 5136 | // 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] | 5137 | __ movl(temp, Address(temp, component_offset)); |
| 5138 | __ MaybeUnpoisonHeapReference(temp); |
| 5139 | __ testl(temp, temp); |
| 5140 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5141 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5142 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5143 | break; |
| 5144 | } |
| 5145 | case TypeCheckKind::kInterfaceCheck: |
| 5146 | default: |
| 5147 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 5148 | instruction, |
| 5149 | instruction->GetDexPc(), |
| 5150 | nullptr); |
| 5151 | break; |
| 5152 | } |
| 5153 | __ Bind(&done); |
| 5154 | |
| 5155 | if (slow_path != nullptr) { |
| 5156 | __ Bind(slow_path->GetExitLabel()); |
| 5157 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5158 | } |
| 5159 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5160 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5161 | LocationSummary* locations = |
| 5162 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5163 | InvokeRuntimeCallingConvention calling_convention; |
| 5164 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5165 | } |
| 5166 | |
| 5167 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5168 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 5169 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 5170 | instruction, |
| 5171 | instruction->GetDexPc(), |
| 5172 | nullptr); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5173 | } |
| 5174 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5175 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 5176 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 5177 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 5178 | |
| 5179 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5180 | LocationSummary* locations = |
| 5181 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5182 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 5183 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 5184 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5185 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5186 | locations->SetOut(Location::SameAsFirstInput()); |
| 5187 | } |
| 5188 | |
| 5189 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 5190 | HandleBitwiseOperation(instruction); |
| 5191 | } |
| 5192 | |
| 5193 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 5194 | HandleBitwiseOperation(instruction); |
| 5195 | } |
| 5196 | |
| 5197 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 5198 | HandleBitwiseOperation(instruction); |
| 5199 | } |
| 5200 | |
| 5201 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5202 | LocationSummary* locations = instruction->GetLocations(); |
| 5203 | Location first = locations->InAt(0); |
| 5204 | Location second = locations->InAt(1); |
| 5205 | DCHECK(first.Equals(locations->Out())); |
| 5206 | |
| 5207 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 5208 | if (second.IsRegister()) { |
| 5209 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5210 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5211 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5212 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5213 | } else { |
| 5214 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5215 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5216 | } |
| 5217 | } else if (second.IsConstant()) { |
| 5218 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 5219 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5220 | __ andl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5221 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5222 | __ orl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5223 | } else { |
| 5224 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5225 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5226 | } |
| 5227 | } else { |
| 5228 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 5229 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5230 | __ andl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5231 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5232 | __ orl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5233 | } else { |
| 5234 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5235 | __ xorl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5236 | } |
| 5237 | } |
| 5238 | } else { |
| 5239 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5240 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 5241 | bool second_is_constant = false; |
| 5242 | int64_t value = 0; |
| 5243 | if (second.IsConstant()) { |
| 5244 | second_is_constant = true; |
| 5245 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5246 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5247 | bool is_int32_value = IsInt<32>(value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5248 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5249 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5250 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5251 | if (is_int32_value) { |
| 5252 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 5253 | } else { |
| 5254 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 5255 | } |
| 5256 | } else if (second.IsDoubleStackSlot()) { |
| 5257 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5258 | } else { |
| 5259 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 5260 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5261 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5262 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5263 | if (is_int32_value) { |
| 5264 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 5265 | } else { |
| 5266 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 5267 | } |
| 5268 | } else if (second.IsDoubleStackSlot()) { |
| 5269 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5270 | } else { |
| 5271 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 5272 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5273 | } else { |
| 5274 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5275 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5276 | if (is_int32_value) { |
| 5277 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 5278 | } else { |
| 5279 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 5280 | } |
| 5281 | } else if (second.IsDoubleStackSlot()) { |
| 5282 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5283 | } else { |
| 5284 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 5285 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5286 | } |
| 5287 | } |
| 5288 | } |
| 5289 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5290 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction) { |
| 5291 | // Nothing to do, this should be removed during prepare for register allocator. |
| 5292 | UNUSED(instruction); |
| 5293 | LOG(FATAL) << "Unreachable"; |
| 5294 | } |
| 5295 | |
| 5296 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction) { |
| 5297 | // Nothing to do, this should be removed during prepare for register allocator. |
| 5298 | UNUSED(instruction); |
| 5299 | LOG(FATAL) << "Unreachable"; |
| 5300 | } |
| 5301 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5302 | void LocationsBuilderX86_64::VisitFakeString(HFakeString* instruction) { |
| 5303 | DCHECK(codegen_->IsBaseline()); |
| 5304 | LocationSummary* locations = |
| 5305 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5306 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); |
| 5307 | } |
| 5308 | |
| 5309 | void InstructionCodeGeneratorX86_64::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { |
| 5310 | DCHECK(codegen_->IsBaseline()); |
| 5311 | // Will be generated at use site. |
| 5312 | } |
| 5313 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5314 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 5315 | void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5316 | LocationSummary* locations = |
| 5317 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 5318 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5319 | } |
| 5320 | |
| 5321 | void InstructionCodeGeneratorX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5322 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 5323 | int32_t num_entries = switch_instr->GetNumEntries(); |
| 5324 | LocationSummary* locations = switch_instr->GetLocations(); |
| 5325 | CpuRegister value_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5326 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 5327 | |
| 5328 | // Create a series of compare/jumps. |
| 5329 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 5330 | for (int i = 0; i < num_entries; i++) { |
| 5331 | int32_t case_value = lower_bound + i; |
| 5332 | if (case_value == 0) { |
| 5333 | __ testl(value_reg, value_reg); |
| 5334 | } else { |
| 5335 | __ cmpl(value_reg, Immediate(case_value)); |
| 5336 | } |
| 5337 | __ j(kEqual, codegen_->GetLabelOf(successors.at(i))); |
| 5338 | } |
| 5339 | |
| 5340 | // And the default for any other value. |
| 5341 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 5342 | __ jmp(codegen_->GetLabelOf(default_block)); |
| 5343 | } |
| 5344 | } |
| 5345 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5346 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 5347 | if (value == 0) { |
| 5348 | __ xorl(dest, dest); |
| 5349 | } else if (value > 0 && IsInt<32>(value)) { |
| 5350 | // We can use a 32 bit move, as it will zero-extend and is one byte shorter. |
| 5351 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 5352 | } else { |
| 5353 | __ movq(dest, Immediate(value)); |
| 5354 | } |
| 5355 | } |
| 5356 | |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5357 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 5358 | DCHECK(dest.IsDoubleStackSlot()); |
| 5359 | if (IsInt<32>(value)) { |
| 5360 | // Can move directly as an int32 constant. |
| 5361 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 5362 | Immediate(static_cast<int32_t>(value))); |
| 5363 | } else { |
| 5364 | Load64BitValue(CpuRegister(TMP), value); |
| 5365 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 5366 | } |
| 5367 | } |
| 5368 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 5369 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 5370 | // Generate the constant area if needed. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 5371 | X86_64Assembler* assembler = GetAssembler(); |
| 5372 | if (!assembler->IsConstantAreaEmpty()) { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 5373 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 5374 | // byte values. If used for vectors at a later time, this will need to be |
| 5375 | // updated to 16 bytes with the appropriate offset. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 5376 | assembler->Align(4, 0); |
| 5377 | constant_area_start_ = assembler->CodeSize(); |
| 5378 | assembler->AddConstantArea(); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 5379 | } |
| 5380 | |
| 5381 | // And finish up. |
| 5382 | CodeGenerator::Finalize(allocator); |
| 5383 | } |
| 5384 | |
| 5385 | /** |
| 5386 | * Class to handle late fixup of offsets into constant area. |
| 5387 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 5388 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 5389 | public: |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 5390 | RIPFixup(const CodeGeneratorX86_64& codegen, int offset) |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 5391 | : codegen_(codegen), offset_into_constant_area_(offset) {} |
| 5392 | |
| 5393 | private: |
| 5394 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 5395 | // Patch the correct offset for the instruction. We use the address of the |
| 5396 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 5397 | int constant_offset = codegen_.ConstantAreaStart() + offset_into_constant_area_; |
| 5398 | int relative_position = constant_offset - pos; |
| 5399 | |
| 5400 | // Patch in the right value. |
| 5401 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 5402 | } |
| 5403 | |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 5404 | const CodeGeneratorX86_64& codegen_; |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 5405 | |
| 5406 | // Location in constant area that the fixup refers to. |
| 5407 | int offset_into_constant_area_; |
| 5408 | }; |
| 5409 | |
| 5410 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
| 5411 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 5412 | return Address::RIP(fixup); |
| 5413 | } |
| 5414 | |
| 5415 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
| 5416 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 5417 | return Address::RIP(fixup); |
| 5418 | } |
| 5419 | |
| 5420 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
| 5421 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 5422 | return Address::RIP(fixup); |
| 5423 | } |
| 5424 | |
| 5425 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
| 5426 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 5427 | return Address::RIP(fixup); |
| 5428 | } |
| 5429 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5430 | // TODO: trg as memory. |
| 5431 | void CodeGeneratorX86_64::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 5432 | if (!trg.IsValid()) { |
| 5433 | DCHECK(type == Primitive::kPrimVoid); |
| 5434 | return; |
| 5435 | } |
| 5436 | |
| 5437 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 5438 | |
| 5439 | Location return_loc = InvokeDexCallingConventionVisitorX86_64().GetReturnLocation(type); |
| 5440 | if (trg.Equals(return_loc)) { |
| 5441 | return; |
| 5442 | } |
| 5443 | |
| 5444 | // Let the parallel move resolver take care of all of this. |
| 5445 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 5446 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 5447 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 5448 | } |
| 5449 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5450 | #undef __ |
| 5451 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5452 | } // namespace x86_64 |
| 5453 | } // namespace art |