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