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())-> |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 51 | #define QUICK_ENTRY_POINT(x) Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86_64WordSize, x), true) |
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()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 60 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), |
| 61 | instruction_, |
| 62 | instruction_->GetDexPc(), |
| 63 | this); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 64 | } |
| 65 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 66 | bool IsFatal() const OVERRIDE { return true; } |
| 67 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 68 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86_64"; } |
| 69 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 70 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 71 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 72 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86_64); |
| 73 | }; |
| 74 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 75 | class DivZeroCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
| 76 | public: |
| 77 | explicit DivZeroCheckSlowPathX86_64(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 78 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 79 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 80 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 81 | __ Bind(GetEntryLabel()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 82 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), |
| 83 | instruction_, |
| 84 | instruction_->GetDexPc(), |
| 85 | this); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 88 | bool IsFatal() const OVERRIDE { return true; } |
| 89 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 90 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86_64"; } |
| 91 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 92 | private: |
| 93 | HDivZeroCheck* const instruction_; |
| 94 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86_64); |
| 95 | }; |
| 96 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 97 | class DivRemMinusOneSlowPathX86_64 : public SlowPathCodeX86_64 { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 98 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 99 | DivRemMinusOneSlowPathX86_64(Register reg, Primitive::Type type, bool is_div) |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 100 | : cpu_reg_(CpuRegister(reg)), type_(type), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 101 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 102 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 103 | __ Bind(GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 104 | if (type_ == Primitive::kPrimInt) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 105 | if (is_div_) { |
| 106 | __ negl(cpu_reg_); |
| 107 | } else { |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 108 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 111 | } else { |
| 112 | DCHECK_EQ(Primitive::kPrimLong, type_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 113 | if (is_div_) { |
| 114 | __ negq(cpu_reg_); |
| 115 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 116 | __ xorl(cpu_reg_, cpu_reg_); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 117 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 118 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 119 | __ jmp(GetExitLabel()); |
| 120 | } |
| 121 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 122 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86_64"; } |
| 123 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 124 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 125 | const CpuRegister cpu_reg_; |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 126 | const Primitive::Type type_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 127 | const bool is_div_; |
| 128 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86_64); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 129 | }; |
| 130 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 131 | class SuspendCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 132 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 133 | SuspendCheckSlowPathX86_64(HSuspendCheck* instruction, HBasicBlock* successor) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 134 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 135 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 136 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 137 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 138 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 139 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 140 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), |
| 141 | instruction_, |
| 142 | instruction_->GetDexPc(), |
| 143 | this); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 144 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 145 | if (successor_ == nullptr) { |
| 146 | __ jmp(GetReturnLabel()); |
| 147 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 148 | __ jmp(x64_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 149 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 152 | Label* GetReturnLabel() { |
| 153 | DCHECK(successor_ == nullptr); |
| 154 | return &return_label_; |
| 155 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 156 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 157 | HBasicBlock* GetSuccessor() const { |
| 158 | return successor_; |
| 159 | } |
| 160 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 161 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86_64"; } |
| 162 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 163 | private: |
| 164 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 165 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 166 | Label return_label_; |
| 167 | |
| 168 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86_64); |
| 169 | }; |
| 170 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 171 | class BoundsCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 172 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame^] | 173 | explicit BoundsCheckSlowPathX86_64(HBoundsCheck* instruction) |
| 174 | : instruction_(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 175 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 176 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame^] | 177 | LocationSummary* locations = instruction_->GetLocations(); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 178 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 179 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 180 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 181 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 182 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 183 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame^] | 184 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 185 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 186 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame^] | 187 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 188 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 189 | Primitive::kPrimInt); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 190 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds), |
| 191 | instruction_, instruction_->GetDexPc(), this); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 192 | } |
| 193 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 194 | bool IsFatal() const OVERRIDE { return true; } |
| 195 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 196 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86_64"; } |
| 197 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 198 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 199 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 200 | |
| 201 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86_64); |
| 202 | }; |
| 203 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 204 | class LoadClassSlowPathX86_64 : public SlowPathCodeX86_64 { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 205 | public: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 206 | LoadClassSlowPathX86_64(HLoadClass* cls, |
| 207 | HInstruction* at, |
| 208 | uint32_t dex_pc, |
| 209 | bool do_clinit) |
| 210 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 211 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 212 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 213 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 214 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 215 | LocationSummary* locations = at_->GetLocations(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 216 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 217 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 218 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 219 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 220 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 221 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 222 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), Immediate(cls_->GetTypeIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 223 | x64_codegen->InvokeRuntime(do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 224 | : QUICK_ENTRY_POINT(pInitializeType), |
| 225 | at_, dex_pc_, this); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 226 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 227 | Location out = locations->Out(); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 228 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 229 | if (out.IsValid()) { |
| 230 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 231 | x64_codegen->Move(out, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 232 | } |
| 233 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 234 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 235 | __ jmp(GetExitLabel()); |
| 236 | } |
| 237 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 238 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86_64"; } |
| 239 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 240 | private: |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 241 | // The class this slow path will load. |
| 242 | HLoadClass* const cls_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 243 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 244 | // The instruction where this slow path is happening. |
| 245 | // (Might be the load class or an initialization check). |
| 246 | HInstruction* const at_; |
| 247 | |
| 248 | // The dex PC of `at_`. |
| 249 | const uint32_t dex_pc_; |
| 250 | |
| 251 | // Whether to initialize the class. |
| 252 | const bool do_clinit_; |
| 253 | |
| 254 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86_64); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 255 | }; |
| 256 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 257 | class LoadStringSlowPathX86_64 : public SlowPathCodeX86_64 { |
| 258 | public: |
| 259 | explicit LoadStringSlowPathX86_64(HLoadString* instruction) : instruction_(instruction) {} |
| 260 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 261 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 262 | LocationSummary* locations = instruction_->GetLocations(); |
| 263 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 264 | |
| 265 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 266 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 267 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 268 | |
| 269 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 270 | __ movl(CpuRegister(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 271 | Immediate(instruction_->GetStringIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 272 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), |
| 273 | instruction_, |
| 274 | instruction_->GetDexPc(), |
| 275 | this); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 276 | x64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 277 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 278 | __ jmp(GetExitLabel()); |
| 279 | } |
| 280 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 281 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86_64"; } |
| 282 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 283 | private: |
| 284 | HLoadString* const instruction_; |
| 285 | |
| 286 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86_64); |
| 287 | }; |
| 288 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 289 | class TypeCheckSlowPathX86_64 : public SlowPathCodeX86_64 { |
| 290 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame^] | 291 | explicit TypeCheckSlowPathX86_64(HInstruction* instruction) |
| 292 | : instruction_(instruction) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 293 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 294 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 295 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame^] | 296 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 297 | : locations->Out(); |
| 298 | uint32_t dex_pc = instruction_->GetDexPc(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 299 | DCHECK(instruction_->IsCheckCast() |
| 300 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 301 | |
| 302 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
| 303 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 304 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 305 | |
| 306 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 307 | // move resolver. |
| 308 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 309 | codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame^] | 310 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 311 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 312 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame^] | 313 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 314 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 315 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 316 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 317 | if (instruction_->IsInstanceOf()) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 318 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 319 | instruction_, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame^] | 320 | dex_pc, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 321 | this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 322 | } else { |
| 323 | DCHECK(instruction_->IsCheckCast()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 324 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 325 | instruction_, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame^] | 326 | dex_pc, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 327 | this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 328 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 329 | |
| 330 | if (instruction_->IsInstanceOf()) { |
| 331 | x64_codegen->Move(locations->Out(), Location::RegisterLocation(RAX)); |
| 332 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 333 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 334 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 335 | __ jmp(GetExitLabel()); |
| 336 | } |
| 337 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 338 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86_64"; } |
| 339 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 340 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 341 | HInstruction* const instruction_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 342 | |
| 343 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86_64); |
| 344 | }; |
| 345 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 346 | class DeoptimizationSlowPathX86_64 : public SlowPathCodeX86_64 { |
| 347 | public: |
| 348 | explicit DeoptimizationSlowPathX86_64(HInstruction* instruction) |
| 349 | : instruction_(instruction) {} |
| 350 | |
| 351 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 352 | CodeGeneratorX86_64* x64_codegen = down_cast<CodeGeneratorX86_64*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 353 | __ Bind(GetEntryLabel()); |
| 354 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 355 | DCHECK(instruction_->IsDeoptimize()); |
| 356 | HDeoptimize* deoptimize = instruction_->AsDeoptimize(); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 357 | x64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 358 | deoptimize, |
| 359 | deoptimize->GetDexPc(), |
| 360 | this); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 363 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86_64"; } |
| 364 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 365 | private: |
| 366 | HInstruction* const instruction_; |
| 367 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86_64); |
| 368 | }; |
| 369 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 370 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 371 | #define __ down_cast<X86_64Assembler*>(GetAssembler())-> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 372 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 373 | inline Condition X86_64IntegerCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 374 | switch (cond) { |
| 375 | case kCondEQ: return kEqual; |
| 376 | case kCondNE: return kNotEqual; |
| 377 | case kCondLT: return kLess; |
| 378 | case kCondLE: return kLessEqual; |
| 379 | case kCondGT: return kGreater; |
| 380 | case kCondGE: return kGreaterEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 381 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 382 | LOG(FATAL) << "Unreachable"; |
| 383 | UNREACHABLE(); |
| 384 | } |
| 385 | |
| 386 | inline Condition X86_64FPCondition(IfCondition cond) { |
| 387 | switch (cond) { |
| 388 | case kCondEQ: return kEqual; |
| 389 | case kCondNE: return kNotEqual; |
| 390 | case kCondLT: return kBelow; |
| 391 | case kCondLE: return kBelowEqual; |
| 392 | case kCondGT: return kAbove; |
| 393 | case kCondGE: return kAboveEqual; |
| 394 | }; |
| 395 | LOG(FATAL) << "Unreachable"; |
| 396 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 399 | void CodeGeneratorX86_64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 400 | Location temp) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 401 | // All registers are assumed to be correctly set up. |
| 402 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 403 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 404 | switch (invoke->GetMethodLoadKind()) { |
| 405 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 406 | // temp = thread->string_init_entrypoint |
| 407 | __ gs()->movl(temp.AsRegister<CpuRegister>(), |
| 408 | Address::Absolute(invoke->GetStringInitOffset(), true)); |
| 409 | break; |
| 410 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 411 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 412 | break; |
| 413 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 414 | __ movq(temp.AsRegister<CpuRegister>(), Immediate(invoke->GetMethodAddress())); |
| 415 | break; |
| 416 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 417 | __ movl(temp.AsRegister<CpuRegister>(), Immediate(0)); // Placeholder. |
| 418 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 419 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 420 | break; |
| 421 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
| 422 | pc_rel_dex_cache_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 423 | invoke->GetDexCacheArrayOffset()); |
| 424 | __ movq(temp.AsRegister<CpuRegister>(), |
| 425 | Address::Absolute(kDummy32BitOffset, false /* no_rip */)); |
| 426 | // Bind the label at the end of the "movl" insn. |
| 427 | __ Bind(&pc_rel_dex_cache_patches_.back().label); |
| 428 | break; |
| 429 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
| 430 | Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 431 | Register method_reg; |
| 432 | CpuRegister reg = temp.AsRegister<CpuRegister>(); |
| 433 | if (current_method.IsRegister()) { |
| 434 | method_reg = current_method.AsRegister<Register>(); |
| 435 | } else { |
| 436 | DCHECK(invoke->GetLocations()->Intrinsified()); |
| 437 | DCHECK(!current_method.IsValid()); |
| 438 | method_reg = reg.AsRegister(); |
| 439 | __ movq(reg, Address(CpuRegister(RSP), kCurrentMethodStackOffset)); |
| 440 | } |
| 441 | // temp = temp->dex_cache_resolved_methods_; |
| 442 | __ movl(reg, Address(CpuRegister(method_reg), |
| 443 | ArtMethod::DexCacheResolvedMethodsOffset().SizeValue())); |
| 444 | // temp = temp[index_in_cache] |
| 445 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 446 | __ movq(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 447 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 448 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | switch (invoke->GetCodePtrLocation()) { |
| 452 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 453 | __ call(&frame_entry_label_); |
| 454 | break; |
| 455 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 456 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 457 | Label* label = &relative_call_patches_.back().label; |
| 458 | __ call(label); // Bind to the patch label, override at link time. |
| 459 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 460 | break; |
| 461 | } |
| 462 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 463 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 464 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 465 | FALLTHROUGH_INTENDED; |
| 466 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 467 | // (callee_method + offset_of_quick_compiled_code)() |
| 468 | __ call(Address(callee_method.AsRegister<CpuRegister>(), |
| 469 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 470 | kX86_64WordSize).SizeValue())); |
| 471 | break; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 472 | } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 473 | |
| 474 | DCHECK(!IsLeafMethod()); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 475 | } |
| 476 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 477 | void CodeGeneratorX86_64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 478 | DCHECK(linker_patches->empty()); |
| 479 | size_t size = |
| 480 | method_patches_.size() + relative_call_patches_.size() + pc_rel_dex_cache_patches_.size(); |
| 481 | linker_patches->reserve(size); |
| 482 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
| 483 | // The label points to the end of the "movl" instruction but the literal offset for method |
| 484 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 485 | uint32_t literal_offset = info.label.Position() - 4; |
| 486 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 487 | info.target_method.dex_file, |
| 488 | info.target_method.dex_method_index)); |
| 489 | } |
| 490 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
| 491 | // The label points to the end of the "call" instruction but the literal offset for method |
| 492 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 493 | uint32_t literal_offset = info.label.Position() - 4; |
| 494 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 495 | info.target_method.dex_file, |
| 496 | info.target_method.dex_method_index)); |
| 497 | } |
| 498 | for (const PcRelativeDexCacheAccessInfo& info : pc_rel_dex_cache_patches_) { |
| 499 | // The label points to the end of the "mov" instruction but the literal offset for method |
| 500 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 501 | uint32_t literal_offset = info.label.Position() - 4; |
| 502 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 503 | &info.target_dex_file, |
| 504 | info.label.Position(), |
| 505 | info.element_offset)); |
| 506 | } |
| 507 | } |
| 508 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 509 | void CodeGeneratorX86_64::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 510 | stream << Register(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | void CodeGeneratorX86_64::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 514 | stream << FloatRegister(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 515 | } |
| 516 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 517 | size_t CodeGeneratorX86_64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 518 | __ movq(Address(CpuRegister(RSP), stack_index), CpuRegister(reg_id)); |
| 519 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 520 | } |
| 521 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 522 | size_t CodeGeneratorX86_64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 523 | __ movq(CpuRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 524 | return kX86_64WordSize; |
| 525 | } |
| 526 | |
| 527 | size_t CodeGeneratorX86_64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 528 | __ movsd(Address(CpuRegister(RSP), stack_index), XmmRegister(reg_id)); |
| 529 | return kX86_64WordSize; |
| 530 | } |
| 531 | |
| 532 | size_t CodeGeneratorX86_64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 533 | __ movsd(XmmRegister(reg_id), Address(CpuRegister(RSP), stack_index)); |
| 534 | return kX86_64WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 535 | } |
| 536 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 537 | void CodeGeneratorX86_64::InvokeRuntime(Address entry_point, |
| 538 | HInstruction* instruction, |
| 539 | uint32_t dex_pc, |
| 540 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 541 | ValidateInvokeRuntime(instruction, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 542 | __ gs()->call(entry_point); |
| 543 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 544 | } |
| 545 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 546 | static constexpr int kNumberOfCpuRegisterPairs = 0; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 547 | // Use a fake return address register to mimic Quick. |
| 548 | static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 549 | CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph, |
| 550 | const X86_64InstructionSetFeatures& isa_features, |
| 551 | const CompilerOptions& compiler_options) |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 552 | : CodeGenerator(graph, |
| 553 | kNumberOfCpuRegisters, |
| 554 | kNumberOfFloatRegisters, |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 555 | kNumberOfCpuRegisterPairs, |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 556 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 557 | arraysize(kCoreCalleeSaves)) |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 558 | | (1 << kFakeReturnRegister), |
Nicolas Geoffray | 4dee636 | 2015-01-23 18:23:14 +0000 | [diff] [blame] | 559 | ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves), |
| 560 | arraysize(kFpuCalleeSaves)), |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 561 | compiler_options), |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 562 | block_labels_(graph->GetArena(), 0), |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 563 | location_builder_(graph, this), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 564 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 565 | move_resolver_(graph->GetArena(), this), |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 566 | isa_features_(isa_features), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 567 | constant_area_start_(0), |
| 568 | method_patches_(graph->GetArena()->Adapter()), |
| 569 | relative_call_patches_(graph->GetArena()->Adapter()), |
| 570 | pc_rel_dex_cache_patches_(graph->GetArena()->Adapter()) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 571 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
| 572 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 573 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 574 | InstructionCodeGeneratorX86_64::InstructionCodeGeneratorX86_64(HGraph* graph, |
| 575 | CodeGeneratorX86_64* codegen) |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 576 | : HGraphVisitor(graph), |
| 577 | assembler_(codegen->GetAssembler()), |
| 578 | codegen_(codegen) {} |
| 579 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 580 | Location CodeGeneratorX86_64::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 581 | switch (type) { |
| 582 | case Primitive::kPrimLong: |
| 583 | case Primitive::kPrimByte: |
| 584 | case Primitive::kPrimBoolean: |
| 585 | case Primitive::kPrimChar: |
| 586 | case Primitive::kPrimShort: |
| 587 | case Primitive::kPrimInt: |
| 588 | case Primitive::kPrimNot: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 589 | size_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfCpuRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 590 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 594 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 595 | size_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfFloatRegisters); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 596 | return Location::FpuRegisterLocation(reg); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 597 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 598 | |
| 599 | case Primitive::kPrimVoid: |
| 600 | LOG(FATAL) << "Unreachable type " << type; |
| 601 | } |
| 602 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 603 | return Location(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 604 | } |
| 605 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 606 | void CodeGeneratorX86_64::SetupBlockedRegisters(bool is_baseline) const { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 607 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 608 | blocked_core_registers_[RSP] = true; |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 609 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 610 | // Block the register used as TMP. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 611 | blocked_core_registers_[TMP] = true; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 612 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 613 | if (is_baseline) { |
| 614 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 615 | blocked_core_registers_[kCoreCalleeSaves[i]] = true; |
| 616 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 617 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 618 | blocked_fpu_registers_[kFpuCalleeSaves[i]] = true; |
| 619 | } |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 620 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 621 | } |
| 622 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 623 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 624 | return dwarf::Reg::X86_64Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 625 | } |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 626 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 627 | static dwarf::Reg DWARFReg(FloatRegister reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 628 | return dwarf::Reg::X86_64Fp(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 629 | } |
| 630 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 631 | void CodeGeneratorX86_64::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 632 | __ cfi().SetCurrentCFAOffset(kX86_64WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 633 | __ Bind(&frame_entry_label_); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 634 | bool skip_overflow_check = IsLeafMethod() |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 635 | && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86_64); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 636 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 637 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 638 | if (!skip_overflow_check) { |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 639 | __ testq(CpuRegister(RAX), Address( |
| 640 | CpuRegister(RSP), -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86_64)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 641 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 642 | } |
Nicolas Geoffray | a26369a | 2015-01-22 08:46:05 +0000 | [diff] [blame] | 643 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 644 | if (HasEmptyFrame()) { |
| 645 | return; |
| 646 | } |
| 647 | |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 648 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 649 | Register reg = kCoreCalleeSaves[i]; |
Nicolas Geoffray | 4597b5b | 2015-01-23 21:51:55 +0000 | [diff] [blame] | 650 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 651 | __ pushq(CpuRegister(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 652 | __ cfi().AdjustCFAOffset(kX86_64WordSize); |
| 653 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Nicolas Geoffray | 9889396 | 2015-01-21 12:32:32 +0000 | [diff] [blame] | 654 | } |
| 655 | } |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 656 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 657 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 658 | __ subq(CpuRegister(RSP), Immediate(adjust)); |
| 659 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 660 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 661 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 662 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 663 | for (int i = arraysize(kFpuCalleeSaves) - 1; i >= 0; --i) { |
| 664 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 665 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 666 | __ movsd(Address(CpuRegister(RSP), offset), XmmRegister(kFpuCalleeSaves[i])); |
| 667 | __ cfi().RelOffset(DWARFReg(kFpuCalleeSaves[i]), offset); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 668 | } |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 669 | } |
| 670 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 671 | __ movq(Address(CpuRegister(RSP), kCurrentMethodStackOffset), |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 672 | CpuRegister(kMethodRegisterArgument)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | void CodeGeneratorX86_64::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 676 | __ cfi().RememberState(); |
| 677 | if (!HasEmptyFrame()) { |
| 678 | uint32_t xmm_spill_location = GetFpuSpillStart(); |
| 679 | size_t xmm_spill_slot_size = GetFloatingPointSpillSlotSize(); |
| 680 | for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) { |
| 681 | if (allocated_registers_.ContainsFloatingPointRegister(kFpuCalleeSaves[i])) { |
| 682 | int offset = xmm_spill_location + (xmm_spill_slot_size * i); |
| 683 | __ movsd(XmmRegister(kFpuCalleeSaves[i]), Address(CpuRegister(RSP), offset)); |
| 684 | __ cfi().Restore(DWARFReg(kFpuCalleeSaves[i])); |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | int adjust = GetFrameSize() - GetCoreSpillSize(); |
| 689 | __ addq(CpuRegister(RSP), Immediate(adjust)); |
| 690 | __ cfi().AdjustCFAOffset(-adjust); |
| 691 | |
| 692 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 693 | Register reg = kCoreCalleeSaves[i]; |
| 694 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 695 | __ popq(CpuRegister(reg)); |
| 696 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86_64WordSize)); |
| 697 | __ cfi().Restore(DWARFReg(reg)); |
| 698 | } |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 699 | } |
| 700 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 701 | __ ret(); |
| 702 | __ cfi().RestoreState(); |
| 703 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 704 | } |
| 705 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 706 | void CodeGeneratorX86_64::Bind(HBasicBlock* block) { |
| 707 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 708 | } |
| 709 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 710 | Location CodeGeneratorX86_64::GetStackLocation(HLoadLocal* load) const { |
| 711 | switch (load->GetType()) { |
| 712 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 713 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 714 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 715 | |
| 716 | case Primitive::kPrimInt: |
| 717 | case Primitive::kPrimNot: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 718 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 719 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 720 | |
| 721 | case Primitive::kPrimBoolean: |
| 722 | case Primitive::kPrimByte: |
| 723 | case Primitive::kPrimChar: |
| 724 | case Primitive::kPrimShort: |
| 725 | case Primitive::kPrimVoid: |
| 726 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 727 | UNREACHABLE(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 731 | UNREACHABLE(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | void CodeGeneratorX86_64::Move(Location destination, Location source) { |
| 735 | if (source.Equals(destination)) { |
| 736 | return; |
| 737 | } |
| 738 | if (destination.IsRegister()) { |
| 739 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 740 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 741 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 742 | __ movd(destination.AsRegister<CpuRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 743 | } else if (source.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 744 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 745 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 746 | } else { |
| 747 | DCHECK(source.IsDoubleStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 748 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 749 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 750 | } |
| 751 | } else if (destination.IsFpuRegister()) { |
| 752 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 753 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 754 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 755 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 756 | } else if (source.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 757 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 758 | Address(CpuRegister(RSP), source.GetStackIndex())); |
| 759 | } else { |
| 760 | DCHECK(source.IsDoubleStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 761 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 762 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 763 | } |
| 764 | } else if (destination.IsStackSlot()) { |
| 765 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 766 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 767 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 768 | } else if (source.IsFpuRegister()) { |
| 769 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 770 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 771 | } else if (source.IsConstant()) { |
| 772 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 773 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 774 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 775 | } else { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 776 | DCHECK(source.IsStackSlot()) << source; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 777 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 778 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 779 | } |
| 780 | } else { |
| 781 | DCHECK(destination.IsDoubleStackSlot()); |
| 782 | if (source.IsRegister()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 783 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 784 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 785 | } else if (source.IsFpuRegister()) { |
| 786 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 787 | source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 788 | } else if (source.IsConstant()) { |
| 789 | HConstant* constant = source.GetConstant(); |
Zheng Xu | 12bca97 | 2015-03-30 19:35:50 +0800 | [diff] [blame] | 790 | int64_t value; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 791 | if (constant->IsDoubleConstant()) { |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 792 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 793 | } else { |
| 794 | DCHECK(constant->IsLongConstant()); |
| 795 | value = constant->AsLongConstant()->GetValue(); |
| 796 | } |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 797 | Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 798 | } else { |
| 799 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 800 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 801 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 802 | } |
| 803 | } |
| 804 | } |
| 805 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 806 | void CodeGeneratorX86_64::Move(HInstruction* instruction, |
| 807 | Location location, |
| 808 | HInstruction* move_for) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 809 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 810 | if (instruction->IsCurrentMethod()) { |
Mathieu Chartier | e3b034a | 2015-05-31 14:29:23 -0700 | [diff] [blame] | 811 | Move(location, Location::DoubleStackSlot(kCurrentMethodStackOffset)); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 812 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 813 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 814 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 815 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 816 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 817 | Immediate imm(GetInt32ValueOf(const_to_move)); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 818 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 819 | __ movl(location.AsRegister<CpuRegister>(), imm); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 820 | } else if (location.IsStackSlot()) { |
| 821 | __ movl(Address(CpuRegister(RSP), location.GetStackIndex()), imm); |
| 822 | } else { |
| 823 | DCHECK(location.IsConstant()); |
| 824 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 825 | } |
| 826 | } else if (const_to_move->IsLongConstant()) { |
| 827 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 828 | if (location.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 829 | Load64BitValue(location.AsRegister<CpuRegister>(), value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 830 | } else if (location.IsDoubleStackSlot()) { |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 831 | Store64BitValueToStack(location, value); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 832 | } else { |
| 833 | DCHECK(location.IsConstant()); |
| 834 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 835 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 836 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 837 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 838 | switch (instruction->GetType()) { |
| 839 | case Primitive::kPrimBoolean: |
| 840 | case Primitive::kPrimByte: |
| 841 | case Primitive::kPrimChar: |
| 842 | case Primitive::kPrimShort: |
| 843 | case Primitive::kPrimInt: |
| 844 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 845 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 846 | Move(location, Location::StackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
| 847 | break; |
| 848 | |
| 849 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 850 | case Primitive::kPrimDouble: |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 851 | Move(location, |
| 852 | Location::DoubleStackSlot(GetStackSlot(instruction->AsLoadLocal()->GetLocal()))); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 853 | break; |
| 854 | |
| 855 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 856 | LOG(FATAL) << "Unexpected local type " << instruction->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 857 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 858 | } else if (instruction->IsTemporary()) { |
| 859 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
| 860 | Move(location, temp_location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 861 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 862 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 863 | switch (instruction->GetType()) { |
| 864 | case Primitive::kPrimBoolean: |
| 865 | case Primitive::kPrimByte: |
| 866 | case Primitive::kPrimChar: |
| 867 | case Primitive::kPrimShort: |
| 868 | case Primitive::kPrimInt: |
| 869 | case Primitive::kPrimNot: |
| 870 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 871 | case Primitive::kPrimFloat: |
| 872 | case Primitive::kPrimDouble: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 873 | Move(location, locations->Out()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 874 | break; |
| 875 | |
| 876 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 877 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 878 | } |
| 879 | } |
| 880 | } |
| 881 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 882 | void InstructionCodeGeneratorX86_64::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 883 | DCHECK(!successor->IsExitBlock()); |
| 884 | |
| 885 | HBasicBlock* block = got->GetBlock(); |
| 886 | HInstruction* previous = got->GetPrevious(); |
| 887 | |
| 888 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 889 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 890 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 891 | return; |
| 892 | } |
| 893 | |
| 894 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 895 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 896 | } |
| 897 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 898 | __ jmp(codegen_->GetLabelOf(successor)); |
| 899 | } |
| 900 | } |
| 901 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 902 | void LocationsBuilderX86_64::VisitGoto(HGoto* got) { |
| 903 | got->SetLocations(nullptr); |
| 904 | } |
| 905 | |
| 906 | void InstructionCodeGeneratorX86_64::VisitGoto(HGoto* got) { |
| 907 | HandleGoto(got, got->GetSuccessor()); |
| 908 | } |
| 909 | |
| 910 | void LocationsBuilderX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 911 | try_boundary->SetLocations(nullptr); |
| 912 | } |
| 913 | |
| 914 | void InstructionCodeGeneratorX86_64::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 915 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 916 | if (!successor->IsExitBlock()) { |
| 917 | HandleGoto(try_boundary, successor); |
| 918 | } |
| 919 | } |
| 920 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 921 | void LocationsBuilderX86_64::VisitExit(HExit* exit) { |
| 922 | exit->SetLocations(nullptr); |
| 923 | } |
| 924 | |
| 925 | void InstructionCodeGeneratorX86_64::VisitExit(HExit* exit) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 926 | UNUSED(exit); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 927 | } |
| 928 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 929 | void InstructionCodeGeneratorX86_64::GenerateFPJumps(HCondition* cond, |
| 930 | Label* true_label, |
| 931 | Label* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 932 | if (cond->IsFPConditionTrueIfNaN()) { |
| 933 | __ j(kUnordered, true_label); |
| 934 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 935 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 936 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 937 | __ j(X86_64FPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | void InstructionCodeGeneratorX86_64::GenerateCompareTestAndBranch(HIf* if_instr, |
| 941 | HCondition* condition, |
| 942 | Label* true_target, |
| 943 | Label* false_target, |
| 944 | Label* always_true_target) { |
| 945 | LocationSummary* locations = condition->GetLocations(); |
| 946 | Location left = locations->InAt(0); |
| 947 | Location right = locations->InAt(1); |
| 948 | |
| 949 | // We don't want true_target as a nullptr. |
| 950 | if (true_target == nullptr) { |
| 951 | true_target = always_true_target; |
| 952 | } |
| 953 | bool falls_through = (false_target == nullptr); |
| 954 | |
| 955 | // FP compares don't like null false_targets. |
| 956 | if (false_target == nullptr) { |
| 957 | false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 958 | } |
| 959 | |
| 960 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 961 | switch (type) { |
| 962 | case Primitive::kPrimLong: { |
| 963 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 964 | if (right.IsConstant()) { |
| 965 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
| 966 | if (IsInt<32>(value)) { |
| 967 | if (value == 0) { |
| 968 | __ testq(left_reg, left_reg); |
| 969 | } else { |
| 970 | __ cmpq(left_reg, Immediate(static_cast<int32_t>(value))); |
| 971 | } |
| 972 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 973 | // Value won't fit in a 32-bit integer. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 974 | __ cmpq(left_reg, codegen_->LiteralInt64Address(value)); |
| 975 | } |
| 976 | } else if (right.IsDoubleStackSlot()) { |
| 977 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 978 | } else { |
| 979 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 980 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 981 | __ j(X86_64IntegerCondition(condition->GetCondition()), true_target); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 982 | break; |
| 983 | } |
| 984 | case Primitive::kPrimFloat: { |
| 985 | if (right.IsFpuRegister()) { |
| 986 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 987 | } else if (right.IsConstant()) { |
| 988 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 989 | codegen_->LiteralFloatAddress( |
| 990 | right.GetConstant()->AsFloatConstant()->GetValue())); |
| 991 | } else { |
| 992 | DCHECK(right.IsStackSlot()); |
| 993 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), |
| 994 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 995 | } |
| 996 | GenerateFPJumps(condition, true_target, false_target); |
| 997 | break; |
| 998 | } |
| 999 | case Primitive::kPrimDouble: { |
| 1000 | if (right.IsFpuRegister()) { |
| 1001 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1002 | } else if (right.IsConstant()) { |
| 1003 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1004 | codegen_->LiteralDoubleAddress( |
| 1005 | right.GetConstant()->AsDoubleConstant()->GetValue())); |
| 1006 | } else { |
| 1007 | DCHECK(right.IsDoubleStackSlot()); |
| 1008 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), |
| 1009 | Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1010 | } |
| 1011 | GenerateFPJumps(condition, true_target, false_target); |
| 1012 | break; |
| 1013 | } |
| 1014 | default: |
| 1015 | LOG(FATAL) << "Unexpected condition type " << type; |
| 1016 | } |
| 1017 | |
| 1018 | if (!falls_through) { |
| 1019 | __ jmp(false_target); |
| 1020 | } |
| 1021 | } |
| 1022 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1023 | void InstructionCodeGeneratorX86_64::GenerateTestAndBranch(HInstruction* instruction, |
| 1024 | Label* true_target, |
| 1025 | Label* false_target, |
| 1026 | Label* always_true_target) { |
| 1027 | HInstruction* cond = instruction->InputAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1028 | if (cond->IsIntConstant()) { |
| 1029 | // Constant condition, statically compared against 1. |
| 1030 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 1031 | if (cond_value == 1) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1032 | if (always_true_target != nullptr) { |
| 1033 | __ jmp(always_true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1034 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1035 | return; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1036 | } else { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1037 | DCHECK_EQ(cond_value, 0); |
| 1038 | } |
| 1039 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1040 | bool is_materialized = |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1041 | !cond->IsCondition() || cond->AsCondition()->NeedsMaterialization(); |
| 1042 | // Moves do not affect the eflags register, so if the condition is |
| 1043 | // evaluated just before the if, we don't need to evaluate it |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1044 | // again. We can't use the eflags on FP conditions if they are |
| 1045 | // materialized due to the complex branching. |
| 1046 | Primitive::Type type = cond->IsCondition() ? cond->InputAt(0)->GetType() : Primitive::kPrimInt; |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1047 | bool eflags_set = cond->IsCondition() |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1048 | && cond->AsCondition()->IsBeforeWhenDisregardMoves(instruction) |
| 1049 | && !Primitive::IsFloatingPointType(type); |
| 1050 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1051 | if (is_materialized) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1052 | if (!eflags_set) { |
| 1053 | // Materialized condition, compare against 0. |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1054 | Location lhs = instruction->GetLocations()->InAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1055 | if (lhs.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 1056 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1057 | } else { |
| 1058 | __ cmpl(Address(CpuRegister(RSP), lhs.GetStackIndex()), |
| 1059 | Immediate(0)); |
| 1060 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1061 | __ j(kNotEqual, true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1062 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1063 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1064 | } |
| 1065 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1066 | // Condition has not been materialized, use its inputs as the |
| 1067 | // comparison and its condition as the branch condition. |
| 1068 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1069 | // Is this a long or FP comparison that has been folded into the HCondition? |
| 1070 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1071 | // Generate the comparison directly. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1072 | GenerateCompareTestAndBranch(instruction->AsIf(), cond->AsCondition(), |
| 1073 | true_target, false_target, always_true_target); |
| 1074 | return; |
| 1075 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1076 | |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1077 | Location lhs = cond->GetLocations()->InAt(0); |
| 1078 | Location rhs = cond->GetLocations()->InAt(1); |
| 1079 | if (rhs.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1080 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1081 | } else if (rhs.IsConstant()) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1082 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 1083 | if (constant == 0) { |
| 1084 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1085 | } else { |
| 1086 | __ cmpl(lhs.AsRegister<CpuRegister>(), Immediate(constant)); |
| 1087 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1088 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1089 | __ cmpl(lhs.AsRegister<CpuRegister>(), |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1090 | Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1091 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1092 | __ j(X86_64IntegerCondition(cond->AsCondition()->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1093 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1094 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1095 | if (false_target != nullptr) { |
| 1096 | __ jmp(false_target); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1097 | } |
| 1098 | } |
| 1099 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1100 | void LocationsBuilderX86_64::VisitIf(HIf* if_instr) { |
| 1101 | LocationSummary* locations = |
| 1102 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
| 1103 | HInstruction* cond = if_instr->InputAt(0); |
| 1104 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 1105 | locations->SetInAt(0, Location::Any()); |
| 1106 | } |
| 1107 | } |
| 1108 | |
| 1109 | void InstructionCodeGeneratorX86_64::VisitIf(HIf* if_instr) { |
| 1110 | Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor()); |
| 1111 | Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1112 | Label* always_true_target = true_target; |
| 1113 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1114 | if_instr->IfTrueSuccessor())) { |
| 1115 | always_true_target = nullptr; |
| 1116 | } |
| 1117 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1118 | if_instr->IfFalseSuccessor())) { |
| 1119 | false_target = nullptr; |
| 1120 | } |
| 1121 | GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target); |
| 1122 | } |
| 1123 | |
| 1124 | void LocationsBuilderX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1125 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1126 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| 1127 | HInstruction* cond = deoptimize->InputAt(0); |
| 1128 | DCHECK(cond->IsCondition()); |
| 1129 | if (cond->AsCondition()->NeedsMaterialization()) { |
| 1130 | locations->SetInAt(0, Location::Any()); |
| 1131 | } |
| 1132 | } |
| 1133 | |
| 1134 | void InstructionCodeGeneratorX86_64::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1135 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) |
| 1136 | DeoptimizationSlowPathX86_64(deoptimize); |
| 1137 | codegen_->AddSlowPath(slow_path); |
| 1138 | Label* slow_path_entry = slow_path->GetEntryLabel(); |
| 1139 | GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry); |
| 1140 | } |
| 1141 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1142 | void LocationsBuilderX86_64::VisitLocal(HLocal* local) { |
| 1143 | local->SetLocations(nullptr); |
| 1144 | } |
| 1145 | |
| 1146 | void InstructionCodeGeneratorX86_64::VisitLocal(HLocal* local) { |
| 1147 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
| 1148 | } |
| 1149 | |
| 1150 | void LocationsBuilderX86_64::VisitLoadLocal(HLoadLocal* local) { |
| 1151 | local->SetLocations(nullptr); |
| 1152 | } |
| 1153 | |
| 1154 | void InstructionCodeGeneratorX86_64::VisitLoadLocal(HLoadLocal* load) { |
| 1155 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1156 | UNUSED(load); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | void LocationsBuilderX86_64::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1160 | LocationSummary* locations = |
| 1161 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1162 | switch (store->InputAt(1)->GetType()) { |
| 1163 | case Primitive::kPrimBoolean: |
| 1164 | case Primitive::kPrimByte: |
| 1165 | case Primitive::kPrimChar: |
| 1166 | case Primitive::kPrimShort: |
| 1167 | case Primitive::kPrimInt: |
| 1168 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1169 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1170 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1171 | break; |
| 1172 | |
| 1173 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1174 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1175 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1176 | break; |
| 1177 | |
| 1178 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1179 | LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1180 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | void InstructionCodeGeneratorX86_64::VisitStoreLocal(HStoreLocal* store) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1184 | UNUSED(store); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1185 | } |
| 1186 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1187 | void LocationsBuilderX86_64::VisitCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1188 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1189 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1190 | // Handle the long/FP comparisons made in instruction simplification. |
| 1191 | switch (cond->InputAt(0)->GetType()) { |
| 1192 | case Primitive::kPrimLong: |
| 1193 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1194 | locations->SetInAt(1, Location::Any()); |
| 1195 | break; |
| 1196 | case Primitive::kPrimFloat: |
| 1197 | case Primitive::kPrimDouble: |
| 1198 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1199 | locations->SetInAt(1, Location::Any()); |
| 1200 | break; |
| 1201 | default: |
| 1202 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1203 | locations->SetInAt(1, Location::Any()); |
| 1204 | break; |
| 1205 | } |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1206 | if (cond->NeedsMaterialization()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1207 | locations->SetOut(Location::RequiresRegister()); |
| 1208 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1209 | } |
| 1210 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1211 | void InstructionCodeGeneratorX86_64::VisitCondition(HCondition* cond) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1212 | if (!cond->NeedsMaterialization()) { |
| 1213 | return; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1214 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1215 | |
| 1216 | LocationSummary* locations = cond->GetLocations(); |
| 1217 | Location lhs = locations->InAt(0); |
| 1218 | Location rhs = locations->InAt(1); |
| 1219 | CpuRegister reg = locations->Out().AsRegister<CpuRegister>(); |
| 1220 | Label true_label, false_label; |
| 1221 | |
| 1222 | switch (cond->InputAt(0)->GetType()) { |
| 1223 | default: |
| 1224 | // Integer case. |
| 1225 | |
| 1226 | // Clear output register: setcc only sets the low byte. |
| 1227 | __ xorl(reg, reg); |
| 1228 | |
| 1229 | if (rhs.IsRegister()) { |
| 1230 | __ cmpl(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1231 | } else if (rhs.IsConstant()) { |
| 1232 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1233 | if (constant == 0) { |
| 1234 | __ testl(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1235 | } else { |
| 1236 | __ cmpl(lhs.AsRegister<CpuRegister>(), Immediate(constant)); |
| 1237 | } |
| 1238 | } else { |
| 1239 | __ cmpl(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1240 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1241 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1242 | return; |
| 1243 | case Primitive::kPrimLong: |
| 1244 | // Clear output register: setcc only sets the low byte. |
| 1245 | __ xorl(reg, reg); |
| 1246 | |
| 1247 | if (rhs.IsRegister()) { |
| 1248 | __ cmpq(lhs.AsRegister<CpuRegister>(), rhs.AsRegister<CpuRegister>()); |
| 1249 | } else if (rhs.IsConstant()) { |
| 1250 | int64_t value = rhs.GetConstant()->AsLongConstant()->GetValue(); |
| 1251 | if (IsInt<32>(value)) { |
| 1252 | if (value == 0) { |
| 1253 | __ testq(lhs.AsRegister<CpuRegister>(), lhs.AsRegister<CpuRegister>()); |
| 1254 | } else { |
| 1255 | __ cmpq(lhs.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 1256 | } |
| 1257 | } else { |
| 1258 | // Value won't fit in an int. |
| 1259 | __ cmpq(lhs.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 1260 | } |
| 1261 | } else { |
| 1262 | __ cmpq(lhs.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1263 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1264 | __ setcc(X86_64IntegerCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1265 | return; |
| 1266 | case Primitive::kPrimFloat: { |
| 1267 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1268 | if (rhs.IsConstant()) { |
| 1269 | float value = rhs.GetConstant()->AsFloatConstant()->GetValue(); |
| 1270 | __ ucomiss(lhs_reg, codegen_->LiteralFloatAddress(value)); |
| 1271 | } else if (rhs.IsStackSlot()) { |
| 1272 | __ ucomiss(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1273 | } else { |
| 1274 | __ ucomiss(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1275 | } |
| 1276 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1277 | break; |
| 1278 | } |
| 1279 | case Primitive::kPrimDouble: { |
| 1280 | XmmRegister lhs_reg = lhs.AsFpuRegister<XmmRegister>(); |
| 1281 | if (rhs.IsConstant()) { |
| 1282 | double value = rhs.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1283 | __ ucomisd(lhs_reg, codegen_->LiteralDoubleAddress(value)); |
| 1284 | } else if (rhs.IsDoubleStackSlot()) { |
| 1285 | __ ucomisd(lhs_reg, Address(CpuRegister(RSP), rhs.GetStackIndex())); |
| 1286 | } else { |
| 1287 | __ ucomisd(lhs_reg, rhs.AsFpuRegister<XmmRegister>()); |
| 1288 | } |
| 1289 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1290 | break; |
| 1291 | } |
| 1292 | } |
| 1293 | |
| 1294 | // Convert the jumps into the result. |
| 1295 | Label done_label; |
| 1296 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1297 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1298 | __ Bind(&false_label); |
| 1299 | __ xorl(reg, reg); |
| 1300 | __ jmp(&done_label); |
| 1301 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1302 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1303 | __ Bind(&true_label); |
| 1304 | __ movl(reg, Immediate(1)); |
| 1305 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | void LocationsBuilderX86_64::VisitEqual(HEqual* comp) { |
| 1309 | VisitCondition(comp); |
| 1310 | } |
| 1311 | |
| 1312 | void InstructionCodeGeneratorX86_64::VisitEqual(HEqual* comp) { |
| 1313 | VisitCondition(comp); |
| 1314 | } |
| 1315 | |
| 1316 | void LocationsBuilderX86_64::VisitNotEqual(HNotEqual* comp) { |
| 1317 | VisitCondition(comp); |
| 1318 | } |
| 1319 | |
| 1320 | void InstructionCodeGeneratorX86_64::VisitNotEqual(HNotEqual* comp) { |
| 1321 | VisitCondition(comp); |
| 1322 | } |
| 1323 | |
| 1324 | void LocationsBuilderX86_64::VisitLessThan(HLessThan* comp) { |
| 1325 | VisitCondition(comp); |
| 1326 | } |
| 1327 | |
| 1328 | void InstructionCodeGeneratorX86_64::VisitLessThan(HLessThan* comp) { |
| 1329 | VisitCondition(comp); |
| 1330 | } |
| 1331 | |
| 1332 | void LocationsBuilderX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1333 | VisitCondition(comp); |
| 1334 | } |
| 1335 | |
| 1336 | void InstructionCodeGeneratorX86_64::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1337 | VisitCondition(comp); |
| 1338 | } |
| 1339 | |
| 1340 | void LocationsBuilderX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| 1341 | VisitCondition(comp); |
| 1342 | } |
| 1343 | |
| 1344 | void InstructionCodeGeneratorX86_64::VisitGreaterThan(HGreaterThan* comp) { |
| 1345 | VisitCondition(comp); |
| 1346 | } |
| 1347 | |
| 1348 | void LocationsBuilderX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1349 | VisitCondition(comp); |
| 1350 | } |
| 1351 | |
| 1352 | void InstructionCodeGeneratorX86_64::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1353 | VisitCondition(comp); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1354 | } |
| 1355 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1356 | void LocationsBuilderX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1357 | LocationSummary* locations = |
| 1358 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1359 | switch (compare->InputAt(0)->GetType()) { |
| 1360 | case Primitive::kPrimLong: { |
| 1361 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1362 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1363 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1364 | break; |
| 1365 | } |
| 1366 | case Primitive::kPrimFloat: |
| 1367 | case Primitive::kPrimDouble: { |
| 1368 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1369 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1370 | locations->SetOut(Location::RequiresRegister()); |
| 1371 | break; |
| 1372 | } |
| 1373 | default: |
| 1374 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 1375 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1376 | } |
| 1377 | |
| 1378 | void InstructionCodeGeneratorX86_64::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1379 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1380 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1381 | Location left = locations->InAt(0); |
| 1382 | Location right = locations->InAt(1); |
| 1383 | |
| 1384 | Label less, greater, done; |
| 1385 | Primitive::Type type = compare->InputAt(0)->GetType(); |
| 1386 | switch (type) { |
| 1387 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1388 | CpuRegister left_reg = left.AsRegister<CpuRegister>(); |
| 1389 | if (right.IsConstant()) { |
| 1390 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1391 | if (IsInt<32>(value)) { |
| 1392 | if (value == 0) { |
| 1393 | __ testq(left_reg, left_reg); |
| 1394 | } else { |
| 1395 | __ cmpq(left_reg, Immediate(static_cast<int32_t>(value))); |
| 1396 | } |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1397 | } else { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1398 | // Value won't fit in an int. |
| 1399 | __ cmpq(left_reg, codegen_->LiteralInt64Address(value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1400 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1401 | } else if (right.IsDoubleStackSlot()) { |
| 1402 | __ cmpq(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 1403 | } else { |
| 1404 | __ cmpq(left_reg, right.AsRegister<CpuRegister>()); |
| 1405 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1406 | break; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1407 | } |
| 1408 | case Primitive::kPrimFloat: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1409 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1410 | if (right.IsConstant()) { |
| 1411 | float value = right.GetConstant()->AsFloatConstant()->GetValue(); |
| 1412 | __ ucomiss(left_reg, codegen_->LiteralFloatAddress(value)); |
| 1413 | } else if (right.IsStackSlot()) { |
| 1414 | __ ucomiss(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1415 | } else { |
| 1416 | __ ucomiss(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1417 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1418 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 1419 | break; |
| 1420 | } |
| 1421 | case Primitive::kPrimDouble: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1422 | XmmRegister left_reg = left.AsFpuRegister<XmmRegister>(); |
| 1423 | if (right.IsConstant()) { |
| 1424 | double value = right.GetConstant()->AsDoubleConstant()->GetValue(); |
| 1425 | __ ucomisd(left_reg, codegen_->LiteralDoubleAddress(value)); |
| 1426 | } else if (right.IsDoubleStackSlot()) { |
| 1427 | __ ucomisd(left_reg, Address(CpuRegister(RSP), right.GetStackIndex())); |
| 1428 | } else { |
| 1429 | __ ucomisd(left_reg, right.AsFpuRegister<XmmRegister>()); |
| 1430 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1431 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 1432 | break; |
| 1433 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1434 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1435 | LOG(FATAL) << "Unexpected compare type " << type; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1436 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1437 | __ movl(out, Immediate(0)); |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1438 | __ j(kEqual, &done); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1439 | __ 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] | 1440 | |
Calin Juravle | 91debbc | 2014-11-26 19:01:09 +0000 | [diff] [blame] | 1441 | __ Bind(&greater); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1442 | __ movl(out, Immediate(1)); |
| 1443 | __ jmp(&done); |
| 1444 | |
| 1445 | __ Bind(&less); |
| 1446 | __ movl(out, Immediate(-1)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1447 | |
| 1448 | __ Bind(&done); |
| 1449 | } |
| 1450 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1451 | void LocationsBuilderX86_64::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1452 | LocationSummary* locations = |
| 1453 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1454 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1455 | } |
| 1456 | |
| 1457 | void InstructionCodeGeneratorX86_64::VisitIntConstant(HIntConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1458 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1459 | UNUSED(constant); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1460 | } |
| 1461 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1462 | void LocationsBuilderX86_64::VisitNullConstant(HNullConstant* constant) { |
| 1463 | LocationSummary* locations = |
| 1464 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1465 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1466 | } |
| 1467 | |
| 1468 | void InstructionCodeGeneratorX86_64::VisitNullConstant(HNullConstant* constant) { |
| 1469 | // Will be generated at use site. |
| 1470 | UNUSED(constant); |
| 1471 | } |
| 1472 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1473 | void LocationsBuilderX86_64::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1474 | LocationSummary* locations = |
| 1475 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1476 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | void InstructionCodeGeneratorX86_64::VisitLongConstant(HLongConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1480 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1481 | UNUSED(constant); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1482 | } |
| 1483 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1484 | void LocationsBuilderX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 1485 | LocationSummary* locations = |
| 1486 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1487 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1488 | } |
| 1489 | |
| 1490 | void InstructionCodeGeneratorX86_64::VisitFloatConstant(HFloatConstant* constant) { |
| 1491 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1492 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1493 | } |
| 1494 | |
| 1495 | void LocationsBuilderX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1496 | LocationSummary* locations = |
| 1497 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1498 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1499 | } |
| 1500 | |
| 1501 | void InstructionCodeGeneratorX86_64::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1502 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1503 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1504 | } |
| 1505 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1506 | void LocationsBuilderX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1507 | memory_barrier->SetLocations(nullptr); |
| 1508 | } |
| 1509 | |
| 1510 | void InstructionCodeGeneratorX86_64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1511 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 1512 | } |
| 1513 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1514 | void LocationsBuilderX86_64::VisitReturnVoid(HReturnVoid* ret) { |
| 1515 | ret->SetLocations(nullptr); |
| 1516 | } |
| 1517 | |
| 1518 | void InstructionCodeGeneratorX86_64::VisitReturnVoid(HReturnVoid* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1519 | UNUSED(ret); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1520 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1521 | } |
| 1522 | |
| 1523 | void LocationsBuilderX86_64::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1524 | LocationSummary* locations = |
| 1525 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1526 | switch (ret->InputAt(0)->GetType()) { |
| 1527 | case Primitive::kPrimBoolean: |
| 1528 | case Primitive::kPrimByte: |
| 1529 | case Primitive::kPrimChar: |
| 1530 | case Primitive::kPrimShort: |
| 1531 | case Primitive::kPrimInt: |
| 1532 | case Primitive::kPrimNot: |
| 1533 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1534 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1535 | break; |
| 1536 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1537 | case Primitive::kPrimFloat: |
| 1538 | case Primitive::kPrimDouble: |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1539 | locations->SetInAt(0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1540 | break; |
| 1541 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1542 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1543 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1544 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | void InstructionCodeGeneratorX86_64::VisitReturn(HReturn* ret) { |
| 1548 | if (kIsDebugBuild) { |
| 1549 | switch (ret->InputAt(0)->GetType()) { |
| 1550 | case Primitive::kPrimBoolean: |
| 1551 | case Primitive::kPrimByte: |
| 1552 | case Primitive::kPrimChar: |
| 1553 | case Primitive::kPrimShort: |
| 1554 | case Primitive::kPrimInt: |
| 1555 | case Primitive::kPrimNot: |
| 1556 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1557 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<CpuRegister>().AsRegister(), RAX); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1558 | break; |
| 1559 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1560 | case Primitive::kPrimFloat: |
| 1561 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1562 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>().AsFloatRegister(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1563 | XMM0); |
| 1564 | break; |
| 1565 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1566 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1567 | LOG(FATAL) << "Unexpected return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1568 | } |
| 1569 | } |
| 1570 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1571 | } |
| 1572 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1573 | Location InvokeDexCallingConventionVisitorX86_64::GetReturnLocation(Primitive::Type type) const { |
| 1574 | switch (type) { |
| 1575 | case Primitive::kPrimBoolean: |
| 1576 | case Primitive::kPrimByte: |
| 1577 | case Primitive::kPrimChar: |
| 1578 | case Primitive::kPrimShort: |
| 1579 | case Primitive::kPrimInt: |
| 1580 | case Primitive::kPrimNot: |
| 1581 | case Primitive::kPrimLong: |
| 1582 | return Location::RegisterLocation(RAX); |
| 1583 | |
| 1584 | case Primitive::kPrimVoid: |
| 1585 | return Location::NoLocation(); |
| 1586 | |
| 1587 | case Primitive::kPrimDouble: |
| 1588 | case Primitive::kPrimFloat: |
| 1589 | return Location::FpuRegisterLocation(XMM0); |
| 1590 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1591 | |
| 1592 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1593 | } |
| 1594 | |
| 1595 | Location InvokeDexCallingConventionVisitorX86_64::GetMethodLocation() const { |
| 1596 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1597 | } |
| 1598 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1599 | Location InvokeDexCallingConventionVisitorX86_64::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1600 | switch (type) { |
| 1601 | case Primitive::kPrimBoolean: |
| 1602 | case Primitive::kPrimByte: |
| 1603 | case Primitive::kPrimChar: |
| 1604 | case Primitive::kPrimShort: |
| 1605 | case Primitive::kPrimInt: |
| 1606 | case Primitive::kPrimNot: { |
| 1607 | uint32_t index = gp_index_++; |
| 1608 | stack_index_++; |
| 1609 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1610 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1611 | } else { |
| 1612 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1613 | } |
| 1614 | } |
| 1615 | |
| 1616 | case Primitive::kPrimLong: { |
| 1617 | uint32_t index = gp_index_; |
| 1618 | stack_index_ += 2; |
| 1619 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 1620 | gp_index_ += 1; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1621 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1622 | } else { |
| 1623 | gp_index_ += 2; |
| 1624 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1625 | } |
| 1626 | } |
| 1627 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1628 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1629 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1630 | stack_index_++; |
| 1631 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1632 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1633 | } else { |
| 1634 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1635 | } |
| 1636 | } |
| 1637 | |
| 1638 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1639 | uint32_t index = float_index_++; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1640 | stack_index_ += 2; |
| 1641 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1642 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1643 | } else { |
| 1644 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1645 | } |
| 1646 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1647 | |
| 1648 | case Primitive::kPrimVoid: |
| 1649 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1650 | break; |
| 1651 | } |
| 1652 | return Location(); |
| 1653 | } |
| 1654 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1655 | void LocationsBuilderX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1656 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1657 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1658 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1659 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1660 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1661 | if (intrinsic.TryDispatch(invoke)) { |
| 1662 | return; |
| 1663 | } |
| 1664 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1665 | HandleInvoke(invoke); |
| 1666 | } |
| 1667 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1668 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86_64* codegen) { |
| 1669 | if (invoke->GetLocations()->Intrinsified()) { |
| 1670 | IntrinsicCodeGeneratorX86_64 intrinsic(codegen); |
| 1671 | intrinsic.Dispatch(invoke); |
| 1672 | return true; |
| 1673 | } |
| 1674 | return false; |
| 1675 | } |
| 1676 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1677 | void InstructionCodeGeneratorX86_64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1678 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1679 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1680 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1681 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1682 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1683 | return; |
| 1684 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1685 | |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1686 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1687 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1688 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 1689 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1690 | } |
| 1691 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1692 | void LocationsBuilderX86_64::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1693 | InvokeDexCallingConventionVisitorX86_64 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1694 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1695 | } |
| 1696 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1697 | void LocationsBuilderX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1698 | IntrinsicLocationsBuilderX86_64 intrinsic(codegen_); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1699 | if (intrinsic.TryDispatch(invoke)) { |
| 1700 | return; |
| 1701 | } |
| 1702 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1703 | HandleInvoke(invoke); |
| 1704 | } |
| 1705 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1706 | void InstructionCodeGeneratorX86_64::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 1707 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1708 | return; |
| 1709 | } |
| 1710 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1711 | CpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1712 | size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 1713 | invoke->GetVTableIndex(), kX86_64PointerSize).SizeValue(); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1714 | LocationSummary* locations = invoke->GetLocations(); |
| 1715 | Location receiver = locations->InAt(0); |
| 1716 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 1717 | // temp = object->GetClass(); |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 1718 | DCHECK(receiver.IsRegister()); |
| 1719 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1720 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1721 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1722 | // temp = temp->GetMethodAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1723 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1724 | // call temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1725 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1726 | kX86_64WordSize).SizeValue())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1727 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1728 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1729 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 1730 | } |
| 1731 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1732 | void LocationsBuilderX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1733 | HandleInvoke(invoke); |
| 1734 | // Add the hidden argument. |
| 1735 | invoke->GetLocations()->AddTemp(Location::RegisterLocation(RAX)); |
| 1736 | } |
| 1737 | |
| 1738 | void InstructionCodeGeneratorX86_64::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1739 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1740 | CpuRegister temp = invoke->GetLocations()->GetTemp(0).AsRegister<CpuRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1741 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 1742 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86_64PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1743 | LocationSummary* locations = invoke->GetLocations(); |
| 1744 | Location receiver = locations->InAt(0); |
| 1745 | size_t class_offset = mirror::Object::ClassOffset().SizeValue(); |
| 1746 | |
| 1747 | // Set the hidden argument. |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 1748 | CpuRegister hidden_reg = invoke->GetLocations()->GetTemp(1).AsRegister<CpuRegister>(); |
| 1749 | codegen_->Load64BitValue(hidden_reg, invoke->GetDexMethodIndex()); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1750 | |
| 1751 | // temp = object->GetClass(); |
| 1752 | if (receiver.IsStackSlot()) { |
| 1753 | __ movl(temp, Address(CpuRegister(RSP), receiver.GetStackIndex())); |
| 1754 | __ movl(temp, Address(temp, class_offset)); |
| 1755 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1756 | __ movl(temp, Address(receiver.AsRegister<CpuRegister>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1757 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1758 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1759 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1760 | // temp = temp->GetImtEntryAt(method_offset); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1761 | __ movq(temp, Address(temp, method_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1762 | // call temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1763 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1764 | kX86_64WordSize).SizeValue())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1765 | |
| 1766 | DCHECK(!codegen_->IsLeafMethod()); |
| 1767 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1768 | } |
| 1769 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1770 | void LocationsBuilderX86_64::VisitNeg(HNeg* neg) { |
| 1771 | LocationSummary* locations = |
| 1772 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1773 | switch (neg->GetResultType()) { |
| 1774 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1775 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1776 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1777 | locations->SetOut(Location::SameAsFirstInput()); |
| 1778 | break; |
| 1779 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1780 | case Primitive::kPrimFloat: |
| 1781 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1782 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1783 | locations->SetOut(Location::SameAsFirstInput()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1784 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1785 | break; |
| 1786 | |
| 1787 | default: |
| 1788 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1789 | } |
| 1790 | } |
| 1791 | |
| 1792 | void InstructionCodeGeneratorX86_64::VisitNeg(HNeg* neg) { |
| 1793 | LocationSummary* locations = neg->GetLocations(); |
| 1794 | Location out = locations->Out(); |
| 1795 | Location in = locations->InAt(0); |
| 1796 | switch (neg->GetResultType()) { |
| 1797 | case Primitive::kPrimInt: |
| 1798 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1799 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1800 | __ negl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1801 | break; |
| 1802 | |
| 1803 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1804 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1805 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1806 | __ negq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1807 | break; |
| 1808 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1809 | case Primitive::kPrimFloat: { |
| 1810 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1811 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1812 | // Implement float negation with an exclusive or with value |
| 1813 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 1814 | // single-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1815 | __ movss(mask, codegen_->LiteralInt32Address(0x80000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1816 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1817 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1818 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1819 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1820 | case Primitive::kPrimDouble: { |
| 1821 | DCHECK(in.Equals(out)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1822 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1823 | // Implement double negation with an exclusive or with value |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1824 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1825 | // a double-precision floating-point number). |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1826 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000))); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1827 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1828 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1829 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1830 | |
| 1831 | default: |
| 1832 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1833 | } |
| 1834 | } |
| 1835 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1836 | void LocationsBuilderX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 1837 | LocationSummary* locations = |
| 1838 | new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall); |
| 1839 | Primitive::Type result_type = conversion->GetResultType(); |
| 1840 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1841 | DCHECK_NE(result_type, input_type); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1842 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1843 | // The Java language does not allow treating boolean as an integral type but |
| 1844 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1845 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1846 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1847 | case Primitive::kPrimByte: |
| 1848 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1849 | case Primitive::kPrimBoolean: |
| 1850 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1851 | case Primitive::kPrimShort: |
| 1852 | case Primitive::kPrimInt: |
| 1853 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1854 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1855 | locations->SetInAt(0, Location::Any()); |
| 1856 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1857 | break; |
| 1858 | |
| 1859 | default: |
| 1860 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1861 | << " to " << result_type; |
| 1862 | } |
| 1863 | break; |
| 1864 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1865 | case Primitive::kPrimShort: |
| 1866 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1867 | case Primitive::kPrimBoolean: |
| 1868 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1869 | case Primitive::kPrimByte: |
| 1870 | case Primitive::kPrimInt: |
| 1871 | case Primitive::kPrimChar: |
| 1872 | // Processing a Dex `int-to-short' instruction. |
| 1873 | locations->SetInAt(0, Location::Any()); |
| 1874 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1875 | break; |
| 1876 | |
| 1877 | default: |
| 1878 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1879 | << " to " << result_type; |
| 1880 | } |
| 1881 | break; |
| 1882 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1883 | case Primitive::kPrimInt: |
| 1884 | switch (input_type) { |
| 1885 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1886 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1887 | locations->SetInAt(0, Location::Any()); |
| 1888 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1889 | break; |
| 1890 | |
| 1891 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1892 | // Processing a Dex `float-to-int' instruction. |
| 1893 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1894 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1895 | break; |
| 1896 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1897 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1898 | // Processing a Dex `double-to-int' instruction. |
| 1899 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1900 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1901 | break; |
| 1902 | |
| 1903 | default: |
| 1904 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1905 | << " to " << result_type; |
| 1906 | } |
| 1907 | break; |
| 1908 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1909 | case Primitive::kPrimLong: |
| 1910 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1911 | case Primitive::kPrimBoolean: |
| 1912 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1913 | case Primitive::kPrimByte: |
| 1914 | case Primitive::kPrimShort: |
| 1915 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1916 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1917 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1918 | // TODO: We would benefit from a (to-be-implemented) |
| 1919 | // Location::RegisterOrStackSlot requirement for this input. |
| 1920 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1921 | locations->SetOut(Location::RequiresRegister()); |
| 1922 | break; |
| 1923 | |
| 1924 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1925 | // Processing a Dex `float-to-long' instruction. |
| 1926 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1927 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1928 | break; |
| 1929 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1930 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1931 | // Processing a Dex `double-to-long' instruction. |
| 1932 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1933 | locations->SetOut(Location::RequiresRegister()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1934 | break; |
| 1935 | |
| 1936 | default: |
| 1937 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1938 | << " to " << result_type; |
| 1939 | } |
| 1940 | break; |
| 1941 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1942 | case Primitive::kPrimChar: |
| 1943 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1944 | case Primitive::kPrimBoolean: |
| 1945 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1946 | case Primitive::kPrimByte: |
| 1947 | case Primitive::kPrimShort: |
| 1948 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1949 | // Processing a Dex `int-to-char' instruction. |
| 1950 | locations->SetInAt(0, Location::Any()); |
| 1951 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1952 | break; |
| 1953 | |
| 1954 | default: |
| 1955 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1956 | << " to " << result_type; |
| 1957 | } |
| 1958 | break; |
| 1959 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1960 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1961 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1962 | case Primitive::kPrimBoolean: |
| 1963 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1964 | case Primitive::kPrimByte: |
| 1965 | case Primitive::kPrimShort: |
| 1966 | case Primitive::kPrimInt: |
| 1967 | case Primitive::kPrimChar: |
| 1968 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1969 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1970 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1971 | break; |
| 1972 | |
| 1973 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1974 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1975 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1976 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1977 | break; |
| 1978 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1979 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1980 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 1981 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1982 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1983 | break; |
| 1984 | |
| 1985 | default: |
| 1986 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1987 | << " to " << result_type; |
| 1988 | }; |
| 1989 | break; |
| 1990 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1991 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1992 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1993 | case Primitive::kPrimBoolean: |
| 1994 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1995 | case Primitive::kPrimByte: |
| 1996 | case Primitive::kPrimShort: |
| 1997 | case Primitive::kPrimInt: |
| 1998 | case Primitive::kPrimChar: |
| 1999 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2000 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2001 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2002 | break; |
| 2003 | |
| 2004 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2005 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2006 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2007 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2008 | break; |
| 2009 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2010 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2011 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2012 | locations->SetInAt(0, Location::Any()); |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2013 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2014 | break; |
| 2015 | |
| 2016 | default: |
| 2017 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2018 | << " to " << result_type; |
| 2019 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2020 | break; |
| 2021 | |
| 2022 | default: |
| 2023 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2024 | << " to " << result_type; |
| 2025 | } |
| 2026 | } |
| 2027 | |
| 2028 | void InstructionCodeGeneratorX86_64::VisitTypeConversion(HTypeConversion* conversion) { |
| 2029 | LocationSummary* locations = conversion->GetLocations(); |
| 2030 | Location out = locations->Out(); |
| 2031 | Location in = locations->InAt(0); |
| 2032 | Primitive::Type result_type = conversion->GetResultType(); |
| 2033 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2034 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2035 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2036 | case Primitive::kPrimByte: |
| 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 | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2040 | case Primitive::kPrimShort: |
| 2041 | case Primitive::kPrimInt: |
| 2042 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2043 | // Processing a Dex `int-to-byte' instruction. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2044 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2045 | __ movsxb(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2046 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2047 | __ movsxb(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2048 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2049 | } else { |
| 2050 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2051 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2052 | Immediate(static_cast<int8_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2053 | } |
| 2054 | break; |
| 2055 | |
| 2056 | default: |
| 2057 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2058 | << " to " << result_type; |
| 2059 | } |
| 2060 | break; |
| 2061 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2062 | case Primitive::kPrimShort: |
| 2063 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2064 | case Primitive::kPrimBoolean: |
| 2065 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2066 | case Primitive::kPrimByte: |
| 2067 | case Primitive::kPrimInt: |
| 2068 | case Primitive::kPrimChar: |
| 2069 | // Processing a Dex `int-to-short' instruction. |
| 2070 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2071 | __ movsxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2072 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2073 | __ movsxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2074 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2075 | } else { |
| 2076 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2077 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2078 | Immediate(static_cast<int16_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2079 | } |
| 2080 | break; |
| 2081 | |
| 2082 | default: |
| 2083 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2084 | << " to " << result_type; |
| 2085 | } |
| 2086 | break; |
| 2087 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2088 | case Primitive::kPrimInt: |
| 2089 | switch (input_type) { |
| 2090 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2091 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2092 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2093 | __ movl(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2094 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2095 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2096 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2097 | } else { |
| 2098 | DCHECK(in.IsConstant()); |
| 2099 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2100 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2101 | __ movl(out.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2102 | } |
| 2103 | break; |
| 2104 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2105 | case Primitive::kPrimFloat: { |
| 2106 | // Processing a Dex `float-to-int' instruction. |
| 2107 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2108 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2109 | Label done, nan; |
| 2110 | |
| 2111 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2112 | // if input >= (float)INT_MAX goto done |
| 2113 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimIntMax)); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2114 | __ j(kAboveEqual, &done); |
| 2115 | // if input == NaN goto nan |
| 2116 | __ j(kUnordered, &nan); |
| 2117 | // output = float-to-int-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2118 | __ cvttss2si(output, input, false); |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2119 | __ jmp(&done); |
| 2120 | __ Bind(&nan); |
| 2121 | // output = 0 |
| 2122 | __ xorl(output, output); |
| 2123 | __ Bind(&done); |
| 2124 | break; |
| 2125 | } |
| 2126 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2127 | case Primitive::kPrimDouble: { |
| 2128 | // Processing a Dex `double-to-int' instruction. |
| 2129 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2130 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2131 | Label done, nan; |
| 2132 | |
| 2133 | __ movl(output, Immediate(kPrimIntMax)); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2134 | // if input >= (double)INT_MAX goto done |
| 2135 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimIntMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2136 | __ j(kAboveEqual, &done); |
| 2137 | // if input == NaN goto nan |
| 2138 | __ j(kUnordered, &nan); |
| 2139 | // output = double-to-int-truncate(input) |
| 2140 | __ cvttsd2si(output, input); |
| 2141 | __ jmp(&done); |
| 2142 | __ Bind(&nan); |
| 2143 | // output = 0 |
| 2144 | __ xorl(output, output); |
| 2145 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2146 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2147 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2148 | |
| 2149 | default: |
| 2150 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2151 | << " to " << result_type; |
| 2152 | } |
| 2153 | break; |
| 2154 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2155 | case Primitive::kPrimLong: |
| 2156 | switch (input_type) { |
| 2157 | DCHECK(out.IsRegister()); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2158 | case Primitive::kPrimBoolean: |
| 2159 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2160 | case Primitive::kPrimByte: |
| 2161 | case Primitive::kPrimShort: |
| 2162 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2163 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2164 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2165 | DCHECK(in.IsRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2166 | __ movsxd(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2167 | break; |
| 2168 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2169 | case Primitive::kPrimFloat: { |
| 2170 | // Processing a Dex `float-to-long' instruction. |
| 2171 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2172 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2173 | Label done, nan; |
| 2174 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2175 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2176 | // if input >= (float)LONG_MAX goto done |
| 2177 | __ comiss(input, codegen_->LiteralFloatAddress(kPrimLongMax)); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2178 | __ j(kAboveEqual, &done); |
| 2179 | // if input == NaN goto nan |
| 2180 | __ j(kUnordered, &nan); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2181 | // output = float-to-long-truncate(input) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2182 | __ cvttss2si(output, input, true); |
| 2183 | __ jmp(&done); |
| 2184 | __ Bind(&nan); |
| 2185 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2186 | __ xorl(output, output); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2187 | __ Bind(&done); |
| 2188 | break; |
| 2189 | } |
| 2190 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2191 | case Primitive::kPrimDouble: { |
| 2192 | // Processing a Dex `double-to-long' instruction. |
| 2193 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2194 | CpuRegister output = out.AsRegister<CpuRegister>(); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2195 | Label done, nan; |
| 2196 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2197 | codegen_->Load64BitValue(output, kPrimLongMax); |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 2198 | // if input >= (double)LONG_MAX goto done |
| 2199 | __ comisd(input, codegen_->LiteralDoubleAddress(kPrimLongMax)); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2200 | __ j(kAboveEqual, &done); |
| 2201 | // if input == NaN goto nan |
| 2202 | __ j(kUnordered, &nan); |
| 2203 | // output = double-to-long-truncate(input) |
| 2204 | __ cvttsd2si(output, input, true); |
| 2205 | __ jmp(&done); |
| 2206 | __ Bind(&nan); |
| 2207 | // output = 0 |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2208 | __ xorl(output, output); |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2209 | __ Bind(&done); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2210 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2211 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2212 | |
| 2213 | default: |
| 2214 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2215 | << " to " << result_type; |
| 2216 | } |
| 2217 | break; |
| 2218 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2219 | case Primitive::kPrimChar: |
| 2220 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2221 | case Primitive::kPrimBoolean: |
| 2222 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2223 | case Primitive::kPrimByte: |
| 2224 | case Primitive::kPrimShort: |
| 2225 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2226 | // Processing a Dex `int-to-char' instruction. |
| 2227 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2228 | __ movzxw(out.AsRegister<CpuRegister>(), in.AsRegister<CpuRegister>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2229 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2230 | __ movzxw(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2231 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2232 | } else { |
| 2233 | DCHECK(in.GetConstant()->IsIntConstant()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2234 | __ movl(out.AsRegister<CpuRegister>(), |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2235 | Immediate(static_cast<uint16_t>(in.GetConstant()->AsIntConstant()->GetValue()))); |
| 2236 | } |
| 2237 | break; |
| 2238 | |
| 2239 | default: |
| 2240 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2241 | << " to " << result_type; |
| 2242 | } |
| 2243 | break; |
| 2244 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2245 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2246 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2247 | case Primitive::kPrimBoolean: |
| 2248 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2249 | case Primitive::kPrimByte: |
| 2250 | case Primitive::kPrimShort: |
| 2251 | case Primitive::kPrimInt: |
| 2252 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2253 | // Processing a Dex `int-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2254 | if (in.IsRegister()) { |
| 2255 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2256 | } else if (in.IsConstant()) { |
| 2257 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2258 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2259 | if (v == 0) { |
| 2260 | __ xorps(dest, dest); |
| 2261 | } else { |
| 2262 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2263 | } |
| 2264 | } else { |
| 2265 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2266 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2267 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2268 | break; |
| 2269 | |
| 2270 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2271 | // Processing a Dex `long-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2272 | if (in.IsRegister()) { |
| 2273 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2274 | } else if (in.IsConstant()) { |
| 2275 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2276 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2277 | if (v == 0) { |
| 2278 | __ xorps(dest, dest); |
| 2279 | } else { |
| 2280 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2281 | } |
| 2282 | } else { |
| 2283 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), |
| 2284 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2285 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2286 | break; |
| 2287 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2288 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2289 | // Processing a Dex `double-to-float' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2290 | if (in.IsFpuRegister()) { |
| 2291 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2292 | } else if (in.IsConstant()) { |
| 2293 | double v = in.GetConstant()->AsDoubleConstant()->GetValue(); |
| 2294 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2295 | if (bit_cast<int64_t, double>(v) == 0) { |
| 2296 | __ xorps(dest, dest); |
| 2297 | } else { |
| 2298 | __ movss(dest, codegen_->LiteralFloatAddress(static_cast<float>(v))); |
| 2299 | } |
| 2300 | } else { |
| 2301 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), |
| 2302 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2303 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2304 | break; |
| 2305 | |
| 2306 | default: |
| 2307 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2308 | << " to " << result_type; |
| 2309 | }; |
| 2310 | break; |
| 2311 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2312 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2313 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2314 | case Primitive::kPrimBoolean: |
| 2315 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2316 | case Primitive::kPrimByte: |
| 2317 | case Primitive::kPrimShort: |
| 2318 | case Primitive::kPrimInt: |
| 2319 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2320 | // Processing a Dex `int-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2321 | if (in.IsRegister()) { |
| 2322 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), false); |
| 2323 | } else if (in.IsConstant()) { |
| 2324 | int32_t v = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2325 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2326 | if (v == 0) { |
| 2327 | __ xorpd(dest, dest); |
| 2328 | } else { |
| 2329 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2330 | } |
| 2331 | } else { |
| 2332 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2333 | Address(CpuRegister(RSP), in.GetStackIndex()), false); |
| 2334 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2335 | break; |
| 2336 | |
| 2337 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2338 | // Processing a Dex `long-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2339 | if (in.IsRegister()) { |
| 2340 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<CpuRegister>(), true); |
| 2341 | } else if (in.IsConstant()) { |
| 2342 | int64_t v = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2343 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2344 | if (v == 0) { |
| 2345 | __ xorpd(dest, dest); |
| 2346 | } else { |
| 2347 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2348 | } |
| 2349 | } else { |
| 2350 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), |
| 2351 | Address(CpuRegister(RSP), in.GetStackIndex()), true); |
| 2352 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2353 | break; |
| 2354 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2355 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2356 | // Processing a Dex `float-to-double' instruction. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 2357 | if (in.IsFpuRegister()) { |
| 2358 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
| 2359 | } else if (in.IsConstant()) { |
| 2360 | float v = in.GetConstant()->AsFloatConstant()->GetValue(); |
| 2361 | XmmRegister dest = out.AsFpuRegister<XmmRegister>(); |
| 2362 | if (bit_cast<int32_t, float>(v) == 0) { |
| 2363 | __ xorpd(dest, dest); |
| 2364 | } else { |
| 2365 | __ movsd(dest, codegen_->LiteralDoubleAddress(static_cast<double>(v))); |
| 2366 | } |
| 2367 | } else { |
| 2368 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), |
| 2369 | Address(CpuRegister(RSP), in.GetStackIndex())); |
| 2370 | } |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2371 | break; |
| 2372 | |
| 2373 | default: |
| 2374 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2375 | << " to " << result_type; |
| 2376 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2377 | break; |
| 2378 | |
| 2379 | default: |
| 2380 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2381 | << " to " << result_type; |
| 2382 | } |
| 2383 | } |
| 2384 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2385 | void LocationsBuilderX86_64::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2386 | LocationSummary* locations = |
| 2387 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2388 | switch (add->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2389 | case Primitive::kPrimInt: { |
| 2390 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2391 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2392 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2393 | break; |
| 2394 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2395 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2396 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2397 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2398 | // 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] | 2399 | locations->SetInAt(1, Location::RegisterOrInt32LongConstant(add->InputAt(1))); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2400 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2401 | break; |
| 2402 | } |
| 2403 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2404 | case Primitive::kPrimDouble: |
| 2405 | case Primitive::kPrimFloat: { |
| 2406 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2407 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2408 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2409 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2410 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2411 | |
| 2412 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2413 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2414 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2415 | } |
| 2416 | |
| 2417 | void InstructionCodeGeneratorX86_64::VisitAdd(HAdd* add) { |
| 2418 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2419 | Location first = locations->InAt(0); |
| 2420 | Location second = locations->InAt(1); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2421 | Location out = locations->Out(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2422 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2423 | switch (add->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2424 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2425 | if (second.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2426 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2427 | __ addl(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2428 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2429 | __ addl(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2430 | } else { |
| 2431 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2432 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2433 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2434 | } else if (second.IsConstant()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2435 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2436 | __ addl(out.AsRegister<CpuRegister>(), |
| 2437 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
| 2438 | } else { |
| 2439 | __ leal(out.AsRegister<CpuRegister>(), Address( |
| 2440 | first.AsRegister<CpuRegister>(), second.GetConstant()->AsIntConstant()->GetValue())); |
| 2441 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2442 | } else { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 2443 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2444 | __ addl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2445 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2446 | break; |
| 2447 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2448 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2449 | case Primitive::kPrimLong: { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2450 | if (second.IsRegister()) { |
| 2451 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2452 | __ addq(out.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2453 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2454 | __ addq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2455 | } else { |
| 2456 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2457 | first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>(), TIMES_1, 0)); |
| 2458 | } |
| 2459 | } else { |
| 2460 | DCHECK(second.IsConstant()); |
| 2461 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2462 | int32_t int32_value = Low32Bits(value); |
| 2463 | DCHECK_EQ(int32_value, value); |
| 2464 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2465 | __ addq(out.AsRegister<CpuRegister>(), Immediate(int32_value)); |
| 2466 | } else { |
| 2467 | __ leaq(out.AsRegister<CpuRegister>(), Address( |
| 2468 | first.AsRegister<CpuRegister>(), int32_value)); |
| 2469 | } |
| 2470 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2471 | break; |
| 2472 | } |
| 2473 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2474 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2475 | if (second.IsFpuRegister()) { |
| 2476 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2477 | } else if (second.IsConstant()) { |
| 2478 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2479 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 2480 | } else { |
| 2481 | DCHECK(second.IsStackSlot()); |
| 2482 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2483 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2484 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2485 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2486 | } |
| 2487 | |
| 2488 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2489 | if (second.IsFpuRegister()) { |
| 2490 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2491 | } else if (second.IsConstant()) { |
| 2492 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2493 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 2494 | } else { |
| 2495 | DCHECK(second.IsDoubleStackSlot()); |
| 2496 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2497 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2498 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2499 | break; |
| 2500 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2501 | |
| 2502 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2503 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2504 | } |
| 2505 | } |
| 2506 | |
| 2507 | void LocationsBuilderX86_64::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2508 | LocationSummary* locations = |
| 2509 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2510 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2511 | case Primitive::kPrimInt: { |
| 2512 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2513 | locations->SetInAt(1, Location::Any()); |
| 2514 | locations->SetOut(Location::SameAsFirstInput()); |
| 2515 | break; |
| 2516 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2517 | case Primitive::kPrimLong: { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2518 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2519 | locations->SetInAt(1, Location::RegisterOrInt32LongConstant(sub->InputAt(1))); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2520 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2521 | break; |
| 2522 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2523 | case Primitive::kPrimFloat: |
| 2524 | case Primitive::kPrimDouble: { |
| 2525 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2526 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2527 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2528 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2529 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2530 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2531 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2532 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2533 | } |
| 2534 | |
| 2535 | void InstructionCodeGeneratorX86_64::VisitSub(HSub* sub) { |
| 2536 | LocationSummary* locations = sub->GetLocations(); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2537 | Location first = locations->InAt(0); |
| 2538 | Location second = locations->InAt(1); |
| 2539 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2540 | switch (sub->GetResultType()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2541 | case Primitive::kPrimInt: { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2542 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2543 | __ subl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2544 | } else if (second.IsConstant()) { |
| 2545 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2546 | __ subl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2547 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2548 | __ subl(first.AsRegister<CpuRegister>(), Address(CpuRegister(RSP), second.GetStackIndex())); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2549 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 2550 | break; |
| 2551 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2552 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2553 | if (second.IsConstant()) { |
| 2554 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2555 | DCHECK(IsInt<32>(value)); |
| 2556 | __ subq(first.AsRegister<CpuRegister>(), Immediate(static_cast<int32_t>(value))); |
| 2557 | } else { |
| 2558 | __ subq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
| 2559 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2560 | break; |
| 2561 | } |
| 2562 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2563 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2564 | if (second.IsFpuRegister()) { |
| 2565 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2566 | } else if (second.IsConstant()) { |
| 2567 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2568 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 2569 | } else { |
| 2570 | DCHECK(second.IsStackSlot()); |
| 2571 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2572 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2573 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2574 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2575 | } |
| 2576 | |
| 2577 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2578 | if (second.IsFpuRegister()) { |
| 2579 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2580 | } else if (second.IsConstant()) { |
| 2581 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2582 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 2583 | } else { |
| 2584 | DCHECK(second.IsDoubleStackSlot()); |
| 2585 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2586 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2587 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2588 | break; |
| 2589 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2590 | |
| 2591 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2592 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 2593 | } |
| 2594 | } |
| 2595 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2596 | void LocationsBuilderX86_64::VisitMul(HMul* mul) { |
| 2597 | LocationSummary* locations = |
| 2598 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2599 | switch (mul->GetResultType()) { |
| 2600 | case Primitive::kPrimInt: { |
| 2601 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2602 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2603 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2604 | // Can use 3 operand multiply. |
| 2605 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2606 | } else { |
| 2607 | locations->SetOut(Location::SameAsFirstInput()); |
| 2608 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2609 | break; |
| 2610 | } |
| 2611 | case Primitive::kPrimLong: { |
| 2612 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2613 | locations->SetInAt(1, Location::Any()); |
| 2614 | if (mul->InputAt(1)->IsLongConstant() && |
| 2615 | IsInt<32>(mul->InputAt(1)->AsLongConstant()->GetValue())) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2616 | // Can use 3 operand multiply. |
| 2617 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2618 | } else { |
| 2619 | locations->SetOut(Location::SameAsFirstInput()); |
| 2620 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2621 | break; |
| 2622 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2623 | case Primitive::kPrimFloat: |
| 2624 | case Primitive::kPrimDouble: { |
| 2625 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2626 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2627 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2628 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2629 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2630 | |
| 2631 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2632 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2633 | } |
| 2634 | } |
| 2635 | |
| 2636 | void InstructionCodeGeneratorX86_64::VisitMul(HMul* mul) { |
| 2637 | LocationSummary* locations = mul->GetLocations(); |
| 2638 | Location first = locations->InAt(0); |
| 2639 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2640 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2641 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2642 | case Primitive::kPrimInt: |
| 2643 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2644 | // problems where the output may not be the same as the first operand. |
| 2645 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2646 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 2647 | __ imull(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), imm); |
| 2648 | } else if (second.IsRegister()) { |
| 2649 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2650 | __ imull(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2651 | } else { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2652 | DCHECK(first.Equals(out)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2653 | DCHECK(second.IsStackSlot()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2654 | __ imull(first.AsRegister<CpuRegister>(), |
| 2655 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2656 | } |
| 2657 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2658 | case Primitive::kPrimLong: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2659 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2660 | // problems where the output may not be the same as the first operand. |
| 2661 | if (mul->InputAt(1)->IsLongConstant()) { |
| 2662 | int64_t value = mul->InputAt(1)->AsLongConstant()->GetValue(); |
| 2663 | if (IsInt<32>(value)) { |
| 2664 | __ imulq(out.AsRegister<CpuRegister>(), first.AsRegister<CpuRegister>(), |
| 2665 | Immediate(static_cast<int32_t>(value))); |
| 2666 | } else { |
| 2667 | // Have to use the constant area. |
| 2668 | DCHECK(first.Equals(out)); |
| 2669 | __ imulq(first.AsRegister<CpuRegister>(), codegen_->LiteralInt64Address(value)); |
| 2670 | } |
| 2671 | } else if (second.IsRegister()) { |
| 2672 | DCHECK(first.Equals(out)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2673 | __ imulq(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2674 | } else { |
| 2675 | DCHECK(second.IsDoubleStackSlot()); |
| 2676 | DCHECK(first.Equals(out)); |
| 2677 | __ imulq(first.AsRegister<CpuRegister>(), |
| 2678 | Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 2679 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2680 | break; |
| 2681 | } |
| 2682 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2683 | case Primitive::kPrimFloat: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2684 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2685 | if (second.IsFpuRegister()) { |
| 2686 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2687 | } else if (second.IsConstant()) { |
| 2688 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 2689 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 2690 | } else { |
| 2691 | DCHECK(second.IsStackSlot()); |
| 2692 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 2693 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2694 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2695 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2696 | } |
| 2697 | |
| 2698 | case Primitive::kPrimDouble: { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2699 | DCHECK(first.Equals(out)); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 2700 | if (second.IsFpuRegister()) { |
| 2701 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2702 | } else if (second.IsConstant()) { |
| 2703 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 2704 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 2705 | } else { |
| 2706 | DCHECK(second.IsDoubleStackSlot()); |
| 2707 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 2708 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 2709 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2710 | break; |
| 2711 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2712 | |
| 2713 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2714 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2715 | } |
| 2716 | } |
| 2717 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2718 | void InstructionCodeGeneratorX86_64::PushOntoFPStack(Location source, uint32_t temp_offset, |
| 2719 | uint32_t stack_adjustment, bool is_float) { |
| 2720 | if (source.IsStackSlot()) { |
| 2721 | DCHECK(is_float); |
| 2722 | __ flds(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 2723 | } else if (source.IsDoubleStackSlot()) { |
| 2724 | DCHECK(!is_float); |
| 2725 | __ fldl(Address(CpuRegister(RSP), source.GetStackIndex() + stack_adjustment)); |
| 2726 | } else { |
| 2727 | // Write the value to the temporary location on the stack and load to FP stack. |
| 2728 | if (is_float) { |
| 2729 | Location stack_temp = Location::StackSlot(temp_offset); |
| 2730 | codegen_->Move(stack_temp, source); |
| 2731 | __ flds(Address(CpuRegister(RSP), temp_offset)); |
| 2732 | } else { |
| 2733 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 2734 | codegen_->Move(stack_temp, source); |
| 2735 | __ fldl(Address(CpuRegister(RSP), temp_offset)); |
| 2736 | } |
| 2737 | } |
| 2738 | } |
| 2739 | |
| 2740 | void InstructionCodeGeneratorX86_64::GenerateRemFP(HRem *rem) { |
| 2741 | Primitive::Type type = rem->GetResultType(); |
| 2742 | bool is_float = type == Primitive::kPrimFloat; |
| 2743 | size_t elem_size = Primitive::ComponentSize(type); |
| 2744 | LocationSummary* locations = rem->GetLocations(); |
| 2745 | Location first = locations->InAt(0); |
| 2746 | Location second = locations->InAt(1); |
| 2747 | Location out = locations->Out(); |
| 2748 | |
| 2749 | // Create stack space for 2 elements. |
| 2750 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2751 | __ subq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 2752 | |
| 2753 | // Load the values to the FP stack in reverse order, using temporaries if needed. |
| 2754 | PushOntoFPStack(second, elem_size, 2 * elem_size, is_float); |
| 2755 | PushOntoFPStack(first, 0, 2 * elem_size, is_float); |
| 2756 | |
| 2757 | // Loop doing FPREM until we stabilize. |
| 2758 | Label retry; |
| 2759 | __ Bind(&retry); |
| 2760 | __ fprem(); |
| 2761 | |
| 2762 | // Move FP status to AX. |
| 2763 | __ fstsw(); |
| 2764 | |
| 2765 | // And see if the argument reduction is complete. This is signaled by the |
| 2766 | // C2 FPU flag bit set to 0. |
| 2767 | __ andl(CpuRegister(RAX), Immediate(kC2ConditionMask)); |
| 2768 | __ j(kNotEqual, &retry); |
| 2769 | |
| 2770 | // We have settled on the final value. Retrieve it into an XMM register. |
| 2771 | // Store FP top of stack to real stack. |
| 2772 | if (is_float) { |
| 2773 | __ fsts(Address(CpuRegister(RSP), 0)); |
| 2774 | } else { |
| 2775 | __ fstl(Address(CpuRegister(RSP), 0)); |
| 2776 | } |
| 2777 | |
| 2778 | // Pop the 2 items from the FP stack. |
| 2779 | __ fucompp(); |
| 2780 | |
| 2781 | // Load the value from the stack into an XMM register. |
| 2782 | DCHECK(out.IsFpuRegister()) << out; |
| 2783 | if (is_float) { |
| 2784 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 2785 | } else { |
| 2786 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(CpuRegister(RSP), 0)); |
| 2787 | } |
| 2788 | |
| 2789 | // And remove the temporary stack space we allocated. |
| 2790 | __ addq(CpuRegister(RSP), Immediate(2 * elem_size)); |
| 2791 | } |
| 2792 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2793 | void InstructionCodeGeneratorX86_64::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2794 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2795 | |
| 2796 | LocationSummary* locations = instruction->GetLocations(); |
| 2797 | Location second = locations->InAt(1); |
| 2798 | DCHECK(second.IsConstant()); |
| 2799 | |
| 2800 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 2801 | CpuRegister input_register = locations->InAt(0).AsRegister<CpuRegister>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2802 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2803 | |
| 2804 | DCHECK(imm == 1 || imm == -1); |
| 2805 | |
| 2806 | switch (instruction->GetResultType()) { |
| 2807 | case Primitive::kPrimInt: { |
| 2808 | if (instruction->IsRem()) { |
| 2809 | __ xorl(output_register, output_register); |
| 2810 | } else { |
| 2811 | __ movl(output_register, input_register); |
| 2812 | if (imm == -1) { |
| 2813 | __ negl(output_register); |
| 2814 | } |
| 2815 | } |
| 2816 | break; |
| 2817 | } |
| 2818 | |
| 2819 | case Primitive::kPrimLong: { |
| 2820 | if (instruction->IsRem()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2821 | __ xorl(output_register, output_register); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2822 | } else { |
| 2823 | __ movq(output_register, input_register); |
| 2824 | if (imm == -1) { |
| 2825 | __ negq(output_register); |
| 2826 | } |
| 2827 | } |
| 2828 | break; |
| 2829 | } |
| 2830 | |
| 2831 | default: |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2832 | LOG(FATAL) << "Unexpected type for div by (-)1 " << instruction->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2833 | } |
| 2834 | } |
| 2835 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2836 | void InstructionCodeGeneratorX86_64::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2837 | LocationSummary* locations = instruction->GetLocations(); |
| 2838 | Location second = locations->InAt(1); |
| 2839 | |
| 2840 | CpuRegister output_register = locations->Out().AsRegister<CpuRegister>(); |
| 2841 | CpuRegister numerator = locations->InAt(0).AsRegister<CpuRegister>(); |
| 2842 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2843 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2844 | |
| 2845 | DCHECK(IsPowerOfTwo(std::abs(imm))); |
| 2846 | |
| 2847 | CpuRegister tmp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2848 | |
| 2849 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 2850 | __ leal(tmp, Address(numerator, std::abs(imm) - 1)); |
| 2851 | __ testl(numerator, numerator); |
| 2852 | __ cmov(kGreaterEqual, tmp, numerator); |
| 2853 | int shift = CTZ(imm); |
| 2854 | __ sarl(tmp, Immediate(shift)); |
| 2855 | |
| 2856 | if (imm < 0) { |
| 2857 | __ negl(tmp); |
| 2858 | } |
| 2859 | |
| 2860 | __ movl(output_register, tmp); |
| 2861 | } else { |
| 2862 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 2863 | CpuRegister rdx = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2864 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2865 | codegen_->Load64BitValue(rdx, std::abs(imm) - 1); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2866 | __ addq(rdx, numerator); |
| 2867 | __ testq(numerator, numerator); |
| 2868 | __ cmov(kGreaterEqual, rdx, numerator); |
| 2869 | int shift = CTZ(imm); |
| 2870 | __ sarq(rdx, Immediate(shift)); |
| 2871 | |
| 2872 | if (imm < 0) { |
| 2873 | __ negq(rdx); |
| 2874 | } |
| 2875 | |
| 2876 | __ movq(output_register, rdx); |
| 2877 | } |
| 2878 | } |
| 2879 | |
| 2880 | void InstructionCodeGeneratorX86_64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2881 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2882 | |
| 2883 | LocationSummary* locations = instruction->GetLocations(); |
| 2884 | Location second = locations->InAt(1); |
| 2885 | |
| 2886 | CpuRegister numerator = instruction->IsDiv() ? locations->GetTemp(1).AsRegister<CpuRegister>() |
| 2887 | : locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 2888 | CpuRegister eax = locations->InAt(0).AsRegister<CpuRegister>(); |
| 2889 | CpuRegister edx = instruction->IsDiv() ? locations->GetTemp(0).AsRegister<CpuRegister>() |
| 2890 | : locations->Out().AsRegister<CpuRegister>(); |
| 2891 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 2892 | |
| 2893 | DCHECK_EQ(RAX, eax.AsRegister()); |
| 2894 | DCHECK_EQ(RDX, edx.AsRegister()); |
| 2895 | if (instruction->IsDiv()) { |
| 2896 | DCHECK_EQ(RAX, out.AsRegister()); |
| 2897 | } else { |
| 2898 | DCHECK_EQ(RDX, out.AsRegister()); |
| 2899 | } |
| 2900 | |
| 2901 | int64_t magic; |
| 2902 | int shift; |
| 2903 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2904 | // TODO: can these branches be written as one? |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2905 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 2906 | int imm = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2907 | |
| 2908 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2909 | |
| 2910 | __ movl(numerator, eax); |
| 2911 | |
| 2912 | Label no_div; |
| 2913 | Label end; |
| 2914 | __ testl(eax, eax); |
| 2915 | __ j(kNotEqual, &no_div); |
| 2916 | |
| 2917 | __ xorl(out, out); |
| 2918 | __ jmp(&end); |
| 2919 | |
| 2920 | __ Bind(&no_div); |
| 2921 | |
| 2922 | __ movl(eax, Immediate(magic)); |
| 2923 | __ imull(numerator); |
| 2924 | |
| 2925 | if (imm > 0 && magic < 0) { |
| 2926 | __ addl(edx, numerator); |
| 2927 | } else if (imm < 0 && magic > 0) { |
| 2928 | __ subl(edx, numerator); |
| 2929 | } |
| 2930 | |
| 2931 | if (shift != 0) { |
| 2932 | __ sarl(edx, Immediate(shift)); |
| 2933 | } |
| 2934 | |
| 2935 | __ movl(eax, edx); |
| 2936 | __ shrl(edx, Immediate(31)); |
| 2937 | __ addl(edx, eax); |
| 2938 | |
| 2939 | if (instruction->IsRem()) { |
| 2940 | __ movl(eax, numerator); |
| 2941 | __ imull(edx, Immediate(imm)); |
| 2942 | __ subl(eax, edx); |
| 2943 | __ movl(edx, eax); |
| 2944 | } else { |
| 2945 | __ movl(eax, edx); |
| 2946 | } |
| 2947 | __ Bind(&end); |
| 2948 | } else { |
| 2949 | int64_t imm = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2950 | |
| 2951 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 2952 | |
| 2953 | CpuRegister rax = eax; |
| 2954 | CpuRegister rdx = edx; |
| 2955 | |
| 2956 | CalculateMagicAndShiftForDivRem(imm, true /* is_long */, &magic, &shift); |
| 2957 | |
| 2958 | // Save the numerator. |
| 2959 | __ movq(numerator, rax); |
| 2960 | |
| 2961 | // RAX = magic |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2962 | codegen_->Load64BitValue(rax, magic); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2963 | |
| 2964 | // RDX:RAX = magic * numerator |
| 2965 | __ imulq(numerator); |
| 2966 | |
| 2967 | if (imm > 0 && magic < 0) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2968 | // RDX += numerator |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2969 | __ addq(rdx, numerator); |
| 2970 | } else if (imm < 0 && magic > 0) { |
| 2971 | // RDX -= numerator |
| 2972 | __ subq(rdx, numerator); |
| 2973 | } |
| 2974 | |
| 2975 | // Shift if needed. |
| 2976 | if (shift != 0) { |
| 2977 | __ sarq(rdx, Immediate(shift)); |
| 2978 | } |
| 2979 | |
| 2980 | // RDX += 1 if RDX < 0 |
| 2981 | __ movq(rax, rdx); |
| 2982 | __ shrq(rdx, Immediate(63)); |
| 2983 | __ addq(rdx, rax); |
| 2984 | |
| 2985 | if (instruction->IsRem()) { |
| 2986 | __ movq(rax, numerator); |
| 2987 | |
| 2988 | if (IsInt<32>(imm)) { |
| 2989 | __ imulq(rdx, Immediate(static_cast<int32_t>(imm))); |
| 2990 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 2991 | __ imulq(rdx, codegen_->LiteralInt64Address(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2992 | } |
| 2993 | |
| 2994 | __ subq(rax, rdx); |
| 2995 | __ movq(rdx, rax); |
| 2996 | } else { |
| 2997 | __ movq(rax, rdx); |
| 2998 | } |
| 2999 | } |
| 3000 | } |
| 3001 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3002 | void InstructionCodeGeneratorX86_64::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3003 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3004 | Primitive::Type type = instruction->GetResultType(); |
| 3005 | DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong); |
| 3006 | |
| 3007 | bool is_div = instruction->IsDiv(); |
| 3008 | LocationSummary* locations = instruction->GetLocations(); |
| 3009 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3010 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3011 | Location second = locations->InAt(1); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3012 | |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3013 | DCHECK_EQ(RAX, locations->InAt(0).AsRegister<CpuRegister>().AsRegister()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3014 | DCHECK_EQ(is_div ? RAX : RDX, out.AsRegister()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3015 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3016 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3017 | int64_t imm = Int64FromConstant(second.GetConstant()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3018 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3019 | if (imm == 0) { |
| 3020 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 3021 | } else if (imm == 1 || imm == -1) { |
| 3022 | DivRemOneOrMinusOne(instruction); |
| 3023 | } else if (instruction->IsDiv() && IsPowerOfTwo(std::abs(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3024 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3025 | } else { |
| 3026 | DCHECK(imm <= -2 || imm >= 2); |
| 3027 | GenerateDivRemWithAnyConstant(instruction); |
| 3028 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3029 | } else { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3030 | SlowPathCodeX86_64* slow_path = |
| 3031 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86_64( |
| 3032 | out.AsRegister(), type, is_div); |
| 3033 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3034 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3035 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
| 3036 | // 0x80000000(00000000)/-1 triggers an arithmetic exception! |
| 3037 | // Dividing by -1 is actually negation and -0x800000000(00000000) = 0x80000000(00000000) |
| 3038 | // so it's safe to just use negl instead of more complex comparisons. |
| 3039 | if (type == Primitive::kPrimInt) { |
| 3040 | __ cmpl(second_reg, Immediate(-1)); |
| 3041 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3042 | // edx:eax <- sign-extended of eax |
| 3043 | __ cdq(); |
| 3044 | // eax = quotient, edx = remainder |
| 3045 | __ idivl(second_reg); |
| 3046 | } else { |
| 3047 | __ cmpq(second_reg, Immediate(-1)); |
| 3048 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3049 | // rdx:rax <- sign-extended of rax |
| 3050 | __ cqo(); |
| 3051 | // rax = quotient, rdx = remainder |
| 3052 | __ idivq(second_reg); |
| 3053 | } |
| 3054 | __ Bind(slow_path->GetExitLabel()); |
| 3055 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3056 | } |
| 3057 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3058 | void LocationsBuilderX86_64::VisitDiv(HDiv* div) { |
| 3059 | LocationSummary* locations = |
| 3060 | new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall); |
| 3061 | switch (div->GetResultType()) { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3062 | case Primitive::kPrimInt: |
| 3063 | case Primitive::kPrimLong: { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3064 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3065 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3066 | locations->SetOut(Location::SameAsFirstInput()); |
| 3067 | // Intel uses edx:eax as the dividend. |
| 3068 | locations->AddTemp(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3069 | // We need to save the numerator while we tweak rax and rdx. As we are using imul in a way |
| 3070 | // which enforces results to be in RAX and RDX, things are simpler if we use RDX also as |
| 3071 | // output and request another temp. |
| 3072 | if (div->InputAt(1)->IsConstant()) { |
| 3073 | locations->AddTemp(Location::RequiresRegister()); |
| 3074 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3075 | break; |
| 3076 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3077 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3078 | case Primitive::kPrimFloat: |
| 3079 | case Primitive::kPrimDouble: { |
| 3080 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3081 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3082 | locations->SetOut(Location::SameAsFirstInput()); |
| 3083 | break; |
| 3084 | } |
| 3085 | |
| 3086 | default: |
| 3087 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3088 | } |
| 3089 | } |
| 3090 | |
| 3091 | void InstructionCodeGeneratorX86_64::VisitDiv(HDiv* div) { |
| 3092 | LocationSummary* locations = div->GetLocations(); |
| 3093 | Location first = locations->InAt(0); |
| 3094 | Location second = locations->InAt(1); |
| 3095 | DCHECK(first.Equals(locations->Out())); |
| 3096 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3097 | Primitive::Type type = div->GetResultType(); |
| 3098 | switch (type) { |
| 3099 | case Primitive::kPrimInt: |
| 3100 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3101 | GenerateDivRemIntegral(div); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3102 | break; |
| 3103 | } |
| 3104 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3105 | case Primitive::kPrimFloat: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3106 | if (second.IsFpuRegister()) { |
| 3107 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3108 | } else if (second.IsConstant()) { |
| 3109 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3110 | codegen_->LiteralFloatAddress(second.GetConstant()->AsFloatConstant()->GetValue())); |
| 3111 | } else { |
| 3112 | DCHECK(second.IsStackSlot()); |
| 3113 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3114 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3115 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3116 | break; |
| 3117 | } |
| 3118 | |
| 3119 | case Primitive::kPrimDouble: { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 3120 | if (second.IsFpuRegister()) { |
| 3121 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3122 | } else if (second.IsConstant()) { |
| 3123 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3124 | codegen_->LiteralDoubleAddress(second.GetConstant()->AsDoubleConstant()->GetValue())); |
| 3125 | } else { |
| 3126 | DCHECK(second.IsDoubleStackSlot()); |
| 3127 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3128 | Address(CpuRegister(RSP), second.GetStackIndex())); |
| 3129 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3130 | break; |
| 3131 | } |
| 3132 | |
| 3133 | default: |
| 3134 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3135 | } |
| 3136 | } |
| 3137 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3138 | void LocationsBuilderX86_64::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3139 | Primitive::Type type = rem->GetResultType(); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3140 | LocationSummary* locations = |
| 3141 | new (GetGraph()->GetArena()) LocationSummary(rem, LocationSummary::kNoCall); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3142 | |
| 3143 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3144 | case Primitive::kPrimInt: |
| 3145 | case Primitive::kPrimLong: { |
| 3146 | locations->SetInAt(0, Location::RegisterLocation(RAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3147 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3148 | // Intel uses rdx:rax as the dividend and puts the remainder in rdx |
| 3149 | locations->SetOut(Location::RegisterLocation(RDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3150 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3151 | // which enforces results to be in RAX and RDX, things are simpler if we use EAX also as |
| 3152 | // output and request another temp. |
| 3153 | if (rem->InputAt(1)->IsConstant()) { |
| 3154 | locations->AddTemp(Location::RequiresRegister()); |
| 3155 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3156 | break; |
| 3157 | } |
| 3158 | |
| 3159 | case Primitive::kPrimFloat: |
| 3160 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3161 | locations->SetInAt(0, Location::Any()); |
| 3162 | locations->SetInAt(1, Location::Any()); |
| 3163 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3164 | locations->AddTemp(Location::RegisterLocation(RAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3165 | break; |
| 3166 | } |
| 3167 | |
| 3168 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3169 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3170 | } |
| 3171 | } |
| 3172 | |
| 3173 | void InstructionCodeGeneratorX86_64::VisitRem(HRem* rem) { |
| 3174 | Primitive::Type type = rem->GetResultType(); |
| 3175 | switch (type) { |
| 3176 | case Primitive::kPrimInt: |
| 3177 | case Primitive::kPrimLong: { |
| 3178 | GenerateDivRemIntegral(rem); |
| 3179 | break; |
| 3180 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3181 | case Primitive::kPrimFloat: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3182 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3183 | GenerateRemFP(rem); |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3184 | break; |
| 3185 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3186 | default: |
| 3187 | LOG(FATAL) << "Unexpected rem type " << rem->GetResultType(); |
| 3188 | } |
| 3189 | } |
| 3190 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3191 | void LocationsBuilderX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3192 | LocationSummary* locations = |
| 3193 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3194 | locations->SetInAt(0, Location::Any()); |
| 3195 | if (instruction->HasUses()) { |
| 3196 | locations->SetOut(Location::SameAsFirstInput()); |
| 3197 | } |
| 3198 | } |
| 3199 | |
| 3200 | void InstructionCodeGeneratorX86_64::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3201 | SlowPathCodeX86_64* slow_path = |
| 3202 | new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86_64(instruction); |
| 3203 | codegen_->AddSlowPath(slow_path); |
| 3204 | |
| 3205 | LocationSummary* locations = instruction->GetLocations(); |
| 3206 | Location value = locations->InAt(0); |
| 3207 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3208 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3209 | case Primitive::kPrimByte: |
| 3210 | case Primitive::kPrimChar: |
| 3211 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3212 | case Primitive::kPrimInt: { |
| 3213 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3214 | __ testl(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3215 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3216 | } else if (value.IsStackSlot()) { |
| 3217 | __ cmpl(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3218 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3219 | } else { |
| 3220 | DCHECK(value.IsConstant()) << value; |
| 3221 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3222 | __ jmp(slow_path->GetEntryLabel()); |
| 3223 | } |
| 3224 | } |
| 3225 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3226 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3227 | case Primitive::kPrimLong: { |
| 3228 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3229 | __ testq(value.AsRegister<CpuRegister>(), value.AsRegister<CpuRegister>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3230 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3231 | } else if (value.IsDoubleStackSlot()) { |
| 3232 | __ cmpq(Address(CpuRegister(RSP), value.GetStackIndex()), Immediate(0)); |
| 3233 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3234 | } else { |
| 3235 | DCHECK(value.IsConstant()) << value; |
| 3236 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3237 | __ jmp(slow_path->GetEntryLabel()); |
| 3238 | } |
| 3239 | } |
| 3240 | break; |
| 3241 | } |
| 3242 | default: |
| 3243 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3244 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3245 | } |
| 3246 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3247 | void LocationsBuilderX86_64::HandleShift(HBinaryOperation* op) { |
| 3248 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3249 | |
| 3250 | LocationSummary* locations = |
| 3251 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3252 | |
| 3253 | switch (op->GetResultType()) { |
| 3254 | case Primitive::kPrimInt: |
| 3255 | case Primitive::kPrimLong: { |
| 3256 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3257 | // The shift count needs to be in CL. |
| 3258 | locations->SetInAt(1, Location::ByteRegisterOrConstant(RCX, op->InputAt(1))); |
| 3259 | locations->SetOut(Location::SameAsFirstInput()); |
| 3260 | break; |
| 3261 | } |
| 3262 | default: |
| 3263 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3264 | } |
| 3265 | } |
| 3266 | |
| 3267 | void InstructionCodeGeneratorX86_64::HandleShift(HBinaryOperation* op) { |
| 3268 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3269 | |
| 3270 | LocationSummary* locations = op->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3271 | CpuRegister first_reg = locations->InAt(0).AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3272 | Location second = locations->InAt(1); |
| 3273 | |
| 3274 | switch (op->GetResultType()) { |
| 3275 | case Primitive::kPrimInt: { |
| 3276 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3277 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3278 | if (op->IsShl()) { |
| 3279 | __ shll(first_reg, second_reg); |
| 3280 | } else if (op->IsShr()) { |
| 3281 | __ sarl(first_reg, second_reg); |
| 3282 | } else { |
| 3283 | __ shrl(first_reg, second_reg); |
| 3284 | } |
| 3285 | } else { |
Nicolas Geoffray | 486cc19 | 2014-12-08 18:00:55 +0000 | [diff] [blame] | 3286 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3287 | if (op->IsShl()) { |
| 3288 | __ shll(first_reg, imm); |
| 3289 | } else if (op->IsShr()) { |
| 3290 | __ sarl(first_reg, imm); |
| 3291 | } else { |
| 3292 | __ shrl(first_reg, imm); |
| 3293 | } |
| 3294 | } |
| 3295 | break; |
| 3296 | } |
| 3297 | case Primitive::kPrimLong: { |
| 3298 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3299 | CpuRegister second_reg = second.AsRegister<CpuRegister>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3300 | if (op->IsShl()) { |
| 3301 | __ shlq(first_reg, second_reg); |
| 3302 | } else if (op->IsShr()) { |
| 3303 | __ sarq(first_reg, second_reg); |
| 3304 | } else { |
| 3305 | __ shrq(first_reg, second_reg); |
| 3306 | } |
| 3307 | } else { |
Nicolas Geoffray | 486cc19 | 2014-12-08 18:00:55 +0000 | [diff] [blame] | 3308 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3309 | if (op->IsShl()) { |
| 3310 | __ shlq(first_reg, imm); |
| 3311 | } else if (op->IsShr()) { |
| 3312 | __ sarq(first_reg, imm); |
| 3313 | } else { |
| 3314 | __ shrq(first_reg, imm); |
| 3315 | } |
| 3316 | } |
| 3317 | break; |
| 3318 | } |
| 3319 | default: |
| 3320 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 3321 | } |
| 3322 | } |
| 3323 | |
| 3324 | void LocationsBuilderX86_64::VisitShl(HShl* shl) { |
| 3325 | HandleShift(shl); |
| 3326 | } |
| 3327 | |
| 3328 | void InstructionCodeGeneratorX86_64::VisitShl(HShl* shl) { |
| 3329 | HandleShift(shl); |
| 3330 | } |
| 3331 | |
| 3332 | void LocationsBuilderX86_64::VisitShr(HShr* shr) { |
| 3333 | HandleShift(shr); |
| 3334 | } |
| 3335 | |
| 3336 | void InstructionCodeGeneratorX86_64::VisitShr(HShr* shr) { |
| 3337 | HandleShift(shr); |
| 3338 | } |
| 3339 | |
| 3340 | void LocationsBuilderX86_64::VisitUShr(HUShr* ushr) { |
| 3341 | HandleShift(ushr); |
| 3342 | } |
| 3343 | |
| 3344 | void InstructionCodeGeneratorX86_64::VisitUShr(HUShr* ushr) { |
| 3345 | HandleShift(ushr); |
| 3346 | } |
| 3347 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3348 | void LocationsBuilderX86_64::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3349 | LocationSummary* locations = |
| 3350 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3351 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3352 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3353 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3354 | locations->SetOut(Location::RegisterLocation(RAX)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3355 | } |
| 3356 | |
| 3357 | void InstructionCodeGeneratorX86_64::VisitNewInstance(HNewInstance* instruction) { |
| 3358 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3359 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 3360 | instruction->GetTypeIndex()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3361 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3362 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3363 | |
| 3364 | codegen_->InvokeRuntime( |
| 3365 | Address::Absolute(GetThreadOffset<kX86_64WordSize>(instruction->GetEntrypoint()), true), |
| 3366 | instruction, |
| 3367 | instruction->GetDexPc(), |
| 3368 | nullptr); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3369 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 3370 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3371 | } |
| 3372 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3373 | void LocationsBuilderX86_64::VisitNewArray(HNewArray* instruction) { |
| 3374 | LocationSummary* locations = |
| 3375 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3376 | InvokeRuntimeCallingConvention calling_convention; |
| 3377 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3378 | locations->SetOut(Location::RegisterLocation(RAX)); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3379 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3380 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3381 | } |
| 3382 | |
| 3383 | void InstructionCodeGeneratorX86_64::VisitNewArray(HNewArray* instruction) { |
| 3384 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 3385 | codegen_->Load64BitValue(CpuRegister(calling_convention.GetRegisterAt(0)), |
| 3386 | instruction->GetTypeIndex()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3387 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3388 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3389 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3390 | codegen_->InvokeRuntime( |
| 3391 | Address::Absolute(GetThreadOffset<kX86_64WordSize>(instruction->GetEntrypoint()), true), |
| 3392 | instruction, |
| 3393 | instruction->GetDexPc(), |
| 3394 | nullptr); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3395 | |
| 3396 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3397 | } |
| 3398 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3399 | void LocationsBuilderX86_64::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3400 | LocationSummary* locations = |
| 3401 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3402 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3403 | if (location.IsStackSlot()) { |
| 3404 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3405 | } else if (location.IsDoubleStackSlot()) { |
| 3406 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3407 | } |
| 3408 | locations->SetOut(location); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3409 | } |
| 3410 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3411 | void InstructionCodeGeneratorX86_64::VisitParameterValue( |
| 3412 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3413 | // Nothing to do, the parameter is already at its location. |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3414 | } |
| 3415 | |
| 3416 | void LocationsBuilderX86_64::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3417 | LocationSummary* locations = |
| 3418 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3419 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3420 | } |
| 3421 | |
| 3422 | void InstructionCodeGeneratorX86_64::VisitCurrentMethod( |
| 3423 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 3424 | // Nothing to do, the method is already at its location. |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3425 | } |
| 3426 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3427 | void LocationsBuilderX86_64::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3428 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3429 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 3430 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3431 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3432 | } |
| 3433 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3434 | void InstructionCodeGeneratorX86_64::VisitNot(HNot* not_) { |
| 3435 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3436 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 3437 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3438 | Location out = locations->Out(); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3439 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3440 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3441 | __ notl(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3442 | break; |
| 3443 | |
| 3444 | case Primitive::kPrimLong: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3445 | __ notq(out.AsRegister<CpuRegister>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3446 | break; |
| 3447 | |
| 3448 | default: |
| 3449 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3450 | } |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3451 | } |
| 3452 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3453 | void LocationsBuilderX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3454 | LocationSummary* locations = |
| 3455 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3456 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3457 | locations->SetOut(Location::SameAsFirstInput()); |
| 3458 | } |
| 3459 | |
| 3460 | void InstructionCodeGeneratorX86_64::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3461 | LocationSummary* locations = bool_not->GetLocations(); |
| 3462 | DCHECK_EQ(locations->InAt(0).AsRegister<CpuRegister>().AsRegister(), |
| 3463 | locations->Out().AsRegister<CpuRegister>().AsRegister()); |
| 3464 | Location out = locations->Out(); |
| 3465 | __ xorl(out.AsRegister<CpuRegister>(), Immediate(1)); |
| 3466 | } |
| 3467 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3468 | void LocationsBuilderX86_64::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3469 | LocationSummary* locations = |
| 3470 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3471 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 3472 | locations->SetInAt(i, Location::Any()); |
| 3473 | } |
| 3474 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3475 | } |
| 3476 | |
| 3477 | void InstructionCodeGeneratorX86_64::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3478 | UNUSED(instruction); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 3479 | LOG(FATAL) << "Unimplemented"; |
| 3480 | } |
| 3481 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3482 | void InstructionCodeGeneratorX86_64::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3483 | /* |
| 3484 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 3485 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 3486 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 3487 | */ |
| 3488 | switch (kind) { |
| 3489 | case MemBarrierKind::kAnyAny: { |
| 3490 | __ mfence(); |
| 3491 | break; |
| 3492 | } |
| 3493 | case MemBarrierKind::kAnyStore: |
| 3494 | case MemBarrierKind::kLoadAny: |
| 3495 | case MemBarrierKind::kStoreStore: { |
| 3496 | // nop |
| 3497 | break; |
| 3498 | } |
| 3499 | default: |
| 3500 | LOG(FATAL) << "Unexpected memory barier " << kind; |
| 3501 | } |
| 3502 | } |
| 3503 | |
| 3504 | void LocationsBuilderX86_64::HandleFieldGet(HInstruction* instruction) { |
| 3505 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 3506 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3507 | LocationSummary* locations = |
| 3508 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3509 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3510 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3511 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3512 | } else { |
| 3513 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3514 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3515 | } |
| 3516 | |
| 3517 | void InstructionCodeGeneratorX86_64::HandleFieldGet(HInstruction* instruction, |
| 3518 | const FieldInfo& field_info) { |
| 3519 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 3520 | |
| 3521 | LocationSummary* locations = instruction->GetLocations(); |
| 3522 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3523 | Location out = locations->Out(); |
| 3524 | bool is_volatile = field_info.IsVolatile(); |
| 3525 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3526 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3527 | |
| 3528 | switch (field_type) { |
| 3529 | case Primitive::kPrimBoolean: { |
| 3530 | __ movzxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3531 | break; |
| 3532 | } |
| 3533 | |
| 3534 | case Primitive::kPrimByte: { |
| 3535 | __ movsxb(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3536 | break; |
| 3537 | } |
| 3538 | |
| 3539 | case Primitive::kPrimShort: { |
| 3540 | __ movsxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3541 | break; |
| 3542 | } |
| 3543 | |
| 3544 | case Primitive::kPrimChar: { |
| 3545 | __ movzxw(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3546 | break; |
| 3547 | } |
| 3548 | |
| 3549 | case Primitive::kPrimInt: |
| 3550 | case Primitive::kPrimNot: { |
| 3551 | __ movl(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3552 | break; |
| 3553 | } |
| 3554 | |
| 3555 | case Primitive::kPrimLong: { |
| 3556 | __ movq(out.AsRegister<CpuRegister>(), Address(base, offset)); |
| 3557 | break; |
| 3558 | } |
| 3559 | |
| 3560 | case Primitive::kPrimFloat: { |
| 3561 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 3562 | break; |
| 3563 | } |
| 3564 | |
| 3565 | case Primitive::kPrimDouble: { |
| 3566 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
| 3567 | break; |
| 3568 | } |
| 3569 | |
| 3570 | case Primitive::kPrimVoid: |
| 3571 | LOG(FATAL) << "Unreachable type " << field_type; |
| 3572 | UNREACHABLE(); |
| 3573 | } |
| 3574 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3575 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3576 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3577 | if (is_volatile) { |
| 3578 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 3579 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3580 | |
| 3581 | if (field_type == Primitive::kPrimNot) { |
| 3582 | __ MaybeUnpoisonHeapReference(out.AsRegister<CpuRegister>()); |
| 3583 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3584 | } |
| 3585 | |
| 3586 | void LocationsBuilderX86_64::HandleFieldSet(HInstruction* instruction, |
| 3587 | const FieldInfo& field_info) { |
| 3588 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3589 | |
| 3590 | LocationSummary* locations = |
| 3591 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3592 | Primitive::Type field_type = field_info.GetFieldType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3593 | bool needs_write_barrier = |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3594 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3595 | |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3596 | locations->SetInAt(0, Location::RequiresRegister()); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3597 | if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) { |
| 3598 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3599 | } else { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3600 | locations->SetInAt(1, Location::RegisterOrInt32LongConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3601 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3602 | if (needs_write_barrier) { |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3603 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3604 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3605 | locations->AddTemp(Location::RequiresRegister()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3606 | } else if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 3607 | // Temporary register for the reference poisoning. |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3608 | locations->AddTemp(Location::RequiresRegister()); |
| 3609 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3610 | } |
| 3611 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3612 | void InstructionCodeGeneratorX86_64::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3613 | const FieldInfo& field_info, |
| 3614 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3615 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3616 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3617 | LocationSummary* locations = instruction->GetLocations(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3618 | CpuRegister base = locations->InAt(0).AsRegister<CpuRegister>(); |
| 3619 | Location value = locations->InAt(1); |
| 3620 | bool is_volatile = field_info.IsVolatile(); |
| 3621 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3622 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3623 | |
| 3624 | if (is_volatile) { |
| 3625 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 3626 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3627 | |
| 3628 | switch (field_type) { |
| 3629 | case Primitive::kPrimBoolean: |
| 3630 | case Primitive::kPrimByte: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3631 | if (value.IsConstant()) { |
| 3632 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 3633 | __ movb(Address(base, offset), Immediate(v)); |
| 3634 | } else { |
| 3635 | __ movb(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3636 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3637 | break; |
| 3638 | } |
| 3639 | |
| 3640 | case Primitive::kPrimShort: |
| 3641 | case Primitive::kPrimChar: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3642 | if (value.IsConstant()) { |
| 3643 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 3644 | __ movw(Address(base, offset), Immediate(v)); |
| 3645 | } else { |
| 3646 | __ movw(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3647 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3648 | break; |
| 3649 | } |
| 3650 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3651 | case Primitive::kPrimInt: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3652 | case Primitive::kPrimNot: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3653 | if (value.IsConstant()) { |
| 3654 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3655 | // `field_type == Primitive::kPrimNot` implies `v == 0`. |
| 3656 | DCHECK((field_type != Primitive::kPrimNot) || (v == 0)); |
| 3657 | // Note: if heap poisoning is enabled, no need to poison |
| 3658 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 06b66d0 | 2015-07-01 12:47:25 +0100 | [diff] [blame] | 3659 | __ movl(Address(base, offset), Immediate(v)); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3660 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3661 | if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) { |
| 3662 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3663 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 3664 | __ PoisonHeapReference(temp); |
| 3665 | __ movl(Address(base, offset), temp); |
| 3666 | } else { |
| 3667 | __ movl(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3668 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3669 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3670 | break; |
| 3671 | } |
| 3672 | |
| 3673 | case Primitive::kPrimLong: { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3674 | if (value.IsConstant()) { |
| 3675 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| 3676 | DCHECK(IsInt<32>(v)); |
| 3677 | int32_t v_32 = v; |
| 3678 | __ movq(Address(base, offset), Immediate(v_32)); |
| 3679 | } else { |
| 3680 | __ movq(Address(base, offset), value.AsRegister<CpuRegister>()); |
| 3681 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3682 | break; |
| 3683 | } |
| 3684 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3685 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3686 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3687 | break; |
| 3688 | } |
| 3689 | |
| 3690 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3691 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3692 | break; |
| 3693 | } |
| 3694 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3695 | case Primitive::kPrimVoid: |
| 3696 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3697 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3698 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3699 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3700 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3701 | |
| 3702 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 3703 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 3704 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3705 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<CpuRegister>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3706 | } |
| 3707 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3708 | if (is_volatile) { |
| 3709 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 3710 | } |
| 3711 | } |
| 3712 | |
| 3713 | void LocationsBuilderX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 3714 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3715 | } |
| 3716 | |
| 3717 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3718 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3719 | } |
| 3720 | |
| 3721 | void LocationsBuilderX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3722 | HandleFieldGet(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3723 | } |
| 3724 | |
| 3725 | void InstructionCodeGeneratorX86_64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3726 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3727 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3728 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3729 | void LocationsBuilderX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3730 | HandleFieldGet(instruction); |
| 3731 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3732 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3733 | void InstructionCodeGeneratorX86_64::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3734 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3735 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3736 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3737 | void LocationsBuilderX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3738 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3739 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3740 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3741 | void InstructionCodeGeneratorX86_64::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3742 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3743 | } |
| 3744 | |
| 3745 | void LocationsBuilderX86_64::VisitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3746 | LocationSummary* locations = |
| 3747 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3748 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 3749 | ? Location::RequiresRegister() |
| 3750 | : Location::Any(); |
| 3751 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3752 | if (instruction->HasUses()) { |
| 3753 | locations->SetOut(Location::SameAsFirstInput()); |
| 3754 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3755 | } |
| 3756 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3757 | void InstructionCodeGeneratorX86_64::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3758 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 3759 | return; |
| 3760 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3761 | LocationSummary* locations = instruction->GetLocations(); |
| 3762 | Location obj = locations->InAt(0); |
| 3763 | |
| 3764 | __ testl(CpuRegister(RAX), Address(obj.AsRegister<CpuRegister>(), 0)); |
| 3765 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3766 | } |
| 3767 | |
| 3768 | void InstructionCodeGeneratorX86_64::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 3769 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3770 | codegen_->AddSlowPath(slow_path); |
| 3771 | |
| 3772 | LocationSummary* locations = instruction->GetLocations(); |
| 3773 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3774 | |
| 3775 | if (obj.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 3776 | __ testl(obj.AsRegister<CpuRegister>(), obj.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3777 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3778 | __ cmpl(Address(CpuRegister(RSP), obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3779 | } else { |
| 3780 | DCHECK(obj.IsConstant()) << obj; |
| 3781 | DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0); |
| 3782 | __ jmp(slow_path->GetEntryLabel()); |
| 3783 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3784 | } |
| 3785 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3786 | } |
| 3787 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3788 | void InstructionCodeGeneratorX86_64::VisitNullCheck(HNullCheck* instruction) { |
| 3789 | if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) { |
| 3790 | GenerateImplicitNullCheck(instruction); |
| 3791 | } else { |
| 3792 | GenerateExplicitNullCheck(instruction); |
| 3793 | } |
| 3794 | } |
| 3795 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3796 | void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3797 | LocationSummary* locations = |
| 3798 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3799 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3800 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3801 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3802 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3803 | } else { |
| 3804 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3805 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3806 | } |
| 3807 | |
| 3808 | void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { |
| 3809 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3810 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3811 | Location index = locations->InAt(1); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3812 | Primitive::Type type = instruction->GetType(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3813 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3814 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3815 | case Primitive::kPrimBoolean: { |
| 3816 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3817 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3818 | if (index.IsConstant()) { |
| 3819 | __ movzxb(out, Address(obj, |
| 3820 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 3821 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3822 | __ movzxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3823 | } |
| 3824 | break; |
| 3825 | } |
| 3826 | |
| 3827 | case Primitive::kPrimByte: { |
| 3828 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3829 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3830 | if (index.IsConstant()) { |
| 3831 | __ movsxb(out, Address(obj, |
| 3832 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 3833 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3834 | __ movsxb(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3835 | } |
| 3836 | break; |
| 3837 | } |
| 3838 | |
| 3839 | case Primitive::kPrimShort: { |
| 3840 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3841 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3842 | if (index.IsConstant()) { |
| 3843 | __ movsxw(out, Address(obj, |
| 3844 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 3845 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3846 | __ movsxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3847 | } |
| 3848 | break; |
| 3849 | } |
| 3850 | |
| 3851 | case Primitive::kPrimChar: { |
| 3852 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3853 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3854 | if (index.IsConstant()) { |
| 3855 | __ movzxw(out, Address(obj, |
| 3856 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 3857 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3858 | __ movzxw(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3859 | } |
| 3860 | break; |
| 3861 | } |
| 3862 | |
| 3863 | case Primitive::kPrimInt: |
| 3864 | case Primitive::kPrimNot: { |
Roland Levillain | 33d6903 | 2015-06-18 18:20:59 +0100 | [diff] [blame] | 3865 | static_assert(sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 3866 | "art::mirror::HeapReference<mirror::Object> and int32_t have different sizes."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3867 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3868 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3869 | if (index.IsConstant()) { |
| 3870 | __ movl(out, Address(obj, |
| 3871 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 3872 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3873 | __ movl(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3874 | } |
| 3875 | break; |
| 3876 | } |
| 3877 | |
| 3878 | case Primitive::kPrimLong: { |
| 3879 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3880 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3881 | if (index.IsConstant()) { |
| 3882 | __ movq(out, Address(obj, |
| 3883 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 3884 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3885 | __ movq(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3886 | } |
| 3887 | break; |
| 3888 | } |
| 3889 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3890 | case Primitive::kPrimFloat: { |
| 3891 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3892 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3893 | if (index.IsConstant()) { |
| 3894 | __ movss(out, Address(obj, |
| 3895 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 3896 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3897 | __ movss(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3898 | } |
| 3899 | break; |
| 3900 | } |
| 3901 | |
| 3902 | case Primitive::kPrimDouble: { |
| 3903 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3904 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3905 | if (index.IsConstant()) { |
| 3906 | __ movsd(out, Address(obj, |
| 3907 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 3908 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3909 | __ movsd(out, Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3910 | } |
| 3911 | break; |
| 3912 | } |
| 3913 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3914 | case Primitive::kPrimVoid: |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3915 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3916 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3917 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3918 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3919 | |
| 3920 | if (type == Primitive::kPrimNot) { |
| 3921 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 3922 | __ MaybeUnpoisonHeapReference(out); |
| 3923 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3924 | } |
| 3925 | |
| 3926 | void LocationsBuilderX86_64::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3927 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3928 | |
| 3929 | bool needs_write_barrier = |
| 3930 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 3931 | bool needs_runtime_call = instruction->NeedsTypeCheck(); |
| 3932 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3933 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3934 | instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall); |
| 3935 | if (needs_runtime_call) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3936 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3937 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3938 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3939 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3940 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3941 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 3942 | locations->SetInAt( |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3943 | 1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 3944 | locations->SetInAt(2, Location::RequiresRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3945 | if (value_type == Primitive::kPrimLong) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 3946 | locations->SetInAt(2, Location::RegisterOrInt32LongConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3947 | } else if (value_type == Primitive::kPrimFloat || value_type == Primitive::kPrimDouble) { |
| 3948 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3949 | } else { |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3950 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3951 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3952 | |
| 3953 | if (needs_write_barrier) { |
| 3954 | // Temporary registers for the write barrier. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3955 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3956 | locations->AddTemp(Location::RequiresRegister()); |
| 3957 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3958 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3959 | } |
| 3960 | |
| 3961 | void InstructionCodeGeneratorX86_64::VisitArraySet(HArraySet* instruction) { |
| 3962 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3963 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3964 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3965 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3966 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 3967 | bool needs_runtime_call = locations->WillCall(); |
| 3968 | bool needs_write_barrier = |
| 3969 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3970 | |
| 3971 | switch (value_type) { |
| 3972 | case Primitive::kPrimBoolean: |
| 3973 | case Primitive::kPrimByte: { |
| 3974 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3975 | if (index.IsConstant()) { |
| 3976 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3977 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3978 | __ movb(Address(obj, offset), value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3979 | } else { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3980 | __ movb(Address(obj, offset), |
| 3981 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3982 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3983 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3984 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3985 | __ movb(Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset), |
| 3986 | value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3987 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3988 | __ movb(Address(obj, index.AsRegister<CpuRegister>(), TIMES_1, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3989 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 3990 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3991 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3992 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3993 | break; |
| 3994 | } |
| 3995 | |
| 3996 | case Primitive::kPrimShort: |
| 3997 | case Primitive::kPrimChar: { |
| 3998 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3999 | if (index.IsConstant()) { |
| 4000 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4001 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4002 | __ movw(Address(obj, offset), value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4003 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4004 | DCHECK(value.IsConstant()) << value; |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4005 | __ movw(Address(obj, offset), |
| 4006 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4007 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4008 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4009 | DCHECK(index.IsRegister()) << index; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4010 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4011 | __ movw(Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset), |
| 4012 | value.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4013 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4014 | DCHECK(value.IsConstant()) << value; |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4015 | __ movw(Address(obj, index.AsRegister<CpuRegister>(), TIMES_2, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4016 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4017 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4018 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4019 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4020 | break; |
| 4021 | } |
| 4022 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4023 | case Primitive::kPrimInt: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4024 | case Primitive::kPrimNot: { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4025 | if (!needs_runtime_call) { |
| 4026 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4027 | if (index.IsConstant()) { |
| 4028 | size_t offset = |
| 4029 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4030 | if (value.IsRegister()) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4031 | if (kPoisonHeapReferences && value_type == Primitive::kPrimNot) { |
| 4032 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4033 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4034 | __ PoisonHeapReference(temp); |
| 4035 | __ movl(Address(obj, offset), temp); |
| 4036 | } else { |
| 4037 | __ movl(Address(obj, offset), value.AsRegister<CpuRegister>()); |
| 4038 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4039 | } else { |
| 4040 | DCHECK(value.IsConstant()) << value; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4041 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4042 | // `value_type == Primitive::kPrimNot` implies `v == 0`. |
| 4043 | DCHECK((value_type != Primitive::kPrimNot) || (v == 0)); |
| 4044 | // Note: if heap poisoning is enabled, no need to poison |
| 4045 | // (negate) `v` if it is a reference, as it would be null. |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4046 | __ movl(Address(obj, offset), Immediate(v)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4047 | } |
| 4048 | } else { |
| 4049 | DCHECK(index.IsRegister()) << index; |
| 4050 | if (value.IsRegister()) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4051 | if (kPoisonHeapReferences && value_type == Primitive::kPrimNot) { |
| 4052 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4053 | __ movl(temp, value.AsRegister<CpuRegister>()); |
| 4054 | __ PoisonHeapReference(temp); |
| 4055 | __ movl(Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset), temp); |
| 4056 | } else { |
| 4057 | __ movl(Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset), |
| 4058 | value.AsRegister<CpuRegister>()); |
| 4059 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4060 | } else { |
| 4061 | DCHECK(value.IsConstant()) << value; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4062 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4063 | // `value_type == Primitive::kPrimNot` implies `v == 0`. |
| 4064 | DCHECK((value_type != Primitive::kPrimNot) || (v == 0)); |
| 4065 | // Note: if heap poisoning is enabled, no need to poison |
| 4066 | // (negate) `v` if it is a reference, as it would be null. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4067 | __ movl(Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset), |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4068 | Immediate(v)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4069 | } |
| 4070 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4071 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4072 | if (needs_write_barrier) { |
| 4073 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4074 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
| 4075 | CpuRegister card = locations->GetTemp(1).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4076 | codegen_->MarkGCCard( |
| 4077 | temp, card, obj, value.AsRegister<CpuRegister>(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4078 | } |
| 4079 | } else { |
| 4080 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4081 | // Note: if heap poisoning is enabled, pAputObject takes cares |
| 4082 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 4083 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 4084 | instruction, |
| 4085 | instruction->GetDexPc(), |
| 4086 | nullptr); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4087 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4088 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4089 | break; |
| 4090 | } |
| 4091 | |
| 4092 | case Primitive::kPrimLong: { |
| 4093 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4094 | if (index.IsConstant()) { |
| 4095 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4096 | if (value.IsRegister()) { |
| 4097 | __ movq(Address(obj, offset), value.AsRegister<CpuRegister>()); |
| 4098 | } else { |
| 4099 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| 4100 | DCHECK(IsInt<32>(v)); |
| 4101 | int32_t v_32 = v; |
| 4102 | __ movq(Address(obj, offset), Immediate(v_32)); |
| 4103 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4104 | } else { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4105 | if (value.IsRegister()) { |
| 4106 | __ movq(Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset), |
| 4107 | value.AsRegister<CpuRegister>()); |
| 4108 | } else { |
| 4109 | int64_t v = value.GetConstant()->AsLongConstant()->GetValue(); |
| 4110 | DCHECK(IsInt<32>(v)); |
| 4111 | int32_t v_32 = v; |
| 4112 | __ movq(Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset), |
| 4113 | Immediate(v_32)); |
| 4114 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4115 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4116 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4117 | break; |
| 4118 | } |
| 4119 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4120 | case Primitive::kPrimFloat: { |
| 4121 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4122 | if (index.IsConstant()) { |
| 4123 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4124 | DCHECK(value.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4125 | __ movss(Address(obj, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4126 | } else { |
| 4127 | DCHECK(value.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4128 | __ movss(Address(obj, index.AsRegister<CpuRegister>(), TIMES_4, data_offset), |
| 4129 | value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4130 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4131 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4132 | break; |
| 4133 | } |
| 4134 | |
| 4135 | case Primitive::kPrimDouble: { |
| 4136 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4137 | if (index.IsConstant()) { |
| 4138 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 4139 | DCHECK(value.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4140 | __ movsd(Address(obj, offset), value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4141 | } else { |
| 4142 | DCHECK(value.IsFpuRegister()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4143 | __ movsd(Address(obj, index.AsRegister<CpuRegister>(), TIMES_8, data_offset), |
| 4144 | value.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4145 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4146 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4147 | break; |
| 4148 | } |
| 4149 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4150 | case Primitive::kPrimVoid: |
| 4151 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4152 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4153 | } |
| 4154 | } |
| 4155 | |
| 4156 | void LocationsBuilderX86_64::VisitArrayLength(HArrayLength* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4157 | LocationSummary* locations = |
| 4158 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4159 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4160 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4161 | } |
| 4162 | |
| 4163 | void InstructionCodeGeneratorX86_64::VisitArrayLength(HArrayLength* instruction) { |
| 4164 | LocationSummary* locations = instruction->GetLocations(); |
| 4165 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4166 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
| 4167 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4168 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4169 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4170 | } |
| 4171 | |
| 4172 | void LocationsBuilderX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4173 | LocationSummary* locations = |
| 4174 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4175 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4176 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4177 | if (instruction->HasUses()) { |
| 4178 | locations->SetOut(Location::SameAsFirstInput()); |
| 4179 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4180 | } |
| 4181 | |
| 4182 | void InstructionCodeGeneratorX86_64::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4183 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4184 | Location index_loc = locations->InAt(0); |
| 4185 | Location length_loc = locations->InAt(1); |
| 4186 | SlowPathCodeX86_64* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame^] | 4187 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4188 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4189 | if (length_loc.IsConstant()) { |
| 4190 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 4191 | if (index_loc.IsConstant()) { |
| 4192 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 4193 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4194 | if (index < 0 || index >= length) { |
| 4195 | codegen_->AddSlowPath(slow_path); |
| 4196 | __ jmp(slow_path->GetEntryLabel()); |
| 4197 | } else { |
| 4198 | // Some optimization after BCE may have generated this, and we should not |
| 4199 | // generate a bounds check if it is a valid range. |
| 4200 | } |
| 4201 | return; |
| 4202 | } |
| 4203 | |
| 4204 | // We have to reverse the jump condition because the length is the constant. |
| 4205 | CpuRegister index_reg = index_loc.AsRegister<CpuRegister>(); |
| 4206 | __ cmpl(index_reg, Immediate(length)); |
| 4207 | codegen_->AddSlowPath(slow_path); |
| 4208 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4209 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4210 | CpuRegister length = length_loc.AsRegister<CpuRegister>(); |
| 4211 | if (index_loc.IsConstant()) { |
| 4212 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4213 | __ cmpl(length, Immediate(value)); |
| 4214 | } else { |
| 4215 | __ cmpl(length, index_loc.AsRegister<CpuRegister>()); |
| 4216 | } |
| 4217 | codegen_->AddSlowPath(slow_path); |
| 4218 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4219 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4220 | } |
| 4221 | |
| 4222 | void CodeGeneratorX86_64::MarkGCCard(CpuRegister temp, |
| 4223 | CpuRegister card, |
| 4224 | CpuRegister object, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4225 | CpuRegister value, |
| 4226 | bool value_can_be_null) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4227 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4228 | if (value_can_be_null) { |
| 4229 | __ testl(value, value); |
| 4230 | __ j(kEqual, &is_null); |
| 4231 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4232 | __ gs()->movq(card, Address::Absolute( |
| 4233 | Thread::CardTableOffset<kX86_64WordSize>().Int32Value(), true)); |
| 4234 | __ movq(temp, object); |
| 4235 | __ shrq(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4236 | __ movb(Address(temp, card, TIMES_1, 0), card); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4237 | if (value_can_be_null) { |
| 4238 | __ Bind(&is_null); |
| 4239 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4240 | } |
| 4241 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4242 | void LocationsBuilderX86_64::VisitTemporary(HTemporary* temp) { |
| 4243 | temp->SetLocations(nullptr); |
| 4244 | } |
| 4245 | |
| 4246 | void InstructionCodeGeneratorX86_64::VisitTemporary(HTemporary* temp) { |
| 4247 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4248 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4249 | } |
| 4250 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4251 | void LocationsBuilderX86_64::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4252 | UNUSED(instruction); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4253 | LOG(FATAL) << "Unimplemented"; |
| 4254 | } |
| 4255 | |
| 4256 | void InstructionCodeGeneratorX86_64::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4257 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4258 | } |
| 4259 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4260 | void LocationsBuilderX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4261 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4262 | } |
| 4263 | |
| 4264 | void InstructionCodeGeneratorX86_64::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4265 | HBasicBlock* block = instruction->GetBlock(); |
| 4266 | if (block->GetLoopInformation() != nullptr) { |
| 4267 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4268 | // The back edge will generate the suspend check. |
| 4269 | return; |
| 4270 | } |
| 4271 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4272 | // The goto will generate the suspend check. |
| 4273 | return; |
| 4274 | } |
| 4275 | GenerateSuspendCheck(instruction, nullptr); |
| 4276 | } |
| 4277 | |
| 4278 | void InstructionCodeGeneratorX86_64::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 4279 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4280 | SuspendCheckSlowPathX86_64* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4281 | down_cast<SuspendCheckSlowPathX86_64*>(instruction->GetSlowPath()); |
| 4282 | if (slow_path == nullptr) { |
| 4283 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86_64(instruction, successor); |
| 4284 | instruction->SetSlowPath(slow_path); |
| 4285 | codegen_->AddSlowPath(slow_path); |
| 4286 | if (successor != nullptr) { |
| 4287 | DCHECK(successor->IsLoopHeader()); |
| 4288 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 4289 | } |
| 4290 | } else { |
| 4291 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 4292 | } |
| 4293 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4294 | __ gs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4295 | Thread::ThreadFlagsOffset<kX86_64WordSize>().Int32Value(), true), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4296 | if (successor == nullptr) { |
| 4297 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4298 | __ Bind(slow_path->GetReturnLabel()); |
| 4299 | } else { |
| 4300 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 4301 | __ jmp(slow_path->GetEntryLabel()); |
| 4302 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4303 | } |
| 4304 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4305 | X86_64Assembler* ParallelMoveResolverX86_64::GetAssembler() const { |
| 4306 | return codegen_->GetAssembler(); |
| 4307 | } |
| 4308 | |
| 4309 | void ParallelMoveResolverX86_64::EmitMove(size_t index) { |
| 4310 | MoveOperands* move = moves_.Get(index); |
| 4311 | Location source = move->GetSource(); |
| 4312 | Location destination = move->GetDestination(); |
| 4313 | |
| 4314 | if (source.IsRegister()) { |
| 4315 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4316 | __ movq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4317 | } else if (destination.IsStackSlot()) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4318 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4319 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4320 | } else { |
| 4321 | DCHECK(destination.IsDoubleStackSlot()); |
| 4322 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4323 | source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4324 | } |
| 4325 | } else if (source.IsStackSlot()) { |
| 4326 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4327 | __ movl(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4328 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4329 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4330 | __ movss(destination.AsFpuRegister<XmmRegister>(), |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4331 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4332 | } else { |
| 4333 | DCHECK(destination.IsStackSlot()); |
| 4334 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 4335 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 4336 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4337 | } else if (source.IsDoubleStackSlot()) { |
| 4338 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4339 | __ movq(destination.AsRegister<CpuRegister>(), |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4340 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4341 | } else if (destination.IsFpuRegister()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4342 | __ movsd(destination.AsFpuRegister<XmmRegister>(), |
| 4343 | Address(CpuRegister(RSP), source.GetStackIndex())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4344 | } else { |
Nicolas Geoffray | c8147a7 | 2014-10-21 16:06:20 +0100 | [diff] [blame] | 4345 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4346 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), source.GetStackIndex())); |
| 4347 | __ movq(Address(CpuRegister(RSP), destination.GetStackIndex()), CpuRegister(TMP)); |
| 4348 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4349 | } else if (source.IsConstant()) { |
| 4350 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4351 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 4352 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4353 | if (destination.IsRegister()) { |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4354 | if (value == 0) { |
| 4355 | __ xorl(destination.AsRegister<CpuRegister>(), destination.AsRegister<CpuRegister>()); |
| 4356 | } else { |
| 4357 | __ movl(destination.AsRegister<CpuRegister>(), Immediate(value)); |
| 4358 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4359 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4360 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 748f140 | 2015-01-27 08:17:54 +0000 | [diff] [blame] | 4361 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4362 | } |
| 4363 | } else if (constant->IsLongConstant()) { |
| 4364 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 4365 | if (destination.IsRegister()) { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4366 | codegen_->Load64BitValue(destination.AsRegister<CpuRegister>(), value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4367 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4368 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 4369 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4370 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4371 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4372 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4373 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4374 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4375 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4376 | if (value == 0) { |
| 4377 | // easy FP 0.0. |
| 4378 | __ xorps(dest, dest); |
| 4379 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4380 | __ movss(dest, codegen_->LiteralFloatAddress(fp_value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4381 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4382 | } else { |
| 4383 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4384 | Immediate imm(value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4385 | __ movl(Address(CpuRegister(RSP), destination.GetStackIndex()), imm); |
| 4386 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4387 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4388 | DCHECK(constant->IsDoubleConstant()) << constant->DebugName(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4389 | double fp_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4390 | int64_t value = bit_cast<int64_t, double>(fp_value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4391 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4392 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4393 | if (value == 0) { |
| 4394 | __ xorpd(dest, dest); |
| 4395 | } else { |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4396 | __ movsd(dest, codegen_->LiteralDoubleAddress(fp_value)); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4397 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4398 | } else { |
| 4399 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 4400 | codegen_->Store64BitValueToStack(destination, value); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4401 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4402 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4403 | } else if (source.IsFpuRegister()) { |
| 4404 | if (destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4405 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4406 | } else if (destination.IsStackSlot()) { |
| 4407 | __ movss(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4408 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4409 | } else { |
Nicolas Geoffray | 3159674 | 2014-11-24 15:28:45 +0000 | [diff] [blame] | 4410 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4411 | __ movsd(Address(CpuRegister(RSP), destination.GetStackIndex()), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4412 | source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4413 | } |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4414 | } |
| 4415 | } |
| 4416 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4417 | void ParallelMoveResolverX86_64::Exchange32(CpuRegister reg, int mem) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4418 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4419 | __ movl(Address(CpuRegister(RSP), mem), reg); |
| 4420 | __ movl(reg, CpuRegister(TMP)); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4421 | } |
| 4422 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4423 | void ParallelMoveResolverX86_64::Exchange32(int mem1, int mem2) { |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4424 | ScratchRegisterScope ensure_scratch( |
| 4425 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
| 4426 | |
| 4427 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 4428 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 4429 | __ movl(CpuRegister(ensure_scratch.GetRegister()), |
| 4430 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 4431 | __ movl(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 4432 | __ movl(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 4433 | CpuRegister(ensure_scratch.GetRegister())); |
| 4434 | } |
| 4435 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4436 | void ParallelMoveResolverX86_64::Exchange64(CpuRegister reg, int mem) { |
| 4437 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 4438 | __ movq(Address(CpuRegister(RSP), mem), reg); |
| 4439 | __ movq(reg, CpuRegister(TMP)); |
| 4440 | } |
| 4441 | |
| 4442 | void ParallelMoveResolverX86_64::Exchange64(int mem1, int mem2) { |
| 4443 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4444 | this, TMP, RAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4445 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4446 | int stack_offset = ensure_scratch.IsSpilled() ? kX86_64WordSize : 0; |
| 4447 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem1 + stack_offset)); |
| 4448 | __ movq(CpuRegister(ensure_scratch.GetRegister()), |
| 4449 | Address(CpuRegister(RSP), mem2 + stack_offset)); |
| 4450 | __ movq(Address(CpuRegister(RSP), mem2 + stack_offset), CpuRegister(TMP)); |
| 4451 | __ movq(Address(CpuRegister(RSP), mem1 + stack_offset), |
| 4452 | CpuRegister(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4453 | } |
| 4454 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4455 | void ParallelMoveResolverX86_64::Exchange32(XmmRegister reg, int mem) { |
| 4456 | __ movl(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 4457 | __ movss(Address(CpuRegister(RSP), mem), reg); |
| 4458 | __ movd(reg, CpuRegister(TMP)); |
| 4459 | } |
| 4460 | |
| 4461 | void ParallelMoveResolverX86_64::Exchange64(XmmRegister reg, int mem) { |
| 4462 | __ movq(CpuRegister(TMP), Address(CpuRegister(RSP), mem)); |
| 4463 | __ movsd(Address(CpuRegister(RSP), mem), reg); |
| 4464 | __ movd(reg, CpuRegister(TMP)); |
| 4465 | } |
| 4466 | |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4467 | void ParallelMoveResolverX86_64::EmitSwap(size_t index) { |
| 4468 | MoveOperands* move = moves_.Get(index); |
| 4469 | Location source = move->GetSource(); |
| 4470 | Location destination = move->GetDestination(); |
| 4471 | |
| 4472 | if (source.IsRegister() && destination.IsRegister()) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4473 | __ xchgq(destination.AsRegister<CpuRegister>(), source.AsRegister<CpuRegister>()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4474 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4475 | Exchange32(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4476 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4477 | Exchange32(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4478 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4479 | Exchange32(destination.GetStackIndex(), source.GetStackIndex()); |
| 4480 | } else if (source.IsRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4481 | Exchange64(source.AsRegister<CpuRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4482 | } else if (source.IsDoubleStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4483 | Exchange64(destination.AsRegister<CpuRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4484 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 4485 | Exchange64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4486 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4487 | __ movd(CpuRegister(TMP), source.AsFpuRegister<XmmRegister>()); |
| 4488 | __ movaps(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 4489 | __ movd(destination.AsFpuRegister<XmmRegister>(), CpuRegister(TMP)); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4490 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4491 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4492 | } else if (source.IsStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4493 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4494 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4495 | Exchange64(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4496 | } else if (source.IsDoubleStackSlot() && destination.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4497 | Exchange64(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4498 | } else { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4499 | LOG(FATAL) << "Unimplemented swap between " << source << " and " << destination; |
Nicolas Geoffray | ecb2f9b | 2014-06-13 08:59:59 +0000 | [diff] [blame] | 4500 | } |
| 4501 | } |
| 4502 | |
| 4503 | |
| 4504 | void ParallelMoveResolverX86_64::SpillScratch(int reg) { |
| 4505 | __ pushq(CpuRegister(reg)); |
| 4506 | } |
| 4507 | |
| 4508 | |
| 4509 | void ParallelMoveResolverX86_64::RestoreScratch(int reg) { |
| 4510 | __ popq(CpuRegister(reg)); |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4511 | } |
| 4512 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4513 | void InstructionCodeGeneratorX86_64::GenerateClassInitializationCheck( |
| 4514 | SlowPathCodeX86_64* slow_path, CpuRegister class_reg) { |
| 4515 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 4516 | Immediate(mirror::Class::kStatusInitialized)); |
| 4517 | __ j(kLess, slow_path->GetEntryLabel()); |
| 4518 | __ Bind(slow_path->GetExitLabel()); |
| 4519 | // No need for memory fence, thanks to the X86_64 memory model. |
| 4520 | } |
| 4521 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4522 | void LocationsBuilderX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4523 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() |
| 4524 | ? LocationSummary::kCallOnSlowPath |
| 4525 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4526 | LocationSummary* locations = |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4527 | new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4528 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4529 | locations->SetOut(Location::RequiresRegister()); |
| 4530 | } |
| 4531 | |
| 4532 | void InstructionCodeGeneratorX86_64::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4533 | LocationSummary* locations = cls->GetLocations(); |
| 4534 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4535 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4536 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4537 | DCHECK(!cls->CanCallRuntime()); |
| 4538 | DCHECK(!cls->MustGenerateClinitCheck()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4539 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4540 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4541 | DCHECK(cls->CanCallRuntime()); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4542 | __ movl(out, Address( |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4543 | current_method, ArtMethod::DexCacheResolvedTypesOffset().Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4544 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4545 | __ MaybeUnpoisonHeapReference(out); |
| 4546 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4547 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 4548 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 4549 | codegen_->AddSlowPath(slow_path); |
| 4550 | __ testl(out, out); |
| 4551 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4552 | if (cls->MustGenerateClinitCheck()) { |
| 4553 | GenerateClassInitializationCheck(slow_path, out); |
| 4554 | } else { |
| 4555 | __ Bind(slow_path->GetExitLabel()); |
| 4556 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4557 | } |
| 4558 | } |
| 4559 | |
| 4560 | void LocationsBuilderX86_64::VisitClinitCheck(HClinitCheck* check) { |
| 4561 | LocationSummary* locations = |
| 4562 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 4563 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4564 | if (check->HasUses()) { |
| 4565 | locations->SetOut(Location::SameAsFirstInput()); |
| 4566 | } |
| 4567 | } |
| 4568 | |
| 4569 | void InstructionCodeGeneratorX86_64::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4570 | // We assume the class to not be null. |
| 4571 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86_64( |
| 4572 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4573 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4574 | GenerateClassInitializationCheck(slow_path, |
| 4575 | check->GetLocations()->InAt(0).AsRegister<CpuRegister>()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4576 | } |
| 4577 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4578 | void LocationsBuilderX86_64::VisitLoadString(HLoadString* load) { |
| 4579 | LocationSummary* locations = |
| 4580 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4581 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4582 | locations->SetOut(Location::RequiresRegister()); |
| 4583 | } |
| 4584 | |
| 4585 | void InstructionCodeGeneratorX86_64::VisitLoadString(HLoadString* load) { |
| 4586 | SlowPathCodeX86_64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86_64(load); |
| 4587 | codegen_->AddSlowPath(slow_path); |
| 4588 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4589 | LocationSummary* locations = load->GetLocations(); |
| 4590 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
| 4591 | CpuRegister current_method = locations->InAt(0).AsRegister<CpuRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4592 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 4593 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4594 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4595 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4596 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4597 | __ testl(out, out); |
| 4598 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4599 | __ Bind(slow_path->GetExitLabel()); |
| 4600 | } |
| 4601 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4602 | static Address GetExceptionTlsAddress() { |
| 4603 | return Address::Absolute(Thread::ExceptionOffset<kX86_64WordSize>().Int32Value(), true); |
| 4604 | } |
| 4605 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4606 | void LocationsBuilderX86_64::VisitLoadException(HLoadException* load) { |
| 4607 | LocationSummary* locations = |
| 4608 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 4609 | locations->SetOut(Location::RequiresRegister()); |
| 4610 | } |
| 4611 | |
| 4612 | void InstructionCodeGeneratorX86_64::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4613 | __ gs()->movl(load->GetLocations()->Out().AsRegister<CpuRegister>(), GetExceptionTlsAddress()); |
| 4614 | } |
| 4615 | |
| 4616 | void LocationsBuilderX86_64::VisitClearException(HClearException* clear) { |
| 4617 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 4618 | } |
| 4619 | |
| 4620 | void InstructionCodeGeneratorX86_64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 4621 | __ gs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4622 | } |
| 4623 | |
| 4624 | void LocationsBuilderX86_64::VisitThrow(HThrow* instruction) { |
| 4625 | LocationSummary* locations = |
| 4626 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4627 | InvokeRuntimeCallingConvention calling_convention; |
| 4628 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4629 | } |
| 4630 | |
| 4631 | void InstructionCodeGeneratorX86_64::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 4632 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 4633 | instruction, |
| 4634 | instruction->GetDexPc(), |
| 4635 | nullptr); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4636 | } |
| 4637 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4638 | void LocationsBuilderX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4639 | LocationSummary::CallKind call_kind = instruction->IsClassFinal() |
| 4640 | ? LocationSummary::kNoCall |
| 4641 | : LocationSummary::kCallOnSlowPath; |
| 4642 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4643 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4644 | locations->SetInAt(1, Location::Any()); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame^] | 4645 | // Note that TypeCheckSlowPathX86_64 uses this register too. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4646 | locations->SetOut(Location::RequiresRegister()); |
| 4647 | } |
| 4648 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4649 | void InstructionCodeGeneratorX86_64::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4650 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4651 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4652 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4653 | CpuRegister out = locations->Out().AsRegister<CpuRegister>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4654 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4655 | Label done, zero; |
| 4656 | SlowPathCodeX86_64* slow_path = nullptr; |
| 4657 | |
| 4658 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4659 | // Avoid null check if we know obj is not null. |
| 4660 | if (instruction->MustDoNullCheck()) { |
| 4661 | __ testl(obj, obj); |
| 4662 | __ j(kEqual, &zero); |
| 4663 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4664 | // Compare the class of `obj` with `cls`. |
| 4665 | __ movl(out, Address(obj, class_offset)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4666 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4667 | if (cls.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4668 | __ cmpl(out, cls.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4669 | } else { |
| 4670 | DCHECK(cls.IsStackSlot()) << cls; |
| 4671 | __ cmpl(out, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 4672 | } |
| 4673 | if (instruction->IsClassFinal()) { |
| 4674 | // Classes must be equal for the instanceof to succeed. |
| 4675 | __ j(kNotEqual, &zero); |
| 4676 | __ movl(out, Immediate(1)); |
| 4677 | __ jmp(&done); |
| 4678 | } else { |
| 4679 | // If the classes are not equal, we go into a slow path. |
| 4680 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame^] | 4681 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4682 | codegen_->AddSlowPath(slow_path); |
| 4683 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4684 | __ movl(out, Immediate(1)); |
| 4685 | __ jmp(&done); |
| 4686 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4687 | |
| 4688 | if (instruction->MustDoNullCheck() || instruction->IsClassFinal()) { |
| 4689 | __ Bind(&zero); |
| 4690 | __ movl(out, Immediate(0)); |
| 4691 | } |
| 4692 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4693 | if (slow_path != nullptr) { |
| 4694 | __ Bind(slow_path->GetExitLabel()); |
| 4695 | } |
| 4696 | __ Bind(&done); |
| 4697 | } |
| 4698 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4699 | void LocationsBuilderX86_64::VisitCheckCast(HCheckCast* instruction) { |
| 4700 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 4701 | instruction, LocationSummary::kCallOnSlowPath); |
| 4702 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4703 | locations->SetInAt(1, Location::Any()); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame^] | 4704 | // Note that TypeCheckSlowPathX86_64 uses this register too. |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4705 | locations->AddTemp(Location::RequiresRegister()); |
| 4706 | } |
| 4707 | |
| 4708 | void InstructionCodeGeneratorX86_64::VisitCheckCast(HCheckCast* instruction) { |
| 4709 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4710 | CpuRegister obj = locations->InAt(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4711 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4712 | CpuRegister temp = locations->GetTemp(0).AsRegister<CpuRegister>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4713 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame^] | 4714 | SlowPathCodeX86_64* slow_path = |
| 4715 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86_64(instruction); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4716 | codegen_->AddSlowPath(slow_path); |
| 4717 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4718 | // Avoid null check if we know obj is not null. |
| 4719 | if (instruction->MustDoNullCheck()) { |
| 4720 | __ testl(obj, obj); |
| 4721 | __ j(kEqual, slow_path->GetExitLabel()); |
| 4722 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4723 | // Compare the class of `obj` with `cls`. |
| 4724 | __ movl(temp, Address(obj, class_offset)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4725 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4726 | if (cls.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4727 | __ cmpl(temp, cls.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4728 | } else { |
| 4729 | DCHECK(cls.IsStackSlot()) << cls; |
| 4730 | __ cmpl(temp, Address(CpuRegister(RSP), cls.GetStackIndex())); |
| 4731 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4732 | // The checkcast succeeds if the classes are equal (fast path). |
| 4733 | // 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] | 4734 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4735 | __ Bind(slow_path->GetExitLabel()); |
| 4736 | } |
| 4737 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4738 | void LocationsBuilderX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 4739 | LocationSummary* locations = |
| 4740 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4741 | InvokeRuntimeCallingConvention calling_convention; |
| 4742 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4743 | } |
| 4744 | |
| 4745 | void InstructionCodeGeneratorX86_64::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 4746 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 4747 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 4748 | instruction, |
| 4749 | instruction->GetDexPc(), |
| 4750 | nullptr); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4751 | } |
| 4752 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4753 | void LocationsBuilderX86_64::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 4754 | void LocationsBuilderX86_64::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 4755 | void LocationsBuilderX86_64::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 4756 | |
| 4757 | void LocationsBuilderX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 4758 | LocationSummary* locations = |
| 4759 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4760 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 4761 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 4762 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4763 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4764 | locations->SetOut(Location::SameAsFirstInput()); |
| 4765 | } |
| 4766 | |
| 4767 | void InstructionCodeGeneratorX86_64::VisitAnd(HAnd* instruction) { |
| 4768 | HandleBitwiseOperation(instruction); |
| 4769 | } |
| 4770 | |
| 4771 | void InstructionCodeGeneratorX86_64::VisitOr(HOr* instruction) { |
| 4772 | HandleBitwiseOperation(instruction); |
| 4773 | } |
| 4774 | |
| 4775 | void InstructionCodeGeneratorX86_64::VisitXor(HXor* instruction) { |
| 4776 | HandleBitwiseOperation(instruction); |
| 4777 | } |
| 4778 | |
| 4779 | void InstructionCodeGeneratorX86_64::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 4780 | LocationSummary* locations = instruction->GetLocations(); |
| 4781 | Location first = locations->InAt(0); |
| 4782 | Location second = locations->InAt(1); |
| 4783 | DCHECK(first.Equals(locations->Out())); |
| 4784 | |
| 4785 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 4786 | if (second.IsRegister()) { |
| 4787 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4788 | __ andl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4789 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4790 | __ orl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4791 | } else { |
| 4792 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4793 | __ xorl(first.AsRegister<CpuRegister>(), second.AsRegister<CpuRegister>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4794 | } |
| 4795 | } else if (second.IsConstant()) { |
| 4796 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue()); |
| 4797 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4798 | __ andl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4799 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4800 | __ orl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4801 | } else { |
| 4802 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4803 | __ xorl(first.AsRegister<CpuRegister>(), imm); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4804 | } |
| 4805 | } else { |
| 4806 | Address address(CpuRegister(RSP), second.GetStackIndex()); |
| 4807 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4808 | __ andl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4809 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4810 | __ orl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4811 | } else { |
| 4812 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4813 | __ xorl(first.AsRegister<CpuRegister>(), address); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4814 | } |
| 4815 | } |
| 4816 | } else { |
| 4817 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4818 | CpuRegister first_reg = first.AsRegister<CpuRegister>(); |
| 4819 | bool second_is_constant = false; |
| 4820 | int64_t value = 0; |
| 4821 | if (second.IsConstant()) { |
| 4822 | second_is_constant = true; |
| 4823 | value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4824 | } |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4825 | bool is_int32_value = IsInt<32>(value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4826 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4827 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4828 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4829 | if (is_int32_value) { |
| 4830 | __ andq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 4831 | } else { |
| 4832 | __ andq(first_reg, codegen_->LiteralInt64Address(value)); |
| 4833 | } |
| 4834 | } else if (second.IsDoubleStackSlot()) { |
| 4835 | __ andq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4836 | } else { |
| 4837 | __ andq(first_reg, second.AsRegister<CpuRegister>()); |
| 4838 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4839 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4840 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4841 | if (is_int32_value) { |
| 4842 | __ orq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 4843 | } else { |
| 4844 | __ orq(first_reg, codegen_->LiteralInt64Address(value)); |
| 4845 | } |
| 4846 | } else if (second.IsDoubleStackSlot()) { |
| 4847 | __ orq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4848 | } else { |
| 4849 | __ orq(first_reg, second.AsRegister<CpuRegister>()); |
| 4850 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4851 | } else { |
| 4852 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4853 | if (second_is_constant) { |
Mark Mendell | 40741f3 | 2015-04-20 22:10:34 -0400 | [diff] [blame] | 4854 | if (is_int32_value) { |
| 4855 | __ xorq(first_reg, Immediate(static_cast<int32_t>(value))); |
| 4856 | } else { |
| 4857 | __ xorq(first_reg, codegen_->LiteralInt64Address(value)); |
| 4858 | } |
| 4859 | } else if (second.IsDoubleStackSlot()) { |
| 4860 | __ xorq(first_reg, Address(CpuRegister(RSP), second.GetStackIndex())); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4861 | } else { |
| 4862 | __ xorq(first_reg, second.AsRegister<CpuRegister>()); |
| 4863 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4864 | } |
| 4865 | } |
| 4866 | } |
| 4867 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4868 | void LocationsBuilderX86_64::VisitBoundType(HBoundType* instruction) { |
| 4869 | // Nothing to do, this should be removed during prepare for register allocator. |
| 4870 | UNUSED(instruction); |
| 4871 | LOG(FATAL) << "Unreachable"; |
| 4872 | } |
| 4873 | |
| 4874 | void InstructionCodeGeneratorX86_64::VisitBoundType(HBoundType* instruction) { |
| 4875 | // Nothing to do, this should be removed during prepare for register allocator. |
| 4876 | UNUSED(instruction); |
| 4877 | LOG(FATAL) << "Unreachable"; |
| 4878 | } |
| 4879 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 4880 | void LocationsBuilderX86_64::VisitFakeString(HFakeString* instruction) { |
| 4881 | DCHECK(codegen_->IsBaseline()); |
| 4882 | LocationSummary* locations = |
| 4883 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4884 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); |
| 4885 | } |
| 4886 | |
| 4887 | void InstructionCodeGeneratorX86_64::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { |
| 4888 | DCHECK(codegen_->IsBaseline()); |
| 4889 | // Will be generated at use site. |
| 4890 | } |
| 4891 | |
Mark Mendell | 92e83bf | 2015-05-07 11:25:03 -0400 | [diff] [blame] | 4892 | void CodeGeneratorX86_64::Load64BitValue(CpuRegister dest, int64_t value) { |
| 4893 | if (value == 0) { |
| 4894 | __ xorl(dest, dest); |
| 4895 | } else if (value > 0 && IsInt<32>(value)) { |
| 4896 | // We can use a 32 bit move, as it will zero-extend and is one byte shorter. |
| 4897 | __ movl(dest, Immediate(static_cast<int32_t>(value))); |
| 4898 | } else { |
| 4899 | __ movq(dest, Immediate(value)); |
| 4900 | } |
| 4901 | } |
| 4902 | |
Mark Mendell | cfa410b | 2015-05-25 16:02:44 -0400 | [diff] [blame] | 4903 | void CodeGeneratorX86_64::Store64BitValueToStack(Location dest, int64_t value) { |
| 4904 | DCHECK(dest.IsDoubleStackSlot()); |
| 4905 | if (IsInt<32>(value)) { |
| 4906 | // Can move directly as an int32 constant. |
| 4907 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), |
| 4908 | Immediate(static_cast<int32_t>(value))); |
| 4909 | } else { |
| 4910 | Load64BitValue(CpuRegister(TMP), value); |
| 4911 | __ movq(Address(CpuRegister(RSP), dest.GetStackIndex()), CpuRegister(TMP)); |
| 4912 | } |
| 4913 | } |
| 4914 | |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4915 | void CodeGeneratorX86_64::Finalize(CodeAllocator* allocator) { |
| 4916 | // Generate the constant area if needed. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 4917 | X86_64Assembler* assembler = GetAssembler(); |
| 4918 | if (!assembler->IsConstantAreaEmpty()) { |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4919 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 4920 | // byte values. If used for vectors at a later time, this will need to be |
| 4921 | // updated to 16 bytes with the appropriate offset. |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 4922 | assembler->Align(4, 0); |
| 4923 | constant_area_start_ = assembler->CodeSize(); |
| 4924 | assembler->AddConstantArea(); |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4925 | } |
| 4926 | |
| 4927 | // And finish up. |
| 4928 | CodeGenerator::Finalize(allocator); |
| 4929 | } |
| 4930 | |
| 4931 | /** |
| 4932 | * Class to handle late fixup of offsets into constant area. |
| 4933 | */ |
| 4934 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocMisc> { |
| 4935 | public: |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 4936 | RIPFixup(const CodeGeneratorX86_64& codegen, int offset) |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4937 | : codegen_(codegen), offset_into_constant_area_(offset) {} |
| 4938 | |
| 4939 | private: |
| 4940 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 4941 | // Patch the correct offset for the instruction. We use the address of the |
| 4942 | // 'next' instruction, which is 'pos' (patch the 4 bytes before). |
| 4943 | int constant_offset = codegen_.ConstantAreaStart() + offset_into_constant_area_; |
| 4944 | int relative_position = constant_offset - pos; |
| 4945 | |
| 4946 | // Patch in the right value. |
| 4947 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 4948 | } |
| 4949 | |
Mark Mendell | 39dcf55 | 2015-04-09 20:42:42 -0400 | [diff] [blame] | 4950 | const CodeGeneratorX86_64& codegen_; |
Mark Mendell | f55c3e0 | 2015-03-26 21:07:46 -0400 | [diff] [blame] | 4951 | |
| 4952 | // Location in constant area that the fixup refers to. |
| 4953 | int offset_into_constant_area_; |
| 4954 | }; |
| 4955 | |
| 4956 | Address CodeGeneratorX86_64::LiteralDoubleAddress(double v) { |
| 4957 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 4958 | return Address::RIP(fixup); |
| 4959 | } |
| 4960 | |
| 4961 | Address CodeGeneratorX86_64::LiteralFloatAddress(float v) { |
| 4962 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 4963 | return Address::RIP(fixup); |
| 4964 | } |
| 4965 | |
| 4966 | Address CodeGeneratorX86_64::LiteralInt32Address(int32_t v) { |
| 4967 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 4968 | return Address::RIP(fixup); |
| 4969 | } |
| 4970 | |
| 4971 | Address CodeGeneratorX86_64::LiteralInt64Address(int64_t v) { |
| 4972 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 4973 | return Address::RIP(fixup); |
| 4974 | } |
| 4975 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4976 | #undef __ |
| 4977 | |
Nicolas Geoffray | 9cf3552 | 2014-06-09 18:40:10 +0100 | [diff] [blame] | 4978 | } // namespace x86_64 |
| 4979 | } // namespace art |