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