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