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; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame^] | 455 | case kCondB: return kBelow; |
| 456 | case kCondBE: return kBelowEqual; |
| 457 | case kCondA: return kAbove; |
| 458 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 459 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 460 | LOG(FATAL) << "Unreachable"; |
| 461 | UNREACHABLE(); |
| 462 | } |
| 463 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame^] | 464 | // Maps FP condition to x86_64 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 465 | inline Condition X86_64FPCondition(IfCondition cond) { |
| 466 | switch (cond) { |
| 467 | case kCondEQ: return kEqual; |
| 468 | case kCondNE: return kNotEqual; |
| 469 | case kCondLT: return kBelow; |
| 470 | case kCondLE: return kBelowEqual; |
| 471 | case kCondGT: return kAbove; |
| 472 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame^] | 473 | default: break; // should not happen |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 474 | }; |
| 475 | LOG(FATAL) << "Unreachable"; |
| 476 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 477 | } |
| 478 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 479 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 480 | Location temp) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 481 | // All registers are assumed to be correctly set up. |
| 482 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 483 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 484 | switch (invoke->GetMethodLoadKind()) { |
| 485 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 486 | // temp = thread->string_init_entrypoint |
| 487 | __ gs()->movl(temp.AsRegister<CpuRegister>(), |
| 488 | Address::Absolute(invoke->GetStringInitOffset(), true)); |
| 489 | break; |
| 490 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 491 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 492 | break; |
| 493 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 494 | __ movq(temp.AsRegister<CpuRegister>(), Immediate(invoke->GetMethodAddress())); |
| 495 | break; |
| 496 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 497 | __ movl(temp.AsRegister<CpuRegister>(), Immediate(0)); // Placeholder. |
| 498 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 499 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 500 | break; |
| 501 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
| 502 | pc_rel_dex_cache_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 503 | invoke->GetDexCacheArrayOffset()); |
| 504 | __ movq(temp.AsRegister<CpuRegister>(), |
| 505 | Address::Absolute(kDummy32BitOffset, false /* no_rip */)); |
| 506 | // Bind the label at the end of the "movl" insn. |
| 507 | __ Bind(&pc_rel_dex_cache_patches_.back().label); |
| 508 | break; |
| 509 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
| 510 | Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 511 | Register method_reg; |
| 512 | CpuRegister reg = temp.AsRegister<CpuRegister>(); |
| 513 | if (current_method.IsRegister()) { |
| 514 | method_reg = current_method.AsRegister<Register>(); |
| 515 | } else { |
| 516 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 517 | DCHECK(!current_method.IsValid()); |
| 518 | method_reg = reg.AsRegister(); |
| 519 | __ movq(reg, Address(CpuRegister(RSP), kCurrentMethodStackOffset)); |
| 520 | } |
| 521 | // temp = temp->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 522 | __ movq(reg, |
| 523 | Address(CpuRegister(method_reg), |
| 524 | ArtMethod::DexCacheResolvedMethodsOffset(kX86_64PointerSize).SizeValue())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 525 | // temp = temp[index_in_cache] |
| 526 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 527 | __ movq(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 528 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 529 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | switch (invoke->GetCodePtrLocation()) { |
| 533 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 534 | __ call(&frame_entry_label_); |
| 535 | break; |
| 536 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 537 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 538 | Label* label = &relative_call_patches_.back().label; |
| 539 | __ call(label); // Bind to the patch label, override at link time. |
| 540 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 541 | break; |
| 542 | } |
| 543 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 544 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 545 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 546 | FALLTHROUGH_INTENDED; |
| 547 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 548 | // (callee_method + offset_of_quick_compiled_code)() |
| 549 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 550 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 551 | kX86_64WordSize).SizeValue())); |
| 552 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 553 | } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 554 | |
| 555 | DCHECK(!IsLeafMethod()); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 556 | } |
| 557 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 558 | void CodeGeneratorX86_64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 559 | CpuRegister temp = temp_in.AsRegister<CpuRegister>(); |
| 560 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 561 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
| 562 | LocationSummary* locations = invoke->GetLocations(); |
| 563 | Location receiver = locations->InAt(0); |
| 564 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 565 | // temp = object->GetClass(); |
| 566 | DCHECK(receiver.IsRegister()); |
| 567 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
| 568 | MaybeRecordImplicitNullCheck(invoke); |
| 569 | __ MaybeUnpoisonHeapReference(temp); |
| 570 | // temp = temp->GetMethodAt(method_offset); |
| 571 | __ movq(temp, Address(temp, method_offset)); |
| 572 | // call temp->GetEntryPoint(); |
| 573 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 574 | kX86_64WordSize).SizeValue())); |
| 575 | } |
| 576 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 577 | void CodeGeneratorX86_64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 578 | DCHECK(linker_patches->empty()); |
| 579 | size_t size = |
| 580 | method_patches_.size() + relative_call_patches_.size() + pc_rel_dex_cache_patches_.size(); |
| 581 | linker_patches->reserve(size); |
| 582 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
| 583 | // The label points to the end of the "movl" instruction but the literal offset for method |
| 584 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 585 | uint32_t literal_offset = info.label.Position() - 4; |
| 586 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 587 | info.target_method.dex_file, |
| 588 | info.target_method.dex_method_index)); |
| 589 | } |
| 590 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
| 591 | // The label points to the end of the "call" instruction but the literal offset for method |
| 592 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 593 | uint32_t literal_offset = info.label.Position() - 4; |
| 594 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 595 | info.target_method.dex_file, |
| 596 | info.target_method.dex_method_index)); |
| 597 | } |
| 598 | for (const PcRelativeDexCacheAccessInfo& info : pc_rel_dex_cache_patches_) { |
| 599 | // The label points to the end of the "mov" instruction but the literal offset for method |
| 600 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 601 | uint32_t literal_offset = info.label.Position() - 4; |
| 602 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 603 | &info.target_dex_file, |
| 604 | info.label.Position(), |
| 605 | info.element_offset)); |
| 606 | } |
| 607 | } |
| 608 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 609 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 610 | stream << Register(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 614 | stream << FloatRegister(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 615 | } |
| 616 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 617 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 618 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 619 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 620 | } |
| 621 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 622 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 623 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 624 | return kX86_64WordSize; |
| 625 | } |
| 626 | |
| 627 | size_t CodeGeneratorX86_64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 628 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 629 | return kX86_64WordSize; |
| 630 | } |
| 631 | |
| 632 | size_t CodeGeneratorX86_64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 633 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 634 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 635 | } |
| 636 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 637 | void CodeGeneratorX86_64::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 638 | HInstruction* instruction, |
| 639 | uint32_t dex_pc, |
| 640 | SlowPathCode* slow_path) { |
| 641 | InvokeRuntime(GetThreadOffset<kX86_64WordSize>(entrypoint).Int32Value(), |
| 642 | instruction, |
| 643 | dex_pc, |
| 644 | slow_path); |
| 645 | } |
| 646 | |
| 647 | void CodeGeneratorX86_64::InvokeRuntime(int32_t entry_point_offset, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 648 | HInstruction* instruction, |
| 649 | uint32_t dex_pc, |
| 650 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 651 | ValidateInvokeRuntime(instruction, slow_path); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 652 | __ gs()->call(Address::Absolute(entry_point_offset, true)); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 653 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 654 | } |
| 655 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 656 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 657 | // Use a fake return address register to mimic Quick. |
| 658 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 659 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
| 660 | const X86_64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 661 | const CompilerOptions& compiler_options, |
| 662 | OptimizingCompilerStats* stats) |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 663 | : CodeGenerator(graph, |
| 664 | kNumberOfCpuRegisters, |
| 665 | kNumberOfFloatRegisters, |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 666 | kNumberOfCpuRegisterPairs, |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 667 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 668 | arraysize(kCoreCalleeSaves)) |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 669 | | (1 << kFakeReturnRegister), |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 670 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 671 | arraysize(kFpuCalleeSaves)), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 672 | compiler_options, |
| 673 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 674 | block_labels_(nullptr), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 675 | location_builder_(graph, this), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 676 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 677 | move_resolver_(graph->GetArena(), this), |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 678 | isa_features_(isa_features), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 679 | constant_area_start_(0), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 680 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 681 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 682 | pc_rel_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 683 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 684 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 685 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 686 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 687 | CodeGeneratorX86_64* codegen) |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 688 | : HGraphVisitor(graph), |
| 689 | assembler_(codegen->GetAssembler()), |
| 690 | codegen_(codegen) {} |
| 691 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 692 | Location CodeGeneratorX86_64::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 693 | switch (type) { |
| 694 | case Primitive::kPrimLong: |
| 695 | case Primitive::kPrimByte: |
| 696 | case Primitive::kPrimBoolean: |
| 697 | case Primitive::kPrimChar: |
| 698 | case Primitive::kPrimShort: |
| 699 | case Primitive::kPrimInt: |
| 700 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 701 | size_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfCpuRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 702 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 706 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 707 | size_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfFloatRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 708 | return Location::FpuRegisterLocation(reg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 709 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 710 | |
| 711 | case Primitive::kPrimVoid: |
| 712 | LOG(FATAL) << "Unreachable type " << type; |
| 713 | } |
| 714 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 715 | return Location(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 716 | } |
| 717 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 718 | void CodeGeneratorX86_64::SetupBlockedRegisters(bool is_baseline) const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 719 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 720 | blocked_core_registers_[RSP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 721 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 722 | // Block the register used as TMP. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 723 | blocked_core_registers_[TMP] = true; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 724 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 725 | if (is_baseline) { |
| 726 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 727 | blocked_core_registers_[kCoreCalleeSaves[i]] = true; |
| 728 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 729 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 730 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 731 | } |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 732 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 733 | } |
| 734 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 735 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 736 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 737 | } |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 738 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 739 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 740 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 741 | } |
| 742 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 743 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 744 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 745 | __ Bind(&frame_entry_label_); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 746 | bool skip_overflow_check = IsLeafMethod() |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 747 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 748 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 749 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 750 | if (!skip_overflow_check) { |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 751 | __ testq(CpuRegister(RAX), Address( |
| 752 | CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 753 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 754 | } |
Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 755 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 756 | if (HasEmptyFrame()) { |
| 757 | return; |
| 758 | } |
| 759 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 760 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 761 | Register reg = kCoreCalleeSaves[i]; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 762 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 763 | __ pushq(CpuRegister(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 764 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 765 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 766 | } |
| 767 | } |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 768 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 769 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 770 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 771 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 772 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 773 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 774 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 775 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 776 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 777 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 778 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 779 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 780 | } |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 781 | } |
| 782 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 783 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 784 | CpuRegister(kMethodRegisterArgument)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | void CodeGeneratorX86_64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 788 | __ cfi().RememberState(); |
| 789 | if (!HasEmptyFrame()) { |
| 790 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 791 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| 792 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 793 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 794 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 795 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 796 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 801 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 802 | __ cfi().AdjustCFAOffset(-adjust); |
| 803 | |
| 804 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 805 | Register reg = kCoreCalleeSaves[i]; |
| 806 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 807 | __ popq(CpuRegister(reg)); |
| 808 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 809 | __ cfi().Restore(DWARFReg(reg)); |
| 810 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 811 | } |
| 812 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 813 | __ ret(); |
| 814 | __ cfi().RestoreState(); |
| 815 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 816 | } |
| 817 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 818 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 819 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 820 | } |
| 821 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 822 | Location CodeGeneratorX86_64::GetStackLocation(HLoadLocal* load) const { |
| 823 | switch (load->GetType()) { |
| 824 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 825 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 826 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 827 | |
| 828 | case Primitive::kPrimInt: |
| 829 | case Primitive::kPrimNot: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 830 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 831 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 832 | |
| 833 | case Primitive::kPrimBoolean: |
| 834 | case Primitive::kPrimByte: |
| 835 | case Primitive::kPrimChar: |
| 836 | case Primitive::kPrimShort: |
| 837 | case Primitive::kPrimVoid: |
| 838 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 839 | UNREACHABLE(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 843 | UNREACHABLE(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 847 | if (source.Equals(destination)) { |
| 848 | return; |
| 849 | } |
| 850 | if (destination.IsRegister()) { |
| 851 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 852 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 853 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 854 | __ movd(destination.AsRegister<CpuRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 855 | } else if (source.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 856 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 857 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 858 | } else { |
| 859 | DCHECK(source.IsDoubleStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 860 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 861 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 862 | } |
| 863 | } else if (destination.IsFpuRegister()) { |
| 864 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 865 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 866 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 867 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 868 | } else if (source.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 869 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 870 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 871 | } else { |
| 872 | DCHECK(source.IsDoubleStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 873 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 874 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 875 | } |
| 876 | } else if (destination.IsStackSlot()) { |
| 877 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 878 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 879 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 880 | } else if (source.IsFpuRegister()) { |
| 881 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 882 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 883 | } else if (source.IsConstant()) { |
| 884 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 885 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 886 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 887 | } else { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 888 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 889 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 890 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 891 | } |
| 892 | } else { |
| 893 | DCHECK(destination.IsDoubleStackSlot()); |
| 894 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 895 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 896 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 897 | } else if (source.IsFpuRegister()) { |
| 898 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 899 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 900 | } else if (source.IsConstant()) { |
| 901 | HConstant* constant = source.GetConstant(); |
Zheng Xu | 12bca97 | 2015-03-30 19:35:50 +0800 | [diff] [blame] | 902 | int64_t value; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 903 | if (constant->IsDoubleConstant()) { |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 904 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 905 | } else { |
| 906 | DCHECK(constant->IsLongConstant()); |
| 907 | value = constant->AsLongConstant()->GetValue(); |
| 908 | } |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 909 | Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 910 | } else { |
| 911 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 912 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 913 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 914 | } |
| 915 | } |
| 916 | } |
| 917 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 918 | void CodeGeneratorX86_64::Move(HInstruction* instruction, |
| 919 | Location location, |
| 920 | HInstruction* move_for) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 921 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 922 | if (instruction->IsCurrentMethod()) { |
Mathieu Chartier | e3b034a | 2015-05-31 14:29:23 -0700 | [diff] [blame] | 923 | Move(location, Location::DoubleStackSlot(kCurrentMethodStackOffset)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 924 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 925 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 926 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 927 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 928 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 929 | Immediate imm(GetInt32ValueOf(const_to_move)); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 930 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 931 | __ movl(location.AsRegister<CpuRegister>(), imm); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 932 | } else if (location.IsStackSlot()) { |
| 933 | __ movl(Address(CpuRegister(RSP), location.GetStackIndex()), imm); |
| 934 | } else { |
| 935 | DCHECK(location.IsConstant()); |
| 936 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 937 | } |
| 938 | } else if (const_to_move->IsLongConstant()) { |
| 939 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 940 | if (location.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 941 | Load64BitValue(location.AsRegister<CpuRegister>(), value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 942 | } else if (location.IsDoubleStackSlot()) { |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 943 | Store64BitValueToStack(location, value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 944 | } else { |
| 945 | DCHECK(location.IsConstant()); |
| 946 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 947 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 948 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 949 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 950 | switch (instruction->GetType()) { |
| 951 | case Primitive::kPrimBoolean: |
| 952 | case Primitive::kPrimByte: |
| 953 | case Primitive::kPrimChar: |
| 954 | case Primitive::kPrimShort: |
| 955 | case Primitive::kPrimInt: |
| 956 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 957 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 958 | Move(location, Location::StackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
| 959 | break; |
| 960 | |
| 961 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 962 | case Primitive::kPrimDouble: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 963 | Move(location, |
| 964 | Location::DoubleStackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 965 | break; |
| 966 | |
| 967 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 968 | LOG(FATAL) << "Unexpected local type " << instruction->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 969 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 970 | } else if (instruction->IsTemporary()) { |
| 971 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
| 972 | Move(location, temp_location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 973 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 974 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 975 | switch (instruction->GetType()) { |
| 976 | case Primitive::kPrimBoolean: |
| 977 | case Primitive::kPrimByte: |
| 978 | case Primitive::kPrimChar: |
| 979 | case Primitive::kPrimShort: |
| 980 | case Primitive::kPrimInt: |
| 981 | case Primitive::kPrimNot: |
| 982 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 983 | case Primitive::kPrimFloat: |
| 984 | case Primitive::kPrimDouble: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 985 | Move(location, locations->Out()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 986 | break; |
| 987 | |
| 988 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 989 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 990 | } |
| 991 | } |
| 992 | } |
| 993 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 994 | void CodeGeneratorX86_64::MoveConstant(Location location, int32_t value) { |
| 995 | DCHECK(location.IsRegister()); |
| 996 | Load64BitValue(location.AsRegister<CpuRegister>(), static_cast<int64_t>(value)); |
| 997 | } |
| 998 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 999 | void CodeGeneratorX86_64::MoveLocation( |
| 1000 | Location dst, Location src, Primitive::Type dst_type ATTRIBUTE_UNUSED) { |
| 1001 | Move(dst, src); |
| 1002 | } |
| 1003 | |
| 1004 | void CodeGeneratorX86_64::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1005 | if (location.IsRegister()) { |
| 1006 | locations->AddTemp(location); |
| 1007 | } else { |
| 1008 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1009 | } |
| 1010 | } |
| 1011 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1012 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1013 | DCHECK(!successor->IsExitBlock()); |
| 1014 | |
| 1015 | HBasicBlock* block = got->GetBlock(); |
| 1016 | HInstruction* previous = got->GetPrevious(); |
| 1017 | |
| 1018 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1019 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1020 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1021 | return; |
| 1022 | } |
| 1023 | |
| 1024 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1025 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1026 | } |
| 1027 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1028 | __ jmp(codegen_->GetLabelOf(successor)); |
| 1029 | } |
| 1030 | } |
| 1031 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1032 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 1033 | got->SetLocations(nullptr); |
| 1034 | } |
| 1035 | |
| 1036 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 1037 | HandleGoto(got, got->GetSuccessor()); |
| 1038 | } |
| 1039 | |
| 1040 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1041 | try_boundary->SetLocations(nullptr); |
| 1042 | } |
| 1043 | |
| 1044 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1045 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1046 | if (!successor->IsExitBlock()) { |
| 1047 | HandleGoto(try_boundary, successor); |
| 1048 | } |
| 1049 | } |
| 1050 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1051 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 1052 | exit->SetLocations(nullptr); |
| 1053 | } |
| 1054 | |
| 1055 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1056 | UNUSED(exit); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1057 | } |
| 1058 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1059 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
| 1060 | Label* true_label, |
| 1061 | Label* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1062 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1063 | __ j(kUnordered, true_label); |
| 1064 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1065 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1066 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1067 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HIf* if_instr, |
| 1071 | HCondition* condition, |
| 1072 | Label* true_target, |
| 1073 | Label* false_target, |
| 1074 | Label* always_true_target) { |
| 1075 | LocationSummary* locations = condition->GetLocations(); |
| 1076 | Location left = locations->InAt(0); |
| 1077 | Location right = locations->InAt(1); |
| 1078 | |
| 1079 | // We don't want true_target as a nullptr. |
| 1080 | if (true_target == nullptr) { |
| 1081 | true_target = always_true_target; |
| 1082 | } |
| 1083 | bool falls_through = (false_target == nullptr); |
| 1084 | |
| 1085 | // FP compares don't like null false_targets. |
| 1086 | if (false_target == nullptr) { |
| 1087 | false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1088 | } |
| 1089 | |
| 1090 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1091 | switch (type) { |
| 1092 | case Primitive::kPrimLong: { |
| 1093 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1094 | if (right.IsConstant()) { |
| 1095 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 1096 | if (IsInt<32>(value)) { |
| 1097 | if (value == 0) { |
| 1098 | __ testq(left_reg, left_reg); |
| 1099 | } else { |
| 1100 | __ cmpq(left_reg, Immediate(static_cast<int32_t>(value))); |
| 1101 | } |
| 1102 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1103 | // Value won't fit in a 32-bit integer. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1104 | __ cmpq(left_reg, codegen_->LiteralInt64Address(value)); |
| 1105 | } |
| 1106 | } else if (right.IsDoubleStackSlot()) { |
| 1107 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1108 | } else { |
| 1109 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1110 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1111 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1112 | break; |
| 1113 | } |
| 1114 | case Primitive::kPrimFloat: { |
| 1115 | if (right.IsFpuRegister()) { |
| 1116 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1117 | } else if (right.IsConstant()) { |
| 1118 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1119 | codegen_->LiteralFloatAddress( |
| 1120 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 1121 | } else { |
| 1122 | DCHECK(right.IsStackSlot()); |
| 1123 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 1124 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1125 | } |
| 1126 | GenerateFPJumps(condition, true_target, false_target); |
| 1127 | break; |
| 1128 | } |
| 1129 | case Primitive::kPrimDouble: { |
| 1130 | if (right.IsFpuRegister()) { |
| 1131 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1132 | } else if (right.IsConstant()) { |
| 1133 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1134 | codegen_->LiteralDoubleAddress( |
| 1135 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1136 | } else { |
| 1137 | DCHECK(right.IsDoubleStackSlot()); |
| 1138 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1139 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1140 | } |
| 1141 | GenerateFPJumps(condition, true_target, false_target); |
| 1142 | break; |
| 1143 | } |
| 1144 | default: |
| 1145 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1146 | } |
| 1147 | |
| 1148 | if (!falls_through) { |
| 1149 | __ jmp(false_target); |
| 1150 | } |
| 1151 | } |
| 1152 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1153 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
| 1154 | Label* true_target, |
| 1155 | Label* false_target, |
| 1156 | Label* always_true_target) { |
| 1157 | HInstruction* cond = instruction->InputAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1158 | if (cond->IsIntConstant()) { |
| 1159 | // Constant condition, statically compared against 1. |
| 1160 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 1161 | if (cond_value == 1) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1162 | if (always_true_target != nullptr) { |
| 1163 | __ jmp(always_true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1164 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1165 | return; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1166 | } else { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1167 | DCHECK_EQ(cond_value, 0); |
| 1168 | } |
| 1169 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1170 | bool is_materialized = |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1171 | !cond->IsCondition() || cond->AsCondition()->NeedsMaterialization(); |
| 1172 | // Moves do not affect the eflags register, so if the condition is |
| 1173 | // evaluated just before the if, we don't need to evaluate it |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1174 | // again. We can't use the eflags on FP conditions if they are |
| 1175 | // materialized due to the complex branching. |
| 1176 | Primitive::Type type = cond->IsCondition() ? cond->InputAt(0)->GetType() : Primitive::kPrimInt; |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1177 | bool eflags_set = cond->IsCondition() |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1178 | && cond->AsCondition()->IsBeforeWhenDisregardMoves(instruction) |
| 1179 | && !Primitive::IsFloatingPointType(type); |
| 1180 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1181 | if (is_materialized) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1182 | if (!eflags_set) { |
| 1183 | // Materialized condition, compare against 0. |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1184 | Location lhs = instruction->GetLocations()->InAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1185 | if (lhs.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 1186 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1187 | } else { |
| 1188 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), |
| 1189 | Immediate(0)); |
| 1190 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1191 | __ j(kNotEqual, true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1192 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1193 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1194 | } |
| 1195 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1196 | // Condition has not been materialized, use its inputs as the |
| 1197 | // comparison and its condition as the branch condition. |
| 1198 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1199 | // Is this a long or FP comparison that has been folded into the HCondition? |
| 1200 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1201 | // Generate the comparison directly. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1202 | GenerateCompareTestAndBranch(instruction->AsIf(), cond->AsCondition(), |
| 1203 | true_target, false_target, always_true_target); |
| 1204 | return; |
| 1205 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1206 | |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1207 | Location lhs = cond->GetLocations()->InAt(0); |
| 1208 | Location rhs = cond->GetLocations()->InAt(1); |
| 1209 | if (rhs.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1210 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1211 | } else if (rhs.IsConstant()) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1212 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 1213 | if (constant == 0) { |
| 1214 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1215 | } else { |
| 1216 | __ cmpl(lhs.AsRegister<CpuRegister>(), Immediate(constant)); |
| 1217 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1218 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1219 | __ cmpl(lhs.AsRegister<CpuRegister>(), |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1220 | Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1221 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1222 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1223 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1224 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1225 | if (false_target != nullptr) { |
| 1226 | __ jmp(false_target); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1227 | } |
| 1228 | } |
| 1229 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1230 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
| 1231 | LocationSummary* locations = |
| 1232 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
| 1233 | HInstruction* cond = if_instr->InputAt(0); |
| 1234 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 1235 | locations->SetInAt(0, Location::Any()); |
| 1236 | } |
| 1237 | } |
| 1238 | |
| 1239 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
| 1240 | Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor()); |
| 1241 | Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1242 | Label* always_true_target = true_target; |
| 1243 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1244 | if_instr->IfTrueSuccessor())) { |
| 1245 | always_true_target = nullptr; |
| 1246 | } |
| 1247 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1248 | if_instr->IfFalseSuccessor())) { |
| 1249 | false_target = nullptr; |
| 1250 | } |
| 1251 | GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target); |
| 1252 | } |
| 1253 | |
| 1254 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1255 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1256 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| 1257 | HInstruction* cond = deoptimize->InputAt(0); |
| 1258 | DCHECK(cond->IsCondition()); |
| 1259 | if (cond->AsCondition()->NeedsMaterialization()) { |
| 1260 | locations->SetInAt(0, Location::Any()); |
| 1261 | } |
| 1262 | } |
| 1263 | |
| 1264 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 1265 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1266 | DeoptimizationSlowPathX86_64(deoptimize); |
| 1267 | codegen_->AddSlowPath(slow_path); |
| 1268 | Label* slow_path_entry = slow_path->GetEntryLabel(); |
| 1269 | GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry); |
| 1270 | } |
| 1271 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1272 | void LocationsBuilderX86_64::VisitLocal(HLocal* local) { |
| 1273 | local->SetLocations(nullptr); |
| 1274 | } |
| 1275 | |
| 1276 | void InstructionCodeGeneratorX86_64::VisitLocal(HLocal* local) { |
| 1277 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
| 1278 | } |
| 1279 | |
| 1280 | void LocationsBuilderX86_64::VisitLoadLocal(HLoadLocal* local) { |
| 1281 | local->SetLocations(nullptr); |
| 1282 | } |
| 1283 | |
| 1284 | void InstructionCodeGeneratorX86_64::VisitLoadLocal(HLoadLocal* load) { |
| 1285 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1286 | UNUSED(load); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | void LocationsBuilderX86_64::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1290 | LocationSummary* locations = |
| 1291 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1292 | switch (store->InputAt(1)->GetType()) { |
| 1293 | case Primitive::kPrimBoolean: |
| 1294 | case Primitive::kPrimByte: |
| 1295 | case Primitive::kPrimChar: |
| 1296 | case Primitive::kPrimShort: |
| 1297 | case Primitive::kPrimInt: |
| 1298 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1299 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1300 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1301 | break; |
| 1302 | |
| 1303 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1304 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1305 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1306 | break; |
| 1307 | |
| 1308 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1309 | LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1310 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1311 | } |
| 1312 | |
| 1313 | void InstructionCodeGeneratorX86_64::VisitStoreLocal(HStoreLocal* store) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1314 | UNUSED(store); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1315 | } |
| 1316 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1317 | void LocationsBuilderX86_64::VisitCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1318 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1319 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1320 | // Handle the long/FP comparisons made in instruction simplification. |
| 1321 | switch (cond->InputAt(0)->GetType()) { |
| 1322 | case Primitive::kPrimLong: |
| 1323 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1324 | locations->SetInAt(1, Location::Any()); |
| 1325 | break; |
| 1326 | case Primitive::kPrimFloat: |
| 1327 | case Primitive::kPrimDouble: |
| 1328 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1329 | locations->SetInAt(1, Location::Any()); |
| 1330 | break; |
| 1331 | default: |
| 1332 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1333 | locations->SetInAt(1, Location::Any()); |
| 1334 | break; |
| 1335 | } |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1336 | if (cond->NeedsMaterialization()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1337 | locations->SetOut(Location::RequiresRegister()); |
| 1338 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1339 | } |
| 1340 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1341 | void InstructionCodeGeneratorX86_64::VisitCondition(HCondition* cond) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1342 | if (!cond->NeedsMaterialization()) { |
| 1343 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1344 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1345 | |
| 1346 | LocationSummary* locations = cond->GetLocations(); |
| 1347 | Location lhs = locations->InAt(0); |
| 1348 | Location rhs = locations->InAt(1); |
| 1349 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
| 1350 | Label true_label, false_label; |
| 1351 | |
| 1352 | switch (cond->InputAt(0)->GetType()) { |
| 1353 | default: |
| 1354 | // Integer case. |
| 1355 | |
| 1356 | // Clear output register: setcc only sets the low byte. |
| 1357 | __ xorl(reg, reg); |
| 1358 | |
| 1359 | if (rhs.IsRegister()) { |
| 1360 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1361 | } else if (rhs.IsConstant()) { |
| 1362 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1363 | if (constant == 0) { |
| 1364 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1365 | } else { |
| 1366 | __ cmpl(lhs.AsRegister<CpuRegister>(), Immediate(constant)); |
| 1367 | } |
| 1368 | } else { |
| 1369 | __ cmpl(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1370 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1371 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1372 | return; |
| 1373 | case Primitive::kPrimLong: |
| 1374 | // Clear output register: setcc only sets the low byte. |
| 1375 | __ xorl(reg, reg); |
| 1376 | |
| 1377 | if (rhs.IsRegister()) { |
| 1378 | __ cmpq(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1379 | } else if (rhs.IsConstant()) { |
| 1380 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
| 1381 | if (IsInt<32>(value)) { |
| 1382 | if (value == 0) { |
| 1383 | __ testq(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1384 | } else { |
| 1385 | __ cmpq(lhs.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 1386 | } |
| 1387 | } else { |
| 1388 | // Value won't fit in an int. |
| 1389 | __ cmpq(lhs.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 1390 | } |
| 1391 | } else { |
| 1392 | __ cmpq(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1393 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1394 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1395 | return; |
| 1396 | case Primitive::kPrimFloat: { |
| 1397 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1398 | if (rhs.IsConstant()) { |
| 1399 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 1400 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 1401 | } else if (rhs.IsStackSlot()) { |
| 1402 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1403 | } else { |
| 1404 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1405 | } |
| 1406 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1407 | break; |
| 1408 | } |
| 1409 | case Primitive::kPrimDouble: { |
| 1410 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1411 | if (rhs.IsConstant()) { |
| 1412 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1413 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 1414 | } else if (rhs.IsDoubleStackSlot()) { |
| 1415 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1416 | } else { |
| 1417 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1418 | } |
| 1419 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1420 | break; |
| 1421 | } |
| 1422 | } |
| 1423 | |
| 1424 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1425 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1426 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1427 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1428 | __ Bind(&false_label); |
| 1429 | __ xorl(reg, reg); |
| 1430 | __ jmp(&done_label); |
| 1431 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1432 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1433 | __ Bind(&true_label); |
| 1434 | __ movl(reg, Immediate(1)); |
| 1435 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1436 | } |
| 1437 | |
| 1438 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
| 1439 | VisitCondition(comp); |
| 1440 | } |
| 1441 | |
| 1442 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
| 1443 | VisitCondition(comp); |
| 1444 | } |
| 1445 | |
| 1446 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
| 1447 | VisitCondition(comp); |
| 1448 | } |
| 1449 | |
| 1450 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
| 1451 | VisitCondition(comp); |
| 1452 | } |
| 1453 | |
| 1454 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
| 1455 | VisitCondition(comp); |
| 1456 | } |
| 1457 | |
| 1458 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
| 1459 | VisitCondition(comp); |
| 1460 | } |
| 1461 | |
| 1462 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1463 | VisitCondition(comp); |
| 1464 | } |
| 1465 | |
| 1466 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1467 | VisitCondition(comp); |
| 1468 | } |
| 1469 | |
| 1470 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| 1471 | VisitCondition(comp); |
| 1472 | } |
| 1473 | |
| 1474 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| 1475 | VisitCondition(comp); |
| 1476 | } |
| 1477 | |
| 1478 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1479 | VisitCondition(comp); |
| 1480 | } |
| 1481 | |
| 1482 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1483 | VisitCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1484 | } |
| 1485 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame^] | 1486 | void LocationsBuilderX86_64::VisitBelow(HBelow* comp) { |
| 1487 | VisitCondition(comp); |
| 1488 | } |
| 1489 | |
| 1490 | void InstructionCodeGeneratorX86_64::VisitBelow(HBelow* comp) { |
| 1491 | VisitCondition(comp); |
| 1492 | } |
| 1493 | |
| 1494 | void LocationsBuilderX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 1495 | VisitCondition(comp); |
| 1496 | } |
| 1497 | |
| 1498 | void InstructionCodeGeneratorX86_64::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 1499 | VisitCondition(comp); |
| 1500 | } |
| 1501 | |
| 1502 | void LocationsBuilderX86_64::VisitAbove(HAbove* comp) { |
| 1503 | VisitCondition(comp); |
| 1504 | } |
| 1505 | |
| 1506 | void InstructionCodeGeneratorX86_64::VisitAbove(HAbove* comp) { |
| 1507 | VisitCondition(comp); |
| 1508 | } |
| 1509 | |
| 1510 | void LocationsBuilderX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 1511 | VisitCondition(comp); |
| 1512 | } |
| 1513 | |
| 1514 | void InstructionCodeGeneratorX86_64::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 1515 | VisitCondition(comp); |
| 1516 | } |
| 1517 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1518 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1519 | LocationSummary* locations = |
| 1520 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1521 | switch (compare->InputAt(0)->GetType()) { |
| 1522 | case Primitive::kPrimLong: { |
| 1523 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1524 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1525 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1526 | break; |
| 1527 | } |
| 1528 | case Primitive::kPrimFloat: |
| 1529 | case Primitive::kPrimDouble: { |
| 1530 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1531 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1532 | locations->SetOut(Location::RequiresRegister()); |
| 1533 | break; |
| 1534 | } |
| 1535 | default: |
| 1536 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 1537 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1538 | } |
| 1539 | |
| 1540 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1541 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1542 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1543 | Location left = locations->InAt(0); |
| 1544 | Location right = locations->InAt(1); |
| 1545 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1546 | NearLabel less, greater, done; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1547 | Primitive::Type type = compare->InputAt(0)->GetType(); |
| 1548 | switch (type) { |
| 1549 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1550 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1551 | if (right.IsConstant()) { |
| 1552 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1553 | if (IsInt<32>(value)) { |
| 1554 | if (value == 0) { |
| 1555 | __ testq(left_reg, left_reg); |
| 1556 | } else { |
| 1557 | __ cmpq(left_reg, Immediate(static_cast<int32_t>(value))); |
| 1558 | } |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1559 | } else { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1560 | // Value won't fit in an int. |
| 1561 | __ cmpq(left_reg, codegen_->LiteralInt64Address(value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1562 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1563 | } else if (right.IsDoubleStackSlot()) { |
| 1564 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1565 | } else { |
| 1566 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1567 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1568 | break; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1569 | } |
| 1570 | case Primitive::kPrimFloat: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1571 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1572 | if (right.IsConstant()) { |
| 1573 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 1574 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 1575 | } else if (right.IsStackSlot()) { |
| 1576 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1577 | } else { |
| 1578 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1579 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1580 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 1581 | break; |
| 1582 | } |
| 1583 | case Primitive::kPrimDouble: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1584 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1585 | if (right.IsConstant()) { |
| 1586 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1587 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 1588 | } else if (right.IsDoubleStackSlot()) { |
| 1589 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1590 | } else { |
| 1591 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1592 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1593 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 1594 | break; |
| 1595 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1596 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1597 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1598 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1599 | __ movl(out, Immediate(0)); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1600 | __ j(kEqual, &done); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1601 | __ 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] | 1602 | |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1603 | __ Bind(&greater); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1604 | __ movl(out, Immediate(1)); |
| 1605 | __ jmp(&done); |
| 1606 | |
| 1607 | __ Bind(&less); |
| 1608 | __ movl(out, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1609 | |
| 1610 | __ Bind(&done); |
| 1611 | } |
| 1612 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1613 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1614 | LocationSummary* locations = |
| 1615 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1616 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1617 | } |
| 1618 | |
| 1619 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1620 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1621 | UNUSED(constant); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1622 | } |
| 1623 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1624 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 1625 | LocationSummary* locations = |
| 1626 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1627 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1628 | } |
| 1629 | |
| 1630 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant) { |
| 1631 | // Will be generated at use site. |
| 1632 | UNUSED(constant); |
| 1633 | } |
| 1634 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1635 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1636 | LocationSummary* locations = |
| 1637 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1638 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1639 | } |
| 1640 | |
| 1641 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1642 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1643 | UNUSED(constant); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1644 | } |
| 1645 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1646 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 1647 | LocationSummary* locations = |
| 1648 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1649 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1650 | } |
| 1651 | |
| 1652 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 1653 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1654 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1655 | } |
| 1656 | |
| 1657 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1658 | LocationSummary* locations = |
| 1659 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1660 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1661 | } |
| 1662 | |
| 1663 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1664 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1665 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1666 | } |
| 1667 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1668 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1669 | memory_barrier->SetLocations(nullptr); |
| 1670 | } |
| 1671 | |
| 1672 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1673 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 1674 | } |
| 1675 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1676 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 1677 | ret->SetLocations(nullptr); |
| 1678 | } |
| 1679 | |
| 1680 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1681 | UNUSED(ret); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1682 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1683 | } |
| 1684 | |
| 1685 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1686 | LocationSummary* locations = |
| 1687 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1688 | switch (ret->InputAt(0)->GetType()) { |
| 1689 | case Primitive::kPrimBoolean: |
| 1690 | case Primitive::kPrimByte: |
| 1691 | case Primitive::kPrimChar: |
| 1692 | case Primitive::kPrimShort: |
| 1693 | case Primitive::kPrimInt: |
| 1694 | case Primitive::kPrimNot: |
| 1695 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1696 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1697 | break; |
| 1698 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1699 | case Primitive::kPrimFloat: |
| 1700 | case Primitive::kPrimDouble: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1701 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1702 | break; |
| 1703 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1704 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1705 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1706 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1707 | } |
| 1708 | |
| 1709 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 1710 | if (kIsDebugBuild) { |
| 1711 | switch (ret->InputAt(0)->GetType()) { |
| 1712 | case Primitive::kPrimBoolean: |
| 1713 | case Primitive::kPrimByte: |
| 1714 | case Primitive::kPrimChar: |
| 1715 | case Primitive::kPrimShort: |
| 1716 | case Primitive::kPrimInt: |
| 1717 | case Primitive::kPrimNot: |
| 1718 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1719 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1720 | break; |
| 1721 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1722 | case Primitive::kPrimFloat: |
| 1723 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1724 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1725 | XMM0); |
| 1726 | break; |
| 1727 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1728 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1729 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1730 | } |
| 1731 | } |
| 1732 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1733 | } |
| 1734 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1735 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(Primitive::Type type) const { |
| 1736 | switch (type) { |
| 1737 | case Primitive::kPrimBoolean: |
| 1738 | case Primitive::kPrimByte: |
| 1739 | case Primitive::kPrimChar: |
| 1740 | case Primitive::kPrimShort: |
| 1741 | case Primitive::kPrimInt: |
| 1742 | case Primitive::kPrimNot: |
| 1743 | case Primitive::kPrimLong: |
| 1744 | return Location::RegisterLocation(RAX); |
| 1745 | |
| 1746 | case Primitive::kPrimVoid: |
| 1747 | return Location::NoLocation(); |
| 1748 | |
| 1749 | case Primitive::kPrimDouble: |
| 1750 | case Primitive::kPrimFloat: |
| 1751 | return Location::FpuRegisterLocation(XMM0); |
| 1752 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1753 | |
| 1754 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 1758 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1759 | } |
| 1760 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1761 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1762 | switch (type) { |
| 1763 | case Primitive::kPrimBoolean: |
| 1764 | case Primitive::kPrimByte: |
| 1765 | case Primitive::kPrimChar: |
| 1766 | case Primitive::kPrimShort: |
| 1767 | case Primitive::kPrimInt: |
| 1768 | case Primitive::kPrimNot: { |
| 1769 | uint32_t index = gp_index_++; |
| 1770 | stack_index_++; |
| 1771 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1772 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1773 | } else { |
| 1774 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1775 | } |
| 1776 | } |
| 1777 | |
| 1778 | case Primitive::kPrimLong: { |
| 1779 | uint32_t index = gp_index_; |
| 1780 | stack_index_ += 2; |
| 1781 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 1782 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1783 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1784 | } else { |
| 1785 | gp_index_ += 2; |
| 1786 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1787 | } |
| 1788 | } |
| 1789 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1790 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1791 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1792 | stack_index_++; |
| 1793 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1794 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1795 | } else { |
| 1796 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1797 | } |
| 1798 | } |
| 1799 | |
| 1800 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1801 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1802 | stack_index_ += 2; |
| 1803 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1804 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1805 | } else { |
| 1806 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1807 | } |
| 1808 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1809 | |
| 1810 | case Primitive::kPrimVoid: |
| 1811 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1812 | break; |
| 1813 | } |
| 1814 | return Location(); |
| 1815 | } |
| 1816 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1817 | void LocationsBuilderX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1818 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1819 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1820 | // the method_idx. |
| 1821 | HandleInvoke(invoke); |
| 1822 | } |
| 1823 | |
| 1824 | void InstructionCodeGeneratorX86_64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1825 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1826 | } |
| 1827 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1828 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1829 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1830 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1831 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1832 | |
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 | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1838 | HandleInvoke(invoke); |
| 1839 | } |
| 1840 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1841 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 1842 | if (invoke->GetLocations()->Intrinsified()) { |
| 1843 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 1844 | intrinsic.Dispatch(invoke); |
| 1845 | return true; |
| 1846 | } |
| 1847 | return false; |
| 1848 | } |
| 1849 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1850 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1851 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1852 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1853 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1854 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1855 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1856 | return; |
| 1857 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1858 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1859 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1860 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1861 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 1862 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1863 | } |
| 1864 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1865 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1866 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1867 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1868 | } |
| 1869 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1870 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1871 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1872 | if (intrinsic.TryDispatch(invoke)) { |
| 1873 | return; |
| 1874 | } |
| 1875 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1876 | HandleInvoke(invoke); |
| 1877 | } |
| 1878 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1879 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1880 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1881 | return; |
| 1882 | } |
| 1883 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1884 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1885 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1886 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1887 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1888 | } |
| 1889 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1890 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1891 | HandleInvoke(invoke); |
| 1892 | // Add the hidden argument. |
| 1893 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 1894 | } |
| 1895 | |
| 1896 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1897 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1898 | CpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1899 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 1900 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86_64PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1901 | LocationSummary* locations = invoke->GetLocations(); |
| 1902 | Location receiver = locations->InAt(0); |
| 1903 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 1904 | |
| 1905 | // Set the hidden argument. |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 1906 | CpuRegister hidden_reg = invoke->GetLocations()->GetTemp(1).AsRegister<CpuRegister>(); |
| 1907 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1908 | |
| 1909 | // temp = object->GetClass(); |
| 1910 | if (receiver.IsStackSlot()) { |
| 1911 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
| 1912 | __ movl(temp, Address(temp, class_offset)); |
| 1913 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1914 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1915 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1916 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1917 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1918 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1919 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1920 | // call temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1921 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1922 | kX86_64WordSize).SizeValue())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1923 | |
| 1924 | DCHECK(!codegen_->IsLeafMethod()); |
| 1925 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1926 | } |
| 1927 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1928 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 1929 | LocationSummary* locations = |
| 1930 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1931 | switch (neg->GetResultType()) { |
| 1932 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1933 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1934 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1935 | locations->SetOut(Location::SameAsFirstInput()); |
| 1936 | break; |
| 1937 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1938 | case Primitive::kPrimFloat: |
| 1939 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1940 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1941 | locations->SetOut(Location::SameAsFirstInput()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1942 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1943 | break; |
| 1944 | |
| 1945 | default: |
| 1946 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1947 | } |
| 1948 | } |
| 1949 | |
| 1950 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 1951 | LocationSummary* locations = neg->GetLocations(); |
| 1952 | Location out = locations->Out(); |
| 1953 | Location in = locations->InAt(0); |
| 1954 | switch (neg->GetResultType()) { |
| 1955 | case Primitive::kPrimInt: |
| 1956 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1957 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1958 | __ negl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1959 | break; |
| 1960 | |
| 1961 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1962 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1963 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1964 | __ negq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1965 | break; |
| 1966 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1967 | case Primitive::kPrimFloat: { |
| 1968 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1969 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1970 | // Implement float negation with an exclusive or with value |
| 1971 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 1972 | // single-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1973 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1974 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1975 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1976 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1977 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1978 | case Primitive::kPrimDouble: { |
| 1979 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1980 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1981 | // Implement double negation with an exclusive or with value |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1982 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1983 | // a double-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1984 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1985 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1986 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1987 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1988 | |
| 1989 | default: |
| 1990 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1991 | } |
| 1992 | } |
| 1993 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1994 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 1995 | LocationSummary* locations = |
| 1996 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 1997 | Primitive::Type result_type = conversion->GetResultType(); |
| 1998 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1999 | DCHECK_NE(result_type, input_type); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2000 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2001 | // The Java language does not allow treating boolean as an integral type but |
| 2002 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2003 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2004 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2005 | case Primitive::kPrimByte: |
| 2006 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2007 | case Primitive::kPrimBoolean: |
| 2008 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2009 | case Primitive::kPrimShort: |
| 2010 | case Primitive::kPrimInt: |
| 2011 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2012 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2013 | locations->SetInAt(0, Location::Any()); |
| 2014 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2015 | break; |
| 2016 | |
| 2017 | default: |
| 2018 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2019 | << " to " << result_type; |
| 2020 | } |
| 2021 | break; |
| 2022 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2023 | case Primitive::kPrimShort: |
| 2024 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2025 | case Primitive::kPrimBoolean: |
| 2026 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2027 | case Primitive::kPrimByte: |
| 2028 | case Primitive::kPrimInt: |
| 2029 | case Primitive::kPrimChar: |
| 2030 | // Processing a Dex `int-to-short' instruction. |
| 2031 | locations->SetInAt(0, Location::Any()); |
| 2032 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2033 | break; |
| 2034 | |
| 2035 | default: |
| 2036 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2037 | << " to " << result_type; |
| 2038 | } |
| 2039 | break; |
| 2040 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2041 | case Primitive::kPrimInt: |
| 2042 | switch (input_type) { |
| 2043 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2044 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2045 | locations->SetInAt(0, Location::Any()); |
| 2046 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2047 | break; |
| 2048 | |
| 2049 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2050 | // Processing a Dex `float-to-int' instruction. |
| 2051 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2052 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2053 | break; |
| 2054 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2055 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2056 | // Processing a Dex `double-to-int' instruction. |
| 2057 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2058 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2059 | break; |
| 2060 | |
| 2061 | default: |
| 2062 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2063 | << " to " << result_type; |
| 2064 | } |
| 2065 | break; |
| 2066 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2067 | case Primitive::kPrimLong: |
| 2068 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2069 | case Primitive::kPrimBoolean: |
| 2070 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2071 | case Primitive::kPrimByte: |
| 2072 | case Primitive::kPrimShort: |
| 2073 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2074 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2075 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2076 | // TODO: We would benefit from a (to-be-implemented) |
| 2077 | // Location::RegisterOrStackSlot requirement for this input. |
| 2078 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2079 | locations->SetOut(Location::RequiresRegister()); |
| 2080 | break; |
| 2081 | |
| 2082 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2083 | // Processing a Dex `float-to-long' instruction. |
| 2084 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2085 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2086 | break; |
| 2087 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2088 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2089 | // Processing a Dex `double-to-long' instruction. |
| 2090 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2091 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2092 | break; |
| 2093 | |
| 2094 | default: |
| 2095 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2096 | << " to " << result_type; |
| 2097 | } |
| 2098 | break; |
| 2099 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2100 | case Primitive::kPrimChar: |
| 2101 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2102 | case Primitive::kPrimBoolean: |
| 2103 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2104 | case Primitive::kPrimByte: |
| 2105 | case Primitive::kPrimShort: |
| 2106 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2107 | // Processing a Dex `int-to-char' instruction. |
| 2108 | locations->SetInAt(0, Location::Any()); |
| 2109 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2110 | break; |
| 2111 | |
| 2112 | default: |
| 2113 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2114 | << " to " << result_type; |
| 2115 | } |
| 2116 | break; |
| 2117 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2118 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2119 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2120 | case Primitive::kPrimBoolean: |
| 2121 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2122 | case Primitive::kPrimByte: |
| 2123 | case Primitive::kPrimShort: |
| 2124 | case Primitive::kPrimInt: |
| 2125 | case Primitive::kPrimChar: |
| 2126 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2127 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2128 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2129 | break; |
| 2130 | |
| 2131 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2132 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2133 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2134 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2135 | break; |
| 2136 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2137 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2138 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2139 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2140 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2141 | break; |
| 2142 | |
| 2143 | default: |
| 2144 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2145 | << " to " << result_type; |
| 2146 | }; |
| 2147 | break; |
| 2148 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2149 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2150 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2151 | case Primitive::kPrimBoolean: |
| 2152 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2153 | case Primitive::kPrimByte: |
| 2154 | case Primitive::kPrimShort: |
| 2155 | case Primitive::kPrimInt: |
| 2156 | case Primitive::kPrimChar: |
| 2157 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2158 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2159 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2160 | break; |
| 2161 | |
| 2162 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2163 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2164 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2165 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2166 | break; |
| 2167 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2168 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2169 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2170 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2171 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2172 | break; |
| 2173 | |
| 2174 | default: |
| 2175 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2176 | << " to " << result_type; |
| 2177 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2178 | break; |
| 2179 | |
| 2180 | default: |
| 2181 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2182 | << " to " << result_type; |
| 2183 | } |
| 2184 | } |
| 2185 | |
| 2186 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2187 | LocationSummary* locations = conversion->GetLocations(); |
| 2188 | Location out = locations->Out(); |
| 2189 | Location in = locations->InAt(0); |
| 2190 | Primitive::Type result_type = conversion->GetResultType(); |
| 2191 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2192 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2193 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2194 | case Primitive::kPrimByte: |
| 2195 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2196 | case Primitive::kPrimBoolean: |
| 2197 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2198 | case Primitive::kPrimShort: |
| 2199 | case Primitive::kPrimInt: |
| 2200 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2201 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2202 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2203 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2204 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2205 | __ movsxb(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2206 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2207 | } else { |
| 2208 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2209 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2210 | Immediate(static_cast<int8_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2211 | } |
| 2212 | break; |
| 2213 | |
| 2214 | default: |
| 2215 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2216 | << " to " << result_type; |
| 2217 | } |
| 2218 | break; |
| 2219 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2220 | case Primitive::kPrimShort: |
| 2221 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2222 | case Primitive::kPrimBoolean: |
| 2223 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2224 | case Primitive::kPrimByte: |
| 2225 | case Primitive::kPrimInt: |
| 2226 | case Primitive::kPrimChar: |
| 2227 | // Processing a Dex `int-to-short' instruction. |
| 2228 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2229 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2230 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2231 | __ movsxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2232 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2233 | } else { |
| 2234 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2235 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2236 | Immediate(static_cast<int16_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2237 | } |
| 2238 | break; |
| 2239 | |
| 2240 | default: |
| 2241 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2242 | << " to " << result_type; |
| 2243 | } |
| 2244 | break; |
| 2245 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2246 | case Primitive::kPrimInt: |
| 2247 | switch (input_type) { |
| 2248 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2249 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2250 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2251 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2252 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2253 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2254 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2255 | } else { |
| 2256 | DCHECK(in.IsConstant()); |
| 2257 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2258 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2259 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2260 | } |
| 2261 | break; |
| 2262 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2263 | case Primitive::kPrimFloat: { |
| 2264 | // Processing a Dex `float-to-int' instruction. |
| 2265 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2266 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2267 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2268 | |
| 2269 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2270 | // if input >= (float)INT_MAX goto done |
| 2271 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimIntMax)); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2272 | __ j(kAboveEqual, &done); |
| 2273 | // if input == NaN goto nan |
| 2274 | __ j(kUnordered, &nan); |
| 2275 | // output = float-to-int-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2276 | __ cvttss2si(output, input, false); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2277 | __ jmp(&done); |
| 2278 | __ Bind(&nan); |
| 2279 | // output = 0 |
| 2280 | __ xorl(output, output); |
| 2281 | __ Bind(&done); |
| 2282 | break; |
| 2283 | } |
| 2284 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2285 | case Primitive::kPrimDouble: { |
| 2286 | // Processing a Dex `double-to-int' instruction. |
| 2287 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2288 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2289 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2290 | |
| 2291 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2292 | // if input >= (double)INT_MAX goto done |
| 2293 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2294 | __ j(kAboveEqual, &done); |
| 2295 | // if input == NaN goto nan |
| 2296 | __ j(kUnordered, &nan); |
| 2297 | // output = double-to-int-truncate(input) |
| 2298 | __ cvttsd2si(output, input); |
| 2299 | __ jmp(&done); |
| 2300 | __ Bind(&nan); |
| 2301 | // output = 0 |
| 2302 | __ xorl(output, output); |
| 2303 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2304 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2305 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2306 | |
| 2307 | default: |
| 2308 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2309 | << " to " << result_type; |
| 2310 | } |
| 2311 | break; |
| 2312 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2313 | case Primitive::kPrimLong: |
| 2314 | switch (input_type) { |
| 2315 | DCHECK(out.IsRegister()); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2316 | case Primitive::kPrimBoolean: |
| 2317 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2318 | case Primitive::kPrimByte: |
| 2319 | case Primitive::kPrimShort: |
| 2320 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2321 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2322 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2323 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2324 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2325 | break; |
| 2326 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2327 | case Primitive::kPrimFloat: { |
| 2328 | // Processing a Dex `float-to-long' instruction. |
| 2329 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2330 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2331 | NearLabel done, nan; |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2332 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2333 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2334 | // if input >= (float)LONG_MAX goto done |
| 2335 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimLongMax)); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2336 | __ j(kAboveEqual, &done); |
| 2337 | // if input == NaN goto nan |
| 2338 | __ j(kUnordered, &nan); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2339 | // output = float-to-long-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2340 | __ cvttss2si(output, input, true); |
| 2341 | __ jmp(&done); |
| 2342 | __ Bind(&nan); |
| 2343 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2344 | __ xorl(output, output); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2345 | __ Bind(&done); |
| 2346 | break; |
| 2347 | } |
| 2348 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2349 | case Primitive::kPrimDouble: { |
| 2350 | // Processing a Dex `double-to-long' instruction. |
| 2351 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2352 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2353 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2354 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2355 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2356 | // if input >= (double)LONG_MAX goto done |
| 2357 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimLongMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2358 | __ j(kAboveEqual, &done); |
| 2359 | // if input == NaN goto nan |
| 2360 | __ j(kUnordered, &nan); |
| 2361 | // output = double-to-long-truncate(input) |
| 2362 | __ cvttsd2si(output, input, true); |
| 2363 | __ jmp(&done); |
| 2364 | __ Bind(&nan); |
| 2365 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2366 | __ xorl(output, output); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2367 | __ Bind(&done); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2368 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2369 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2370 | |
| 2371 | default: |
| 2372 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2373 | << " to " << result_type; |
| 2374 | } |
| 2375 | break; |
| 2376 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2377 | case Primitive::kPrimChar: |
| 2378 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2379 | case Primitive::kPrimBoolean: |
| 2380 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2381 | case Primitive::kPrimByte: |
| 2382 | case Primitive::kPrimShort: |
| 2383 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2384 | // Processing a Dex `int-to-char' instruction. |
| 2385 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2386 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2387 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2388 | __ movzxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2389 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2390 | } else { |
| 2391 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2392 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2393 | Immediate(static_cast<uint16_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2394 | } |
| 2395 | break; |
| 2396 | |
| 2397 | default: |
| 2398 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2399 | << " to " << result_type; |
| 2400 | } |
| 2401 | break; |
| 2402 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2403 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2404 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2405 | case Primitive::kPrimBoolean: |
| 2406 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2407 | case Primitive::kPrimByte: |
| 2408 | case Primitive::kPrimShort: |
| 2409 | case Primitive::kPrimInt: |
| 2410 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2411 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2412 | if (in.IsRegister()) { |
| 2413 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2414 | } else if (in.IsConstant()) { |
| 2415 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2416 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2417 | if (v == 0) { |
| 2418 | __ xorps(dest, dest); |
| 2419 | } else { |
| 2420 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2421 | } |
| 2422 | } else { |
| 2423 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2424 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2425 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2426 | break; |
| 2427 | |
| 2428 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2429 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2430 | if (in.IsRegister()) { |
| 2431 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2432 | } else if (in.IsConstant()) { |
| 2433 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2434 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2435 | if (v == 0) { |
| 2436 | __ xorps(dest, dest); |
| 2437 | } else { |
| 2438 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2439 | } |
| 2440 | } else { |
| 2441 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2442 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2443 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2444 | break; |
| 2445 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2446 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2447 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2448 | if (in.IsFpuRegister()) { |
| 2449 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2450 | } else if (in.IsConstant()) { |
| 2451 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2452 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2453 | if (bit_cast<int64_t, double>(v) == 0) { |
| 2454 | __ xorps(dest, dest); |
| 2455 | } else { |
| 2456 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2457 | } |
| 2458 | } else { |
| 2459 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 2460 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2461 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2462 | break; |
| 2463 | |
| 2464 | default: |
| 2465 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2466 | << " to " << result_type; |
| 2467 | }; |
| 2468 | break; |
| 2469 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2470 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2471 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2472 | case Primitive::kPrimBoolean: |
| 2473 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2474 | case Primitive::kPrimByte: |
| 2475 | case Primitive::kPrimShort: |
| 2476 | case Primitive::kPrimInt: |
| 2477 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2478 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2479 | if (in.IsRegister()) { |
| 2480 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2481 | } else if (in.IsConstant()) { |
| 2482 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2483 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2484 | if (v == 0) { |
| 2485 | __ xorpd(dest, dest); |
| 2486 | } else { |
| 2487 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2488 | } |
| 2489 | } else { |
| 2490 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2491 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2492 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2493 | break; |
| 2494 | |
| 2495 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2496 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2497 | if (in.IsRegister()) { |
| 2498 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2499 | } else if (in.IsConstant()) { |
| 2500 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2501 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2502 | if (v == 0) { |
| 2503 | __ xorpd(dest, dest); |
| 2504 | } else { |
| 2505 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2506 | } |
| 2507 | } else { |
| 2508 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2509 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2510 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2511 | break; |
| 2512 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2513 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2514 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2515 | if (in.IsFpuRegister()) { |
| 2516 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2517 | } else if (in.IsConstant()) { |
| 2518 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 2519 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2520 | if (bit_cast<int32_t, float>(v) == 0) { |
| 2521 | __ xorpd(dest, dest); |
| 2522 | } else { |
| 2523 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2524 | } |
| 2525 | } else { |
| 2526 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 2527 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2528 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2529 | break; |
| 2530 | |
| 2531 | default: |
| 2532 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2533 | << " to " << result_type; |
| 2534 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2535 | break; |
| 2536 | |
| 2537 | default: |
| 2538 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2539 | << " to " << result_type; |
| 2540 | } |
| 2541 | } |
| 2542 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2543 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2544 | LocationSummary* locations = |
| 2545 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2546 | switch (add->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2547 | case Primitive::kPrimInt: { |
| 2548 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2549 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2550 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2551 | break; |
| 2552 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2553 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2554 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2555 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2556 | // 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] | 2557 | locations->SetInAt(1, Location::RegisterOrInt32LongConstant(add->InputAt(1))); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2558 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2559 | break; |
| 2560 | } |
| 2561 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2562 | case Primitive::kPrimDouble: |
| 2563 | case Primitive::kPrimFloat: { |
| 2564 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2565 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2566 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2567 | break; |
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 | |
| 2570 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2571 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2572 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2573 | } |
| 2574 | |
| 2575 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 2576 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2577 | Location first = locations->InAt(0); |
| 2578 | Location second = locations->InAt(1); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2579 | Location out = locations->Out(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2580 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2581 | switch (add->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2582 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2583 | if (second.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2584 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2585 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2586 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2587 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2588 | } else { |
| 2589 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2590 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2591 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2592 | } else if (second.IsConstant()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2593 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2594 | __ addl(out.AsRegister<CpuRegister>(), |
| 2595 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 2596 | } else { |
| 2597 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2598 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 2599 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2600 | } else { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2601 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2602 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2603 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2604 | break; |
| 2605 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2606 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2607 | case Primitive::kPrimLong: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2608 | if (second.IsRegister()) { |
| 2609 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2610 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2611 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2612 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2613 | } else { |
| 2614 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2615 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2616 | } |
| 2617 | } else { |
| 2618 | DCHECK(second.IsConstant()); |
| 2619 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2620 | int32_t int32_value = Low32Bits(value); |
| 2621 | DCHECK_EQ(int32_value, value); |
| 2622 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2623 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 2624 | } else { |
| 2625 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2626 | first.AsRegister<CpuRegister>(), int32_value)); |
| 2627 | } |
| 2628 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2629 | break; |
| 2630 | } |
| 2631 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2632 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2633 | if (second.IsFpuRegister()) { |
| 2634 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2635 | } else if (second.IsConstant()) { |
| 2636 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2637 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 2638 | } else { |
| 2639 | DCHECK(second.IsStackSlot()); |
| 2640 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2641 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2642 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2643 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2644 | } |
| 2645 | |
| 2646 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2647 | if (second.IsFpuRegister()) { |
| 2648 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2649 | } else if (second.IsConstant()) { |
| 2650 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2651 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 2652 | } else { |
| 2653 | DCHECK(second.IsDoubleStackSlot()); |
| 2654 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2655 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2656 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2657 | break; |
| 2658 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2659 | |
| 2660 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2661 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2662 | } |
| 2663 | } |
| 2664 | |
| 2665 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2666 | LocationSummary* locations = |
| 2667 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2668 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2669 | case Primitive::kPrimInt: { |
| 2670 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2671 | locations->SetInAt(1, Location::Any()); |
| 2672 | locations->SetOut(Location::SameAsFirstInput()); |
| 2673 | break; |
| 2674 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2675 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2676 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2677 | locations->SetInAt(1, Location::RegisterOrInt32LongConstant(sub->InputAt(1))); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2678 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2679 | break; |
| 2680 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2681 | case Primitive::kPrimFloat: |
| 2682 | case Primitive::kPrimDouble: { |
| 2683 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2684 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2685 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2686 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2687 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2688 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2689 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2690 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2691 | } |
| 2692 | |
| 2693 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 2694 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2695 | Location first = locations->InAt(0); |
| 2696 | Location second = locations->InAt(1); |
| 2697 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2698 | switch (sub->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2699 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2700 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2701 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2702 | } else if (second.IsConstant()) { |
| 2703 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2704 | __ subl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2705 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2706 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2707 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2708 | break; |
| 2709 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2710 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2711 | if (second.IsConstant()) { |
| 2712 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2713 | DCHECK(IsInt<32>(value)); |
| 2714 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 2715 | } else { |
| 2716 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 2717 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2718 | break; |
| 2719 | } |
| 2720 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2721 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2722 | if (second.IsFpuRegister()) { |
| 2723 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2724 | } else if (second.IsConstant()) { |
| 2725 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2726 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 2727 | } else { |
| 2728 | DCHECK(second.IsStackSlot()); |
| 2729 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2730 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2731 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2732 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2733 | } |
| 2734 | |
| 2735 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2736 | if (second.IsFpuRegister()) { |
| 2737 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2738 | } else if (second.IsConstant()) { |
| 2739 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2740 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 2741 | } else { |
| 2742 | DCHECK(second.IsDoubleStackSlot()); |
| 2743 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2744 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2745 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2746 | break; |
| 2747 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2748 | |
| 2749 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2750 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2751 | } |
| 2752 | } |
| 2753 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2754 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 2755 | LocationSummary* locations = |
| 2756 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2757 | switch (mul->GetResultType()) { |
| 2758 | case Primitive::kPrimInt: { |
| 2759 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2760 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2761 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2762 | // Can use 3 operand multiply. |
| 2763 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2764 | } else { |
| 2765 | locations->SetOut(Location::SameAsFirstInput()); |
| 2766 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2767 | break; |
| 2768 | } |
| 2769 | case Primitive::kPrimLong: { |
| 2770 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2771 | locations->SetInAt(1, Location::Any()); |
| 2772 | if (mul->InputAt(1)->IsLongConstant() && |
| 2773 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2774 | // Can use 3 operand multiply. |
| 2775 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2776 | } else { |
| 2777 | locations->SetOut(Location::SameAsFirstInput()); |
| 2778 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2779 | break; |
| 2780 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2781 | case Primitive::kPrimFloat: |
| 2782 | case Primitive::kPrimDouble: { |
| 2783 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2784 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2785 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2786 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2787 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2788 | |
| 2789 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2790 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2791 | } |
| 2792 | } |
| 2793 | |
| 2794 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 2795 | LocationSummary* locations = mul->GetLocations(); |
| 2796 | Location first = locations->InAt(0); |
| 2797 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2798 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2799 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2800 | case Primitive::kPrimInt: |
| 2801 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2802 | // problems where the output may not be the same as the first operand. |
| 2803 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2804 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 2805 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 2806 | } else if (second.IsRegister()) { |
| 2807 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2808 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2809 | } else { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2810 | DCHECK(first.Equals(out)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2811 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2812 | __ imull(first.AsRegister<CpuRegister>(), |
| 2813 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2814 | } |
| 2815 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2816 | case Primitive::kPrimLong: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2817 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2818 | // problems where the output may not be the same as the first operand. |
| 2819 | if (mul->InputAt(1)->IsLongConstant()) { |
| 2820 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 2821 | if (IsInt<32>(value)) { |
| 2822 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 2823 | Immediate(static_cast<int32_t>(value))); |
| 2824 | } else { |
| 2825 | // Have to use the constant area. |
| 2826 | DCHECK(first.Equals(out)); |
| 2827 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 2828 | } |
| 2829 | } else if (second.IsRegister()) { |
| 2830 | DCHECK(first.Equals(out)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2831 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2832 | } else { |
| 2833 | DCHECK(second.IsDoubleStackSlot()); |
| 2834 | DCHECK(first.Equals(out)); |
| 2835 | __ imulq(first.AsRegister<CpuRegister>(), |
| 2836 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2837 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2838 | break; |
| 2839 | } |
| 2840 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2841 | case Primitive::kPrimFloat: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2842 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2843 | if (second.IsFpuRegister()) { |
| 2844 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2845 | } else if (second.IsConstant()) { |
| 2846 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 2847 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 2848 | } else { |
| 2849 | DCHECK(second.IsStackSlot()); |
| 2850 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 2851 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2852 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2853 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2854 | } |
| 2855 | |
| 2856 | case Primitive::kPrimDouble: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2857 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2858 | if (second.IsFpuRegister()) { |
| 2859 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2860 | } else if (second.IsConstant()) { |
| 2861 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 2862 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 2863 | } else { |
| 2864 | DCHECK(second.IsDoubleStackSlot()); |
| 2865 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 2866 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2867 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2868 | break; |
| 2869 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2870 | |
| 2871 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2872 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2873 | } |
| 2874 | } |
| 2875 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2876 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 2877 | uint32_t stack_adjustment, bool is_float) { |
| 2878 | if (source.IsStackSlot()) { |
| 2879 | DCHECK(is_float); |
| 2880 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 2881 | } else if (source.IsDoubleStackSlot()) { |
| 2882 | DCHECK(!is_float); |
| 2883 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 2884 | } else { |
| 2885 | // Write the value to the temporary location on the stack and load to FP stack. |
| 2886 | if (is_float) { |
| 2887 | Location stack_temp = Location::StackSlot(temp_offset); |
| 2888 | codegen_->Move(stack_temp, source); |
| 2889 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 2890 | } else { |
| 2891 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 2892 | codegen_->Move(stack_temp, source); |
| 2893 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 2894 | } |
| 2895 | } |
| 2896 | } |
| 2897 | |
| 2898 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| 2899 | Primitive::Type type = rem->GetResultType(); |
| 2900 | bool is_float = type == Primitive::kPrimFloat; |
| 2901 | size_t elem_size = Primitive::ComponentSize(type); |
| 2902 | LocationSummary* locations = rem->GetLocations(); |
| 2903 | Location first = locations->InAt(0); |
| 2904 | Location second = locations->InAt(1); |
| 2905 | Location out = locations->Out(); |
| 2906 | |
| 2907 | // Create stack space for 2 elements. |
| 2908 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2909 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 2910 | |
| 2911 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 2912 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 2913 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 2914 | |
| 2915 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2916 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2917 | __ Bind(&retry); |
| 2918 | __ fprem(); |
| 2919 | |
| 2920 | // Move FP status to AX. |
| 2921 | __ fstsw(); |
| 2922 | |
| 2923 | // And see if the argument reduction is complete. This is signaled by the |
| 2924 | // C2 FPU flag bit set to 0. |
| 2925 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 2926 | __ j(kNotEqual, &retry); |
| 2927 | |
| 2928 | // We have settled on the final value. Retrieve it into an XMM register. |
| 2929 | // Store FP top of stack to real stack. |
| 2930 | if (is_float) { |
| 2931 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 2932 | } else { |
| 2933 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 2934 | } |
| 2935 | |
| 2936 | // Pop the 2 items from the FP stack. |
| 2937 | __ fucompp(); |
| 2938 | |
| 2939 | // Load the value from the stack into an XMM register. |
| 2940 | DCHECK(out.IsFpuRegister()) << out; |
| 2941 | if (is_float) { |
| 2942 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 2943 | } else { |
| 2944 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 2945 | } |
| 2946 | |
| 2947 | // And remove the temporary stack space we allocated. |
| 2948 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 2949 | } |
| 2950 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2951 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2952 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2953 | |
| 2954 | LocationSummary* locations = instruction->GetLocations(); |
| 2955 | Location second = locations->InAt(1); |
| 2956 | DCHECK(second.IsConstant()); |
| 2957 | |
| 2958 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 2959 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2960 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2961 | |
| 2962 | DCHECK(imm == 1 || imm == -1); |
| 2963 | |
| 2964 | switch (instruction->GetResultType()) { |
| 2965 | case Primitive::kPrimInt: { |
| 2966 | if (instruction->IsRem()) { |
| 2967 | __ xorl(output_register, output_register); |
| 2968 | } else { |
| 2969 | __ movl(output_register, input_register); |
| 2970 | if (imm == -1) { |
| 2971 | __ negl(output_register); |
| 2972 | } |
| 2973 | } |
| 2974 | break; |
| 2975 | } |
| 2976 | |
| 2977 | case Primitive::kPrimLong: { |
| 2978 | if (instruction->IsRem()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2979 | __ xorl(output_register, output_register); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2980 | } else { |
| 2981 | __ movq(output_register, input_register); |
| 2982 | if (imm == -1) { |
| 2983 | __ negq(output_register); |
| 2984 | } |
| 2985 | } |
| 2986 | break; |
| 2987 | } |
| 2988 | |
| 2989 | default: |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2990 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2991 | } |
| 2992 | } |
| 2993 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2994 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2995 | LocationSummary* locations = instruction->GetLocations(); |
| 2996 | Location second = locations->InAt(1); |
| 2997 | |
| 2998 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 2999 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3000 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3001 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3002 | |
| 3003 | DCHECK(IsPowerOfTwo(std::abs(imm))); |
| 3004 | |
| 3005 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3006 | |
| 3007 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 3008 | __ leal(tmp, Address(numerator, std::abs(imm) - 1)); |
| 3009 | __ testl(numerator, numerator); |
| 3010 | __ cmov(kGreaterEqual, tmp, numerator); |
| 3011 | int shift = CTZ(imm); |
| 3012 | __ sarl(tmp, Immediate(shift)); |
| 3013 | |
| 3014 | if (imm < 0) { |
| 3015 | __ negl(tmp); |
| 3016 | } |
| 3017 | |
| 3018 | __ movl(output_register, tmp); |
| 3019 | } else { |
| 3020 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3021 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3022 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3023 | codegen_->Load64BitValue(rdx, std::abs(imm) - 1); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3024 | __ addq(rdx, numerator); |
| 3025 | __ testq(numerator, numerator); |
| 3026 | __ cmov(kGreaterEqual, rdx, numerator); |
| 3027 | int shift = CTZ(imm); |
| 3028 | __ sarq(rdx, Immediate(shift)); |
| 3029 | |
| 3030 | if (imm < 0) { |
| 3031 | __ negq(rdx); |
| 3032 | } |
| 3033 | |
| 3034 | __ movq(output_register, rdx); |
| 3035 | } |
| 3036 | } |
| 3037 | |
| 3038 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3039 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3040 | |
| 3041 | LocationSummary* locations = instruction->GetLocations(); |
| 3042 | Location second = locations->InAt(1); |
| 3043 | |
| 3044 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 3045 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3046 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3047 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 3048 | : locations->Out().AsRegister<CpuRegister>(); |
| 3049 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3050 | |
| 3051 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 3052 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 3053 | if (instruction->IsDiv()) { |
| 3054 | DCHECK_EQ(RAX, out.AsRegister()); |
| 3055 | } else { |
| 3056 | DCHECK_EQ(RDX, out.AsRegister()); |
| 3057 | } |
| 3058 | |
| 3059 | int64_t magic; |
| 3060 | int shift; |
| 3061 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3062 | // TODO: can these branches be written as one? |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3063 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 3064 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 3065 | |
| 3066 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3067 | |
| 3068 | __ movl(numerator, eax); |
| 3069 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3070 | NearLabel no_div; |
| 3071 | NearLabel end; |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3072 | __ testl(eax, eax); |
| 3073 | __ j(kNotEqual, &no_div); |
| 3074 | |
| 3075 | __ xorl(out, out); |
| 3076 | __ jmp(&end); |
| 3077 | |
| 3078 | __ Bind(&no_div); |
| 3079 | |
| 3080 | __ movl(eax, Immediate(magic)); |
| 3081 | __ imull(numerator); |
| 3082 | |
| 3083 | if (imm > 0 && magic < 0) { |
| 3084 | __ addl(edx, numerator); |
| 3085 | } else if (imm < 0 && magic > 0) { |
| 3086 | __ subl(edx, numerator); |
| 3087 | } |
| 3088 | |
| 3089 | if (shift != 0) { |
| 3090 | __ sarl(edx, Immediate(shift)); |
| 3091 | } |
| 3092 | |
| 3093 | __ movl(eax, edx); |
| 3094 | __ shrl(edx, Immediate(31)); |
| 3095 | __ addl(edx, eax); |
| 3096 | |
| 3097 | if (instruction->IsRem()) { |
| 3098 | __ movl(eax, numerator); |
| 3099 | __ imull(edx, Immediate(imm)); |
| 3100 | __ subl(eax, edx); |
| 3101 | __ movl(edx, eax); |
| 3102 | } else { |
| 3103 | __ movl(eax, edx); |
| 3104 | } |
| 3105 | __ Bind(&end); |
| 3106 | } else { |
| 3107 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3108 | |
| 3109 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 3110 | |
| 3111 | CpuRegister rax = eax; |
| 3112 | CpuRegister rdx = edx; |
| 3113 | |
| 3114 | CalculateMagicAndShiftForDivRem(imm, true /* is_long */, &magic, &shift); |
| 3115 | |
| 3116 | // Save the numerator. |
| 3117 | __ movq(numerator, rax); |
| 3118 | |
| 3119 | // RAX = magic |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3120 | codegen_->Load64BitValue(rax, magic); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3121 | |
| 3122 | // RDX:RAX = magic * numerator |
| 3123 | __ imulq(numerator); |
| 3124 | |
| 3125 | if (imm > 0 && magic < 0) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3126 | // RDX += numerator |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3127 | __ addq(rdx, numerator); |
| 3128 | } else if (imm < 0 && magic > 0) { |
| 3129 | // RDX -= numerator |
| 3130 | __ subq(rdx, numerator); |
| 3131 | } |
| 3132 | |
| 3133 | // Shift if needed. |
| 3134 | if (shift != 0) { |
| 3135 | __ sarq(rdx, Immediate(shift)); |
| 3136 | } |
| 3137 | |
| 3138 | // RDX += 1 if RDX < 0 |
| 3139 | __ movq(rax, rdx); |
| 3140 | __ shrq(rdx, Immediate(63)); |
| 3141 | __ addq(rdx, rax); |
| 3142 | |
| 3143 | if (instruction->IsRem()) { |
| 3144 | __ movq(rax, numerator); |
| 3145 | |
| 3146 | if (IsInt<32>(imm)) { |
| 3147 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 3148 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3149 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3150 | } |
| 3151 | |
| 3152 | __ subq(rax, rdx); |
| 3153 | __ movq(rdx, rax); |
| 3154 | } else { |
| 3155 | __ movq(rax, rdx); |
| 3156 | } |
| 3157 | } |
| 3158 | } |
| 3159 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3160 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3161 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3162 | Primitive::Type type = instruction->GetResultType(); |
| 3163 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 3164 | |
| 3165 | bool is_div = instruction->IsDiv(); |
| 3166 | LocationSummary* locations = instruction->GetLocations(); |
| 3167 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3168 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3169 | Location second = locations->InAt(1); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3170 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3171 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3172 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3173 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3174 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3175 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3176 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3177 | if (imm == 0) { |
| 3178 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3179 | } else if (imm == 1 || imm == -1) { |
| 3180 | DivRemOneOrMinusOne(instruction); |
| 3181 | } else if (instruction->IsDiv() && IsPowerOfTwo(std::abs(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3182 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3183 | } else { |
| 3184 | DCHECK(imm <= -2 || imm >= 2); |
| 3185 | GenerateDivRemWithAnyConstant(instruction); |
| 3186 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3187 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3188 | SlowPathCode* slow_path = |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3189 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86_64( |
| 3190 | out.AsRegister(), type, is_div); |
| 3191 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3192 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3193 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3194 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3195 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3196 | // so it's safe to just use negl instead of more complex comparisons. |
| 3197 | if (type == Primitive::kPrimInt) { |
| 3198 | __ cmpl(second_reg, Immediate(-1)); |
| 3199 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3200 | // edx:eax <- sign-extended of eax |
| 3201 | __ cdq(); |
| 3202 | // eax = quotient, edx = remainder |
| 3203 | __ idivl(second_reg); |
| 3204 | } else { |
| 3205 | __ cmpq(second_reg, Immediate(-1)); |
| 3206 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3207 | // rdx:rax <- sign-extended of rax |
| 3208 | __ cqo(); |
| 3209 | // rax = quotient, rdx = remainder |
| 3210 | __ idivq(second_reg); |
| 3211 | } |
| 3212 | __ Bind(slow_path->GetExitLabel()); |
| 3213 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3214 | } |
| 3215 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3216 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3217 | LocationSummary* locations = |
| 3218 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3219 | switch (div->GetResultType()) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3220 | case Primitive::kPrimInt: |
| 3221 | case Primitive::kPrimLong: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3222 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3223 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3224 | locations->SetOut(Location::SameAsFirstInput()); |
| 3225 | // Intel uses edx:eax as the dividend. |
| 3226 | locations->AddTemp(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3227 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3228 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3229 | // output and request another temp. |
| 3230 | if (div->InputAt(1)->IsConstant()) { |
| 3231 | locations->AddTemp(Location::RequiresRegister()); |
| 3232 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3233 | break; |
| 3234 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3235 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3236 | case Primitive::kPrimFloat: |
| 3237 | case Primitive::kPrimDouble: { |
| 3238 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3239 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3240 | locations->SetOut(Location::SameAsFirstInput()); |
| 3241 | break; |
| 3242 | } |
| 3243 | |
| 3244 | default: |
| 3245 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3246 | } |
| 3247 | } |
| 3248 | |
| 3249 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3250 | LocationSummary* locations = div->GetLocations(); |
| 3251 | Location first = locations->InAt(0); |
| 3252 | Location second = locations->InAt(1); |
| 3253 | DCHECK(first.Equals(locations->Out())); |
| 3254 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3255 | Primitive::Type type = div->GetResultType(); |
| 3256 | switch (type) { |
| 3257 | case Primitive::kPrimInt: |
| 3258 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3259 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3260 | break; |
| 3261 | } |
| 3262 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3263 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3264 | if (second.IsFpuRegister()) { |
| 3265 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3266 | } else if (second.IsConstant()) { |
| 3267 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3268 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 3269 | } else { |
| 3270 | DCHECK(second.IsStackSlot()); |
| 3271 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3272 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3273 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3274 | break; |
| 3275 | } |
| 3276 | |
| 3277 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3278 | if (second.IsFpuRegister()) { |
| 3279 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3280 | } else if (second.IsConstant()) { |
| 3281 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3282 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 3283 | } else { |
| 3284 | DCHECK(second.IsDoubleStackSlot()); |
| 3285 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3286 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3287 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3288 | break; |
| 3289 | } |
| 3290 | |
| 3291 | default: |
| 3292 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3293 | } |
| 3294 | } |
| 3295 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3296 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3297 | Primitive::Type type = rem->GetResultType(); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3298 | LocationSummary* locations = |
| 3299 | new (GetGraph()->GetArena()) LocationSummary(rem, LocationSummary::kNoCall); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3300 | |
| 3301 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3302 | case Primitive::kPrimInt: |
| 3303 | case Primitive::kPrimLong: { |
| 3304 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3305 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3306 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3307 | locations->SetOut(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3308 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3309 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3310 | // output and request another temp. |
| 3311 | if (rem->InputAt(1)->IsConstant()) { |
| 3312 | locations->AddTemp(Location::RequiresRegister()); |
| 3313 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3314 | break; |
| 3315 | } |
| 3316 | |
| 3317 | case Primitive::kPrimFloat: |
| 3318 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3319 | locations->SetInAt(0, Location::Any()); |
| 3320 | locations->SetInAt(1, Location::Any()); |
| 3321 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3322 | locations->AddTemp(Location::RegisterLocation(RAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3323 | break; |
| 3324 | } |
| 3325 | |
| 3326 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3327 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3328 | } |
| 3329 | } |
| 3330 | |
| 3331 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| 3332 | Primitive::Type type = rem->GetResultType(); |
| 3333 | switch (type) { |
| 3334 | case Primitive::kPrimInt: |
| 3335 | case Primitive::kPrimLong: { |
| 3336 | GenerateDivRemIntegral(rem); |
| 3337 | break; |
| 3338 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3339 | case Primitive::kPrimFloat: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3340 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3341 | GenerateRemFP(rem); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3342 | break; |
| 3343 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3344 | default: |
| 3345 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3346 | } |
| 3347 | } |
| 3348 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3349 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3350 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3351 | ? LocationSummary::kCallOnSlowPath |
| 3352 | : LocationSummary::kNoCall; |
| 3353 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3354 | locations->SetInAt(0, Location::Any()); |
| 3355 | if (instruction->HasUses()) { |
| 3356 | locations->SetOut(Location::SameAsFirstInput()); |
| 3357 | } |
| 3358 | } |
| 3359 | |
| 3360 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3361 | SlowPathCode* slow_path = |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3362 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction); |
| 3363 | codegen_->AddSlowPath(slow_path); |
| 3364 | |
| 3365 | LocationSummary* locations = instruction->GetLocations(); |
| 3366 | Location value = locations->InAt(0); |
| 3367 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3368 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3369 | case Primitive::kPrimByte: |
| 3370 | case Primitive::kPrimChar: |
| 3371 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3372 | case Primitive::kPrimInt: { |
| 3373 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3374 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3375 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3376 | } else if (value.IsStackSlot()) { |
| 3377 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3378 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3379 | } else { |
| 3380 | DCHECK(value.IsConstant()) << value; |
| 3381 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3382 | __ jmp(slow_path->GetEntryLabel()); |
| 3383 | } |
| 3384 | } |
| 3385 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3386 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3387 | case Primitive::kPrimLong: { |
| 3388 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3389 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3390 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3391 | } else if (value.IsDoubleStackSlot()) { |
| 3392 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3393 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3394 | } else { |
| 3395 | DCHECK(value.IsConstant()) << value; |
| 3396 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3397 | __ jmp(slow_path->GetEntryLabel()); |
| 3398 | } |
| 3399 | } |
| 3400 | break; |
| 3401 | } |
| 3402 | default: |
| 3403 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3404 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3405 | } |
| 3406 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3407 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 3408 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3409 | |
| 3410 | LocationSummary* locations = |
| 3411 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3412 | |
| 3413 | switch (op->GetResultType()) { |
| 3414 | case Primitive::kPrimInt: |
| 3415 | case Primitive::kPrimLong: { |
| 3416 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3417 | // The shift count needs to be in CL. |
| 3418 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 3419 | locations->SetOut(Location::SameAsFirstInput()); |
| 3420 | break; |
| 3421 | } |
| 3422 | default: |
| 3423 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3424 | } |
| 3425 | } |
| 3426 | |
| 3427 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 3428 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3429 | |
| 3430 | LocationSummary* locations = op->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3431 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3432 | Location second = locations->InAt(1); |
| 3433 | |
| 3434 | switch (op->GetResultType()) { |
| 3435 | case Primitive::kPrimInt: { |
| 3436 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3437 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3438 | if (op->IsShl()) { |
| 3439 | __ shll(first_reg, second_reg); |
| 3440 | } else if (op->IsShr()) { |
| 3441 | __ sarl(first_reg, second_reg); |
| 3442 | } else { |
| 3443 | __ shrl(first_reg, second_reg); |
| 3444 | } |
| 3445 | } else { |
Nicolas Geoffray | 486cc19 | 2014-12-08 18:00:55 +0000 | [diff] [blame] | 3446 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3447 | if (op->IsShl()) { |
| 3448 | __ shll(first_reg, imm); |
| 3449 | } else if (op->IsShr()) { |
| 3450 | __ sarl(first_reg, imm); |
| 3451 | } else { |
| 3452 | __ shrl(first_reg, imm); |
| 3453 | } |
| 3454 | } |
| 3455 | break; |
| 3456 | } |
| 3457 | case Primitive::kPrimLong: { |
| 3458 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3459 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3460 | if (op->IsShl()) { |
| 3461 | __ shlq(first_reg, second_reg); |
| 3462 | } else if (op->IsShr()) { |
| 3463 | __ sarq(first_reg, second_reg); |
| 3464 | } else { |
| 3465 | __ shrq(first_reg, second_reg); |
| 3466 | } |
| 3467 | } else { |
Nicolas Geoffray | 486cc19 | 2014-12-08 18:00:55 +0000 | [diff] [blame] | 3468 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3469 | if (op->IsShl()) { |
| 3470 | __ shlq(first_reg, imm); |
| 3471 | } else if (op->IsShr()) { |
| 3472 | __ sarq(first_reg, imm); |
| 3473 | } else { |
| 3474 | __ shrq(first_reg, imm); |
| 3475 | } |
| 3476 | } |
| 3477 | break; |
| 3478 | } |
| 3479 | default: |
| 3480 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3481 | } |
| 3482 | } |
| 3483 | |
| 3484 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 3485 | HandleShift(shl); |
| 3486 | } |
| 3487 | |
| 3488 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 3489 | HandleShift(shl); |
| 3490 | } |
| 3491 | |
| 3492 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 3493 | HandleShift(shr); |
| 3494 | } |
| 3495 | |
| 3496 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 3497 | HandleShift(shr); |
| 3498 | } |
| 3499 | |
| 3500 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 3501 | HandleShift(ushr); |
| 3502 | } |
| 3503 | |
| 3504 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 3505 | HandleShift(ushr); |
| 3506 | } |
| 3507 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3508 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3509 | LocationSummary* locations = |
| 3510 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3511 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3512 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3513 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3514 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3515 | } |
| 3516 | |
| 3517 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
| 3518 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3519 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 3520 | instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3521 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3522 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3523 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3524 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3525 | instruction, |
| 3526 | instruction->GetDexPc(), |
| 3527 | nullptr); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3528 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 3529 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3530 | } |
| 3531 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3532 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 3533 | LocationSummary* locations = |
| 3534 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3535 | InvokeRuntimeCallingConvention calling_convention; |
| 3536 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3537 | locations->SetOut(Location::RegisterLocation(RAX)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3538 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3539 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3540 | } |
| 3541 | |
| 3542 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| 3543 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3544 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 3545 | instruction->GetTypeIndex()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3546 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3547 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3548 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3549 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3550 | instruction, |
| 3551 | instruction->GetDexPc(), |
| 3552 | nullptr); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3553 | |
| 3554 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3555 | } |
| 3556 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3557 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3558 | LocationSummary* locations = |
| 3559 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3560 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3561 | if (location.IsStackSlot()) { |
| 3562 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3563 | } else if (location.IsDoubleStackSlot()) { |
| 3564 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3565 | } |
| 3566 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3567 | } |
| 3568 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3569 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 3570 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3571 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3572 | } |
| 3573 | |
| 3574 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3575 | LocationSummary* locations = |
| 3576 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3577 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3578 | } |
| 3579 | |
| 3580 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 3581 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3582 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3583 | } |
| 3584 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3585 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3586 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3587 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3588 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3589 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3590 | } |
| 3591 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3592 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 3593 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3594 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 3595 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3596 | Location out = locations->Out(); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3597 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3598 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3599 | __ notl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3600 | break; |
| 3601 | |
| 3602 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3603 | __ notq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3604 | break; |
| 3605 | |
| 3606 | default: |
| 3607 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3608 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3609 | } |
| 3610 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3611 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3612 | LocationSummary* locations = |
| 3613 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3614 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3615 | locations->SetOut(Location::SameAsFirstInput()); |
| 3616 | } |
| 3617 | |
| 3618 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3619 | LocationSummary* locations = bool_not->GetLocations(); |
| 3620 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 3621 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 3622 | Location out = locations->Out(); |
| 3623 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 3624 | } |
| 3625 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3626 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3627 | LocationSummary* locations = |
| 3628 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3629 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 3630 | locations->SetInAt(i, Location::Any()); |
| 3631 | } |
| 3632 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3633 | } |
| 3634 | |
| 3635 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3636 | UNUSED(instruction); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3637 | LOG(FATAL) << "Unimplemented"; |
| 3638 | } |
| 3639 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3640 | void InstructionCodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3641 | /* |
| 3642 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 3643 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 3644 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 3645 | */ |
| 3646 | switch (kind) { |
| 3647 | case MemBarrierKind::kAnyAny: { |
| 3648 | __ mfence(); |
| 3649 | break; |
| 3650 | } |
| 3651 | case MemBarrierKind::kAnyStore: |
| 3652 | case MemBarrierKind::kLoadAny: |
| 3653 | case MemBarrierKind::kStoreStore: { |
| 3654 | // nop |
| 3655 | break; |
| 3656 | } |
| 3657 | default: |
| 3658 | LOG(FATAL) << "Unexpected memory barier " << kind; |
| 3659 | } |
| 3660 | } |
| 3661 | |
| 3662 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 3663 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 3664 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3665 | LocationSummary* locations = |
| 3666 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3667 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3668 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3669 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3670 | } else { |
| 3671 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3672 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3673 | } |
| 3674 | |
| 3675 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 3676 | const FieldInfo& field_info) { |
| 3677 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 3678 | |
| 3679 | LocationSummary* locations = instruction->GetLocations(); |
| 3680 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3681 | Location out = locations->Out(); |
| 3682 | bool is_volatile = field_info.IsVolatile(); |
| 3683 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3684 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3685 | |
| 3686 | switch (field_type) { |
| 3687 | case Primitive::kPrimBoolean: { |
| 3688 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3689 | break; |
| 3690 | } |
| 3691 | |
| 3692 | case Primitive::kPrimByte: { |
| 3693 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3694 | break; |
| 3695 | } |
| 3696 | |
| 3697 | case Primitive::kPrimShort: { |
| 3698 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3699 | break; |
| 3700 | } |
| 3701 | |
| 3702 | case Primitive::kPrimChar: { |
| 3703 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3704 | break; |
| 3705 | } |
| 3706 | |
| 3707 | case Primitive::kPrimInt: |
| 3708 | case Primitive::kPrimNot: { |
| 3709 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3710 | break; |
| 3711 | } |
| 3712 | |
| 3713 | case Primitive::kPrimLong: { |
| 3714 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3715 | break; |
| 3716 | } |
| 3717 | |
| 3718 | case Primitive::kPrimFloat: { |
| 3719 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 3720 | break; |
| 3721 | } |
| 3722 | |
| 3723 | case Primitive::kPrimDouble: { |
| 3724 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 3725 | break; |
| 3726 | } |
| 3727 | |
| 3728 | case Primitive::kPrimVoid: |
| 3729 | LOG(FATAL) << "Unreachable type " << field_type; |
| 3730 | UNREACHABLE(); |
| 3731 | } |
| 3732 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3733 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3734 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3735 | if (is_volatile) { |
| 3736 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 3737 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3738 | |
| 3739 | if (field_type == Primitive::kPrimNot) { |
| 3740 | __ MaybeUnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 3741 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3742 | } |
| 3743 | |
| 3744 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 3745 | const FieldInfo& field_info) { |
| 3746 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3747 | |
| 3748 | LocationSummary* locations = |
| 3749 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3750 | Primitive::Type field_type = field_info.GetFieldType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3751 | bool needs_write_barrier = |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3752 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3753 | |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3754 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3755 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
| 3756 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3757 | } else { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3758 | locations->SetInAt(1, Location::RegisterOrInt32LongConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3759 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3760 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3761 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3762 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3763 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3764 | } else if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 3765 | // Temporary register for the reference poisoning. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3766 | locations->AddTemp(Location::RequiresRegister()); |
| 3767 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3768 | } |
| 3769 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3770 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3771 | const FieldInfo& field_info, |
| 3772 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3773 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3774 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3775 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3776 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3777 | Location value = locations->InAt(1); |
| 3778 | bool is_volatile = field_info.IsVolatile(); |
| 3779 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3780 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3781 | |
| 3782 | if (is_volatile) { |
| 3783 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 3784 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3785 | |
| 3786 | switch (field_type) { |
| 3787 | case Primitive::kPrimBoolean: |
| 3788 | case Primitive::kPrimByte: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3789 | if (value.IsConstant()) { |
| 3790 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 3791 | __ movb(Address(base, offset), Immediate(v)); |
| 3792 | } else { |
| 3793 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3794 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3795 | break; |
| 3796 | } |
| 3797 | |
| 3798 | case Primitive::kPrimShort: |
| 3799 | case Primitive::kPrimChar: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3800 | if (value.IsConstant()) { |
| 3801 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 3802 | __ movw(Address(base, offset), Immediate(v)); |
| 3803 | } else { |
| 3804 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3805 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3806 | break; |
| 3807 | } |
| 3808 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3809 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3810 | case Primitive::kPrimNot: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3811 | if (value.IsConstant()) { |
| 3812 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3813 | // `field_type == Primitive::kPrimNot` implies `v == 0`. |
| 3814 | DCHECK((field_type != Primitive::kPrimNot) || (v == 0)); |
| 3815 | // Note: if heap poisoning is enabled, no need to poison |
| 3816 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 3817 | __ movl(Address(base, offset), Immediate(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3818 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3819 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 3820 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3821 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 3822 | __ PoisonHeapReference(temp); |
| 3823 | __ movl(Address(base, offset), temp); |
| 3824 | } else { |
| 3825 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3826 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3827 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3828 | break; |
| 3829 | } |
| 3830 | |
| 3831 | case Primitive::kPrimLong: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3832 | if (value.IsConstant()) { |
| 3833 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| 3834 | DCHECK(IsInt<32>(v)); |
| 3835 | int32_t v_32 = v; |
| 3836 | __ movq(Address(base, offset), Immediate(v_32)); |
| 3837 | } else { |
| 3838 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3839 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3840 | break; |
| 3841 | } |
| 3842 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3843 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3844 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3845 | break; |
| 3846 | } |
| 3847 | |
| 3848 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3849 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3850 | break; |
| 3851 | } |
| 3852 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3853 | case Primitive::kPrimVoid: |
| 3854 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3855 | UNREACHABLE(); |
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 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3858 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3859 | |
| 3860 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 3861 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3862 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3863 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3864 | } |
| 3865 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3866 | if (is_volatile) { |
| 3867 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 3868 | } |
| 3869 | } |
| 3870 | |
| 3871 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 3872 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3873 | } |
| 3874 | |
| 3875 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3876 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3877 | } |
| 3878 | |
| 3879 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3880 | HandleFieldGet(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3881 | } |
| 3882 | |
| 3883 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3884 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3885 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3886 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3887 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3888 | HandleFieldGet(instruction); |
| 3889 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3890 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3891 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3892 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3893 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3894 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3895 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3896 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3897 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3898 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3899 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3900 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3901 | } |
| 3902 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 3903 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldGet( |
| 3904 | HUnresolvedInstanceFieldGet* instruction) { |
| 3905 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3906 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3907 | instruction, instruction->GetFieldType(), calling_convention); |
| 3908 | } |
| 3909 | |
| 3910 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldGet( |
| 3911 | HUnresolvedInstanceFieldGet* instruction) { |
| 3912 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3913 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3914 | instruction->GetFieldType(), |
| 3915 | instruction->GetFieldIndex(), |
| 3916 | instruction->GetDexPc(), |
| 3917 | calling_convention); |
| 3918 | } |
| 3919 | |
| 3920 | void LocationsBuilderX86_64::VisitUnresolvedInstanceFieldSet( |
| 3921 | HUnresolvedInstanceFieldSet* instruction) { |
| 3922 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3923 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3924 | instruction, instruction->GetFieldType(), calling_convention); |
| 3925 | } |
| 3926 | |
| 3927 | void InstructionCodeGeneratorX86_64::VisitUnresolvedInstanceFieldSet( |
| 3928 | HUnresolvedInstanceFieldSet* instruction) { |
| 3929 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3930 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3931 | instruction->GetFieldType(), |
| 3932 | instruction->GetFieldIndex(), |
| 3933 | instruction->GetDexPc(), |
| 3934 | calling_convention); |
| 3935 | } |
| 3936 | |
| 3937 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldGet( |
| 3938 | HUnresolvedStaticFieldGet* instruction) { |
| 3939 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3940 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3941 | instruction, instruction->GetFieldType(), calling_convention); |
| 3942 | } |
| 3943 | |
| 3944 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldGet( |
| 3945 | HUnresolvedStaticFieldGet* instruction) { |
| 3946 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3947 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3948 | instruction->GetFieldType(), |
| 3949 | instruction->GetFieldIndex(), |
| 3950 | instruction->GetDexPc(), |
| 3951 | calling_convention); |
| 3952 | } |
| 3953 | |
| 3954 | void LocationsBuilderX86_64::VisitUnresolvedStaticFieldSet( |
| 3955 | HUnresolvedStaticFieldSet* instruction) { |
| 3956 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3957 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 3958 | instruction, instruction->GetFieldType(), calling_convention); |
| 3959 | } |
| 3960 | |
| 3961 | void InstructionCodeGeneratorX86_64::VisitUnresolvedStaticFieldSet( |
| 3962 | HUnresolvedStaticFieldSet* instruction) { |
| 3963 | FieldAccessCallingConventionX86_64 calling_convention; |
| 3964 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 3965 | instruction->GetFieldType(), |
| 3966 | instruction->GetFieldIndex(), |
| 3967 | instruction->GetDexPc(), |
| 3968 | calling_convention); |
| 3969 | } |
| 3970 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3971 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3972 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3973 | ? LocationSummary::kCallOnSlowPath |
| 3974 | : LocationSummary::kNoCall; |
| 3975 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 3976 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3977 | ? Location::RequiresRegister() |
| 3978 | : Location::Any(); |
| 3979 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3980 | if (instruction->HasUses()) { |
| 3981 | locations->SetOut(Location::SameAsFirstInput()); |
| 3982 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3983 | } |
| 3984 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3985 | void InstructionCodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3986 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 3987 | return; |
| 3988 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3989 | LocationSummary* locations = instruction->GetLocations(); |
| 3990 | Location obj = locations->InAt(0); |
| 3991 | |
| 3992 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
| 3993 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3994 | } |
| 3995 | |
| 3996 | void InstructionCodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3997 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3998 | codegen_->AddSlowPath(slow_path); |
| 3999 | |
| 4000 | LocationSummary* locations = instruction->GetLocations(); |
| 4001 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4002 | |
| 4003 | if (obj.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4004 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4005 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4006 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4007 | } else { |
| 4008 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4009 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4010 | __ jmp(slow_path->GetEntryLabel()); |
| 4011 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4012 | } |
| 4013 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4014 | } |
| 4015 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4016 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4017 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4018 | GenerateImplicitNullCheck(instruction); |
| 4019 | } else { |
| 4020 | GenerateExplicitNullCheck(instruction); |
| 4021 | } |
| 4022 | } |
| 4023 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4024 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4025 | LocationSummary* locations = |
| 4026 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4027 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4028 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4029 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4030 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4031 | } else { |
| 4032 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4033 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4034 | } |
| 4035 | |
| 4036 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 4037 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4038 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4039 | Location index = locations->InAt(1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4040 | Primitive::Type type = instruction->GetType(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4041 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4042 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4043 | case Primitive::kPrimBoolean: { |
| 4044 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4045 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4046 | if (index.IsConstant()) { |
| 4047 | __ movzxb(out, Address(obj, |
| 4048 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4049 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4050 | __ movzxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4051 | } |
| 4052 | break; |
| 4053 | } |
| 4054 | |
| 4055 | case Primitive::kPrimByte: { |
| 4056 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4057 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4058 | if (index.IsConstant()) { |
| 4059 | __ movsxb(out, Address(obj, |
| 4060 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4061 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4062 | __ movsxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4063 | } |
| 4064 | break; |
| 4065 | } |
| 4066 | |
| 4067 | case Primitive::kPrimShort: { |
| 4068 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4069 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4070 | if (index.IsConstant()) { |
| 4071 | __ movsxw(out, Address(obj, |
| 4072 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4073 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4074 | __ movsxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4075 | } |
| 4076 | break; |
| 4077 | } |
| 4078 | |
| 4079 | case Primitive::kPrimChar: { |
| 4080 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4081 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4082 | if (index.IsConstant()) { |
| 4083 | __ movzxw(out, Address(obj, |
| 4084 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4085 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4086 | __ movzxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4087 | } |
| 4088 | break; |
| 4089 | } |
| 4090 | |
| 4091 | case Primitive::kPrimInt: |
| 4092 | case Primitive::kPrimNot: { |
Roland Levillain | 33d6903 | 2015-06-18 18:20:59 +0100 | [diff] [blame] | 4093 | static_assert(sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4094 | "art::mirror::HeapReference<mirror::Object> and int32_t have different sizes."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4095 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4096 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4097 | if (index.IsConstant()) { |
| 4098 | __ movl(out, Address(obj, |
| 4099 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4100 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4101 | __ movl(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4102 | } |
| 4103 | break; |
| 4104 | } |
| 4105 | |
| 4106 | case Primitive::kPrimLong: { |
| 4107 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4108 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4109 | if (index.IsConstant()) { |
| 4110 | __ movq(out, Address(obj, |
| 4111 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4112 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4113 | __ movq(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4114 | } |
| 4115 | break; |
| 4116 | } |
| 4117 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4118 | case Primitive::kPrimFloat: { |
| 4119 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4120 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4121 | if (index.IsConstant()) { |
| 4122 | __ movss(out, Address(obj, |
| 4123 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4124 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4125 | __ movss(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4126 | } |
| 4127 | break; |
| 4128 | } |
| 4129 | |
| 4130 | case Primitive::kPrimDouble: { |
| 4131 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4132 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4133 | if (index.IsConstant()) { |
| 4134 | __ movsd(out, Address(obj, |
| 4135 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4136 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4137 | __ movsd(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4138 | } |
| 4139 | break; |
| 4140 | } |
| 4141 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4142 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4143 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4144 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4145 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4146 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4147 | |
| 4148 | if (type == Primitive::kPrimNot) { |
| 4149 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4150 | __ MaybeUnpoisonHeapReference(out); |
| 4151 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4152 | } |
| 4153 | |
| 4154 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4155 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4156 | |
| 4157 | bool needs_write_barrier = |
| 4158 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4159 | bool may_need_runtime_call = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4160 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4161 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4162 | instruction, |
| 4163 | may_need_runtime_call ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4164 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4165 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4166 | locations->SetInAt( |
| 4167 | 1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4168 | locations->SetInAt(2, Location::RequiresRegister()); |
| 4169 | if (value_type == Primitive::kPrimLong) { |
| 4170 | locations->SetInAt(2, Location::RegisterOrInt32LongConstant(instruction->InputAt(2))); |
| 4171 | } else if (value_type == Primitive::kPrimFloat || value_type == Primitive::kPrimDouble) { |
| 4172 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| 4173 | } else { |
| 4174 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 4175 | } |
| 4176 | |
| 4177 | if (needs_write_barrier) { |
| 4178 | // Temporary registers for the write barrier. |
| 4179 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 4180 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4181 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4182 | } |
| 4183 | |
| 4184 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 4185 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4186 | CpuRegister array = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4187 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4188 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4189 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4190 | bool may_need_runtime_call = locations->CanCall(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4191 | bool needs_write_barrier = |
| 4192 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4193 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4194 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4195 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4196 | |
| 4197 | switch (value_type) { |
| 4198 | case Primitive::kPrimBoolean: |
| 4199 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4200 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 4201 | Address address = index.IsConstant() |
| 4202 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 4203 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_1, offset); |
| 4204 | if (value.IsRegister()) { |
| 4205 | __ movb(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4206 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4207 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4208 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4209 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4210 | break; |
| 4211 | } |
| 4212 | |
| 4213 | case Primitive::kPrimShort: |
| 4214 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4215 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 4216 | Address address = index.IsConstant() |
| 4217 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 4218 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_2, offset); |
| 4219 | if (value.IsRegister()) { |
| 4220 | __ movw(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4221 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4222 | DCHECK(value.IsConstant()) << value; |
| 4223 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4224 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4225 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4226 | break; |
| 4227 | } |
| 4228 | |
| 4229 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4230 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4231 | Address address = index.IsConstant() |
| 4232 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4233 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
| 4234 | if (!value.IsRegister()) { |
| 4235 | // Just setting null. |
| 4236 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 4237 | DCHECK(value.IsConstant()) << value; |
| 4238 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4239 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4240 | DCHECK(!needs_write_barrier); |
| 4241 | DCHECK(!may_need_runtime_call); |
| 4242 | break; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4243 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4244 | |
| 4245 | DCHECK(needs_write_barrier); |
| 4246 | CpuRegister register_value = value.AsRegister<CpuRegister>(); |
| 4247 | NearLabel done, not_null, do_put; |
| 4248 | SlowPathCode* slow_path = nullptr; |
| 4249 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4250 | if (may_need_runtime_call) { |
| 4251 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86_64(instruction); |
| 4252 | codegen_->AddSlowPath(slow_path); |
| 4253 | if (instruction->GetValueCanBeNull()) { |
| 4254 | __ testl(register_value, register_value); |
| 4255 | __ j(kNotEqual, ¬_null); |
| 4256 | __ movl(address, Immediate(0)); |
| 4257 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4258 | __ jmp(&done); |
| 4259 | __ Bind(¬_null); |
| 4260 | } |
| 4261 | |
| 4262 | __ movl(temp, Address(array, class_offset)); |
| 4263 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4264 | __ MaybeUnpoisonHeapReference(temp); |
| 4265 | __ movl(temp, Address(temp, component_offset)); |
| 4266 | // No need to poison/unpoison, we're comparing two poisoned references. |
| 4267 | __ cmpl(temp, Address(register_value, class_offset)); |
| 4268 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4269 | __ j(kEqual, &do_put); |
| 4270 | __ MaybeUnpoisonHeapReference(temp); |
| 4271 | __ movl(temp, Address(temp, super_offset)); |
| 4272 | // No need to unpoison the result, we're comparing against null. |
| 4273 | __ testl(temp, temp); |
| 4274 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4275 | __ Bind(&do_put); |
| 4276 | } else { |
| 4277 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4278 | } |
| 4279 | } |
| 4280 | |
| 4281 | if (kPoisonHeapReferences) { |
| 4282 | __ movl(temp, register_value); |
| 4283 | __ PoisonHeapReference(temp); |
| 4284 | __ movl(address, temp); |
| 4285 | } else { |
| 4286 | __ movl(address, register_value); |
| 4287 | } |
| 4288 | if (!may_need_runtime_call) { |
| 4289 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4290 | } |
| 4291 | |
| 4292 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
| 4293 | codegen_->MarkGCCard( |
| 4294 | temp, card, array, value.AsRegister<CpuRegister>(), instruction->GetValueCanBeNull()); |
| 4295 | __ Bind(&done); |
| 4296 | |
| 4297 | if (slow_path != nullptr) { |
| 4298 | __ Bind(slow_path->GetExitLabel()); |
| 4299 | } |
| 4300 | |
| 4301 | break; |
| 4302 | } |
| 4303 | case Primitive::kPrimInt: { |
| 4304 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4305 | Address address = index.IsConstant() |
| 4306 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4307 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
| 4308 | if (value.IsRegister()) { |
| 4309 | __ movl(address, value.AsRegister<CpuRegister>()); |
| 4310 | } else { |
| 4311 | DCHECK(value.IsConstant()) << value; |
| 4312 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4313 | __ movl(address, Immediate(v)); |
| 4314 | } |
| 4315 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4316 | break; |
| 4317 | } |
| 4318 | |
| 4319 | case Primitive::kPrimLong: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4320 | uint32_t offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
| 4321 | Address address = index.IsConstant() |
| 4322 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 4323 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset); |
| 4324 | if (value.IsRegister()) { |
| 4325 | __ movq(address, value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4326 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4327 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| 4328 | DCHECK(IsInt<32>(v)); |
| 4329 | int32_t v_32 = v; |
| 4330 | __ movq(address, Immediate(v_32)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4331 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4332 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4333 | break; |
| 4334 | } |
| 4335 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4336 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4337 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4338 | Address address = index.IsConstant() |
| 4339 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4340 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_4, offset); |
| 4341 | DCHECK(value.IsFpuRegister()); |
| 4342 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4343 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4344 | break; |
| 4345 | } |
| 4346 | |
| 4347 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4348 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4349 | Address address = index.IsConstant() |
| 4350 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 4351 | : Address(array, index.AsRegister<CpuRegister>(), TIMES_8, offset); |
| 4352 | DCHECK(value.IsFpuRegister()); |
| 4353 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4354 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4355 | break; |
| 4356 | } |
| 4357 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4358 | case Primitive::kPrimVoid: |
| 4359 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4360 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4361 | } |
| 4362 | } |
| 4363 | |
| 4364 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4365 | LocationSummary* locations = |
| 4366 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4367 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4368 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4369 | } |
| 4370 | |
| 4371 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
| 4372 | LocationSummary* locations = instruction->GetLocations(); |
| 4373 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4374 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4375 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4376 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4377 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4378 | } |
| 4379 | |
| 4380 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4381 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4382 | ? LocationSummary::kCallOnSlowPath |
| 4383 | : LocationSummary::kNoCall; |
| 4384 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4385 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4386 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4387 | if (instruction->HasUses()) { |
| 4388 | locations->SetOut(Location::SameAsFirstInput()); |
| 4389 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4390 | } |
| 4391 | |
| 4392 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4393 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4394 | Location index_loc = locations->InAt(0); |
| 4395 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4396 | SlowPathCode* slow_path = |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4397 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4398 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4399 | if (length_loc.IsConstant()) { |
| 4400 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 4401 | if (index_loc.IsConstant()) { |
| 4402 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 4403 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4404 | if (index < 0 || index >= length) { |
| 4405 | codegen_->AddSlowPath(slow_path); |
| 4406 | __ jmp(slow_path->GetEntryLabel()); |
| 4407 | } else { |
| 4408 | // Some optimization after BCE may have generated this, and we should not |
| 4409 | // generate a bounds check if it is a valid range. |
| 4410 | } |
| 4411 | return; |
| 4412 | } |
| 4413 | |
| 4414 | // We have to reverse the jump condition because the length is the constant. |
| 4415 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 4416 | __ cmpl(index_reg, Immediate(length)); |
| 4417 | codegen_->AddSlowPath(slow_path); |
| 4418 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4419 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4420 | CpuRegister length = length_loc.AsRegister<CpuRegister>(); |
| 4421 | if (index_loc.IsConstant()) { |
| 4422 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4423 | __ cmpl(length, Immediate(value)); |
| 4424 | } else { |
| 4425 | __ cmpl(length, index_loc.AsRegister<CpuRegister>()); |
| 4426 | } |
| 4427 | codegen_->AddSlowPath(slow_path); |
| 4428 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4429 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4430 | } |
| 4431 | |
| 4432 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 4433 | CpuRegister card, |
| 4434 | CpuRegister object, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4435 | CpuRegister value, |
| 4436 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4437 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4438 | if (value_can_be_null) { |
| 4439 | __ testl(value, value); |
| 4440 | __ j(kEqual, &is_null); |
| 4441 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4442 | __ gs()->movq(card, Address::Absolute( |
| 4443 | Thread::CardTableOffset<kX86_64WordSize>().Int32Value(), true)); |
| 4444 | __ movq(temp, object); |
| 4445 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4446 | __ movb(Address(temp, card, TIMES_1, 0), card); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4447 | if (value_can_be_null) { |
| 4448 | __ Bind(&is_null); |
| 4449 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4450 | } |
| 4451 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4452 | void LocationsBuilderX86_64::VisitTemporary(HTemporary* temp) { |
| 4453 | temp->SetLocations(nullptr); |
| 4454 | } |
| 4455 | |
| 4456 | void InstructionCodeGeneratorX86_64::VisitTemporary(HTemporary* temp) { |
| 4457 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4458 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4459 | } |
| 4460 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4461 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4462 | UNUSED(instruction); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4463 | LOG(FATAL) << "Unimplemented"; |
| 4464 | } |
| 4465 | |
| 4466 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4467 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4468 | } |
| 4469 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4470 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4471 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4472 | } |
| 4473 | |
| 4474 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4475 | HBasicBlock* block = instruction->GetBlock(); |
| 4476 | if (block->GetLoopInformation() != nullptr) { |
| 4477 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4478 | // The back edge will generate the suspend check. |
| 4479 | return; |
| 4480 | } |
| 4481 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4482 | // The goto will generate the suspend check. |
| 4483 | return; |
| 4484 | } |
| 4485 | GenerateSuspendCheck(instruction, nullptr); |
| 4486 | } |
| 4487 | |
| 4488 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 4489 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4490 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4491 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 4492 | if (slow_path == nullptr) { |
| 4493 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
| 4494 | instruction->SetSlowPath(slow_path); |
| 4495 | codegen_->AddSlowPath(slow_path); |
| 4496 | if (successor != nullptr) { |
| 4497 | DCHECK(successor->IsLoopHeader()); |
| 4498 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 4499 | } |
| 4500 | } else { |
| 4501 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 4502 | } |
| 4503 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4504 | __ gs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4505 | Thread::ThreadFlagsOffset<kX86_64WordSize>().Int32Value(), true), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4506 | if (successor == nullptr) { |
| 4507 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4508 | __ Bind(slow_path->GetReturnLabel()); |
| 4509 | } else { |
| 4510 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 4511 | __ jmp(slow_path->GetEntryLabel()); |
| 4512 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4513 | } |
| 4514 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4515 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 4516 | return codegen_->GetAssembler(); |
| 4517 | } |
| 4518 | |
| 4519 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 4520 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4521 | Location source = move->GetSource(); |
| 4522 | Location destination = move->GetDestination(); |
| 4523 | |
| 4524 | if (source.IsRegister()) { |
| 4525 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4526 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4527 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4528 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4529 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4530 | } else { |
| 4531 | DCHECK(destination.IsDoubleStackSlot()); |
| 4532 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4533 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4534 | } |
| 4535 | } else if (source.IsStackSlot()) { |
| 4536 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4537 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4538 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4539 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4540 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4541 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4542 | } else { |
| 4543 | DCHECK(destination.IsStackSlot()); |
| 4544 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 4545 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 4546 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4547 | } else if (source.IsDoubleStackSlot()) { |
| 4548 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4549 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4550 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4551 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4552 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 4553 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4554 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 4555 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4556 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 4557 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 4558 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4559 | } else if (source.IsConstant()) { |
| 4560 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4561 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 4562 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4563 | if (destination.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4564 | if (value == 0) { |
| 4565 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 4566 | } else { |
| 4567 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 4568 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4569 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4570 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4571 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4572 | } |
| 4573 | } else if (constant->IsLongConstant()) { |
| 4574 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 4575 | if (destination.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4576 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4577 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4578 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 4579 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4580 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4581 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4582 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4583 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4584 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4585 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4586 | if (value == 0) { |
| 4587 | // easy FP 0.0. |
| 4588 | __ xorps(dest, dest); |
| 4589 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4590 | __ movss(dest, codegen_->LiteralFloatAddress(fp_value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4591 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4592 | } else { |
| 4593 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4594 | Immediate imm(value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4595 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 4596 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4597 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4598 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4599 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4600 | int64_t value = bit_cast<int64_t, double>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4601 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4602 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4603 | if (value == 0) { |
| 4604 | __ xorpd(dest, dest); |
| 4605 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4606 | __ movsd(dest, codegen_->LiteralDoubleAddress(fp_value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4607 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4608 | } else { |
| 4609 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 4610 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4611 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4612 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4613 | } else if (source.IsFpuRegister()) { |
| 4614 | if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4615 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4616 | } else if (destination.IsStackSlot()) { |
| 4617 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4618 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4619 | } else { |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 4620 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4621 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4622 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4623 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4624 | } |
| 4625 | } |
| 4626 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4627 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4628 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4629 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 4630 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4631 | } |
| 4632 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4633 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4634 | ScratchRegisterScope ensure_scratch( |
| 4635 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 4636 | |
| 4637 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 4638 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 4639 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 4640 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 4641 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 4642 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 4643 | CpuRegister(ensure_scratch.GetRegister())); |
| 4644 | } |
| 4645 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4646 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 4647 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 4648 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 4649 | __ movq(reg, CpuRegister(TMP)); |
| 4650 | } |
| 4651 | |
| 4652 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 4653 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4654 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4655 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4656 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 4657 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 4658 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 4659 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 4660 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 4661 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 4662 | CpuRegister(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4663 | } |
| 4664 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4665 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 4666 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 4667 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 4668 | __ movd(reg, CpuRegister(TMP)); |
| 4669 | } |
| 4670 | |
| 4671 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 4672 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 4673 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 4674 | __ movd(reg, CpuRegister(TMP)); |
| 4675 | } |
| 4676 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4677 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 4678 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4679 | Location source = move->GetSource(); |
| 4680 | Location destination = move->GetDestination(); |
| 4681 | |
| 4682 | if (source.IsRegister() && destination.IsRegister()) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4683 | __ xchgq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4684 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4685 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4686 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4687 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4688 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4689 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 4690 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4691 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4692 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4693 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4694 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 4695 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4696 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4697 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 4698 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 4699 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4700 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4701 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4702 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4703 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4704 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4705 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4706 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4707 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4708 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4709 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4710 | } |
| 4711 | } |
| 4712 | |
| 4713 | |
| 4714 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 4715 | __ pushq(CpuRegister(reg)); |
| 4716 | } |
| 4717 | |
| 4718 | |
| 4719 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 4720 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4721 | } |
| 4722 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4723 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4724 | SlowPathCode* slow_path, CpuRegister class_reg) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4725 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 4726 | Immediate(mirror::Class::kStatusInitialized)); |
| 4727 | __ j(kLess, slow_path->GetEntryLabel()); |
| 4728 | __ Bind(slow_path->GetExitLabel()); |
| 4729 | // No need for memory fence, thanks to the X86_64 memory model. |
| 4730 | } |
| 4731 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4732 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4733 | InvokeRuntimeCallingConvention calling_convention; |
| 4734 | CodeGenerator::CreateLoadClassLocationSummary( |
| 4735 | cls, |
| 4736 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 4737 | Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4738 | } |
| 4739 | |
| 4740 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4741 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4742 | if (cls->NeedsAccessCheck()) { |
| 4743 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 4744 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 4745 | cls, |
| 4746 | cls->GetDexPc(), |
| 4747 | nullptr); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 4748 | return; |
| 4749 | } |
| 4750 | |
| 4751 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4752 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4753 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4754 | DCHECK(!cls->CanCallRuntime()); |
| 4755 | DCHECK(!cls->MustGenerateClinitCheck()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4756 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4757 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4758 | DCHECK(cls->CanCallRuntime()); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4759 | __ movq(out, Address( |
| 4760 | current_method, ArtMethod::DexCacheResolvedTypesOffset(kX86_64PointerSize).Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4761 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4762 | // TODO: We will need a read barrier here. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4763 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4764 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4765 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 4766 | codegen_->AddSlowPath(slow_path); |
| 4767 | __ testl(out, out); |
| 4768 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4769 | if (cls->MustGenerateClinitCheck()) { |
| 4770 | GenerateClassInitializationCheck(slow_path, out); |
| 4771 | } else { |
| 4772 | __ Bind(slow_path->GetExitLabel()); |
| 4773 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4774 | } |
| 4775 | } |
| 4776 | |
| 4777 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 4778 | LocationSummary* locations = |
| 4779 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 4780 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4781 | if (check->HasUses()) { |
| 4782 | locations->SetOut(Location::SameAsFirstInput()); |
| 4783 | } |
| 4784 | } |
| 4785 | |
| 4786 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4787 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4788 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4789 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4790 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4791 | GenerateClassInitializationCheck(slow_path, |
| 4792 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4793 | } |
| 4794 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4795 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
| 4796 | LocationSummary* locations = |
| 4797 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4798 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4799 | locations->SetOut(Location::RequiresRegister()); |
| 4800 | } |
| 4801 | |
| 4802 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4803 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86_64(load); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4804 | codegen_->AddSlowPath(slow_path); |
| 4805 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4806 | LocationSummary* locations = load->GetLocations(); |
| 4807 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4808 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4809 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4810 | __ movq(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4811 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4812 | // TODO: We will need a read barrier here. |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4813 | __ testl(out, out); |
| 4814 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4815 | __ Bind(slow_path->GetExitLabel()); |
| 4816 | } |
| 4817 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4818 | static Address GetExceptionTlsAddress() { |
| 4819 | return Address::Absolute(Thread::ExceptionOffset<kX86_64WordSize>().Int32Value(), true); |
| 4820 | } |
| 4821 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4822 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 4823 | LocationSummary* locations = |
| 4824 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 4825 | locations->SetOut(Location::RequiresRegister()); |
| 4826 | } |
| 4827 | |
| 4828 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4829 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 4830 | } |
| 4831 | |
| 4832 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
| 4833 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 4834 | } |
| 4835 | |
| 4836 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 4837 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4838 | } |
| 4839 | |
| 4840 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| 4841 | LocationSummary* locations = |
| 4842 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4843 | InvokeRuntimeCallingConvention calling_convention; |
| 4844 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4845 | } |
| 4846 | |
| 4847 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 4848 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 4849 | instruction, |
| 4850 | instruction->GetDexPc(), |
| 4851 | nullptr); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4852 | } |
| 4853 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4854 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4855 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 4856 | switch (instruction->GetTypeCheckKind()) { |
| 4857 | case TypeCheckKind::kExactCheck: |
| 4858 | case TypeCheckKind::kAbstractClassCheck: |
| 4859 | case TypeCheckKind::kClassHierarchyCheck: |
| 4860 | case TypeCheckKind::kArrayObjectCheck: |
| 4861 | call_kind = LocationSummary::kNoCall; |
| 4862 | break; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4863 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4864 | case TypeCheckKind::kInterfaceCheck: |
| 4865 | call_kind = LocationSummary::kCall; |
| 4866 | break; |
| 4867 | case TypeCheckKind::kArrayCheck: |
| 4868 | call_kind = LocationSummary::kCallOnSlowPath; |
| 4869 | break; |
| 4870 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4871 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4872 | if (call_kind != LocationSummary::kCall) { |
| 4873 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4874 | locations->SetInAt(1, Location::Any()); |
| 4875 | // Note that TypeCheckSlowPathX86_64 uses this register too. |
| 4876 | locations->SetOut(Location::RequiresRegister()); |
| 4877 | } else { |
| 4878 | InvokeRuntimeCallingConvention calling_convention; |
| 4879 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4880 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 4881 | locations->SetOut(Location::RegisterLocation(RAX)); |
| 4882 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4883 | } |
| 4884 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4885 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4886 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4887 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4888 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4889 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4890 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4891 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4892 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4893 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4894 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4895 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4896 | |
| 4897 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4898 | // Avoid null check if we know obj is not null. |
| 4899 | if (instruction->MustDoNullCheck()) { |
| 4900 | __ testl(obj, obj); |
| 4901 | __ j(kEqual, &zero); |
| 4902 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4903 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4904 | // In case of an interface/unresolved check, we put the object class into the object register. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4905 | // This is safe, as the register is caller-save, and the object must be in another |
| 4906 | // register if it survives the runtime call. |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4907 | CpuRegister target = (instruction->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck) || |
| 4908 | (instruction->GetTypeCheckKind() == TypeCheckKind::kUnresolvedCheck) |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4909 | ? obj |
| 4910 | : out; |
| 4911 | __ movl(target, Address(obj, class_offset)); |
| 4912 | __ MaybeUnpoisonHeapReference(target); |
| 4913 | |
| 4914 | switch (instruction->GetTypeCheckKind()) { |
| 4915 | case TypeCheckKind::kExactCheck: { |
| 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 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4922 | if (zero.IsLinked()) { |
| 4923 | // Classes must be equal for the instanceof to succeed. |
| 4924 | __ j(kNotEqual, &zero); |
| 4925 | __ movl(out, Immediate(1)); |
| 4926 | __ jmp(&done); |
| 4927 | } else { |
| 4928 | __ setcc(kEqual, out); |
| 4929 | // setcc only sets the low byte. |
| 4930 | __ andl(out, Immediate(1)); |
| 4931 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4932 | break; |
| 4933 | } |
| 4934 | case TypeCheckKind::kAbstractClassCheck: { |
| 4935 | // If the class is abstract, we eagerly fetch the super class of the |
| 4936 | // object to avoid doing a comparison we know will fail. |
| 4937 | NearLabel loop, success; |
| 4938 | __ Bind(&loop); |
| 4939 | __ movl(out, Address(out, super_offset)); |
| 4940 | __ MaybeUnpoisonHeapReference(out); |
| 4941 | __ testl(out, out); |
| 4942 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4943 | __ j(kEqual, &done); |
| 4944 | if (cls.IsRegister()) { |
| 4945 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 4946 | } else { |
| 4947 | DCHECK(cls.IsStackSlot()) << cls; |
| 4948 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 4949 | } |
| 4950 | __ j(kNotEqual, &loop); |
| 4951 | __ movl(out, Immediate(1)); |
| 4952 | if (zero.IsLinked()) { |
| 4953 | __ jmp(&done); |
| 4954 | } |
| 4955 | break; |
| 4956 | } |
| 4957 | case TypeCheckKind::kClassHierarchyCheck: { |
| 4958 | // Walk over the class hierarchy to find a match. |
| 4959 | NearLabel loop, success; |
| 4960 | __ Bind(&loop); |
| 4961 | if (cls.IsRegister()) { |
| 4962 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 4963 | } else { |
| 4964 | DCHECK(cls.IsStackSlot()) << cls; |
| 4965 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 4966 | } |
| 4967 | __ j(kEqual, &success); |
| 4968 | __ movl(out, Address(out, super_offset)); |
| 4969 | __ MaybeUnpoisonHeapReference(out); |
| 4970 | __ testl(out, out); |
| 4971 | __ j(kNotEqual, &loop); |
| 4972 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4973 | __ jmp(&done); |
| 4974 | __ Bind(&success); |
| 4975 | __ movl(out, Immediate(1)); |
| 4976 | if (zero.IsLinked()) { |
| 4977 | __ jmp(&done); |
| 4978 | } |
| 4979 | break; |
| 4980 | } |
| 4981 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4982 | // Do an exact check. |
| 4983 | NearLabel exact_check; |
| 4984 | if (cls.IsRegister()) { |
| 4985 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 4986 | } else { |
| 4987 | DCHECK(cls.IsStackSlot()) << cls; |
| 4988 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 4989 | } |
| 4990 | __ j(kEqual, &exact_check); |
| 4991 | // 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] | 4992 | __ movl(out, Address(out, component_offset)); |
| 4993 | __ MaybeUnpoisonHeapReference(out); |
| 4994 | __ testl(out, out); |
| 4995 | // If `out` is null, we use it for the result, and jump to `done`. |
| 4996 | __ j(kEqual, &done); |
| 4997 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 4998 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 4999 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5000 | __ movl(out, Immediate(1)); |
| 5001 | __ jmp(&done); |
| 5002 | break; |
| 5003 | } |
| 5004 | case TypeCheckKind::kArrayCheck: { |
| 5005 | if (cls.IsRegister()) { |
| 5006 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
| 5007 | } else { |
| 5008 | DCHECK(cls.IsStackSlot()) << cls; |
| 5009 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5010 | } |
| 5011 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5012 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64( |
| 5013 | instruction, /* is_fatal */ false); |
| 5014 | codegen_->AddSlowPath(slow_path); |
| 5015 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5016 | __ movl(out, Immediate(1)); |
| 5017 | if (zero.IsLinked()) { |
| 5018 | __ jmp(&done); |
| 5019 | } |
| 5020 | break; |
| 5021 | } |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5022 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5023 | case TypeCheckKind::kInterfaceCheck: |
| 5024 | default: { |
| 5025 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 5026 | instruction, |
| 5027 | instruction->GetDexPc(), |
| 5028 | nullptr); |
| 5029 | if (zero.IsLinked()) { |
| 5030 | __ jmp(&done); |
| 5031 | } |
| 5032 | break; |
| 5033 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5034 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5035 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5036 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5037 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5038 | __ xorl(out, out); |
| 5039 | } |
| 5040 | |
| 5041 | if (done.IsLinked()) { |
| 5042 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5043 | } |
| 5044 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5045 | if (slow_path != nullptr) { |
| 5046 | __ Bind(slow_path->GetExitLabel()); |
| 5047 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5048 | } |
| 5049 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5050 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5051 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5052 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 5053 | |
| 5054 | switch (instruction->GetTypeCheckKind()) { |
| 5055 | case TypeCheckKind::kExactCheck: |
| 5056 | case TypeCheckKind::kAbstractClassCheck: |
| 5057 | case TypeCheckKind::kClassHierarchyCheck: |
| 5058 | case TypeCheckKind::kArrayObjectCheck: |
| 5059 | call_kind = throws_into_catch |
| 5060 | ? LocationSummary::kCallOnSlowPath |
| 5061 | : LocationSummary::kNoCall; |
| 5062 | break; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5063 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5064 | case TypeCheckKind::kInterfaceCheck: |
| 5065 | call_kind = LocationSummary::kCall; |
| 5066 | break; |
| 5067 | case TypeCheckKind::kArrayCheck: |
| 5068 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5069 | break; |
| 5070 | } |
| 5071 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5072 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5073 | instruction, call_kind); |
| 5074 | if (call_kind != LocationSummary::kCall) { |
| 5075 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5076 | locations->SetInAt(1, Location::Any()); |
| 5077 | // Note that TypeCheckSlowPathX86_64 uses this register too. |
| 5078 | locations->AddTemp(Location::RequiresRegister()); |
| 5079 | } else { |
| 5080 | InvokeRuntimeCallingConvention calling_convention; |
| 5081 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5082 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5083 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5084 | } |
| 5085 | |
| 5086 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
| 5087 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5088 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5089 | Location cls = locations->InAt(1); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5090 | CpuRegister temp = locations->WillCall() |
| 5091 | ? CpuRegister(kNoRegister) |
| 5092 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame] | 5093 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5094 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5095 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5096 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5097 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 5098 | SlowPathCode* slow_path = nullptr; |
| 5099 | |
| 5100 | if (!locations->WillCall()) { |
| 5101 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64( |
| 5102 | instruction, !locations->CanCall()); |
| 5103 | codegen_->AddSlowPath(slow_path); |
| 5104 | } |
| 5105 | |
| 5106 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5107 | // Avoid null check if we know obj is not null. |
| 5108 | if (instruction->MustDoNullCheck()) { |
| 5109 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5110 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5111 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5112 | |
| 5113 | if (locations->WillCall()) { |
| 5114 | __ movl(obj, Address(obj, class_offset)); |
| 5115 | __ MaybeUnpoisonHeapReference(obj); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5116 | } else { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5117 | __ movl(temp, Address(obj, class_offset)); |
| 5118 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5119 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5120 | |
| 5121 | switch (instruction->GetTypeCheckKind()) { |
| 5122 | case TypeCheckKind::kExactCheck: |
| 5123 | case TypeCheckKind::kArrayCheck: { |
| 5124 | if (cls.IsRegister()) { |
| 5125 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5126 | } else { |
| 5127 | DCHECK(cls.IsStackSlot()) << cls; |
| 5128 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5129 | } |
| 5130 | // Jump to slow path for throwing the exception or doing a |
| 5131 | // more involved array check. |
| 5132 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5133 | break; |
| 5134 | } |
| 5135 | case TypeCheckKind::kAbstractClassCheck: { |
| 5136 | // If the class is abstract, we eagerly fetch the super class of the |
| 5137 | // object to avoid doing a comparison we know will fail. |
| 5138 | NearLabel loop; |
| 5139 | __ Bind(&loop); |
| 5140 | __ movl(temp, Address(temp, super_offset)); |
| 5141 | __ MaybeUnpoisonHeapReference(temp); |
| 5142 | __ testl(temp, temp); |
| 5143 | // Jump to the slow path to throw the exception. |
| 5144 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5145 | if (cls.IsRegister()) { |
| 5146 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5147 | } else { |
| 5148 | DCHECK(cls.IsStackSlot()) << cls; |
| 5149 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5150 | } |
| 5151 | __ j(kNotEqual, &loop); |
| 5152 | break; |
| 5153 | } |
| 5154 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5155 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5156 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5157 | __ Bind(&loop); |
| 5158 | if (cls.IsRegister()) { |
| 5159 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5160 | } else { |
| 5161 | DCHECK(cls.IsStackSlot()) << cls; |
| 5162 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5163 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5164 | __ j(kEqual, &done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5165 | __ movl(temp, Address(temp, super_offset)); |
| 5166 | __ MaybeUnpoisonHeapReference(temp); |
| 5167 | __ testl(temp, temp); |
| 5168 | __ j(kNotEqual, &loop); |
| 5169 | // Jump to the slow path to throw the exception. |
| 5170 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5171 | break; |
| 5172 | } |
| 5173 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5174 | // Do an exact check. |
| 5175 | if (cls.IsRegister()) { |
| 5176 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
| 5177 | } else { |
| 5178 | DCHECK(cls.IsStackSlot()) << cls; |
| 5179 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 5180 | } |
| 5181 | __ j(kEqual, &done); |
| 5182 | // 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] | 5183 | __ movl(temp, Address(temp, component_offset)); |
| 5184 | __ MaybeUnpoisonHeapReference(temp); |
| 5185 | __ testl(temp, temp); |
| 5186 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5187 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5188 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5189 | break; |
| 5190 | } |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5191 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5192 | case TypeCheckKind::kInterfaceCheck: |
| 5193 | default: |
| 5194 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 5195 | instruction, |
| 5196 | instruction->GetDexPc(), |
| 5197 | nullptr); |
| 5198 | break; |
| 5199 | } |
| 5200 | __ Bind(&done); |
| 5201 | |
| 5202 | if (slow_path != nullptr) { |
| 5203 | __ Bind(slow_path->GetExitLabel()); |
| 5204 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5205 | } |
| 5206 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5207 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5208 | LocationSummary* locations = |
| 5209 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5210 | InvokeRuntimeCallingConvention calling_convention; |
| 5211 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5212 | } |
| 5213 | |
| 5214 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5215 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 5216 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 5217 | instruction, |
| 5218 | instruction->GetDexPc(), |
| 5219 | nullptr); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5220 | } |
| 5221 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5222 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 5223 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 5224 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 5225 | |
| 5226 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5227 | LocationSummary* locations = |
| 5228 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5229 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 5230 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 5231 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5232 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5233 | locations->SetOut(Location::SameAsFirstInput()); |
| 5234 | } |
| 5235 | |
| 5236 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 5237 | HandleBitwiseOperation(instruction); |
| 5238 | } |
| 5239 | |
| 5240 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 5241 | HandleBitwiseOperation(instruction); |
| 5242 | } |
| 5243 | |
| 5244 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 5245 | HandleBitwiseOperation(instruction); |
| 5246 | } |
| 5247 | |
| 5248 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5249 | LocationSummary* locations = instruction->GetLocations(); |
| 5250 | Location first = locations->InAt(0); |
| 5251 | Location second = locations->InAt(1); |
| 5252 | DCHECK(first.Equals(locations->Out())); |
| 5253 | |
| 5254 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 5255 | if (second.IsRegister()) { |
| 5256 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5257 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5258 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5259 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5260 | } else { |
| 5261 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5262 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5263 | } |
| 5264 | } else if (second.IsConstant()) { |
| 5265 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 5266 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5267 | __ andl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5268 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5269 | __ orl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5270 | } else { |
| 5271 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5272 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5273 | } |
| 5274 | } else { |
| 5275 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 5276 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5277 | __ andl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5278 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5279 | __ orl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5280 | } else { |
| 5281 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5282 | __ xorl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5283 | } |
| 5284 | } |
| 5285 | } else { |
| 5286 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5287 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 5288 | bool second_is_constant = false; |
| 5289 | int64_t value = 0; |
| 5290 | if (second.IsConstant()) { |
| 5291 | second_is_constant = true; |
| 5292 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5293 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5294 | bool is_int32_value = IsInt<32>(value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5295 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5296 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5297 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5298 | if (is_int32_value) { |
| 5299 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 5300 | } else { |
| 5301 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 5302 | } |
| 5303 | } else if (second.IsDoubleStackSlot()) { |
| 5304 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5305 | } else { |
| 5306 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 5307 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5308 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5309 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5310 | if (is_int32_value) { |
| 5311 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 5312 | } else { |
| 5313 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 5314 | } |
| 5315 | } else if (second.IsDoubleStackSlot()) { |
| 5316 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5317 | } else { |
| 5318 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 5319 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5320 | } else { |
| 5321 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5322 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 5323 | if (is_int32_value) { |
| 5324 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 5325 | } else { |
| 5326 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 5327 | } |
| 5328 | } else if (second.IsDoubleStackSlot()) { |
| 5329 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5330 | } else { |
| 5331 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 5332 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5333 | } |
| 5334 | } |
| 5335 | } |
| 5336 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5337 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction) { |
| 5338 | // Nothing to do, this should be removed during prepare for register allocator. |
| 5339 | UNUSED(instruction); |
| 5340 | LOG(FATAL) << "Unreachable"; |
| 5341 | } |
| 5342 | |
| 5343 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction) { |
| 5344 | // Nothing to do, this should be removed during prepare for register allocator. |
| 5345 | UNUSED(instruction); |
| 5346 | LOG(FATAL) << "Unreachable"; |
| 5347 | } |
| 5348 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5349 | void LocationsBuilderX86_64::VisitFakeString(HFakeString* instruction) { |
| 5350 | DCHECK(codegen_->IsBaseline()); |
| 5351 | LocationSummary* locations = |
| 5352 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5353 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); |
| 5354 | } |
| 5355 | |
| 5356 | void InstructionCodeGeneratorX86_64::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { |
| 5357 | DCHECK(codegen_->IsBaseline()); |
| 5358 | // Will be generated at use site. |
| 5359 | } |
| 5360 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5361 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 5362 | void LocationsBuilderX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5363 | LocationSummary* locations = |
| 5364 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 5365 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5366 | } |
| 5367 | |
| 5368 | void InstructionCodeGeneratorX86_64::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5369 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 5370 | int32_t num_entries = switch_instr->GetNumEntries(); |
| 5371 | LocationSummary* locations = switch_instr->GetLocations(); |
| 5372 | CpuRegister value_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
| 5373 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 5374 | |
| 5375 | // Create a series of compare/jumps. |
| 5376 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 5377 | for (int i = 0; i < num_entries; i++) { |
| 5378 | int32_t case_value = lower_bound + i; |
| 5379 | if (case_value == 0) { |
| 5380 | __ testl(value_reg, value_reg); |
| 5381 | } else { |
| 5382 | __ cmpl(value_reg, Immediate(case_value)); |
| 5383 | } |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 5384 | __ j(kEqual, codegen_->GetLabelOf(successors[i])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5385 | } |
| 5386 | |
| 5387 | // And the default for any other value. |
| 5388 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 5389 | __ jmp(codegen_->GetLabelOf(default_block)); |
| 5390 | } |
| 5391 | } |
| 5392 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 5393 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 5394 | if (value == 0) { |
| 5395 | __ xorl(dest, dest); |
| 5396 | } else if (value > 0 && IsInt<32>(value)) { |
| 5397 | // We can use a 32 bit move, as it will zero-extend and is one byte shorter. |
| 5398 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 5399 | } else { |
| 5400 | __ movq(dest, Immediate(value)); |
| 5401 | } |
| 5402 | } |
| 5403 | |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 5404 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 5405 | DCHECK(dest.IsDoubleStackSlot()); |
| 5406 | if (IsInt<32>(value)) { |
| 5407 | // Can move directly as an int32 constant. |
| 5408 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 5409 | Immediate(static_cast<int32_t>(value))); |
| 5410 | } else { |
| 5411 | Load64BitValue(CpuRegister(TMP), value); |
| 5412 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 5413 | } |
| 5414 | } |
| 5415 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 5416 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 5417 | // Generate the constant area if needed. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 5418 | X86_64Assembler* assembler = GetAssembler(); |
| 5419 | if (!assembler->IsConstantAreaEmpty()) { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 5420 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 5421 | // byte values. If used for vectors at a later time, this will need to be |
| 5422 | // updated to 16 bytes with the appropriate offset. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 5423 | assembler->Align(4, 0); |
| 5424 | constant_area_start_ = assembler->CodeSize(); |
| 5425 | assembler->AddConstantArea(); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 5426 | } |
| 5427 | |
| 5428 | // And finish up. |
| 5429 | CodeGenerator::Finalize(allocator); |
| 5430 | } |
| 5431 | |
| 5432 | /** |
| 5433 | * Class to handle late fixup of offsets into constant area. |
| 5434 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 5435 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 5436 | public: |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 5437 | RIPFixup(const CodeGeneratorX86_64& codegen, int offset) |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 5438 | : codegen_(codegen), offset_into_constant_area_(offset) {} |
| 5439 | |
| 5440 | private: |
| 5441 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 5442 | // Patch the correct offset for the instruction. We use the address of the |
| 5443 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 5444 | int constant_offset = codegen_.ConstantAreaStart() + offset_into_constant_area_; |
| 5445 | int relative_position = constant_offset - pos; |
| 5446 | |
| 5447 | // Patch in the right value. |
| 5448 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 5449 | } |
| 5450 | |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 5451 | const CodeGeneratorX86_64& codegen_; |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 5452 | |
| 5453 | // Location in constant area that the fixup refers to. |
| 5454 | int offset_into_constant_area_; |
| 5455 | }; |
| 5456 | |
| 5457 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
| 5458 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 5459 | return Address::RIP(fixup); |
| 5460 | } |
| 5461 | |
| 5462 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
| 5463 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 5464 | return Address::RIP(fixup); |
| 5465 | } |
| 5466 | |
| 5467 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
| 5468 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 5469 | return Address::RIP(fixup); |
| 5470 | } |
| 5471 | |
| 5472 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
| 5473 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 5474 | return Address::RIP(fixup); |
| 5475 | } |
| 5476 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5477 | // TODO: trg as memory. |
| 5478 | void CodeGeneratorX86_64::MoveFromReturnRegister(Location trg, Primitive::Type type) { |
| 5479 | if (!trg.IsValid()) { |
| 5480 | DCHECK(type == Primitive::kPrimVoid); |
| 5481 | return; |
| 5482 | } |
| 5483 | |
| 5484 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 5485 | |
| 5486 | Location return_loc = InvokeDexCallingConventionVisitorX86_64().GetReturnLocation(type); |
| 5487 | if (trg.Equals(return_loc)) { |
| 5488 | return; |
| 5489 | } |
| 5490 | |
| 5491 | // Let the parallel move resolver take care of all of this. |
| 5492 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 5493 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 5494 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 5495 | } |
| 5496 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5497 | #undef __ |
| 5498 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 5499 | } // namespace x86_64 |
| 5500 | } // namespace art |